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

MediaInfoCommandBuilder   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 32
c 1
b 0
f 0
wmc 4
lcom 0
cbo 2
ccs 13
cts 13
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B buildMediaInfoCommandRunner() 0 23 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