Passed
Branch master (b4f9b9)
by Maxime
03:00
created

buildMediaInfoCommandRunner()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 18
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3.0123

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 18
ccs 8
cts 9
cp 0.8889
rs 9.4285
cc 3
eloc 9
nc 3
nop 2
crap 3.0123
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 3
    public function buildMediaInfoCommandRunner($filepath, array $configuration = array())
17
    {
18 3
        $fileSystem = new Filesystem();
19
20 3
        if (!$fileSystem->exists($filepath)) {
21 1
            throw new \Exception('File doesn\'t exist');
22
        }
23
24 2
        if (is_dir($filepath)) {
25
            throw new \Exception('You must specify a filename, not a directory name');
26
        }
27
28
        $configuration = $configuration + array(
29 2
            'command' => null,
30 2
        );
31
32 2
        return new MediaInfoCommandRunner($filepath, $configuration['command']);
33
    }
34
}
35