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

MediaInfoOutputParser::getMediaInfoContainer()   B

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 5

Importance

Changes 5
Bugs 1 Features 1
Metric Value
c 5
b 1
f 1
dl 0
loc 23
ccs 12
cts 12
cp 1
rs 8.5906
cc 5
eloc 12
nc 5
nop 1
crap 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