|
12 | 12 | namespace Symfony\Bundle\MakerBundle\Util; |
13 | 13 |
|
14 | 14 | use Symfony\Bundle\MakerBundle\Exception\RuntimeCommandException; |
| 15 | +use Symfony\Bundle\MakerBundle\FileManager; |
15 | 16 | use Symfony\Component\Console\Output\OutputInterface; |
16 | 17 | use Symfony\Component\Process\ExecutableFinder; |
17 | 18 | use Symfony\Component\Process\Process; |
|
25 | 26 | */ |
26 | 27 | final class TemplateLinter |
27 | 28 | { |
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 | | - |
31 | 29 | private bool $usingBundledPhpCsFixer = true; |
32 | 30 | private bool $usingBundledPhpCsFixerConfig = true; |
33 | 31 | private bool $needsPhpCmdPrefix = true; |
34 | 32 |
|
35 | 33 | public function __construct( |
| 34 | + private FileManager $fileManager, |
36 | 35 | private ?string $phpCsFixerBinaryPath = null, |
37 | 36 | private ?string $phpCsFixerConfigPath = null, |
38 | 37 | ) { |
@@ -98,9 +97,15 @@ public function writeLinterMessage(OutputInterface $output): void |
98 | 97 |
|
99 | 98 | private function setBinary(): void |
100 | 99 | { |
101 | | - // Use Bundled PHP-CS-Fixer |
| 100 | + // Use Bundled (shim) PHP-CS-Fixer |
102 | 101 | 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); |
| 102 | + $shimLocation = \sprintf('%s/vendor/bin/php-cs-fixer', \dirname(__DIR__, 2)); |
| 103 | + |
| 104 | + if (is_file($shimLocation)) { |
| 105 | + $this->phpCsFixerBinaryPath = $shimLocation; |
| 106 | + |
| 107 | + return; |
| 108 | + } |
104 | 109 |
|
105 | 110 | return; |
106 | 111 | } |
@@ -129,7 +134,8 @@ private function setBinary(): void |
129 | 134 | private function setConfig(): void |
130 | 135 | { |
131 | 136 | // No config provided, but there is a dist config file in the project dir |
132 | | - if (null === $this->phpCsFixerConfigPath && file_exists($defaultConfigPath = '.php-cs-fixer.dist.php')) { |
| 137 | + $defaultConfigPath = \sprintf('%s/.php-cs-fixer.dist.php', $this->fileManager->getRootDirectory()); |
| 138 | + if (null === $this->phpCsFixerConfigPath && file_exists($defaultConfigPath)) { |
133 | 139 | $this->phpCsFixerConfigPath = $defaultConfigPath; |
134 | 140 |
|
135 | 141 | $this->usingBundledPhpCsFixerConfig = false; |
|
0 commit comments