From b406a9dee319ce2c818c4546990f5b8a5f7cf80b Mon Sep 17 00:00:00 2001 From: SpacePossum Date: Tue, 11 Jan 2022 17:18:55 +0100 Subject: [PATCH] Fix priority descriptions and tests. --- src/Fixer/Comment/CommentToPhpdocFixer.php | 2 +- .../PhpdocToReturnTypeFixer.php | 2 +- .../Phpdoc/AlignMultilineCommentFixer.php | 2 +- .../PhpdocAddMissingParamAnnotationFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocIndentFixer.php | 2 +- .../Phpdoc/PhpdocNoUselessInheritdocFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocScalarFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocToCommentFixer.php | 2 +- ...rimConsecutiveBlankLineSeparationFixer.php | 2 +- src/Fixer/Phpdoc/PhpdocTypesFixer.php | 2 +- tests/AutoReview/FixerFactoryTest.php | 1196 +++++++++-------- 11 files changed, 680 insertions(+), 536 deletions(-) diff --git a/src/Fixer/Comment/CommentToPhpdocFixer.php b/src/Fixer/Comment/CommentToPhpdocFixer.php index b887b18757a..9d5df5a131a 100644 --- a/src/Fixer/Comment/CommentToPhpdocFixer.php +++ b/src/Fixer/Comment/CommentToPhpdocFixer.php @@ -58,7 +58,7 @@ public function isRisky(): bool /** * {@inheritdoc} * - * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToCommentFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. + * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToCommentFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. * Must run after AlignMultilineCommentFixer. */ public function getPriority(): int diff --git a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php index e31f247e5a9..1c7584692e8 100644 --- a/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php +++ b/src/Fixer/FunctionNotation/PhpdocToReturnTypeFixer.php @@ -121,7 +121,7 @@ public function isCandidate(Tokens $tokens): bool * {@inheritdoc} * * Must run before FullyQualifiedStrictTypesFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAlignFixer, ReturnTypeDeclarationFixer. - * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer, PhpdocTypesFixer. + * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php b/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php index 01f2d4b6cb4..16872747cf1 100644 --- a/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php +++ b/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php @@ -93,7 +93,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run before CommentToPhpdocFixer, GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. + * Must run before CommentToPhpdocFixer, GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. * Must run after ArrayIndentationFixer. */ public function getPriority(): int diff --git a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php index 98404d46ade..38e627816f2 100644 --- a/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php @@ -82,7 +82,7 @@ function f9(string $foo, $bar, $baz) {} /** * {@inheritdoc} * - * Must run before NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAlignFixer, PhpdocAlignFixer, PhpdocOrderFixer. + * Must run before NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAlignFixer, PhpdocOrderFixer. * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, GeneralPhpdocTagRenameFixer, PhpdocIndentFixer, PhpdocNoAliasTagFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer. */ public function getPriority(): int diff --git a/src/Fixer/Phpdoc/PhpdocIndentFixer.php b/src/Fixer/Phpdoc/PhpdocIndentFixer.php index 687aa54d19e..d926dbbff10 100644 --- a/src/Fixer/Phpdoc/PhpdocIndentFixer.php +++ b/src/Fixer/Phpdoc/PhpdocIndentFixer.php @@ -51,7 +51,7 @@ class DocBlocks /** * {@inheritdoc} * - * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. + * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. * Must run after IndentationTypeFixer, PhpdocToCommentFixer. */ public function getPriority(): int diff --git a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php index ef99675ffbe..65d420fab09 100644 --- a/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php +++ b/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php @@ -46,7 +46,7 @@ public function getDefinition(): FixerDefinitionInterface * {@inheritdoc} * * Must run before NoEmptyPhpdocFixer, NoTrailingWhitespaceInCommentFixer, PhpdocAlignFixer. - * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocToCommentFixer, PhpdocTypesFixer. + * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Phpdoc/PhpdocScalarFixer.php b/src/Fixer/Phpdoc/PhpdocScalarFixer.php index cbfdfe65771..140b6d67495 100644 --- a/src/Fixer/Phpdoc/PhpdocScalarFixer.php +++ b/src/Fixer/Phpdoc/PhpdocScalarFixer.php @@ -85,7 +85,7 @@ function sample($a, $b, $c) /** * {@inheritdoc} * - * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAlignFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. + * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. * Must run after PhpdocTypesFixer. */ public function getPriority(): int diff --git a/src/Fixer/Phpdoc/PhpdocToCommentFixer.php b/src/Fixer/Phpdoc/PhpdocToCommentFixer.php index b335b4019a8..49b55e3e5d8 100644 --- a/src/Fixer/Phpdoc/PhpdocToCommentFixer.php +++ b/src/Fixer/Phpdoc/PhpdocToCommentFixer.php @@ -49,7 +49,7 @@ public function isCandidate(Tokens $tokens): bool /** * {@inheritdoc} * - * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. + * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyCommentFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. * Must run after CommentToPhpdocFixer. */ public function getPriority(): int diff --git a/src/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixer.php b/src/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixer.php index bb721040104..3d41bdb859b 100644 --- a/src/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTrimConsecutiveBlankLineSeparationFixer.php @@ -66,7 +66,7 @@ function fnc($foo) {} * {@inheritdoc} * * Must run before PhpdocAlignFixer. - * Must run after AlignMultilineCommentFixer, AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer. + * Must run after AlignMultilineCommentFixer, CommentToPhpdocFixer, PhpdocIndentFixer, PhpdocScalarFixer, PhpdocToCommentFixer, PhpdocTypesFixer. */ public function getPriority(): int { diff --git a/src/Fixer/Phpdoc/PhpdocTypesFixer.php b/src/Fixer/Phpdoc/PhpdocTypesFixer.php index 415f6066f05..4ecef2c22f4 100644 --- a/src/Fixer/Phpdoc/PhpdocTypesFixer.php +++ b/src/Fixer/Phpdoc/PhpdocTypesFixer.php @@ -133,7 +133,7 @@ public function getDefinition(): FixerDefinitionInterface /** * {@inheritdoc} * - * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocAlignFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocScalarFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. + * Must run before GeneralPhpdocAnnotationRemoveFixer, GeneralPhpdocTagRenameFixer, NoBlankLinesAfterPhpdocFixer, NoEmptyPhpdocFixer, NoSuperfluousPhpdocTagsFixer, PhpdocAddMissingParamAnnotationFixer, PhpdocAlignFixer, PhpdocInlineTagNormalizerFixer, PhpdocLineSpanFixer, PhpdocNoAccessFixer, PhpdocNoAliasTagFixer, PhpdocNoEmptyReturnFixer, PhpdocNoPackageFixer, PhpdocNoUselessInheritdocFixer, PhpdocOrderByValueFixer, PhpdocOrderFixer, PhpdocReturnSelfReferenceFixer, PhpdocScalarFixer, PhpdocSeparationFixer, PhpdocSingleLineVarSpacingFixer, PhpdocSummaryFixer, PhpdocTagCasingFixer, PhpdocTagTypeFixer, PhpdocToParamTypeFixer, PhpdocToPropertyTypeFixer, PhpdocToReturnTypeFixer, PhpdocTrimConsecutiveBlankLineSeparationFixer, PhpdocTrimFixer, PhpdocTypesOrderFixer, PhpdocVarAnnotationCorrectOrderFixer, PhpdocVarWithoutNameFixer. * Must run after PhpdocAnnotationWithoutDotFixer, PhpdocIndentFixer. */ public function getPriority(): int diff --git a/tests/AutoReview/FixerFactoryTest.php b/tests/AutoReview/FixerFactoryTest.php index 15ba96e6da0..ddbe087353e 100644 --- a/tests/AutoReview/FixerFactoryTest.php +++ b/tests/AutoReview/FixerFactoryTest.php @@ -46,575 +46,182 @@ public function testFixersPriorityEdgeFixers(): void } } - /** - * @dataProvider provideFixersPriorityCases - * @dataProvider provideFixersPrioritySpecialPhpdocCases - */ - public function testFixersPriority(FixerInterface $first, FixerInterface $second): void - { - static::assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', \get_class($second), \get_class($first))); - } - - public function provideFixersPriorityCases(): array + public function testFixersPriority(): void { - $factory = new FixerFactory(); - $factory->registerBuiltInFixers(); - - $fixers = []; - - foreach ($factory->getFixers() as $fixer) { - $fixers[$fixer->getName()] = $fixer; - } + $fixers = self::getAllFixers(); - return [ - [$fixers['align_multiline_comment'], $fixers['phpdoc_trim_consecutive_blank_line_separation']], - [$fixers['array_indentation'], $fixers['align_multiline_comment']], - [$fixers['array_indentation'], $fixers['binary_operator_spaces']], - [$fixers['array_syntax'], $fixers['binary_operator_spaces']], - [$fixers['array_syntax'], $fixers['ternary_operator_spaces']], - [$fixers['assign_null_coalescing_to_coalesce_equal'], $fixers['binary_operator_spaces']], - [$fixers['assign_null_coalescing_to_coalesce_equal'], $fixers['no_whitespace_in_blank_line']], - [$fixers['backtick_to_shell_exec'], $fixers['escape_implicit_backslashes']], - [$fixers['backtick_to_shell_exec'], $fixers['explicit_string_variable']], - [$fixers['backtick_to_shell_exec'], $fixers['native_function_invocation']], - [$fixers['backtick_to_shell_exec'], $fixers['single_quote']], - [$fixers['blank_line_after_opening_tag'], $fixers['no_blank_lines_before_namespace']], - [$fixers['braces'], $fixers['array_indentation']], - [$fixers['braces'], $fixers['method_argument_space']], - [$fixers['braces'], $fixers['method_chaining_indentation']], - [$fixers['class_attributes_separation'], $fixers['braces']], - [$fixers['class_attributes_separation'], $fixers['indentation_type']], - [$fixers['class_attributes_separation'], $fixers['no_extra_blank_lines']], - [$fixers['class_definition'], $fixers['braces']], - [$fixers['class_keyword_remove'], $fixers['no_unused_imports']], - [$fixers['combine_consecutive_issets'], $fixers['multiline_whitespace_before_semicolons']], - [$fixers['combine_consecutive_issets'], $fixers['no_singleline_whitespace_before_semicolons']], - [$fixers['combine_consecutive_issets'], $fixers['no_spaces_inside_parenthesis']], - [$fixers['combine_consecutive_issets'], $fixers['no_trailing_whitespace']], - [$fixers['combine_consecutive_issets'], $fixers['no_whitespace_in_blank_line']], - [$fixers['combine_consecutive_unsets'], $fixers['no_extra_blank_lines']], - [$fixers['combine_consecutive_unsets'], $fixers['no_trailing_whitespace']], - [$fixers['combine_consecutive_unsets'], $fixers['no_whitespace_in_blank_line']], - [$fixers['combine_consecutive_unsets'], $fixers['space_after_semicolon']], - [$fixers['combine_nested_dirname'], $fixers['method_argument_space']], - [$fixers['combine_nested_dirname'], $fixers['no_spaces_inside_parenthesis']], - [$fixers['declare_strict_types'], $fixers['blank_line_after_opening_tag']], - [$fixers['declare_strict_types'], $fixers['declare_equal_normalize']], - [$fixers['declare_strict_types'], $fixers['header_comment']], - [$fixers['dir_constant'], $fixers['combine_nested_dirname']], - [$fixers['doctrine_annotation_array_assignment'], $fixers['doctrine_annotation_spaces']], - [$fixers['echo_tag_syntax'], $fixers['no_mixed_echo_print']], - [$fixers['elseif'], $fixers['braces']], - [$fixers['empty_loop_body'], $fixers['braces']], - [$fixers['empty_loop_body'], $fixers['no_extra_blank_lines']], - [$fixers['empty_loop_body'], $fixers['no_trailing_whitespace']], - [$fixers['empty_loop_condition'], $fixers['no_extra_blank_lines']], - [$fixers['empty_loop_condition'], $fixers['no_trailing_whitespace']], - [$fixers['escape_implicit_backslashes'], $fixers['heredoc_to_nowdoc']], - [$fixers['escape_implicit_backslashes'], $fixers['single_quote']], - [$fixers['explicit_string_variable'], $fixers['simple_to_complex_string_variable']], - [$fixers['final_internal_class'], $fixers['protected_to_private']], - [$fixers['final_internal_class'], $fixers['self_static_accessor']], - [$fixers['fully_qualified_strict_types'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['function_declaration'], $fixers['method_argument_space']], - [$fixers['function_to_constant'], $fixers['native_function_casing']], - [$fixers['function_to_constant'], $fixers['no_extra_blank_lines']], - [$fixers['function_to_constant'], $fixers['no_singleline_whitespace_before_semicolons']], - [$fixers['function_to_constant'], $fixers['no_trailing_whitespace']], - [$fixers['function_to_constant'], $fixers['no_whitespace_in_blank_line']], - [$fixers['function_to_constant'], $fixers['self_static_accessor']], - [$fixers['general_phpdoc_annotation_remove'], $fixers['no_empty_phpdoc']], - [$fixers['general_phpdoc_annotation_remove'], $fixers['phpdoc_line_span']], - [$fixers['general_phpdoc_annotation_remove'], $fixers['phpdoc_separation']], - [$fixers['general_phpdoc_annotation_remove'], $fixers['phpdoc_trim']], - [$fixers['general_phpdoc_tag_rename'], $fixers['phpdoc_add_missing_param_annotation']], - [$fixers['get_class_to_class_keyword'], $fixers['multiline_whitespace_before_semicolons']], - [$fixers['global_namespace_import'], $fixers['no_unused_imports']], - [$fixers['global_namespace_import'], $fixers['ordered_imports']], - [$fixers['header_comment'], $fixers['single_line_comment_style']], - [$fixers['implode_call'], $fixers['method_argument_space']], - [$fixers['indentation_type'], $fixers['phpdoc_indent']], - [$fixers['is_null'], $fixers['yoda_style']], - [$fixers['lambda_not_used_import'], $fixers['no_spaces_inside_parenthesis']], - [$fixers['line_ending'], $fixers['braces']], - [$fixers['list_syntax'], $fixers['binary_operator_spaces']], - [$fixers['list_syntax'], $fixers['ternary_operator_spaces']], - [$fixers['method_argument_space'], $fixers['array_indentation']], - [$fixers['method_chaining_indentation'], $fixers['array_indentation']], - [$fixers['method_chaining_indentation'], $fixers['method_argument_space']], - [$fixers['modernize_strpos'], $fixers['binary_operator_spaces']], - [$fixers['modernize_strpos'], $fixers['no_extra_blank_lines']], - [$fixers['modernize_strpos'], $fixers['no_spaces_inside_parenthesis']], - [$fixers['modernize_strpos'], $fixers['no_trailing_whitespace']], - [$fixers['modernize_strpos'], $fixers['not_operator_with_space']], - [$fixers['modernize_strpos'], $fixers['not_operator_with_successor_space']], - [$fixers['modernize_strpos'], $fixers['php_unit_dedicate_assert']], - [$fixers['modernize_strpos'], $fixers['single_space_after_construct']], - [$fixers['multiline_whitespace_before_semicolons'], $fixers['space_after_semicolon']], - [$fixers['native_constant_invocation'], $fixers['global_namespace_import']], - [$fixers['native_function_invocation'], $fixers['global_namespace_import']], - [$fixers['new_with_braces'], $fixers['class_definition']], - [$fixers['no_alias_functions'], $fixers['implode_call']], - [$fixers['no_alias_functions'], $fixers['php_unit_dedicate_assert']], - [$fixers['no_alternative_syntax'], $fixers['braces']], - [$fixers['no_alternative_syntax'], $fixers['elseif']], - [$fixers['no_alternative_syntax'], $fixers['no_superfluous_elseif']], - [$fixers['no_alternative_syntax'], $fixers['no_useless_else']], - [$fixers['no_alternative_syntax'], $fixers['switch_continue_to_break']], - [$fixers['no_blank_lines_after_phpdoc'], $fixers['header_comment']], - [$fixers['no_empty_comment'], $fixers['no_extra_blank_lines']], - [$fixers['no_empty_comment'], $fixers['no_trailing_whitespace']], - [$fixers['no_empty_comment'], $fixers['no_whitespace_in_blank_line']], - [$fixers['no_empty_phpdoc'], $fixers['no_extra_blank_lines']], - [$fixers['no_empty_phpdoc'], $fixers['no_trailing_whitespace']], - [$fixers['no_empty_phpdoc'], $fixers['no_whitespace_in_blank_line']], - [$fixers['no_empty_statement'], $fixers['braces']], - [$fixers['no_empty_statement'], $fixers['combine_consecutive_unsets']], - [$fixers['no_empty_statement'], $fixers['empty_loop_body']], - [$fixers['no_empty_statement'], $fixers['multiline_whitespace_before_semicolons']], - [$fixers['no_empty_statement'], $fixers['no_extra_blank_lines']], - [$fixers['no_empty_statement'], $fixers['no_singleline_whitespace_before_semicolons']], - [$fixers['no_empty_statement'], $fixers['no_trailing_whitespace']], - [$fixers['no_empty_statement'], $fixers['no_useless_else']], - [$fixers['no_empty_statement'], $fixers['no_useless_return']], - [$fixers['no_empty_statement'], $fixers['no_whitespace_in_blank_line']], - [$fixers['no_empty_statement'], $fixers['return_assignment']], - [$fixers['no_empty_statement'], $fixers['space_after_semicolon']], - [$fixers['no_empty_statement'], $fixers['switch_case_semicolon_to_colon']], - [$fixers['no_extra_blank_lines'], $fixers['blank_line_before_statement']], - [$fixers['no_leading_import_slash'], $fixers['ordered_imports']], - [$fixers['no_multiline_whitespace_around_double_arrow'], $fixers['binary_operator_spaces']], - [$fixers['no_multiline_whitespace_around_double_arrow'], $fixers['method_argument_space']], - [$fixers['no_multiline_whitespace_around_double_arrow'], $fixers['trailing_comma_in_multiline']], - [$fixers['no_php4_constructor'], $fixers['ordered_class_elements']], - [$fixers['no_short_bool_cast'], $fixers['cast_spaces']], - [$fixers['no_spaces_after_function_name'], $fixers['function_to_constant']], - [$fixers['no_spaces_after_function_name'], $fixers['get_class_to_class_keyword']], - [$fixers['no_spaces_inside_parenthesis'], $fixers['function_to_constant']], - [$fixers['no_spaces_inside_parenthesis'], $fixers['get_class_to_class_keyword']], - [$fixers['no_spaces_inside_parenthesis'], $fixers['string_length_to_empty']], - [$fixers['no_superfluous_elseif'], $fixers['simplified_if_return']], - [$fixers['no_superfluous_phpdoc_tags'], $fixers['no_empty_phpdoc']], - [$fixers['no_superfluous_phpdoc_tags'], $fixers['void_return']], - [$fixers['no_unneeded_control_parentheses'], $fixers['no_trailing_whitespace']], - [$fixers['no_unneeded_curly_braces'], $fixers['no_useless_else']], - [$fixers['no_unneeded_curly_braces'], $fixers['no_useless_return']], - [$fixers['no_unneeded_curly_braces'], $fixers['return_assignment']], - [$fixers['no_unneeded_curly_braces'], $fixers['simplified_if_return']], - [$fixers['no_unset_cast'], $fixers['binary_operator_spaces']], - [$fixers['no_unset_on_property'], $fixers['combine_consecutive_unsets']], - [$fixers['no_unused_imports'], $fixers['blank_line_after_namespace']], - [$fixers['no_unused_imports'], $fixers['no_extra_blank_lines']], - [$fixers['no_unused_imports'], $fixers['no_leading_import_slash']], - [$fixers['no_unused_imports'], $fixers['single_line_after_imports']], - [$fixers['no_useless_else'], $fixers['braces']], - [$fixers['no_useless_else'], $fixers['combine_consecutive_unsets']], - [$fixers['no_useless_else'], $fixers['no_break_comment']], - [$fixers['no_useless_else'], $fixers['no_extra_blank_lines']], - [$fixers['no_useless_else'], $fixers['no_trailing_whitespace']], - [$fixers['no_useless_else'], $fixers['no_useless_return']], - [$fixers['no_useless_else'], $fixers['no_whitespace_in_blank_line']], - [$fixers['no_useless_else'], $fixers['simplified_if_return']], - [$fixers['no_useless_return'], $fixers['blank_line_before_statement']], - [$fixers['no_useless_return'], $fixers['no_extra_blank_lines']], - [$fixers['no_useless_return'], $fixers['no_whitespace_in_blank_line']], - [$fixers['no_useless_return'], $fixers['single_line_comment_style']], - [$fixers['no_useless_sprintf'], $fixers['method_argument_space']], - [$fixers['no_useless_sprintf'], $fixers['native_function_casing']], - [$fixers['no_useless_sprintf'], $fixers['no_empty_statement']], - [$fixers['no_useless_sprintf'], $fixers['no_extra_blank_lines']], - [$fixers['no_useless_sprintf'], $fixers['no_spaces_inside_parenthesis']], - [$fixers['nullable_type_declaration_for_default_null_value'], $fixers['no_unreachable_default_argument_value']], - [$fixers['ordered_class_elements'], $fixers['class_attributes_separation']], - [$fixers['ordered_class_elements'], $fixers['no_blank_lines_after_class_opening']], - [$fixers['ordered_class_elements'], $fixers['space_after_semicolon']], - [$fixers['php_unit_construct'], $fixers['php_unit_dedicate_assert']], - [$fixers['php_unit_dedicate_assert'], $fixers['no_unused_imports']], - [$fixers['php_unit_dedicate_assert'], $fixers['php_unit_dedicate_assert_internal_type']], - [$fixers['php_unit_fqcn_annotation'], $fixers['no_unused_imports']], - [$fixers['php_unit_fqcn_annotation'], $fixers['phpdoc_order_by_value']], - [$fixers['php_unit_internal_class'], $fixers['final_internal_class']], - [$fixers['php_unit_no_expectation_annotation'], $fixers['no_empty_phpdoc']], - [$fixers['php_unit_no_expectation_annotation'], $fixers['php_unit_expectation']], - [$fixers['php_unit_test_annotation'], $fixers['no_empty_phpdoc']], - [$fixers['php_unit_test_annotation'], $fixers['php_unit_method_casing']], - [$fixers['php_unit_test_annotation'], $fixers['phpdoc_trim']], - [$fixers['php_unit_test_case_static_method_calls'], $fixers['self_static_accessor']], - [$fixers['phpdoc_add_missing_param_annotation'], $fixers['no_empty_phpdoc']], - [$fixers['phpdoc_add_missing_param_annotation'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['phpdoc_add_missing_param_annotation'], $fixers['phpdoc_align']], - [$fixers['phpdoc_add_missing_param_annotation'], $fixers['phpdoc_order']], - [$fixers['phpdoc_annotation_without_dot'], $fixers['phpdoc_types']], - [$fixers['phpdoc_annotation_without_dot'], $fixers['phpdoc_types_order']], - [$fixers['phpdoc_line_span'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['phpdoc_no_access'], $fixers['no_empty_phpdoc']], - [$fixers['phpdoc_no_access'], $fixers['phpdoc_separation']], - [$fixers['phpdoc_no_access'], $fixers['phpdoc_trim']], - [$fixers['phpdoc_no_alias_tag'], $fixers['phpdoc_add_missing_param_annotation']], - [$fixers['phpdoc_no_alias_tag'], $fixers['phpdoc_single_line_var_spacing']], - [$fixers['phpdoc_no_empty_return'], $fixers['no_empty_phpdoc']], - [$fixers['phpdoc_no_empty_return'], $fixers['phpdoc_order']], - [$fixers['phpdoc_no_empty_return'], $fixers['phpdoc_separation']], - [$fixers['phpdoc_no_empty_return'], $fixers['phpdoc_trim']], - [$fixers['phpdoc_no_package'], $fixers['no_empty_phpdoc']], - [$fixers['phpdoc_no_package'], $fixers['phpdoc_separation']], - [$fixers['phpdoc_no_package'], $fixers['phpdoc_trim']], - [$fixers['phpdoc_no_useless_inheritdoc'], $fixers['no_empty_phpdoc']], - [$fixers['phpdoc_no_useless_inheritdoc'], $fixers['no_trailing_whitespace_in_comment']], - [$fixers['phpdoc_order'], $fixers['phpdoc_separation']], - [$fixers['phpdoc_order'], $fixers['phpdoc_trim']], - [$fixers['phpdoc_return_self_reference'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['phpdoc_scalar'], $fixers['phpdoc_to_return_type']], - [$fixers['phpdoc_to_comment'], $fixers['no_empty_comment']], - [$fixers['phpdoc_to_comment'], $fixers['phpdoc_no_useless_inheritdoc']], - [$fixers['phpdoc_to_param_type'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['phpdoc_to_property_type'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['phpdoc_to_return_type'], $fixers['fully_qualified_strict_types']], - [$fixers['phpdoc_to_return_type'], $fixers['no_superfluous_phpdoc_tags']], - [$fixers['phpdoc_to_return_type'], $fixers['return_type_declaration']], - [$fixers['phpdoc_types'], $fixers['phpdoc_to_return_type']], - [$fixers['pow_to_exponentiation'], $fixers['binary_operator_spaces']], - [$fixers['pow_to_exponentiation'], $fixers['method_argument_space']], - [$fixers['pow_to_exponentiation'], $fixers['native_function_casing']], - [$fixers['pow_to_exponentiation'], $fixers['no_spaces_after_function_name']], - [$fixers['pow_to_exponentiation'], $fixers['no_spaces_inside_parenthesis']], - [$fixers['protected_to_private'], $fixers['ordered_class_elements']], - [$fixers['regular_callable_call'], $fixers['native_function_invocation']], - [$fixers['return_assignment'], $fixers['blank_line_before_statement']], - [$fixers['semicolon_after_instruction'], $fixers['simplified_if_return']], - [$fixers['simplified_if_return'], $fixers['multiline_whitespace_before_semicolons']], - [$fixers['simplified_if_return'], $fixers['no_singleline_whitespace_before_semicolons']], - [$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']], - [$fixers['single_import_per_statement'], $fixers['no_unused_imports']], - [$fixers['single_import_per_statement'], $fixers['space_after_semicolon']], - [$fixers['single_line_throw'], $fixers['braces']], - [$fixers['single_line_throw'], $fixers['concat_space']], - [$fixers['single_space_after_construct'], $fixers['braces']], - [$fixers['single_space_after_construct'], $fixers['function_declaration']], - [$fixers['single_trait_insert_per_statement'], $fixers['braces']], - [$fixers['single_trait_insert_per_statement'], $fixers['space_after_semicolon']], - [$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['method_argument_space']], - [$fixers['strict_param'], $fixers['native_function_invocation']], - [$fixers['string_length_to_empty'], $fixers['no_extra_blank_lines']], - [$fixers['string_length_to_empty'], $fixers['no_trailing_whitespace']], - [$fixers['ternary_to_elvis_operator'], $fixers['no_trailing_whitespace']], - [$fixers['ternary_to_elvis_operator'], $fixers['ternary_operator_spaces']], - [$fixers['ternary_to_null_coalescing'], $fixers['assign_null_coalescing_to_coalesce_equal']], - [$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']], - [$fixers['void_return'], $fixers['return_type_declaration']], + $graphs = [ + self::getFixersPriorityGraph(), + self::getPhpDocFixersPriorityGraph(), ]; - } - - public function provideFixersPrioritySpecialPhpdocCases(): array - { - $factory = new FixerFactory(); - $factory->registerBuiltInFixers(); - - $fixers = []; - - foreach ($factory->getFixers() as $fixer) { - $fixers[$fixer->getName()] = $fixer; - } - - $cases = []; - - // Prepare bulk tests for phpdoc fixers to test that: - // * `align_multiline_comment` is first - // * `comment_to_phpdoc` is second - // * `phpdoc_to_comment` is third - // * `phpdoc_indent` is fourth - // * `phpdoc_types` is fifth - // * `phpdoc_scalar` is sixth - // * `phpdoc_align` is last - // Add these cases in test-order instead of alphabetical - $cases[] = [$fixers['align_multiline_comment'], $fixers['comment_to_phpdoc']]; - $cases[] = [$fixers['comment_to_phpdoc'], $fixers['phpdoc_to_comment']]; - $cases[] = [$fixers['phpdoc_to_comment'], $fixers['phpdoc_indent']]; - $cases[] = [$fixers['phpdoc_indent'], $fixers['phpdoc_types']]; - $cases[] = [$fixers['phpdoc_types'], $fixers['phpdoc_scalar']]; - $docFixerNames = array_filter( - array_keys($fixers), - static function (string $name): bool { - return str_contains($name, 'phpdoc'); - } - ); + foreach ($graphs as $graph) { + foreach ($graph as $fixerName => $edges) { + $first = $fixers[$fixerName]; - foreach ($docFixerNames as $docFixerName) { - if (!\in_array($docFixerName, ['comment_to_phpdoc', 'phpdoc_to_comment', 'phpdoc_indent', 'phpdoc_types', 'phpdoc_scalar'], true)) { - $cases[] = [$fixers['align_multiline_comment'], $fixers[$docFixerName]]; - $cases[] = [$fixers['comment_to_phpdoc'], $fixers[$docFixerName]]; - $cases[] = [$fixers['phpdoc_indent'], $fixers[$docFixerName]]; - $cases[] = [$fixers['phpdoc_to_comment'], $fixers[$docFixerName]]; + foreach ($edges as $edge) { + $second = $fixers[$edge]; - if ('phpdoc_annotation_without_dot' !== $docFixerName) { - $cases[] = [$fixers['phpdoc_scalar'], $fixers[$docFixerName]]; - $cases[] = [$fixers['phpdoc_types'], $fixers[$docFixerName]]; + static::assertLessThan($first->getPriority(), $second->getPriority(), sprintf('"%s" should have less priority than "%s"', $fixerName, $edge)); } } - - if ('phpdoc_align' !== $docFixerName) { - $cases[] = [$fixers[$docFixerName], $fixers['phpdoc_align']]; - } } - - return $cases; } - /** - * @dataProvider provideFixersPriorityPairsHaveIntegrationTestCases - */ - public function testFixersPriorityPairsHaveIntegrationTest(FixerInterface $first, FixerInterface $second): void + public function testFixersPriorityCasesHaveIntegrationTest(): void { - $integrationTestName = $this->generateIntegrationTestName($first, $second); - $file = $this->getIntegrationPriorityDirectory().$integrationTestName; - - if (is_file($file)) { - $description = sprintf('Integration of fixers: %s,%s.', $first->getName(), $second->getName()); - $integrationTestExists = true; - } else { - $file = $this->getIntegrationPriorityDirectory().$this->generateIntegrationTestName($second, $first); - $description = sprintf('Integration of fixers: %s,%s.', $second->getName(), $first->getName()); - $integrationTestExists = is_file($file); - } + $forPerformanceEdgesOnly = [ + 'function_to_constant' => [ + 'native_function_casing' => true, + ], + 'no_unused_imports' => [ + 'no_leading_import_slash' => true, + ], + 'no_useless_sprintf' => [ + 'native_function_casing' => true, + ], + 'pow_to_exponentiation' => [ + 'method_argument_space' => true, + 'native_function_casing' => true, + 'no_spaces_after_function_name' => true, + 'no_spaces_inside_parenthesis' => true, + ], + ]; - static::assertTrue($integrationTestExists, sprintf('There shall be an integration test "%s". How do you know that priority set up is good, if there is no integration test to check it?', $integrationTestName)); + foreach (self::getFixersPriorityGraph() as $fixerName => $edges) { + foreach ($edges as $edge) { + if (isset($forPerformanceEdgesOnly[$fixerName][$edge])) { + continue; + } - $file = realpath($file); - $factory = new IntegrationCaseFactory(); + $file = self::getIntegrationPriorityDirectory().$fixerName.','.$edge.'.test'; - $test = $factory->create(new SplFileInfo($file, './', __DIR__)); - $rules = $test->getRuleset()->getRules(); - $expected = [$first->getName(), $second->getName()]; - $actual = array_keys($rules); + static::assertFileExists($file, 'There shall be an integration test. How do you know that priority set up is good, if there is no integration test to check it?'); - sort($expected); - sort($actual); + $file = realpath($file); + $factory = new IntegrationCaseFactory(); + $test = $factory->create(new SplFileInfo($file, './', __DIR__)); + $rules = $test->getRuleset()->getRules(); + $expected = [$fixerName, $edge]; + $actual = array_keys($rules); - static::assertSame($description, $test->getTitle(), sprintf('Please fix the title in "%s".', $file)); - static::assertCount(2, $rules, sprintf('Only the two rules that are tested for priority should be in the ruleset of "%s".', $file)); + sort($expected); + sort($actual); - foreach ($rules as $name => $config) { - static::assertNotFalse($config, sprintf('The rule "%s" in "%s" may not be disabled for the test.', $name, $file)); - } + static::assertSame( + sprintf('Integration of fixers: %s,%s.', $fixerName, $edge), + $test->getTitle(), + sprintf('Please fix the title in "%s".', $file) + ); - static::assertSame($expected, $actual, sprintf('The ruleset of "%s" must contain the rules for the priority test.', $file)); - } + static::assertCount(2, $rules, sprintf('Only the two rules that are tested for priority should be in the ruleset of "%s".', $file)); - public function provideFixersPriorityPairsHaveIntegrationTestCases(): array - { - return array_filter( - $this->provideFixersPriorityCases(), - // ignore speed-up only priorities set up - function (array $case): bool { - return !\in_array( - $this->generateIntegrationTestName($case[0], $case[1]), - [ - 'function_to_constant,native_function_casing.test', - 'no_unused_imports,no_leading_import_slash.test', - 'pow_to_exponentiation,method_argument_space.test', - 'pow_to_exponentiation,native_function_casing.test', - 'pow_to_exponentiation,no_spaces_after_function_name.test', - 'pow_to_exponentiation,no_spaces_inside_parenthesis.test', - 'no_useless_sprintf,native_function_casing.test', - ], - true - ); - } - ); - } + foreach ($rules as $name => $config) { + static::assertNotFalse($config, sprintf('The rule "%s" in "%s" may not be disabled for the test.', $name, $file)); + } - public function testPriorityIntegrationDirectoryOnlyContainsFiles(): void - { - foreach (new \DirectoryIterator($this->getIntegrationPriorityDirectory()) as $candidate) { - if ($candidate->isDot()) { - continue; + static::assertSame($expected, $actual, sprintf('The ruleset of "%s" must contain the rules for the priority test.', $file)); } - - $fileName = $candidate->getFilename(); - static::assertTrue($candidate->isFile(), sprintf('Expected only files in the priority integration test directory, got "%s".', $fileName)); - static::assertFalse($candidate->isLink(), sprintf('No (sym)links expected the priority integration test directory, got "%s".', $fileName)); } } /** * @dataProvider provideIntegrationTestFilesCases */ - public function testPriorityIntegrationTestFilesAreListedPriorityCases(string $fileName): void + public function testPriorityIntegrationTestFilesAreListedAsPriorityCases(\SplFileInfo $file): void { - static $priorityCases; - - if (null === $priorityCases) { - $priorityCases = []; - - foreach ($this->provideFixersPriorityCases() as $priorityCase) { - $fixerName = $priorityCase[0]->getName(); - if (!isset($priorityCases[$fixerName])) { - $priorityCases[$fixerName] = []; - } - - $priorityCases[$fixerName][$priorityCase[1]->getName()] = true; - } - - ksort($priorityCases); - } + $fileName = $file->getFilename(); + static::assertTrue($file->isFile(), sprintf('Expected only files in the priority integration test directory, got "%s".', $fileName)); + static::assertFalse($file->isLink(), sprintf('No (sym)links expected the priority integration test directory, got "%s".', $fileName)); static::assertSame( 1, preg_match('#^([a-z][a-z0-9_]*),([a-z][a-z_]*)(?:_\d{1,3})?\.test(-(in|out)\.php)?$#', $fileName, $matches), sprintf('File with unexpected name "%s" in the priority integration test directory.', $fileName) ); + $graph = self::getFixersPriorityGraph(); $fixerName1 = $matches[1]; $fixerName2 = $matches[2]; static::assertTrue( - isset($priorityCases[$fixerName1][$fixerName2]), + isset($graph[$fixerName1]) && \in_array($fixerName2, $graph[$fixerName1], true), sprintf('Missing priority test entry for file "%s".', $fileName) ); } - public function provideIntegrationTestFilesCases(): array + public function provideIntegrationTestFilesCases(): \Generator { - $fileNames = []; - - foreach (new \DirectoryIterator($this->getIntegrationPriorityDirectory()) as $candidate) { - if ($candidate->isDot()) { - continue; + foreach (new \DirectoryIterator(self::getIntegrationPriorityDirectory()) as $candidate) { + if (!$candidate->isDot()) { + yield [clone $candidate]; } - - $fileNames[] = [$candidate->getFilename()]; } - - sort($fileNames); - - return $fileNames; } - public function testProvideFixersPriorityCasesAreSorted(): void + public function testFixersPriorityGraphIsSorted(): void { - $cases = $this->provideFixersPriorityCases(); - $sorted = $cases; - - usort( - $sorted, - /** - * @param array $priorityPair1 - * @param array $priorityPair2 - */ - static function (array $priorityPair1, array $priorityPair2): int { - $fixer1 = $priorityPair1[0]; - $fixer2 = $priorityPair2[0]; - - if ($fixer1->getName() === $fixer2->getName()) { - $fixer1 = $priorityPair1[1]; - $fixer2 = $priorityPair2[1]; - } - - return strcmp($fixer1->getName(), $fixer2->getName()); - } - ); - - if ($sorted !== $cases) { // PHPUnit takes a very long time creating a diff view on the arrays - $casesDescription = ''; + $previous = ''; - foreach ($cases as $pair) { - $casesDescription .= sprintf("\n%s/%s", $pair[0]->getName(), $pair[1]->getName()); - } - - $sortedDescription = ''; + foreach (self::getFixersPriorityGraph() as $fixerName => $edges) { + static::assertLessThan(0, strcmp($previous, $fixerName), sprintf('Not sorted "%s" "%s".', $previous, $fixerName)); - foreach ($sorted as $pair) { - $sortedDescription .= sprintf("\n%s/%s", $pair[0]->getName(), $pair[1]->getName()); - } + $edgesSorted = $edges; + sort($edgesSorted); - static::assertSame($sortedDescription, $casesDescription); - } else { - $this->addToAssertionCount(1); + static::assertSame($edgesSorted, $edges, sprintf('Fixer "%s" edges are not sorted', $fixerName)); + $previous = $fixerName; } } - public function testFixerPriorityComment(): void + public function testFixersPriorityComment(): void { - $cases = array_merge( - $this->provideFixersPriorityCases(), - $this->provideFixersPrioritySpecialPhpdocCases() - ); - - $map = []; - - foreach ($cases as $beforeAfter) { - [$before, $after] = $beforeAfter; - - $beforeClass = \get_class($before); - $afterClass = \get_class($after); + $fixersPhpDocIssues = []; + $fixers = self::getAllFixers(); - $beforeName = substr($beforeClass, strrpos($beforeClass, '\\') + 1); - $afterName = substr($afterClass, strrpos($afterClass, '\\') + 1); + foreach ($fixers as $name => $fixer) { + $reflection = new \ReflectionObject($fixer); + $fixers[$name] = ['reflection' => $reflection, 'short_classname' => $reflection->getShortName()]; + } - if (!isset($map[$beforeName])) { - $map[$beforeName] = [ - 'before' => [], - 'after' => [], - 'class' => $beforeClass, - ]; - } + $graph = array_merge_recursive( + self::getFixersPriorityGraph(), + self::getPhpDocFixersPriorityGraph() + ); - $map[$beforeName]['before'][] = $afterName; + foreach ($graph as $fixerName => $edges) { + $after = []; - if (!isset($map[$afterName])) { - $map[$afterName] = [ - 'before' => [], - 'after' => [], - 'class' => $afterClass, - ]; + foreach ($graph as $candidateFixer => $candidateEdges) { + if (\in_array($fixerName, $candidateEdges, true)) { + $after[] = $candidateFixer; + } } - $map[$afterName]['after'][] = $beforeName; - } - - $fixersPhpDocIssues = []; - - foreach ($map as $fixerName => $priorityMap) { $expectedMessage = "/**\n * {@inheritdoc}\n *"; - if (\count($priorityMap['before']) > 0) { - sort($priorityMap['before']); - $expectedMessage .= sprintf("\n * Must run before %s.", implode(', ', $priorityMap['before'])); - } + foreach (['before' => $edges, 'after' => $after] as $label => $others) { + if (\count($others) > 0) { + $shortClassNames = []; - // @phpstan-ignore-next-line to avoid `Comparison operation ">" between int<1, max> and 0 is always true.` - if (\count($priorityMap['after']) > 0) { - sort($priorityMap['after']); - $expectedMessage .= sprintf("\n * Must run after %s.", implode(', ', $priorityMap['after'])); + foreach ($others as $other) { + $shortClassNames[$other] = $fixers[$other]['short_classname']; + } + + sort($shortClassNames); + $expectedMessage .= sprintf("\n * Must run %s %s.", $label, implode(', ', $shortClassNames)); + } } $expectedMessage .= "\n */"; - $reflection = new \ReflectionClass($priorityMap['class']); - $method = $reflection->getMethod('getPriority'); + $method = $fixers[$fixerName]['reflection']->getMethod('getPriority'); $phpDoc = $method->getDocComment(); if (false === $phpDoc) { $fixersPhpDocIssues[$fixerName] = sprintf("PHPDoc for %s::getPriority is missing.\nExpected:\n%s", $fixerName, $expectedMessage); - - continue; - } - - if ($expectedMessage !== $phpDoc) { + } elseif ($expectedMessage !== $phpDoc) { $fixersPhpDocIssues[$fixerName] = sprintf("PHPDoc for %s::getPriority is not as expected.\nExpected:\n%s", $fixerName, $expectedMessage); - - continue; } } @@ -622,8 +229,8 @@ public function testFixerPriorityComment(): void $this->addToAssertionCount(1); } else { $message = sprintf("There are %d priority PHPDoc issues found.\n", \count($fixersPhpDocIssues)); - ksort($fixersPhpDocIssues); + foreach ($fixersPhpDocIssues as $fixerName => $issue) { $message .= sprintf("\n--------------------------------------------------\n%s\n%s", $fixerName, $issue); } @@ -634,51 +241,46 @@ public function testFixerPriorityComment(): void public function testFixerWithNoneDefaultPriorityIsTested(): void { + $knownIssues = [ // should only shrink + 'final_class' => true, + 'psr_autoloading' => true, + 'single_blank_line_before_namespace' => true, + ]; + $factory = new FixerFactory(); $factory->registerBuiltInFixers(); $fixers = $factory->getFixers(); - $priorityTests = []; + $fixerNamesWithTests = []; - foreach (self::getFixerWithFixedPosition() as $fixerName => $offset) { - $priorityTests[$fixerName] = true; + foreach (self::getFixerWithFixedPosition() as $fixerName => $priority) { + $fixerNamesWithTests[$fixerName] = true; } - foreach ($this->provideFixersPriorityCases() as $pair) { - [$first, $second] = $pair; - $priorityTests[$first->getName()] = true; - $priorityTests[$second->getName()] = true; - } + foreach ([ + self::getFixersPriorityGraph(), + self::getPhpDocFixersPriorityGraph(), + ] as $set) { + foreach ($set as $fixerName => $edges) { + $fixerNamesWithTests[$fixerName] = true; - foreach ($this->provideFixersPrioritySpecialPhpdocCases() as $pair) { - [$first, $second] = $pair; - $priorityTests[$first->getName()] = true; - $priorityTests[$second->getName()] = true; + foreach ($edges as $edge) { + $fixerNamesWithTests[$edge] = true; + } + } } $missing = []; foreach ($fixers as $fixer) { - $priority = $fixer->getPriority(); + $fixerName = $fixer->getName(); - if (0 === $priority) { - continue; - } - - $name = $fixer->getName(); - - if (!isset($priorityTests[$name])) { - $missing[$name] = true; + if (0 !== $fixer->getPriority() && !isset($fixerNamesWithTests[$fixerName])) { + $missing[$fixerName] = true; } } - $knownIssues = [ // should only shrink - 'final_class', - 'psr_autoloading', - 'single_blank_line_before_namespace', - ]; - - foreach ($knownIssues as $knownIssue) { + foreach ($knownIssues as $knownIssue => $true) { if (isset($missing[$knownIssue])) { unset($missing[$knownIssue]); } else { @@ -689,6 +291,537 @@ public function testFixerWithNoneDefaultPriorityIsTested(): void static::assertEmpty($missing, 'Fixers without default priority and without priority tests: "'.implode('", "', array_keys($missing)).'."'); } + /** + * @return array + */ + private static function getFixersPriorityGraph(): array + { + return [ + 'align_multiline_comment' => [ + 'phpdoc_trim_consecutive_blank_line_separation', + ], + 'array_indentation' => [ + 'align_multiline_comment', + 'binary_operator_spaces', + ], + 'array_syntax' => [ + 'binary_operator_spaces', + 'ternary_operator_spaces', + ], + 'assign_null_coalescing_to_coalesce_equal' => [ + 'binary_operator_spaces', + 'no_whitespace_in_blank_line', + ], + 'backtick_to_shell_exec' => [ + 'escape_implicit_backslashes', + 'explicit_string_variable', + 'native_function_invocation', + 'single_quote', + ], + 'blank_line_after_opening_tag' => [ + 'no_blank_lines_before_namespace', + ], + 'braces' => [ + 'array_indentation', + 'method_argument_space', + 'method_chaining_indentation', + ], + 'class_attributes_separation' => [ + 'braces', + 'indentation_type', + 'no_extra_blank_lines', + ], + 'class_definition' => [ + 'braces', + ], + 'class_keyword_remove' => [ + 'no_unused_imports', + ], + 'combine_consecutive_issets' => [ + 'multiline_whitespace_before_semicolons', + 'no_singleline_whitespace_before_semicolons', + 'no_spaces_inside_parenthesis', + 'no_trailing_whitespace', + 'no_whitespace_in_blank_line', + ], + 'combine_consecutive_unsets' => [ + 'no_extra_blank_lines', + 'no_trailing_whitespace', + 'no_whitespace_in_blank_line', + 'space_after_semicolon', + ], + 'combine_nested_dirname' => [ + 'method_argument_space', + 'no_spaces_inside_parenthesis', + ], + 'declare_strict_types' => [ + 'blank_line_after_opening_tag', + 'declare_equal_normalize', + 'header_comment', + ], + 'dir_constant' => [ + 'combine_nested_dirname', + ], + 'doctrine_annotation_array_assignment' => [ + 'doctrine_annotation_spaces', + ], + 'echo_tag_syntax' => [ + 'no_mixed_echo_print', + ], + 'elseif' => [ + 'braces', + ], + 'empty_loop_body' => [ + 'braces', + 'no_extra_blank_lines', + 'no_trailing_whitespace', + ], + 'empty_loop_condition' => [ + 'no_extra_blank_lines', + 'no_trailing_whitespace', + ], + 'escape_implicit_backslashes' => [ + 'heredoc_to_nowdoc', + 'single_quote', + ], + 'explicit_string_variable' => [ + 'simple_to_complex_string_variable', + ], + 'final_internal_class' => [ + 'protected_to_private', + 'self_static_accessor', + ], + 'fully_qualified_strict_types' => [ + 'no_superfluous_phpdoc_tags', + ], + 'function_declaration' => [ + 'method_argument_space', + ], + 'function_to_constant' => [ + 'native_function_casing', + 'no_extra_blank_lines', + 'no_singleline_whitespace_before_semicolons', + 'no_trailing_whitespace', + 'no_whitespace_in_blank_line', + 'self_static_accessor', + ], + 'general_phpdoc_annotation_remove' => [ + 'no_empty_phpdoc', + 'phpdoc_line_span', + 'phpdoc_separation', + 'phpdoc_trim', + ], + 'general_phpdoc_tag_rename' => [ + 'phpdoc_add_missing_param_annotation', + ], + 'get_class_to_class_keyword' => [ + 'multiline_whitespace_before_semicolons', + ], + 'global_namespace_import' => [ + 'no_unused_imports', + 'ordered_imports', + ], + 'header_comment' => [ + 'single_line_comment_style', + ], + 'implode_call' => [ + 'method_argument_space', + ], + 'indentation_type' => [ + 'phpdoc_indent', + ], + 'is_null' => [ + 'yoda_style', + ], + 'lambda_not_used_import' => [ + 'no_spaces_inside_parenthesis', + ], + 'line_ending' => [ + 'braces', + ], + 'list_syntax' => [ + 'binary_operator_spaces', + 'ternary_operator_spaces', + ], + 'method_argument_space' => [ + 'array_indentation', + ], + 'method_chaining_indentation' => [ + 'array_indentation', + 'method_argument_space', + ], + 'modernize_strpos' => [ + 'binary_operator_spaces', + 'no_extra_blank_lines', + 'no_spaces_inside_parenthesis', + 'no_trailing_whitespace', + 'not_operator_with_space', + 'not_operator_with_successor_space', + 'php_unit_dedicate_assert', + 'single_space_after_construct', + ], + 'multiline_whitespace_before_semicolons' => [ + 'space_after_semicolon', + ], + 'native_constant_invocation' => [ + 'global_namespace_import', + ], + 'native_function_invocation' => [ + 'global_namespace_import', + ], + 'new_with_braces' => [ + 'class_definition', + ], + 'no_alias_functions' => [ + 'implode_call', + 'php_unit_dedicate_assert', + ], + 'no_alternative_syntax' => [ + 'braces', + 'elseif', + 'no_superfluous_elseif', + 'no_useless_else', + 'switch_continue_to_break', + ], + 'no_blank_lines_after_phpdoc' => [ + 'header_comment', + ], + 'no_empty_comment' => [ + 'no_extra_blank_lines', + 'no_trailing_whitespace', + 'no_whitespace_in_blank_line', + ], + 'no_empty_phpdoc' => [ + 'no_extra_blank_lines', + 'no_trailing_whitespace', + 'no_whitespace_in_blank_line', + ], + 'no_empty_statement' => [ + 'braces', + 'combine_consecutive_unsets', + 'empty_loop_body', + 'multiline_whitespace_before_semicolons', + 'no_extra_blank_lines', + 'no_singleline_whitespace_before_semicolons', + 'no_trailing_whitespace', + 'no_useless_else', + 'no_useless_return', + 'no_whitespace_in_blank_line', + 'return_assignment', + 'space_after_semicolon', + 'switch_case_semicolon_to_colon', + ], + 'no_extra_blank_lines' => [ + 'blank_line_before_statement', + ], + 'no_leading_import_slash' => [ + 'ordered_imports', + ], + 'no_multiline_whitespace_around_double_arrow' => [ + 'binary_operator_spaces', + 'method_argument_space', + 'trailing_comma_in_multiline', + ], + 'no_php4_constructor' => [ + 'ordered_class_elements', + ], + 'no_short_bool_cast' => [ + 'cast_spaces', + ], + 'no_spaces_after_function_name' => [ + 'function_to_constant', + 'get_class_to_class_keyword', + ], + 'no_spaces_inside_parenthesis' => [ + 'function_to_constant', + 'get_class_to_class_keyword', + 'string_length_to_empty', + ], + 'no_superfluous_elseif' => [ + 'simplified_if_return', + ], + 'no_superfluous_phpdoc_tags' => [ + 'no_empty_phpdoc', + 'void_return', + ], + 'no_unneeded_control_parentheses' => [ + 'no_trailing_whitespace', + ], + 'no_unneeded_curly_braces' => [ + 'no_useless_else', + 'no_useless_return', + 'return_assignment', + 'simplified_if_return', + ], + 'no_unset_cast' => [ + 'binary_operator_spaces', + ], + 'no_unset_on_property' => [ + 'combine_consecutive_unsets', + ], + 'no_unused_imports' => [ + 'blank_line_after_namespace', + 'no_extra_blank_lines', + 'no_leading_import_slash', + 'single_line_after_imports', + ], + 'no_useless_else' => [ + 'braces', + 'combine_consecutive_unsets', + 'no_break_comment', + 'no_extra_blank_lines', + 'no_trailing_whitespace', + 'no_useless_return', + 'no_whitespace_in_blank_line', + 'simplified_if_return', + ], + 'no_useless_return' => [ + 'blank_line_before_statement', + 'no_extra_blank_lines', + 'no_whitespace_in_blank_line', + 'single_line_comment_style', + ], + 'no_useless_sprintf' => [ + 'method_argument_space', + 'native_function_casing', + 'no_empty_statement', + 'no_extra_blank_lines', + 'no_spaces_inside_parenthesis', + ], + 'nullable_type_declaration_for_default_null_value' => [ + 'no_unreachable_default_argument_value', + ], + 'ordered_class_elements' => [ + 'class_attributes_separation', + 'no_blank_lines_after_class_opening', + 'space_after_semicolon', + ], + 'php_unit_construct' => [ + 'php_unit_dedicate_assert', + ], + 'php_unit_dedicate_assert' => [ + 'no_unused_imports', + 'php_unit_dedicate_assert_internal_type', + ], + 'php_unit_fqcn_annotation' => [ + 'no_unused_imports', + 'phpdoc_order_by_value', + ], + 'php_unit_internal_class' => [ + 'final_internal_class', + ], + 'php_unit_no_expectation_annotation' => [ + 'no_empty_phpdoc', + 'php_unit_expectation', + ], + 'php_unit_test_annotation' => [ + 'no_empty_phpdoc', + 'php_unit_method_casing', + 'phpdoc_trim', + ], + 'php_unit_test_case_static_method_calls' => [ + 'self_static_accessor', + ], + 'phpdoc_add_missing_param_annotation' => [ + 'no_empty_phpdoc', + 'no_superfluous_phpdoc_tags', + 'phpdoc_align', + 'phpdoc_order', + ], + 'phpdoc_annotation_without_dot' => [ + 'phpdoc_types', + 'phpdoc_types_order', + ], + 'phpdoc_line_span' => [ + 'no_superfluous_phpdoc_tags', + ], + 'phpdoc_no_access' => [ + 'no_empty_phpdoc', + 'phpdoc_separation', + 'phpdoc_trim', + ], + 'phpdoc_no_alias_tag' => [ + 'phpdoc_add_missing_param_annotation', + 'phpdoc_single_line_var_spacing', + ], + 'phpdoc_no_empty_return' => [ + 'no_empty_phpdoc', + 'phpdoc_order', + 'phpdoc_separation', + 'phpdoc_trim', + ], + 'phpdoc_no_package' => [ + 'no_empty_phpdoc', + 'phpdoc_separation', + 'phpdoc_trim', + ], + 'phpdoc_no_useless_inheritdoc' => [ + 'no_empty_phpdoc', + 'no_trailing_whitespace_in_comment', + ], + 'phpdoc_order' => [ + 'phpdoc_separation', + 'phpdoc_trim', + ], + 'phpdoc_return_self_reference' => [ + 'no_superfluous_phpdoc_tags', + ], + 'phpdoc_scalar' => [ + 'phpdoc_to_return_type', + ], + 'phpdoc_to_comment' => [ + 'no_empty_comment', + 'phpdoc_no_useless_inheritdoc', + ], + 'phpdoc_to_param_type' => [ + 'no_superfluous_phpdoc_tags', + ], + 'phpdoc_to_property_type' => [ + 'no_superfluous_phpdoc_tags', + ], + 'phpdoc_to_return_type' => [ + 'fully_qualified_strict_types', + 'no_superfluous_phpdoc_tags', + 'return_type_declaration', + ], + 'phpdoc_types' => [ + 'phpdoc_to_return_type', + ], + 'pow_to_exponentiation' => [ + 'binary_operator_spaces', + 'method_argument_space', + 'native_function_casing', + 'no_spaces_after_function_name', + 'no_spaces_inside_parenthesis', + ], + 'protected_to_private' => [ + 'ordered_class_elements', + ], + 'regular_callable_call' => [ + 'native_function_invocation', + ], + 'return_assignment' => [ + 'blank_line_before_statement', + ], + 'semicolon_after_instruction' => [ + 'simplified_if_return', + ], + 'simplified_if_return' => [ + 'multiline_whitespace_before_semicolons', + 'no_singleline_whitespace_before_semicolons', + ], + 'simplified_null_return' => [ + 'no_useless_return', + 'void_return', + ], + 'single_class_element_per_statement' => [ + 'class_attributes_separation', + ], + 'single_import_per_statement' => [ + 'multiline_whitespace_before_semicolons', + 'no_leading_import_slash', + 'no_singleline_whitespace_before_semicolons', + 'no_unused_imports', + 'space_after_semicolon', + ], + 'single_line_throw' => [ + 'braces', + 'concat_space', + ], + 'single_space_after_construct' => [ + 'braces', + 'function_declaration', + ], + 'single_trait_insert_per_statement' => [ + 'braces', + 'space_after_semicolon', + ], + 'standardize_increment' => [ + 'increment_style', + ], + 'standardize_not_equals' => [ + 'binary_operator_spaces', + ], + 'strict_comparison' => [ + 'binary_operator_spaces', + ], + 'strict_param' => [ + 'method_argument_space', + 'native_function_invocation', + ], + 'string_length_to_empty' => [ + 'no_extra_blank_lines', + 'no_trailing_whitespace', + ], + 'ternary_to_elvis_operator' => [ + 'no_trailing_whitespace', + 'ternary_operator_spaces', + ], + 'ternary_to_null_coalescing' => [ + 'assign_null_coalescing_to_coalesce_equal', + ], + 'unary_operator_spaces' => [ + 'not_operator_with_space', + 'not_operator_with_successor_space', + ], + 'void_return' => [ + 'phpdoc_no_empty_return', + 'return_type_declaration', + ], + ]; + } + + private static function getPhpDocFixersPriorityGraph(): array + { + // Prepare bulk tests for phpdoc fixers to test that: + // * `align_multiline_comment` is first + // * `comment_to_phpdoc` is second + // * `phpdoc_to_comment` is third + // * `phpdoc_indent` is fourth + // * `phpdoc_types` is fifth + // * `phpdoc_scalar` is sixth + // * `phpdoc_align` is last + + $cases = [ + 'align_multiline_comment' => ['comment_to_phpdoc'], + 'comment_to_phpdoc' => ['phpdoc_to_comment'], + 'phpdoc_to_comment' => ['phpdoc_indent'], + 'phpdoc_indent' => ['phpdoc_types'], + 'phpdoc_types' => ['phpdoc_scalar'], + 'phpdoc_scalar' => [], + ]; + + $docFixerNames = array_filter( + array_keys(self::getAllFixers()), + static function (string $name): bool { + return str_contains($name, 'phpdoc'); + } + ); + + foreach ($docFixerNames as $docFixerName) { + if (!\in_array($docFixerName, ['comment_to_phpdoc', 'phpdoc_to_comment', 'phpdoc_indent', 'phpdoc_types', 'phpdoc_scalar'], true)) { + $cases['align_multiline_comment'][] = $docFixerName; + $cases['comment_to_phpdoc'][] = $docFixerName; + $cases['phpdoc_indent'][] = $docFixerName; + $cases['phpdoc_to_comment'][] = $docFixerName; + + if ('phpdoc_annotation_without_dot' !== $docFixerName) { + $cases['phpdoc_scalar'][] = $docFixerName; + $cases['phpdoc_types'][] = $docFixerName; + } + } + + if ('phpdoc_align' !== $docFixerName) { + $cases[$docFixerName][] = 'phpdoc_align'; + } + } + + return $cases; + } + + /** + * @return array + */ private static function getFixerWithFixedPosition(): array { return [ @@ -698,12 +831,23 @@ private static function getFixerWithFixedPosition(): array ]; } - private function generateIntegrationTestName(FixerInterface $first, FixerInterface $second): string + /** + * @return array + */ + private static function getAllFixers(): array { - return "{$first->getName()},{$second->getName()}.test"; + $factory = new FixerFactory(); + $factory->registerBuiltInFixers(); + $fixers = []; + + foreach ($factory->getFixers() as $fixer) { + $fixers[$fixer->getName()] = $fixer; + } + + return $fixers; } - private function getIntegrationPriorityDirectory(): string + private static function getIntegrationPriorityDirectory(): string { return __DIR__.'/../Fixtures/Integration/priority/'; }