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

PathAssertionsTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
eloc 8
dl 0
loc 23
ccs 10
cts 10
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A ensureFileExists() 0 4 2
A ensureFileReadable() 0 7 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