-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added --cs-fix option to run phpcbf on changed files
- Loading branch information
matt
committed
Feb 24, 2024
1 parent
bf0c423
commit cc818cf
Showing
11 changed files
with
234 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kynx\Laminas\FormShape\CodingStandards; | ||
|
||
interface FixerInterface | ||
{ | ||
public function getName(): string; | ||
|
||
public function addFile(string $path): void; | ||
|
||
public function fix(): void; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Kynx\Laminas\FormShape\CodingStandards; | ||
|
||
use Kynx\Laminas\FormShape\CodingStandards\FixerInterface; | ||
|
||
use function array_map; | ||
use function basename; | ||
use function escapeshellarg; | ||
use function escapeshellcmd; | ||
use function implode; | ||
use function passthru; | ||
|
||
final class PhpCodeSnifferFixer implements FixerInterface | ||
{ | ||
private array $paths = []; | ||
|
||
public function __construct(private string $phpCbf) | ||
{ | ||
} | ||
|
||
public function getName(): string | ||
{ | ||
return basename($this->phpCbf); | ||
} | ||
|
||
public function addFile(string $path): void | ||
{ | ||
$this->paths[] = $path; | ||
} | ||
|
||
public function fix(): void | ||
{ | ||
$paths = array_map(static fn (string $path): string => escapeshellarg($path), $this->paths); | ||
passthru(escapeshellcmd($this->phpCbf) . ' ' . implode(' ', $paths)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#!/usr/bin/env php | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
$command = array_shift($argv); | ||
echo basename($command) . ' ' . implode(' ', (array) $argv); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KynxTest\Laminas\FormShape\CodingStandards; | ||
|
||
use Kynx\Laminas\FormShape\CodingStandards\FixerInterface; | ||
|
||
final class MockFixer implements FixerInterface | ||
{ | ||
public array $paths = []; | ||
public bool $fixed = false; | ||
|
||
public function getName(): string | ||
{ | ||
return 'mock-fixer'; | ||
} | ||
|
||
public function addFile(string $path): void | ||
{ | ||
$this->paths[] = $path; | ||
} | ||
|
||
public function fix(): void | ||
{ | ||
$this->fixed = true; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace KynxTest\Laminas\FormShape\CodingStandards; | ||
|
||
use Kynx\Laminas\FormShape\CodingStandards\PhpCodeSnifferFixer; | ||
use PHPUnit\Framework\Attributes\CoversClass; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
use function ob_get_clean; | ||
use function ob_start; | ||
|
||
#[CoversClass(PhpCodeSnifferFixer::class)] | ||
final class PhpCodeSnifferFixerTest extends TestCase | ||
{ | ||
public function testFixProcessesPaths(): void | ||
{ | ||
$expected = 'mock-fixer.php foo bar'; | ||
$fixer = new PhpCodeSnifferFixer(__DIR__ . '/Asset/mock-fixer.php'); | ||
|
||
$fixer->addFile('foo'); | ||
$fixer->addFile('bar'); | ||
|
||
ob_start(); | ||
$fixer->fix(); | ||
$actual = ob_get_clean(); | ||
|
||
self::assertSame($expected, $actual); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.