|
12 | 12 | use function count; |
13 | 13 | use function escapeshellarg; |
14 | 14 | use function preg_match; |
| 15 | +use function str_replace; |
15 | 16 |
|
16 | 17 | final class PHPStan extends Action |
17 | 18 | { |
@@ -70,13 +71,26 @@ protected function shouldSkipFileCheck(string $file, array $excludedFiles): bool |
70 | 71 | protected function analyzeFile(string $file, Config $config, Config\Action $action): array |
71 | 72 | { |
72 | 73 | $process = new Processor(); |
73 | | - $phpstanPath = $action->getOptions()->get('phpstan_path') ?? 'vendor/bin/phpstan'; |
74 | | - $level = $action->getOptions()->get('level') ?? 8; |
75 | | - $result = $process->run($config->getPhpPath() . ' ' . $phpstanPath . ' analyse --level=' . $level . ' ' . escapeshellarg($file)); |
| 74 | + |
| 75 | + $result = $process->run($this->getCommand($file, $config, $action)); |
76 | 76 |
|
77 | 77 | return [ |
78 | 78 | 'success' => $result->isSuccessful(), |
79 | 79 | 'output' => $result->getStdOut(), |
80 | 80 | ]; |
81 | 81 | } |
| 82 | + |
| 83 | + protected function getCommand(string $file, Config $config, Config\Action $action): string |
| 84 | + { |
| 85 | + $command = $action->getOptions()->get('command'); |
| 86 | + |
| 87 | + if ($command !== null) { |
| 88 | + return str_replace('%file%', escapeshellarg($file), $command); |
| 89 | + } |
| 90 | + |
| 91 | + $phpstanPath = $action->getOptions()->get('phpstan_path') ?? 'vendor/bin/phpstan'; |
| 92 | + $level = $action->getOptions()->get('level') ?? 8; |
| 93 | + |
| 94 | + return $config->getPhpPath() . ' ' . $phpstanPath . ' analyse --level=' . $level . ' ' . escapeshellarg($file); |
| 95 | + } |
82 | 96 | } |
0 commit comments