Skip to content

Commit

Permalink
Feat: Add OctalNotationFixer for explicit octal notation using 0o in …
Browse files Browse the repository at this point in the history
…PHP 8.1+ (part of #94)
  • Loading branch information
OndraM committed May 10, 2024
1 parent 2a3f239 commit 5a6dca0
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 0 deletions.
3 changes: 3 additions & 0 deletions ecs.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/Integration/CodingStandardTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
12 changes: 12 additions & 0 deletions tests/Integration/Fixtures/Php81.correct.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Lmc\CodingStandard\Integration\Fixtures;

class Php81
{
public function php81features(): void
{
// OctalNotationFixer
$numberInOctalNotation = 0o123;
}
}
12 changes: 12 additions & 0 deletions tests/Integration/Fixtures/Php81.wrong.php.inc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);

namespace Lmc\CodingStandard\Integration\Fixtures;

class Php81
{
public function php81features(): void
{
// OctalNotationFixer
$numberInOctalNotation = 0123;
}
}

0 comments on commit 5a6dca0

Please sign in to comment.