From 296de6086edb529cb05139b34935e3e581c83ea5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sun, 14 Jun 2020 23:27:37 +0200 Subject: [PATCH 1/7] NoEmptyCommentFixer - better handle comments sequence --- src/Fixer/Comment/NoEmptyCommentFixer.php | 5 +++++ .../Fixer/Comment/NoEmptyCommentFixerTest.php | 18 +++++++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/src/Fixer/Comment/NoEmptyCommentFixer.php b/src/Fixer/Comment/NoEmptyCommentFixer.php index 652daab5be6..c6873e72a86 100644 --- a/src/Fixer/Comment/NoEmptyCommentFixer.php +++ b/src/Fixer/Comment/NoEmptyCommentFixer.php @@ -89,6 +89,11 @@ private function getCommentBlock(Tokens $tokens, $index) { $commentType = $this->getCommentType($tokens[$index]->getContent()); $empty = $this->isEmptyComment($tokens[$index]->getContent()); + + if (self::TYPE_SLASH_ASTERISK === $commentType) { + return [$index, $index, $empty]; + } + $start = $index; $count = \count($tokens); ++$index; diff --git a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php index 9cd2eb97510..87d39cb64b6 100644 --- a/tests/Fixer/Comment/NoEmptyCommentFixerTest.php +++ b/tests/Fixer/Comment/NoEmptyCommentFixerTest.php @@ -232,6 +232,22 @@ public function provideFixCases() ********/ ', ], + [ + ' Date: Mon, 15 Jun 2020 17:50:57 +0200 Subject: [PATCH 2/7] StrictParamFixer - must run before NativeFunctionInvocationFixer --- .../NativeFunctionInvocationFixer.php | 10 ++++++++++ src/Fixer/Strict/StrictParamFixer.php | 10 ++++++++++ tests/AutoReview/FixerFactoryTest.php | 1 + ...rict_param,native_function_invocation.test | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+) create mode 100644 tests/Fixtures/Integration/priority/strict_param,native_function_invocation.test diff --git a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php index 26bf5416152..285de8130f4 100644 --- a/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php +++ b/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php @@ -176,6 +176,16 @@ public function isRisky() return true; } + /** + * {@inheritdoc} + * + * Must run after StrictParamFixer. + */ + public function getPriority() + { + return 0; + } + /** * {@inheritdoc} */ diff --git a/src/Fixer/Strict/StrictParamFixer.php b/src/Fixer/Strict/StrictParamFixer.php index b8c5c17b9fd..4e1834aa803 100644 --- a/src/Fixer/Strict/StrictParamFixer.php +++ b/src/Fixer/Strict/StrictParamFixer.php @@ -53,6 +53,16 @@ public function isRisky() return true; } + /** + * {@inheritdoc} + * + * Must run before NativeFunctionInvocationFixer. + */ + public function getPriority() + { + return 1; + } + /** * {@inheritdoc} */ diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 894d19729df..679a714fab0 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -235,6 +235,7 @@ public function provideFixersPriorityCases() [$fixers['standardize_increment'], $fixers['increment_style']], [$fixers['standardize_not_equals'], $fixers['binary_operator_spaces']], [$fixers['strict_comparison'], $fixers['binary_operator_spaces']], + [$fixers['strict_param'], $fixers['native_function_invocation']], [$fixers['unary_operator_spaces'], $fixers['not_operator_with_space']], [$fixers['unary_operator_spaces'], $fixers['not_operator_with_successor_space']], [$fixers['void_return'], $fixers['phpdoc_no_empty_return']], diff --git a/tests/Fixtures/Integration/priority/strict_param,native_function_invocation.test b/tests/Fixtures/Integration/priority/strict_param,native_function_invocation.test new file mode 100644 index 00000000000..325fc228246 --- /dev/null +++ b/tests/Fixtures/Integration/priority/strict_param,native_function_invocation.test @@ -0,0 +1,19 @@ +--TEST-- +Integration of fixers: strict_param,native_function_invocation. +--RULESET-- +{"strict_param": true, "native_function_invocation": true} +--EXPECT-- + Date: Sun, 21 Jun 2020 13:41:27 +0200 Subject: [PATCH 3/7] Fix issue templates --- .github/ISSUE_TEMPLATE/bug_report.md | 2 +- .github/ISSUE_TEMPLATE/feature_request.md | 2 +- .github/ISSUE_TEMPLATE/rule_request.md | 2 +- .github/ISSUE_TEMPLATE/support_question.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index a78ff3260c9..df222c17d73 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -1,7 +1,7 @@ --- name: Bug report 🐛 about: Existing feature does not behave as expected. -label: kind/bug +labels: kind/bug --- ## Bug report diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md index d12a4be768d..cf0df9253c4 100644 --- a/.github/ISSUE_TEMPLATE/feature_request.md +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -1,7 +1,7 @@ --- name: Feature request 🚀 about: I have a suggestion about a new feature (and may want to implement it)! -label: kind/feature request +labels: kind/feature request --- ## Feature request diff --git a/.github/ISSUE_TEMPLATE/rule_request.md b/.github/ISSUE_TEMPLATE/rule_request.md index 2f43fafe48d..26e2a078909 100644 --- a/.github/ISSUE_TEMPLATE/rule_request.md +++ b/.github/ISSUE_TEMPLATE/rule_request.md @@ -1,7 +1,7 @@ --- name: Rule request ✍️ about: I have a suggestion about a new rule (and may want to implement it)! -label: kind/feature request +labels: kind/feature request --- ## Rule request diff --git a/.github/ISSUE_TEMPLATE/support_question.md b/.github/ISSUE_TEMPLATE/support_question.md index 3ca94bfa033..debc85118f3 100644 --- a/.github/ISSUE_TEMPLATE/support_question.md +++ b/.github/ISSUE_TEMPLATE/support_question.md @@ -1,7 +1,7 @@ --- name: Support question ❓ about: You have a question about how the tool works or how to use it. -label: kind/question +labels: kind/question --- ## Support question From 950c8a2b8975d4aca821462c9b9b550196088aad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kuba=20Wer=C5=82os?= Date: Sun, 21 Jun 2020 23:44:19 +0200 Subject: [PATCH 4/7] DX: add missing non-default code samples --- .../DoctrineAnnotationSpacesFixer.php | 4 ++++ .../PhpdocToReturnTypeFixer.php | 10 ++++++++++ .../PhpUnit/PhpUnitInternalClassFixer.php | 8 +++++++- src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php | 19 +++++++++++------- .../PhpUnitTestCaseStaticMethodCallsFixer.php | 15 +++++++------- .../GeneralPhpdocAnnotationRemoveFixer.php | 14 ++++++++++++- src/Fixer/Phpdoc/PhpdocScalarFixer.php | 20 +++++++++++++++++-- src/Fixer/Phpdoc/PhpdocTypesFixer.php | 10 ++++++++++ tests/AutoReview/FixerTest.php | 13 +++--------- 9 files changed, 85 insertions(+), 28 deletions(-) diff --git a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php index 86c6dce7e42..5ff458de406 100644 --- a/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php +++ b/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php @@ -38,6 +38,10 @@ public function getDefinition() new CodeSample( " false, 'before_array_assignments_equals' => false] + ), ], 'There must not be any space around parentheses; commas must be preceded by no space and followed by one space; there must be no space around named arguments assignment operator; there must be one space around array assignment operator.' ); diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index dda3fa27d69..f33ef8717e5 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -115,6 +115,16 @@ function my_foo() ', new VersionSpecification(70200) ), + new VersionSpecificCodeSample( + ' false] + ), ], null, 'This rule is EXPERIMENTAL and [1] is not covered with backward compatibility promise. [2] `@return` annotation is mandatory for the fixer to make changes, signatures of methods without it (no docblock, inheritdocs) will not be fixed. [3] Manual actions are required if inherited signatures are not properly documented. [4] `@inheritdocs` support is under construction.' diff --git a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php index bb0bf276b0a..b7018a9215d 100644 --- a/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitInternalClassFixer.php @@ -38,7 +38,13 @@ public function getDefinition() { return new FixerDefinition( 'All PHPUnit test classes should be marked as internal.', - [new CodeSample(" ['final']] + ), + ] ); } diff --git a/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php b/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php index a017279e5a9..2b0ba34a4a6 100644 --- a/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php @@ -49,16 +49,21 @@ final class PhpUnitNamespacedFixer extends AbstractFixer implements Configuratio */ public function getDefinition() { - return new FixerDefinition( - 'PHPUnit classes MUST be used in namespaced version, e.g. `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.', - [ - new CodeSample( - ' PhpUnitTargetVersion::VERSION_4_8]), ], "PHPUnit v6 has finally fully switched to namespaces.\n" ."You could start preparing the upgrade by switching from non-namespaced TestCase to namespaced one.\n" diff --git a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php index 1bdaf88b3e9..ca623c3fd13 100644 --- a/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php +++ b/src/Fixer/PhpUnit/PhpUnitTestCaseStaticMethodCallsFixer.php @@ -274,11 +274,7 @@ final class PhpUnitTestCaseStaticMethodCallsFixer extends AbstractFixer implemen */ public function getDefinition() { - return new FixerDefinition( - 'Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type, either `$this->`, `self::` or `static::`.', - [ - new CodeSample( - '`, `self::` or `static::`.', + [ + new CodeSample($codeSample), + new CodeSample($codeSample, ['call_type' => self::CALL_TYPE_THIS]), ], null, 'Risky when PHPUnit methods are overridden or not accessible, or when project has PHPUnit incompatibilities.' diff --git a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php index 17fa1a9c782..4e8025323ae 100644 --- a/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php +++ b/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php @@ -40,12 +40,24 @@ public function getDefinition() ' ['author']] ), + new CodeSample( + ' ['package', 'subpackage']] + ), ] ); } diff --git a/src/Fixer/Phpdoc/PhpdocScalarFixer.php b/src/Fixer/Phpdoc/PhpdocScalarFixer.php index 5119f1b73e4..75f2c4e08f4 100644 --- a/src/Fixer/Phpdoc/PhpdocScalarFixer.php +++ b/src/Fixer/Phpdoc/PhpdocScalarFixer.php @@ -46,7 +46,8 @@ public function getDefinition() { return new FixerDefinition( 'Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.', - [new CodeSample(' ['boolean']] + ), + ] ); } diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php index be894951490..ec3a55f2c34 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php @@ -98,6 +98,16 @@ public function getDefinition() */ ' ), + new CodeSample( + ' ['simple', 'alias']] + ), ] ); } diff --git a/tests/AutoReview/FixerTest.php b/tests/AutoReview/FixerTest.php index 6b3b12b6db6..2940a58fd76 100644 --- a/tests/AutoReview/FixerTest.php +++ b/tests/AutoReview/FixerTest.php @@ -133,17 +133,10 @@ public function testFixerDefinitions(AbstractFixer $fixer) static::assertArrayHasKey($fixerName, $this->allowedRequiredOptions, sprintf('[%s] Has no sample for default configuration.', $fixerName)); } - $fixerNamesWithKnownMissingSamplesWithConfig = [ - 'doctrine_annotation_spaces', - 'general_phpdoc_annotation_remove', - 'is_null', + // It may only shrink, never add anything to it. + $fixerNamesWithKnownMissingSamplesWithConfig = [ // @TODO 3.0 - remove this + 'is_null', // has only one option which is deprecated 'php_unit_dedicate_assert_internal_type', - 'php_unit_internal_class', - 'php_unit_namespaced', - 'php_unit_test_case_static_method_calls', - 'phpdoc_scalar', - 'phpdoc_to_return_type', - 'phpdoc_types', ]; if (\count($configSamplesProvided) < 2) { From 9c4120b9f75e6bd0e91a5d4d0ea812ecb7f0d328 Mon Sep 17 00:00:00 2001 From: Grzegorz Byrka Date: Sun, 14 Jun 2020 22:29:36 +0200 Subject: [PATCH 5/7] Enhancement: Social justification applied --- README.rst | 10 +++++----- src/Console/Command/HelpCommand.php | 6 +++--- src/Fixer/ClassNotation/FinalInternalClassFixer.php | 8 ++++---- .../ControlStructure/NoUnneededCurlyBracesFixer.php | 4 ++-- src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php | 4 ++-- src/Fixer/FunctionNotation/VoidReturnFixer.php | 4 ++-- .../ClassNotation/FinalInternalClassFixerTest.php | 2 +- .../FunctionNotation/PhpdocToReturnTypeFixerTest.php | 2 +- 8 files changed, 20 insertions(+), 20 deletions(-) diff --git a/README.rst b/README.rst index 3608d784711..20a7c62d09e 100644 --- a/README.rst +++ b/README.rst @@ -193,14 +193,14 @@ apply (the rule names must be separated by a comma): $ php php-cs-fixer.phar fix /path/to/dir --rules=line_ending,full_opening_tag,indentation_type -You can also blacklist the rules you don't want by placing a dash in front of the rule name, if this is more convenient, +You can also exclude the rules you don't want by placing a dash in front of the rule name, if this is more convenient, using ``-name_of_fixer``: .. code-block:: bash $ php php-cs-fixer.phar fix /path/to/dir --rules=-full_opening_tag,-indentation_type -When using combinations of exact and blacklist rules, applying exact rules along with above blacklisted results: +When using combinations of exact and exclude rules, applying exact rules along with above excluded results: .. code-block:: bash @@ -677,8 +677,8 @@ Choose from the list of available rules: Configuration options: - ``annotation-black-list`` (``array``): class level annotations tags that must be - omitted to fix the class, even if all of the white list ones are used - as well. (case insensitive); defaults to ``['@final', '@Entity', + omitted to fix the class, even if all of the excluded ones are used as + well. (case insensitive); defaults to ``['@final', '@Entity', '@ORM\\Entity', '@ORM\\Mapping\\Entity', '@Mapping\\Entity']`` - ``annotation-white-list`` (``array``): class level annotations tags that must be set in order to fix the class. (case insensitive); defaults to @@ -1972,7 +1972,7 @@ Both ``exclude`` and ``notPath`` methods accept only relative paths to the ones See `Symfony\\Finder `_ online documentation for other `Finder` methods. -You may also use a blacklist for the rules instead of the above shown whitelist approach. +You may also use an exclude list for the rules instead of the above shown include approach. The following example shows how to use all ``Symfony`` rules but the ``full_opening_tag`` rule. .. code-block:: php diff --git a/src/Console/Command/HelpCommand.php b/src/Console/Command/HelpCommand.php index 97f59fde659..ac0d836246e 100644 --- a/src/Console/Command/HelpCommand.php +++ b/src/Console/Command/HelpCommand.php @@ -94,12 +94,12 @@ public static function getHelpCopy() $ php %command.full_name% /path/to/dir --rules=line_ending,full_opening_tag,indentation_type -You can also blacklist the rules you don't want by placing a dash in front of the rule name, if this is more convenient, +You can also exclude the rules you don't want by placing a dash in front of the rule name, if this is more convenient, using -name_of_fixer: $ php %command.full_name% /path/to/dir --rules=-full_opening_tag,-indentation_type -When using combinations of exact and blacklist rules, applying exact rules along with above blacklisted results: +When using combinations of exact and exclude rules, applying exact rules along with above excluded results: $ php %command.full_name% /path/to/project --rules=@Symfony,-@PSR1,-blank_line_before_statement,strict_comparison @@ -203,7 +203,7 @@ public static function getHelpCopy() See `Symfony\Finder` (https://symfony.com/doc/current/components/finder.html) online documentation for other `Finder` methods. -You may also use a blacklist for the rules instead of the above shown whitelist approach. +You may also use an exclude list for the rules instead of the above shown include approach. The following example shows how to use all ``Symfony`` rules but the ``full_opening_tag`` rule. getName(), sprintf('Annotation cannot be used in both the white- and black list, got duplicates: "%s".', implode('", "', array_keys($intersect)))); + throw new InvalidFixerConfigurationException($this->getName(), sprintf('Annotation cannot be used in both the include and exclude list, got duplicates: "%s".', implode('", "', array_keys($intersect)))); } } @@ -152,7 +152,7 @@ protected function createConfigurationDefinition() ->setDefault(['@internal']) ->setNormalizer($annotationsNormalizer) ->getOption(), - (new FixerOptionBuilder('annotation-black-list', 'Class level annotations tags that must be omitted to fix the class, even if all of the white list ones are used as well. (case insensitive)')) + (new FixerOptionBuilder('annotation-black-list', 'Class level annotations tags that must be omitted to fix the class, even if all of the excluded ones are used as well. (case insensitive)')) ->setAllowedTypes(['array']) ->setAllowedValues($annotationsAsserts) ->setDefault([ @@ -196,7 +196,7 @@ private function isClassCandidate(Tokens $tokens, $index) $tag = strtolower(substr(array_shift($matches), 1)); foreach ($this->configuration['annotation-black-list'] as $tagStart => $true) { if (0 === strpos($tag, $tagStart)) { - return false; // ignore class: class-level PHPDoc contains tag that has been black listed through configuration + return false; // ignore class: class-level PHPDoc contains tag that has been excluded through configuration } } @@ -205,7 +205,7 @@ private function isClassCandidate(Tokens $tokens, $index) foreach ($this->configuration['annotation-white-list'] as $tag => $true) { if (!isset($tags[$tag])) { - return false; // ignore class: class-level PHPDoc does not contain all tags that has been white listed through configuration + return false; // ignore class: class-level PHPDoc does not contain all tags that has been included through configuration } } diff --git a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php index 3f3ccaaa5f0..b38d49657ba 100644 --- a/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php +++ b/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php @@ -131,9 +131,9 @@ private function findCurlyBraceOpen(Tokens $tokens) */ private function isOverComplete(Tokens $tokens, $index) { - static $whiteList = ['{', '}', [T_OPEN_TAG], ':', ';']; + static $include = ['{', '}', [T_OPEN_TAG], ':', ';']; - return $tokens[$tokens->getPrevMeaningfulToken($index)]->equalsAny($whiteList); + return $tokens[$tokens->getPrevMeaningfulToken($index)]->equalsAny($include); } private function clearIfIsOverCompleteNamespaceBlock(Tokens $tokens) diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index dda3fa27d69..d3d4cc7fd07 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -34,7 +34,7 @@ final class PhpdocToReturnTypeFixer extends AbstractFixer implements Configurati /** * @var array> */ - private $blacklistFuncNames = [ + private $excludeFuncNames = [ [T_STRING, '__construct'], [T_STRING, '__destruct'], [T_STRING, '__clone'], @@ -179,7 +179,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $funcName = $tokens->getNextMeaningfulToken($index); - if ($tokens[$funcName]->equalsAny($this->blacklistFuncNames, false)) { + if ($tokens[$funcName]->equalsAny($this->excludeFuncNames, false)) { continue; } diff --git a/src/Fixer/FunctionNotation/VoidReturnFixer.php b/src/Fixer/FunctionNotation/VoidReturnFixer.php index 9784d0f5728..8e468678318 100644 --- a/src/Fixer/FunctionNotation/VoidReturnFixer.php +++ b/src/Fixer/FunctionNotation/VoidReturnFixer.php @@ -78,7 +78,7 @@ public function isRisky() protected function applyFix(\SplFileInfo $file, Tokens $tokens) { // These cause syntax errors. - static $blacklistFuncNames = [ + static $excludeFuncNames = [ [T_STRING, '__construct'], [T_STRING, '__destruct'], [T_STRING, '__clone'], @@ -90,7 +90,7 @@ protected function applyFix(\SplFileInfo $file, Tokens $tokens) } $funcName = $tokens->getNextMeaningfulToken($index); - if ($tokens[$funcName]->equalsAny($blacklistFuncNames, false)) { + if ($tokens[$funcName]->equalsAny($excludeFuncNames, false)) { continue; } diff --git a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php index 38c08ee4542..d87a1970286 100644 --- a/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php +++ b/tests/Fixer/ClassNotation/FinalInternalClassFixerTest.php @@ -289,7 +289,7 @@ public function testConfigureSameAnnotationInBothLists() { $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class); $this->expectExceptionMessageRegExp( - sprintf('#^%s$#', preg_quote('[final_internal_class] Annotation cannot be used in both the white- and black list, got duplicates: "internal123".', '#')) + sprintf('#^%s$#', preg_quote('[final_internal_class] Annotation cannot be used in both the include and exclude list, got duplicates: "internal123".', '#')) ); $this->fixer->configure([ diff --git a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php index c95a4a49acb..3f0b7603f90 100644 --- a/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php +++ b/tests/Fixer/FunctionNotation/PhpdocToReturnTypeFixerTest.php @@ -69,7 +69,7 @@ public function provideFixCases() 'invalid class 5' => [ ' [ + 'excluded class methods' => [ ' Date: Mon, 15 Jun 2020 00:09:50 +0200 Subject: [PATCH 6/7] SimplifiedNullReturnFixer - must run before VoidReturnFixer --- .../FunctionNotation/VoidReturnFixer.php | 1 + .../SimplifiedNullReturnFixer.php | 4 ++-- tests/AutoReview/FixerFactoryTest.php | 1 + .../simplified_null_return,void_return.test | 23 +++++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 tests/Fixtures/Integration/priority/simplified_null_return,void_return.test diff --git a/src/Fixer/FunctionNotation/VoidReturnFixer.php b/src/Fixer/FunctionNotation/VoidReturnFixer.php index 9784d0f5728..47c60b1f7a7 100644 --- a/src/Fixer/FunctionNotation/VoidReturnFixer.php +++ b/src/Fixer/FunctionNotation/VoidReturnFixer.php @@ -50,6 +50,7 @@ public function getDefinition() * {@inheritdoc} * * Must run before PhpdocNoEmptyReturnFixer, ReturnTypeDeclarationFixer. + * Must run after SimplifiedNullReturnFixer. */ public function getPriority() { diff --git a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php index 486a9de4935..6b324ea5f1e 100644 --- a/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php +++ b/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php @@ -53,11 +53,11 @@ function xyz(): void { return null; } /** * {@inheritdoc} * - * Must run before NoUselessReturnFixer. + * Must run before NoUselessReturnFixer, VoidReturnFixer. */ public function getPriority() { - return -17; + return 16; } /** diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 894d19729df..22d67217d47 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -225,6 +225,7 @@ public function provideFixersPriorityCases() [$fixers['protected_to_private'], $fixers['ordered_class_elements']], [$fixers['return_assignment'], $fixers['blank_line_before_statement']], [$fixers['simplified_null_return'], $fixers['no_useless_return']], + [$fixers['simplified_null_return'], $fixers['void_return']], [$fixers['single_import_per_statement'], $fixers['multiline_whitespace_before_semicolons']], [$fixers['single_import_per_statement'], $fixers['no_leading_import_slash']], [$fixers['single_import_per_statement'], $fixers['no_singleline_whitespace_before_semicolons']], diff --git a/tests/Fixtures/Integration/priority/simplified_null_return,void_return.test b/tests/Fixtures/Integration/priority/simplified_null_return,void_return.test new file mode 100644 index 00000000000..1417d451d15 --- /dev/null +++ b/tests/Fixtures/Integration/priority/simplified_null_return,void_return.test @@ -0,0 +1,23 @@ +--TEST-- +Integration of fixers: simplified_null_return,void_return. +--RULESET-- +{"simplified_null_return": true, "void_return": true} +--REQUIREMENTS-- +{"php": 70100} +--EXPECT-- + Date: Mon, 15 Jun 2020 17:16:45 +0200 Subject: [PATCH 7/7] SingleClassElementPerStatementFixer - must run before ClassAttributesSeparationFixer --- .../ClassAttributesSeparationFixer.php | 2 +- .../SingleClassElementPerStatementFixer.php | 10 ++++++++++ tests/AutoReview/FixerFactoryTest.php | 1 + ...statement,class_attributes_separation.test | 19 +++++++++++++++++++ 4 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 tests/Fixtures/Integration/priority/single_class_element_per_statement,class_attributes_separation.test diff --git a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php index 2ab99bb8572..f9dbe264aea 100644 --- a/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php +++ b/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php @@ -106,7 +106,7 @@ class Sample * {@inheritdoc} * * Must run before BracesFixer, IndentationTypeFixer. - * Must run after OrderedClassElementsFixer. + * Must run after OrderedClassElementsFixer, SingleClassElementPerStatementFixer. */ public function getPriority() { diff --git a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php index d009bb4eedc..98b598e3da0 100644 --- a/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php +++ b/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php @@ -43,6 +43,16 @@ public function isCandidate(Tokens $tokens) return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds()); } + /** + * {@inheritdoc} + * + * Must run before ClassAttributesSeparationFixer. + */ + public function getPriority() + { + return 56; + } + /** * {@inheritdoc} */ diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 22d67217d47..75114dcff10 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -226,6 +226,7 @@ public function provideFixersPriorityCases() [$fixers['return_assignment'], $fixers['blank_line_before_statement']], [$fixers['simplified_null_return'], $fixers['no_useless_return']], [$fixers['simplified_null_return'], $fixers['void_return']], + [$fixers['single_class_element_per_statement'], $fixers['class_attributes_separation']], [$fixers['single_import_per_statement'], $fixers['multiline_whitespace_before_semicolons']], [$fixers['single_import_per_statement'], $fixers['no_leading_import_slash']], [$fixers['single_import_per_statement'], $fixers['no_singleline_whitespace_before_semicolons']], diff --git a/tests/Fixtures/Integration/priority/single_class_element_per_statement,class_attributes_separation.test b/tests/Fixtures/Integration/priority/single_class_element_per_statement,class_attributes_separation.test new file mode 100644 index 00000000000..e722f301ddb --- /dev/null +++ b/tests/Fixtures/Integration/priority/single_class_element_per_statement,class_attributes_separation.test @@ -0,0 +1,19 @@ +--TEST-- +Integration of fixers: single_class_element_per_statement,class_attributes_separation. +--RULESET-- +{"class_attributes_separation": true, "single_class_element_per_statement": true} +--EXPECT-- +