Test Failed
Push — fix-76 ( 8c38ae )
by Maxime
02:19
created

MediaInfoOutputParser::getMediaInfoContainer()   C

Complexity

Conditions 7
Paths 11

Size

Total Lines 32
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 17
CRAP Score 7.0572

Importance

Changes 2
Bugs 2 Features 0
Metric Value
dl 0
loc 32
ccs 17
cts 19
cp 0.8947
rs 6.7272
c 2
b 2
f 0
cc 7
eloc 17
nc 11
nop 1
crap 7.0572
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
        $root = 'File';
38 3
        $version = $this->parsedOutput['@attributes']['version'];
39
40 3
        if ($version == 2.0) { // mediainfo output change on version >= 17.0
41
            $root = 'media';
42
        }
43
44 3
        $mediaInfoContainerBuilder->setVersion($version);
45
46 3
        foreach ($this->parsedOutput[$root]['track'] as $trackType) {
47
            try {
48 3
                if (isset($trackType['@attributes']['type'])) {
49 3
                    $mediaInfoContainerBuilder->addTrackType($trackType['@attributes']['type'], $trackType);
50 3
                }
51 3
            } catch (UnknownTrackTypeException $ex) {
52 2
                if (!$ignoreUnknownTrackTypes) {
53
                    // rethrow exception
54 1
                    throw $ex;
55
                }
56
                // else ignore
57
            }
58 3
        }
59
60 2
        return $mediaInfoContainerBuilder->build();
61
    }
62
}
63