Skip to content

Commit 5a6dca0

Browse files
committed
Feat: Add OctalNotationFixer for explicit octal notation using 0o in PHP 8.1+ (part of #94)
1 parent 2a3f239 commit 5a6dca0

File tree

4 files changed

+41
-0
lines changed

4 files changed

+41
-0
lines changed

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;
@@ -244,6 +245,8 @@
244245
SingleLineEmptyBodyFixer::class, // Defined in PER 2.0
245246
// Values separated by a comma on a single line should not have a trailing comma.
246247
NoTrailingCommaInSinglelineFixer::class,
248+
// Literal octal must be in 0o notation.
249+
OctalNotationFixer::class,
247250
// Arrays should be formatted like function/method arguments
248251
TrimArraySpacesFixer::class,
249252
// In array declaration, there MUST be a whitespace after each comma

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();
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+
}
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)