diff --git a/codestyle.php b/codestyle.php index 4445cbf..58858b8 100644 --- a/codestyle.php +++ b/codestyle.php @@ -11,8 +11,7 @@ "bin", "src", "tests/unit", - "tests/codestyle/CodestyleTest.php", - "tests/codestyle/config.php", + "tests/codestyle", ), ); diff --git a/composer.json b/composer.json index fee1314..2034fa1 100644 --- a/composer.json +++ b/composer.json @@ -5,8 +5,8 @@ "type": "library", "require": { "php": "^8.1", - "friendsofphp/php-cs-fixer": "^3.16", - "kubawerlos/php-cs-fixer-custom-fixers": "^3.14" + "friendsofphp/php-cs-fixer": "^3.23", + "kubawerlos/php-cs-fixer-custom-fixers": "^3.16" }, "require-dev": { "jetbrains/phpstorm-attributes": "^1.0", diff --git a/src/Configuration/Defaults/CommonRules.php b/src/Configuration/Defaults/CommonRules.php index f151c21..8ce9c01 100644 --- a/src/Configuration/Defaults/CommonRules.php +++ b/src/Configuration/Defaults/CommonRules.php @@ -10,7 +10,10 @@ use PhpCsFixer\Fixer\ArrayNotation\NoWhitespaceBeforeCommaInArrayFixer; use PhpCsFixer\Fixer\ArrayNotation\TrimArraySpacesFixer; use PhpCsFixer\Fixer\ArrayNotation\WhitespaceAfterCommaInArrayFixer; +use PhpCsFixer\Fixer\Basic\CurlyBracesPositionFixer; +use PhpCsFixer\Fixer\Basic\NoMultipleStatementsPerLineFixer; use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; +use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer; use PhpCsFixer\Fixer\Casing\LowercaseStaticReferenceFixer; use PhpCsFixer\Fixer\Casing\MagicConstantCasingFixer; use PhpCsFixer\Fixer\Casing\MagicMethodCasingFixer; @@ -29,13 +32,14 @@ use PhpCsFixer\Fixer\Comment\NoEmptyCommentFixer; use PhpCsFixer\Fixer\Comment\NoTrailingWhitespaceInCommentFixer; use PhpCsFixer\Fixer\Comment\SingleLineCommentSpacingFixer; +use PhpCsFixer\Fixer\ControlStructure\ControlStructureBracesFixer; +use PhpCsFixer\Fixer\ControlStructure\ControlStructureContinuationPositionFixer; use PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer; use PhpCsFixer\Fixer\ControlStructure\NoUnneededCurlyBracesFixer; use PhpCsFixer\Fixer\ControlStructure\NoUselessElseFixer; use PhpCsFixer\Fixer\ControlStructure\TrailingCommaInMultilineFixer; use PhpCsFixer\Fixer\ControlStructure\YodaStyleFixer; use PhpCsFixer\Fixer\FunctionNotation\FunctionDeclarationFixer; -use PhpCsFixer\Fixer\FunctionNotation\FunctionTypehintSpaceFixer; use PhpCsFixer\Fixer\FunctionNotation\LambdaNotUsedImportFixer; use PhpCsFixer\Fixer\FunctionNotation\MethodArgumentSpaceFixer; use PhpCsFixer\Fixer\FunctionNotation\NullableTypeDeclarationForDefaultNullValueFixer; @@ -52,9 +56,9 @@ use PhpCsFixer\Fixer\LanguageConstruct\FunctionToConstantFixer; use PhpCsFixer\Fixer\LanguageConstruct\IsNullFixer; use PhpCsFixer\Fixer\NamespaceNotation\BlankLineAfterNamespaceFixer; +use PhpCsFixer\Fixer\NamespaceNotation\BlankLinesBeforeNamespaceFixer; use PhpCsFixer\Fixer\NamespaceNotation\CleanNamespaceFixer; use PhpCsFixer\Fixer\NamespaceNotation\NoLeadingNamespaceWhitespaceFixer; -use PhpCsFixer\Fixer\NamespaceNotation\SingleBlankLineBeforeNamespaceFixer; use PhpCsFixer\Fixer\Naming\NoHomoglyphNamesFixer; use PhpCsFixer\Fixer\Operator\AssignNullCoalescingToCoalesceEqualFixer; use PhpCsFixer\Fixer\Operator\BinaryOperatorSpacesFixer; @@ -99,10 +103,10 @@ use PhpCsFixer\Fixer\Whitespace\MethodChainingIndentationFixer; use PhpCsFixer\Fixer\Whitespace\NoExtraBlankLinesFixer; use PhpCsFixer\Fixer\Whitespace\NoSpacesAroundOffsetFixer; -use PhpCsFixer\Fixer\Whitespace\NoSpacesInsideParenthesisFixer; use PhpCsFixer\Fixer\Whitespace\NoWhitespaceInBlankLineFixer; use PhpCsFixer\Fixer\Whitespace\SingleBlankLineAtEofFixer; use PhpCsFixer\Fixer\Whitespace\StatementIndentationFixer; +use PhpCsFixer\Fixer\Whitespace\TypeDeclarationSpacesFixer; use PhpCsFixerCustomFixers\Fixer\CommentedOutFunctionFixer; use PhpCsFixerCustomFixers\Fixer\ConstructorEmptyBracesFixer; use PhpCsFixerCustomFixers\Fixer\MultilinePromotedPropertiesFixer; @@ -113,7 +117,6 @@ use PhpCsFixerCustomFixers\Fixer\PhpdocArrayStyleFixer; use PhpCsFixerCustomFixers\Fixer\PhpdocNoIncorrectVarAnnotationFixer; use PhpCsFixerCustomFixers\Fixer\PhpdocNoSuperfluousParamFixer; -use PhpCsFixerCustomFixers\Fixer\PhpdocParamOrderFixer; use PhpCsFixerCustomFixers\Fixer\PromotedConstructorPropertyFixer; use PhpCsFixerCustomFixers\Fixer\SingleSpaceAfterStatementFixer; use PhpCsFixerCustomFixers\Fixer\SingleSpaceBeforeStatementFixer; @@ -157,7 +160,6 @@ class CommonRules extends Rules "remove_inheritdoc" => true, "allow_mixed" => true, ], - SingleBlankLineBeforeNamespaceFixer::class => true, PhpUnitTestAnnotationFixer::class => true, PhpUnitSetUpTearDownVisibilityFixer::class => true, BlankLineAfterOpeningTagFixer::class => true, @@ -173,7 +175,6 @@ class CommonRules extends Rules ], ], SingleTraitInsertPerStatementFixer::class => true, - FunctionTypehintSpaceFixer::class => true, NoBlankLinesAfterClassOpeningFixer::class => true, NoSinglelineWhitespaceBeforeSemicolonsFixer::class => true, PhpdocSingleLineVarSpacingFixer::class => true, @@ -275,8 +276,6 @@ class CommonRules extends Rules NoPhpStormGeneratedCommentFixer::class => true, PhpdocNoIncorrectVarAnnotationFixer::class => true, PhpdocNoSuperfluousParamFixer::class => true, - PhpdocParamOrderFixer::class => true, - NoSpacesInsideParenthesisFixer::class => true, YodaStyleFixer::class => [ "equal" => false, "identical" => false, @@ -318,6 +317,16 @@ class CommonRules extends Rules "for", "foreach", "while", - ]], + ], + ], + NoMultipleStatementsPerLineFixer::class => true, + BlankLinesBeforeNamespaceFixer::class => true, + PsrAutoloadingFixer::class => true, + TypeDeclarationSpacesFixer::class => true, + ControlStructureBracesFixer::class => true, + ControlStructureContinuationPositionFixer::class => true, + CurlyBracesPositionFixer::class => [ + "anonymous_functions_opening_brace" => "same_line", + ], ]; } diff --git a/src/Configuration/Defaults/Paths.php b/src/Configuration/Defaults/Paths.php index 550cd1a..2c464b5 100644 --- a/src/Configuration/Defaults/Paths.php +++ b/src/Configuration/Defaults/Paths.php @@ -23,7 +23,7 @@ public function get(): array public function add(string ...$paths): static { foreach ($paths as $path) { - if (!in_array($path, $this->paths, true)) { + if (!in_array($path, $this->paths, strict: true)) { $this->paths[] = $path; } } @@ -41,7 +41,7 @@ public function clear(): static public function filter(string ...$paths): static { foreach ($this->paths as $index => $path) { - if (in_array($path, $paths, true)) { + if (in_array($path, $paths, strict: true)) { unset($this->paths[$index]); } } diff --git a/src/Configuration/Defaults/Rules.php b/src/Configuration/Defaults/Rules.php index fed62ec..7111f1b 100644 --- a/src/Configuration/Defaults/Rules.php +++ b/src/Configuration/Defaults/Rules.php @@ -28,7 +28,7 @@ public function get(): array public function add(Rule ...$rules): static { foreach ($rules as $rule) { - if (!in_array($rule->getFixerClassName(), array_keys($this->rules), true)) { + if (!in_array($rule->getFixerClassName(), array_keys($this->rules), strict: true)) { $this->rules[$rule->getFixerClassName()] = $rule->getOptions(); } } @@ -46,7 +46,7 @@ public function clear(): static public function filter(string ...$rules): static { foreach (array_keys($this->rules) as $rule) { - if (in_array($rule, $rules, true)) { + if (in_array($rule, $rules, strict: true)) { unset($this->rules[$rule]); } } diff --git a/tests/codestyle/CodestyleTestCase.php b/tests/codestyle/CodestyleTestCase.php index bdfb905..bc0c93b 100644 --- a/tests/codestyle/CodestyleTestCase.php +++ b/tests/codestyle/CodestyleTestCase.php @@ -28,7 +28,7 @@ protected function tearDown(): void */ protected function testFixture(string $name): void { - copy(__DIR__ . "/fixtures/{$name}/actual.php", __DIR__ . "/tmp/{$name}.php"); + copy(__DIR__ . "/../fixtures/{$name}/actual.php", __DIR__ . "/tmp/{$name}.php"); $this->assertFalse( $this->runFixer(), @@ -41,7 +41,7 @@ protected function testFixture(string $name): void ); $this->assertFileEquals( - __DIR__ . "/fixtures/{$name}/expected.php", + __DIR__ . "/../fixtures/{$name}/expected.php", __DIR__ . "/tmp/{$name}.php", "Result of proceeded fixture fixtures/{$name} is not equal to expected.", ); @@ -67,6 +67,7 @@ protected function runFixer(bool $fix = false): bool protected function clearTempDirectory(): void { $files = glob(__DIR__ . "/tmp/*.php"); + foreach ($files as $file) { unlink($file); } diff --git a/tests/codestyle/CommonRulesetTest.php b/tests/codestyle/CommonRulesetTest.php index 79ba30b..2b97ea2 100644 --- a/tests/codestyle/CommonRulesetTest.php +++ b/tests/codestyle/CommonRulesetTest.php @@ -1,8 +1,11 @@ filter(PsrAutoloadingFixer::class), ); return $config->config(); diff --git a/tests/codestyle/config/config.purge.php b/tests/codestyle/config/config.purge.php index 09d643f..20b9121 100644 --- a/tests/codestyle/config/config.purge.php +++ b/tests/codestyle/config/config.purge.php @@ -3,10 +3,16 @@ declare(strict_types=1); use Blumilk\Codestyle\Config; +use Blumilk\Codestyle\Configuration\Defaults\CommonRules; use Blumilk\Codestyle\Configuration\Defaults\Paths; +use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer; + +$paths = new Paths("tests/codestyle/tmp"); +$rules = new CommonRules(); $config = new Config( - paths: new Paths("tests/codestyle/tmp"), + paths: $paths, + rules: $rules->filter(PsrAutoloadingFixer::class), ); return $config->purgeMode()->config(); diff --git a/tests/codestyle/fixtures/bracesFixer/actual.php b/tests/codestyle/fixtures/bracesFixer/actual.php deleted file mode 100644 index 3bab43a..0000000 --- a/tests/codestyle/fixtures/bracesFixer/actual.php +++ /dev/null @@ -1,16 +0,0 @@ -translate(trim($data[1]), "en"); + + if (trim($data[0]) === "Uşak") + $cityName = "Usak"; + else $cityName = $this->translate(trim($data[0]), "en"); + } +} diff --git a/tests/fixtures/braces/expected.php b/tests/fixtures/braces/expected.php new file mode 100644 index 0000000..5a5be0e --- /dev/null +++ b/tests/fixtures/braces/expected.php @@ -0,0 +1,21 @@ +translate(trim($data[1]), "en"); + } + + if (trim($data[0]) === "Uşak") { + $cityName = "Usak"; + } else { + $cityName = $this->translate(trim($data[0]), "en"); + } + } +} diff --git a/tests/codestyle/fixtures/classAttributesSeparation/actual.php b/tests/fixtures/classAttributesSeparation/actual.php similarity index 100% rename from tests/codestyle/fixtures/classAttributesSeparation/actual.php rename to tests/fixtures/classAttributesSeparation/actual.php diff --git a/tests/codestyle/fixtures/classAttributesSeparation/expected.php b/tests/fixtures/classAttributesSeparation/expected.php similarity index 100% rename from tests/codestyle/fixtures/classAttributesSeparation/expected.php rename to tests/fixtures/classAttributesSeparation/expected.php diff --git a/tests/codestyle/fixtures/emptyLines/actual.php b/tests/fixtures/emptyLines/actual.php similarity index 100% rename from tests/codestyle/fixtures/emptyLines/actual.php rename to tests/fixtures/emptyLines/actual.php diff --git a/tests/codestyle/fixtures/emptyLines/expected.php b/tests/fixtures/emptyLines/expected.php similarity index 100% rename from tests/codestyle/fixtures/emptyLines/expected.php rename to tests/fixtures/emptyLines/expected.php diff --git a/tests/codestyle/fixtures/enums/actual.php b/tests/fixtures/enums/actual.php similarity index 100% rename from tests/codestyle/fixtures/enums/actual.php rename to tests/fixtures/enums/actual.php diff --git a/tests/codestyle/fixtures/enums/expected.php b/tests/fixtures/enums/expected.php similarity index 100% rename from tests/codestyle/fixtures/enums/expected.php rename to tests/fixtures/enums/expected.php diff --git a/tests/codestyle/fixtures/importsOrder/actual.php b/tests/fixtures/importsOrder/actual.php similarity index 100% rename from tests/codestyle/fixtures/importsOrder/actual.php rename to tests/fixtures/importsOrder/actual.php diff --git a/tests/codestyle/fixtures/importsOrder/expected.php b/tests/fixtures/importsOrder/expected.php similarity index 100% rename from tests/codestyle/fixtures/importsOrder/expected.php rename to tests/fixtures/importsOrder/expected.php diff --git a/tests/codestyle/fixtures/laravelMigrations/actual.php b/tests/fixtures/laravelMigrations/actual.php similarity index 100% rename from tests/codestyle/fixtures/laravelMigrations/actual.php rename to tests/fixtures/laravelMigrations/actual.php diff --git a/tests/codestyle/fixtures/laravelMigrations/expected.php b/tests/fixtures/laravelMigrations/expected.php similarity index 100% rename from tests/codestyle/fixtures/laravelMigrations/expected.php rename to tests/fixtures/laravelMigrations/expected.php diff --git a/tests/codestyle/fixtures/namespaces/actual.php b/tests/fixtures/namespaces/actual.php similarity index 100% rename from tests/codestyle/fixtures/namespaces/actual.php rename to tests/fixtures/namespaces/actual.php diff --git a/tests/codestyle/fixtures/namespaces/expected.php b/tests/fixtures/namespaces/expected.php similarity index 100% rename from tests/codestyle/fixtures/namespaces/expected.php rename to tests/fixtures/namespaces/expected.php diff --git a/tests/codestyle/fixtures/noComments/actual.php b/tests/fixtures/noComments/actual.php similarity index 100% rename from tests/codestyle/fixtures/noComments/actual.php rename to tests/fixtures/noComments/actual.php diff --git a/tests/codestyle/fixtures/noComments/expected.php b/tests/fixtures/noComments/expected.php similarity index 100% rename from tests/codestyle/fixtures/noComments/expected.php rename to tests/fixtures/noComments/expected.php diff --git a/tests/codestyle/fixtures/noExtraBlankLines/actual.php b/tests/fixtures/noExtraBlankLines/actual.php similarity index 100% rename from tests/codestyle/fixtures/noExtraBlankLines/actual.php rename to tests/fixtures/noExtraBlankLines/actual.php diff --git a/tests/codestyle/fixtures/noExtraBlankLines/expected.php b/tests/fixtures/noExtraBlankLines/expected.php similarity index 100% rename from tests/codestyle/fixtures/noExtraBlankLines/expected.php rename to tests/fixtures/noExtraBlankLines/expected.php diff --git a/tests/codestyle/fixtures/nullableTypeForDefaultNull/actual.php b/tests/fixtures/nullableTypeForDefaultNull/actual.php similarity index 100% rename from tests/codestyle/fixtures/nullableTypeForDefaultNull/actual.php rename to tests/fixtures/nullableTypeForDefaultNull/actual.php diff --git a/tests/codestyle/fixtures/nullableTypeForDefaultNull/expected.php b/tests/fixtures/nullableTypeForDefaultNull/expected.php similarity index 100% rename from tests/codestyle/fixtures/nullableTypeForDefaultNull/expected.php rename to tests/fixtures/nullableTypeForDefaultNull/expected.php diff --git a/tests/codestyle/fixtures/objectOperators/actual.php b/tests/fixtures/objectOperators/actual.php similarity index 100% rename from tests/codestyle/fixtures/objectOperators/actual.php rename to tests/fixtures/objectOperators/actual.php diff --git a/tests/codestyle/fixtures/objectOperators/expected.php b/tests/fixtures/objectOperators/expected.php similarity index 100% rename from tests/codestyle/fixtures/objectOperators/expected.php rename to tests/fixtures/objectOperators/expected.php diff --git a/tests/codestyle/fixtures/operatorSpacing/actual.php b/tests/fixtures/operatorSpacing/actual.php similarity index 100% rename from tests/codestyle/fixtures/operatorSpacing/actual.php rename to tests/fixtures/operatorSpacing/actual.php diff --git a/tests/codestyle/fixtures/operatorSpacing/expected.php b/tests/fixtures/operatorSpacing/expected.php similarity index 100% rename from tests/codestyle/fixtures/operatorSpacing/expected.php rename to tests/fixtures/operatorSpacing/expected.php diff --git a/tests/codestyle/fixtures/php82/actual.php b/tests/fixtures/php82/actual.php similarity index 100% rename from tests/codestyle/fixtures/php82/actual.php rename to tests/fixtures/php82/actual.php diff --git a/tests/codestyle/fixtures/php82/expected.php b/tests/fixtures/php82/expected.php similarity index 100% rename from tests/codestyle/fixtures/php82/expected.php rename to tests/fixtures/php82/expected.php diff --git a/tests/codestyle/fixtures/phpdocs/actual.php b/tests/fixtures/phpdocs/actual.php similarity index 100% rename from tests/codestyle/fixtures/phpdocs/actual.php rename to tests/fixtures/phpdocs/actual.php diff --git a/tests/codestyle/fixtures/phpdocs/expected.php b/tests/fixtures/phpdocs/expected.php similarity index 100% rename from tests/codestyle/fixtures/phpdocs/expected.php rename to tests/fixtures/phpdocs/expected.php diff --git a/tests/codestyle/fixtures/readonlies/actual.php b/tests/fixtures/readonlies/actual.php similarity index 100% rename from tests/codestyle/fixtures/readonlies/actual.php rename to tests/fixtures/readonlies/actual.php diff --git a/tests/codestyle/fixtures/readonlies/expected.php b/tests/fixtures/readonlies/expected.php similarity index 100% rename from tests/codestyle/fixtures/readonlies/expected.php rename to tests/fixtures/readonlies/expected.php diff --git a/tests/codestyle/fixtures/references/actual.php b/tests/fixtures/references/actual.php similarity index 100% rename from tests/codestyle/fixtures/references/actual.php rename to tests/fixtures/references/actual.php diff --git a/tests/codestyle/fixtures/references/expected.php b/tests/fixtures/references/expected.php similarity index 100% rename from tests/codestyle/fixtures/references/expected.php rename to tests/fixtures/references/expected.php diff --git a/tests/codestyle/fixtures/singleQuotes/actual.php b/tests/fixtures/singleQuotes/actual.php similarity index 100% rename from tests/codestyle/fixtures/singleQuotes/actual.php rename to tests/fixtures/singleQuotes/actual.php diff --git a/tests/codestyle/fixtures/singleQuotes/expected.php b/tests/fixtures/singleQuotes/expected.php similarity index 100% rename from tests/codestyle/fixtures/singleQuotes/expected.php rename to tests/fixtures/singleQuotes/expected.php diff --git a/tests/codestyle/fixtures/strictTypes/actual.php b/tests/fixtures/strictTypes/actual.php similarity index 100% rename from tests/codestyle/fixtures/strictTypes/actual.php rename to tests/fixtures/strictTypes/actual.php diff --git a/tests/codestyle/fixtures/strictTypes/expected.php b/tests/fixtures/strictTypes/expected.php similarity index 100% rename from tests/codestyle/fixtures/strictTypes/expected.php rename to tests/fixtures/strictTypes/expected.php diff --git a/tests/codestyle/fixtures/stringVariables/actual.php b/tests/fixtures/stringVariables/actual.php similarity index 100% rename from tests/codestyle/fixtures/stringVariables/actual.php rename to tests/fixtures/stringVariables/actual.php diff --git a/tests/codestyle/fixtures/stringVariables/expected.php b/tests/fixtures/stringVariables/expected.php similarity index 100% rename from tests/codestyle/fixtures/stringVariables/expected.php rename to tests/fixtures/stringVariables/expected.php diff --git a/tests/codestyle/fixtures/trailingCommas/actual.php b/tests/fixtures/trailingCommas/actual.php similarity index 100% rename from tests/codestyle/fixtures/trailingCommas/actual.php rename to tests/fixtures/trailingCommas/actual.php diff --git a/tests/codestyle/fixtures/trailingCommas/expected.php b/tests/fixtures/trailingCommas/expected.php similarity index 100% rename from tests/codestyle/fixtures/trailingCommas/expected.php rename to tests/fixtures/trailingCommas/expected.php diff --git a/tests/codestyle/fixtures/unionTypes/actual.php b/tests/fixtures/unionTypes/actual.php similarity index 100% rename from tests/codestyle/fixtures/unionTypes/actual.php rename to tests/fixtures/unionTypes/actual.php diff --git a/tests/codestyle/fixtures/unionTypes/expected.php b/tests/fixtures/unionTypes/expected.php similarity index 100% rename from tests/codestyle/fixtures/unionTypes/expected.php rename to tests/fixtures/unionTypes/expected.php diff --git a/tests/codestyle/fixtures/uselessParenthesis/actual.php b/tests/fixtures/uselessParenthesis/actual.php similarity index 100% rename from tests/codestyle/fixtures/uselessParenthesis/actual.php rename to tests/fixtures/uselessParenthesis/actual.php diff --git a/tests/codestyle/fixtures/uselessParenthesis/expected.php b/tests/fixtures/uselessParenthesis/expected.php similarity index 100% rename from tests/codestyle/fixtures/uselessParenthesis/expected.php rename to tests/fixtures/uselessParenthesis/expected.php diff --git a/tests/codestyle/fixtures/yodaStyle/actual.php b/tests/fixtures/yodaStyle/actual.php similarity index 100% rename from tests/codestyle/fixtures/yodaStyle/actual.php rename to tests/fixtures/yodaStyle/actual.php diff --git a/tests/codestyle/fixtures/yodaStyle/expected.php b/tests/fixtures/yodaStyle/expected.php similarity index 100% rename from tests/codestyle/fixtures/yodaStyle/expected.php rename to tests/fixtures/yodaStyle/expected.php