BinaryAssertionsTrait   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A ensureBinaryAvailable() 0 17 6
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @see       https://github.com/soluble-io/soluble-mediatools for the canonical repository
7
 *
8
 * @copyright Copyright (c) 2018-2020 Sébastien Vanvelthem. (https://github.com/belgattitude)
9
 * @license   https://github.com/soluble-io/soluble-mediatools/blob/master/LICENSE.md MIT
10
 */
11
12
namespace Soluble\MediaTools\Common\Assert;
13
14
use Soluble\MediaTools\Common\Exception\MissingBinaryException;
15
16
trait BinaryAssertionsTrait
17
{
18
    /**
19
     * Check for executable presence (skipped for executable in %PATH%).
20
     *
21
     * @throws MissingBinaryException
22
     */
23 3
    private function ensureBinaryAvailable(string $binaryFile): void
24
    {
25
        // Case of binary (no path given), we cannot tell
26 3
        if (basename($binaryFile) === $binaryFile) {
27 1
            $exists     = true; // assume it exists
28 1
            $executable = true;
29
        } else {
30 2
            $exists     = file_exists($binaryFile);
31 2
            $executable = is_executable($binaryFile);
32
        }
33
34 3
        if (!$exists || !$executable) {
35 1
            throw new MissingBinaryException(sprintf(
36 1
                'Missing \'%s\' binary: (exists: %s, executable: %s)',
37
                $binaryFile,
38 1
                $exists ? 'true' : 'false',
39 1
                $executable ? 'true' : 'false'
40
            ));
41
        }
42 2
    }
43
}
44