Test Failed
Pull Request — master (#101)
by Maxime
01:57
created

buildMediaInfoCommandRunner()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.3398

Importance

Changes 0
Metric Value
dl 0
loc 30
ccs 9
cts 16
cp 0.5625
rs 9.44
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 5.3398
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
     * @throws \Exception
15
     *
16
     * @return MediaInfoCommandRunner
17
     */
18 2
    public function buildMediaInfoCommandRunner($filePath, array $configuration = [])
19
    {
20 2
        if (filter_var($filePath, FILTER_VALIDATE_URL) === false) {
21 2
            $fileSystem = new Filesystem();
22
23 2
            if (!$fileSystem->exists($filePath)) {
24 1
                throw new \Exception(sprintf('File "%s" does not exist', $filePath));
25
            }
26
27 1
            if (is_dir($filePath)) {
28 1
                throw new \Exception(sprintf(
29 1
                    'Expected a filename, got "%s", which is a directory',
30 1
                    $filePath
31
                ));
32
            }
33
        }
34
35
        $configuration = $configuration + [
36
            'command'                            => null,
37
            'use_oldxml_mediainfo_output_format' => false,
38
        ];
39
40
        return new MediaInfoCommandRunner(
41
            $filePath,
42
            $configuration['command'],
43
            null,
44
            null,
45
            $configuration['use_oldxml_mediainfo_output_format']
46
        );
47
    }
48
}
49