Skip to content

Commit ff3cf42

Browse files
committed
Feat: Add OctalNotationFixer for explicit octal notation using 0o in PHP 8.1+ (part of #94)
1 parent 36f596b commit ff3cf42

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

Diff for: ecs.php

+3
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
use PhpCsFixer\Fixer\AttributeNotation\AttributeEmptyParenthesesFixer;
4747
use PhpCsFixer\Fixer\Basic\BracesFixer;
4848
use PhpCsFixer\Fixer\Basic\NoTrailingCommaInSinglelineFixer;
49+
use PhpCsFixer\Fixer\Basic\OctalNotationFixer;
4950
use PhpCsFixer\Fixer\Basic\PsrAutoloadingFixer;
5051
use PhpCsFixer\Fixer\Basic\SingleLineEmptyBodyFixer;
5152
use PhpCsFixer\Fixer\Casing\ClassReferenceNameCasingFixer;
@@ -245,6 +246,8 @@
245246
SingleLineEmptyBodyFixer::class, // Defined in PER 2.0
246247
// Values separated by a comma on a single line should not have a trailing comma.
247248
NoTrailingCommaInSinglelineFixer::class,
249+
// Literal octal must be in 0o notation.
250+
OctalNotationFixer::class,
248251
// Arrays should be formatted like function/method arguments
249252
TrimArraySpacesFixer::class,
250253
// In array declaration, there MUST be a whitespace after each comma

Diff for: tests/Integration/CodingStandardTest.php

+14
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,20 @@ public function provideFilesToFix(): array
3939
];
4040
}
4141

42+
/**
43+
* @test
44+
* @requires PHP >= 8.1
45+
*/
46+
public function shouldFixPhp81(): void
47+
{
48+
$fixedFile = $this->runEcsCheckOnFile(__DIR__ . '/Fixtures/Php81.wrong.php.inc');
49+
50+
$this->assertStringEqualsFile(
51+
__DIR__ . '/Fixtures/Php81.correct.php.inc',
52+
file_get_contents($fixedFile),
53+
);
54+
}
55+
4256
private function runEcsCheckOnFile(string $file): string
4357
{
4458
$fixtureFile = $this->initTempFixtureFile();

Diff for: tests/Integration/Fixtures/Php81.correct.php.inc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lmc\CodingStandard\Integration\Fixtures;
4+
5+
class Php81
6+
{
7+
public function php81features(): void
8+
{
9+
// OctalNotationFixer
10+
$numberInOctalNotation = 0o123;
11+
}
12+
}

Diff for: tests/Integration/Fixtures/Php81.wrong.php.inc

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php declare(strict_types=1);
2+
3+
namespace Lmc\CodingStandard\Integration\Fixtures;
4+
5+
class Php81
6+
{
7+
public function php81features(): void
8+
{
9+
// OctalNotationFixer
10+
$numberInOctalNotation = 0123;
11+
}
12+
}

0 commit comments

Comments
 (0)