diff --git a/config/set/php-cs-fixer.php b/config/set/php-cs-fixer.php index a4a0835..a50d243 100644 --- a/config/set/php-cs-fixer.php +++ b/config/set/php-cs-fixer.php @@ -6,27 +6,17 @@ use PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer; use PhpCsFixer\Fixer\ClassNotation\OrderedClassElementsFixer; use PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer; -use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer; -use PhpCsFixer\Fixer\FunctionNotation\SingleLineThrowFixer; use PhpCsFixer\Fixer\Import\OrderedImportsFixer; use PhpCsFixer\Fixer\Operator\ConcatSpaceFixer; use PhpCsFixer\Fixer\Operator\IncrementStyleFixer; use PhpCsFixer\Fixer\Operator\LogicalOperatorsFixer; use PhpCsFixer\Fixer\Operator\NotOperatorWithSuccessorSpaceFixer; -use PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer; -use PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocAlignFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocNoAliasTagFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocSummaryFixer; -use PhpCsFixer\Fixer\Phpdoc\PhpdocToCommentFixer; use PhpCsFixer\Fixer\Phpdoc\PhpdocTypesOrderFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitInternalClassFixer; -use PhpCsFixer\Fixer\PhpUnit\PhpUnitTestClassRequiresCoversFixer; use PhpCsFixer\Fixer\ReturnNotation\SimplifiedNullReturnFixer; use PhpCsFixer\Fixer\Semicolon\MultilineWhitespaceBeforeSemicolonsFixer; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; -use Symplify\EasyCodingStandard\ValueObject\Option; return static function (ContainerConfigurator $containerConfigurator): void { $containerConfigurator->import(__DIR__ . '/../../vendor/symplify/easy-coding-standard/config/set/php-cs-fixer.php', null, true); @@ -36,20 +26,16 @@ $containerConfigurator->import(__DIR__ . '/../../../../symplify/easy-coding-standard/config/set/php-cs-fixer.php', null, true); $services = $containerConfigurator->services(); - $services->set(ClassAttributesSeparationFixer::class); - $services->set(MultilineWhitespaceBeforeSemicolonsFixer::class); - $services->set(SimplifiedNullReturnFixer::class); - $services->set(NotOperatorWithSuccessorSpaceFixer::class); - $services->set(LogicalOperatorsFixer::class); - $services->set(OrderedImportsFixer::class) + $services->set(ArraySyntaxFixer::class) ->call( 'configure', [ [ - 'importsOrder' => ['class', 'function', 'const'], + 'syntax' => 'short', ], ] ); + $services->set(ClassAttributesSeparationFixer::class); $services->set(ConcatSpaceFixer::class) ->call( 'configure', @@ -59,53 +45,58 @@ ], ] ); - $services->set(PhpdocAlignFixer::class) + $services->set(IncrementStyleFixer::class) ->call( 'configure', [ [ - 'align' => 'left', + 'style' => 'post', ], ] ); - $services->set(ArraySyntaxFixer::class) + $services->set(LogicalOperatorsFixer::class); + $services->set(MultilineWhitespaceBeforeSemicolonsFixer::class); + $services->set(NotOperatorWithSuccessorSpaceFixer::class); + $services->set(OrderedClassElementsFixer::class) ->call( 'configure', [ [ - 'syntax' => 'short', + 'order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private'], ], ] ); - $services->set(VisibilityRequiredFixer::class) + $services->set(OrderedImportsFixer::class) ->call( 'configure', [ [ - 'elements' => ['property', 'method', 'const'], + 'importsOrder' => ['class', 'function', 'const'], ], ] ); - - $services->set(OrderedClassElementsFixer::class) + $services->set(PhpdocAlignFixer::class) ->call( 'configure', [ [ - 'order' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private'], + 'align' => 'left', ], ] ); - - $services->set(IncrementStyleFixer::class) + $services->set(PhpdocNoAliasTagFixer::class) ->call( 'configure', [ [ - 'style' => 'post', + 'replacements' => [ + 'type' => 'var', + 'link' => 'see', + ], ], ] ); + $services->set(PhpdocTypesOrderFixer::class) ->call( 'configure', @@ -116,21 +107,15 @@ ], ] ); - $parameters = $containerConfigurator->parameters(); - $parameters->set( - Option::SKIP, - [ - UnaryOperatorSpacesFixer::class => null, - SingleLineThrowFixer::class => null, - PhpdocSummaryFixer::class => null, - PhpdocToCommentFixer::class => null, - PhpdocNoEmptyReturnFixer::class => null, - PhpdocNoAliasTagFixer::class => null, - PhpdocTypesOrderFixer::class => null, - PhpUnitTestClassRequiresCoversFixer::class => null, - PhpUnitInternalClassFixer::class => null, - NoSuperfluousPhpdocTagsFixer::class => null, - YodaStyleFixer::class => null, - ] - ); + $services->set(SimplifiedNullReturnFixer::class); + + $services->set(VisibilityRequiredFixer::class) + ->call( + 'configure', + [ + [ + 'elements' => ['property', 'method', 'const'], + ], + ] + ); }; diff --git a/config/set/php_codesniffer.php b/config/set/php_codesniffer.php index ba479a9..4685959 100644 --- a/config/set/php_codesniffer.php +++ b/config/set/php_codesniffer.php @@ -49,40 +49,37 @@ use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\DisallowTabIndentSniff; use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\IncrementDecrementSpacingSniff; use PHP_CodeSniffer\Standards\Generic\Sniffs\WhiteSpace\ScopeIndentSniff; -use PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\FunctionCallSignatureSniff; use PHP_CodeSniffer\Standards\PEAR\Sniffs\Functions\ValidDefaultValueSniff; use PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ObjectOperatorIndentSniff; -use PHP_CodeSniffer\Standards\PEAR\Sniffs\WhiteSpace\ScopeClosingBraceSniff; use PHP_CodeSniffer\Standards\PSR1\Sniffs\Files\SideEffectsSniff; use PHP_CodeSniffer\Standards\PSR1\Sniffs\Methods\CamelCapsMethodNameSniff; -use PHP_CodeSniffer\Standards\PSR12\Sniffs\Classes\AnonClassDeclarationSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Classes\ClassInstantiationSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Classes\ClosingBraceSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\ControlStructures\BooleanOperatorPlacementSniff; +use PHP_CodeSniffer\Standards\PSR12\Sniffs\ControlStructures\ControlStructureSpacingSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Files\DeclareStatementSniff; -use PHP_CodeSniffer\Standards\PSR12\Sniffs\Files\FileHeaderSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Files\ImportStatementSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Files\OpenTagSniff; +use PHP_CodeSniffer\Standards\PSR12\Sniffs\Functions\NullableTypeDeclarationSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Functions\ReturnTypeDeclarationSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Keywords\ShortFormTypeKeywordsSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Namespaces\CompoundNamespaceDepthSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Operators\OperatorSpacingSniff; use PHP_CodeSniffer\Standards\PSR12\Sniffs\Properties\ConstantVisibilitySniff; -use PHP_CodeSniffer\Standards\PSR12\Sniffs\Traits\UseDeclarationSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\ClassDeclarationSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\Classes\PropertyDeclarationSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\ElseIfDeclarationSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\ControlStructures\SwitchDeclarationSniff; +use PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\EndFileNewlineSniff; +use PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionClosingBraceSniff; use PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\MethodDeclarationSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff; -use PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\ValidClassNameSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\DocCommentAlignmentSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\EmptyCatchCommentSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\LongConditionClosingCommentSniff; -use PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\PostStatementCommentSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ControlSignatureSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ForEachLoopDeclarationSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\ControlStructures\ForLoopDeclarationSniff; @@ -95,51 +92,62 @@ use PHP_CodeSniffer\Standards\Squiz\Sniffs\PHP\GlobalKeywordSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MethodScopeSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\CastSpacingSniff; -use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ControlStructureSpacingSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff; +use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ScopeClosingBraceSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ScopeKeywordSpacingSniff; use PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SuperfluousWhitespaceSniff; use PHP_CodeSniffer\Standards\Zend\Sniffs\Debug\CodeAnalyzerSniff; -use PHP_CodeSniffer\Standards\Zend\Sniffs\Files\ClosingTagSniff; -use Symplify\EasyCodingStandard\ValueObject\Option; return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); - $services->set(OperatorSpacingSniff::class); - $services->set(UseDeclarationSniff::class); - $services->set(ClosingBraceSniff::class); - $services->set(AnonClassDeclarationSniff::class); - $services->set(ClassInstantiationSniff::class); - $services->set(CompoundNamespaceDepthSniff::class); - $services->set(ConstantVisibilitySniff::class); - $services->set(ImportStatementSniff::class); - $services->set(FileHeaderSniff::class); - $services->set(OpenTagSniff::class); - $services->set(DeclareStatementSniff::class); - // 报错 - //$services->set(\PHP_CodeSniffer\Standards\PSR12\Sniffs\Functions\NullableTypeDeclarationSniff::class); - $services->set(ReturnTypeDeclarationSniff::class); - $services->set(\PHP_CodeSniffer\Standards\PSR12\Sniffs\ControlStructures\ControlStructureSpacingSniff::class); - $services->set(BooleanOperatorPlacementSniff::class); - $services->set(ShortFormTypeKeywordsSniff::class); - $services->set(CamelCapsMethodNameSniff::class); - $services->set(\PHP_CodeSniffer\Standards\PSR1\Sniffs\Classes\ClassDeclarationSniff::class); - $services->set(SideEffectsSniff::class); - $services->set(DisallowAlternativePHPTagsSniff::class); - $services->set(DisallowShortOpenTagSniff::class); + $services->set(ArrayIndentSniff::class); + $services->set(DisallowLongArraySyntaxSniff::class); + $services->set(EmptyPHPStatementSniff::class); + $services->set(EmptyStatementSniff::class); + $services->set(ForLoopShouldBeWhileLoopSniff::class); + $services->set(ForLoopWithTestFunctionCallSniff::class); + $services->set(JumbledIncrementerSniff::class); + $services->set(UnconditionalIfStatementSniff::class); + $services->set(UnnecessaryFinalModifierSniff::class); + $services->set(UnusedFunctionParameterSniff::class); + $services->set(UselessOverridingMethodSniff::class); + $services->set(FixmeSniff::class); + $services->set(TodoSniff::class); + $services->set(InlineControlStructureSniff::class) + ->property('error', 'true'); $services->set(ByteOrderMarkSniff::class); - $services->set(ValidClassNameSniff::class); - $services->set(UpperCaseConstantNameSniff::class); $services->set(LineEndingsSniff::class) ->property('eolChar', '\n'); - $services->set(EndFileNewlineSniff::class); - $services->set(\PHP_CodeSniffer\Standards\PSR2\Sniffs\Files\ClosingTagSniff::class); $services->set(LineLengthSniff::class) ->property('lineLimit', '120') ->property('absoluteLineLimit', '0'); - $services->set(SuperfluousWhitespaceSniff::class) - ->property('ignoreBlankLines', 'true'); + $services->set(OneClassPerFileSniff::class); + $services->set(OneInterfacePerFileSniff::class); + $services->set(OneTraitPerFileSniff::class); $services->set(DisallowMultipleStatementsSniff::class); + $services->set(SpaceAfterCastSniff::class); + $services->set(SpaceAfterNotSniff::class); + $services->set(CallTimePassByReferenceSniff::class); + $services->set(FunctionCallArgumentSpacingSniff::class); + $services->set(UpperCaseConstantNameSniff::class); + $services->set(BacktickOperatorSniff::class); + $services->set(CharacterBeforePHPOpeningTagSniff::class); + $services->set(DeprecatedFunctionsSniff::class); + $services->set(DisallowAlternativePHPTagsSniff::class); + $services->set(DisallowShortOpenTagSniff::class); + $services->set(DiscourageGotoSniff::class); + $services->set(ForbiddenFunctionsSniff::class); + $services->set(LowerCaseConstantSniff::class); + $services->set(LowerCaseKeywordSniff::class); + $services->set(LowerCaseTypeSniff::class); + $services->set(NoSilencedErrorsSniff::class); + $services->set(SAPIUsageSniff::class); + $services->set(SyntaxSniff::class); + $services->set(UnnecessaryStringConcatSniff::class); + $services->set(GitMergeConflictSniff::class); + $services->set(ArbitraryParenthesesSpacingSniff::class); + $services->set(DisallowTabIndentSniff::class); + $services->set(IncrementDecrementSpacingSniff::class); $services->set(ScopeIndentSniff::class) ->property( 'ignoreIndentationTokens', @@ -148,103 +156,55 @@ 'T_DOC_COMMENT_OPEN_TAG', ] ); - $services->set(DisallowTabIndentSniff::class); - $services->set(LowerCaseKeywordSniff::class); - $services->set(LowerCaseConstantSniff::class); - $services->set(LowerCaseTypeSniff::class); + $services->set(ValidDefaultValueSniff::class); + $services->set(ObjectOperatorIndentSniff::class); + $services->set(ClassInstantiationSniff::class); + $services->set(ClosingBraceSniff::class); + $services->set(BooleanOperatorPlacementSniff::class); + $services->set(ControlStructureSpacingSniff::class); + $services->set(DeclareStatementSniff::class); + $services->set(ImportStatementSniff::class); + $services->set(OpenTagSniff::class); + $services->set(NullableTypeDeclarationSniff::class); + $services->set(ReturnTypeDeclarationSniff::class); + $services->set(ShortFormTypeKeywordsSniff::class); + $services->set(CompoundNamespaceDepthSniff::class); + $services->set(OperatorSpacingSniff::class); + $services->set(ConstantVisibilitySniff::class); + $services->set(SideEffectsSniff::class); + $services->set(CamelCapsMethodNameSniff::class); $services->set(ClassDeclarationSniff::class); $services->set(PropertyDeclarationSniff::class); - $services->set(MethodScopeSniff::class); - $services->set(ScopeKeywordSpacingSniff::class); - $services->set(MethodDeclarationSniff::class); + $services->set(ElseIfDeclarationSniff::class); + $services->set(SwitchDeclarationSniff::class); + $services->set(ClosingTagSniff::class); + $services->set(EndFileNewlineSniff::class); + $services->set(FunctionCallSignatureSniff::class); $services->set(FunctionClosingBraceSniff::class); - $services->set(FunctionDeclarationSniff::class); - $services->set(LowercaseFunctionKeywordsSniff::class); - $services->set(FunctionDeclarationArgumentSpacingSniff::class) - ->property('equalsSpacing', '1'); - $services->set(ValidDefaultValueSniff::class); - $services->set(MultiLineFunctionDeclarationSniff::class); - $services->set(FunctionCallArgumentSpacingSniff::class); - $services->set(\PHP_CodeSniffer\Standards\PSR2\Sniffs\Methods\FunctionCallSignatureSniff::class); + $services->set(MethodDeclarationSniff::class); + $services->set(ArrayBracketSpacingSniff::class); + $services->set(ValidClassNameSniff::class); + $services->set(DocCommentAlignmentSniff::class); + $services->set(EmptyCatchCommentSniff::class); + $services->set(LongConditionClosingCommentSniff::class); $services->set(ControlSignatureSniff::class); - $services->set(ControlStructureSpacingSniff::class); - $services->set(\PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ScopeClosingBraceSniff::class); $services->set(ForEachLoopDeclarationSniff::class); $services->set(ForLoopDeclarationSniff::class) ->property('ignoreNewlines', 'true'); $services->set(LowercaseDeclarationSniff::class); - $services->set(InlineControlStructureSniff::class) - ->property('error', 'true'); - $services->set(ElseIfDeclarationSniff::class); - $services->set(SwitchDeclarationSniff::class); - $services->set(IncrementDecrementSpacingSniff::class); + $services->set(FunctionDeclarationArgumentSpacingSniff::class) + ->property('equalsSpacing', '1'); + $services->set(FunctionDeclarationSniff::class); + $services->set(LowercaseFunctionKeywordsSniff::class); + $services->set(MultiLineFunctionDeclarationSniff::class); + $services->set(EvalSniff::class); + $services->set(GlobalKeywordSniff::class); + $services->set(MethodScopeSniff::class); $services->set(CastSpacingSniff::class); - $services->set(ArrayBracketSpacingSniff::class); - $services->set(ArrayDeclarationSniff::class); - $services->set(DocCommentAlignmentSniff::class); - $services->set(EmptyCatchCommentSniff::class); - $services->set(LongConditionClosingCommentSniff::class); - $services->set(PostStatementCommentSniff::class); - $services->set(TodoSniff::class); - $services->set(ClosingTagSniff::class); - $services->set(FunctionCallSignatureSniff::class); - $services->set(DisallowLongArraySyntaxSniff::class); - $services->set(SpaceAfterCastSniff::class); - $services->set(SpaceAfterNotSniff::class); - $services->set(BacktickOperatorSniff::class); - $services->set(CharacterBeforePHPOpeningTagSniff::class); - $services->set(ForbiddenFunctionsSniff::class); - $services->set(SAPIUsageSniff::class); - $services->set(SyntaxSniff::class); - $services->set(GitMergeConflictSniff::class); - $services->set(ArbitraryParenthesesSpacingSniff::class); - $services->set(ObjectOperatorIndentSniff::class); - $services->set(ScopeClosingBraceSniff::class); $services->set(LanguageConstructSpacingSniff::class); - $services->set(UnnecessaryFinalModifierSniff::class); - $services->set(ArrayIndentSniff::class); - $services->set(EmptyPHPStatementSniff::class); - $services->set(EmptyStatementSniff::class); - $services->set(ForLoopShouldBeWhileLoopSniff::class); - $services->set(ForLoopWithTestFunctionCallSniff::class); - $services->set(JumbledIncrementerSniff::class); - $services->set(UnconditionalIfStatementSniff::class); - $services->set(UselessOverridingMethodSniff::class); - $services->set(DiscourageGotoSniff::class); - $services->set(NoSilencedErrorsSniff::class); - $services->set(UnnecessaryStringConcatSniff::class); - $services->set(EvalSniff::class); + $services->set(ScopeClosingBraceSniff::class); + $services->set(ScopeKeywordSpacingSniff::class); + $services->set(SuperfluousWhitespaceSniff::class) + ->property('ignoreBlankLines', 'true'); $services->set(CodeAnalyzerSniff::class); - $services->set(FixmeSniff::class); - $services->set(UnusedFunctionParameterSniff::class); - $services->set(CallTimePassByReferenceSniff::class); - $services->set(DeprecatedFunctionsSniff::class); - $services->set(GlobalKeywordSniff::class); - $services->set(OneClassPerFileSniff::class); - $services->set(OneInterfacePerFileSniff::class); - $services->set(OneTraitPerFileSniff::class); - - $parameters = $containerConfigurator->parameters(); - $parameters->set( - Option::SKIP, - [ - FileHeaderSniff::class => null, - FileHeaderSniff::class . '.SpacingAfterBlock' => null, - FileHeaderSniff::class . '.IncorrectOrder' => null, - FileHeaderSniff::class . '.IncorrectGrouping' => null, - ArrayDeclarationSniff::class . '.DoubleArrowNotAligned' => null, - ArrayDeclarationSniff::class . '.NoKeySpecified' => null, - ArrayDeclarationSniff::class . '.KeySpecified' => null, - ArrayDeclarationSniff::class . '.SingleLineNotAllowed' => null, - ArrayDeclarationSniff::class . '.KeyNotAligned' => null, - ArrayDeclarationSniff::class . '.ValueNotAligned' => null, - ArrayDeclarationSniff::class . '.CloseBraceNotAligned' => null, - ArrayDeclarationSniff::class . '.CloseBraceNewLine' => null, - ArrayDeclarationSniff::class . '.MultiLineNotAllowed' => null, - UseDeclarationSniff::class . '.UseAfterBrace' => null, - AnonClassDeclarationSniff::class . '.SpaceAfterKeyword' => null, - ControlStructureSpacingSniff::class . '.LineAfterClose' => null, - PostStatementCommentSniff::class . '.Found' => null, - ] - ); }; diff --git a/config/set/slevomat-coding-standard.php b/config/set/slevomat-coding-standard.php index 7fef4ad..b74d3ff 100644 --- a/config/set/slevomat-coding-standard.php +++ b/config/set/slevomat-coding-standard.php @@ -19,11 +19,8 @@ use SlevomatCodingStandard\Sniffs\Classes\TraitUseSpacingSniff; use SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff; use SlevomatCodingStandard\Sniffs\Classes\UselessLateStaticBindingSniff; -use SlevomatCodingStandard\Sniffs\Commenting\DisallowCommentAfterCodeSniff; use SlevomatCodingStandard\Sniffs\Commenting\EmptyCommentSniff; use SlevomatCodingStandard\Sniffs\Commenting\ForbiddenCommentsSniff; -use SlevomatCodingStandard\Sniffs\Commenting\InlineDocCommentDeclarationSniff; -use SlevomatCodingStandard\Sniffs\Commenting\UselessFunctionDocCommentSniff; use SlevomatCodingStandard\Sniffs\Commenting\UselessInheritDocCommentSniff; use SlevomatCodingStandard\Sniffs\ControlStructures\AssignmentInConditionSniff; use SlevomatCodingStandard\Sniffs\ControlStructures\DisallowContinueWithoutIntegerOperandInSwitchSniff; @@ -33,7 +30,6 @@ use SlevomatCodingStandard\Sniffs\Exceptions\DeadCatchSniff; use SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff; use SlevomatCodingStandard\Sniffs\Functions\UnusedInheritedVariablePassedToClosureSniff; -use SlevomatCodingStandard\Sniffs\Functions\UnusedParameterSniff; use SlevomatCodingStandard\Sniffs\Functions\UselessParameterDefaultValueSniff; use SlevomatCodingStandard\Sniffs\Namespaces\FullyQualifiedClassNameInAnnotationSniff; use SlevomatCodingStandard\Sniffs\Namespaces\NamespaceDeclarationSniff; @@ -62,109 +58,65 @@ use SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff; use SlevomatCodingStandard\Sniffs\Variables\UselessVariableSniff; use SlevomatCodingStandard\Sniffs\Whitespaces\DuplicateSpacesSniff; -use Symplify\EasyCodingStandard\ValueObject\Option; return static function (ContainerConfigurator $containerConfigurator): void { $services = $containerConfigurator->services(); + $services->set(DisallowImplicitArrayCreationSniff::class); $services->set(TrailingArrayCommaSniff::class); - $services->set(NamespaceSpacingSniff::class); - $services->set(RequireOneNamespaceInFileSniff::class); - $services->set(FullyQualifiedClassNameInAnnotationSniff::class); - $services->set(UseDoesNotStartWithBackslashSniff::class); - $services->set(UseSpacingSniff::class); - $services->set(SpreadOperatorSpacingSniff::class); - $services->set(ShortListSniff::class); - $services->set(ParameterTypeHintSpacingSniff::class); - $services->set(ReturnTypeHintSpacingSniff::class); $services->set(ClassConstantVisibilitySniff::class); $services->set(DisallowLateStaticBindingForConstantsSniff::class); + $services->set(DisallowMultiConstantDefinitionSniff::class); + $services->set(DisallowMultiPropertyDefinitionSniff::class); $services->set(ModernClassNameReferenceSniff::class); + $services->set(ParentCallSpacingSniff::class); + $services->set(SuperfluousAbstractClassNamingSniff::class); + $services->set(SuperfluousInterfaceNamingSniff::class); + $services->set(SuperfluousTraitNamingSniff::class); + $services->set(TraitUseDeclarationSniff::class); + $services->set(TraitUseSpacingSniff::class) + ->property('linesCountAfterLastUse', 1) + ->property('linesCountAfterLastUseWhenLastInClass', 0) + ->property('linesCountBeforeFirstUse', 0) + ->property('linesCountBetweenUses', 0); + $services->set(UnusedPrivateElementsSniff::class); $services->set(UselessLateStaticBindingSniff::class); - $services->set(DisallowImplicitArrayCreationSniff::class); + $services->set(EmptyCommentSniff::class); + $services->set(ForbiddenCommentsSniff::class); + $services->set(UselessInheritDocCommentSniff::class); $services->set(AssignmentInConditionSniff::class); $services->set(DisallowContinueWithoutIntegerOperandInSwitchSniff::class); $services->set(DisallowYodaComparisonSniff::class); $services->set(LanguageConstructWithParenthesesSniff::class); + $services->set(RequireShortTernaryOperatorSniff::class); $services->set(DeadCatchSniff::class); + $services->set(ReferenceThrowableOnlySniff::class); $services->set(UnusedInheritedVariablePassedToClosureSniff::class); $services->set(UselessParameterDefaultValueSniff::class); + $services->set(FullyQualifiedClassNameInAnnotationSniff::class); + $services->set(NamespaceDeclarationSniff::class); + $services->set(NamespaceSpacingSniff::class); + $services->set(RequireOneNamespaceInFileSniff::class); + $services->set(UseDoesNotStartWithBackslashSniff::class); $services->set(UseFromSameNamespaceSniff::class); + $services->set(UseSpacingSniff::class); $services->set(UselessAliasSniff::class); $services->set(RequireCombinedAssignmentOperatorSniff::class); $services->set(RequireOnlyStandaloneIncrementAndDecrementOperatorsSniff::class); + $services->set(SpreadOperatorSpacingSniff::class); + $services->set(DisallowDirectMagicInvokeCallSniff::class); $services->set(OptimizedFunctionsWithoutUnpackingSniff::class); + $services->set(ShortListSniff::class); $services->set(TypeCastSniff::class); $services->set(UselessParenthesesSniff::class); $services->set(UselessSemicolonSniff::class); - $services->set(DuplicateAssignmentToVariableSniff::class); - $services->set(UselessVariableSniff::class); - $services->set(EmptyCommentSniff::class); - $services->set(ForbiddenCommentsSniff::class); - $services->set(InlineDocCommentDeclarationSniff::class); - $services->set(UselessFunctionDocCommentSniff::class); - $services->set(UselessInheritDocCommentSniff::class); $services->set(LongTypeHintsSniff::class); - $services->set(NullableTypeForNullDefaultValueSniff::class); $services->set(NullTypeHintOnLastPositionSniff::class); + $services->set(NullableTypeForNullDefaultValueSniff::class); + $services->set(ParameterTypeHintSpacingSniff::class); + $services->set(ReturnTypeHintSpacingSniff::class); $services->set(UselessConstantTypeHintSniff::class); - $services->set(SuperfluousAbstractClassNamingSniff::class); - $services->set(SuperfluousInterfaceNamingSniff::class); - $services->set(NamespaceDeclarationSniff::class); - $services->set(SuperfluousTraitNamingSniff::class); - $services->set(DisallowDirectMagicInvokeCallSniff::class); + $services->set(DuplicateAssignmentToVariableSniff::class); $services->set(UnusedVariableSniff::class); - $services->set(UselessVariableSniff::class); - - $services->set(UnusedInheritedVariablePassedToClosureSniff::class); - - $services->set(UselessSemicolonSniff::class); - - $services->set(UselessParenthesesSniff::class); - $services->set(UnusedPrivateElementsSniff::class); - $services->set(RequireShortTernaryOperatorSniff::class); - - $services->set(RequireCombinedAssignmentOperatorSniff::class); - $services->set(DisallowCommentAfterCodeSniff::class); - $services->set(EmptyCommentSniff::class); - $services->set(DisallowMultiConstantDefinitionSniff::class); - - $services->set(DisallowMultiPropertyDefinitionSniff::class); - $services->set(ModernClassNameReferenceSniff::class); - $services->set(TraitUseDeclarationSniff::class); - - $services->set(NullTypeHintOnLastPositionSniff::class); - $services->set(UselessAliasSniff::class); - - $services->set(ParentCallSpacingSniff::class); - $services->set(DuplicateSpacesSniff::class); - $services->set(TraitUseSpacingSniff::class) - ->property('linesCountAfterLastUse', 1) - ->property('linesCountAfterLastUseWhenLastInClass', 0) - ->property('linesCountBeforeFirstUse', 0) - ->property('linesCountBetweenUses', 0); - - $services->set(UnusedPrivateElementsSniff::class); - - $services->set(UnusedInheritedVariablePassedToClosureSniff::class); - - $services->set(UnusedParameterSniff::class); - - $services->set(UnusedVariableSniff::class); - - $services->set(ReferenceThrowableOnlySniff::class); - - $parameters = $containerConfigurator->parameters(); - $parameters->set( - Option::SKIP, - [ - UnusedParameterSniff::class . '.UnusedParameter' => null, - DisallowCommentAfterCodeSniff::class . '.DisallowedCommentAfterCode' => null, - InlineDocCommentDeclarationSniff::class . '.MissingVariable' => null, - InlineDocCommentDeclarationSniff::class . '.NoAssignment' => null, - UselessFunctionDocCommentSniff::class . '.UselessDocComment' => null, - ModernClassNameReferenceSniff::class . '.ClassNameReferencedViaFunctionCall' => null, - ] - ); }; diff --git a/correct/Bar.php b/correct/Bar.php index 02651d9..9582ff2 100644 --- a/correct/Bar.php +++ b/correct/Bar.php @@ -4,6 +4,6 @@ namespace Zing\CodingStandard\Correct; -class Bar +final class Bar { } diff --git a/correct/Concerns/Comparable.php b/correct/Concerns/Comparable.php new file mode 100644 index 0000000..42816b0 --- /dev/null +++ b/correct/Concerns/Comparable.php @@ -0,0 +1,9 @@ + + */ public static $config = [ // test 'test' => true, @@ -36,7 +39,7 @@ final class TestClass implements TestableContract public $bar; /** - * TestClass constructor + * TestClass constructor. * * @param \Zing\CodingStandard\Correct\Foo $foo * @param \Zing\CodingStandard\Correct\Bar $bar @@ -50,8 +53,6 @@ public function __construct(Foo $foo, Bar $bar) /** * @param $a * @param $b - * - * @return int */ public function a($a, $b): int { @@ -62,7 +63,7 @@ public function a($a, $b): int return $a + $b; } - public function concat($a) + public function concat($a): string { return $a . ''; } @@ -71,7 +72,7 @@ public function test(): void { } - public function formatConst() + public function formatConst(): int { return self::A ?? self::C; } @@ -110,22 +111,25 @@ public function logicalOperators(): bool return random_int(0, 1) !== 0 && random_int(0, 1) !== 0; } - public function useFunction() + public function useFunction(): int { return count([]); } - public function useConst() + public function useConst(): string { return PHP_EOL; } - public function testSingleArray() + /** + * @return string[] + */ + public function testSingleArray(): array { return ['a', 'b']; // post statement comment } - public function testScopeClosingBrace() + public function testScopeClosingBrace(): array { return [ 'eventCrowd' => function ($query) { diff --git a/ecs.php b/ecs.php index f8c98f8..46dd4e2 100644 --- a/ecs.php +++ b/ecs.php @@ -2,6 +2,7 @@ declare(strict_types=1); +use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer; use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; use Symplify\EasyCodingStandard\ValueObject\Option; use Symplify\EasyCodingStandard\ValueObject\Set\SetList; @@ -21,7 +22,12 @@ SetList::PSR_12, ] ); - + $parameters->set( + Option::SKIP, + [ + YodaStyleFixer::class => null, + ] + ); $parameters->set( Option::PATHS, [ diff --git a/rector.php b/rector.php index 2925a39..6d18bbc 100644 --- a/rector.php +++ b/rector.php @@ -43,7 +43,6 @@ $parameters->set( Option::SETS, [ - SetList::ARRAY_STR_FUNCTIONS_TO_STATIC_CALL, SetList::DOCTRINE_CODE_QUALITY, SetList::CODING_STYLE, SetList::CODE_QUALITY, @@ -57,6 +56,8 @@ SetList::PHP_71, SetList::PHP_72, SetList::EARLY_RETURN, + SetList::TYPE_DECLARATION, + SetList::TYPE_DECLARATION_STRICT, ] ); diff --git a/tests/StyleTest.php b/tests/StyleTest.php index a6cdde8..f6d792a 100644 --- a/tests/StyleTest.php +++ b/tests/StyleTest.php @@ -4,25 +4,29 @@ namespace Zing\CodingStandard\Tests; +/** + * @internal + * @coversNothing + */ final class StyleTest extends TestCase { public function testFileFixed(): void { - $this->assertFileEquals(__DIR__ . '/../correct/file.php', __DIR__ . '/../fixed/file.php'); + self::assertFileEquals(__DIR__ . '/../correct/file.php', __DIR__ . '/../fixed/file.php'); } public function testClassFixed(): void { - $this->assertFileEquals(__DIR__ . '/../correct/TestClass.php', __DIR__ . '/../fixed/TestClass.php'); + self::assertFileEquals(__DIR__ . '/../correct/TestClass.php', __DIR__ . '/../fixed/TestClass.php'); } public function testTraitFixed(): void { - $this->assertFileEquals(__DIR__ . '/../correct/Concerns/Testable.php', __DIR__ . '/../fixed/Concerns/Testable.php'); + self::assertFileEquals(__DIR__ . '/../correct/Concerns/Testable.php', __DIR__ . '/../fixed/Concerns/Testable.php'); } public function testInterfaceFixed(): void { - $this->assertFileEquals(__DIR__ . '/../correct/TestableContract.php', __DIR__ . '/../fixed/TestableContract.php'); + self::assertFileEquals(__DIR__ . '/../correct/TestableContract.php', __DIR__ . '/../fixed/TestableContract.php'); } } diff --git a/tests/TestCase.php b/tests/TestCase.php index ded136e..95b31b4 100644 --- a/tests/TestCase.php +++ b/tests/TestCase.php @@ -6,6 +6,10 @@ use PHPUnit\Framework\TestCase as BaseTestCase; +/** + * @internal + * @coversNothing + */ class TestCase extends BaseTestCase { }