1 | <?php |
||
2 | |||
3 | namespace Jackal\BinLocator; |
||
4 | |||
5 | use Jackal\BinLocator\Exception\BinLocatorException; |
||
6 | use Symfony\Component\Process\Process; |
||
7 | |||
8 | class BinLocator |
||
9 | { |
||
10 | protected $binToLocate; |
||
11 | protected $whichCommand = 'which'; |
||
12 | |||
13 | public function __construct($binToLocate) |
||
14 | { |
||
15 | $this->binToLocate = $binToLocate; |
||
16 | } |
||
17 | |||
18 | public function locate(){ |
||
19 | $process = new Process([$this->whichCommand,$this->binToLocate]); |
||
20 | $process->run(); |
||
21 | |||
22 | if($process->getErrorOutput()){ |
||
23 | throw BinLocatorException::processFailed($process); |
||
24 | } |
||
25 | |||
26 | $path = trim($process->getOutput()); |
||
27 | |||
28 | if(!$path){ |
||
29 | throw BinLocatorException::notFound($this->binToLocate); |
||
30 | } |
||
31 | |||
32 | return $path; |
||
33 | } |
||
34 | |||
35 | public function getProcess(array $commandLine){ |
||
36 | $bin = $this->locate(); |
||
37 | |||
38 | $commandLine = implode(' ', array_merge([$bin], $commandLine)); |
||
39 | |||
40 | //compatibility fix Process >= 5.x |
||
41 | if(method_exists(Process::class, 'fromShellCommandline')){ |
||
42 | return Process::fromShellCommandline($commandLine); |
||
0 ignored issues
–
show
|
|||
43 | } |
||
44 | |||
45 | //Process < 5.x |
||
46 | return new Process($commandLine); |
||
47 | } |
||
48 | } |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.