ProgressListenerDecorator   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 108
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 25
dl 0
loc 108
rs 10
c 0
b 0
f 0
wmc 19

18 Methods

Rating   Name   Duplication   Size   Complexity  
A getPasses() 0 3 1
A getListeners() 0 3 1
A once() 0 3 1
A removeAllListeners() 0 3 1
A getAudioChannels() 0 3 1
A emit() 0 3 1
A createProgressListener() 0 4 1
A getAudioKiloBitrate() 0 3 1
A __call() 0 3 1
A listeners() 0 3 1
A getAvailableAudioCodecs() 0 3 1
A decorate() 0 7 2
A __get() 0 3 1
A removeListener() 0 3 1
A getExtraParams() 0 3 1
A getAudioCodec() 0 3 1
A on() 0 3 1
A __construct() 0 3 1
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use FFMpeg\FFProbe;
0 ignored issues
show
Bug introduced by
This use statement conflicts with another class in this namespace, ProtoneMedia\LaravelFFMpeg\FFMpeg\FFProbe. Consider defining an alias.

Let?s assume that you have a directory layout like this:

.
|-- OtherDir
|   |-- Bar.php
|   `-- Foo.php
`-- SomeDir
    `-- Foo.php

and let?s assume the following content of Bar.php:

// Bar.php
namespace OtherDir;

use SomeDir\Foo; // This now conflicts the class OtherDir\Foo

If both files OtherDir/Foo.php and SomeDir/Foo.php are loaded in the same runtime, you will see a PHP error such as the following:

PHP Fatal error:  Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php

However, as OtherDir/Foo.php does not necessarily have to be loaded and the error is only triggered if it is loaded before OtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias:

// Bar.php
namespace OtherDir;

use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
6
use FFMpeg\Format\AudioInterface;
7
use FFMpeg\Format\ProgressableInterface;
8
use FFMpeg\Format\VideoInterface;
9
use FFMpeg\Media\MediaTypeInterface;
10
use Illuminate\Support\Traits\ForwardsCalls;
11
12
/**
13
 * Use this decorator to get access to the AbstractProgressListeners0
14
 * with the `getListeners` method.
15
 */
16
class ProgressListenerDecorator implements ProgressableInterface, AudioInterface
17
{
18
    use ForwardsCalls;
19
20
    /**
21
     * @var \FFMpeg\Format\AudioInterface|\FFMpeg\Format\VideoInterface
22
     */
23
    protected $format;
24
25
    /**
26
     * @var array
27
     */
28
    protected $listeners = [];
29
30
    public function __construct($format)
31
    {
32
        $this->format = $format;
33
    }
34
35
    public static function decorate($format)
36
    {
37
        if ($format instanceof VideoInterface) {
38
            return new VideoProgressListenerDecorator($format);
39
        }
40
41
        return new static($format);
42
    }
43
44
    public function getListeners(): array
45
    {
46
        return $this->listeners;
47
    }
48
49
    public function createProgressListener(MediaTypeInterface $media, FFProbe $ffprobe, $pass, $total, $duration = 0)
50
    {
51
        return tap($this->format->createProgressListener(...func_get_args()), function (array $listeners) {
0 ignored issues
show
Bug introduced by
The method createProgressListener() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

51
        return tap($this->format->/** @scrutinizer ignore-call */ createProgressListener(...func_get_args()), function (array $listeners) {
Loading history...
52
            $this->listeners = array_merge($this->listeners, $listeners);
53
        });
54
    }
55
56
    public function on($event, callable $listener)
57
    {
58
        return $this->format->on(...func_get_args());
0 ignored issues
show
Bug introduced by
The method on() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

58
        return $this->format->/** @scrutinizer ignore-call */ on(...func_get_args());
Loading history...
59
    }
60
61
    public function once($event, callable $listener)
62
    {
63
        return $this->format->once(...func_get_args());
0 ignored issues
show
Bug introduced by
The method once() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

63
        return $this->format->/** @scrutinizer ignore-call */ once(...func_get_args());
Loading history...
64
    }
65
66
    public function removeListener($event, callable $listener)
67
    {
68
        return $this->format->removeListener(...func_get_args());
0 ignored issues
show
Bug introduced by
The method removeListener() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

68
        return $this->format->/** @scrutinizer ignore-call */ removeListener(...func_get_args());
Loading history...
69
    }
70
71
    public function removeAllListeners($event = null)
72
    {
73
        return $this->format->removeAllListeners(...func_get_args());
0 ignored issues
show
Bug introduced by
The method removeAllListeners() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

73
        return $this->format->/** @scrutinizer ignore-call */ removeAllListeners(...func_get_args());
Loading history...
74
    }
75
76
    public function listeners($event = null)
77
    {
78
        return $this->format->listeners(...func_get_args());
0 ignored issues
show
Bug introduced by
The method listeners() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

78
        return $this->format->/** @scrutinizer ignore-call */ listeners(...func_get_args());
Loading history...
79
    }
80
81
    public function emit($event, array $arguments = [])
82
    {
83
        return $this->format->emit(...func_get_args());
0 ignored issues
show
Bug introduced by
The method emit() does not exist on FFMpeg\Format\AudioInterface. It seems like you code against a sub-type of said class. However, the method does not exist in FFMpeg\Format\VideoInterface. Are you sure you never get one of those? ( Ignorable by Annotation )

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

83
        return $this->format->/** @scrutinizer ignore-call */ emit(...func_get_args());
Loading history...
84
    }
85
86
    public function getPasses()
87
    {
88
        return $this->format->getPasses(...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to FFMpeg\Format\FormatInterface::getPasses() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

88
        return $this->format->/** @scrutinizer ignore-call */ getPasses(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
89
    }
90
91
    public function getExtraParams()
92
    {
93
        return $this->format->getExtraParams(...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to FFMpeg\Format\FormatInterface::getExtraParams() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

93
        return $this->format->/** @scrutinizer ignore-call */ getExtraParams(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
94
    }
95
96
    public function getAudioKiloBitrate()
97
    {
98
        return $this->format->getAudioKiloBitrate(...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to FFMpeg\Format\AudioInter...::getAudioKiloBitrate() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

98
        return $this->format->/** @scrutinizer ignore-call */ getAudioKiloBitrate(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
99
    }
100
101
    public function getAudioChannels()
102
    {
103
        return $this->format->getAudioChannels(...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to FFMpeg\Format\AudioInterface::getAudioChannels() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

103
        return $this->format->/** @scrutinizer ignore-call */ getAudioChannels(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
104
    }
105
106
    public function getAudioCodec()
107
    {
108
        return $this->format->getAudioCodec(...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to FFMpeg\Format\AudioInterface::getAudioCodec() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

108
        return $this->format->/** @scrutinizer ignore-call */ getAudioCodec(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
109
    }
110
111
    public function getAvailableAudioCodecs()
112
    {
113
        return $this->format->getAvailableAudioCodecs(...func_get_args());
0 ignored issues
show
Unused Code introduced by
The call to FFMpeg\Format\AudioInter...tAvailableAudioCodecs() has too many arguments starting with func_get_args(). ( Ignorable by Annotation )

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

113
        return $this->format->/** @scrutinizer ignore-call */ getAvailableAudioCodecs(...func_get_args());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
114
    }
115
116
    public function __get($key)
117
    {
118
        return $this->format->{$key};
119
    }
120
121
    public function __call($method, $arguments)
122
    {
123
        return $this->forwardCallTo($this->format, $method, $arguments);
124
    }
125
}
126