Failed Conditions
Push — master ( 85c284...561f65 )
by Sébastien
02:44
created

BinaryAssertionsTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 24
ccs 0
cts 15
cp 0
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A ensureIsExecutable() 0 17 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Util\Assert;
6
7
use Soluble\MediaTools\Exception\MissingBinaryException;
8
9
trait BinaryAssertionsTrait
10
{
11
    /**
12
     * Check for executable presence (skipped for executable in %PATH%).
13
     *
14
     * @throws MissingBinaryException
15
     */
16
    public function ensureIsExecutable(string $binaryFile): void
17
    {
18
        // Case of binary (no path given), we cannot tell
19
        if (basename($binaryFile) === $binaryFile) {
20
            $exists     = true; // assume it exists
21
            $executable = true;
22
        } else {
23
            $exists     = file_exists($binaryFile);
24
            $executable = is_executable($binaryFile);
25
        }
26
27
        if (!$exists || !$executable) {
28
            throw new MissingBinaryException(sprintf(
29
                'Missing \'%s\' binary: (exists: %s, executable: %s)',
30
                $binaryFile,
31
                $exists ? 'true' : 'false',
32
                $executable ? 'true' : 'false'
33
            ));
34
        }
35
    }
36
}
37