Media   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 16
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isInstanceofArgument() 0 3 2
A __call() 0 4 1
A __construct() 0 5 1
A baseMedia() 0 3 1
A isTmp() 0 3 1
A stream2file() 0 3 1
A dash() 0 3 1
A getInputOptions() 0 3 1
A hls() 0 3 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\Media\MediaTypeInterface;
15
use FFMpeg\Media\Video;
16
17
18
/** @mixin  \FFMpeg\Media\Video */
19
class Media
20
{
21
    /** @var \FFMpeg\Media\Video */
22
    private $media;
23
24
    /** @var bool */
25
    private $is_tmp;
26
27
    /** @var array */
28
    private $input_options;
29
30
    /**
31
     * Media constructor.
32
     * @param MediaTypeInterface $media
33
     * @param bool $is_tmp
34
     * @param array $input_options
35
     */
36
    public function __construct(MediaTypeInterface $media, bool $is_tmp, array $input_options = [])
37
    {
38
        $this->media = $media;
0 ignored issues
show
Documentation Bug introduced by
$media is of type FFMpeg\Media\MediaTypeInterface, but the property $media was declared to be of type FFMpeg\Media\Video. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
39
        $this->is_tmp = $is_tmp;
40
        $this->input_options = $input_options;
41
    }
42
43
    /**
44
     * @return DASH
45
     */
46
    public function dash(): DASH
47
    {
48
        return new DASH($this);
49
    }
50
51
    /**
52
     * @return HLS
53
     */
54
    public function hls(): HLS
55
    {
56
        return new HLS($this);
57
    }
58
59
    /**
60
     * @return StreamToFile
61
     */
62
    public function stream2file(): StreamToFile
63
    {
64
        return new StreamToFile($this);
65
    }
66
67
    /**
68
     * @return bool
69
     */
70
    public function isTmp(): bool
71
    {
72
        return $this->is_tmp;
73
    }
74
75
    /**
76
     * @return Video | \FFMpeg\Media\Audio
77
     */
78
    public function baseMedia(): MediaTypeInterface
79
    {
80
        return $this->media;
81
    }
82
83
    /**
84
     * @param $argument
85
     * @return Media | \FFMpeg\Media\Video
86
     */
87
    private function isInstanceofArgument($argument)
88
    {
89
        return ($argument instanceof $this->media) ? $this : $argument;
90
    }
91
92
    /**
93
     * @param $method
94
     * @param $parameters
95
     * @return Media | \FFMpeg\Media\Video
96
     */
97
    public function __call($method, $parameters)
98
    {
99
        return $this->isInstanceofArgument(
100
            call_user_func_array([$this->media, $method], $parameters)
101
        );
102
    }
103
104
    /**
105
     * @return array
106
     */
107
    public function getInputOptions(): array
108
    {
109
        return $this->input_options;
110
    }
111
}