Skip to content

Commit a7efe8f

Browse files
committed
Logging, and look in more places for phpcs
1 parent 184cafd commit a7efe8f

File tree

1 file changed

+38
-9
lines changed

1 file changed

+38
-9
lines changed

src/PhpcsDiff.php

Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -189,20 +189,49 @@ public function run(): void
189189
*/
190190
protected function runPhpcs(array $files = [], string $ruleset = 'ruleset.xml')
191191
{
192-
$exec = 'vendor/bin/phpcs';
192+
$exec = null;
193+
$root = dirname(__DIR__);
194+
195+
$locations = [
196+
'vendor/bin/phpcs',
197+
$root . '/../../bin/phpcs',
198+
$root . '/../bin/phpcs',
199+
$root . '/bin/phpcs',
200+
$root . '/vendor/bin/phpcs',
201+
'~/.config/composer/vendor/bin/phpcs',
202+
'~/.composer/vendor/bin/phpcs',
203+
];
204+
205+
foreach ($locations as $location) {
206+
if (is_file($location)) {
207+
$exec = $location;
208+
break;
209+
}
210+
}
193211

194-
if (is_file(__DIR__ . '/../../../bin/phpcs')) {
195-
$exec = realpath(__DIR__ . '/../../../bin/phpcs');
196-
} elseif (is_file(__DIR__ . '/../bin/phpcs')) {
197-
$exec = realpath(__DIR__ . '/../bin/phpcs');
212+
if (!$exec) {
213+
return null;
214+
}
215+
216+
if ($this->isVerbose) {
217+
$this->climate->info('Using phpcs executable: ' . $exec);
198218
}
199219

200220
$exec = PHP_BINARY . ' ' . $exec;
221+
$command = $exec . ' --report=json --standard=' . $ruleset . ' ' . implode(' ', $files);
222+
$output = shell_exec($command);
201223

202-
return json_decode(
203-
shell_exec($exec . ' --report=json --standard=' . $ruleset . ' ' . implode(' ', $files)),
204-
true
205-
);
224+
if ($this->isVerbose) {
225+
$this->climate->info('Running: ' . $command);
226+
}
227+
228+
229+
$json = $output ? json_decode($output, true) : null;
230+
if ($json === null && $output) {
231+
$this->climate->error($output);
232+
}
233+
234+
return $json;
206235
}
207236

208237
/**

0 commit comments

Comments
 (0)