Passed
Push — master ( 3ee3fe...b14545 )
by Amin
04:48
created

Media::isInstanceofArgument()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
/**
4
 * This file is part of the PHP-FFmpeg-video-streaming package.
5
 *
6
 * (c) Amin Yazdanpanah <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Streaming;
13
14
use FFMpeg\FFProbe\DataMapping\Stream;
15
use FFMpeg\Media\MediaTypeInterface;
16
17
/**
18
 * @method mixed save(\FFMpeg\Format\FormatInterface $format, $outputPathfile)
19
 * @method mixed addFilter(\FFMpeg\Filters\FilterInterface $filter)
20
 * @method mixed getStreams()
21
 */
22
class Media
23
{
24
25
    protected $media;
26
    /**
27
     * @var string
28
     */
29
    private $path;
30
31
    /**
32
     * Media constructor.
33
     * @param MediaTypeInterface $media
34
     * @param string $path
35
     */
36
    public function __construct(MediaTypeInterface $media, string $path)
37
    {
38
        $this->media = $media;
39
        $this->path = $path;
40
    }
41
42
    /**
43
     * @return DASH
44
     */
45
    public function DASH(): DASH
46
    {
47
        return new DASH($this);
48
    }
49
50
    /**
51
     * @return HLS
52
     */
53
    public function HLS(): HLS
54
    {
55
        return new HLS($this);
56
    }
57
58
    /**
59
     * @param $argument
60
     * @return Media
61
     */
62
    protected function isInstanceofArgument($argument)
63
    {
64
        return ($argument instanceof $this->media) ? $this : $argument;
65
    }
66
67
    /**
68
     * @param $method
69
     * @param $parameters
70
     * @return Media
71
     */
72
    public function __call($method, $parameters)
73
    {
74
        return $this->isInstanceofArgument(
75
            call_user_func_array([$this->media, $method], $parameters)
76
        );
77
    }
78
79
    /**
80
     * @return mixed
81
     */
82
    public function getFirstStream(): Stream
83
    {
84
        return $this->media->getStreams()->first();
0 ignored issues
show
Bug introduced by
The method getStreams() does not exist on FFMpeg\Media\MediaTypeInterface. It seems like you code against a sub-type of FFMpeg\Media\MediaTypeInterface such as FFMpeg\Media\AbstractStreamableMedia. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

84
        return $this->media->/** @scrutinizer ignore-call */ getStreams()->first();
Loading history...
85
    }
86
87
    /**
88
     * @return array
89
     */
90
    public function getPathInfo(): array
91
    {
92
        return pathinfo($this->path);
93
    }
94
}
95