diff --git a/CHANGELOG.md b/CHANGELOG.md index 9807c72..21c01e0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ ## Unreleased - Replace `Symplify\CodingStandard\Sniffs\Naming\[AbstractClassNameSniff, ClassNameSuffixByParentSniff, InterfaceNameSniff and TraitNameSniff]` with equivalent versions backported to this repository. - Drop PHP 7.2 support. +- **[BC break]** Change YAML config to PHP. +- Upgrade to easy-coding-standard 9. ## 2.1.0 - 2020-11-25 - Add various dangerous function calls to list of forbidden functions. diff --git a/composer.json b/composer.json index 11ee710..b4a6e4d 100644 --- a/composer.json +++ b/composer.json @@ -13,16 +13,7 @@ "php": "^7.3", "friendsofphp/php-cs-fixer": "^2.16.3", "slevomat/coding-standard": "^6.4.1", - "symplify/auto-bind-parameter": "<8.1.21", - "symplify/autowire-array-parameter": "<8.1.21", - "symplify/coding-standard": "<8.1.21", - "symplify/console-color-diff": "<8.1.21", - "symplify/easy-coding-standard": "<8.1.21", - "symplify/package-builder": "<8.1.21", - "symplify/parameter-name-guard": "<8.1.21", - "symplify/phpstan-extensions": "<8.1.21", - "symplify/set-config-resolver": "<8.1.21", - "symplify/smart-file-system": "<8.1.21" + "symplify/easy-coding-standard": "^9.0.50" }, "require-dev": { "ergebnis/composer-normalize": "^2.11", @@ -58,19 +49,17 @@ "@test" ], "analyze": [ - "vendor/bin/ecs check src/ tests/ --ansi", + "vendor/bin/ecs check src/ tests/ ecs.php --ansi", "vendor/bin/phpstan.phar analyze -c phpstan.neon --ansi" ], "fix": [ "@composer normalize", - "vendor/bin/ecs check ./src/ ./tests/ --ansi --fix" + "vendor/bin/ecs check ./src/ ./tests/ ecs.php --ansi --fix" ], "lint": [ - "vendor/bin/parallel-lint -j 10 -e php ./src ./tests", + "vendor/bin/parallel-lint -j 10 -e php ./src ./tests ecs.php", "@composer validate", - "@composer normalize --dry-run", - "for FILE_NAME in *.yml *.yaml; do vendor/bin/yaml-lint \"$FILE_NAME\"; done", - "vendor/bin/yaml-sort-checker" + "@composer normalize --dry-run" ], "test": [ "vendor/bin/phpunit --colors=always" diff --git a/easy-coding-standard.yaml b/easy-coding-standard.yaml deleted file mode 100644 index 07d1967..0000000 --- a/easy-coding-standard.yaml +++ /dev/null @@ -1,288 +0,0 @@ -imports: - # Import path of PSR2 rules when this package is installed as a dependency (in vendor dir) - - { resource: '../../symplify/easy-coding-standard/config/set/psr2.yaml', ignore_errors: not_found } - # Import path of PSR2 rules when this package is used directly (during development) - - { resource: 'vendor/symplify/easy-coding-standard/config/set/psr2.yaml', ignore_errors: not_found } - -services: - # Function http_build_query() should always have specified `$arg_separator` parameter - Lmc\CodingStandard\Fixer\SpecifyArgSeparatorFixer: ~ - # Abstract class should have prefix "Abstract" - Lmc\CodingStandard\Sniffs\Naming\AbstractClassNameSniff: ~ - # Classes should have suffix by theirs parent class/interface - Lmc\CodingStandard\Sniffs\Naming\ClassNameSuffixByParentSniff: - # Interface should have suffix "Interface" - Lmc\CodingStandard\Sniffs\Naming\InterfaceNameSniff: ~ - # Trait should have suffix "Trait" - Lmc\CodingStandard\Sniffs\Naming\TraitNameSniff: ~ - - # Class and Interface names should be unique in a project, they should never be duplicated - PHP_CodeSniffer\Standards\Generic\Sniffs\Classes\DuplicateClassNameSniff: ~ - # Control Structures must have at least one statement inside of the body (empty catch rules is skipped) - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff: ~ - # For loops that have only a second expression (the condition) should be converted to while loops - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\ForLoopShouldBeWhileLoopSniff: ~ - # Incrementers in nested loops should use different variable names - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\JumbledIncrementerSniff: ~ - # If statements that are always evaluated should not be used - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UnconditionalIfStatementSniff: ~ - # Methods should not be declared final inside of classes that are declared final - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UnnecessaryFinalModifierSniff: ~ - # Methods should not be defined that only call the parent method - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\UselessOverridingMethodSniff: ~ - # Doc comment formatting (but some of the rules are skipped) - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff: ~ - # Line length should not exceed 120 characters - PHP_CodeSniffer\Standards\Generic\Sniffs\Files\LineLengthSniff: - absoluteLineLimit: 0 - lineLimit: 120 - # There should only be one class defined in a file - PHP_CodeSniffer\Standards\Generic\Sniffs\Files\OneClassPerFileSniff: ~ - # There should only be one interface defined in a file - PHP_CodeSniffer\Standards\Generic\Sniffs\Files\OneInterfacePerFileSniff: ~ - # There should only be one trait defined in a file - PHP_CodeSniffer\Standards\Generic\Sniffs\Files\OneTraitPerFileSniff: ~ - # Exactly one space is allowed after a cast - PHP_CodeSniffer\Standards\Generic\Sniffs\Formatting\SpaceAfterCastSniff: ~ - # Some functions should not appear in the code - PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff: - forbiddenFunctions: - # Program execution functions, inspired by https://github.com/spaze/phpstan-disallowed-calls - exec: null - passthru: null - proc_open: null - shell_exec: null - system: null - pcntl_exec: null - popen: null - - # Dangerous function calls, inspired by https://github.com/spaze/phpstan-disallowed-calls - apache_setenv: null # might overwrite existing variables - dl: null # removed from most SAPIs, might load untrusted code - eval: null # eval is evil, please write more code and do not use eval() - extract: null # do not use extract() and especially not on untrusted data - highlight_file: null # might reveal source code or config files - pfsockopen: null # use fsockopen() to create non-persistent socket connections - posix_getpwuid: null # might reveal system user information - posix_kill: null # do not send signals to processes from the script - posix_mkfifo: null # do not create named pipes in the script - posix_mknod: null # do not create special files in the script - proc_nice: null # changes the priority of the current process - putenv: null # might overwrite existing variables - show_source: null # might reveal source code or config files (alias of highlight_file()) - socket_create_listen: null # do not accept new socket connections in the PHP script - socket_listen: null # do not accept new socket connections in the PHP script - - # PHP include/require functions, use autoloading instead - include: null - include_once: null - require: null - require_once: null - - # Probably forgotten debug calls, use logger instead - dump: null - echo: null - phpinfo: null - print_r: null - printf: null - var_export: null - var_dump: null - - # When referencing arrays you should not put whitespace around the opening bracket or before the closing bracket - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayBracketSpacingSniff: ~ - # Various array declaration rules (but some of the rules are skipped) - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff: ~ - # The self keyword should be used instead of the current class name - PHP_CodeSniffer\Standards\Squiz\Sniffs\Classes\SelfMemberReferenceSniff: ~ - # The asterisks in a doc comment should align, and there should be one space between the asterisk and tags - PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\DocCommentAlignmentSniff: ~ - # Empty catch statements must have comment explaining why the exception is not handled - PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\EmptyCatchCommentSniff: ~ - # Tests that the ++ operators are used when possible and not used when it makes the code confusing - PHP_CodeSniffer\Standards\Squiz\Sniffs\Operators\IncrementDecrementUsageSniff: ~ - # Verifies that class members have scope modifiers - PHP_CodeSniffer\Standards\Squiz\Sniffs\Scope\MemberVarScopeSniff: ~ - # Casts should not have whitespace inside the parentheses - PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\CastSpacingSniff: ~ - # The php constructs like echo, return, include, etc. should have one space after them - PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LanguageConstructSpacingSniff: ~ - # Verifies that operators have valid spacing surrounding them - PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\LogicalOperatorSpacingSniff: ~ - # Proper operator spacing - PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\OperatorSpacingSniff: - ignoreNewlines: true - # The php keywords static, public, private, and protected should have one space after them - PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\ScopeKeywordSpacingSniff: ~ - # Semicolons should not have spaces before them - PHP_CodeSniffer\Standards\Squiz\Sniffs\WhiteSpace\SemicolonSpacingSniff: ~ - - PhpCsFixer\Fixer\Alias\MbStrFunctionsFixer: ~ - PhpCsFixer\Fixer\Alias\NoAliasFunctionsFixer: ~ - PhpCsFixer\Fixer\Alias\RandomApiMigrationFixer: ~ - # Cast shall be used, not `settype()` - PhpCsFixer\Fixer\Alias\SetTypeToCastFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\ArraySyntaxFixer: - syntax: short - PhpCsFixer\Fixer\ArrayNotation\NormalizeIndexBraceFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\NoTrailingCommaInSinglelineArrayFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\TrailingCommaInMultilineArrayFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer: ~ - PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer: ~ - PhpCsFixer\Fixer\Basic\BracesFixer: - allow_single_line_closure: true - PhpCsFixer\Fixer\Basic\Psr4Fixer: ~ - PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer: ~ - PhpCsFixer\Fixer\Casing\NativeFunctionCasingFixer: ~ - # Native type hints for functions should use the correct case - PhpCsFixer\Fixer\Casing\NativeFunctionTypeDeclarationCasingFixer: - PhpCsFixer\Fixer\CastNotation\CastSpacesFixer: ~ - PhpCsFixer\Fixer\CastNotation\LowercaseCastFixer: ~ - PhpCsFixer\Fixer\CastNotation\ShortScalarCastFixer: ~ - PhpCsFixer\Fixer\ClassNotation\ClassAttributesSeparationFixer: - elements: - - method - PhpCsFixer\Fixer\ClassNotation\NoBlankLinesAfterClassOpeningFixer: ~ - PhpCsFixer\Fixer\ClassNotation\SelfAccessorFixer: ~ - # Each trait `use` must be done as single statement - PhpCsFixer\Fixer\ClassNotation\SingleTraitInsertPerStatementFixer: ~ - # Visibility MUST be declared on all properties, methods and class constants - PhpCsFixer\Fixer\ClassNotation\VisibilityRequiredFixer: - elements: - - const - - method - - property - PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer: ~ - PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer: ~ - PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer: - equal: false - identical: false - less_and_greater: false - # Replace multiple nested calls of `dirname` by only one call with second `$level` parameter. - PhpCsFixer\Fixer\FunctionNotation\CombineNestedDirnameFixer: ~ - # Order the flags in `fopen` calls, `b` and `t` must be last. - PhpCsFixer\Fixer\FunctionNotation\FopenFlagOrderFixer: ~ - # The flags in `fopen` calls must contain `b` and must omit `t`. - PhpCsFixer\Fixer\FunctionNotation\FopenFlagsFixer: ~ - # Add missing space between function's argument and its typehint. - PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer: ~ - # Function `implode` must be called with 2 arguments in the documented order. - PhpCsFixer\Fixer\FunctionNotation\ImplodeCallFixer: ~ - PhpCsFixer\Fixer\FunctionNotation\NoUnreachableDefaultArgumentValueFixer: ~ - PhpCsFixer\Fixer\FunctionNotation\ReturnTypeDeclarationFixer: ~ - PhpCsFixer\Fixer\FunctionNotation\VoidReturnFixer: ~ - PhpCsFixer\Fixer\Import\NoLeadingImportSlashFixer: ~ - PhpCsFixer\Fixer\Import\NoUnusedImportsFixer: - PhpCsFixer\Fixer\Import\OrderedImportsFixer: ~ - PhpCsFixer\Fixer\LanguageConstruct\DeclareEqualNormalizeFixer: ~ - PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer: - use_yoda_style: false - PhpCsFixer\Fixer\ListNotation\ListSyntaxFixer: - syntax: short - PhpCsFixer\Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer: ~ - PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer: ~ - PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer: ~ - PhpCsFixer\Fixer\Operator\ConcatSpaceFixer: - spacing: one - PhpCsFixer\Fixer\Operator\NewWithBracesFixer: ~ - PhpCsFixer\Fixer\Operator\ObjectOperatorWithoutWhitespaceFixer: ~ - PhpCsFixer\Fixer\Operator\StandardizeNotEqualsFixer: ~ - PhpCsFixer\Fixer\Operator\TernaryOperatorSpacesFixer: ~ - PhpCsFixer\Fixer\Operator\TernaryToNullCoalescingFixer: ~ - PhpCsFixer\Fixer\Operator\UnaryOperatorSpacesFixer: ~ - PhpCsFixer\Fixer\Phpdoc\NoBlankLinesAfterPhpdocFixer: ~ - PhpCsFixer\Fixer\Phpdoc\NoEmptyPhpdocFixer: ~ - # Removes `@param` and `@return` tags that don't provide any useful information - PhpCsFixer\Fixer\Phpdoc\NoSuperfluousPhpdocTagsFixer: - allow_mixed: true # allow `@mixed` annotations to be preserved - allow_unused_params: false # whether param annotation without actual signature is allowed - remove_inheritdoc: true # remove @inheritDoc tags - PhpCsFixer\Fixer\Phpdoc\PhpdocAddMissingParamAnnotationFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocIndentFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoAccessFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoEmptyReturnFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocNoPackageFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocOrderFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocReturnSelfReferenceFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocScalarFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocSingleLineVarSpacingFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocTrimFixer: ~ - PhpCsFixer\Fixer\Phpdoc\PhpdocTypesFixer: ~ - # `@var` and `@type` annotations must have type and name in the correct order - PhpCsFixer\Fixer\Phpdoc\PhpdocVarAnnotationCorrectOrderFixer: ~ - PhpCsFixer\Fixer\PhpTag\FullOpeningTagFixer: ~ - PhpCsFixer\Fixer\PhpUnit\PhpUnitConstructFixer: ~ - # PHPUnit assertions like assertInternalType, assertFileExists, should be used over assertTrue - PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertFixer: ~ - # PHPUnit assertions like assertIsArray should be used over assertInternalType - PhpCsFixer\Fixer\PhpUnit\PhpUnitDedicateAssertInternalTypeFixer: - # Use dedicated helper methods createMock() and createPartialMock() where possible - PhpCsFixer\Fixer\PhpUnit\PhpUnitMockFixer: ~ - # Use of eg. ->will($this->returnValue(..)) must be replaced by its shorter equivalent such as ->willReturn(...) - PhpCsFixer\Fixer\PhpUnit\PhpUnitMockShortWillReturnFixer: ~ - # Use expectedException*() methods instead of @expectedException* annotation (both following fixers must be applied to do so) - PhpCsFixer\Fixer\PhpUnit\PhpUnitNoExpectationAnnotationFixer: ~ - PhpCsFixer\Fixer\PhpUnit\PhpUnitExpectationFixer: ~ - # Order `@covers` annotation of PHPUnit tests - PhpCsFixer\Fixer\PhpUnit\PhpUnitOrderedCoversFixer: ~ - # Visibility of setUp() and tearDown() method should be kept protected - PhpCsFixer\Fixer\PhpUnit\PhpUnitSetUpTearDownVisibilityFixer: ~ - # Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type (`$this->...`) - PhpCsFixer\Fixer\PhpUnit\PhpUnitTestCaseStaticMethodCallsFixer: - call_type: 'this' - PhpCsFixer\Fixer\ReturnNotation\NoUselessReturnFixer: ~ - PhpCsFixer\Fixer\Semicolon\NoEmptyStatementFixer: ~ - PhpCsFixer\Fixer\Semicolon\NoSinglelineWhitespaceBeforeSemicolonsFixer: ~ - PhpCsFixer\Fixer\Semicolon\SpaceAfterSemicolonFixer: ~ - PhpCsFixer\Fixer\Strict\DeclareStrictTypesFixer: ~ - PhpCsFixer\Fixer\Strict\StrictParamFixer: ~ - PhpCsFixer\Fixer\StringNotation\SingleQuoteFixer: ~ - PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer: - statements: - - return - - try - PhpCsFixer\Fixer\Whitespace\CompactNullableTypehintFixer: ~ - PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer: - tokens: - - break - - continue - - curly_brace_block - - extra - - parenthesis_brace_block - - return - - square_brace_block - - throw - - use - - use_trait - PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer: ~ - - SlevomatCodingStandard\Sniffs\Exceptions\ReferenceThrowableOnlySniff: ~ - # The @param, @return, @var and inline @var annotations should keep standard format - Symplify\CodingStandard\Fixer\Commenting\ParamReturnAndVarTagMalformsFixer: ~ - -parameters: - skip: - # We allow empty catch statements (but they must have comment - see EmptyCatchCommentSniff) - PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff.DetectedCatch: ~ - - # Skip unwanted rules from DocCommentSniff - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ContentAfterOpen: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ContentBeforeClose: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.MissingShort: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.NonParamGroup: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ParamGroup: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ParamNotFirst: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.SpacingBeforeTags: ~ - PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.TagValueIndent: ~ - - # Skip unwanted rules from ArrayDeclarationSniff - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.CloseBraceNotAligned: ~ - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.DoubleArrowNotAligned: ~ - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.KeyNotAligned: ~ - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.MultiLineNotAllowed: ~ - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.SingleLineNotAllowed: ~ - # Temporarily disable ValueNoNewline because of bug in PHP_CodeSniffer 3.5.5 https://github.com/squizlabs/PHP_CodeSniffer/issues/2937 - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.ValueNoNewline: ~ - PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.ValueNotAligned: ~ - - # There could be more than one space after star (eg. in Doctrine annotations) - PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\DocCommentAlignmentSniff.SpaceAfterStar: ~ diff --git a/ecs.php b/ecs.php new file mode 100644 index 0000000..dcf064a --- /dev/null +++ b/ecs.php @@ -0,0 +1,479 @@ +import($vendorDir . '/symplify/easy-coding-standard/config/set/php_cs_fixer/php-cs-fixer-psr2.php'); + $containerConfigurator->import($vendorDir . '/symplify/easy-coding-standard/config/set/php_codesniffer/php-codesniffer-psr2.php'); + + $services = $containerConfigurator->services(); + (function () use ($services): void { + // Function http_build_query() should always have specified `$arg_separator` parameter + $services->set(SpecifyArgSeparatorFixer::class); + // Abstract class should have prefix "Abstract" + $services->set(AbstractClassNameSniff::class); + // Classes should have suffix by theirs parent class/interface + $services->set(ClassNameSuffixByParentSniff::class); + // Interface should have suffix "Interface" + $services->set(InterfaceNameSniff::class); + // Trait should have suffix "Trait" + $services->set(TraitNameSniff::class); + // Class and Interface names should be unique in a project, they should never be duplicated + $services->set(DuplicateClassNameSniff::class); + // Control Structures must have at least one statement inside of the body (empty catch rules is skipped) + $services->set(EmptyStatementSniff::class); + // For loops that have only a second expression (the condition) should be converted to while loops + $services->set(ForLoopShouldBeWhileLoopSniff::class); + // Incrementers in nested loops should use different variable names + $services->set(JumbledIncrementerSniff::class); + // If statements that are always evaluated should not be used + $services->set(UnconditionalIfStatementSniff::class); + // Methods should not be declared final inside of classes that are declared final + $services->set(UnnecessaryFinalModifierSniff::class); + // Methods should not be defined that only call the parent method + $services->set(UselessOverridingMethodSniff::class); + // Doc comment formatting (but some of the rules are skipped) + $services->set(DocCommentSniff::class); + // Line length should not exceed 120 characters + $services->set(LineLengthSniff::class) + ->property('absoluteLineLimit', 0) + ->property('lineLimit', 120); + // There should only be one class defined in a file + $services->set(OneClassPerFileSniff::class); + // There should only be one interface defined in a file + $services->set(OneInterfacePerFileSniff::class); + // There should only be one trait defined in a file + $services->set(OneTraitPerFileSniff::class); + // Exactly one space is allowed after a cast + $services->set(SpaceAfterCastSniff::class); + // Some functions should not appear in the code + $services->set(ForbiddenFunctionsSniff::class) + ->property( + 'forbiddenFunctions', + [ + // Program execution functions, inspired by https://github.com/spaze/phpstan-disallowed-calls + 'exec' => null, + 'passthru' => null, + 'proc_open' => null, + 'shell_exec' => null, + 'system' => null, + 'pcntl_exec' => null, + 'popen' => null, + + // Dangerous function calls, inspired by https://github.com/spaze/phpstan-disallowed-calls + 'apache_setenv' => null, // might overwrite existing variables + 'dl' => null, // removed from most SAPIs, might load untrusted code + 'eval' => null, // eval is evil, please write more code and do not use eval() + 'extract' => null, // do not use extract() and especially not on untrusted data + 'highlight_file' => null, // might reveal source code or config files + 'pfsockopen' => null, // use fsockopen() to create non-persistent socket connections + 'posix_getpwuid' => null, // might reveal system user information + 'posix_kill' => null, // do not send signals to processes from the script + 'posix_mkfifo' => null, // do not create named pipes in the script + 'posix_mknod' => null, // do not create special files in the script + 'proc_nice' => null, // changes the priority of the current process + 'putenv' => null, // might overwrite existing variables + 'show_source' => null, // might reveal source code or config files (alias of highlight_file()) + 'socket_create_listen' => null, // do not accept new socket connections in the PHP script + 'socket_listen' => null, // do not accept new socket connections in the PHP script + + // PHP include/require functions, use autoloading instead + 'include' => null, + 'include_once' => null, + 'require' => null, + 'require_once' => null, + + // Probably forgotten debug calls, use logger instead + 'dump' => null, + 'echo' => null, + 'phpinfo' => null, + 'print_r' => null, + 'printf' => null, + 'var_export' => null, + 'var_dump' => null, + ] + ); + // When referencing arrays you should not put whitespace around the opening bracket or before the closing bracket + $services->set(ArrayBracketSpacingSniff::class); + // Various array declaration rules (but some of the rules are skipped) + $services->set(ArrayDeclarationSniff::class); + // The self keyword should be used instead of the current class name + $services->set(SelfMemberReferenceSniff::class); + // The asterisks in a doc comment should align, and there should be one space between the asterisk and tags + $services->set(DocCommentAlignmentSniff::class); + // Empty catch statements must have comment explaining why the exception is not handled + $services->set(EmptyCatchCommentSniff::class); + // Tests that the ++ operators are used when possible and not used when it makes the code confusing + $services->set(IncrementDecrementUsageSniff::class); + // Verifies that class members have scope modifiers + $services->set(MemberVarScopeSniff::class); + // Casts should not have whitespace inside the parentheses + $services->set(CastSpacingSniff::class); + // The php constructs like echo, return, include, etc. should have one space after them + $services->set(LanguageConstructSpacingSniff::class); + // Verifies that operators have valid spacing surrounding them + $services->set(LogicalOperatorSpacingSniff::class); + // Proper operator spacing + $services->set(OperatorSpacingSniff::class) + ->property('ignoreNewlines', true); + // The php keywords static, public, private, and protected should have one space after them + $services->set(ScopeKeywordSpacingSniff::class); + // Semicolons should not have spaces before them + $services->set(SemicolonSpacingSniff::class); + // Replace non multibyte-safe functions with corresponding mb function + $services->set(MbStrFunctionsFixer::class); + // Master functions shall be used instead of aliases + $services->set(NoAliasFunctionsFixer::class); + // Replaces `rand`, `srand`, `getrandmax` functions calls with their `mt_*` analogs + $services->set(RandomApiMigrationFixer::class); + // Cast shall be used, not `settype()` + $services->set(SetTypeToCastFixer::class); + // PHP arrays should be declared using the configured syntax + $services->set(ArraySyntaxFixer::class) + ->call('configure', [['syntax' => 'short']]); + // Array index should always be written by using square braces + $services->set(NormalizeIndexBraceFixer::class); + // PHP single-line arrays should not have trailing comma + $services->set(NoTrailingCommaInSinglelineArrayFixer::class); + // PHP multi-line arrays should have a trailing comma + $services->set(TrailingCommaInMultilineArrayFixer::class); + // Arrays should be formatted like function/method arguments + $services->set(TrimArraySpacesFixer::class); + // In array declaration, there MUST be a whitespace after each comma + $services->set(WhitespaceAfterCommaInArrayFixer::class); + // The body of each structure MUST be enclosed by braces. Braces should be properly placed + $services->set(BracesFixer::class) + ->call('configure', [['allow_single_line_closure' => true]]); + // Class names should match the file name according to PSR-4 + $services->set(Psr4Fixer::class); + // Magic method definitions and calls must be using the correct casing + $services->set(MagicMethodCasingFixer::class); + // Function defined by PHP should be called using the correct casing + $services->set(NativeFunctionCasingFixer::class); + // Native type hints for functions should use the correct case + $services->set(NativeFunctionTypeDeclarationCasingFixer::class); + // A single space or none should be between cast and variable + $services->set(CastSpacesFixer::class); + // Cast should be written in lower case + $services->set(LowercaseCastFixer::class); + // Cast like `(boolean)` and `(integer)` should be written as `(bool)`, `(int)` etc. + $services->set(ShortScalarCastFixer::class); + // Class, trait and interface elements must be separated with one or none blank line + $services->set(ClassAttributesSeparationFixer::class) + ->call('configure', [['elements' => ['method']]]); + // There should be no empty lines after class opening brace + $services->set(NoBlankLinesAfterClassOpeningFixer::class); + // Inside class or interface element `self` should be preferred to the class name itself + $services->set(SelfAccessorFixer::class); + // Each trait `use` must be done as single statement + $services->set(SingleTraitInsertPerStatementFixer::class); + // Visibility MUST be declared on all properties, methods and class constants + $services->set(VisibilityRequiredFixer::class) + ->call('configure', [['elements' => ['const', 'method', 'property']]]); + // There should not be any empty comments + $services->set(NoEmptyCommentFixer::class); + // There should not be useless `else` cases + $services->set(NoUselessElseFixer::class); + // Conditions must be written in non-Yoda style + $services->set(YodaStyleFixer::class) + ->call('configure', [['equal' => false, 'identical' => false, 'less_and_greater' => false]]); + // Replace multiple nested calls of `dirname` by only one call with second `$level` parameter. + $services->set(CombineNestedDirnameFixer::class); + // Order the flags in `fopen` calls, `b` and `t` must be last. + $services->set(FopenFlagOrderFixer::class); + // The flags in `fopen` calls must contain `b` and must omit `t`. + $services->set(FopenFlagsFixer::class); + // Add missing space between function's argument and its typehint. + $services->set(FunctionTypehintSpaceFixer::class); + // Function `implode` must be called with 2 arguments in the documented order. + $services->set(ImplodeCallFixer::class); + + $services->set(NoUnreachableDefaultArgumentValueFixer::class); + + $services->set(ReturnTypeDeclarationFixer::class); + + $services->set(VoidReturnFixer::class); + + $services->set(NoLeadingImportSlashFixer::class); + + $services->set(NoUnusedImportsFixer::class); + + $services->set(OrderedImportsFixer::class); + + $services->set(DeclareEqualNormalizeFixer::class); + + $services->set(IsNullFixer::class) + ->call('configure', [['use_yoda_style' => false]]); + + $services->set(ListSyntaxFixer::class) + ->call('configure', [['syntax' => 'short']]); + + $services->set(NoLeadingNamespaceWhitespaceFixer::class); + + $services->set(SingleBlankLineBeforeNamespaceFixer::class); + + $services->set(BinaryOperatorSpacesFixer::class); + + $services->set(ConcatSpaceFixer::class) + ->call('configure', [['spacing' => 'one']]); + + $services->set(NewWithBracesFixer::class); + + $services->set(ObjectOperatorWithoutWhitespaceFixer::class); + + $services->set(StandardizeNotEqualsFixer::class); + + $services->set(TernaryOperatorSpacesFixer::class); + + $services->set(TernaryToNullCoalescingFixer::class); + + $services->set(UnaryOperatorSpacesFixer::class); + + $services->set(NoBlankLinesAfterPhpdocFixer::class); + + $services->set(NoEmptyPhpdocFixer::class); + // Removes `@param` and `@return` tags that don't provide any useful information + $services->set(NoSuperfluousPhpdocTagsFixer::class) + ->call( + 'configure', + [ + [ + 'allow_mixed' => true, // allow `@mixed` annotations to be preserved + 'allow_unused_params' => false, // whether param annotation without actual signature is allowed + 'remove_inheritdoc' => true, // remove @inheritDoc tags + ], + ] + ); + + $services->set(PhpdocAddMissingParamAnnotationFixer::class); + + $services->set(PhpdocIndentFixer::class); + + $services->set(PhpdocNoAccessFixer::class); + + $services->set(PhpdocNoEmptyReturnFixer::class); + + $services->set(PhpdocNoPackageFixer::class); + + $services->set(PhpdocOrderFixer::class); + + $services->set(PhpdocReturnSelfReferenceFixer::class); + + $services->set(PhpdocScalarFixer::class); + + $services->set(PhpdocSingleLineVarSpacingFixer::class); + + $services->set(PhpdocTrimFixer::class); + + $services->set(PhpdocTypesFixer::class); + // `@var` and `@type` annotations must have type and name in the correct order + $services->set(PhpdocVarAnnotationCorrectOrderFixer::class); + // PHP code must use the long `set(FullOpeningTagFixer::class); + // PHPUnit assertion method calls like ->assertSame(true, $foo) should be written with dedicated method like ->assertTrue($foo) + $services->set(PhpUnitConstructFixer::class); + // PHPUnit assertions like assertInternalType, assertFileExists, should be used over assertTrue + $services->set(PhpUnitDedicateAssertFixer::class); + // PHPUnit assertions like assertIsArray should be used over assertInternalType + $services->set(PhpUnitDedicateAssertInternalTypeFixer::class); + // Use dedicated helper methods createMock() and createPartialMock() where possible + $services->set(PhpUnitMockFixer::class); + // Use of eg. ->will($this->returnValue(..)) must be replaced by its shorter equivalent such as ->willReturn(...) + $services->set(PhpUnitMockShortWillReturnFixer::class); + // Use expectedException*() methods instead of @expectedException* annotation (both following fixers must be applied to do so) + $services->set(PhpUnitNoExpectationAnnotationFixer::class); + // Usages of ->setExpectedException* methods MUST be replaced by ->expectException* methods + $services->set(PhpUnitExpectationFixer::class); + // Order `@covers` annotation of PHPUnit tests + $services->set(PhpUnitOrderedCoversFixer::class); + // Visibility of setUp() and tearDown() method should be kept protected + $services->set(PhpUnitSetUpTearDownVisibilityFixer::class); + // Calls to `PHPUnit\Framework\TestCase` static methods must all be of the same type (`$this->...`) + $services->set(PhpUnitTestCaseStaticMethodCallsFixer::class) + ->call('configure', [['call_type' => 'this']]); + // There should not be an empty `return` statement at the end of a function + $services->set(NoUselessReturnFixer::class); + // Remove useless (semicolon) statements + $services->set(NoEmptyStatementFixer::class); + // Single-line whitespace before closing semicolon are prohibited + $services->set(NoSinglelineWhitespaceBeforeSemicolonsFixer::class); + // Fix whitespace after a semicolon + $services->set(SpaceAfterSemicolonFixer::class); + // Force strict types declaration in all files + $services->set(DeclareStrictTypesFixer::class); + // Functions should be used with `$strict` param set to `true` + $services->set(StrictParamFixer::class); + // Convert double quotes to single quotes for simple strings + $services->set(SingleQuoteFixer::class); + // An empty line feed must precede any configured statement + $services->set(BlankLineBeforeStatementFixer::class) + ->call('configure', [['statements' => ['return', 'try']]]); + // Remove extra spaces in a nullable typehint + $services->set(CompactNullableTypehintFixer::class); + // Removes extra blank lines and/or blank lines following configuration + $services->set(NoExtraBlankLinesFixer::class) + ->call( + 'configure', + [['tokens' => ['break', 'continue', 'curly_brace_block', 'extra', 'parenthesis_brace_block', 'return', 'square_brace_block', 'throw', 'use', 'use_trait']]] + ); + // Remove trailing whitespace at the end of blank lines + $services->set(NoWhitespaceInBlankLineFixer::class); + // Use \Throwable instead of \Exception + $services->set(ReferenceThrowableOnlySniff::class); + // The @param, @return, @var and inline @var annotations should keep standard format + $services->set(ParamReturnAndVarTagMalformsFixer::class); + })(); + + $parameters = $containerConfigurator->parameters(); + (function () use ($parameters): void { + $parameters->set( + Option::SKIP, + [ + 'PHP_CodeSniffer\Standards\Generic\Sniffs\CodeAnalysis\EmptyStatementSniff.DetectedCatch' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ContentAfterOpen' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ContentBeforeClose' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.MissingShort' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.NonParamGroup' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ParamGroup' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.ParamNotFirst' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.SpacingBeforeTags' => null, + 'PHP_CodeSniffer\Standards\Generic\Sniffs\Commenting\DocCommentSniff.TagValueIndent' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.CloseBraceNotAligned' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.DoubleArrowNotAligned' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.KeyNotAligned' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.MultiLineNotAllowed' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.SingleLineNotAllowed' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.ValueNoNewline' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Arrays\ArrayDeclarationSniff.ValueNotAligned' => null, + 'PHP_CodeSniffer\Standards\Squiz\Sniffs\Commenting\DocCommentAlignmentSniff.SpaceAfterStar' => null, + ] + ); + })(); +}; diff --git a/yaml-sort-checker.yml b/yaml-sort-checker.yml deleted file mode 100644 index cc23ec6..0000000 --- a/yaml-sort-checker.yml +++ /dev/null @@ -1,10 +0,0 @@ -files: - easy-coding-standard.yaml: - depth: 3 - excludedKeys: - 0: parameters - services: - - PhpCsFixer\Fixer\PhpUnit\PhpUnitExpectationFixer - excludedSections: - 0: imports - yaml-sort-checker.yml: