Passed
Push — master ( b8e16f...40853b )
by Carlos C
02:32
created

ShellWhich::__invoke()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 3.009

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 1
dl 0
loc 13
ccs 9
cts 10
cp 0.9
crap 3.009
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\RfcLinc\Util;
6
7
class ShellWhich
8
{
9 14
    public function __invoke(string $executable): string
10
    {
11 14
        $output = [];
12 14
        $return = -1;
13 14
        exec('which ' . escapeshellarg($executable), $output, $return);
14 14
        if (0 !== (int) $return) {
15 1
            return '';
16
        }
17 13
        $count = count($output);
18 13
        if (0 === $count) {
19
            return '';
20
        }
21 13
        return $output[$count - 1];
22
    }
23
}
24