WhichTrait::which()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 3.0261

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 9
ccs 6
cts 7
cp 0.8571
rs 10
cc 3
nc 2
nop 1
crap 3.0261
1
<?php
2
3
declare(strict_types=1);
4
5
namespace PhpCfdi\SatCatalogosPopulate\Utils;
6
7
use RuntimeException;
8
9
trait WhichTrait
10
{
11 4
    public function which(string $executable): string
12
    {
13 4
        $wichPath = '/usr/bin/which';
14 4
        if (! is_file($wichPath) || ! is_executable($wichPath)) {
15
            throw new RuntimeException('Cannot find which command');
16
        }
17 4
        return trim((string) shell_exec(implode(' ', [
18 4
            escapeshellarg($wichPath),
19 4
            escapeshellarg($executable),
20 4
        ])));
21
    }
22
}
23