diff --git a/.php_cs b/.php_cs index dcd9cd1b..5f6b5da1 100644 --- a/.php_cs +++ b/.php_cs @@ -1,40 +1,5 @@ - -For the full copyright and license information, please view the LICENSE -file that was distributed with this source code. -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(), array( - 'header_comment' => array('header' => $header) - ))); -} - -return $config; +return require_once __DIR__.'/.php_cs.dist'; diff --git a/.php_cs.dist b/.php_cs.dist new file mode 100644 index 00000000..62b8e5aa --- /dev/null +++ b/.php_cs.dist @@ -0,0 +1,77 @@ + + +For the full copyright and license information, please view the LICENSE +file that was distributed with this source code. +HEADER; + +$rules = [ + '@Symfony' => true, + '@Symfony:risky' => true, + 'array_syntax' => [ + 'syntax' => 'short', + ], + 'combine_consecutive_issets' => true, + 'combine_consecutive_unsets' => true, + 'header_comment' => [ + 'header' => $header, + ], + 'no_extra_consecutive_blank_lines' => true, + 'no_php4_constructor' => true, + 'no_useless_else' => true, + 'no_useless_return' => true, + 'ordered_class_elements' => true, + 'ordered_imports' => true, + 'phpdoc_order' => true, + // To be tested before insertion: +// 'strict_comparison' => true, +// 'strict_param' => true, +// 'php_unit_strict' => true, +]; + +if (\PHP_VERSION_ID >= 50600) { + $rules = array_merge($rules, [ + '@PHP56Migration' => true, + '@PHP56Migration:risky' => true, + '@PHPUnit57Migration:risky' => true, + ]); +} +if (\PHP_VERSION_ID >= 70000) { + $rules = array_merge($rules, [ + '@PHP70Migration' => true, + '@PHP70Migration:risky' => true, + '@PHPUnit60Migration:risky' => true, + ]); +} +if (\PHP_VERSION_ID >= 70100) { + $rules = array_merge($rules, [ + '@PHP71Migration' => true, + '@PHP71Migration:risky' => true, + 'compact_nullable_typehint' => true, + ]); +} + +$finder = PhpCsFixer\Finder::create() + ->in(preg_match('/dev-kit\/project$/', __DIR__, $matches) ? __DIR__.'/..' : __DIR__) + ->exclude('Tests/Fixtures') + ->exclude('tests/Fixtures') + ->exclude('Resources/skeleton') + ->exclude('Resources/public/vendor') +; + +return PhpCsFixer\Config::create() + ->setFinder($finder) + ->setRiskyAllowed(true) + ->setRules($rules) + ->setUsingCache(true) +; diff --git a/.styleci.yml b/.styleci.yml index 6424eea7..fb48254e 100644 --- a/.styleci.yml +++ b/.styleci.yml @@ -1,30 +1 @@ -# DO NOT EDIT THIS FILE! -# -# It's auto-generated by sonata-project/dev-kit package. -# -# Package `sllh/php-cs-fixer-styleci-bridge` is required to get it working. - -preset: symfony - -enabled: - - combine_consecutive_unsets - - short_array_syntax - - newline_after_open_tag - - no_php4_constructor - - no_useless_else - - ordered_class_elements - - ordered_use -# Comment strict rules for the moment. Should be uncomment later to see StyleCI PR results -# - strict -# - strict_param -# - php_unit_construct -# - php_unit_strict - -finder: - exclude: - - 'Tests/Fixtures' - - 'tests/Fixtures' - # ecommerce special case: - - 'Resources/skeleton' - # ignore vendor assets - - 'Resources/public/vendor' +# TO BE REMOVED diff --git a/.travis.yml b/.travis.yml index 532739e9..e2d12d11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -13,11 +13,17 @@ php: - '5.6' - '7.0' - '7.1' + - '7.2' - nightly sudo: false dist: trusty +addons: + apt: + packages: + - libxml2-utils + cache: pip: true directories: @@ -34,36 +40,38 @@ env: matrix: fast_finish: true include: - - php: '7.1' + - php: '7.2' env: TARGET=docs - - php: '7.1' + - php: '5.6' env: TARGET=lint - php: '5.6' env: COMPOSER_FLAGS="--prefer-lowest" - - php: '7.1' + - php: '7.2' env: SYMFONY=2.8.* - - php: '7.1' + - php: '7.2' env: SYMFONY=3.2.* - - php: '7.1' + - php: '7.2' env: SYMFONY=3.3.* - - php: '7.1' - env: SYMFONY='dev-master as 3.3' - - php: '7.1' + - php: '7.2' + env: SYMFONY=3.4.* + - php: '7.2' + env: SYMFONY='dev-master as 3.4.x-dev' + - php: '7.2' env: SONATA_CORE=3.* - - php: '7.1' - env: SONATA_CORE='dev-master as 3' - - php: '7.1' + - php: '7.2' + env: SONATA_CORE='dev-master as 3.x-dev' + - php: '7.2' env: SONATA_ADMIN=3.* - - php: '7.1' - env: SONATA_ADMIN='dev-master as 3' - - php: '7.1' + - php: '7.2' + env: SONATA_ADMIN='dev-master as 3.x-dev' + - php: '7.2' env: SYMFONY_DEPRECATIONS_HELPER=0 allow_failures: - php: nightly - env: SYMFONY_DEPRECATIONS_HELPER=0 - - env: SYMFONY='dev-master as 3.3' - - env: SONATA_CORE='dev-master as 3' - - env: SONATA_ADMIN='dev-master as 3' + - env: SYMFONY='dev-master as 3.4.x-dev' + - env: SONATA_CORE='dev-master as 3.x-dev' + - env: SONATA_ADMIN='dev-master as 3.x-dev' before_install: - git remote add upstream ${UPSTREAM_URL} && git fetch --all diff --git a/.travis/install_lint.sh b/.travis/install_lint.sh index ab8f0f39..864c751e 100755 --- a/.travis/install_lint.sh +++ b/.travis/install_lint.sh @@ -1,6 +1,11 @@ #!/usr/bin/env sh set -ev +mkdir --parents "${HOME}/bin" + +wget "http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar" --output-document="${HOME}/bin/php-cs-fixer" +chmod u+x "${HOME}/bin/php-cs-fixer" + composer global require sllh/composer-lint:@stable --prefer-dist --no-interaction gem install yaml-lint diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 029f06c3..30f3a9c0 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -72,6 +72,23 @@ and run this command before committing your modifications: php-cs-fixer fix --verbose ``` +Please note that we try to keep phpdoc to a minimum, so if an `@param` phpdoc +comment brings nothing more than the type hint and variable name already do, +it should be removed. Descriptions are optional if you want to document a type. + +```php +/** + * @param Bar|Baz $foo + * @param int $limit a crucial, highly interesting comment + */ +protected function bar($foo, string $name, int $limit) +{ + // ... +} +``` + +Please also note that multiline signatures are allowed when the line is longer than 120 characters. + #### The documentation The documentation is mostly written with the `rst` format, and can be found in the `docs` directory. diff --git a/Makefile b/Makefile index 43e65b4e..6fb54c87 100644 --- a/Makefile +++ b/Makefile @@ -11,8 +11,9 @@ lint: composer validate find . -name '*.yml' -not -path './vendor/*' -not -path './Resources/public/vendor/*' | xargs yaml-lint find . \( -name '*.xml' -or -name '*.xliff' \) \ - -not -path './vendor/*' -not -path './Resources/public/vendor/*' -type f \ - -exec xmllint --encode UTF-8 --output '{}' --format '{}' \; + -not -path './vendor/*' -not -path './Resources/public/vendor/*' \ + | xargs -I'{}' xmllint --encode UTF-8 --output '{}' --format '{}' + php-cs-fixer fix --verbose git diff --exit-code test: diff --git a/composer.json b/composer.json index 1fbda3d5..e95ee5c1 100644 --- a/composer.json +++ b/composer.json @@ -18,9 +18,9 @@ ], "require": { "php": "^5.6 || ^7.0", - "sonata-project/admin-bundle": "^3.23", - "sonata-project/block-bundle": "^3.4", - "sonata-project/core-bundle": "^3.6", + "sonata-project/admin-bundle": "^3.28", + "sonata-project/block-bundle": "^3.8", + "sonata-project/core-bundle": "^3.7.1", "symfony/framework-bundle": "^2.8 || ^3.2", "symfony/options-resolver": "^2.8 || ^3.2", "twig/twig": "^1.35 || ^2.4" @@ -29,8 +29,7 @@ "doctrine/orm": "^2.5", "knplabs/doctrine-behaviors": "^1.4", "matthiasnoback/symfony-dependency-injection-test": "^1.0", - "sllh/php-cs-fixer-styleci-bridge": "^2.0", - "sonata-project/doctrine-orm-admin-bundle": "^3.1", + "sonata-project/doctrine-orm-admin-bundle": "^3.2", "stof/doctrine-extensions-bundle": "^1.1", "symfony/phpunit-bridge": "^3.3" }, diff --git a/src/Model/Gedmo/AbstractPersonalTranslatable.php b/src/Model/Gedmo/AbstractPersonalTranslatable.php index c3d5926f..52d5cb3b 100644 --- a/src/Model/Gedmo/AbstractPersonalTranslatable.php +++ b/src/Model/Gedmo/AbstractPersonalTranslatable.php @@ -58,8 +58,6 @@ public function getTranslation($field, $locale) return $translation->getContent(); } } - - return; } /** diff --git a/src/Test/DoctrineOrmTestCase.php b/src/Test/DoctrineOrmTestCase.php index d65ec72b..1d272d85 100644 --- a/src/Test/DoctrineOrmTestCase.php +++ b/src/Test/DoctrineOrmTestCase.php @@ -28,7 +28,7 @@ * Inspired by BaseTestCaseORM * @author Gediminas Morkevicius */ -abstract class DoctrineOrmTestCase extends \PHPUnit_Framework_TestCase +abstract class DoctrineOrmTestCase extends \PHPUnit\Framework\TestCase { /** * @var EntityManager diff --git a/src/Traits/Gedmo/PersonalTranslatableTrait.php b/src/Traits/Gedmo/PersonalTranslatableTrait.php index a5d98b9e..eea593b0 100644 --- a/src/Traits/Gedmo/PersonalTranslatableTrait.php +++ b/src/Traits/Gedmo/PersonalTranslatableTrait.php @@ -43,8 +43,6 @@ public function getTranslation($field, $locale) return $translation->getContent(); } } - - return; } /**