Passed
Push — master ( ac0e9d...b23da5 )
by Amin
04:21
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\Media\MediaTypeInterface;
15
16
17
/** @mixin  \FFMpeg\Media\Video */
18
class Media
19
{
20
    /** @var \FFMpeg\Media\Video */
21
    private $media;
22
23
    /** @var bool */
24
    private $is_tmp;
25
26
    /**
27
     * Media constructor.
28
     * @param MediaTypeInterface $media
29
     * @param bool $is_tmp
30
     */
31
    public function __construct(MediaTypeInterface $media, bool $is_tmp)
32
    {
33
        $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...
34
        $this->is_tmp = $is_tmp;
35
    }
36
37
    /**
38
     * @return DASH
39
     */
40
    public function dash(): DASH
41
    {
42
        return new DASH($this);
43
    }
44
45
    /**
46
     * @return HLS
47
     */
48
    public function hls(): HLS
49
    {
50
        return new HLS($this);
51
    }
52
53
    /**
54
     * @return StreamToFile
55
     */
56
    public function stream2file(): StreamToFile
57
    {
58
        return new StreamToFile($this);
59
    }
60
61
    /**
62
     * @return bool
63
     */
64
    public function isTmp(): bool
65
    {
66
        return $this->is_tmp;
67
    }
68
69
    /**
70
     * @param $argument
71
     * @return Media | \FFMpeg\Media\Video
72
     */
73
    private function isInstanceofArgument($argument)
74
    {
75
        return ($argument instanceof $this->media) ? $this : $argument;
76
    }
77
78
    /**
79
     * @param $method
80
     * @param $parameters
81
     * @return Media | \FFMpeg\Media\Video
82
     */
83
    public function __call($method, $parameters)
84
    {
85
        return $this->isInstanceofArgument(
86
            call_user_func_array([$this->media, $method], $parameters)
87
        );
88
    }
89
}