From 5a6dca06469664774b28b4529452b13f82005914 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Machulda?= Date: Fri, 10 May 2024 12:15:04 +0200 Subject: [PATCH] Feat: Add OctalNotationFixer for explicit octal notation using 0o in PHP 8.1+ (part of #94) --- ecs.php | 3 +++ tests/Integration/CodingStandardTest.php | 14 ++++++++++++++ tests/Integration/Fixtures/Php81.correct.php.inc | 12 ++++++++++++ tests/Integration/Fixtures/Php81.wrong.php.inc | 12 ++++++++++++ 4 files changed, 41 insertions(+) create mode 100644 tests/Integration/Fixtures/Php81.correct.php.inc create mode 100644 tests/Integration/Fixtures/Php81.wrong.php.inc diff --git a/ecs.php b/ecs.php index b7b4732..29d907f 100644 --- a/ecs.php +++ b/ecs.php @@ -46,6 +46,7 @@ use PhpCsFixer\Fixer\AttributeNotation\AttributeEmptyParenthesesFixer; use PhpCsFixer\Fixer\Basic\BracesFixer; use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer; +use PhpCsFixer\Fixer\Basic\OctalNotationFixer; use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer; use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer; use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer; @@ -244,6 +245,8 @@ SingleLineEmptyBodyFixer::class, // Defined in PER 2.0 // Values separated by a comma on a single line should not have a trailing comma. NoTrailingCommaInSinglelineFixer::class, + // Literal octal must be in 0o notation. + OctalNotationFixer::class, // Arrays should be formatted like function/method arguments TrimArraySpacesFixer::class, // In array declaration, there MUST be a whitespace after each comma diff --git a/tests/Integration/CodingStandardTest.php b/tests/Integration/CodingStandardTest.php index 316f58b..e8658a5 100644 --- a/tests/Integration/CodingStandardTest.php +++ b/tests/Integration/CodingStandardTest.php @@ -39,6 +39,20 @@ public function provideFilesToFix(): array ]; } + /** + * @test + * @requires PHP >= 8.1 + */ + public function shouldFixPhp81(): void + { + $fixedFile = $this->runEcsCheckOnFile(__DIR__ . '/Fixtures/Php81.wrong.php.inc'); + + $this->assertStringEqualsFile( + __DIR__ . '/Fixtures/Php81.correct.php.inc', + file_get_contents($fixedFile), + ); + } + private function runEcsCheckOnFile(string $file): string { $fixtureFile = $this->initTempFixtureFile(); diff --git a/tests/Integration/Fixtures/Php81.correct.php.inc b/tests/Integration/Fixtures/Php81.correct.php.inc new file mode 100644 index 0000000..f80047a --- /dev/null +++ b/tests/Integration/Fixtures/Php81.correct.php.inc @@ -0,0 +1,12 @@ +