Passed
Push — master ( c2411e...541f04 )
by Amin
02:01
created

Media::HLS()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * Copyright 2019 Amin Yazdanpanah<http://www.aminyazdanpanah.com>.
5
 *
6
 * Licensed under the MIT License;
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *      https://opensource.org/licenses/MIT
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace AYazdanpanah\FFMpegStreaming;
20
21
use FFMpeg\FFProbe\DataMapping\Stream;
22
use FFMpeg\Media\MediaTypeInterface;
23
24
/**
25
 * @method mixed save(\FFMpeg\Format\FormatInterface $format, $outputPathfile)
26
 * @method mixed addFilter(\FFMpeg\Filters\FilterInterface $filter)
27
 * @method mixed getStreams()
28
 */
29
class Media
30
{
31
32
    protected $media;
33
    /**
34
     * @var string
35
     */
36
    private $path;
37
38
    /**
39
     * Media constructor.
40
     * @param MediaTypeInterface $media
41
     * @param string $path
42
     */
43
    public function __construct(MediaTypeInterface $media, string $path)
44
    {
45
        $this->media = $media;
46
        $this->path = $path;
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 getFirstStream(): Stream
90
    {
91
        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

91
        return $this->media->/** @scrutinizer ignore-call */ getStreams()->first();
Loading history...
92
    }
93
94
    /**
95
     * @return array
96
     */
97
    public function getPathInfo(): array
98
    {
99
        return pathinfo($this->path);
100
    }
101
}
102