/
ComposerExecutableFinder.php
42 lines (35 loc) · 1.18 KB
/
ComposerExecutableFinder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
/**
* Copyright © 2017 Maks Rafalko
*
* License: https://opensource.org/licenses/BSD-3-Clause New BSD License
*/
declare(strict_types=1);
namespace Infection\Finder;
use Symfony\Component\Process\ExecutableFinder;
final class ComposerExecutableFinder extends AbstractExecutableFinder
{
public function find(bool $includeArgs = true): string
{
$probable = ['composer', 'composer.phar'];
$finder = new ExecutableFinder();
$immediatePaths = [getcwd(), realpath(getcwd() . '/../'), realpath(getcwd() . '/../../')];
foreach ($probable as $name) {
if ($path = $finder->find($name, null, $immediatePaths)) {
return $path;
}
}
/**
* Check for options without execute permissions and prefix the PHP
* executable instead.
*/
$result = $this->searchNonExecutables($probable, $immediatePaths, $includeArgs);
if (null !== $result) {
return $result;
}
throw new \RuntimeException(
'Unable to locate a Composer executable on local system. Ensure '
. 'that Composer is installed and available.'
);
}
}