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

MediaInfoOutputParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 10
Bugs 2 Features 2
Metric Value
wmc 6
c 10
b 2
f 2
lcom 1
cbo 3
dl 0
loc 45
ccs 15
cts 15
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parse() 0 4 1
B getMediaInfoContainer() 0 23 5
1
<?php
2
3
namespace Mhor\MediaInfo\Parser;
4
5
use Mhor\MediaInfo\Builder\MediaInfoContainerBuilder;
6
use Mhor\MediaInfo\Container\MediaInfoContainer;
7
use Mhor\MediaInfo\Exception\UnknownTrackTypeException;
8
9
class MediaInfoOutputParser extends AbstractXmlOutputParser
10
{
11
    /**
12
     * @var array
13
     */
14
    private $parsedOutput;
15
16
    /**
17
     * @param string $output
18
     */
19 3
    public function parse($output)
20
    {
21 3
        $this->parsedOutput = $this->transformXmlToArray($output);
22 3
    }
23
24
    /**
25
     * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The
26
     *                                      default behavior (false) is throw an exception on unknown track types.
27
     *
28
     * @return MediaInfoContainer
29
     */
30 4
    public function getMediaInfoContainer($ignoreUnknownTrackTypes = false)
31
    {
32 4
        if ($this->parsedOutput === null) {
33 1
            throw new \Exception('You must run `parse` before running `getMediaInfoContainer`');
34
        }
35
36 3
        $mediaInfoContainerBuilder = new MediaInfoContainerBuilder($ignoreUnknownTrackTypes);
0 ignored issues
show
Unused Code introduced by
The call to MediaInfoContainerBuilder::__construct() has too many arguments starting with $ignoreUnknownTrackTypes.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
37 3
        $mediaInfoContainerBuilder->setVersion($this->parsedOutput['@attributes']['version']);
38
39 3
        foreach ($this->parsedOutput['File']['track'] as $trackType) {
40
            try {
41 3
                $mediaInfoContainerBuilder->addTrackType($trackType['@attributes']['type'], $trackType);
42 3
            } catch (UnknownTrackTypeException $ex) {
43 2
                if (!$ignoreUnknownTrackTypes) {
44
                    // rethrow exception
45 1
                    throw $ex;
46
                }
47
                // else ignore
48
            }
49 3
        }
50
51 2
        return $mediaInfoContainerBuilder->build();
52
    }
53
}
54