Completed
Push — master ( 176514...705d93 )
by Amin
04:53
created

Media::__call()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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
     * @var bool
32
     */
33
    private $is_tmp;
34
35
36
    /**
37
     * Media constructor.
38
     * @param MediaTypeInterface $media
39
     * @param string $path
40
     * @param bool $is_tmp
41
     */
42
    public function __construct(MediaTypeInterface $media, string $path, bool $is_tmp)
43
    {
44
        $this->media = $media;
45
        $this->path = $path;
46
        $this->is_tmp = $is_tmp;
47
    }
48
49
    /**
50
     * @return DASH
51
     */
52
    public function DASH(): DASH
53
    {
54
        return new DASH($this);
55
    }
56
57
    /**
58
     * @return HLS
59
     */
60
    public function HLS(): HLS
61
    {
62
        return new HLS($this);
63
    }
64
65
    /**
66
     * @param $argument
67
     * @return Media
68
     */
69
    protected function isInstanceofArgument($argument)
70
    {
71
        return ($argument instanceof $this->media) ? $this : $argument;
72
    }
73
74
    /**
75
     * @param $method
76
     * @param $parameters
77
     * @return Media
78
     */
79
    public function __call($method, $parameters)
80
    {
81
        return $this->isInstanceofArgument(
82
            call_user_func_array([$this->media, $method], $parameters)
83
        );
84
    }
85
86
    /**
87
     * @return mixed
88
     */
89
    public function getVideoStream(): Stream
90
    {
91
        return $this->media->getStreams()->videos()->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

91
        return $this->media->/** @scrutinizer ignore-call */ getStreams()->videos()->first();
Loading history...
92
    }
93
94
    /**
95
     * @return mixed
96
     */
97
    public function getAllStreams()
98
    {
99
        return $this->media->getStreams()->all();
100
    }
101
102
    /**
103
     * @return string
104
     */
105
    public function getPath(): string
106
    {
107
        return $this->path;
108
    }
109
110
    /**
111
     * @return bool
112
     */
113
    public function isTmp(): bool
114
    {
115
        return $this->is_tmp;
116
    }
117
}
118