diff --git a/.dev-tools/src/Readme/ReadmeCommand.php b/.dev-tools/src/Readme/ReadmeCommand.php index 4d061f98..eb16a1ff 100644 --- a/.dev-tools/src/Readme/ReadmeCommand.php +++ b/.dev-tools/src/Readme/ReadmeCommand.php @@ -198,9 +198,19 @@ private function fixers(): string $fixer->configure(['force' => true]); } if ($fixer->isRisky()) { + $riskyDescription = $fixer->getDefinition()->getRiskyDescription(); + $starts = [ + 'Risky when' => 'when', + 'Fixer could be risky if' => 'when', + ]; + foreach ($starts as $from => $to) { + if (\str_starts_with($riskyDescription, $from)) { + $riskyDescription = $to . \substr($riskyDescription, \strlen($from)); + } + } $output .= \sprintf( "\n *Risky: %s.*", - $fixer->getDefinition()->getRiskyDescription(), + \lcfirst(\rtrim($riskyDescription, '.')), ); } if ($fixer instanceof DataProviderStaticFixer) { diff --git a/README.md b/README.md index d084d14b..d90a9044 100644 --- a/README.md +++ b/README.md @@ -94,10 +94,10 @@ Constructor's empty braces must be on a single line. #### DataProviderNameFixer Data provider names must match the name of the test. DEPRECATED: use `php_unit_data_provider_name` instead. - *Risky: when relying on name of data provider function.* + *Risky: when one is calling data provider by name as function.* Configuration options: - `prefix` (`string`): prefix that replaces "test"; defaults to `'provide'` -- `suffix` (`string`): suffix to be added at the end"; defaults to `'Cases'` +- `suffix` (`string`): suffix to be present at the end; defaults to `'Cases'` ```diff ` type must be used instead of `T[]`. DEPRECATED: use `phpdoc_array_type` instead. ```diff +- * @param int[] $x +- * @param string[][] $y ++ * @param array $x ++ * @param array> $y */ - function foo() { return [1, 2]; } ``` #### PhpdocNoIncorrectVarAnnotationFixer @@ -566,12 +567,14 @@ Orders all `@param` annotations in DocBlocks according to method signature. ```diff -+ * @param list +- * @param array $x +- * @param array> $y ++ * @param list $x ++ * @param list> $y */ - function foo($x) {} ``` #### PhpdocTypesCommaSpacesFixer diff --git a/src/Fixer/DataProviderNameFixer.php b/src/Fixer/DataProviderNameFixer.php index 17645fde..1dc228bb 100644 --- a/src/Fixer/DataProviderNameFixer.php +++ b/src/Fixer/DataProviderNameFixer.php @@ -14,29 +14,20 @@ use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderNameFixer; -use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; -use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; /** * @deprecated * - * @implements ConfigurableFixerInterface<_InputConfig, _Config> - * - * @phpstan-type _InputConfig array{prefix?: string, suffix?: string} - * @phpstan-type _Config array{prefix: string, suffix: string} + * @implements ConfigurableFixerInterface * * @no-named-arguments */ final class DataProviderNameFixer extends AbstractFixer implements ConfigurableFixerInterface, DeprecatedFixerInterface { private PhpUnitDataProviderNameFixer $phpUnitDataProviderNameFixer; - private string $prefix = 'provide'; - private string $suffix = 'Cases'; public function __construct() { @@ -45,38 +36,12 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - $this->phpUnitDataProviderNameFixer->getDefinition()->getSummary(), - [ - new CodeSample( - 'phpUnitDataProviderNameFixer->getDefinition(); } public function getConfigurationDefinition(): FixerConfigurationResolverInterface { - return new FixerConfigurationResolver([ - (new FixerOptionBuilder('prefix', 'prefix that replaces "test"')) - ->setAllowedTypes(['string']) - ->setDefault($this->prefix) - ->getOption(), - (new FixerOptionBuilder('suffix', 'suffix to be added at the end"')) - ->setAllowedTypes(['string']) - ->setDefault($this->suffix) - ->getOption(), - ]); + return $this->phpUnitDataProviderNameFixer->getConfigurationDefinition(); } public function configure(array $configuration): void @@ -104,9 +69,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->phpUnitDataProviderNameFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->phpUnitDataProviderNameFixer->getName()]; diff --git a/src/Fixer/DataProviderReturnTypeFixer.php b/src/Fixer/DataProviderReturnTypeFixer.php index 6bd86654..71d79e47 100644 --- a/src/Fixer/DataProviderReturnTypeFixer.php +++ b/src/Fixer/DataProviderReturnTypeFixer.php @@ -13,8 +13,6 @@ use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderReturnTypeFixer; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; @@ -34,24 +32,7 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - $this->phpUnitDataProviderReturnTypeFixer->getDefinition()->getSummary(), - [ - new CodeSample( - 'phpUnitDataProviderReturnTypeFixer->getDefinition(); } /** @@ -77,9 +58,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->phpUnitDataProviderReturnTypeFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->phpUnitDataProviderReturnTypeFixer->getName()]; diff --git a/src/Fixer/DataProviderStaticFixer.php b/src/Fixer/DataProviderStaticFixer.php index f44332fa..6cfeb763 100644 --- a/src/Fixer/DataProviderStaticFixer.php +++ b/src/Fixer/DataProviderStaticFixer.php @@ -14,27 +14,19 @@ use PhpCsFixer\Fixer\ConfigurableFixerInterface; use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\Fixer\PhpUnit\PhpUnitDataProviderStaticFixer; -use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver; use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface; -use PhpCsFixer\FixerConfiguration\FixerOptionBuilder; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; /** * @deprecated * - * @implements ConfigurableFixerInterface<_InputConfig, _Config> - * - * @phpstan-type _InputConfig array{force?: bool} - * @phpstan-type _Config array{force: bool} + * @implements ConfigurableFixerInterface * * @no-named-arguments */ final class DataProviderStaticFixer extends AbstractFixer implements ConfigurableFixerInterface, DeprecatedFixerInterface { - private bool $force = false; private PhpUnitDataProviderStaticFixer $phpUnitDataProviderStaticFixer; public function __construct() @@ -44,45 +36,17 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - $this->phpUnitDataProviderStaticFixer->getDefinition()->getSummary(), - [ - new CodeSample( - 'phpUnitDataProviderStaticFixer->getDefinition(); } public function getConfigurationDefinition(): FixerConfigurationResolverInterface { - return new FixerConfigurationResolver([ - (new FixerOptionBuilder('force', 'whether to make static data providers having dynamic class calls')) - ->setAllowedTypes(['bool']) - ->setDefault($this->force) - ->getOption(), - ]); + return $this->phpUnitDataProviderStaticFixer->getConfigurationDefinition(); } - /** - * @param array $configuration - */ public function configure(array $configuration): void { - if (\array_key_exists('force', $configuration)) { - $this->force = $configuration['force']; - } - $this->phpUnitDataProviderStaticFixer->configure(['force' => $this->force]); + $this->phpUnitDataProviderStaticFixer->configure($configuration); } public function getPriority(): int @@ -105,9 +69,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->phpUnitDataProviderStaticFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->phpUnitDataProviderStaticFixer->getName()]; diff --git a/src/Fixer/InternalClassCasingFixer.php b/src/Fixer/InternalClassCasingFixer.php index 42b03765..da964796 100644 --- a/src/Fixer/InternalClassCasingFixer.php +++ b/src/Fixer/InternalClassCasingFixer.php @@ -13,8 +13,6 @@ use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer; use PhpCsFixer\Fixer\DeprecatedFixerInterface; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; @@ -34,11 +32,7 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - 'Classes defined internally by an extension or the core must be referenced with the correct case.', - [new CodeSample("classReferenceNameCasingFixer->getDefinition(); } public function getPriority(): int @@ -61,9 +55,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->classReferenceNameCasingFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->classReferenceNameCasingFixer->getName()]; diff --git a/src/Fixer/MultilinePromotedPropertiesFixer.php b/src/Fixer/MultilinePromotedPropertiesFixer.php index df9bc4dd..ddef0080 100644 --- a/src/Fixer/MultilinePromotedPropertiesFixer.php +++ b/src/Fixer/MultilinePromotedPropertiesFixer.php @@ -23,10 +23,7 @@ /** * @deprecated * - * @implements ConfigurableFixerInterface<_InputConfig, _Config> - * - * @phpstan-type _InputConfig array{keep_blank_lines?: bool, minimum_number_of_parameters?: int} - * @phpstan-type _Config array{keep_blank_lines: bool, minimum_number_of_parameters: int} + * @implements ConfigurableFixerInterface * * @no-named-arguments */ @@ -49,9 +46,6 @@ public function getConfigurationDefinition(): FixerConfigurationResolverInterfac return $this->multilinePromotedPropertiesFixer->getConfigurationDefinition(); } - /** - * @param array{minimum_number_of_parameters?: int, keep_blank_lines?: bool} $configuration - */ public function configure(array $configuration): void { $this->multilinePromotedPropertiesFixer->configure($configuration); @@ -86,9 +80,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->multilinePromotedPropertiesFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->multilinePromotedPropertiesFixer->getName()]; diff --git a/src/Fixer/PhpdocArrayStyleFixer.php b/src/Fixer/PhpdocArrayStyleFixer.php index c452d8f5..35cc14c0 100644 --- a/src/Fixer/PhpdocArrayStyleFixer.php +++ b/src/Fixer/PhpdocArrayStyleFixer.php @@ -13,8 +13,6 @@ use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\Fixer\Phpdoc\PhpdocArrayTypeFixer; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; @@ -34,20 +32,7 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - 'Generic array style should be used in PHPDoc.', - [ - new CodeSample( - 'phpdocArrayTypeFixer->getDefinition(); } /** @@ -73,9 +58,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->phpdocArrayTypeFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->phpdocArrayTypeFixer->getName()]; diff --git a/src/Fixer/PhpdocParamOrderFixer.php b/src/Fixer/PhpdocParamOrderFixer.php index 492172a2..e005b481 100644 --- a/src/Fixer/PhpdocParamOrderFixer.php +++ b/src/Fixer/PhpdocParamOrderFixer.php @@ -12,8 +12,6 @@ namespace PhpCsFixerCustomFixers\Fixer; use PhpCsFixer\Fixer\DeprecatedFixerInterface; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; @@ -33,18 +31,7 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - $this->phpdocParamOrderFixer->getDefinition()->getSummary(), - [new CodeSample('phpdocParamOrderFixer->getDefinition(); } /** @@ -71,9 +58,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->phpdocParamOrderFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->phpdocParamOrderFixer->getName()]; diff --git a/src/Fixer/PhpdocTypeListFixer.php b/src/Fixer/PhpdocTypeListFixer.php index b05b3beb..02ef22aa 100644 --- a/src/Fixer/PhpdocTypeListFixer.php +++ b/src/Fixer/PhpdocTypeListFixer.php @@ -13,8 +13,6 @@ use PhpCsFixer\Fixer\DeprecatedFixerInterface; use PhpCsFixer\Fixer\Phpdoc\PhpdocListTypeFixer; -use PhpCsFixer\FixerDefinition\CodeSample; -use PhpCsFixer\FixerDefinition\FixerDefinition; use PhpCsFixer\FixerDefinition\FixerDefinitionInterface; use PhpCsFixer\Tokenizer\Tokens; @@ -34,16 +32,7 @@ public function __construct() public function getDefinition(): FixerDefinitionInterface { - return new FixerDefinition( - 'PHPDoc type `list` must be used instead of `array` without a key type.', - [new CodeSample(' - */ -function foo($x) {} -')], - '', - ); + return $this->phpdocListTypeFixer->getDefinition(); } /** @@ -52,7 +41,7 @@ function foo($x) {} */ public function getPriority(): int { - return 1; + return $this->phpdocListTypeFixer->getPriority(); } public function isCandidate(Tokens $tokens): bool @@ -70,9 +59,6 @@ public function fix(\SplFileInfo $file, Tokens $tokens): void $this->phpdocListTypeFixer->fix($file, $tokens); } - /** - * @return list - */ public function getSuccessorsNames(): array { return [$this->phpdocListTypeFixer->getName()]; diff --git a/tests/Fixer/AbstractFixerTestCase.php b/tests/Fixer/AbstractFixerTestCase.php index 6f9fb62f..c41bcf50 100644 --- a/tests/Fixer/AbstractFixerTestCase.php +++ b/tests/Fixer/AbstractFixerTestCase.php @@ -55,7 +55,7 @@ final public function testFixerDefinitionSummaryStartWithCorrectCase(): void final public function testFixerDefinitionRiskyDescriptionStartWithLowercase(): void { - if (!self::getFixer()->isRisky()) { + if (self::getFixer() instanceof DeprecatedFixerInterface || !self::getFixer()->isRisky()) { $this->expectNotToPerformAssertions(); return; @@ -69,7 +69,7 @@ final public function testFixerDefinitionRiskyDescriptionStartWithLowercase(): v final public function testFixerDefinitionRiskyDescriptionDoesNotEndWithDot(): void { - if (!self::getFixer()->isRisky()) { + if (self::getFixer() instanceof DeprecatedFixerInterface || !self::getFixer()->isRisky()) { $this->expectNotToPerformAssertions(); return;