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] 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) {