Skip to content

Commit 3b5e735

Browse files
committed
build: Use a PHP-CS-Fixer shim rather than an external PHAR
1 parent e8e4417 commit 3b5e735

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;
@@ -99,7 +96,18 @@ private function setBinary(): void
9996
{
10097
// Use Bundled PHP-CS-Fixer
10198
if (null === $this->phpCsFixerBinaryPath) {
102-
$this->phpCsFixerBinaryPath = sprintf('%s/Resources/bin/php-cs-fixer-v%s.phar', \dirname(__DIR__), self::BUNDLED_PHP_CS_FIXER_VERSION);
99+
$pathCandidates = [
100+
__DIR__.'/../../vendor/php-cs-fixer/shim/php-cs-fixer',
101+
__DIR__.'/../../../php-cs-fixer/shim/php-cs-fixer',
102+
];
103+
104+
foreach ($pathCandidates as $pathCandidate) {
105+
if (is_file($pathCandidate)) {
106+
$this->phpCsFixerBinaryPath = $pathCandidate;
107+
108+
return;
109+
}
110+
}
103111

104112
return;
105113
}

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;
@@ -44,12 +45,13 @@ public function testPhpCsFixerVersion(): void
4445
$this->markTestSkipped('Test only runs on linux.');
4546
}
4647

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

4951
$process = Process::fromShellCommandline(sprintf('%s -V', $fixerPath));
5052

5153
$process->run();
5254

53-
self::assertStringContainsString(TemplateLinter::BUNDLED_PHP_CS_FIXER_VERSION, $process->getOutput());
55+
self::assertStringContainsString($expectedVersion, $process->getOutput());
5456
}
5557
}

0 commit comments

Comments
 (0)