From 158c076b22a8d3b022f1b645f096e105f358c8f9 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 10 Jun 2026 22:11:04 +0200 Subject: [PATCH 1/2] move symplify/coding-standard package here --- composer.json | 7 +- packages/coding-standard/LICENSE | 25 ++ .../coding-standard/config/sets/docblock.php | 37 +++ packages/coding-standard/config/symplify.php | 51 ++++ .../src/DocBlock/UselessDocBlockCleaner.php | 119 +++++++++ .../src/Enum/BlockBorderType.php | 12 + .../Exception/ShouldNotHappenException.php | 11 + .../src/Fixer/AbstractSymplifyFixer.php | 35 +++ ...oveMethodNameDuplicateDescriptionFixer.php | 89 +++++++ .../RemovePHPStormAnnotationFixer.php | 68 +++++ ...vePropertyVariableNameDescriptionFixer.php | 105 ++++++++ .../ArrayListItemNewlineFixer.php | 70 +++++ .../ArrayOpenerAndCloserNewlineFixer.php | 178 +++++++++++++ .../StandaloneLineInMultilineArrayFixer.php | 109 ++++++++ .../Commenting/AbstractDocBlockFixer.php | 114 +++++++++ .../Commenting/AddMissingParamNameFixer.php | 155 +++++++++++ .../Commenting/AddMissingVarNameFixer.php | 72 ++++++ .../DoubleAsteriskInlineVarFixer.php | 46 ++++ .../Commenting/FixParamNameTypoFixer.php | 145 +++++++++++ .../ParamReturnAndVarTagMalformsFixer.php | 61 +++++ .../Fixer/Commenting/RemoveDeadParamFixer.php | 51 ++++ .../RemoveParamNameReferenceFixer.php | 41 +++ .../RemoveSuperfluousReturnNameFixer.php | 92 +++++++ .../RemoveSuperfluousVarNameFixer.php | 97 +++++++ .../RemoveUselessDefaultCommentFixer.php | 78 ++++++ .../SingleLineInlineVarDocBlockFixer.php | 92 +++++++ .../Commenting/SwitchedTypeAndNameFixer.php | 65 +++++ .../src/Fixer/LineLength/LineLengthFixer.php | 240 ++++++++++++++++++ .../src/Fixer/Naming/ClassNameResolver.php | 65 +++++ .../src/Fixer/Naming/MethodNameResolver.php | 44 ++++ .../src/Fixer/Naming/PropertyNameResolver.php | 31 +++ .../Spacing/MethodChainingNewlineFixer.php | 155 +++++++++++ .../SpaceAfterCommaHereNowDocFixer.php | 63 +++++ .../StandaloneLineConstructorParamFixer.php | 75 ++++++ .../StandaloneLinePromotedPropertyFixer.php | 80 ++++++ .../Strict/BlankLineAfterStrictTypesFixer.php | 81 ++++++ .../TokenAnalyzer/ChainMethodCallAnalyzer.php | 108 ++++++++ .../DocblockRelatedParamNamesResolver.php | 56 ++++ .../TokenAnalyzer/FunctionCallNameMatcher.php | 49 ++++ .../src/TokenAnalyzer/HeredocAnalyzer.php | 39 +++ .../Naming/MethodNameResolver.php | 56 ++++ .../src/TokenAnalyzer/NewlineAnalyzer.php | 49 ++++ .../src/TokenAnalyzer/ParamNewliner.php | 34 +++ .../Analyzer/FixerAnalyzer/ArrayAnalyzer.php | 89 +++++++ .../Analyzer/FixerAnalyzer/BlockFinder.php | 178 +++++++++++++ .../Analyzer/FixerAnalyzer/CallAnalyzer.php | 32 +++ .../Analyzer/FixerAnalyzer/IndentDetector.php | 47 ++++ .../Analyzer/FixerAnalyzer/TokenSkipper.php | 101 ++++++++ .../TokenRunner/Arrays/ArrayItemNewliner.php | 57 +++++ .../src/TokenRunner/Enum/LineKind.php | 15 ++ .../MissingImplementationException.php | 11 + .../Exception/TokenNotFoundException.php | 17 ++ .../src/TokenRunner/TokenFinder.php | 60 +++++ .../FirstLineLengthResolver.php | 90 +++++++ .../LineLengthCloserTransformer.php | 81 ++++++ .../LineLengthOpenerTransformer.php | 51 ++++ .../FixerTransformer/LineLengthResolver.php | 114 +++++++++ .../LineLengthTransformer.php | 68 +++++ .../FixerTransformer/TokensInliner.php | 62 +++++ .../FixerTransformer/TokensNewliner.php | 116 +++++++++ .../Traverser/ArrayBlockInfoFinder.php | 53 ++++ .../TokenRunner/Traverser/TokenReverser.php | 29 +++ .../src/TokenRunner/ValueObject/BlockInfo.php | 24 ++ .../ValueObject/LineLengthAndPosition.php | 24 ++ .../TokenRunner/ValueObject/TokenKinds.php | 15 ++ .../Wrapper/FixerWrapper/ArrayWrapper.php | 81 ++++++ .../LineLengthAndPositionFactory.php | 65 +++++ .../TokenRunner/Whitespace/IndentResolver.php | 60 +++++ .../FixerWrapper/ArrayWrapperFactory.php | 27 ++ packages/coding-standard/src/Utils/Regex.php | 44 ++++ .../src/ValueObject/BlockInfoMetadata.php | 26 ++ .../src/ValueObject/CodingStandardConfig.php | 13 + .../Fixture/simple_annotation.php.inc | 30 +++ .../Fixture/with_return_date_time.php.inc | 34 +++ ...ethodNameDuplicateDescriptionFixerTest.php | 28 ++ .../config/configured_rule.php | 12 + .../Fixture/simple_annotation.php.inc | 30 +++ .../Fixture/skip_non_phpstorm.php.inc | 15 ++ .../RemovePHPStormAnnotationFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/phpstan_annotation.php.inc | 27 ++ .../Fixture/psalm_annotation.php.inc | 27 ++ .../Fixture/simple_annotation.php.inc | 27 ++ .../Fixture/skip_multiple_var.php.inc | 18 ++ .../Fixture/skip_name_in_the_middle.php.inc | 11 + .../Fixture/skip_param.php.inc | 13 + ...opertyVariableNameDescriptionFixerTest.php | 28 ++ .../config/configured_rule.php | 12 + .../ArrayListItemNewlineFixerTest.php | 28 ++ .../Fixture/simple_two_items.php.inc | 28 ++ .../Fixture/skip_inline_comment.php.inc | 14 + .../Fixture/skip_interpolated_string.php.inc | 16 ++ .../Fixture/skip_non_indexed_items.php.inc | 11 + .../Fixture/skip_simple_indent.php.inc | 18 ++ .../config/configured_rule.php | 10 + .../ArrayOpenerAndCloserNewlineFixerTest.php | 28 ++ .../Fixture/also_closer.php.inc | 29 +++ .../Fixture/handle_long_line.php.inc | 31 +++ .../Fixture/nested_array.php.inc | 19 ++ .../single_element_without_list.php.inc | 39 +++ .../Fixture/skip_double_opener.php.inc | 16 ++ .../Fixture/skip_no_keys.php.inc | 11 + .../Fixture/skip_single_item.php.inc | 15 ++ .../config/configured_rule.php | 10 + .../Fixture/correct.php.inc | 12 + .../Fixture/correct2.php.inc | 11 + .../Fixture/correct3.php.inc | 8 + .../Fixture/correct4.php.inc | 14 + .../Fixture/correct6.php.inc | 13 + .../Fixture/correct7.php.inc | 15 ++ .../Fixture/wrong.php.inc | 25 ++ .../Fixture/wrong2.php.inc | 52 ++++ .../FixturePhp80/wrong3.php.inc | 33 +++ .../FixturePhp80/wrong4.php.inc | 33 +++ ...tandaloneLineInMultilineArrayFixerTest.php | 28 ++ ...LineInMultilineArrayFixerTestPhp80Test.php | 28 ++ .../config/configured_rule.php | 10 + .../AddMissingParamNameFixerTest.php | 28 ++ .../Fixture/wrong6.php.inc | 41 +++ .../config/configured_rule.php | 10 + .../AddMissingVarNameFixerTest.php | 28 ++ .../Fixture/inlined_var_above.php.inc | 27 ++ .../inlined_var_above_many_types.php.inc | 19 ++ .../config/configured_rule.php | 10 + .../DoubleAsteriskInlineVarFixerTest.php | 28 ++ .../Fixture/single_asterisk.php.inc | 13 + .../config/configured_rule.php | 10 + .../FixParamNameTypoFixerTest.php | 28 ++ .../Fixture/param_name_wrong.php.inc | 23 ++ .../Fixture/wrong11.php.inc | 23 ++ .../Fixture/wrong12.php.inc | 25 ++ .../config/configured_rule.php | 10 + .../Fixture/dead_param.php.inc | 22 ++ .../Fixture/dead_param_only.php.inc | 18 ++ .../RemoveDeadParamFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/param_reference.php.inc | 19 ++ .../RemoveParamNameReferenceFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/wrong10.php.inc | 23 ++ .../Fixture/wrong7.php.inc | 105 ++++++++ .../RemoveSuperfluousReturnNameFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/wrong8.php.inc | 59 +++++ .../RemoveSuperfluousVarNameFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/class_docblock.php.inc | 35 +++ .../interface_docblock.php.inc | 23 ++ .../trait_docblock.php.inc | 23 ++ .../Fixture/class_representing.php.inc | 23 ++ .../constructor/constructor_blank.php.inc | 28 ++ ...ip_constructor_as_part_of_sentence.php.inc | 13 + .../useless_class_constructor_comment.php.inc | 43 ++++ .../Fixture/doctrine_generated.php.inc | 24 ++ .../Fixture/name_class_itself.php.inc | 23 ++ .../Fixture/remove_from_bottom_line.php.inc | 28 ++ .../Fixture/remove_from_property.php.inc | 28 ++ .../Fixture/simple_inline_comment.php.inc | 31 +++ ..._1_extra_word_class_method_comment.php.inc | 13 + .../Fixture/skip_inline_set.php.inc | 12 + .../Fixture/skip_no_changes.php.inc | 15 ++ .../skip_todo_non_phpstorm_comment.php.inc | 7 + .../skip_usefull_class_comment.php.inc | 10 + ..._usefull_class_constructor_comment.php.inc | 13 + .../todo_change_autogenerated_comment.php.inc | 15 ++ .../Fixture/todo_comment.php.inc | 28 ++ .../Fixture/trait_name_class_itself.php.inc | 28 ++ .../RemoveUselessDefaultCommentFixerTest.php | 28 ++ .../config/configured_rule.php | 13 + .../Fixture/multiline_var.php.inc | 21 ++ .../SingleLineInlineVarDocBlockFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/wrong3.php.inc | 27 ++ .../SwitchedTypeAndNameFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../ArrayLineLengthFixerTest.php | 28 ++ .../ConfiguredLineLengthFixerTest.php | 28 ++ .../Fixture/break_attribute.php.inc | 27 ++ .../break_method_call_with_array.php.inc | 26 ++ .../Fixture/break_new_some_object.php.inc | 21 ++ .../LineLengthFixer/Fixture/correct.php.inc | 21 ++ .../LineLengthFixer/Fixture/correct10.php.inc | 15 ++ .../LineLengthFixer/Fixture/correct11.php.inc | 11 + .../LineLengthFixer/Fixture/correct12.php.inc | 16 ++ .../LineLengthFixer/Fixture/correct2.php.inc | 19 ++ .../LineLengthFixer/Fixture/correct3.php.inc | 14 + .../LineLengthFixer/Fixture/correct4.php.inc | 20 ++ .../LineLengthFixer/Fixture/correct5.php.inc | 14 + .../LineLengthFixer/Fixture/correct6.php.inc | 5 + .../LineLengthFixer/Fixture/correct7.php.inc | 8 + .../LineLengthFixer/Fixture/correct8.php.inc | 14 + .../LineLengthFixer/Fixture/correct9.php.inc | 15 ++ .../Fixture/correct_heredoc.php.inc | 59 +++++ .../Fixture/inline_new_arguments.php.inc | 14 + .../Fixture/method_call_arguments.php.inc | 33 +++ .../Fixture/skip_correct_file.php.inc | 14 + .../Fixture/skip_property_promotion.php.inc | 14 + .../Fixture/skip_valid_attribute.php.inc | 12 + .../Fixture/use_arguments.php.inc | 39 +++ .../LineLengthFixer/Fixture/wrong.php.inc | 44 ++++ .../LineLengthFixer/Fixture/wrong10.php.inc | 32 +++ .../LineLengthFixer/Fixture/wrong11.php.inc | 32 +++ .../LineLengthFixer/Fixture/wrong12.php.inc | 26 ++ .../LineLengthFixer/Fixture/wrong13.php.inc | 28 ++ .../LineLengthFixer/Fixture/wrong14.php.inc | 14 + .../LineLengthFixer/Fixture/wrong15.php.inc | 26 ++ .../LineLengthFixer/Fixture/wrong16.php.inc | 34 +++ .../LineLengthFixer/Fixture/wrong18.php.inc | 34 +++ .../LineLengthFixer/Fixture/wrong2.php.inc | 36 +++ .../LineLengthFixer/Fixture/wrong8.php.inc | 26 ++ .../LineLengthFixer/Fixture/wrong9.php.inc | 31 +++ ...array_bracket_position_in_arg_list.php.inc | 29 +++ .../break_func_call_with_array.php.inc | 46 ++++ .../skip_method_call_with_array.php.inc | 52 ++++ .../FixtureArray/wrong17.php.inc | 26 ++ .../configured-wrong.php.inc | 24 ++ .../LineLengthFixer/LineLengthFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../LineLengthFixer/config/custom_rule.php | 14 + .../Fixture/many_multi_line_chain.php.inc | 33 +++ .../many_multi_line_chain_with_args.php.inc | 29 +++ .../Fixture/multi_line_chain.php.inc | 32 +++ .../Fixture/skip_another_line_bracket.php.inc | 15 ++ .../Fixture/skip_clone_call.php.inc | 13 + .../Fixture/skip_concat.php.inc | 13 + .../skip_func_call_args_single_method.php.inc | 11 + .../skip_func_call_single_method.php.inc | 11 + ..._func_call_single_method_with_args.php.inc | 11 + ...func_call_single_method_with_array.php.inc | 11 + .../skip_func_call_with_method_call.php.inc | 11 + .../Fixture/skip_in_array.php.inc | 13 + .../Fixture/skip_in_array_more.php.inc | 13 + .../Fixture/skip_in_call.php.inc | 17 ++ .../Fixture/skip_multi_line_chain.php.inc | 22 ++ .../skip_single_call_on_instantiation.php.inc | 16 ++ .../skip_static_call_date_time.php.inc | 15 ++ .../MethodChainingNewlineFixerTest.php | 28 ++ .../Source/SomeClassWithChains.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/end_array.php.inc | 34 +++ .../Fixture/wrong.php.inc | 38 +++ .../SpaceAfterCommaHereNowDocFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../Fixture/constructor_params.php.inc | 28 ++ .../Fixture/empty_constructor.php.inc | 13 + .../Fixture/include_single_item.php.inc | 27 ++ ...combination_with_line_lenght_fixer.php.inc | 27 ++ ...tructorParamFixerContraindicationsTest.php | 28 ++ ...tandaloneLineConstructorParamFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../config/contraindications.php | 15 ++ .../Fixture/promoted_properties.php.inc | 28 ++ .../Fixture/promoted_property.php.inc | 27 ++ .../Fixture/skip_attributes.php.inc | 96 +++++++ ...tandaloneLinePromotedPropertyFixerTest.php | 28 ++ .../config/configured_rule.php | 10 + .../BlankLineAfterStrictTypesFixerTest.php | 28 ++ .../Fixture/correct.php.inc | 1 + ...none_between_declare_and_namespace.php.inc | 14 + ...many_between_declare_and_namespace.php.inc | 16 ++ .../config/configured_rule.php | 10 + .../tests/Issues/Fixture/inline_array.php.inc | 39 +++ .../Fixture/line_length_parentheses.php.inc | 21 ++ ..._comment_and_statement_indentation.php.inc | 12 + .../Fixture/skip_already_inlined.php.inc | 19 ++ .../tests/Issues/InlineArrayTest.php | 29 +++ .../Issues/LineLengthParenthesesTest.php | 28 ++ ...ommentAndStatementIndentationFixerTest.php | 28 ++ .../config/config_inline_long_array.php | 12 + ...ault_comment_and_statement_indentation.php | 16 ++ .../Issues/config/line_length_parentheses.php | 18 ++ .../tests/Set/DocblockSet/DocblockSetTest.php | 31 +++ .../Set/DocblockSet/Fixture/correct.php.inc | 19 ++ .../Set/DocblockSet/Fixture/correct2.php.inc | 27 ++ .../DocblockSet/Fixture/iterator_flip.php.inc | 19 ++ .../Fixture/param_variable_mallforms.php.inc | 25 ++ ...has_same_param_previous_definition.php.inc | 16 ++ .../Fixture/skip_callable_param.php.inc | 15 ++ .../Fixture/skip_curly_newline.php.inc | 21 ++ .../skip_edge_case_with_assert.php.inc | 14 + .../Fixture/skip_inlined_var_in_doc.php.inc | 8 + .../Fixture/skip_nested_multiline.php.inc | 11 + .../Fixture/skip_union_array.php.inc | 11 + .../Set/DocblockSet/Fixture/wrong4.php.inc | 54 ++++ .../Set/DocblockSet/Fixture/wrong5.php.inc | 49 ++++ .../Set/DocblockSet/Fixture/wrong9.php.inc | 26 ++ .../tests/Set/DocblockSet/Source/Schedule.php | 9 + .../coding-standard/tests/Utils/RegexTest.php | 51 ++++ phpunit.xml | 1 + 289 files changed, 9805 insertions(+), 3 deletions(-) create mode 100644 packages/coding-standard/LICENSE create mode 100644 packages/coding-standard/config/sets/docblock.php create mode 100644 packages/coding-standard/config/symplify.php create mode 100644 packages/coding-standard/src/DocBlock/UselessDocBlockCleaner.php create mode 100644 packages/coding-standard/src/Enum/BlockBorderType.php create mode 100644 packages/coding-standard/src/Exception/ShouldNotHappenException.php create mode 100644 packages/coding-standard/src/Fixer/AbstractSymplifyFixer.php create mode 100644 packages/coding-standard/src/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer.php create mode 100644 packages/coding-standard/src/Fixer/Annotation/RemovePHPStormAnnotationFixer.php create mode 100644 packages/coding-standard/src/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer.php create mode 100644 packages/coding-standard/src/Fixer/ArrayNotation/ArrayListItemNewlineFixer.php create mode 100644 packages/coding-standard/src/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer.php create mode 100644 packages/coding-standard/src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/AbstractDocBlockFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/AddMissingVarNameFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/RemoveDeadParamFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php create mode 100644 packages/coding-standard/src/Fixer/Commenting/SwitchedTypeAndNameFixer.php create mode 100644 packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php create mode 100644 packages/coding-standard/src/Fixer/Naming/ClassNameResolver.php create mode 100644 packages/coding-standard/src/Fixer/Naming/MethodNameResolver.php create mode 100644 packages/coding-standard/src/Fixer/Naming/PropertyNameResolver.php create mode 100644 packages/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php create mode 100644 packages/coding-standard/src/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer.php create mode 100644 packages/coding-standard/src/Fixer/Spacing/StandaloneLineConstructorParamFixer.php create mode 100644 packages/coding-standard/src/Fixer/Spacing/StandaloneLinePromotedPropertyFixer.php create mode 100644 packages/coding-standard/src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/ChainMethodCallAnalyzer.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/FunctionCallNameMatcher.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/HeredocAnalyzer.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/Naming/MethodNameResolver.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/NewlineAnalyzer.php create mode 100644 packages/coding-standard/src/TokenAnalyzer/ParamNewliner.php create mode 100644 packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/ArrayAnalyzer.php create mode 100644 packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php create mode 100644 packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/CallAnalyzer.php create mode 100644 packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/IndentDetector.php create mode 100644 packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php create mode 100644 packages/coding-standard/src/TokenRunner/Arrays/ArrayItemNewliner.php create mode 100644 packages/coding-standard/src/TokenRunner/Enum/LineKind.php create mode 100644 packages/coding-standard/src/TokenRunner/Exception/MissingImplementationException.php create mode 100644 packages/coding-standard/src/TokenRunner/Exception/TokenNotFoundException.php create mode 100644 packages/coding-standard/src/TokenRunner/TokenFinder.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/FirstLineLengthResolver.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthCloserTransformer.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthOpenerTransformer.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthResolver.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthTransformer.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensInliner.php create mode 100644 packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensNewliner.php create mode 100644 packages/coding-standard/src/TokenRunner/Traverser/ArrayBlockInfoFinder.php create mode 100644 packages/coding-standard/src/TokenRunner/Traverser/TokenReverser.php create mode 100644 packages/coding-standard/src/TokenRunner/ValueObject/BlockInfo.php create mode 100644 packages/coding-standard/src/TokenRunner/ValueObject/LineLengthAndPosition.php create mode 100644 packages/coding-standard/src/TokenRunner/ValueObject/TokenKinds.php create mode 100644 packages/coding-standard/src/TokenRunner/ValueObject/Wrapper/FixerWrapper/ArrayWrapper.php create mode 100644 packages/coding-standard/src/TokenRunner/ValueObjectFactory/LineLengthAndPositionFactory.php create mode 100644 packages/coding-standard/src/TokenRunner/Whitespace/IndentResolver.php create mode 100644 packages/coding-standard/src/TokenRunner/Wrapper/FixerWrapper/ArrayWrapperFactory.php create mode 100644 packages/coding-standard/src/Utils/Regex.php create mode 100644 packages/coding-standard/src/ValueObject/BlockInfoMetadata.php create mode 100644 packages/coding-standard/src/ValueObject/CodingStandardConfig.php create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/Fixture/simple_annotation.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/Fixture/with_return_date_time.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/RemoveMethodNameDuplicateDescriptionFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/simple_annotation.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/skip_non_phpstorm.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/RemovePHPStormAnnotationFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/phpstan_annotation.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/psalm_annotation.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/simple_annotation.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_multiple_var.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_name_in_the_middle.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_param.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/RemovePropertyVariableNameDescriptionFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/ArrayListItemNewlineFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/simple_two_items.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_inline_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_interpolated_string.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_non_indexed_items.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_simple_indent.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/ArrayOpenerAndCloserNewlineFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/also_closer.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/handle_long_line.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/nested_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/single_element_without_list.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_double_opener.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_no_keys.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_single_item.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct2.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct3.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct4.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct6.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct7.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong2.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong3.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong4.php.inc create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTestPhp80Test.php create mode 100644 packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/Fixture/wrong6.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above_many_types.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/param_name_wrong.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong11.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong12.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param_only.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/Fixture/param_reference.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong10.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong7.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/Fixture/wrong8.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_docblock.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/interface_docblock.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/trait_docblock.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_representing.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/constructor_blank.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/skip_constructor_as_part_of_sentence.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/useless_class_constructor_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/doctrine_generated.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/name_class_itself.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_bottom_line.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_property.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/simple_inline_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_1_extra_word_class_method_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_inline_set.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_no_changes.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_todo_non_phpstorm_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_usefull_class_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_usefull_class_constructor_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_change_autogenerated_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_comment.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/trait_name_class_itself.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/RemoveUselessDefaultCommentFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/Fixture/wrong3.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ArrayLineLengthFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ConfiguredLineLengthFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_attribute.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_method_call_with_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_new_some_object.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct10.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct11.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct12.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct2.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct3.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct4.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct5.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct6.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct7.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct8.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct9.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct_heredoc.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/inline_new_arguments.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/method_call_arguments.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_correct_file.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_property_promotion.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_valid_attribute.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/use_arguments.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong10.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong11.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong12.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong13.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong14.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong15.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong16.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong18.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong2.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong8.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong9.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong_array_bracket_position_in_arg_list.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/break_func_call_with_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/skip_method_call_with_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/wrong17.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureConfigured/configured-wrong.php.inc create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/LineLengthFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/custom_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain_with_args.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/multi_line_chain.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_another_line_bracket.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_clone_call.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_concat.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_args_single_method.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_args.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_with_method_call.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array_more.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_call.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_multi_line_chain.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_single_call_on_instantiation.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_static_call_date_time.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/MethodChainingNewlineFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Source/SomeClassWithChains.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/end_array.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/wrong.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/SpaceAfterCommaHereNowDocFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/constructor_params.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/empty_constructor.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/include_single_item.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/FixtureContraindications/combination_with_line_lenght_fixer.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerContraindicationsTest.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/contraindications.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_properties.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_property.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/skip_attributes.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/StandaloneLinePromotedPropertyFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/BlankLineAfterStrictTypesFixerTest.php create mode 100644 packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/correct.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/none_between_declare_and_namespace.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/too_many_between_declare_and_namespace.php.inc create mode 100644 packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/config/configured_rule.php create mode 100644 packages/coding-standard/tests/Issues/Fixture/inline_array.php.inc create mode 100644 packages/coding-standard/tests/Issues/Fixture/line_length_parentheses.php.inc create mode 100644 packages/coding-standard/tests/Issues/Fixture/remove_useless_default_comment_and_statement_indentation.php.inc create mode 100644 packages/coding-standard/tests/Issues/Fixture/skip_already_inlined.php.inc create mode 100644 packages/coding-standard/tests/Issues/InlineArrayTest.php create mode 100644 packages/coding-standard/tests/Issues/LineLengthParenthesesTest.php create mode 100644 packages/coding-standard/tests/Issues/RemoveUselessDefaultCommentAndStatementIndentationFixerTest.php create mode 100644 packages/coding-standard/tests/Issues/config/config_inline_long_array.php create mode 100644 packages/coding-standard/tests/Issues/config/config_remove_useless_default_comment_and_statement_indentation.php create mode 100644 packages/coding-standard/tests/Issues/config/line_length_parentheses.php create mode 100644 packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/correct2.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/iterator_flip.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_curly_newline.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc create mode 100644 packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php create mode 100644 packages/coding-standard/tests/Utils/RegexTest.php diff --git a/composer.json b/composer.json index 854fabe7c34..488312cd6a6 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,6 @@ "squizlabs/php_codesniffer": "^4.0.1", "symfony/console": "^6.4.24", "symfony/finder": "^7.4", - "symplify/coding-standard": "^13.1", "symplify/easy-parallel": "^11.2", "webmozart/assert": "^2.4" }, @@ -44,12 +43,14 @@ }, "autoload": { "psr-4": { - "Symplify\\EasyCodingStandard\\": "src" + "Symplify\\EasyCodingStandard\\": "src", + "Symplify\\CodingStandard\\": "packages/coding-standard/src" } }, "autoload-dev": { "psr-4": { - "Symplify\\EasyCodingStandard\\Tests\\": "tests" + "Symplify\\EasyCodingStandard\\Tests\\": "tests", + "Symplify\\CodingStandard\\Tests\\": "packages/coding-standard/tests" }, "files": [ "tests/functions.php" diff --git a/packages/coding-standard/LICENSE b/packages/coding-standard/LICENSE new file mode 100644 index 00000000000..2dbf78e6f91 --- /dev/null +++ b/packages/coding-standard/LICENSE @@ -0,0 +1,25 @@ +The MIT License +--------------- + +Copyright (c) 2020 Tomas Votruba (https://tomasvotruba.com) + +Permission is hereby granted, free of charge, to any person +obtaining a copy of this software and associated documentation +files (the "Software"), to deal in the Software without +restriction, including without limitation the rights to use, +copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the +Software is furnished to do so, subject to the following +conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES +OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT +HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR +OTHER DEALINGS IN THE SOFTWARE. diff --git a/packages/coding-standard/config/sets/docblock.php b/packages/coding-standard/config/sets/docblock.php new file mode 100644 index 00000000000..33b1d74c275 --- /dev/null +++ b/packages/coding-standard/config/sets/docblock.php @@ -0,0 +1,37 @@ +rules([ + // inline @var + DoubleAsteriskInlineVarFixer::class, + SingleLineInlineVarDocBlockFixer::class, + AddMissingVarNameFixer::class, + + // @param + AddMissingParamNameFixer::class, + FixParamNameTypoFixer::class, + RemoveParamNameReferenceFixer::class, + RemoveDeadParamFixer::class, + + // superfluous names + RemoveSuperfluousReturnNameFixer::class, + RemoveSuperfluousVarNameFixer::class, + + // switched type/name order + SwitchedTypeAndNameFixer::class, + ]); +}; diff --git a/packages/coding-standard/config/symplify.php b/packages/coding-standard/config/symplify.php new file mode 100644 index 00000000000..103222e1805 --- /dev/null +++ b/packages/coding-standard/config/symplify.php @@ -0,0 +1,51 @@ +sets([__DIR__ . '/sets/docblock.php']); + + $ecsConfig->rules([ + // docblocks and comments + RemovePHPStormAnnotationFixer::class, + RemoveUselessDefaultCommentFixer::class, + RemoveMethodNameDuplicateDescriptionFixer::class, + RemovePropertyVariableNameDescriptionFixer::class, + + // arrays + ArrayListItemNewlineFixer::class, + ArrayOpenerAndCloserNewlineFixer::class, + StandaloneLineInMultilineArrayFixer::class, + StandaloneLinePromotedPropertyFixer::class, + StandaloneLineConstructorParamFixer::class, + + // newlines + MethodChainingNewlineFixer::class, + SpaceAfterCommaHereNowDocFixer::class, + BlankLineAfterStrictTypesFixer::class, + + // line length + LineLengthFixer::class, + ]); + + $ecsConfig->ruleWithConfiguration(GeneralPhpdocAnnotationRemoveFixer::class, [ + 'annotations' => ['throws', 'author', 'package', 'group', 'covers', 'category'], + ]); +}; diff --git a/packages/coding-standard/src/DocBlock/UselessDocBlockCleaner.php b/packages/coding-standard/src/DocBlock/UselessDocBlockCleaner.php new file mode 100644 index 00000000000..362658669c6 --- /dev/null +++ b/packages/coding-standard/src/DocBlock/UselessDocBlockCleaner.php @@ -0,0 +1,119 @@ +getContent(); + + $cleanedCommentLines = []; + + foreach (explode("\n", $docContent) as $key => $commentLine) { + if ($this->isClassLikeName($commentLine, $classLikeName)) { + continue; + } + + foreach (self::CLEANING_REGEXES as $cleaningRegex) { + $commentLine = Regex::replace($commentLine, $cleaningRegex); + } + + $cleanedCommentLines[$key] = $commentLine; + } + + // remove empty lines + $cleanedCommentLines = array_filter($cleanedCommentLines); + $cleanedCommentLines = array_values($cleanedCommentLines); + + // is totally empty? + if ($this->isEmptyDocblock($cleanedCommentLines)) { + return ''; + } + + $commentText = implode("\n", $cleanedCommentLines); + + // run multilines regex on final result + return Regex::replace($commentText, self::DOCTRINE_GENERATED_COMMENT_REGEX); + } + + /** + * @param string[] $commentLines + */ + private function isEmptyDocblock(array $commentLines): bool + { + if (count($commentLines) !== 2) { + return false; + } + + $startCommentLine = $commentLines[0]; + $endCommentLine = $commentLines[1]; + + return $startCommentLine === '/**' && trim($endCommentLine) === '*/'; + } + + private function isClassLikeName(string $commentLine, ?string $classLikeName): bool + { + if ($classLikeName === null) { + return false; + } + + return trim($commentLine, '* ') === $classLikeName; + } +} diff --git a/packages/coding-standard/src/Enum/BlockBorderType.php b/packages/coding-standard/src/Enum/BlockBorderType.php new file mode 100644 index 00000000000..18e39b86ec2 --- /dev/null +++ b/packages/coding-standard/src/Enum/BlockBorderType.php @@ -0,0 +1,12 @@ +methodNameResolver = new MethodNameResolver(); + } + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isTokenKindFound(T_FUNCTION)) { + return false; + } + + return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { + continue; + } + + $methodName = $this->methodNameResolver->resolve($tokens, $index); + if ($methodName === null) { + continue; + } + + // skip if not setter or getter + $originalDocContent = $token->getContent(); + + $hasChanged = false; + + $docblockLines = explode("\n", $originalDocContent); + foreach ($docblockLines as $key => $docblockLine) { + $spacelessDocblockLine = Regex::replace($docblockLine, '#[\s\n]+#', ''); + if (strtolower($spacelessDocblockLine) !== strtolower('*' . $methodName)) { + continue; + } + + $hasChanged = true; + unset($docblockLines[$key]); + } + + if (! $hasChanged) { + continue; + } + + $tokens[$index] = new Token([T_DOC_COMMENT, implode("\n", $docblockLines)]); + } + } +} diff --git a/packages/coding-standard/src/Fixer/Annotation/RemovePHPStormAnnotationFixer.php b/packages/coding-standard/src/Fixer/Annotation/RemovePHPStormAnnotationFixer.php new file mode 100644 index 00000000000..905415da6a8 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Annotation/RemovePHPStormAnnotationFixer.php @@ -0,0 +1,68 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { + continue; + } + + $originalDocContent = $token->getContent(); + $cleanedDocContent = Regex::replace($originalDocContent, self::CREATED_BY_PHPSTORM_DOC_REGEX, ''); + if ($cleanedDocContent !== '') { + continue; + } + + // remove token + $tokens->clearAt($index); + } + } +} diff --git a/packages/coding-standard/src/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer.php b/packages/coding-standard/src/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer.php new file mode 100644 index 00000000000..024ed7f54a7 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer.php @@ -0,0 +1,105 @@ +propertyNameResolver = new PropertyNameResolver(); + } + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isTokenKindFound(T_VARIABLE)) { + return false; + } + + return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { + continue; + } + + $propertyName = $this->propertyNameResolver->resolve($tokens, $index); + if ($propertyName === null) { + continue; + } + + // skip if not setter or getter + $originalDocContent = $token->getContent(); + + preg_match_all(self::VAR_REGEX, $originalDocContent, $matches); + + if (count($matches[0]) !== 1) { + continue; + } + + $hasChanged = false; + + $docblockLines = explode("\n", $originalDocContent); + foreach ($docblockLines as $key => $docblockLine) { + if (! str_ends_with($docblockLine, ' ' . $propertyName)) { + continue; + } + + if (! preg_match(self::VAR_REGEX, $docblockLine)) { + continue; + } + + // remove last x characters + $docblockLine = mb_substr($docblockLine, 0, -strlen(' ' . $propertyName)); + + $hasChanged = true; + $docblockLines[$key] = rtrim($docblockLine); + } + + if (! $hasChanged) { + continue; + } + + $tokens[$index] = new Token([T_DOC_COMMENT, implode("\n", $docblockLines)]); + } + } +} diff --git a/packages/coding-standard/src/Fixer/ArrayNotation/ArrayListItemNewlineFixer.php b/packages/coding-standard/src/Fixer/ArrayNotation/ArrayListItemNewlineFixer.php new file mode 100644 index 00000000000..29cbb5dd0c2 --- /dev/null +++ b/packages/coding-standard/src/Fixer/ArrayNotation/ArrayListItemNewlineFixer.php @@ -0,0 +1,70 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isAnyTokenKindsFound(TokenKinds::ARRAY_OPEN_TOKENS)) { + return false; + } + + return $tokens->isTokenKindFound(T_DOUBLE_ARROW); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $arrayBlockInfos = $this->arrayBlockInfoFinder->findArrayOpenerBlockInfos($tokens); + foreach ($arrayBlockInfos as $arrayBlockInfo) { + if (! $this->arrayAnalyzer->isIndexedList($tokens, $arrayBlockInfo)) { + continue; + } + + $this->arrayItemNewliner->fixArrayOpener($tokens, $arrayBlockInfo); + } + } +} diff --git a/packages/coding-standard/src/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer.php b/packages/coding-standard/src/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer.php new file mode 100644 index 00000000000..121c7770cf0 --- /dev/null +++ b/packages/coding-standard/src/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer.php @@ -0,0 +1,178 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isAnyTokenKindsFound(TokenKinds::ARRAY_OPEN_TOKENS)) { + return false; + } + + return $tokens->isTokenKindFound(T_DOUBLE_ARROW); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $blockInfos = $this->arrayBlockInfoFinder->findArrayOpenerBlockInfos($tokens); + + $blockInfoMetadatas = []; + + foreach ($blockInfos as $blockInfo) { + $blockInfoMetadatas[$blockInfo->getStart()] = new BlockInfoMetadata(BlockBorderType::OPENER, $blockInfo); + $blockInfoMetadatas[$blockInfo->getEnd()] = new BlockInfoMetadata(BlockBorderType::CLOSER, $blockInfo); + } + + // sort from the highest position to the lowest, so we respect the changed tokens from bottom to the top convention + krsort($blockInfoMetadatas); + + foreach ($blockInfoMetadatas as $blockInfoMetadata) { + $this->fixPositionAndType($blockInfoMetadata, $tokens); + } + } + + /** + * @param Tokens $tokens + */ + private function fixPositionAndType(BlockInfoMetadata $blockInfoMetadata, Tokens $tokens): void + { + $blockInfo = $blockInfoMetadata->getBlockInfo(); + if ($this->isNextTokenAlsoArrayOpener($tokens, $blockInfo->getStart())) { + return; + } + + // no items + $itemCount = $this->arrayAnalyzer->getItemCount($tokens, $blockInfo); + if ($itemCount === 0) { + return; + } + + if (! $this->arrayAnalyzer->isIndexedList($tokens, $blockInfo)) { + return; + } + + // closer must run before the opener, as tokens as added by traversing up + if ($blockInfoMetadata->getBlockType() === BlockBorderType::CLOSER) { + $this->handleArrayCloser($tokens, $blockInfo->getEnd()); + } elseif ($blockInfoMetadata->getBlockType() === BlockBorderType::OPENER) { + $this->handleArrayOpener($tokens, $blockInfo->getStart()); + } + } + + /** + * @param Tokens $tokens + */ + private function isNextTokenAlsoArrayOpener(Tokens $tokens, int $index): bool + { + $nextToken = $this->getNextMeaningfulToken($tokens, $index); + if (! $nextToken instanceof Token) { + return false; + } + + return $nextToken->isGivenKind(TokenKinds::ARRAY_OPEN_TOKENS); + } + + /** + * @param Tokens $tokens + */ + private function handleArrayCloser(Tokens $tokens, int $arrayCloserPosition): void + { + $preArrayCloserPosition = $arrayCloserPosition - 1; + + $previousCloserToken = $tokens[$preArrayCloserPosition] ?? null; + if (! $previousCloserToken instanceof Token) { + return; + } + + // already whitespace + if (\str_contains($previousCloserToken->getContent(), "\n")) { + return; + } + + $tokens->ensureWhitespaceAtIndex($preArrayCloserPosition, 1, $this->whitespacesFixerConfig->getLineEnding()); + } + + /** + * @param Tokens $tokens + */ + private function handleArrayOpener(Tokens $tokens, int $arrayOpenerPosition): void + { + $postArrayOpenerPosition = $arrayOpenerPosition + 1; + + $nextToken = $tokens[$postArrayOpenerPosition] ?? null; + if (! $nextToken instanceof Token) { + return; + } + + // already is whitespace + if (\str_contains($nextToken->getContent(), "\n")) { + return; + } + + $tokens->ensureWhitespaceAtIndex($postArrayOpenerPosition, 0, $this->whitespacesFixerConfig->getLineEnding()); + } + + /** + * @param Tokens $tokens + */ + private function getNextMeaningfulToken(Tokens $tokens, int $index): ?Token + { + $nextMeaningfulTokenPosition = $tokens->getNextMeaningfulToken($index); + if ($nextMeaningfulTokenPosition === null) { + return null; + } + + return $tokens[$nextMeaningfulTokenPosition]; + } +} diff --git a/packages/coding-standard/src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php b/packages/coding-standard/src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php new file mode 100644 index 00000000000..63b1c11d0e0 --- /dev/null +++ b/packages/coding-standard/src/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer.php @@ -0,0 +1,109 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isAnyTokenKindsFound(TokenKinds::ARRAY_OPEN_TOKENS)) { + return false; + } + + return $tokens->isTokenKindFound(T_DOUBLE_ARROW); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + foreach ($tokens as $index => $token) { + if (! $token->isGivenKind(TokenKinds::ARRAY_OPEN_TOKENS)) { + continue; + } + + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $index); + if (! $blockInfo instanceof BlockInfo) { + continue; + } + + if ($this->shouldSkipNestedArrayValue($tokens, $blockInfo)) { + return; + } + + $this->tokensNewliner->breakItems($blockInfo, $tokens, LineKind::ARRAYS); + } + } + + /** + * @param Tokens $tokens + */ + private function shouldSkipNestedArrayValue(Tokens $tokens, BlockInfo $blockInfo): bool + { + $arrayWrapper = $this->arrayWrapperFactory->createFromTokensAndBlockInfo($tokens, $blockInfo); + if (! $arrayWrapper->isAssociativeArray()) { + return true; + } + + if ($arrayWrapper->getItemCount() === 1 && ! $arrayWrapper->isFirstItemArray()) { + $previousTokenPosition = $tokens->getPrevMeaningfulToken($blockInfo->getStart()); + if ($previousTokenPosition === null) { + return false; + } + + /** @var Token $previousToken */ + $previousToken = $tokens[$previousTokenPosition]; + return ! $previousToken->isGivenKind(T_DOUBLE_ARROW); + } + + return false; + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/AbstractDocBlockFixer.php b/packages/coding-standard/src/Fixer/Commenting/AbstractDocBlockFixer.php new file mode 100644 index 00000000000..a91215e32ce --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/AbstractDocBlockFixer.php @@ -0,0 +1,114 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + if (! $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT])) { + return false; + } + + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_CALLABLE])) { + continue; + } + + if (! (isset($tokens[$index + 3]) && $tokens[$index + 3]->getContent() === ')')) { + continue; + } + + return false; + } + + return $tokens->isAnyTokenKindsFound([T_FUNCTION, T_VARIABLE]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { + continue; + } + + $docContent = $token->getContent(); + if (! Regex::match($docContent, self::TYPE_ANNOTATION_REGEX)) { + continue; + } + + $newDocContent = $this->processDocContent($docContent, $tokens, $index); + if ($newDocContent === $docContent) { + continue; + } + + // doc block became empty after removing dead lines → remove it completely, + // including the whitespace that followed it, to avoid leaving a blank line + if ($this->isEmptyDocBlock($newDocContent)) { + $tokens->clearAt($index); + if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) { + $tokens->clearAt($index + 1); + } + + continue; + } + + $tokens[$index] = new Token([T_DOC_COMMENT, $newDocContent]); + } + } + + /** + * Must run before + * + * @see \PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer::getPriority() + */ + #[Override] + public function getPriority(): int + { + return -37; + } + + /** + * @param Tokens $tokens + */ + abstract protected function processDocContent(string $docContent, Tokens $tokens, int $position): string; + + private function isEmptyDocBlock(string $docContent): bool + { + return Regex::replace($docContent, '#/\*\*|\*/|\*|\s#', '') === ''; + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php new file mode 100644 index 00000000000..73b537cba2a --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/AddMissingParamNameFixer.php @@ -0,0 +1,155 @@ + $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + $argumentNames = $this->docblockRelatedParamNamesResolver->resolve($tokens, $position); + if ($argumentNames === []) { + return $docContent; + } + + $missingArgumentNames = $this->filterOutExistingParamNames($docContent, $argumentNames); + if ($missingArgumentNames === []) { + return $docContent; + } + + $docBlock = new DocBlock($docContent); + + $this->completeMissingArgumentNames($missingArgumentNames, $argumentNames, $docBlock); + + return $docBlock->getContent(); + } + + /** + * @param string[] $functionArgumentNames + * @return string[] + */ + private function filterOutExistingParamNames(string $docContent, array $functionArgumentNames): array + { + foreach ($functionArgumentNames as $key => $functionArgumentName) { + $pattern = '# ' . preg_quote($functionArgumentName, '#') . '\b#'; + if (Regex::match($docContent, $pattern)) { + unset($functionArgumentNames[$key]); + } + } + + return array_values($functionArgumentNames); + } + + /** + * @param string[] $missingArgumentNames + * @param string[] $argumentNames + */ + private function completeMissingArgumentNames( + array $missingArgumentNames, + array $argumentNames, + DocBlock $docBlock + ): void { + foreach ($missingArgumentNames as $key => $missingArgumentName) { + $newArgumentName = $this->resolveNewArgumentName($argumentNames, $missingArgumentName, $key); + + $lines = $docBlock->getLines(); + foreach ($lines as $line) { + if ($this->shouldSkipLine($line)) { + continue; + } + + $newLineContent = $this->createNewLineContent($newArgumentName, $line); + $line->setContent($newLineContent); + continue 2; + } + } + } + + /** + * @param string[] $argumentNames + */ + private function resolveNewArgumentName(array $argumentNames, string $missingArgumentName, int $key): string + { + if (array_search($missingArgumentName, $argumentNames, true)) { + return $missingArgumentName; + } + + return $argumentNames[$key]; + } + + private function shouldSkipLine(Line $line): bool + { + if (! \str_contains($line->getContent(), self::PARAM_ANNOTATOIN_START_REGEX)) { + return true; + } + + // already has a param name + if (Regex::match($line->getContent(), self::PARAM_WITH_NAME_REGEX)) { + return true; + } + + $match = Regex::match($line->getContent(), self::PARAM_WITHOUT_NAME_REGEX); + return $match === null; + } + + private function createNewLineContent(string $newArgumentName, Line $line): string + { + // @see https://regex101.com/r/4FL49H/1 + $missingDollarSignPattern = '#(@param\s+([\w\|\[\]\\\\]+\s)?)(' . ltrim($newArgumentName, '$') . ')#'; + + // missing \$ case - possibly own worker + if (Regex::match($line->getContent(), $missingDollarSignPattern)) { + return Regex::replace($line->getContent(), $missingDollarSignPattern, '$1$$3'); + } + + $replacement = '@param $1 ' . $newArgumentName . '$2' . "\n"; + + return Regex::replace($line->getContent(), self::PARAM_WITHOUT_NAME_REGEX, $replacement); + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/AddMissingVarNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/AddMissingVarNameFixer.php new file mode 100644 index 00000000000..84e23df9bad --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/AddMissingVarNameFixer.php @@ -0,0 +1,72 @@ +\/\*\* @(?:psalm-|phpstan-)?var )(?[\\\\\w\|-|]+)(?\s+\*\/)$#'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + if (! Regex::match($docContent, self::VAR_WITHOUT_NAME_REGEX)) { + return $docContent; + } + + $nextVariableToken = $this->getNextVariableToken($tokens, $position); + if (! $nextVariableToken instanceof Token) { + return $docContent; + } + + return Regex::replace( + $docContent, + self::VAR_WITHOUT_NAME_REGEX, + static fn (array $match): string => $match['open'] . $match['type'] . ' ' . $nextVariableToken->getContent() . $match['close'] + ); + } + + /** + * @param Tokens $tokens + */ + private function getNextVariableToken(Tokens $tokens, int $position): ?Token + { + $nextMeaningfulTokenPosition = $tokens->getNextMeaningfulToken($position); + if ($nextMeaningfulTokenPosition === null) { + return null; + } + + $nextToken = $tokens[$nextMeaningfulTokenPosition] ?? null; + if (! $nextToken instanceof Token) { + return null; + } + + if (! $nextToken->isGivenKind(T_VARIABLE)) { + return null; + } + + return $nextToken; + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php b/packages/coding-standard/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php new file mode 100644 index 00000000000..27897c27e5e --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/DoubleAsteriskInlineVarFixer.php @@ -0,0 +1,46 @@ + $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + /** @var Token $token */ + $token = $tokens[$position]; + + if (! $token->isGivenKind(T_COMMENT)) { + return $docContent; + } + + return Regex::replace($docContent, self::SINGLE_ASTERISK_START_REGEX, '/**$1'); + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php b/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php new file mode 100644 index 00000000000..45ff067f70b --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php @@ -0,0 +1,145 @@ +callable)?(.*?)(?\$\w+)#'; + + public function __construct( + TokenReverser $tokenReverser, + private readonly DocblockRelatedParamNamesResolver $docblockRelatedParamNamesResolver + ) { + parent::__construct($tokenReverser); + } + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + $argumentNames = $this->docblockRelatedParamNamesResolver->resolve($tokens, $position); + if ($argumentNames === []) { + return $docContent; + } + + $paramNames = $this->getParamNames($docContent); + + $missArgumentNames = []; + // remove correct params + foreach ($argumentNames as $key => $argumentName) { + if (in_array($argumentName, $paramNames, true)) { + $paramPosition = array_search($argumentName, $paramNames, true); + unset($paramNames[$paramPosition]); + } else { + $missArgumentNames[$key] = $argumentName; + } + } + + // nothing to edit, all arguments are correct or there are no more @param annotations + if ($missArgumentNames === []) { + return $docContent; + } + + if ($paramNames === []) { + return $docContent; + } + + return $this->fixTypos($argumentNames, $missArgumentNames, $paramNames, $docContent); + } + + /** + * @return string[] + */ + private function getParamNames(string $docContent): array + { + $paramAnnotations = $this->getAnnotationsOfType($docContent, 'param'); + + $paramNames = []; + foreach ($paramAnnotations as $paramAnnotation) { + $match = Regex::match($paramAnnotation->getContent(), self::PARAM_NAME_REGEX); + if (isset($match['paramName'])) { + // skip callables, as they contain nested params + if (isset($match['callable']) && $match['callable'] === 'callable') { + continue; + } + + $paramNames[] = $match['paramName']; + } + } + + return $paramNames; + } + + /** + * @return Annotation[] + */ + private function getAnnotationsOfType(string $docContent, string $type): array + { + $docBlock = new DocBlock($docContent); + + return $docBlock->getAnnotationsOfType($type); + } + + /** + * @param string[] $argumentNames + * @param string[] $missArgumentNames + * @param string[] $paramNames + */ + private function fixTypos(array $argumentNames, array $missArgumentNames, array $paramNames, string $docContent): string + { + // A table of permuted params. initialized by $argumentName instead of $paramNames is correct + $replacedParams = array_fill_keys($argumentNames, false); + + foreach ($missArgumentNames as $key => $argumentName) { + // 1. the same position + if (! isset($paramNames[$key])) { + continue; + } + + $typoName = $paramNames[$key]; + $replacePattern = '#@param(.*?)(' . preg_quote($typoName, '#') . '\b)#'; + + $docContent = Regex::replace($docContent, $replacePattern, static function (array $matched) use ($argumentName, &$replacedParams) { + $paramName = $matched[2]; + + // 2. If the PHPDoc $paramName is one of the existing $argumentNames and has not already been replaced, it will be deferred + if (isset($replacedParams[$paramName]) && ! $replacedParams[$paramName]) { + $replacedParams[$paramName] = true; + + return $matched[0]; + } + + // 3. Otherwise, replace $paramName with $argumentName in the @param line + return sprintf('@param%s%s', $matched[1], $argumentName); + }); + } + + return $docContent; + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php b/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php new file mode 100644 index 00000000000..8d2157ba760 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php @@ -0,0 +1,61 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return false; + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + } + + /** + * @return list + */ + public function getSuccessorsNames(): array + { + return [ + DoubleAsteriskInlineVarFixer::class, + SingleLineInlineVarDocBlockFixer::class, + AddMissingParamNameFixer::class, + AddMissingVarNameFixer::class, + RemoveParamNameReferenceFixer::class, + FixParamNameTypoFixer::class, + RemoveSuperfluousReturnNameFixer::class, + RemoveSuperfluousVarNameFixer::class, + SwitchedTypeAndNameFixer::class, + RemoveDeadParamFixer::class, + ]; + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/RemoveDeadParamFixer.php b/packages/coding-standard/src/Fixer/Commenting/RemoveDeadParamFixer.php new file mode 100644 index 00000000000..16f88f286ac --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/RemoveDeadParamFixer.php @@ -0,0 +1,51 @@ + $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + $docBlock = new DocBlock($docContent); + + foreach ($docBlock->getLines() as $line) { + if (! Regex::match($line->getContent(), self::PARAM_WITHOUT_TYPE_REGEX)) { + continue; + } + + $line->remove(); + } + + return $docBlock->getContent(); + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php b/packages/coding-standard/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php new file mode 100644 index 00000000000..b911f89accf --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/RemoveParamNameReferenceFixer.php @@ -0,0 +1,41 @@ +@param(.*?))&(?\$\w+)#'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + return Regex::replace( + $docContent, + self::PARAM_NAME_REGEX, + static fn ($match): string => $match['param'] . $match['paramName'] + ); + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php new file mode 100644 index 00000000000..99b1c55abad --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousReturnNameFixer.php @@ -0,0 +1,92 @@ +@(?:psalm-|phpstan-)?return)(?\s+[|\\\\\w]+)?(\s+)(?<' . self::VARIABLE_NAME_PART . '>\$[\w]+)#'; + + /** + * @var string[] + */ + private const array ALLOWED_VARIABLE_NAMES = ['$this']; + + /** + * @see https://regex101.com/r/IE9fA6/1 + */ + private const string VARIABLE_NAME_REGEX = '#\$\w+#'; + + private const string VARIABLE_NAME_PART = 'variableName'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + $docBlock = new DocBlock($docContent); + + $lines = $docBlock->getLines(); + foreach ($lines as $line) { + $match = Regex::match($line->getContent(), self::RETURN_VARIABLE_NAME_REGEX); + if ($match === null) { + continue; + } + + if ($this->shouldSkip($match, $line->getContent())) { + continue; + } + + $newLineContent = Regex::replace( + $line->getContent(), + self::RETURN_VARIABLE_NAME_REGEX, + static function (array $match) { + $replacement = $match['tag']; + if ($match['type'] !== []) { + $replacement .= $match['type']; + } + + return $replacement; + } + ); + + $line->setContent($newLineContent); + } + + return $docBlock->getContent(); + } + + /** + * @param array $match + */ + private function shouldSkip(array $match, string $content): bool + { + if (in_array($match[self::VARIABLE_NAME_PART], self::ALLOWED_VARIABLE_NAMES, true)) { + return true; + } + + // has multiple return values? "@return array $one, $two" + return count(Regex::matchAll($content, self::VARIABLE_NAME_REGEX)) >= 2; + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php new file mode 100644 index 00000000000..aa8cf4385e7 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/RemoveSuperfluousVarNameFixer.php @@ -0,0 +1,97 @@ +@(?:psalm-|phpstan-)?var)(?\s+[|\\\\\w]+)?(\s+)(?\$[\w]+)#'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + if ($this->shouldSkip($tokens, $position)) { + return $docContent; + } + + $docBlock = new DocBlock($docContent); + + $lines = $docBlock->getLines(); + foreach ($lines as $line) { + $match = Regex::match($line->getContent(), self::VAR_VARIABLE_NAME_REGEX); + if ($match === null) { + continue; + } + + $newLineContent = Regex::replace( + $line->getContent(), + self::VAR_VARIABLE_NAME_REGEX, + static function (array $match): string { + $replacement = $match['tag']; + if ($match['type'] !== []) { + $replacement .= $match['type']; + } + + if (Regex::match($match['propertyName'], self::THIS_VARIABLE_REGEX)) { + return $match['tag'] . ' self'; + } + + return $replacement; + } + ); + + $line->setContent($newLineContent); + } + + return $docBlock->getContent(); + } + + /** + * Is property doc block? + * + * @param Tokens $tokens + */ + private function shouldSkip(Tokens $tokens, int $position): bool + { + $nextMeaningfulTokenPosition = $tokens->getNextMeaningfulToken($position); + + // nothing to change + if ($nextMeaningfulTokenPosition === null) { + return true; + } + + /** @var Token $nextMeaningfulToken */ + $nextMeaningfulToken = $tokens[$nextMeaningfulTokenPosition]; + + // should be protected/private/public/static, to know we're property + return ! $nextMeaningfulToken->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC]); + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php b/packages/coding-standard/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php new file mode 100644 index 00000000000..730834775e8 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/RemoveUselessDefaultCommentFixer.php @@ -0,0 +1,78 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound([T_DOC_COMMENT, T_COMMENT]); + } + + #[Override] + public function getPriority(): int + { + /** must run before @see \PhpCsFixer\Fixer\Basic\BracesFixer to cleanup spaces */ + return 40; + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $reversedTokens = $this->tokenReverser->reverse($tokens); + + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind([T_DOC_COMMENT, T_COMMENT])) { + continue; + } + + $classLikeName = $this->classNameResolver->resolveClassName($fileInfo, $tokens); + + $originalContent = $token->getContent(); + $cleanedDocContent = $this->uselessDocBlockCleaner->clearDocTokenContent($token, $classLikeName); + + if ($cleanedDocContent === '') { + // remove token + $tokens->clearTokenAndMergeSurroundingWhitespace($index); + } elseif ($cleanedDocContent !== $originalContent) { + // update in case of other contents + $tokens[$index] = new Token([T_DOC_COMMENT, $cleanedDocContent]); + } + } + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php b/packages/coding-standard/src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php new file mode 100644 index 00000000000..43befccabaa --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/SingleLineInlineVarDocBlockFixer.php @@ -0,0 +1,92 @@ + $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + if (! $this->isVariableComment($tokens, $position)) { + return $docContent; + } + + // more than 2 newlines - keep it + if (substr_count($docContent, "\n") > 2) { + return $docContent; + } + + // asterisk start + $docContent = Regex::replace($docContent, self::SINGLE_ASTERISK_START_REGEX, '/**$1'); + + // inline + $docContent = Regex::replace($docContent, self::SPACE_REGEX, ' '); + + // remove asterisk leftover + return Regex::replace($docContent, self::ASTERISK_LEFTOVERS_REGEX, '$1'); + } + + /** + * @param Tokens $tokens + */ + private function isVariableComment(Tokens $tokens, int $position): bool + { + $nextPosition = $tokens->getNextMeaningfulToken($position); + if ($nextPosition === null) { + return false; + } + + $nextNextPosition = $tokens->getNextMeaningfulToken($nextPosition + 2); + if ($nextNextPosition === null) { + return false; + } + + /** @var Token $nextNextToken */ + $nextNextToken = $tokens[$nextNextPosition]; + if ($nextNextToken->isGivenKind([T_STATIC, T_FUNCTION])) { + return false; + } + + // is inline variable + /** @var Token $nextToken */ + $nextToken = $tokens[$nextPosition]; + return $nextToken->isGivenKind(T_VARIABLE); + } +} diff --git a/packages/coding-standard/src/Fixer/Commenting/SwitchedTypeAndNameFixer.php b/packages/coding-standard/src/Fixer/Commenting/SwitchedTypeAndNameFixer.php new file mode 100644 index 00000000000..4cb2131ff2d --- /dev/null +++ b/packages/coding-standard/src/Fixer/Commenting/SwitchedTypeAndNameFixer.php @@ -0,0 +1,65 @@ +\$\w+)(\s+)(?[|\\\\\w\[\]\<\>]+)#'; + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + protected function processDocContent(string $docContent, Tokens $tokens, int $position): string + { + $docBlock = new DocBlock($docContent); + + $lines = $docBlock->getLines(); + foreach ($lines as $line) { + // $value is first, instead of type is first + $match = Regex::match($line->getContent(), self::NAME_THEN_TYPE_REGEX); + if ($match === null) { + continue; + } + + if ($match['name'] === '') { + continue; + } + + if ($match['type'] === '') { + continue; + } + + // skip random words that look like type without autolaoding + if (in_array($match['type'], ['The', 'Set'], true)) { + continue; + } + + $newLine = Regex::replace($line->getContent(), self::NAME_THEN_TYPE_REGEX, '@$1$2$5$4$3'); + $line->setContent($newLine); + } + + return $docBlock->getContent(); + } +} diff --git a/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php b/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php new file mode 100644 index 00000000000..b5423090b11 --- /dev/null +++ b/packages/coding-standard/src/Fixer/LineLength/LineLengthFixer.php @@ -0,0 +1,240 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound([ + // "[" + T_ARRAY, + // "array"() + CT::T_ARRAY_SQUARE_BRACE_OPEN, + '(', + ')', + // "function" + T_FUNCTION, + // "use" (...) + CT::T_USE_LAMBDA, + // "new" + T_NEW, + // "#[" + T_ATTRIBUTE, + ]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + // function arguments, function call parameters, lambda use() + for ($position = count($tokens) - 1; $position >= 0; --$position) { + /** @var Token $token */ + $token = $tokens[$position]; + + if ($token->equals(')')) { + $this->processMethodCall($tokens, $position); + continue; + } + + // opener + if ($token->isGivenKind([T_ATTRIBUTE, T_FUNCTION, CT::T_USE_LAMBDA, T_NEW])) { + $this->processFunctionOrArray($tokens, $position); + continue; + } + + // closer + if (! $token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) { + continue; + } + + if (! $token->isArray()) { + continue; + } + + $this->processFunctionOrArray($tokens, $position); + } + } + + /** + * Must run before + * + * @see \PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer::getPriority() + */ + #[Override] + public function getPriority(): int + { + return 5; + } + + /** + * @param array $configuration + */ + public function configure(array $configuration): void + { + $this->lineLength = $configuration[self::LINE_LENGTH] ?? self::DEFAULT_LINE_LENGHT; + $this->breakLongLines = $configuration[self::BREAK_LONG_LINES] ?? true; + $this->inlineShortLines = $configuration[self::INLINE_SHORT_LINES] ?? true; + } + + public function getConfigurationDefinition(): FixerConfigurationResolverInterface + { + throw new ShouldNotHappenException(); + } + + /** + * @param Tokens $tokens + */ + private function processMethodCall(Tokens $tokens, int $position): void + { + $methodNamePosition = $this->functionCallNameMatcher->matchName($tokens, $position); + if ($methodNamePosition === null) { + return; + } + + $blockInfo = $this->blockFinder->findInTokensByPositionAndContent($tokens, $methodNamePosition, '('); + if (! $blockInfo instanceof BlockInfo) { + return; + } + + // has comments => dangerous to change: https://github.com/symplify/symplify/issues/973 + $comments = $tokens->findGivenKind(T_COMMENT, $blockInfo->getStart(), $blockInfo->getEnd()); + if ($comments !== []) { + return; + } + + $this->lineLengthTransformer->fixStartPositionToEndPosition( + $blockInfo, + $tokens, + $this->lineLength, + $this->breakLongLines, + $this->inlineShortLines + ); + } + + /** + * @param Tokens $tokens + */ + private function processFunctionOrArray(Tokens $tokens, int $position): void + { + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $position); + if (! $blockInfo instanceof BlockInfo) { + return; + } + + // @todo is __construct() class method and is newline parma enabled? → skip it + if ($this->standaloneLineConstructorParamFixer && $this->methodNameResolver->isMethodName( + $tokens, + $position, + '__construct' + )) { + return; + } + + if ($this->shouldSkip($tokens, $blockInfo)) { + return; + } + + $this->lineLengthTransformer->fixStartPositionToEndPosition( + $blockInfo, + $tokens, + $this->lineLength, + $this->breakLongLines, + $this->inlineShortLines + ); + } + + /** + * @param Tokens $tokens + */ + private function shouldSkip(Tokens $tokens, BlockInfo $blockInfo): bool + { + // no items inside => skip + if ($blockInfo->getEnd() - $blockInfo->getStart() <= 1) { + return true; + } + + if ($this->heredocAnalyzer->isHerenowDoc($tokens, $blockInfo)) { + return true; + } + + // is array with indexed values "=>" + $doubleArrowTokens = $tokens->findGivenKind(T_DOUBLE_ARROW, $blockInfo->getStart(), $blockInfo->getEnd()); + if ($doubleArrowTokens !== []) { + return true; + } + + // has comments => dangerous to change: https://github.com/symplify/symplify/issues/973 + return (bool) $tokens->findGivenKind(T_COMMENT, $blockInfo->getStart(), $blockInfo->getEnd()); + } +} diff --git a/packages/coding-standard/src/Fixer/Naming/ClassNameResolver.php b/packages/coding-standard/src/Fixer/Naming/ClassNameResolver.php new file mode 100644 index 00000000000..f0ecb77b05f --- /dev/null +++ b/packages/coding-standard/src/Fixer/Naming/ClassNameResolver.php @@ -0,0 +1,65 @@ + + */ + private array $classNameByFilePath = []; + + /** + * @param Tokens $tokens + */ + public function resolveClassName(SplFileInfo $splFileInfo, Tokens $tokens): ?string + { + $filePath = $splFileInfo->getRealPath(); + + if (isset($this->classNameByFilePath[$filePath])) { + return $this->classNameByFilePath[$filePath]; + } + + $classLikeName = $this->resolveFromTokens($tokens); + if (! is_string($classLikeName)) { + return null; + } + + $this->classNameByFilePath[$filePath] = $classLikeName; + + return $classLikeName; + } + + /** + * @param Tokens $tokens + */ + private function resolveFromTokens(Tokens $tokens): ?string + { + foreach ($tokens as $position => $token) { + if (! $token->isGivenKind([T_CLASS, T_TRAIT, T_INTERFACE])) { + continue; + } + + $nextNextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($position + 1); + + if ($nextNextMeaningfulTokenIndex === null) { + continue; + } + + $nextNextMeaningfulToken = $tokens[$nextNextMeaningfulTokenIndex]; + + // skip anonymous classes + if (! $nextNextMeaningfulToken->isGivenKind(T_STRING)) { + continue; + } + + return $nextNextMeaningfulToken->getContent(); + } + + return null; + } +} diff --git a/packages/coding-standard/src/Fixer/Naming/MethodNameResolver.php b/packages/coding-standard/src/Fixer/Naming/MethodNameResolver.php new file mode 100644 index 00000000000..1fdaa71eb6d --- /dev/null +++ b/packages/coding-standard/src/Fixer/Naming/MethodNameResolver.php @@ -0,0 +1,44 @@ + $tokens + */ + public function resolve(Tokens $tokens, int $currentPosition): ?string + { + foreach ($tokens as $position => $token) { + if ($position <= $currentPosition) { + continue; + } + + if (! $token->isGivenKind([T_FUNCTION])) { + continue; + } + + $nextNextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($position + 1); + + if ($nextNextMeaningfulTokenIndex === null) { + continue; + } + + $nextNextMeaningfulToken = $tokens[$nextNextMeaningfulTokenIndex]; + + // skip anonymous functions + if (! $nextNextMeaningfulToken->isGivenKind(T_STRING)) { + continue; + } + + return $nextNextMeaningfulToken->getContent(); + } + + return null; + } +} diff --git a/packages/coding-standard/src/Fixer/Naming/PropertyNameResolver.php b/packages/coding-standard/src/Fixer/Naming/PropertyNameResolver.php new file mode 100644 index 00000000000..954eb334ef4 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Naming/PropertyNameResolver.php @@ -0,0 +1,31 @@ + $tokens + */ + public function resolve(Tokens $tokens, int $currentPosition): ?string + { + foreach ($tokens as $position => $token) { + if ($position <= $currentPosition) { + continue; + } + + if (! $token->isGivenKind([T_VARIABLE])) { + continue; + } + + return $token->getContent(); + } + + return null; + } +} diff --git a/packages/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php b/packages/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php new file mode 100644 index 00000000000..26e65d84c54 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Spacing/MethodChainingNewlineFixer.php @@ -0,0 +1,155 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound([T_OBJECT_OPERATOR]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + // function arguments, function call parameters, lambda use() + for ($index = 1, $count = count($tokens); $index < $count; ++$index) { + $currentToken = $tokens[$index]; + if (! $currentToken->isGivenKind(T_OBJECT_OPERATOR)) { + continue; + } + + if (! $this->shouldPrefixNewline($tokens, $index)) { + continue; + } + + $tokens->ensureWhitespaceAtIndex($index, 0, $this->whitespacesFixerConfig->getLineEnding()); + ++$index; + } + } + + /** + * @param Tokens $tokens + */ + private function shouldPrefixNewline(Tokens $tokens, int $objectOperatorIndex): bool + { + for ($i = $objectOperatorIndex; $i >= 0; --$i) { + /** @var Token $currentToken */ + $currentToken = $tokens[$i]; + + if ($currentToken->equals(')')) { + return $this->shouldBracketPrefix($tokens, $i, $objectOperatorIndex); + } + + if ($currentToken->isGivenKind([T_NEW, T_VARIABLE])) { + return false; + } + + if ($currentToken->getContent() === '(') { + return false; + } + } + + return false; + } + + /** + * @param Tokens $tokens + */ + private function isDoubleBracket(Tokens $tokens, int $position): bool + { + /** @var int $nextTokenPosition */ + $nextTokenPosition = $tokens->getNextNonWhitespace($position); + + /** @var Token $nextToken */ + $nextToken = $tokens[$nextTokenPosition]; + return $nextToken->getContent() === ')'; + } + + /** + * Matches e.g.: - app([ ])->some() + * + * @param Tokens $tokens + */ + private function isPrecededByOpenedCallInAnotherBracket(Tokens $tokens, int $position): bool + { + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $position); + if (! $blockInfo instanceof BlockInfo) { + return false; + } + + return $tokens->isPartialCodeMultiline($blockInfo->getStart(), $blockInfo->getEnd()); + } + + /** + * @param Tokens $tokens + */ + private function shouldBracketPrefix(Tokens $tokens, int $position, int $objectOperatorIndex): bool + { + if ($this->isDoubleBracket($tokens, $position)) { + return false; + } + + if ($this->chainMethodCallAnalyzer->isPartOfMethodCallOrArray($tokens, $position)) { + return false; + } + + if ($this->chainMethodCallAnalyzer->isPrecededByFuncCall($tokens, $position)) { + return false; + } + + if ($this->isPrecededByOpenedCallInAnotherBracket($tokens, $position)) { + return false; + } + + // all good, there is a newline + return ! $tokens->isPartialCodeMultiline($position, $objectOperatorIndex); + } +} diff --git a/packages/coding-standard/src/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer.php b/packages/coding-standard/src/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer.php new file mode 100644 index 00000000000..1d8a6028971 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer.php @@ -0,0 +1,63 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound([T_START_HEREDOC, T_START_NOWDOC]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + // function arguments, function call parameters, lambda use() + for ($position = count($tokens) - 1; $position >= 0; --$position) { + /** @var Token $token */ + $token = $tokens[$position]; + + if (! $token->isGivenKind(T_END_HEREDOC)) { + continue; + } + + // nothing + if (! isset($tokens[$position + 1])) { + continue; + } + + /** @var Token $nextToken */ + $nextToken = $tokens[$position + 1]; + if (! in_array($nextToken->getContent(), [',', ']'], true)) { + continue; + } + + $tokens->ensureWhitespaceAtIndex($position + 1, 0, PHP_EOL); + } + } +} diff --git a/packages/coding-standard/src/Fixer/Spacing/StandaloneLineConstructorParamFixer.php b/packages/coding-standard/src/Fixer/Spacing/StandaloneLineConstructorParamFixer.php new file mode 100644 index 00000000000..8a92d706ef1 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Spacing/StandaloneLineConstructorParamFixer.php @@ -0,0 +1,75 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isTokenKindFound(T_FUNCTION); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + // function arguments, function call parameters, lambda use() + for ($position = count($tokens) - 1; $position >= 0; --$position) { + /** @var Token $token */ + $token = $tokens[$position]; + + if (! $token->isGivenKind(T_FUNCTION)) { + continue; + } + + if (! $this->methodNameResolver->isMethodName($tokens, $position, '__construct')) { + continue; + } + + $this->paramNewliner->processFunction($tokens, $position); + } + } +} diff --git a/packages/coding-standard/src/Fixer/Spacing/StandaloneLinePromotedPropertyFixer.php b/packages/coding-standard/src/Fixer/Spacing/StandaloneLinePromotedPropertyFixer.php new file mode 100644 index 00000000000..f21b1b6cefe --- /dev/null +++ b/packages/coding-standard/src/Fixer/Spacing/StandaloneLinePromotedPropertyFixer.php @@ -0,0 +1,80 @@ + $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAnyTokenKindsFound([ + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, + ]); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + // function arguments, function call parameters, lambda use() + for ($position = count($tokens) - 1; $position >= 0; --$position) { + /** @var Token $token */ + $token = $tokens[$position]; + + if (! $token->isGivenKind([T_FUNCTION])) { + continue; + } + + if (! $this->methodNameResolver->isMethodName($tokens, $position, '__construct')) { + continue; + } + + $this->paramNewliner->processFunction($tokens, $position); + } + } +} diff --git a/packages/coding-standard/src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php b/packages/coding-standard/src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php new file mode 100644 index 00000000000..ed18505d276 --- /dev/null +++ b/packages/coding-standard/src/Fixer/Strict/BlankLineAfterStrictTypesFixer.php @@ -0,0 +1,81 @@ + + */ + private readonly array $declareStrictTypeTokens; + + public function __construct( + private readonly WhitespacesFixerConfig $whitespacesFixerConfig + ) { + $this->declareStrictTypeTokens = [ + new Token([T_DECLARE, 'declare']), + new Token('('), + new Token([T_STRING, 'strict_types']), + new Token('='), + new Token([T_LNUMBER, '1']), + new Token(')'), + new Token(';'), + ]; + } + + public function getDefinition(): FixerDefinitionInterface + { + return new FixerDefinition(self::ERROR_MESSAGE, []); + } + + /** + * @param Tokens $tokens + */ + public function isCandidate(Tokens $tokens): bool + { + return $tokens->isAllTokenKindsFound([T_OPEN_TAG, T_WHITESPACE, T_DECLARE, T_STRING, '=', T_LNUMBER, ';']); + } + + /** + * @param Tokens $tokens + */ + public function fix(SplFileInfo $fileInfo, Tokens $tokens): void + { + $sequenceLocation = $tokens->findSequence($this->declareStrictTypeTokens, 1, 15); + if ($sequenceLocation === null) { + return; + } + + $semicolonPosition = array_key_last($sequenceLocation); + + // empty file + if (! isset($tokens[$semicolonPosition + 2])) { + return; + } + + $lineEnding = $this->whitespacesFixerConfig->getLineEnding(); + + $tokens->ensureWhitespaceAtIndex($semicolonPosition + 1, 0, $lineEnding . $lineEnding); + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/ChainMethodCallAnalyzer.php b/packages/coding-standard/src/TokenAnalyzer/ChainMethodCallAnalyzer.php new file mode 100644 index 00000000000..74e893f5675 --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/ChainMethodCallAnalyzer.php @@ -0,0 +1,108 @@ +some(), app()->some(), (clone app)->some() + * + * @param Tokens $tokens + */ + public function isPrecededByFuncCall(Tokens $tokens, int $position): bool + { + for ($i = $position; $i >= 0; --$i) { + /** @var Token $currentToken */ + $currentToken = $tokens[$i]; + + if ($currentToken->getContent() === 'clone') { + return true; + } + + if ($currentToken->getContent() === '(') { + return $this->newlineAnalyzer->doesContentBeforeBracketRequireNewline($tokens, $i); + } + + if ($this->newlineAnalyzer->isNewlineToken($currentToken)) { + return false; + } + } + + return false; + } + + /** + * Matches e.g. someMethod($this->some()->method()), [$this->some()->method()] + * + * @param Tokens $tokens + */ + public function isPartOfMethodCallOrArray(Tokens $tokens, int $position): bool + { + $this->bracketNesting = 0; + + for ($i = $position; $i >= 0; --$i) { + /** @var Token $currentToken */ + $currentToken = $tokens[$i]; + + // break + if ($this->newlineAnalyzer->isNewlineToken($currentToken)) { + return false; + } + + if ($this->isBreakingChar($currentToken)) { + return true; + } + + if ($this->shouldBreakOnBracket($currentToken)) { + return true; + } + } + + return false; + } + + private function isBreakingChar(Token $currentToken): bool + { + if ($currentToken->isGivenKind([CT::T_ARRAY_SQUARE_BRACE_OPEN, T_ARRAY, T_DOUBLE_COLON])) { + return true; + } + + if ($currentToken->getContent() === '[') { + return true; + } + + return $currentToken->getContent() === '.'; + } + + private function shouldBreakOnBracket(Token $token): bool + { + if ($token->getContent() === ')') { + --$this->bracketNesting; + return false; + } + + if ($token->getContent() === '(') { + if ($this->bracketNesting !== 0) { + ++$this->bracketNesting; + return false; + } + + return true; + } + + return false; + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php b/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php new file mode 100644 index 00000000000..978f7e7c767 --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php @@ -0,0 +1,56 @@ + + */ + private array $functionTokens; + + private readonly FunctionsAnalyzer $functionsAnalyzer; + + public function __construct( + ) { + $this->functionsAnalyzer = new FunctionsAnalyzer(); + + $this->functionTokens = [ + new Token([T_FUNCTION, 'function']), + ]; + + // only in PHP 7.4+ + if ($this->doesFnTokenExist()) { + $this->functionTokens[] = new Token([T_FN, 'fn']); + } + } + + /** + * @return string[] + * @param Tokens $tokens + */ + public function resolve(Tokens $tokens, int $docTokenPosition): array + { + $functionTokenPosition = $tokens->getNextTokenOfKind($docTokenPosition, $this->functionTokens); + if ($functionTokenPosition === null) { + return []; + } + + /** @var array $functionArgumentAnalyses */ + $functionArgumentAnalyses = $this->functionsAnalyzer->getFunctionArguments($tokens, $functionTokenPosition); + + return array_keys($functionArgumentAnalyses); + } + + private function doesFnTokenExist(): bool + { + return PHP_VERSION_ID >= 70400 + && defined('T_FN'); + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/FunctionCallNameMatcher.php b/packages/coding-standard/src/TokenAnalyzer/FunctionCallNameMatcher.php new file mode 100644 index 00000000000..aa33c9fd17e --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/FunctionCallNameMatcher.php @@ -0,0 +1,49 @@ + $tokens + */ + public function matchName(Tokens $tokens, int $position): ?int + { + try { + $blockStart = $tokens->findBlockStart(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $position); + } catch (Throwable) { + // not a block start + return null; + } + + $previousTokenPosition = $blockStart - 1; + /** @var Token $possibleMethodNameToken */ + $possibleMethodNameToken = $tokens[$previousTokenPosition]; + + // not a "methodCall()" + if (! $possibleMethodNameToken->isGivenKind(T_STRING)) { + return null; + } + + // starts with small letter? + $content = $possibleMethodNameToken->getContent(); + if (! ctype_lower($content[0])) { + return null; + } + + // is "someCall()"? we don't care, there are no arguments + if ($tokens[$blockStart + 1]->equals(')')) { + return null; + } + + return $previousTokenPosition; + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/HeredocAnalyzer.php b/packages/coding-standard/src/TokenAnalyzer/HeredocAnalyzer.php new file mode 100644 index 00000000000..31797528b04 --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/HeredocAnalyzer.php @@ -0,0 +1,39 @@ + $tokens + */ + public function isHerenowDoc(Tokens $tokens, BlockInfo $blockInfo): bool + { + // heredoc/nowdoc => skip + $nextToken = $this->getNextMeaningfulToken($tokens, $blockInfo->getStart()); + if (! $nextToken instanceof Token) { + return false; + } + + return \str_contains($nextToken->getContent(), '<<<'); + } + + /** + * @param Tokens $tokens + */ + private function getNextMeaningfulToken(Tokens $tokens, int $index): ?Token + { + $nextMeaningfulTokenPosition = $tokens->getNextMeaningfulToken($index); + if ($nextMeaningfulTokenPosition === null) { + return null; + } + + return $tokens[$nextMeaningfulTokenPosition]; + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/Naming/MethodNameResolver.php b/packages/coding-standard/src/TokenAnalyzer/Naming/MethodNameResolver.php new file mode 100644 index 00000000000..da24a6fc870 --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/Naming/MethodNameResolver.php @@ -0,0 +1,56 @@ + $tokens + */ + public function isMethodName(Tokens $tokens, int $position, string $desiredMethodName): bool + { + $methodName = $this->getMethodName($tokens, $position); + if (! is_string($methodName)) { + return false; + } + + return $methodName === $desiredMethodName; + } + + /** + * @param Tokens $tokens + */ + private function getMethodName(Tokens $tokens, int $position): ?string + { + /** @var Token $currentToken */ + $currentToken = $tokens[$position]; + if (! $currentToken->isGivenKind(T_FUNCTION)) { + return null; + } + + $nextToken = $this->getNextMeaningfulToken($tokens, $position); + if (! $nextToken instanceof Token) { + return null; + } + + return $nextToken->getContent(); + } + + /** + * @param Tokens $tokens + */ + private function getNextMeaningfulToken(Tokens $tokens, int $index): ?Token + { + $nextMeaningfulTokenPosition = $tokens->getNextMeaningfulToken($index); + if ($nextMeaningfulTokenPosition === null) { + return null; + } + + return $tokens[$nextMeaningfulTokenPosition]; + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/NewlineAnalyzer.php b/packages/coding-standard/src/TokenAnalyzer/NewlineAnalyzer.php new file mode 100644 index 00000000000..9172fe06c37 --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/NewlineAnalyzer.php @@ -0,0 +1,49 @@ + $tokens + */ + public function doesContentBeforeBracketRequireNewline(Tokens $tokens, int $i): bool + { + $previousMeaningfulTokenPosition = $tokens->getPrevNonWhitespace($i); + if ($previousMeaningfulTokenPosition === null) { + return false; + } + + $previousToken = $tokens[$previousMeaningfulTokenPosition]; + if (! $previousToken->isGivenKind(T_STRING)) { + return false; + } + + $previousPreviousMeaningfulTokenPosition = $tokens->getPrevNonWhitespace($previousMeaningfulTokenPosition); + if ($previousPreviousMeaningfulTokenPosition === null) { + return false; + } + + $previousPreviousToken = $tokens[$previousPreviousMeaningfulTokenPosition]; + if ($previousPreviousToken->getContent() === '{') { + return true; + } + + // is a function + return $previousPreviousToken->isGivenKind([T_RETURN, T_DOUBLE_COLON, T_OPEN_CURLY_BRACKET]); + } + + public function isNewlineToken(Token $currentToken): bool + { + if (! $currentToken->isWhitespace()) { + return false; + } + + return \str_contains($currentToken->getContent(), "\n"); + } +} diff --git a/packages/coding-standard/src/TokenAnalyzer/ParamNewliner.php b/packages/coding-standard/src/TokenAnalyzer/ParamNewliner.php new file mode 100644 index 00000000000..f0aa6b3a0df --- /dev/null +++ b/packages/coding-standard/src/TokenAnalyzer/ParamNewliner.php @@ -0,0 +1,34 @@ + $tokens + */ + public function processFunction(Tokens $tokens, int $position): void + { + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $position); + if (! $blockInfo instanceof BlockInfo) { + return; + } + + $this->tokensNewliner->breakItems($blockInfo, $tokens, LineKind::CALLS); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/ArrayAnalyzer.php b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/ArrayAnalyzer.php new file mode 100644 index 00000000000..818c7d453f6 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/ArrayAnalyzer.php @@ -0,0 +1,89 @@ + $tokens + */ + public function getItemCount(Tokens $tokens, BlockInfo $blockInfo): int + { + $nextMeanninfulPosition = $tokens->getNextMeaningfulToken($blockInfo->getStart()); + if ($nextMeanninfulPosition === null) { + return 0; + } + + /** @var Token $nextMeaningfulToken */ + $nextMeaningfulToken = $tokens[$nextMeanninfulPosition]; + + // no elements + if ($this->isArrayCloser($nextMeaningfulToken)) { + return 0; + } + + $itemCount = 1; + $this->traverseArrayWithoutNesting($tokens, $blockInfo, static function (Token $token) use ( + &$itemCount + ): void { + if ($token->getContent() === ',') { + ++$itemCount; + } + }); + + return $itemCount; + } + + /** + * @param Tokens $tokens + */ + public function isIndexedList(Tokens $tokens, BlockInfo $blockInfo): bool + { + $isIndexedList = false; + $this->traverseArrayWithoutNesting($tokens, $blockInfo, static function (Token $token) use ( + &$isIndexedList + ): void { + if ($token->isGivenKind(T_DOUBLE_ARROW)) { + $isIndexedList = true; + } + }); + + return $isIndexedList; + } + + /** + * @param Tokens $tokens + * @param callable(Token $token, int $i, Tokens $tokens): void $callable + */ + public function traverseArrayWithoutNesting(Tokens $tokens, BlockInfo $blockInfo, callable $callable): void + { + for ($i = $blockInfo->getEnd() - 1; $i >= $blockInfo->getStart() + 1; --$i) { + $i = $this->tokenSkipper->skipBlocksReversed($tokens, $i); + + /** @var Token $token */ + $token = $tokens[$i]; + $callable($token, $i, $tokens); + } + } + + private function isArrayCloser(Token $token): bool + { + if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) { + return true; + } + + return $token->getContent() === ')'; + } +} diff --git a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php new file mode 100644 index 00000000000..4d02dfaa9eb --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/BlockFinder.php @@ -0,0 +1,178 @@ + + */ + private const array CONTENT_TO_BLOCK_TYPE = [ + '(' => Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + ')' => Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, + '[' => Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, + ']' => Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, + '{' => Tokens::BLOCK_TYPE_CURLY_BRACE, + '}' => Tokens::BLOCK_TYPE_CURLY_BRACE, + '#[' => Tokens::BLOCK_TYPE_ATTRIBUTE, + ]; + + /** + * @var string[] + */ + private const array START_EDGES = ['(', '[', '{']; + + /** + * Accepts position to both start and end token, e.g. (, ), [, ], {, } also to: "array"(, "function" ...(, "use"(, + * "new" ...( + * + * @param Tokens $tokens + */ + public function findInTokensByEdge(Tokens $tokens, int $position): ?BlockInfo + { + $token = $tokens[$position]; + + if ($token->isGivenKind(T_ATTRIBUTE)) { + return $this->createAttributeBlockInfo($tokens, $position); + } + + // shift "array" to "(", event its position + if ($token->isGivenKind(T_ARRAY)) { + $position = $tokens->getNextMeaningfulToken($position); + + if ($position === null) { + return null; + } + + /** @var Token $token */ + $token = $tokens[$position]; + } + + if ($token->isGivenKind([T_FUNCTION, CT::T_USE_LAMBDA, T_NEW])) { + $position = $tokens->getNextTokenOfKind($position, ['(', ';']); + + if ($position === null) { + return null; + } + + /** @var Token $token */ + $token = $tokens[$position]; + + // end of line was sooner => has no block + if ($token->equals(';')) { + return null; + } + + if ($token->equals('(')) { + $closingPosition = $tokens->getNextMeaningfulToken($position); + if ($closingPosition !== null) { + $closingToken = $tokens[$closingPosition]; + if ($closingToken->equals(')')) { + // function has no arguments + return null; + } + } + } + } + + $blockType = $this->getBlockTypeByToken($token); + + return $this->createBlockInfo($token, $position, $tokens, $blockType); + } + + /** + * @param Tokens $tokens + */ + public function findInTokensByPositionAndContent(Tokens $tokens, int $position, string $content): ?BlockInfo + { + $blockStart = $tokens->getNextTokenOfKind($position, [$content]); + if ($blockStart === null) { + return null; + } + + $blockType = $this->getBlockTypeByContent($content); + + return new BlockInfo($blockStart, $tokens->findBlockEnd($blockType, $blockStart)); + } + + /** + * @return Tokens::BLOCK_TYPE_* + */ + private function getBlockTypeByContent(string $content): int + { + if (isset(self::CONTENT_TO_BLOCK_TYPE[$content])) { + return self::CONTENT_TO_BLOCK_TYPE[$content]; + } + + throw new MissingImplementationException(sprintf( + 'Implementation is missing for "%s" in "%s". Just add it to "%s" property with proper block type', + $content, + __METHOD__, + '$contentToBlockType' + )); + } + + /** + * @return Tokens::BLOCK_TYPE_* + */ + private function getBlockTypeByToken(Token $token): int + { + if ($token->isArray()) { + if (in_array($token->getContent(), ['[', ']'], true)) { + return Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE; + } + + return Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE; + } + + return $this->getBlockTypeByContent($token->getContent()); + } + + /** + * @param Tokens $tokens + * @param Tokens::BLOCK_TYPE_* $blockType + */ + private function createBlockInfo(Token $token, int $position, Tokens $tokens, int $blockType): ?BlockInfo + { + try { + if (in_array($token->getContent(), self::START_EDGES, true)) { + $blockStart = $position; + $blockEnd = $tokens->findBlockEnd($blockType, $blockStart); + } else { + $blockEnd = $position; + $blockStart = $tokens->findBlockStart($blockType, $blockEnd); + } + } catch (Throwable) { + // intentionally, no edge found + return null; + } + + return new BlockInfo($blockStart, $blockEnd); + } + + /** + * @param Tokens $tokens + */ + private function createAttributeBlockInfo(Tokens $tokens, int $position): ?BlockInfo + { + // find optional attribute opener, "#[Some()]" + $openerPosition = $tokens->getNextTokenOfKind($position, ['(']); + if (is_int($openerPosition)) { + $position = $openerPosition; + } + + /** @var Token $token */ + $token = $tokens[$position]; + + return $this->createBlockInfo($token, $position, $tokens, Tokens::BLOCK_TYPE_ATTRIBUTE); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/CallAnalyzer.php b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/CallAnalyzer.php new file mode 100644 index 00000000000..2569ea275e5 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/CallAnalyzer.php @@ -0,0 +1,32 @@ + $tokens + */ + public function isMethodCall(Tokens $tokens, int $bracketPosition): bool + { + $objectToken = new Token([T_OBJECT_OPERATOR, '->']); + $whitespaceToken = new Token([T_WHITESPACE, ' ']); + + $previousTokenOfKindPosition = $tokens->getPrevTokenOfKind($bracketPosition, [$objectToken, $whitespaceToken]); + + // probably a function call + if ($previousTokenOfKindPosition === null) { + return false; + } + + /** @var Token $token */ + $token = $tokens[$previousTokenOfKindPosition]; + + return $token->isGivenKind(T_OBJECT_OPERATOR); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/IndentDetector.php b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/IndentDetector.php new file mode 100644 index 00000000000..5d4fd436d30 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/IndentDetector.php @@ -0,0 +1,47 @@ + $tokens + */ + public function detectOnPosition(Tokens $tokens, int $startIndex): int + { + $indent = $this->whitespacesFixerConfig->getIndent(); + + for ($i = $startIndex; $i > 0; --$i) { + /** @var Token $token */ + $token = $tokens[$i]; + + $lastNewlinePos = strrpos($token->getContent(), "\n"); + + if ($token->isWhitespace() && ! $this->containsOnlySpaces($token->getContent())) { + return substr_count($token->getContent(), $indent, (int) $lastNewlinePos); + } + + if ($lastNewlinePos !== false) { + return substr_count($token->getContent(), $indent, $lastNewlinePos); + } + } + + return 0; + } + + private function containsOnlySpaces(string $tokenContent): bool + { + return trim($tokenContent, ' ') === ''; + } +} diff --git a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php new file mode 100644 index 00000000000..54614f21be6 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php @@ -0,0 +1,101 @@ + $tokens + */ + public function skipBlocks(Tokens $tokens, int $position): int + { + if (! isset($tokens[$position])) { + throw new TokenNotFoundException($position); + } + + $token = $tokens[$position]; + + if ($token->getContent() === '{') { + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $position); + if (! $blockInfo instanceof BlockInfo) { + return $position; + } + + return $blockInfo->getEnd(); + } + + if ($token->isGivenKind([CT::T_ARRAY_SQUARE_BRACE_OPEN, T_ARRAY])) { + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $position); + if (! $blockInfo instanceof BlockInfo) { + return $position; + } + + return $blockInfo->getEnd(); + } + + return $position; + } + + /** + * @param Tokens $tokens + */ + public function skipBlocksReversed(Tokens $tokens, int $position): int + { + /** @var Token $token */ + $token = $tokens[$position]; + if (! $token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE) && ! $token->equals(')') && ! $token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { + return $position; + } + + // Check if this is an attribute closing bracket + if ($token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { + $attributeStartPosition = $this->findAttributeStart($tokens, $position); + if ($attributeStartPosition !== null) { + return $attributeStartPosition; + } + } + + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $position); + if (! $blockInfo instanceof BlockInfo) { + throw new ShouldNotHappenException(); + } + + return $blockInfo->getStart(); + } + + /** + * @param Tokens $tokens + */ + private function findAttributeStart(Tokens $tokens, int $closingBracketPosition): ?int + { + // Search backwards for T_ATTRIBUTE token (#[) + for ($i = $closingBracketPosition - 1; $i >= 0; --$i) { + $currentToken = $tokens[$i]; + + if ($currentToken->isGivenKind(T_ATTRIBUTE)) { + return $i; + } + + // If we hit another ] or reach a statement boundary, stop searching + if ($currentToken->equals(']') || $currentToken->equals(';') || $currentToken->equals('{') || $currentToken->equals('}')) { + break; + } + } + + return null; + } +} diff --git a/packages/coding-standard/src/TokenRunner/Arrays/ArrayItemNewliner.php b/packages/coding-standard/src/TokenRunner/Arrays/ArrayItemNewliner.php new file mode 100644 index 00000000000..2efaf7bee60 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Arrays/ArrayItemNewliner.php @@ -0,0 +1,57 @@ + $tokens + */ + public function fixArrayOpener(Tokens $tokens, BlockInfo $blockInfo): void + { + $this->arrayAnalyzer->traverseArrayWithoutNesting( + $tokens, + $blockInfo, + function (Token $token, int $position, Tokens $tokens): void { + if ($token->getContent() !== ',') { + return; + } + + $nextTokenPosition = $position + 1; + $nextToken = $tokens[$nextTokenPosition] ?? null; + if (! $nextToken instanceof Token) { + return; + } + + if (\str_contains($nextToken->getContent(), "\n")) { + return; + } + + $lookaheadPosition = $tokens->getNonWhitespaceSibling($position, 1, " \t\r\0\x0B"); + if ($lookaheadPosition !== null && $tokens[$lookaheadPosition]->isGivenKind(T_COMMENT)) { + return; + } + + if ($nextToken->getContent() === '{') { + return; + } + + $tokens->ensureWhitespaceAtIndex($nextTokenPosition, 0, $this->whitespacesFixerConfig->getLineEnding()); + } + ); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Enum/LineKind.php b/packages/coding-standard/src/TokenRunner/Enum/LineKind.php new file mode 100644 index 00000000000..d06ff4c1eef --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Enum/LineKind.php @@ -0,0 +1,15 @@ + $tokens + */ + public function getPreviousMeaningfulToken(Tokens $tokens, int | Token $position): Token + { + if (is_int($position)) { + return $this->findPreviousTokenByPosition($tokens, $position); + } + + return $this->findPreviousTokenByToken($tokens, $position); + } + + /** + * @param Tokens $tokens + */ + private function findPreviousTokenByPosition(Tokens $tokens, int $position): Token + { + $previousPosition = $position - 1; + if (! isset($tokens[$previousPosition])) { + throw new ShouldNotHappenException(); + } + + return $tokens[$previousPosition]; + } + + /** + * @param Tokens $tokens + */ + private function findPreviousTokenByToken(Tokens $tokens, Token $positionToken): Token + { + $position = $this->resolvePositionByToken($tokens, $positionToken); + return $this->findPreviousTokenByPosition($tokens, $position - 1); + } + + /** + * @param Tokens $tokens + */ + private function resolvePositionByToken(Tokens $tokens, Token $positionToken): int + { + foreach ($tokens as $position => $token) { + if ($token === $positionToken) { + return $position; + } + } + + throw new ShouldNotHappenException(); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/FirstLineLengthResolver.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/FirstLineLengthResolver.php new file mode 100644 index 00000000000..e0bc51a8ed8 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/FirstLineLengthResolver.php @@ -0,0 +1,90 @@ + $tokens + */ + public function resolveFromTokensAndStartPosition(Tokens $tokens, BlockInfo $blockInfo): int + { + // compute from here to start of line + $currentPosition = $blockInfo->getStart(); + + // collect length of tokens on current line which precede token at $currentPosition + $lineLengthAndPosition = $this->lineLengthAndPositionFactory->createFromTokensAndLineStartPosition( + $tokens, + $currentPosition + ); + $lineLength = $lineLengthAndPosition->getLineLength(); + $currentPosition = $lineLengthAndPosition->getCurrentPosition(); + + /** @var Token $currentToken */ + $currentToken = $tokens[$currentPosition]; + + // includes indent in the beginning + $lineLength += strlen($currentToken->getContent()); + + // minus end of lines, do not count line feeds as characters + $endOfLineCount = substr_count($currentToken->getContent(), "\n"); + $lineLength -= $endOfLineCount; + + // compute from here to end of line + $currentPosition = $blockInfo->getStart() + 1; + + // collect length of tokens on current line which follow token at $currentPosition + while (! $this->isEndOFArgumentsLine($tokens, $currentPosition)) { + /** @var Token $currentToken */ + $currentToken = $tokens[$currentPosition]; + + // in case of multiline string, we are interested in length of the part on current line only + $explode = explode("\n", $currentToken->getContent(), 2); + // string follows current token, so we are interested in beginning only + $lineLength += strlen($explode[0]); + + ++$currentPosition; + + if (count($explode) > 1) { + // no longer need to continue searching for end of arguments + break; + } + + if (! isset($tokens[$currentPosition])) { + break; + } + } + + return $lineLength; + } + + /** + * @param Tokens $tokens + */ + private function isEndOFArgumentsLine(Tokens $tokens, int $position): bool + { + if (! isset($tokens[$position])) { + throw new TokenNotFoundException($position); + } + + if (\str_starts_with($tokens[$position]->getContent(), "\n")) { + return true; + } + + return $tokens[$position]->isGivenKind(CT::T_USE_LAMBDA); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthCloserTransformer.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthCloserTransformer.php new file mode 100644 index 00000000000..4a6ff995b74 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthCloserTransformer.php @@ -0,0 +1,81 @@ + $tokens + */ + public function insertNewlineBeforeClosingIfNeeded( + Tokens $tokens, + BlockInfo $blockInfo, + int $kind, + string $newlineIndentWhitespace, + string $closingBracketNewlineIndentWhitespace + ): void { + $isMethodCall = $this->callAnalyzer->isMethodCall($tokens, $blockInfo->getStart()); + $endIndex = $blockInfo->getEnd(); + + $previousToken = $this->tokenFinder->getPreviousMeaningfulToken($tokens, $endIndex); + $previousPreviousToken = $this->tokenFinder->getPreviousMeaningfulToken($tokens, $previousToken); + + // special case, if the function is followed by array - method([...]) - but not - method([[...]])) + if ($this->shouldAddNewlineEarlier($previousToken, $previousPreviousToken, $isMethodCall, $kind)) { + $tokens->ensureWhitespaceAtIndex($endIndex - 1, 0, $newlineIndentWhitespace); + return; + } + + $tokens->ensureWhitespaceAtIndex($endIndex - 1, 1, $closingBracketNewlineIndentWhitespace); + } + + private function shouldAddNewlineEarlier( + Token $previousToken, + Token $previousPreviousToken, + bool $isMethodCall, + int $kind + ): bool { + if ($isMethodCall) { + return false; + } + + if ($kind !== LineKind::CALLS) { + return false; + } + + if (! $previousToken->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) { + return false; + } + + if ($this->isEmptyArray($previousPreviousToken)) { + return false; + } + + return ! $previousPreviousToken->isGivenKind([CT::T_ARRAY_SQUARE_BRACE_CLOSE, CT::T_ARRAY_SQUARE_BRACE_OPEN]); + } + + private function isEmptyArray(Token $token): bool + { + if (! $token->isArray()) { + return false; + } + + return trim($token->getContent()) === ''; + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthOpenerTransformer.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthOpenerTransformer.php new file mode 100644 index 00000000000..8295a4bece9 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthOpenerTransformer.php @@ -0,0 +1,51 @@ + $tokens + */ + public function insertNewlineAfterOpeningIfNeeded( + Tokens $tokens, + int $blockStartIndex, + string $newlineIndentWhitespace + ): void { + if (! isset($tokens[$blockStartIndex + 1])) { + throw new TokenNotFoundException($blockStartIndex + 1); + } + + /** @var Token $nextToken */ + $nextToken = $tokens[$blockStartIndex + 1]; + + if ($nextToken->isGivenKind(T_WHITESPACE)) { + $tokens->ensureWhitespaceAtIndex($blockStartIndex + 1, 0, $newlineIndentWhitespace); + return; + } + + // special case, if the function is followed by array - method([...]) + if ($nextToken->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]) && ! $this->callAnalyzer->isMethodCall( + $tokens, + $blockStartIndex + )) { + $tokens->ensureWhitespaceAtIndex($blockStartIndex + 1, 1, $newlineIndentWhitespace); + return; + } + + $tokens->ensureWhitespaceAtIndex($blockStartIndex, 1, $newlineIndentWhitespace); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthResolver.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthResolver.php new file mode 100644 index 00000000000..a5cfd078f53 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthResolver.php @@ -0,0 +1,114 @@ + $tokens + */ + public function getLengthFromStartEnd(Tokens $tokens, BlockInfo $blockInfo): int + { + $lineLength = 0; + + // compute from function to start of line + $start = $blockInfo->getStart(); + while (! $this->isNewLineOrOpenTag($tokens, $start)) { + $lineLength += strlen($tokens[$start]->getContent()); + --$start; + + if (! isset($tokens[$start])) { + break; + } + } + + // get spaces to first line + $lineLength += strlen($tokens[$start]->getContent()); + + // get length from start of function till end of arguments - with spaces as one + $lineLength += $this->getLengthFromFunctionStartToEndOfArguments($blockInfo, $tokens); + + // get length from end or arguments to first line break + $lineLength += $this->getLengthFromEndOfArgumentToLineBreak($blockInfo, $tokens); + + return $lineLength; + } + + /** + * @param Tokens $tokens + */ + private function isNewLineOrOpenTag(Tokens $tokens, int $position): bool + { + /** @var Token $currentToken */ + $currentToken = $tokens[$position]; + + if (\str_starts_with($currentToken->getContent(), "\n")) { + return true; + } + + return $currentToken->isGivenKind(T_OPEN_TAG); + } + + /** + * @param Tokens $tokens + */ + private function getLengthFromFunctionStartToEndOfArguments(BlockInfo $blockInfo, Tokens $tokens): int + { + $length = 0; + + $start = $blockInfo->getStart(); + + while ($start < $blockInfo->getEnd()) { + /** @var Token $currentToken */ + $currentToken = $tokens[$start]; + + if ($currentToken->isGivenKind(T_WHITESPACE)) { + ++$length; + ++$start; + continue; + } + + $length += strlen($currentToken->getContent()); + ++$start; + + if (! isset($tokens[$start])) { + break; + } + } + + return $length; + } + + /** + * @param Tokens $tokens + */ + private function getLengthFromEndOfArgumentToLineBreak(BlockInfo $blockInfo, Tokens $tokens): int + { + $length = 0; + + $end = $blockInfo->getEnd(); + + /** @var Token $currentToken */ + $currentToken = $tokens[$end]; + + while (! \str_starts_with($currentToken->getContent(), "\n")) { + $length += strlen($currentToken->getContent()); + ++$end; + + if (! isset($tokens[$end])) { + break; + } + + /** @var Token $currentToken */ + $currentToken = $tokens[$end]; + } + + return $length; + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthTransformer.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthTransformer.php new file mode 100644 index 00000000000..8cfb81649fd --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/LineLengthTransformer.php @@ -0,0 +1,68 @@ + $tokens + */ + public function fixStartPositionToEndPosition( + BlockInfo $blockInfo, + Tokens $tokens, + int $lineLength, + bool $breakLongLines, + bool $inlineShortLine + ): void { + if ($this->hasPromotedProperty($tokens, $blockInfo)) { + return; + } + + $firstLineLength = $this->firstLineLengthResolver->resolveFromTokensAndStartPosition($tokens, $blockInfo); + if ($firstLineLength > $lineLength && $breakLongLines) { + $this->tokensNewliner->breakItems($blockInfo, $tokens, LineKind::CALLS); + return; + } + + $fullLineLength = $this->lineLengthResolver->getLengthFromStartEnd($tokens, $blockInfo); + if ($fullLineLength > $lineLength) { + return; + } + + if (! $inlineShortLine) { + return; + } + + $this->tokensInliner->inlineItems($tokens, $blockInfo); + } + + /** + * @param Tokens $tokens + */ + private function hasPromotedProperty(Tokens $tokens, BlockInfo $blockInfo): bool + { + $resultByKind = $tokens->findGivenKind([ + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PUBLIC, + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PROTECTED, + CT::T_CONSTRUCTOR_PROPERTY_PROMOTION_PRIVATE, + ], $blockInfo->getStart(), $blockInfo->getEnd()); + + return (bool) array_filter($resultByKind); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensInliner.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensInliner.php new file mode 100644 index 00000000000..9e2fc191a46 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensInliner.php @@ -0,0 +1,62 @@ + $tokens + */ + public function inlineItems(Tokens $tokens, BlockInfo $blockInfo): void + { + // replace line feeds with " " + for ($i = $blockInfo->getStart() + 1; $i < $blockInfo->getEnd(); ++$i) { + /** @var Token $currentToken */ + $currentToken = $tokens[$i]; + $i = $this->tokenSkipper->skipBlocks($tokens, $i); + if (! $currentToken->isGivenKind(T_WHITESPACE)) { + continue; + } + + /** @var Token $previousToken */ + $previousToken = $tokens[$i - 1]; + + /** @var Token $nextToken */ + $nextToken = $tokens[$i + 1]; + + // do not clear before *doc end, removing spaces breaks stuff + if ($previousToken->isGivenKind([T_START_HEREDOC, T_END_HEREDOC])) { + continue; + } + + // clear space after opening and before closing bracket + if ($this->isBlockStartOrEnd($previousToken, $nextToken)) { + $tokens->clearAt($i); + continue; + } + + $tokens[$i] = new Token([T_WHITESPACE, ' ']); + } + } + + private function isBlockStartOrEnd(Token $previousToken, Token $nextToken): bool + { + if (in_array($previousToken->getContent(), ['(', '['], true)) { + return true; + } + + return in_array($nextToken->getContent(), [')', ']'], true); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensNewliner.php b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensNewliner.php new file mode 100644 index 00000000000..eca2e39ecfa --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Transformer/FixerTransformer/TokensNewliner.php @@ -0,0 +1,116 @@ + $tokens + */ + public function breakItems(BlockInfo $blockInfo, Tokens $tokens, int $kind): void + { + // from bottom top, to prevent skipping ids + // e.g when token is added in the middle, the end index does now point to earlier element! + $currentNewlineIndentWhitespace = $this->indentResolver->resolveCurrentNewlineIndentWhitespace( + $tokens, + $blockInfo->getStart() + ); + + $newlineIndentWhitespace = $this->indentResolver->resolveNewlineIndentWhitespace( + $tokens, + $blockInfo->getStart() + ); + + // 1. break before arguments closing + $this->lineLengthCloserTransformer->insertNewlineBeforeClosingIfNeeded( + $tokens, + $blockInfo, + $kind, + $currentNewlineIndentWhitespace, + $this->indentResolver->resolveClosingBracketNewlineWhitespace($tokens, $blockInfo->getStart()), + ); + + // again, from the bottom to the top + for ($i = $blockInfo->getEnd() - 1; $i >= $blockInfo->getStart(); --$i) { + $i = $this->tokenSkipper->skipBlocksReversed($tokens, $i); + + /** @var Token $currentToken */ + $currentToken = $tokens[$i]; + + // 2. new line after each comma ",", instead of just space + if ($currentToken->getContent() === ',') { + if ($this->isLastItem($tokens, $i)) { + continue; + } + + if ($this->isFollowedByComment($tokens, $i)) { + continue; + } + + $tokens->ensureWhitespaceAtIndex($i + 1, 0, $newlineIndentWhitespace); + } + } + + // 3. break after arguments opening + $this->lineLengthOpenerTransformer->insertNewlineAfterOpeningIfNeeded( + $tokens, + $blockInfo->getStart(), + $newlineIndentWhitespace + ); + } + + /** + * Has already newline? usually the last line => skip to prevent double spacing + * + * @param Tokens $tokens + */ + private function isLastItem(Tokens $tokens, int $position): bool + { + $nextPosition = $position + 1; + if (! isset($tokens[$nextPosition])) { + throw new TokenNotFoundException($nextPosition); + } + + $tokenContent = $tokens[$nextPosition]->getContent(); + return \str_contains($tokenContent, $this->whitespacesFixerConfig->getLineEnding()); + } + + /** + * @param Tokens $tokens + */ + private function isFollowedByComment(Tokens $tokens, int $i): bool + { + $nextToken = $tokens[$i + 1]; + $nextNextToken = $tokens[$i + 2]; + + if ($nextNextToken->isComment()) { + return true; + } + + // if next token is just space, turn it to newline + if (! $nextToken->isWhitespace(' ')) { + return false; + } + + return $nextNextToken->isComment(); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Traverser/ArrayBlockInfoFinder.php b/packages/coding-standard/src/TokenRunner/Traverser/ArrayBlockInfoFinder.php new file mode 100644 index 00000000000..18069edf7de --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Traverser/ArrayBlockInfoFinder.php @@ -0,0 +1,53 @@ + $tokens + * @return BlockInfo[] + */ + public function findArrayOpenerBlockInfos(Tokens $tokens): array + { + $reversedTokens = $this->reverseTokens($tokens); + + $blockInfos = []; + foreach ($reversedTokens as $index => $token) { + if (! $token->isGivenKind(TokenKinds::ARRAY_OPEN_TOKENS)) { + continue; + } + + $blockInfo = $this->blockFinder->findInTokensByEdge($tokens, $index); + if (! $blockInfo instanceof BlockInfo) { + continue; + } + + $blockInfos[] = $blockInfo; + } + + return $blockInfos; + } + + /** + * @param Tokens $tokens + * @return Token[] + */ + private function reverseTokens(Tokens $tokens): array + { + return array_reverse($tokens->toArray(), true); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Traverser/TokenReverser.php b/packages/coding-standard/src/TokenRunner/Traverser/TokenReverser.php new file mode 100644 index 00000000000..b7aac5f8c1c --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Traverser/TokenReverser.php @@ -0,0 +1,29 @@ + $tokens + * @return Token[] + */ + public function reverse(Tokens $tokens): array + { + $reversedTokens = array_reverse($tokens->toArray(), true); + + // remove null values + return array_filter($reversedTokens); + } +} diff --git a/packages/coding-standard/src/TokenRunner/ValueObject/BlockInfo.php b/packages/coding-standard/src/TokenRunner/ValueObject/BlockInfo.php new file mode 100644 index 00000000000..c9a2ac9ea0d --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/ValueObject/BlockInfo.php @@ -0,0 +1,24 @@ +start; + } + + public function getEnd(): int + { + return $this->end; + } +} diff --git a/packages/coding-standard/src/TokenRunner/ValueObject/LineLengthAndPosition.php b/packages/coding-standard/src/TokenRunner/ValueObject/LineLengthAndPosition.php new file mode 100644 index 00000000000..04a1b84eede --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/ValueObject/LineLengthAndPosition.php @@ -0,0 +1,24 @@ +lineLength; + } + + public function getCurrentPosition(): int + { + return $this->currentPosition; + } +} diff --git a/packages/coding-standard/src/TokenRunner/ValueObject/TokenKinds.php b/packages/coding-standard/src/TokenRunner/ValueObject/TokenKinds.php new file mode 100644 index 00000000000..bf2b7c21ca9 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/ValueObject/TokenKinds.php @@ -0,0 +1,15 @@ + $tokens + */ + public function __construct( + private Tokens $tokens, + private BlockInfo $blockInfo, + private TokenSkipper $tokenSkipper + ) { + } + + public function isAssociativeArray(): bool + { + for ($i = $this->blockInfo->getStart() + 1; $i <= $this->blockInfo->getEnd() - 1; ++$i) { + $i = $this->tokenSkipper->skipBlocks($this->tokens, $i); + + $token = $this->tokens[$i]; + if ($token->isGivenKind(T_DOUBLE_ARROW)) { + return true; + } + } + + return false; + } + + public function getItemCount(): int + { + $itemCount = 0; + for ($i = $this->blockInfo->getEnd() - 1; $i >= $this->blockInfo->getStart(); --$i) { + $i = $this->tokenSkipper->skipBlocksReversed($this->tokens, $i); + + $token = $this->tokens[$i]; + if ($token->isGivenKind(T_DOUBLE_ARROW)) { + ++$itemCount; + } + } + + return $itemCount; + } + + public function isFirstItemArray(): bool + { + for ($i = $this->blockInfo->getEnd() - 1; $i >= $this->blockInfo->getStart(); --$i) { + $i = $this->tokenSkipper->skipBlocksReversed($this->tokens, $i); + + /** @var Token $token */ + $token = $this->tokens[$i]; + if ($token->isGivenKind(T_DOUBLE_ARROW)) { + $nextTokenAfterArrowPosition = $this->tokens->getNextNonWhitespace($i); + if ($nextTokenAfterArrowPosition === null) { + return false; + } + + /** @var Token $nextToken */ + $nextToken = $this->tokens[$nextTokenAfterArrowPosition]; + + return $nextToken->isGivenKind(self::ARRAY_OPEN_TOKENS); + } + } + + return false; + } +} diff --git a/packages/coding-standard/src/TokenRunner/ValueObjectFactory/LineLengthAndPositionFactory.php b/packages/coding-standard/src/TokenRunner/ValueObjectFactory/LineLengthAndPositionFactory.php new file mode 100644 index 00000000000..40dbe032063 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/ValueObjectFactory/LineLengthAndPositionFactory.php @@ -0,0 +1,65 @@ + $tokens + */ + public function createFromTokensAndLineStartPosition(Tokens $tokens, int $currentPosition): LineLengthAndPosition + { + $length = 0; + + while (! $this->isNewLineOrOpenTag($tokens, $currentPosition)) { + // in case of multiline string, we are interested in length of the part on current line only + if (! isset($tokens[$currentPosition])) { + throw new TokenNotFoundException($currentPosition); + } + + /** @var Token $currentToken */ + $currentToken = $tokens[$currentPosition]; + + $explode = explode("\n", $currentToken->getContent()); + // string precedes current token, so we are interested in end part only + $lastSection = end($explode); + $length += strlen($lastSection); + + --$currentPosition; + + if (count($explode) > 1) { + // no longer need to continue searching for newline + break; + } + + if (! isset($tokens[$currentPosition])) { + break; + } + } + + return new LineLengthAndPosition($length, $currentPosition); + } + + /** + * @param Tokens $tokens + */ + private function isNewLineOrOpenTag(Tokens $tokens, int $position): bool + { + if (! isset($tokens[$position])) { + throw new TokenNotFoundException($position); + } + + if (\str_starts_with($tokens[$position]->getContent(), "\n")) { + return true; + } + + return $tokens[$position]->isGivenKind(T_OPEN_TAG); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Whitespace/IndentResolver.php b/packages/coding-standard/src/TokenRunner/Whitespace/IndentResolver.php new file mode 100644 index 00000000000..ad0bdf4073f --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Whitespace/IndentResolver.php @@ -0,0 +1,60 @@ + $tokens + */ + public function resolveClosingBracketNewlineWhitespace(Tokens $tokens, int $startIndex): string + { + $indentLevel = $this->indentDetector->detectOnPosition($tokens, $startIndex); + return $this->whitespacesFixerConfig->getLineEnding() . str_repeat( + $this->whitespacesFixerConfig->getIndent(), + $indentLevel + ); + } + + /** + * @param Tokens $tokens + */ + public function resolveCurrentNewlineIndentWhitespace(Tokens $tokens, int $index): string + { + $indentLevel = $this->indentDetector->detectOnPosition($tokens, $index); + $indentWhitespace = str_repeat($this->whitespacesFixerConfig->getIndent(), $indentLevel); + + return $this->whitespacesFixerConfig->getLineEnding() . $indentWhitespace; + } + + /** + * @param Tokens $tokens + */ + public function resolveNewlineIndentWhitespace(Tokens $tokens, int $index): string + { + $indentWhitespace = $this->resolveIndentWhitespace($tokens, $index); + return $this->whitespacesFixerConfig->getLineEnding() . $indentWhitespace; + } + + /** + * @param Tokens $tokens + */ + private function resolveIndentWhitespace(Tokens $tokens, int $index): string + { + $indentLevel = $this->indentDetector->detectOnPosition($tokens, $index); + return str_repeat($this->whitespacesFixerConfig->getIndent(), $indentLevel + 1); + } +} diff --git a/packages/coding-standard/src/TokenRunner/Wrapper/FixerWrapper/ArrayWrapperFactory.php b/packages/coding-standard/src/TokenRunner/Wrapper/FixerWrapper/ArrayWrapperFactory.php new file mode 100644 index 00000000000..3c050cab792 --- /dev/null +++ b/packages/coding-standard/src/TokenRunner/Wrapper/FixerWrapper/ArrayWrapperFactory.php @@ -0,0 +1,27 @@ + $tokens + */ + public function createFromTokensAndBlockInfo(Tokens $tokens, BlockInfo $blockInfo): ArrayWrapper + { + return new ArrayWrapper($tokens, $blockInfo, $this->tokenSkipper); + } +} diff --git a/packages/coding-standard/src/Utils/Regex.php b/packages/coding-standard/src/Utils/Regex.php new file mode 100644 index 00000000000..30577e4fdb6 --- /dev/null +++ b/packages/coding-standard/src/Utils/Regex.php @@ -0,0 +1,44 @@ +|null + */ + public static function match(string $subject, string $pattern): ?array + { + $matches = []; + if (preg_match($pattern, $subject, $matches) === 1) { + return $matches; + } + + return null; + } + + /** + * @return array> + */ + public static function matchAll(string $subject, string $pattern): array + { + $matches = []; + preg_match_all($pattern, $subject, $matches, PREG_SET_ORDER); + + return $matches; + } + + public static function replace(string $subject, string $pattern, string|callable $replacement = ''): string + { + if (is_callable($replacement)) { + return (string) preg_replace_callback($pattern, $replacement, $subject); + } + + return (string) preg_replace($pattern, $replacement, $subject); + } +} diff --git a/packages/coding-standard/src/ValueObject/BlockInfoMetadata.php b/packages/coding-standard/src/ValueObject/BlockInfoMetadata.php new file mode 100644 index 00000000000..2450e86a7f8 --- /dev/null +++ b/packages/coding-standard/src/ValueObject/BlockInfoMetadata.php @@ -0,0 +1,26 @@ +blockType; + } + + public function getBlockInfo(): BlockInfo + { + return $this->blockInfo; + } +} diff --git a/packages/coding-standard/src/ValueObject/CodingStandardConfig.php b/packages/coding-standard/src/ValueObject/CodingStandardConfig.php new file mode 100644 index 00000000000..784677732f7 --- /dev/null +++ b/packages/coding-standard/src/ValueObject/CodingStandardConfig.php @@ -0,0 +1,13 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/Fixture/with_return_date_time.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/Fixture/with_return_date_time.php.inc new file mode 100644 index 00000000000..bcfcb7a9210 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/Fixture/with_return_date_time.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/RemoveMethodNameDuplicateDescriptionFixerTest.php b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/RemoveMethodNameDuplicateDescriptionFixerTest.php new file mode 100644 index 00000000000..8791f59d398 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/RemoveMethodNameDuplicateDescriptionFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php new file mode 100644 index 00000000000..2f01dd20732 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php @@ -0,0 +1,12 @@ +rules([ + RemoveMethodNameDuplicateDescriptionFixer::class, + ]); +}; diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/simple_annotation.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/simple_annotation.php.inc new file mode 100644 index 00000000000..0e40bbb334d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/simple_annotation.php.inc @@ -0,0 +1,30 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/skip_non_phpstorm.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/skip_non_phpstorm.php.inc new file mode 100644 index 00000000000..c5f3662ba63 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/Fixture/skip_non_phpstorm.php.inc @@ -0,0 +1,15 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/config/configured_rule.php new file mode 100644 index 00000000000..4ec4d744ea2 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePHPStormAnnotationFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemovePHPStormAnnotationFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/phpstan_annotation.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/phpstan_annotation.php.inc new file mode 100644 index 00000000000..b0bc5e02caa --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/phpstan_annotation.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/psalm_annotation.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/psalm_annotation.php.inc new file mode 100644 index 00000000000..ebd996ad5ca --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/psalm_annotation.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/simple_annotation.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/simple_annotation.php.inc new file mode 100644 index 00000000000..54ef1f785b1 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/simple_annotation.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_multiple_var.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_multiple_var.php.inc new file mode 100644 index 00000000000..51e8afd8131 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_multiple_var.php.inc @@ -0,0 +1,18 @@ + $args + **/ + $args = $firstArgumentValue->getArgs(); + } +} diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_name_in_the_middle.php.inc b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_name_in_the_middle.php.inc new file mode 100644 index 00000000000..967c0849283 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/Fixture/skip_name_in_the_middle.php.inc @@ -0,0 +1,11 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php new file mode 100644 index 00000000000..8c880480729 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php @@ -0,0 +1,12 @@ +rules([ + RemovePropertyVariableNameDescriptionFixer::class, + ]); +}; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/ArrayListItemNewlineFixerTest.php b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/ArrayListItemNewlineFixerTest.php new file mode 100644 index 00000000000..687b8d72565 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/ArrayListItemNewlineFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/simple_two_items.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/simple_two_items.php.inc new file mode 100644 index 00000000000..9b8621a89fa --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/simple_two_items.php.inc @@ -0,0 +1,28 @@ + 1, 'easy' => 2]; + } +} + +?> +----- + 1, +'easy' => 2]; + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_inline_comment.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_inline_comment.php.inc new file mode 100644 index 00000000000..d8fa9173f60 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_inline_comment.php.inc @@ -0,0 +1,14 @@ + 'The first', // Keep comments here + 3 => 'Another', + ]; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_interpolated_string.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_interpolated_string.php.inc new file mode 100644 index 00000000000..e9d94838aec --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_interpolated_string.php.inc @@ -0,0 +1,16 @@ + "{$a},{$b}", + ]; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_non_indexed_items.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_non_indexed_items.php.inc new file mode 100644 index 00000000000..62ad441d1a4 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/Fixture/skip_non_indexed_items.php.inc @@ -0,0 +1,11 @@ + [ + 'node' => '', + 'children' => [ + 'node' => '', + ], + ], + ]; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/config/configured_rule.php new file mode 100644 index 00000000000..2194d4c5dd5 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayListItemNewlineFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(ArrayListItemNewlineFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/ArrayOpenerAndCloserNewlineFixerTest.php b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/ArrayOpenerAndCloserNewlineFixerTest.php new file mode 100644 index 00000000000..b7676274b36 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/ArrayOpenerAndCloserNewlineFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/also_closer.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/also_closer.php.inc new file mode 100644 index 00000000000..4b5151105ca --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/also_closer.php.inc @@ -0,0 +1,29 @@ + ['SomeClass']]; + } +} + +?> +----- + ['SomeClass'] +]; + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/handle_long_line.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/handle_long_line.php.inc new file mode 100644 index 00000000000..d7a69eda3b9 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/handle_long_line.php.inc @@ -0,0 +1,31 @@ +services(); + $services->set(MoveValueObjectsToValueObjectDirectoryRector::class) + ->call('configure', [[MoveValueObjectsToValueObjectDirectoryRector::TYPES => ['ValueObjectInterfaceClassName'], MoveValueObjectsToValueObjectDirectoryRector::SUFFIXES => ['Search'], MoveValueObjectsToValueObjectDirectoryRector::ENABLE_VALUE_OBJECT_GUESSING => true]]); +}; + +?> +----- +services(); + $services->set(MoveValueObjectsToValueObjectDirectoryRector::class) + ->call('configure', [[ +MoveValueObjectsToValueObjectDirectoryRector::TYPES => ['ValueObjectInterfaceClassName'], MoveValueObjectsToValueObjectDirectoryRector::SUFFIXES => ['Search'], MoveValueObjectsToValueObjectDirectoryRector::ENABLE_VALUE_OBJECT_GUESSING => true +]]); +}; + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/nested_array.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/nested_array.php.inc new file mode 100644 index 00000000000..e6e0d8ca96c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/nested_array.php.inc @@ -0,0 +1,19 @@ + ['keyA' => 'valueA']]; + +?> +----- + [ +'keyA' => 'valueA' +] +]; + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/single_element_without_list.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/single_element_without_list.php.inc new file mode 100644 index 00000000000..7602a380195 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/single_element_without_list.php.inc @@ -0,0 +1,39 @@ +render('one_param.twig', ['param' => $param]); + } + + public function getArguments() + { + return [1, 2]; + } +} + +?> +----- +render('one_param.twig', [ +'param' => $param +]); + } + + public function getArguments() + { + return [1, 2]; + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_double_opener.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_double_opener.php.inc new file mode 100644 index 00000000000..e8cf175a45f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_double_opener.php.inc @@ -0,0 +1,16 @@ +set(ArraySyntaxFixer::class) + ->call('configure', [[ + 'syntax' => 'short', + ]]); + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_no_keys.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_no_keys.php.inc new file mode 100644 index 00000000000..1bec6dc1f60 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/Fixture/skip_no_keys.php.inc @@ -0,0 +1,11 @@ + inline_objects( + [new MethodCallRename('Cake\Form\Form', 'errors', 'getErrors')] + ) + ]; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/config/configured_rule.php new file mode 100644 index 00000000000..1e1b06687df --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/ArrayOpenerAndCloserNewlineFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(ArrayOpenerAndCloserNewlineFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct.php.inc new file mode 100644 index 00000000000..5f64dfbe02c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct.php.inc @@ -0,0 +1,12 @@ + 'Happy', + 2 => 'Relaxed', +]; + +$moreEmotions = [1 => 'Happy']; + +$laterEmotions = ['Happy', 'Excited']; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct2.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct2.php.inc new file mode 100644 index 00000000000..54509055b86 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct2.php.inc @@ -0,0 +1,11 @@ + [ + // keep this in line + new Error(5, 'error message'), + ], + 'anotherFilePath' => 'Hou' +]; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct3.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct3.php.inc new file mode 100644 index 00000000000..91cc270a8e7 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct3.php.inc @@ -0,0 +1,8 @@ +/', [ + 'id' => 123, + 'pid' => 456, +], 'http://localhost/123/456']; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct4.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct4.php.inc new file mode 100644 index 00000000000..750b731338a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct4.php.inc @@ -0,0 +1,14 @@ + $this->wrapMessageToStyle((string) $error->getLine(), $error->isFixable()), + 'message' => $this->wrapMessageToStyle($message, $error->isFixable()), + ]; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct6.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct6.php.inc new file mode 100644 index 00000000000..973cfcefba9 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct6.php.inc @@ -0,0 +1,13 @@ + 'Happy', // comment + 2 => 'Relaxed', // comment + 3 => 'Extatic', /* comment */ + /* comment */ + 4 => 'Sexy', + // comment + 5 => 'Finished', +]; diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct7.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct7.php.inc new file mode 100644 index 00000000000..7ef8529c095 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/correct7.php.inc @@ -0,0 +1,15 @@ + 'b', + 'c' => 'd', + ]; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong.php.inc new file mode 100644 index 00000000000..dec2c5fbd9c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong.php.inc @@ -0,0 +1,25 @@ + 'Peter', 2 => 'Paul',]; + +$friends = array(1 => 'Peter', 2 => 'Paul',); + +?> +----- + 'Peter', + 2 => 'Paul', +]; + +$friends = array( + 1 => 'Peter', + 2 => 'Paul', +); + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong2.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong2.php.inc new file mode 100644 index 00000000000..8b6ff6ae3af --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/Fixture/wrong2.php.inc @@ -0,0 +1,52 @@ + $threshold, 'operator' => $operator, + 'prob' => $prob, 'column' => $col, + 'trainingErrorRate' => $errorRate, ]; + } + } + + public function someMethod2() + { + $this->labels = [1 => $this->labels[0], -1 => $this->labels[1]]; + } +} + +?> +----- + $threshold, + 'operator' => $operator, + 'prob' => $prob, + 'column' => $col, + 'trainingErrorRate' => $errorRate, + ]; + } + } + + public function someMethod2() + { + $this->labels = [ + 1 => $this->labels[0], + -1 => $this->labels[1] + ]; + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong3.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong3.php.inc new file mode 100644 index 00000000000..72a8d64d920 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong3.php.inc @@ -0,0 +1,33 @@ + [ + '$controllerClass' => 'SymfonyController' + ]]; + } +} + +?> +----- + [ + '$controllerClass' => 'SymfonyController' + ] + ]; + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong4.php.inc b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong4.php.inc new file mode 100644 index 00000000000..fa433d87792 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/FixturePhp80/wrong4.php.inc @@ -0,0 +1,33 @@ +containerBuilder->prependExtensionConfig('doctrine', [ + 'orm' => ['mappings' => $entityMappings], + ]); + } +} + +?> +----- +containerBuilder->prependExtensionConfig('doctrine', [ + 'orm' => [ + 'mappings' => $entityMappings + ], + ]); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTest.php b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTest.php new file mode 100644 index 00000000000..cedacbe9171 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTestPhp80Test.php b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTestPhp80Test.php new file mode 100644 index 00000000000..f9d26781803 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/StandaloneLineInMultilineArrayFixerTestPhp80Test.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/FixturePhp80'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/config/configured_rule.php new file mode 100644 index 00000000000..e74cf467fb9 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/ArrayNotation/StandaloneLineInMultilineArrayFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(StandaloneLineInMultilineArrayFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php new file mode 100644 index 00000000000..5078648d86a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/AddMissingParamNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/Fixture/wrong6.php.inc b/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/Fixture/wrong6.php.inc new file mode 100644 index 00000000000..f0e94dfe53e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/Fixture/wrong6.php.inc @@ -0,0 +1,41 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php new file mode 100644 index 00000000000..a3d9374c244 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingParamNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(AddMissingParamNameFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php new file mode 100644 index 00000000000..ba44722bc26 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/AddMissingVarNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above.php.inc b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above.php.inc new file mode 100644 index 00000000000..ed4f08a5f3f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above_many_types.php.inc b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above_many_types.php.inc new file mode 100644 index 00000000000..946775f2cbc --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/Fixture/inlined_var_above_many_types.php.inc @@ -0,0 +1,19 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php new file mode 100644 index 00000000000..6bc21e04435 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/AddMissingVarNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(AddMissingVarNameFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php new file mode 100644 index 00000000000..b46ce6487f2 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/DoubleAsteriskInlineVarFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc b/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc new file mode 100644 index 00000000000..087371c3c84 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/Fixture/single_asterisk.php.inc @@ -0,0 +1,13 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php new file mode 100644 index 00000000000..c932db41432 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/DoubleAsteriskInlineVarFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(DoubleAsteriskInlineVarFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php new file mode 100644 index 00000000000..6efc289e133 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/FixParamNameTypoFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/param_name_wrong.php.inc b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/param_name_wrong.php.inc new file mode 100644 index 00000000000..fb3461f828f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/param_name_wrong.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong11.php.inc b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong11.php.inc new file mode 100644 index 00000000000..a8aad023085 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong11.php.inc @@ -0,0 +1,23 @@ +An existing @param is incorrectly duplicated. + +----- +An existing @param is incorrectly duplicated. + diff --git a/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong12.php.inc b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong12.php.inc new file mode 100644 index 00000000000..e6e8abff73d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/Fixture/wrong12.php.inc @@ -0,0 +1,25 @@ +Wrong @param name is a substring of another param. + +----- +Wrong @param name is a substring of another param. + diff --git a/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php new file mode 100644 index 00000000000..ddc7f4a5dfd --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/FixParamNameTypoFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(FixParamNameTypoFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param.php.inc new file mode 100644 index 00000000000..ebb6c1e9a03 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param.php.inc @@ -0,0 +1,22 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param_only.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param_only.php.inc new file mode 100644 index 00000000000..4233abab624 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/Fixture/dead_param_only.php.inc @@ -0,0 +1,18 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php new file mode 100644 index 00000000000..23c530940f9 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/RemoveDeadParamFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php new file mode 100644 index 00000000000..cdf8fae597e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveDeadParamFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveDeadParamFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/Fixture/param_reference.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/Fixture/param_reference.php.inc new file mode 100644 index 00000000000..e50387f9df4 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/Fixture/param_reference.php.inc @@ -0,0 +1,19 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php new file mode 100644 index 00000000000..d5de0019e0e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/RemoveParamNameReferenceFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php new file mode 100644 index 00000000000..77ffa97de4f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveParamNameReferenceFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveParamNameReferenceFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong10.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong10.php.inc new file mode 100644 index 00000000000..b450a59f809 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong10.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong7.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong7.php.inc new file mode 100644 index 00000000000..ae25e3974e9 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/Fixture/wrong7.php.inc @@ -0,0 +1,105 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php new file mode 100644 index 00000000000..af45d7e07e5 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/RemoveSuperfluousReturnNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php new file mode 100644 index 00000000000..8d2928daf1e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousReturnNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveSuperfluousReturnNameFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/Fixture/wrong8.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/Fixture/wrong8.php.inc new file mode 100644 index 00000000000..7128bb0fe0e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/Fixture/wrong8.php.inc @@ -0,0 +1,59 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php new file mode 100644 index 00000000000..a660b88618a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/RemoveSuperfluousVarNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php new file mode 100644 index 00000000000..29a3fcb5d0f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveSuperfluousVarNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(RemoveSuperfluousVarNameFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_docblock.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_docblock.php.inc new file mode 100644 index 00000000000..725ee08d985 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_docblock.php.inc @@ -0,0 +1,35 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/interface_docblock.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/interface_docblock.php.inc new file mode 100644 index 00000000000..b0c9cc4cd5b --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/interface_docblock.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/trait_docblock.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/trait_docblock.php.inc new file mode 100644 index 00000000000..5d3dfb1d074 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_interface_trait/trait_docblock.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_representing.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_representing.php.inc new file mode 100644 index 00000000000..8d6f24c1c93 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/class_representing.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/constructor_blank.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/constructor_blank.php.inc new file mode 100644 index 00000000000..8105df1392e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/constructor_blank.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/skip_constructor_as_part_of_sentence.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/skip_constructor_as_part_of_sentence.php.inc new file mode 100644 index 00000000000..bd8bb9b3c70 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/constructor/skip_constructor_as_part_of_sentence.php.inc @@ -0,0 +1,13 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/doctrine_generated.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/doctrine_generated.php.inc new file mode 100644 index 00000000000..55079e4cc5d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/doctrine_generated.php.inc @@ -0,0 +1,24 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/name_class_itself.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/name_class_itself.php.inc new file mode 100644 index 00000000000..01a5c4cac55 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/name_class_itself.php.inc @@ -0,0 +1,23 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_bottom_line.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_bottom_line.php.inc new file mode 100644 index 00000000000..fb1c8457134 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_bottom_line.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_property.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_property.php.inc new file mode 100644 index 00000000000..bfd0d0d04b6 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/remove_from_property.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/simple_inline_comment.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/simple_inline_comment.php.inc new file mode 100644 index 00000000000..652da9adf75 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/simple_inline_comment.php.inc @@ -0,0 +1,31 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_1_extra_word_class_method_comment.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_1_extra_word_class_method_comment.php.inc new file mode 100644 index 00000000000..b49193ca020 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_1_extra_word_class_method_comment.php.inc @@ -0,0 +1,13 @@ + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_usefull_class_comment.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_usefull_class_comment.php.inc new file mode 100644 index 00000000000..9b5517a3abd --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/skip_usefull_class_comment.php.inc @@ -0,0 +1,10 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_comment.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_comment.php.inc new file mode 100644 index 00000000000..2f73050ac90 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/todo_comment.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/trait_name_class_itself.php.inc b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/trait_name_class_itself.php.inc new file mode 100644 index 00000000000..f7d773ec31c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/Fixture/trait_name_class_itself.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/RemoveUselessDefaultCommentFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/RemoveUselessDefaultCommentFixerTest.php new file mode 100644 index 00000000000..894f7362ef8 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/RemoveUselessDefaultCommentFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php new file mode 100644 index 00000000000..10574fd3277 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php @@ -0,0 +1,13 @@ +rules([ + RemoveUselessDefaultCommentFixer::class, + BracesFixer::class, + ]); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc b/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc new file mode 100644 index 00000000000..e967b6fa733 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/Fixture/multiline_var.php.inc @@ -0,0 +1,21 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php new file mode 100644 index 00000000000..0d4fe2dd43c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/SingleLineInlineVarDocBlockFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php new file mode 100644 index 00000000000..25ea6027ca6 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/SingleLineInlineVarDocBlockFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(SingleLineInlineVarDocBlockFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/Fixture/wrong3.php.inc b/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/Fixture/wrong3.php.inc new file mode 100644 index 00000000000..f19bdfe0924 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/Fixture/wrong3.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php b/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php new file mode 100644 index 00000000000..63064c95b2a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/SwitchedTypeAndNameFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php new file mode 100644 index 00000000000..4f7d27350c2 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Commenting/SwitchedTypeAndNameFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(SwitchedTypeAndNameFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ArrayLineLengthFixerTest.php b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ArrayLineLengthFixerTest.php new file mode 100644 index 00000000000..3a5df7ae34d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ArrayLineLengthFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/FixtureArray'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ConfiguredLineLengthFixerTest.php b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ConfiguredLineLengthFixerTest.php new file mode 100644 index 00000000000..0d08fed977b --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/ConfiguredLineLengthFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/FixtureConfigured'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/custom_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_attribute.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_attribute.php.inc new file mode 100644 index 00000000000..3ebebb23aa1 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_attribute.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_method_call_with_array.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_method_call_with_array.php.inc new file mode 100644 index 00000000000..24d09fb9090 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_method_call_with_array.php.inc @@ -0,0 +1,26 @@ +someFunction(['foo', 'bar'], ['fooooooooooooooooo', 'baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar']); + } +} + +?> +----- +someFunction( + ['foo', 'bar'], + ['fooooooooooooooooo', 'baaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaar'] + ); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_new_some_object.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_new_some_object.php.inc new file mode 100644 index 00000000000..1ca37d5b43c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/break_new_some_object.php.inc @@ -0,0 +1,21 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct.php.inc new file mode 100644 index 00000000000..8819c4a4d8a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct.php.inc @@ -0,0 +1,21 @@ +someMethod(10, function () { + return 5; + }); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct11.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct11.php.inc new file mode 100644 index 00000000000..8bbf5988339 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct11.php.inc @@ -0,0 +1,11 @@ +prefixDefaultPaginatorOptions("group{$group->getId()}"); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct12.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct12.php.inc new file mode 100644 index 00000000000..18a32173cb9 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct12.php.inc @@ -0,0 +1,16 @@ +completeTagSpaces($comment, $this->originalContent); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct3.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct3.php.inc new file mode 100644 index 00000000000..95a43dd0f3e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct3.php.inc @@ -0,0 +1,14 @@ +assertSame([ + 'one' => 1, + 'two' => 2, + ], $parameterProvider->provide()); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct4.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct4.php.inc new file mode 100644 index 00000000000..a02358524f6 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct4.php.inc @@ -0,0 +1,20 @@ +assertSame([ + 'one' => 1, + 'two' => 2, + ], $parameterProvider->provide()); + + $this->easyCodingStandardStyle->error(sprintf( + 'Found %d error%s.', + $errorCount, + $errorCount === 1 ? '' : 's' + )); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct5.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct5.php.inc new file mode 100644 index 00000000000..b72e53d99e4 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct5.php.inc @@ -0,0 +1,14 @@ + 'looooooooooooooooooooooooooongArraaaaaaaaaaay', 2 => 'looooooooooooooooooooooooooooongArraaaaaaaaaaay']; diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct7.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct7.php.inc new file mode 100644 index 00000000000..207a978a602 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct7.php.inc @@ -0,0 +1,8 @@ +addSubscriber($notifyMeOnVideoPublishedEventSubscriber); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct9.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct9.php.inc new file mode 100644 index 00000000000..c9826f08c5c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct9.php.inc @@ -0,0 +1,15 @@ +someMethod(function () { + return 5; + }); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct_heredoc.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct_heredoc.php.inc new file mode 100644 index 00000000000..3c5189b7ec7 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/correct_heredoc.php.inc @@ -0,0 +1,59 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/inline_new_arguments.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/inline_new_arguments.php.inc new file mode 100644 index 00000000000..d24346b0322 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/inline_new_arguments.php.inc @@ -0,0 +1,14 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/method_call_arguments.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/method_call_arguments.php.inc new file mode 100644 index 00000000000..62a162cd2c6 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/method_call_arguments.php.inc @@ -0,0 +1,33 @@ +someFunctionCall($someLoooooooooooooongArgument, $anotherLoooooooooooooooooooooooooooooooooooongArgumentTo); + + $this->someOtherFunctionCall( + $superShort, + $anotherShort + ); + } +} + +?> +----- +someFunctionCall( + $someLoooooooooooooongArgument, + $anotherLoooooooooooooooooooooooooooooooooooongArgumentTo + ); + + $this->someOtherFunctionCall($superShort, $anotherShort); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_correct_file.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_correct_file.php.inc new file mode 100644 index 00000000000..a759282324d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_correct_file.php.inc @@ -0,0 +1,14 @@ +codeBlocksProtector->protectContentFromCallback($file->getContent(), function (string $content) use ( + $file, + $parameters + ) { + return '...'; + }); + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_property_promotion.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_property_promotion.php.inc new file mode 100644 index 00000000000..4d58395b23c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/skip_property_promotion.php.inc @@ -0,0 +1,14 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong.php.inc new file mode 100644 index 00000000000..352269032b5 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong.php.inc @@ -0,0 +1,44 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong10.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong10.php.inc new file mode 100644 index 00000000000..322ae054fa2 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong10.php.inc @@ -0,0 +1,32 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong11.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong11.php.inc new file mode 100644 index 00000000000..0de1d9cad61 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong11.php.inc @@ -0,0 +1,32 @@ +assertSame( + $parameterProvider->provide(), + [ + 'one' => 1, + 'two' => 2, + ] + ); + } +} + +?> +----- +assertSame($parameterProvider->provide(), [ + 'one' => 1, + 'two' => 2, + ]); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong12.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong12.php.inc new file mode 100644 index 00000000000..b8ecc41818a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong12.php.inc @@ -0,0 +1,26 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong13.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong13.php.inc new file mode 100644 index 00000000000..aa470e53c3f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong13.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong14.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong14.php.inc new file mode 100644 index 00000000000..5696b40cf9c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong14.php.inc @@ -0,0 +1,14 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong15.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong15.php.inc new file mode 100644 index 00000000000..2ef3268d79a --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong15.php.inc @@ -0,0 +1,26 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong16.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong16.php.inc new file mode 100644 index 00000000000..0ea904d8a93 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong16.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong18.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong18.php.inc new file mode 100644 index 00000000000..13d0f7eedfa --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong18.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong2.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong2.php.inc new file mode 100644 index 00000000000..57082efbc2e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong2.php.inc @@ -0,0 +1,36 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong8.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong8.php.inc new file mode 100644 index 00000000000..e46b25842c0 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong8.php.inc @@ -0,0 +1,26 @@ +assertSame(['one' => 1, 'two' => 2, 'fooooooooooooooooooo' => 'baaaaaar'], $parameterProvider->provide()); + } +} + +?> +----- +assertSame( + ['one' => 1, 'two' => 2, 'fooooooooooooooooooo' => 'baaaaaar'], + $parameterProvider->provide() + ); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong9.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong9.php.inc new file mode 100644 index 00000000000..0a02033f796 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong9.php.inc @@ -0,0 +1,31 @@ +getRelativePathname(), $newPackageDirectory . '/' . $fileInfo->getRelativePathname()); + } + } +} + +?> +----- +getRelativePathname(), + $newPackageDirectory . '/' . $fileInfo->getRelativePathname() + ); + } + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong_array_bracket_position_in_arg_list.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong_array_bracket_position_in_arg_list.php.inc new file mode 100644 index 00000000000..b4d0b3bc84e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/Fixture/wrong_array_bracket_position_in_arg_list.php.inc @@ -0,0 +1,29 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/break_func_call_with_array.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/break_func_call_with_array.php.inc new file mode 100644 index 00000000000..e64120ce7d2 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/break_func_call_with_array.php.inc @@ -0,0 +1,46 @@ +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call('configure', [[UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService')])]]); + } +} + +?> +----- +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call( + 'configure', + [[UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([ + new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService') + ])]] + ); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/skip_method_call_with_array.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/skip_method_call_with_array.php.inc new file mode 100644 index 00000000000..609f6388a34 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/skip_method_call_with_array.php.inc @@ -0,0 +1,52 @@ +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call('configure', [[UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => $this->inline_value_objects([new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService')])]]); + } + + private function inline_value_objects(array $array) + { + } +} + +?> +----- +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call( + 'configure', + [[UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => $this->inline_value_objects( + [new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService')] + )]] + ); + } + + private function inline_value_objects(array $array) + { + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/wrong17.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/wrong17.php.inc new file mode 100644 index 00000000000..820d08c051c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureArray/wrong17.php.inc @@ -0,0 +1,26 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureConfigured/configured-wrong.php.inc b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureConfigured/configured-wrong.php.inc new file mode 100644 index 00000000000..fd5d7c7809c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/FixtureConfigured/configured-wrong.php.inc @@ -0,0 +1,24 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/LineLengthFixerTest.php b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/LineLengthFixerTest.php new file mode 100644 index 00000000000..3e14943d8d5 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/LineLengthFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/configured_rule.php new file mode 100644 index 00000000000..dc7c70fb75c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(LineLengthFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/custom_rule.php b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/custom_rule.php new file mode 100644 index 00000000000..f1476a27fbc --- /dev/null +++ b/packages/coding-standard/tests/Fixer/LineLength/LineLengthFixer/config/custom_rule.php @@ -0,0 +1,14 @@ +ruleWithConfiguration(LineLengthFixer::class, [ + LineLengthFixer::LINE_LENGTH => 100, + LineLengthFixer::BREAK_LONG_LINES => true, + LineLengthFixer::INLINE_SHORT_LINES => false, + ]); +}; diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain.php.inc new file mode 100644 index 00000000000..0dd6cfd73f0 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain.php.inc @@ -0,0 +1,33 @@ +one()->two()->three(); + } +} + +?> +----- +one() +->two() +->three(); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain_with_args.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain_with_args.php.inc new file mode 100644 index 00000000000..61becf2fb03 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/many_multi_line_chain_with_args.php.inc @@ -0,0 +1,29 @@ +getChildNodes()->get(0)->getChildNodes(); + } +} + +?> +----- +getChildNodes() +->get(0) +->getChildNodes(); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/multi_line_chain.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/multi_line_chain.php.inc new file mode 100644 index 00000000000..1a4ea88553d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/multi_line_chain.php.inc @@ -0,0 +1,32 @@ +one()->two(); + } +} + +?> +----- +one() +->two(); + } +} + +?> diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_another_line_bracket.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_another_line_bracket.php.inc new file mode 100644 index 00000000000..e2c65305d3d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_another_line_bracket.php.inc @@ -0,0 +1,15 @@ +two([ + 'hey' => 'hou' + ])->three(); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_clone_call.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_clone_call.php.inc new file mode 100644 index 00000000000..498dca6c3cb --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_clone_call.php.inc @@ -0,0 +1,13 @@ +format('date'); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_concat.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_concat.php.inc new file mode 100644 index 00000000000..c5d7a7bcac8 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_concat.php.inc @@ -0,0 +1,13 @@ +symplifyVersionToRequire = '^' . $lastStableVersion->getMajor()->getValue() . '.' . $lastStableVersion->getMinor()->getValue(); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_args_single_method.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_args_single_method.php.inc new file mode 100644 index 00000000000..4a250d13c11 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_args_single_method.php.inc @@ -0,0 +1,11 @@ +set('this', 'that'); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method.php.inc new file mode 100644 index 00000000000..6f340186bd7 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method.php.inc @@ -0,0 +1,11 @@ +one(); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_args.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_args.php.inc new file mode 100644 index 00000000000..facffd28a3c --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_args.php.inc @@ -0,0 +1,11 @@ +set('this', 'that'); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_array.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_array.php.inc new file mode 100644 index 00000000000..e257eaada48 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_single_method_with_array.php.inc @@ -0,0 +1,11 @@ +set(); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_with_method_call.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_with_method_call.php.inc new file mode 100644 index 00000000000..b6935884da3 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_func_call_with_method_call.php.inc @@ -0,0 +1,11 @@ +args($two); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array.php.inc new file mode 100644 index 00000000000..cc09d5d909d --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array.php.inc @@ -0,0 +1,13 @@ +getMajor()->getValue()]; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array_more.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array_more.php.inc new file mode 100644 index 00000000000..6478c5384bb --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_array_more.php.inc @@ -0,0 +1,13 @@ +getMajor()->getValue()]; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_call.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_call.php.inc new file mode 100644 index 00000000000..66c9e2d4cd3 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_in_call.php.inc @@ -0,0 +1,17 @@ +again($version->getMajor()->getValue()); + } + + public function again() + { + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_multi_line_chain.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_multi_line_chain.php.inc new file mode 100644 index 00000000000..ab126d0f31f --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_multi_line_chain.php.inc @@ -0,0 +1,22 @@ +one() + ->two(); + } + + public function one() + { + return $this; + } + + public function two() + { + return $this; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_single_call_on_instantiation.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_single_call_on_instantiation.php.inc new file mode 100644 index 00000000000..04acdfb9c59 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_single_call_on_instantiation.php.inc @@ -0,0 +1,16 @@ +one(); + } + + public function one() + { + return $this; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_static_call_date_time.php.inc b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_static_call_date_time.php.inc new file mode 100644 index 00000000000..014dc7c8ba3 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Fixture/skip_static_call_date_time.php.inc @@ -0,0 +1,15 @@ +getOffset(); + + $starts_date = DateTime::from()->getOffset(); + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/MethodChainingNewlineFixerTest.php b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/MethodChainingNewlineFixerTest.php new file mode 100644 index 00000000000..fe9bcff2fb1 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/MethodChainingNewlineFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Source/SomeClassWithChains.php b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Source/SomeClassWithChains.php new file mode 100644 index 00000000000..fb647490068 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/MethodChainingNewlineFixer/Source/SomeClassWithChains.php @@ -0,0 +1,28 @@ +rule(MethodChainingNewlineFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/end_array.php.inc b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/end_array.php.inc new file mode 100644 index 00000000000..90a403628f3 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/end_array.php.inc @@ -0,0 +1,34 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/wrong.php.inc b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/wrong.php.inc new file mode 100644 index 00000000000..81c76c376dc --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/Fixture/wrong.php.inc @@ -0,0 +1,38 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/SpaceAfterCommaHereNowDocFixerTest.php b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/SpaceAfterCommaHereNowDocFixerTest.php new file mode 100644 index 00000000000..6087af68edc --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/SpaceAfterCommaHereNowDocFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/config/configured_rule.php new file mode 100644 index 00000000000..7ea9ab60ab0 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/SpaceAfterCommaHereNowDocFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(SpaceAfterCommaHereNowDocFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/constructor_params.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/constructor_params.php.inc new file mode 100644 index 00000000000..72d2ab3b151 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/constructor_params.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/empty_constructor.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/empty_constructor.php.inc new file mode 100644 index 00000000000..ea1911e5dd4 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/empty_constructor.php.inc @@ -0,0 +1,13 @@ + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/include_single_item.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/include_single_item.php.inc new file mode 100644 index 00000000000..02f2352cdfe --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/Fixture/include_single_item.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/FixtureContraindications/combination_with_line_lenght_fixer.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/FixtureContraindications/combination_with_line_lenght_fixer.php.inc new file mode 100644 index 00000000000..5524b49c9fc --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/FixtureContraindications/combination_with_line_lenght_fixer.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerContraindicationsTest.php b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerContraindicationsTest.php new file mode 100644 index 00000000000..a425b074235 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerContraindicationsTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/FixtureContraindications'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/contraindications.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerTest.php b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerTest.php new file mode 100644 index 00000000000..6bf99722c76 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/StandaloneLineConstructorParamFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/configured_rule.php new file mode 100644 index 00000000000..668ee2090ba --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(StandaloneLineConstructorParamFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/contraindications.php b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/contraindications.php new file mode 100644 index 00000000000..74df66d15c5 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLineConstructorParamFixer/config/contraindications.php @@ -0,0 +1,15 @@ +rule(StandaloneLineConstructorParamFixer::class); + $ecsConfig->rule(BracesFixer::class); + $ecsConfig->rule(LineLengthFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_properties.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_properties.php.inc new file mode 100644 index 00000000000..b68f0673ed3 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_properties.php.inc @@ -0,0 +1,28 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_property.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_property.php.inc new file mode 100644 index 00000000000..4ea325bb13e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/promoted_property.php.inc @@ -0,0 +1,27 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/skip_attributes.php.inc b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/skip_attributes.php.inc new file mode 100644 index 00000000000..460eb0cbdbc --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/Fixture/skip_attributes.php.inc @@ -0,0 +1,96 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/StandaloneLinePromotedPropertyFixerTest.php b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/StandaloneLinePromotedPropertyFixerTest.php new file mode 100644 index 00000000000..8c0cb5df575 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/StandaloneLinePromotedPropertyFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/config/configured_rule.php new file mode 100644 index 00000000000..cc97cca315e --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Spacing/StandaloneLinePromotedPropertyFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(StandaloneLinePromotedPropertyFixer::class); +}; diff --git a/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/BlankLineAfterStrictTypesFixerTest.php b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/BlankLineAfterStrictTypesFixerTest.php new file mode 100644 index 00000000000..ee18188c5d8 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/BlankLineAfterStrictTypesFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/config/configured_rule.php'; + } +} diff --git a/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/correct.php.inc b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/correct.php.inc new file mode 100644 index 00000000000..6dabfb2d28b --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/correct.php.inc @@ -0,0 +1 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/too_many_between_declare_and_namespace.php.inc b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/too_many_between_declare_and_namespace.php.inc new file mode 100644 index 00000000000..e97a73b09a3 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/Fixture/too_many_between_declare_and_namespace.php.inc @@ -0,0 +1,16 @@ + +----- + diff --git a/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/config/configured_rule.php new file mode 100644 index 00000000000..c30fca0fbe5 --- /dev/null +++ b/packages/coding-standard/tests/Fixer/Strict/BlankLineAfterStrictTypesFixer/config/configured_rule.php @@ -0,0 +1,10 @@ +rule(BlankLineAfterStrictTypesFixer::class); +}; diff --git a/packages/coding-standard/tests/Issues/Fixture/inline_array.php.inc b/packages/coding-standard/tests/Issues/Fixture/inline_array.php.inc new file mode 100644 index 00000000000..c3284e45dd2 --- /dev/null +++ b/packages/coding-standard/tests/Issues/Fixture/inline_array.php.inc @@ -0,0 +1,39 @@ +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call('configure', [[UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService')])]]); +}; + +?> +----- +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call('configure', [[ + UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([ + new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService'), + ]), + ]]); +}; + +?> diff --git a/packages/coding-standard/tests/Issues/Fixture/line_length_parentheses.php.inc b/packages/coding-standard/tests/Issues/Fixture/line_length_parentheses.php.inc new file mode 100644 index 00000000000..b9c9d759af1 --- /dev/null +++ b/packages/coding-standard/tests/Issues/Fixture/line_length_parentheses.php.inc @@ -0,0 +1,21 @@ + +----- + diff --git a/packages/coding-standard/tests/Issues/Fixture/remove_useless_default_comment_and_statement_indentation.php.inc b/packages/coding-standard/tests/Issues/Fixture/remove_useless_default_comment_and_statement_indentation.php.inc new file mode 100644 index 00000000000..1dcbf435807 --- /dev/null +++ b/packages/coding-standard/tests/Issues/Fixture/remove_useless_default_comment_and_statement_indentation.php.inc @@ -0,0 +1,12 @@ +services(); + + $services->set(UnsetAndIssetToMethodCallRector::class) + ->call('configure', [[ + UnsetAndIssetToMethodCallRector::ISSET_UNSET_TO_METHOD_CALL => ValueObjectInliner::inline([ + new IssetUnsetToMethodCall('SomeContainer', 'hasService', 'removeService'), + ]), + ]]); +}; diff --git a/packages/coding-standard/tests/Issues/InlineArrayTest.php b/packages/coding-standard/tests/Issues/InlineArrayTest.php new file mode 100644 index 00000000000..247e593c5d7 --- /dev/null +++ b/packages/coding-standard/tests/Issues/InlineArrayTest.php @@ -0,0 +1,29 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + yield [__DIR__ . '/Fixture/inline_array.php.inc']; + yield [__DIR__ . '/Fixture/skip_already_inlined.php.inc']; + } + + public function provideConfig(): string + { + return __DIR__ . '/config/config_inline_long_array.php'; + } +} diff --git a/packages/coding-standard/tests/Issues/LineLengthParenthesesTest.php b/packages/coding-standard/tests/Issues/LineLengthParenthesesTest.php new file mode 100644 index 00000000000..2297a0b56fc --- /dev/null +++ b/packages/coding-standard/tests/Issues/LineLengthParenthesesTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + yield [__DIR__ . '/Fixture/line_length_parentheses.php.inc']; + } + + public function provideConfig(): string + { + return __DIR__ . '/config/line_length_parentheses.php'; + } +} diff --git a/packages/coding-standard/tests/Issues/RemoveUselessDefaultCommentAndStatementIndentationFixerTest.php b/packages/coding-standard/tests/Issues/RemoveUselessDefaultCommentAndStatementIndentationFixerTest.php new file mode 100644 index 00000000000..619728ca793 --- /dev/null +++ b/packages/coding-standard/tests/Issues/RemoveUselessDefaultCommentAndStatementIndentationFixerTest.php @@ -0,0 +1,28 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + yield [__DIR__ . '/Fixture/remove_useless_default_comment_and_statement_indentation.php.inc']; + } + + public function provideConfig(): string + { + return __DIR__ . '/config/config_remove_useless_default_comment_and_statement_indentation.php'; + } +} diff --git a/packages/coding-standard/tests/Issues/config/config_inline_long_array.php b/packages/coding-standard/tests/Issues/config/config_inline_long_array.php new file mode 100644 index 00000000000..20687b29f01 --- /dev/null +++ b/packages/coding-standard/tests/Issues/config/config_inline_long_array.php @@ -0,0 +1,12 @@ +sets([SetList::ARRAY]); + $ecsConfig->rule(LineLengthFixer::class); +}; diff --git a/packages/coding-standard/tests/Issues/config/config_remove_useless_default_comment_and_statement_indentation.php b/packages/coding-standard/tests/Issues/config/config_remove_useless_default_comment_and_statement_indentation.php new file mode 100644 index 00000000000..143ec7a7b0f --- /dev/null +++ b/packages/coding-standard/tests/Issues/config/config_remove_useless_default_comment_and_statement_indentation.php @@ -0,0 +1,16 @@ +rules([ + BracesFixer::class, + RemoveUselessDefaultCommentFixer::class, + StatementIndentationFixer::class, + ]); +}; diff --git a/packages/coding-standard/tests/Issues/config/line_length_parentheses.php b/packages/coding-standard/tests/Issues/config/line_length_parentheses.php new file mode 100644 index 00000000000..a2cd1bd8015 --- /dev/null +++ b/packages/coding-standard/tests/Issues/config/line_length_parentheses.php @@ -0,0 +1,18 @@ +rules([ + LineLengthFixer::class, + ]); + + $ecsConfig->ruleWithConfiguration(NewWithParenthesesFixer::class, [ + 'anonymous_class' => false, + 'named_class' => false, + ]); +}; diff --git a/packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php b/packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php new file mode 100644 index 00000000000..f522738020e --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php @@ -0,0 +1,31 @@ +doTestFile($filePath); + } + + public static function provideData(): Iterator + { + return self::yieldFiles(__DIR__ . '/Fixture'); + } + + public function provideConfig(): string + { + return __DIR__ . '/../../../config/sets/docblock.php'; + } +} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc new file mode 100644 index 00000000000..a72227a2923 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc @@ -0,0 +1,19 @@ + */ + return $value; +} + +?> +----- + $value */ + return $value; +} + +?> diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc new file mode 100644 index 00000000000..bef5fd842f9 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc @@ -0,0 +1,25 @@ + +----- + diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc new file mode 100644 index 00000000000..d65341b0ac4 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc @@ -0,0 +1,16 @@ + diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc new file mode 100644 index 00000000000..af480314e70 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc @@ -0,0 +1,15 @@ + diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc new file mode 100644 index 00000000000..56c9f374235 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc @@ -0,0 +1,14 @@ +assertEquals('....', $response->getResponse()['message']); + } +} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc new file mode 100644 index 00000000000..7dc477e48bd --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc @@ -0,0 +1,8 @@ +set(Option::IMPORT_DOC_BLOCKS, false); + +} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc new file mode 100644 index 00000000000..ef1e5757ffe --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc @@ -0,0 +1,11 @@ + $foo + */ +function test($foo, $bar): void +{ + +} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc new file mode 100644 index 00000000000..4d33be124bd --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc @@ -0,0 +1,11 @@ + $values + */ + public function run($values) + { + } +} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc new file mode 100644 index 00000000000..233af839ee6 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc @@ -0,0 +1,54 @@ + +----- + diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc new file mode 100644 index 00000000000..130b2e5a95f --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc @@ -0,0 +1,49 @@ + $variable */ +$variable = array(array('hello')); + +/** @var $variable int */ +$variable = 5; + +/** + * @var $variable int + */ +$variable = 5; + +/* + * @var $variable int + */ +$variable = 5; + +/* + * @phpstan-var $variable int + */ +$variable = 5; + +?> +----- + $variable */ +$variable = array(array('hello')); + +/** @var int $variable */ +$variable = 5; + +/** @var int $variable */ +$variable = 5; + +/** @var int $variable */ +$variable = 5; + +/** @phpstan-var int $variable */ +$variable = 5; + +?> diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc new file mode 100644 index 00000000000..a70cc1617c6 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc @@ -0,0 +1,26 @@ + +----- + diff --git a/packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php b/packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php new file mode 100644 index 00000000000..f5908ce3f97 --- /dev/null +++ b/packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php @@ -0,0 +1,9 @@ +\w+)\s+\$(?\w+)#'); + + $this->assertNotNull($match); + $this->assertSame('string', $match['type']); + $this->assertSame('value', $match['name']); + } + + public function testMatchReturnsNullOnNoMatch(): void + { + $this->assertNull(Regex::match('nothing here', '#@param#')); + } + + public function testMatchAllReturnsSetOrder(): void + { + $matches = Regex::matchAll('$a $b $c', '#\$(?\w)#'); + + $this->assertCount(3, $matches); + $this->assertSame('a', $matches[0]['name']); + $this->assertSame('c', $matches[2]['name']); + } + + public function testReplaceWithString(): void + { + $this->assertSame('x-x', Regex::replace('1-2', '#\d#', 'x')); + } + + public function testReplaceWithDefaultRemovesMatch(): void + { + $this->assertSame('abc', Regex::replace('a1b2c3', '#\d#')); + } + + public function testReplaceWithCallable(): void + { + $result = Regex::replace('a1b', '#\d#', static fn (array $match): string => '[' . $match[0] . ']'); + + $this->assertSame('a[1]b', $result); + } +} diff --git a/phpunit.xml b/phpunit.xml index 708465bbb9b..1b4b4cb1cb0 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -9,5 +9,6 @@ > tests + packages/coding-standard/tests From 6e94186328fefd0ba75dfe4c1ff8bd09a3bff780 Mon Sep 17 00:00:00 2001 From: Tomas Votruba Date: Wed, 10 Jun 2026 22:19:40 +0200 Subject: [PATCH 2/2] cleanup --- .github/workflows/buid_release.yaml | 6 +-- .github/workflows/code_analysis.yaml | 2 +- ecs.php | 2 +- .../coding-standard/config/sets/docblock.php | 37 ------------- packages/coding-standard/config/symplify.php | 3 -- .../Commenting/FixParamNameTypoFixer.php | 13 +++-- .../ParamReturnAndVarTagMalformsFixer.php | 4 +- .../DocblockRelatedParamNamesResolver.php | 4 +- .../Analyzer/FixerAnalyzer/TokenSkipper.php | 8 ++- packages/coding-standard/src/Utils/Regex.php | 3 ++ .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 4 +- .../config/configured_rule.php | 6 +-- .../Issues/config/line_length_parentheses.php | 4 +- .../tests/Set/DocblockSet/DocblockSetTest.php | 31 ----------- .../Set/DocblockSet/Fixture/correct.php.inc | 19 ------- .../Set/DocblockSet/Fixture/correct2.php.inc | 27 ---------- .../DocblockSet/Fixture/iterator_flip.php.inc | 19 ------- .../Fixture/param_variable_mallforms.php.inc | 25 --------- ...has_same_param_previous_definition.php.inc | 16 ------ .../Fixture/skip_callable_param.php.inc | 15 ------ .../Fixture/skip_curly_newline.php.inc | 21 -------- .../skip_edge_case_with_assert.php.inc | 14 ----- .../Fixture/skip_inlined_var_in_doc.php.inc | 8 --- .../Fixture/skip_nested_multiline.php.inc | 11 ---- .../Fixture/skip_union_array.php.inc | 11 ---- .../Set/DocblockSet/Fixture/wrong4.php.inc | 54 ------------------- .../Set/DocblockSet/Fixture/wrong5.php.inc | 49 ----------------- .../Set/DocblockSet/Fixture/wrong9.php.inc | 26 --------- .../tests/Set/DocblockSet/Source/Schedule.php | 9 ---- phpstan.neon | 26 ++++++--- rector.php | 2 +- src/Config/Level/DocblockLevel.php | 28 ++++++++++ 33 files changed, 79 insertions(+), 432 deletions(-) delete mode 100644 packages/coding-standard/config/sets/docblock.php delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/correct2.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/iterator_flip.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_curly_newline.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc delete mode 100644 packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php diff --git a/.github/workflows/buid_release.yaml b/.github/workflows/buid_release.yaml index 1b286c716c3..d9400c06a7e 100644 --- a/.github/workflows/buid_release.yaml +++ b/.github/workflows/buid_release.yaml @@ -47,10 +47,10 @@ jobs: - run: composer require rector/rector --working-dir rector-local # clear the dev files - - run: rm -rf tests ecs-build/ecs.php ecs-build/phpstan.neon ecs-build/phpunit.xml ecs-build/.gitignore ecs-build/.editorconfig + - run: rm -rf tests ecs-build/packages/coding-standard/tests ecs-build/ecs.php ecs-build/phpstan.neon ecs-build/phpunit.xml ecs-build/.gitignore ecs-build/.editorconfig # 2. downgrade via Rector - - run: rector-local/vendor/bin/rector process ecs-build/bin ecs-build/config/config.php ecs-build/src ecs-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs + - run: rector-local/vendor/bin/rector process ecs-build/bin ecs-build/config/config.php ecs-build/packages ecs-build/src ecs-build/vendor --config build/config/config-downgrade.php --ansi --no-diffs # 3. prefix classes - run: sh build/build-ecs-scoped.sh ecs-build ecs-prefixed-downgraded @@ -83,7 +83,7 @@ jobs: token: ${{ secrets.ACCESS_TOKEN }} # remove remote files, to avoid piling up dead code in remote repository - - run: rm -rf remote-repository/.github remote-repository/docs remote-repository/config remote-repository/src remote-repository/vendor + - run: rm -rf remote-repository/.github remote-repository/docs remote-repository/config remote-repository/packages remote-repository/src remote-repository/vendor # clear the dev files - run: cp -a ecs-prefixed-downgraded/. remote-repository diff --git a/.github/workflows/code_analysis.yaml b/.github/workflows/code_analysis.yaml index 17c12bd257b..0b6741a7c08 100644 --- a/.github/workflows/code_analysis.yaml +++ b/.github/workflows/code_analysis.yaml @@ -34,7 +34,7 @@ jobs: - name: 'Check Active Classes' - run: vendor/bin/class-leak check bin src --skip-type "Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface" --ansi + run: vendor/bin/class-leak check bin src packages/coding-standard/src --skip-type "Symplify\EasyCodingStandard\Contract\Console\Output\OutputFormatterInterface" --ansi name: ${{ matrix.actions.name }} runs-on: ubuntu-latest diff --git a/ecs.php b/ecs.php index cedc72d9aa8..19148d131e2 100644 --- a/ecs.php +++ b/ecs.php @@ -5,7 +5,7 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return ECSConfig::configure() - ->withPaths([__DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests']) + ->withPaths([__DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/packages', __DIR__ . '/src', __DIR__ . '/tests']) ->withEditorConfig() ->withRootFiles() ->withSkip(['*/Source/*', '*/Fixture/*']) diff --git a/packages/coding-standard/config/sets/docblock.php b/packages/coding-standard/config/sets/docblock.php deleted file mode 100644 index 33b1d74c275..00000000000 --- a/packages/coding-standard/config/sets/docblock.php +++ /dev/null @@ -1,37 +0,0 @@ -rules([ - // inline @var - DoubleAsteriskInlineVarFixer::class, - SingleLineInlineVarDocBlockFixer::class, - AddMissingVarNameFixer::class, - - // @param - AddMissingParamNameFixer::class, - FixParamNameTypoFixer::class, - RemoveParamNameReferenceFixer::class, - RemoveDeadParamFixer::class, - - // superfluous names - RemoveSuperfluousReturnNameFixer::class, - RemoveSuperfluousVarNameFixer::class, - - // switched type/name order - SwitchedTypeAndNameFixer::class, - ]); -}; diff --git a/packages/coding-standard/config/symplify.php b/packages/coding-standard/config/symplify.php index 103222e1805..13c10f93936 100644 --- a/packages/coding-standard/config/symplify.php +++ b/packages/coding-standard/config/symplify.php @@ -19,9 +19,6 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { - // split @param/@return/@var malform rules - $ecsConfig->sets([__DIR__ . '/sets/docblock.php']); - $ecsConfig->rules([ // docblocks and comments RemovePHPStormAnnotationFixer::class, diff --git a/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php b/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php index 45ff067f70b..d0de5ee8197 100644 --- a/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php +++ b/packages/coding-standard/src/Fixer/Commenting/FixParamNameTypoFixer.php @@ -111,8 +111,12 @@ private function getAnnotationsOfType(string $docContent, string $type): array * @param string[] $missArgumentNames * @param string[] $paramNames */ - private function fixTypos(array $argumentNames, array $missArgumentNames, array $paramNames, string $docContent): string - { + private function fixTypos( + array $argumentNames, + array $missArgumentNames, + array $paramNames, + string $docContent + ): string { // A table of permuted params. initialized by $argumentName instead of $paramNames is correct $replacedParams = array_fill_keys($argumentNames, false); @@ -125,7 +129,10 @@ private function fixTypos(array $argumentNames, array $missArgumentNames, array $typoName = $paramNames[$key]; $replacePattern = '#@param(.*?)(' . preg_quote($typoName, '#') . '\b)#'; - $docContent = Regex::replace($docContent, $replacePattern, static function (array $matched) use ($argumentName, &$replacedParams) { + $docContent = Regex::replace($docContent, $replacePattern, static function (array $matched) use ( + $argumentName, + &$replacedParams + ) { $paramName = $matched[2]; // 2. If the PHPDoc $paramName is one of the existing $argumentNames and has not already been replaced, it will be deferred diff --git a/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php b/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php index 8d2157ba760..3485e5bf742 100644 --- a/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php +++ b/packages/coding-standard/src/Fixer/Commenting/ParamReturnAndVarTagMalformsFixer.php @@ -13,8 +13,8 @@ use Symplify\CodingStandard\Fixer\AbstractSymplifyFixer; /** - * @deprecated This rule was split into single-task rules registered in config/sets/docblock.php. - * Use the docblock set or the dedicated rules instead. + * @deprecated This rule was split into single-task rules collected in DocblockLevel. + * Use DocblockLevel or the dedicated rules instead. */ final class ParamReturnAndVarTagMalformsFixer extends AbstractSymplifyFixer implements DeprecatedFixerInterface { diff --git a/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php b/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php index 978f7e7c767..d6c7f299a92 100644 --- a/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php +++ b/packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php @@ -21,9 +21,7 @@ public function __construct( ) { $this->functionsAnalyzer = new FunctionsAnalyzer(); - $this->functionTokens = [ - new Token([T_FUNCTION, 'function']), - ]; + $this->functionTokens = [new Token([T_FUNCTION, 'function'])]; // only in PHP 7.4+ if ($this->doesFnTokenExist()) { diff --git a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php index 54614f21be6..4dc746cb7ce 100644 --- a/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php +++ b/packages/coding-standard/src/TokenRunner/Analyzer/FixerAnalyzer/TokenSkipper.php @@ -57,7 +57,9 @@ public function skipBlocksReversed(Tokens $tokens, int $position): int { /** @var Token $token */ $token = $tokens[$position]; - if (! $token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE) && ! $token->equals(')') && ! $token->isGivenKind(CT::T_ATTRIBUTE_CLOSE)) { + if (! $token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE) && ! $token->equals(')') && ! $token->isGivenKind( + CT::T_ATTRIBUTE_CLOSE + )) { return $position; } @@ -91,7 +93,9 @@ private function findAttributeStart(Tokens $tokens, int $closingBracketPosition) } // If we hit another ] or reach a statement boundary, stop searching - if ($currentToken->equals(']') || $currentToken->equals(';') || $currentToken->equals('{') || $currentToken->equals('}')) { + if ($currentToken->equals(']') || $currentToken->equals(';') || $currentToken->equals( + '{' + ) || $currentToken->equals('}')) { break; } } diff --git a/packages/coding-standard/src/Utils/Regex.php b/packages/coding-standard/src/Utils/Regex.php index 30577e4fdb6..86670e7010b 100644 --- a/packages/coding-standard/src/Utils/Regex.php +++ b/packages/coding-standard/src/Utils/Regex.php @@ -33,6 +33,9 @@ public static function matchAll(string $subject, string $pattern): array return $matches; } + /** + * @param string|callable(array): string $replacement + */ public static function replace(string $subject, string $pattern, string|callable $replacement = ''): string { if (is_callable($replacement)) { diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php index 2f01dd20732..5fca5d516df 100644 --- a/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php +++ b/packages/coding-standard/tests/Fixer/Annotation/RemoveMethodNameDuplicateDescriptionFixer/config/configured_rule.php @@ -6,7 +6,5 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { - $ecsConfig->rules([ - RemoveMethodNameDuplicateDescriptionFixer::class, - ]); + $ecsConfig->rules([RemoveMethodNameDuplicateDescriptionFixer::class]); }; diff --git a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php index 8c880480729..1a5bc899769 100644 --- a/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php +++ b/packages/coding-standard/tests/Fixer/Annotation/RemovePropertyVariableNameDescriptionFixer/config/configured_rule.php @@ -6,7 +6,5 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { - $ecsConfig->rules([ - RemovePropertyVariableNameDescriptionFixer::class, - ]); + $ecsConfig->rules([RemovePropertyVariableNameDescriptionFixer::class]); }; diff --git a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php index 10574fd3277..d58ee66f156 100644 --- a/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php +++ b/packages/coding-standard/tests/Fixer/Commenting/RemoveUselessDefaultCommentFixer/config/configured_rule.php @@ -1,13 +1,11 @@ rules([ - RemoveUselessDefaultCommentFixer::class, - BracesFixer::class, - ]); + $ecsConfig->rules([RemoveUselessDefaultCommentFixer::class, BracesFixer::class]); }; diff --git a/packages/coding-standard/tests/Issues/config/line_length_parentheses.php b/packages/coding-standard/tests/Issues/config/line_length_parentheses.php index a2cd1bd8015..3a6ec0f3c84 100644 --- a/packages/coding-standard/tests/Issues/config/line_length_parentheses.php +++ b/packages/coding-standard/tests/Issues/config/line_length_parentheses.php @@ -7,9 +7,7 @@ use Symplify\EasyCodingStandard\Config\ECSConfig; return static function (ECSConfig $ecsConfig): void { - $ecsConfig->rules([ - LineLengthFixer::class, - ]); + $ecsConfig->rules([LineLengthFixer::class]); $ecsConfig->ruleWithConfiguration(NewWithParenthesesFixer::class, [ 'anonymous_class' => false, diff --git a/packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php b/packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php deleted file mode 100644 index f522738020e..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/DocblockSetTest.php +++ /dev/null @@ -1,31 +0,0 @@ -doTestFile($filePath); - } - - public static function provideData(): Iterator - { - return self::yieldFiles(__DIR__ . '/Fixture'); - } - - public function provideConfig(): string - { - return __DIR__ . '/../../../config/sets/docblock.php'; - } -} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc deleted file mode 100644 index a72227a2923..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/correct.php.inc +++ /dev/null @@ -1,19 +0,0 @@ - */ - return $value; -} - -?> ------ - $value */ - return $value; -} - -?> diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc deleted file mode 100644 index bef5fd842f9..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/param_variable_mallforms.php.inc +++ /dev/null @@ -1,25 +0,0 @@ - ------ - diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc deleted file mode 100644 index d65341b0ac4..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_has_same_param_previous_definition.php.inc +++ /dev/null @@ -1,16 +0,0 @@ - diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc deleted file mode 100644 index af480314e70..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_callable_param.php.inc +++ /dev/null @@ -1,15 +0,0 @@ - diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc deleted file mode 100644 index 56c9f374235..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_edge_case_with_assert.php.inc +++ /dev/null @@ -1,14 +0,0 @@ -assertEquals('....', $response->getResponse()['message']); - } -} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc deleted file mode 100644 index 7dc477e48bd..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_inlined_var_in_doc.php.inc +++ /dev/null @@ -1,8 +0,0 @@ -set(Option::IMPORT_DOC_BLOCKS, false); - -} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc deleted file mode 100644 index ef1e5757ffe..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_nested_multiline.php.inc +++ /dev/null @@ -1,11 +0,0 @@ - $foo - */ -function test($foo, $bar): void -{ - -} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc deleted file mode 100644 index 4d33be124bd..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/skip_union_array.php.inc +++ /dev/null @@ -1,11 +0,0 @@ - $values - */ - public function run($values) - { - } -} diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc deleted file mode 100644 index 233af839ee6..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong4.php.inc +++ /dev/null @@ -1,54 +0,0 @@ - ------ - diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc deleted file mode 100644 index 130b2e5a95f..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong5.php.inc +++ /dev/null @@ -1,49 +0,0 @@ - $variable */ -$variable = array(array('hello')); - -/** @var $variable int */ -$variable = 5; - -/** - * @var $variable int - */ -$variable = 5; - -/* - * @var $variable int - */ -$variable = 5; - -/* - * @phpstan-var $variable int - */ -$variable = 5; - -?> ------ - $variable */ -$variable = array(array('hello')); - -/** @var int $variable */ -$variable = 5; - -/** @var int $variable */ -$variable = 5; - -/** @var int $variable */ -$variable = 5; - -/** @phpstan-var int $variable */ -$variable = 5; - -?> diff --git a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc b/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc deleted file mode 100644 index a70cc1617c6..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Fixture/wrong9.php.inc +++ /dev/null @@ -1,26 +0,0 @@ - ------ - diff --git a/packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php b/packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php deleted file mode 100644 index f5908ce3f97..00000000000 --- a/packages/coding-standard/tests/Set/DocblockSet/Source/Schedule.php +++ /dev/null @@ -1,9 +0,0 @@ -, coding_standard_errors\?\: array\} but returns array<(.*?), array>#' # false positive on custom config tets @@ -57,11 +56,6 @@ parameters: - tests/Skipper/SkipCriteriaResolver/SkippedPathsResolver/SkippedPathsResolverTest.php - src/Testing/PHPUnit/AbstractCheckerTestCase.php - # optional - - - message: '#Method Symplify\\EasyCodingStandard\\Config\\ECSConfig\:\:singleton\(\) has parameter \$concrete with no signature specified for Closure#' - path: src/Config/ECSConfig.php - # testing instance of on purpose - message: '#Call to method PHPUnit\\Framework\\Assert\:\:assertInstanceOf#' @@ -86,3 +80,19 @@ parameters: - identifier: offsetAssign.dimType path: src/Console/Output/JsonOutputFormatter.php + + # coding-standard: runtime-defined PHP_CodeSniffer/php-cs-fixer token constants + - '#Constant T_OPEN_CURLY_BRACKET|T_START_NOWDOC not found#' + + # coding-standard: php-cs-fixer interface generics intentionally left unspecified + - '#Class (.*?) implements generic interface PhpCsFixer\\Fixer\\ConfigurableFixerInterface but does not specify its types\: TFixerInputConfig, TFixerComputedConfig#' + + # coding-standard: intentional cross-version condition + - + message: '#Comparison operation ">\=" between int<\d+, \d+> and (.*?) is always true#' + path: packages/coding-standard/src/TokenAnalyzer/DocblockRelatedParamNamesResolver.php + + # coding-standard: intentional null removal + - + message: '#Parameter \#1 \$array \(array\) to function array_filter does not contain falsy values, the array will always stay the same#' + path: packages/coding-standard/src/TokenRunner/Traverser/TokenReverser.php diff --git a/rector.php b/rector.php index a0d10051856..8ccac0eba2f 100644 --- a/rector.php +++ b/rector.php @@ -17,7 +17,7 @@ naming: true, earlyReturn: true ) - ->withPaths([__DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/src', __DIR__ . '/tests']) + ->withPaths([__DIR__ . '/bin', __DIR__ . '/config', __DIR__ . '/packages', __DIR__ . '/src', __DIR__ . '/tests']) ->withRootFiles() ->withImportNames() ->withBootstrapFiles([__DIR__ . '/tests/bootstrap.php']) diff --git a/src/Config/Level/DocblockLevel.php b/src/Config/Level/DocblockLevel.php index 3ff86509f4c..7c4e6e3ed24 100644 --- a/src/Config/Level/DocblockLevel.php +++ b/src/Config/Level/DocblockLevel.php @@ -17,7 +17,17 @@ use PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocVarWithoutNameFixer; +use Symplify\CodingStandard\Fixer\Commenting\AddMissingParamNameFixer; +use Symplify\CodingStandard\Fixer\Commenting\AddMissingVarNameFixer; +use Symplify\CodingStandard\Fixer\Commenting\DoubleAsteriskInlineVarFixer; +use Symplify\CodingStandard\Fixer\Commenting\FixParamNameTypoFixer; +use Symplify\CodingStandard\Fixer\Commenting\RemoveDeadParamFixer; +use Symplify\CodingStandard\Fixer\Commenting\RemoveParamNameReferenceFixer; +use Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousReturnNameFixer; +use Symplify\CodingStandard\Fixer\Commenting\RemoveSuperfluousVarNameFixer; use Symplify\CodingStandard\Fixer\Commenting\RemoveUselessDefaultCommentFixer; +use Symplify\CodingStandard\Fixer\Commenting\SingleLineInlineVarDocBlockFixer; +use Symplify\CodingStandard\Fixer\Commenting\SwitchedTypeAndNameFixer; /** * Key 0 = level 0 @@ -32,6 +42,24 @@ final class DocblockLevel * @var array> */ public const array RULES = [ + // inline @var + DoubleAsteriskInlineVarFixer::class, + SingleLineInlineVarDocBlockFixer::class, + AddMissingVarNameFixer::class, + + // @param + AddMissingParamNameFixer::class, + FixParamNameTypoFixer::class, + RemoveParamNameReferenceFixer::class, + RemoveDeadParamFixer::class, + + // superfluous names + RemoveSuperfluousReturnNameFixer::class, + RemoveSuperfluousVarNameFixer::class, + + // switched type/name order + SwitchedTypeAndNameFixer::class, + // pure whitespace cleanup NoTrailingWhitespaceInCommentFixer::class, PhpdocTrimFixer::class,