Passed
Push — master ( a0a10b...8caa9b )
by Sébastien
02:50
created

PathAssertionsTrait::ensureFileReadable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 7
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Soluble\MediaTools\Common\Assert;
6
7
use Soluble\MediaTools\Common\Exception\FileNotFoundException;
8
use Soluble\MediaTools\Common\Exception\FileNotReadableException;
9
10
trait PathAssertionsTrait
11
{
12
    /**
13
     * @throws FileNotFoundException
14
     */
15 28
    protected function ensureFileExists(string $file): void
16
    {
17 28
        if (!file_exists($file)) {
18 10
            throw new FileNotFoundException(sprintf('File "%s" does not exists', $file));
19
        }
20 18
    }
21
22
    /**
23
     * @throws FileNotReadableException
24
     * @throws FileNotFoundException
25
     */
26 26
    protected function ensureFileReadable(string $file): void
27
    {
28 26
        $this->ensureFileExists($file);
29 17
        if (!is_readable($file)) {
30 1
            throw new FileNotReadableException(sprintf(
31 1
                'File "%s" is not readable',
32 1
                $file
33
            ));
34
        }
35 16
    }
36
}
37