FFMpegProvider::getDuration()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Toa\Component\Validator\Provider;
4
5
use FFMpeg\FFMpeg;
6
use Toa\Component\Validator\Exception\NotFoundDataException;
7
8
/**
9
 * FFMpegProvider
10
 *
11
 * @author Enrico Thies <[email protected]>
12
 */
13
class FFMpegProvider implements VideoProviderInterface
14
{
15
    /** @var FFMpeg\FFMpeg */
16
    private $ffmpeg;
17
18
    /** @var FFMpeg\FFProbe\DataMapping\Stream[] */
19
    private $streams = array();
20
21
    /**
22
     * @param FFMpeg $ffmpeg
23
     */
24
    public function __construct(FFMpeg $ffmpeg)
25
    {
26
        $this->ffmpeg = $ffmpeg;
0 ignored issues
show
Documentation Bug introduced by
It seems like $ffmpeg of type object<FFMpeg\FFMpeg> is incompatible with the declared type object<FFMpeg\FFMpeg\FFMpeg> of property $ffmpeg.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
    }
28
29
    /**
30
     * @param string $pathfile
31
     *
32
     * @return \FFMpeg\FFProbe\DataMapping\Stream
33
     */
34
    protected function getStream($pathfile)
35
    {
36
        if (!isset($this->streams[$pathfile])) {
37
            try {
38
                $this->streams[$pathfile] = $this->ffmpeg->open($pathfile)->getStreams()->first();
39
            } catch (\RuntimeException $e) {
40
                throw new NotFoundDataException(
41
                    sprintf('Unable to provide data for "%s"', $pathfile),
42
                    $e->getCode(),
43
                    $e
44
                );
45
            }
46
        }
47
48
        return $this->streams[$pathfile];
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function getDuration($value)
55
    {
56
        return $this->getStream($value)->get('duration');
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function getHeight($value)
63
    {
64
        return $this->getStream($value)->get('height');
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70
    public function getWidth($value)
71
    {
72
        return $this->getStream($value)->get('width');
73
    }
74
}
75