• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mhor / php-mediainfo / #270

07 Jan 2026 09:36PM UTC coverage: 93.103% (+0.7%) from 92.44%
#270

push

web-flow
Merge pull request #153 from mhor/feature-upgrade-phpunit

upgrade phpunit

297 of 319 relevant lines covered (93.1%)

4.67 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

32.26
/src/MediaInfo.php
1
<?php
2

3
namespace Mhor\MediaInfo;
4

5
use Mhor\MediaInfo\Builder\MediaInfoCommandBuilder;
6
use Mhor\MediaInfo\Container\MediaInfoContainer;
7
use Mhor\MediaInfo\Parser\MediaInfoOutputParser;
8
use Mhor\MediaInfo\Runner\MediaInfoCommandRunner;
9

10
class MediaInfo
11
{
12
    private ?MediaInfoCommandRunner $mediaInfoCommandRunnerAsync = null;
13

14
    private array $configuration = [
15
        'command'                            => null,
16
        'use_oldxml_mediainfo_output_format' => true,
17
        'urlencode'                          => false,
18
        'include_cover_data'                 => false,
19
        'ignore_unknown_track_types'         => false,
20
        'attribute_checkers'                 => null,
21
    ];
22

23
    /**
24
     * @param string $filePath
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
     *                                          This parameter is deprecated use self::setConfig('ignore_unknown_track_types', true)
28
     *
29
     * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException
30
     *
31
     * @return MediaInfoContainer
32
     */
33
    public function getInfo(string $filePath, bool $ignoreUnknownTrackTypes = false): MediaInfoContainer
34
    {
35
        $mediaInfoCommandBuilder = new MediaInfoCommandBuilder();
×
36
        $output = $mediaInfoCommandBuilder->buildMediaInfoCommandRunner($filePath, $this->configuration)->run();
×
37

38
        $mediaInfoOutputParser = new MediaInfoOutputParser();
×
39
        $mediaInfoOutputParser->parse($output);
×
40

41
        if (true === $ignoreUnknownTrackTypes) {
×
42
            $this->setConfig('ignore_unknown_track_types', true);
×
43
        }
44

45
        return $mediaInfoOutputParser->getMediaInfoContainer($this->configuration);
×
46
    }
47

48
    /**
49
     * Call to start asynchronous process.
50
     *
51
     * Make call to MediaInfo::getInfoWaitAsync() afterwards to received MediaInfoContainer object.
52
     */
53
    public function getInfoStartAsync(string $filePath): void
54
    {
55
        $mediaInfoCommandBuilder = new MediaInfoCommandBuilder();
×
56
        $this->mediaInfoCommandRunnerAsync = $mediaInfoCommandBuilder->buildMediaInfoCommandRunner(
×
57
            $filePath,
×
58
            $this->configuration
×
59
        );
×
60
        $this->mediaInfoCommandRunnerAsync->start();
×
61
    }
62

63
    /**
64
     * @param bool $ignoreUnknownTrackTypes Optional parameter used to skip unknown track types by passing true. The
65
     *                                      default behavior (false) is throw an exception on unknown track types.
66
     *                                      This parameter is deprecated use self::setConfig('ignore_unknown_track_types', true)
67
     *
68
     * @throws \Exception                   If this function is called before getInfoStartAsync()
69
     * @throws \Mhor\MediaInfo\Exception\UnknownTrackTypeException
70
     *
71
     * @return MediaInfoContainer
72
     */
73
    public function getInfoWaitAsync(bool $ignoreUnknownTrackTypes = false): MediaInfoContainer
74
    {
75
        if ($this->mediaInfoCommandRunnerAsync == null) {
×
76
            throw new \Exception('You must run `getInfoStartAsync` before running `getInfoWaitAsync`');
×
77
        }
78

79
        // blocks here until process is complete
80
        $output = $this->mediaInfoCommandRunnerAsync->wait();
×
81

82
        $mediaInfoOutputParser = new MediaInfoOutputParser();
×
83
        $mediaInfoOutputParser->parse($output);
×
84

85
        if (true === $ignoreUnknownTrackTypes) {
×
86
            $this->setConfig('ignore_unknown_track_types', true);
×
87
        }
88

89
        return $mediaInfoOutputParser->getMediaInfoContainer($this->configuration);
×
90
    }
91

92
    /**
93
     * @param mixed $value
94
     *
95
     * @throws \Exception
96
     */
97
    public function setConfig(string $key, $value): void
98
    {
99
        if (!array_key_exists($key, $this->configuration)) {
1✔
100
            throw new \Exception(
1✔
101
                sprintf('key "%s" does\'t exist', $key)
1✔
102
            );
1✔
103
        }
104

105
        $this->configuration[$key] = $value;
1✔
106
    }
107

108
    /**
109
     * @return mixed
110
     *
111
     * @throws \Exception
112
     */
113
    public function getConfig(string $key)
114
    {
115
        if (!array_key_exists($key, $this->configuration)) {
2✔
116
            throw new \Exception(
1✔
117
                sprintf('key "%s" does\'t exist', $key)
1✔
118
            );
1✔
119
        }
120

121
        return $this->configuration[$key];
2✔
122
    }
123
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc