WhichTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Test Coverage

Coverage 85.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 7
c 1
b 0
f 0
dl 0
loc 11
ccs 6
cts 7
cp 0.8571
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A which() 0 9 3
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