Completed
Push — master ( 4f8f95...252732 )
by Maxime
34s
created

buildMediaInfoCommandRunner()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 23
c 1
b 0
f 0
ccs 13
cts 13
cp 1
rs 8.7972
cc 4
eloc 12
nc 4
nop 2
crap 4
1
<?php
2
3
namespace Mhor\MediaInfo\Builder;
4
5
use Mhor\MediaInfo\Runner\MediaInfoCommandRunner;
6
use Symfony\Component\Filesystem\Filesystem;
7
8
class MediaInfoCommandBuilder
9
{
10
    /**
11
     * @param string $filepath
12
     * @param array  $configuration
13
     *
14
     * @return MediaInfoCommandRunner
15
     */
16 5
    public function buildMediaInfoCommandRunner($filepath, array $configuration = array())
17
    {
18 5
        if (filter_var($filepath, FILTER_VALIDATE_URL) === false) {
19 4
            $fileSystem = new Filesystem();
20
21 4
            if (!$fileSystem->exists($filepath)) {
22 1
                throw new \Exception(sprintf('File "%s" does not exist', $filepath));
23
            }
24
25 3
            if (is_dir($filepath)) {
26 1
                throw new \Exception(sprintf(
27 1
                    'Expected a filename, got "%s", which is a directory',
28
                    $filepath
29 1
                ));
30
            }
31 2
        }
32
33
        $configuration = $configuration + array(
34 3
            'command' => null,
35 3
        );
36
37 3
        return new MediaInfoCommandRunner($filepath, $configuration['command']);
38
    }
39
}
40