From 0da054311cec93e1dc8311bc7a7dab4f5859cf20 Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Thu, 17 Aug 2017 13:51:38 +0200 Subject: [PATCH 1/4] Correct Style (and apply fixes from PhpStan) --- .gitattributes | 2 +- .styleci.yml | 25 ------------------- composer.json | 15 +++++++++-- phpstan.neon | 24 ++++++++++++++++++ src/DoctrineDbalFactory.php | 2 +- .../Conversion/AgeDateConversion.php | 4 ++- src/QueryPlatform/AbstractQueryPlatform.php | 2 +- tests/Functional/FunctionalDbalTestCase.php | 4 +-- tests/Mocks/ConnectionMock.php | 1 + 9 files changed, 46 insertions(+), 33 deletions(-) delete mode 100644 .styleci.yml create mode 100644 phpstan.neon diff --git a/.gitattributes b/.gitattributes index 15334a8..56b3359 100644 --- a/.gitattributes +++ b/.gitattributes @@ -8,9 +8,9 @@ core.autocrlf=lf .gitignore export-ignore .php_cs export-ignore .scrutinizer.yml export-ignore -.styleci.yml export-ignore .travis.yml export-ignore .github export-ignore phpunit.xml.dist export-ignore +phpstan.neon export-ignore /tests export-ignore /doc export-ignore diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 9b82a9c..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,25 +0,0 @@ -preset: symfony - -risky: true -linting: true - -enabled: - - newline_after_open_tag - #- ordered_class_elements - - ordered_use - - phpdoc_order - - short_array_syntax - - # Strict - - strict_param - - declare_strict_types - -disabled: - - phpdoc_no_empty_return - -finder: - path: - - 'src/' - - 'tests/' - not-path: - - 'Fixtures' diff --git a/composer.json b/composer.json index 5e64c0c..9b2a554 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "psr-4": { "Rollerworks\\Component\\Search\\Doctrine\\Dbal\\": "src/", "Rollerworks\\Component\\Search\\Extension\\Doctrine\\Dbal\\": "src/Extension/" - } + }, + "exclude-from-classmap": ["tests/"] }, "autoload-dev": { "psr-4": { @@ -41,5 +42,15 @@ "branch-alias": { "dev-master": "2.0-dev" } - } + }, + "config": { + "platform": { + "php": "7.1" + }, + "preferred-install": { + "doctrine/dbal": "source", + "*": "dist" + }, + "sort-packages": true + }, } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..a3753da --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,24 @@ +parameters: + autoload_files: + - vendor/autoload.php + ignoreErrors: + #- '#__construct\(\) does not call parent constructor from .+#' + + # ValueHolder guard there own correctness. A ValuesBag never returns a wrong object (collection). + - '#expects Rollerworks\\Component\\Search\\Value\\[a-zA-Z]+\[\], Rollerworks\\Component\\Search\\Value\\ValueHolder\[\] given#' +# - '#Call to an undefined method Rollerworks\\Component\\Search\\Value\\ValueHolder\:\:#' + + # False positive + - '#Call to an undefined method Doctrine\\DBAL\\Driver\\Connection\:\:sqliteCreateFunction\(\)#' + - '#Parameter \#2 \$type of method Doctrine\\DBAL\\Connection\:\:quote\(\) expects int\|null, Doctrine\\DBAL\\Types\\Type given#' + - "#Casting to string something that's already string#" # cannot fix this yet. + - '#(DbalTestCase|FunctionalDbalTestCase|SearchIntegrationTestCase) not found and could not be autoloaded#' # properly a bug in PHPStan? + + # Tests +# - '#Call to an undefined method Prophecy\\Prophecy\\ObjectProphecy::[a-zA-Z0-9_]+\(\)#' +# - '#Access to an undefined property Prophecy\\Prophecy\\ObjectProphecy::\$[a-zA-Z0-9_]+#' +# - '#Call to an undefined method PHPUnit_Framework_MockObject_MockObject::[a-zA-Z0-9_]+\(\)#' +# - '#expects\s+[^\s]+, PHPUnit_Framework_MockObject_MockObject(\[\])? given#' +# - '#does not accept PHPUnit_Framework_MockObject_MockObject#' +# - '#but returns PHPUnit_Framework_MockObject_MockObject#' +# - '#Call to an undefined static method Money\\Money\:\:#' diff --git a/src/DoctrineDbalFactory.php b/src/DoctrineDbalFactory.php index acb74a4..5392de9 100644 --- a/src/DoctrineDbalFactory.php +++ b/src/DoctrineDbalFactory.php @@ -25,7 +25,7 @@ final class DoctrineDbalFactory /** * @var Cache */ - protected $cacheDriver; + private $cacheDriver; /** * Constructor. diff --git a/src/Extension/Conversion/AgeDateConversion.php b/src/Extension/Conversion/AgeDateConversion.php index c94c006..334627f 100644 --- a/src/Extension/Conversion/AgeDateConversion.php +++ b/src/Extension/Conversion/AgeDateConversion.php @@ -84,7 +84,9 @@ public function convertColumn(string $column, array $options, ConversionHints $h } /** - * {@inheritdoc} + * @inheritdoc + * + * @return string|int */ public function convertValue($value, array $options, ConversionHints $hints) { diff --git a/src/QueryPlatform/AbstractQueryPlatform.php b/src/QueryPlatform/AbstractQueryPlatform.php index cd5b028..e7dccbb 100644 --- a/src/QueryPlatform/AbstractQueryPlatform.php +++ b/src/QueryPlatform/AbstractQueryPlatform.php @@ -59,7 +59,7 @@ public function getValueAsSql($value, QueryField $mappingConfig, string $column, return $this->convertSqlValue($value, $mappingConfig, $column, $strategy); } - return (string) $this->quoteValue( + return $this->quoteValue( $mappingConfig->dbType->convertToDatabaseValue($value, $this->connection->getDatabasePlatform()), $mappingConfig->dbType ); diff --git a/tests/Functional/FunctionalDbalTestCase.php b/tests/Functional/FunctionalDbalTestCase.php index 6316059..c7f7e89 100644 --- a/tests/Functional/FunctionalDbalTestCase.php +++ b/tests/Functional/FunctionalDbalTestCase.php @@ -197,9 +197,9 @@ protected function onNotSuccessfulTest(\Throwable $e) function ($p) { if (is_object($p)) { return get_class($p); - } else { - return "'".var_export($p, true)."'"; } + + return "'".var_export($p, true)."'"; }, $query['params'] ?: [] ); diff --git a/tests/Mocks/ConnectionMock.php b/tests/Mocks/ConnectionMock.php index 996b62c..45cb7b9 100644 --- a/tests/Mocks/ConnectionMock.php +++ b/tests/Mocks/ConnectionMock.php @@ -16,6 +16,7 @@ class ConnectionMock extends \Doctrine\DBAL\Connection { private $_fetchOneResult; + private $_platform; private $_platformMock; private $_lastInsertId = 0; private $_inserts = []; From 336a7c8974a33f10dc45fcdf4df49d86b8c9e5fc Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Thu, 17 Aug 2017 13:57:50 +0200 Subject: [PATCH 2/4] Travis configuration improvements --- .travis.yml | 22 ++++++++++++++-------- composer.json | 2 +- phpunit.xml.dist | 1 - tests/travis/mysql.travis.xml | 1 - tests/travis/pgsql.travis.xml | 1 - tests/travis/sqlite.travis.xml | 1 - 6 files changed, 15 insertions(+), 13 deletions(-) diff --git a/.travis.yml b/.travis.yml index fcf93b1..522a7f4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -21,7 +21,7 @@ php: matrix: include: - php: 7.1 - env: deps='low' + env: deps='low' lint=1 - php: 7.1 env: DB=pgsql - php: 7.1 @@ -29,23 +29,29 @@ matrix: - php: 7.1 env: DB=mysql - php: 7.1 - env: deps='dev' + env: deps='dev' lint=1 fast_finish: true before_install: - phpenv config-rm xdebug.ini || echo "xdebug not available" + - echo "memory_limit=-1" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini + - if [[ $lint = 1 ]]; then wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.3.2/php-cs-fixer.phar; fi + - if [[ $lint = 1 ]]; then composer global require --dev 'phpstan/phpstan:^0.8'; fi + - export PATH="$PATH:$HOME/.composer/vendor/bin" install: - - export COMPOSER_ROOT_VERSION=dev-master - - export SYMFONY_PHPUNIT_REMOVE="symfony/yaml" - - export SYMFONY_PHPUNIT_VERSION=6.2 - - if [[ ! $deps ]]; then composer update --prefer-source --no-progress --no-suggest --ansi; fi - - if [[ $deps = 'dev' ]]; then composer config minimum-stability dev && composer update --prefer-source --no-progress --no-suggest --ansi ; fi - - if [[ $deps = 'low' ]]; then composer update --prefer-source --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi + - if [[ ! $deps ]]; then composer update --no-progress --no-suggest --ansi; fi + - if [[ $deps = 'dev' ]]; then composer config minimum-stability dev && composer update --no-progress --no-suggest --ansi ; fi + - if [[ $deps = 'low' ]]; then composer update --no-progress --no-suggest --prefer-stable --prefer-lowest --ansi; fi before_script: - if [ "$DB" == "mysql" ]; then mysql -e 'create database search_tests;'; fi; script: + - export SYMFONY_DEPRECATIONS_HELPER=strict + - export SYMFONY_PHPUNIT_REMOVE="symfony/yaml" + - export SYMFONY_PHPUNIT_VERSION=6.2 - vendor/bin/simple-phpunit --verbose - if [ "$DB" != "" ]; then vendor/bin/simple-phpunit --configuration tests/travis/$DB.travis.xml; fi; + - if [[ $lint = 1 ]]; then php php-cs-fixer.phar fix --dry-run --diff --no-ansi; fi + - if [[ $lint = 1 ]]; then phpstan analyse -c phpstan.neon -l5 --ansi src tests; fi diff --git a/composer.json b/composer.json index 9b2a554..ce24ade 100644 --- a/composer.json +++ b/composer.json @@ -52,5 +52,5 @@ "*": "dist" }, "sort-packages": true - }, + } } diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 34a6661..7c9cc09 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -4,7 +4,6 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" colors="true" bootstrap="tests/bootstrap.php" - beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" > diff --git a/tests/travis/mysql.travis.xml b/tests/travis/mysql.travis.xml index a05a00c..98b61c2 100644 --- a/tests/travis/mysql.travis.xml +++ b/tests/travis/mysql.travis.xml @@ -4,7 +4,6 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" colors="true" bootstrap="../bootstrap.php" - beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" > diff --git a/tests/travis/pgsql.travis.xml b/tests/travis/pgsql.travis.xml index 4b41314..2956080 100644 --- a/tests/travis/pgsql.travis.xml +++ b/tests/travis/pgsql.travis.xml @@ -4,7 +4,6 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" colors="true" bootstrap="../bootstrap.php" - beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" > diff --git a/tests/travis/sqlite.travis.xml b/tests/travis/sqlite.travis.xml index 3281005..889503e 100644 --- a/tests/travis/sqlite.travis.xml +++ b/tests/travis/sqlite.travis.xml @@ -4,7 +4,6 @@ xsi:noNamespaceSchemaLocation="http://schema.phpunit.de/6.2/phpunit.xsd" colors="true" bootstrap="../bootstrap.php" - beStrictAboutTestsThatDoNotTestAnything="false" beStrictAboutOutputDuringTests="true" beStrictAboutTodoAnnotatedTests="true" > From 5cada450ad07e9f74323949c844382b8b1cc39bd Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Thu, 17 Aug 2017 14:12:10 +0200 Subject: [PATCH 3/4] Rename .php_cs to .php_cs.dist --- .gitattributes | 2 +- .php_cs | 38 ------------------------------------- .php_cs.dist | 51 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 52 insertions(+), 39 deletions(-) delete mode 100644 .php_cs create mode 100644 .php_cs.dist diff --git a/.gitattributes b/.gitattributes index 56b3359..10b4753 100644 --- a/.gitattributes +++ b/.gitattributes @@ -6,7 +6,7 @@ core.autocrlf=lf .editorconfig .gitattributes export-ignore .gitignore export-ignore -.php_cs export-ignore +.php_cs.dist export-ignore .scrutinizer.yml export-ignore .travis.yml export-ignore .github export-ignore diff --git a/.php_cs b/.php_cs deleted file mode 100644 index d0136cf..0000000 --- a/.php_cs +++ /dev/null @@ -1,38 +0,0 @@ - - -This source file is subject to the MIT license that is bundled -with this source code in the file LICENSE. -EOF; - -// PHP-CS-Fixer 1.x -if (class_exists('Symfony\CS\Fixer\Contrib\HeaderCommentFixer')) { - \Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); -} - -$config = ConfigBridge::create() - ->setUsingCache(true) -; - -// PHP-CS-Fixer 2.x -if (method_exists($config, 'setRules')) { - $config->setRules( - array_merge( - $config->getRules(), - [ - 'header_comment' => ['header' => $header], - ] - ) - ); -} - -return $config; diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 0000000..bc841cf --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,51 @@ + + +This source file is subject to the MIT license that is bundled +with this source code in the file LICENSE. +EOF; + +return PhpCsFixer\Config::create() + ->setRules([ + '@Symfony' => true, + '@Symfony:risky' => true, + '@PHP70Migration' => true, + '@PHP71Migration' => true, + 'array_syntax' => array('syntax' => 'short'), + 'combine_consecutive_unsets' => true, + 'declare_strict_types' => true, + 'header_comment' => ['header' => $header], + 'heredoc_to_nowdoc' => true, + 'linebreak_after_opening_tag' => true, + 'no_extra_consecutive_blank_lines' => ['continue', 'extra', 'return', 'throw', 'use', 'parenthesis_brace_block', 'square_brace_block', 'curly_brace_block'], + 'no_short_echo_tag' => true, + 'no_unreachable_default_argument_value' => false, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => false, + 'ordered_imports' => true, + 'phpdoc_add_missing_param_annotation' => false, + 'phpdoc_annotation_without_dot' => true, + 'phpdoc_no_empty_return' => false, // PHP 7 compatibility + 'phpdoc_order' => true, + // This breaks for variable @var blocks + 'phpdoc_to_comment' => false, + 'phpdoc_var_without_name' => false, + 'semicolon_after_instruction' => true, + 'single_import_per_statement' => false, + 'strict_comparison' => false, + 'strict_param' => true, + // Breaks with phpstan + 'phpdoc_inline_tag' => false, + ]) + ->setRiskyAllowed(true) + ->setFinder( + PhpCsFixer\Finder::create() + ->exclude('Fixtures') + ->in([__DIR__.'/src', __DIR__.'/tests']) + ) +; From 69fe9dc518adf0a51d7bf94d29648c1cdc8cd788 Mon Sep 17 00:00:00 2001 From: Sebastiaan Stok Date: Thu, 17 Aug 2017 14:17:22 +0200 Subject: [PATCH 4/4] Fix phpstan violation --- phpstan.neon | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/phpstan.neon b/phpstan.neon index a3753da..1c6b51a 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -10,7 +10,7 @@ parameters: # False positive - '#Call to an undefined method Doctrine\\DBAL\\Driver\\Connection\:\:sqliteCreateFunction\(\)#' - - '#Parameter \#2 \$type of method Doctrine\\DBAL\\Connection\:\:quote\(\) expects int\|null, Doctrine\\DBAL\\Types\\Type given#' + - '#Parameter \#2 \$type of method Doctrine\\DBAL\\Connection\:\:quote\(\) expects ([^\s]+)#' - "#Casting to string something that's already string#" # cannot fix this yet. - '#(DbalTestCase|FunctionalDbalTestCase|SearchIntegrationTestCase) not found and could not be autoloaded#' # properly a bug in PHPStan?