Skip to content

Commit 902eba9

Browse files
theofidryjrushlow
authored andcommitted
build: Use a PHP-CS-Fixer shim rather than an external PHAR
1 parent e7aeeb2 commit 902eba9

File tree

4 files changed

+17
-6
lines changed

4 files changed

+17
-6
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"php": ">=8.1",
1717
"doctrine/inflector": "^2.0",
1818
"nikic/php-parser": "^4.18|^5.0",
19+
"php-cs-fixer/shim": "^v3.59.3",
1920
"symfony/config": "^6.4|^7.0",
2021
"symfony/console": "^6.4|^7.0",
2122
"symfony/dependency-injection": "^6.4|^7.0",
-2.69 MB
Binary file not shown.

src/Util/TemplateLinter.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,6 @@
2525
*/
2626
final class TemplateLinter
2727
{
28-
// Version must match bundled version file name. e.g. php-cs-fixer-v3.49.9.phar
29-
public const BUNDLED_PHP_CS_FIXER_VERSION = '3.49.0';
30-
3128
private bool $usingBundledPhpCsFixer = true;
3229
private bool $usingBundledPhpCsFixerConfig = true;
3330
private bool $needsPhpCmdPrefix = true;
@@ -100,7 +97,18 @@ private function setBinary(): void
10097
{
10198
// Use Bundled PHP-CS-Fixer
10299
if (null === $this->phpCsFixerBinaryPath) {
103-
$this->phpCsFixerBinaryPath = \sprintf('%s/Resources/bin/php-cs-fixer-v%s.phar', \dirname(__DIR__), self::BUNDLED_PHP_CS_FIXER_VERSION);
100+
$pathCandidates = [
101+
__DIR__.'/../../vendor/php-cs-fixer/shim/php-cs-fixer',
102+
__DIR__.'/../../../php-cs-fixer/shim/php-cs-fixer',
103+
];
104+
105+
foreach ($pathCandidates as $pathCandidate) {
106+
if (is_file($pathCandidate)) {
107+
$this->phpCsFixerBinaryPath = $pathCandidate;
108+
109+
return;
110+
}
111+
}
104112

105113
return;
106114
}

tests/Util/TemplateLinterTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace Symfony\Bundle\MakerBundle\Tests\Util;
1313

14+
use Composer\InstalledVersions;
1415
use PHPUnit\Framework\TestCase;
1516
use Symfony\Bundle\MakerBundle\Util\TemplateLinter;
1617
use Symfony\Component\Process\Process;
@@ -42,13 +43,14 @@ public function testPhpCsFixerVersion(): void
4243
{
4344
$this->markTestSkippedOnWindows();
4445

45-
$fixerPath = \sprintf('%s/src/Resources/bin/php-cs-fixer-v%s.phar', \dirname(__DIR__, 2), TemplateLinter::BUNDLED_PHP_CS_FIXER_VERSION);
46+
$fixerPath = __DIR__.'/../../vendor/php-cs-fixer/shim/php-cs-fixer';
47+
$expectedVersion = InstalledVersions::getVersion('php-cs-fixer/shim');
4648

4749
$process = Process::fromShellCommandline(\sprintf('%s -V', $fixerPath));
4850

4951
$process->run();
5052

51-
self::assertStringContainsString(TemplateLinter::BUNDLED_PHP_CS_FIXER_VERSION, $process->getOutput());
53+
self::assertStringContainsString($expectedVersion, $process->getOutput());
5254
}
5355

5456
private function markTestSkippedOnWindows(): void

0 commit comments

Comments
 (0)