Passed
Push — master ( 4991cf...c37170 )
by Amin
02:21
created

Representations::checkFormat()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 1
b 1
f 0
cc 2
nc 2
nop 0
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\Traits;
13
14
use Streaming\AutoRepresentations;
15
use Streaming\Exception\InvalidArgumentException;
16
use Streaming\Representation;
17
18
trait Representations
19
{
20
    /** @var array */
21
    protected $representations = [];
22
23
    /**
24
     * @param Representation $rep
25
     * @return $this
26
     * @deprecated Please use addRepresentations instead
27
     */
28
    public function addRepresentation(Representation $rep)
29
    {
30
        @trigger_error('addRepresentation method is deprecated and will be removed in a future release. Use addRepresentations instead.', E_USER_DEPRECATED);
31
        $this->checkFormat();
32
        $this->representations[] = $rep;
33
34
        return $this;
35
    }
36
37
    /**
38
     * @return $this
39
     */
40
    public function addRepresentations()
41
    {
42
        $this->checkFormat();
43
        $reps = func_get_args();
44
45
        foreach ($reps as $rep) {
46
            if (!$rep instanceof Representation) {
47
                throw new InvalidArgumentException('It must be instance of Representation object');
48
            }
49
        }
50
51
        $this->representations = $reps;
52
        return $this;
53
    }
54
55
    /**
56
     * @return array
57
     */
58
    public function getRepresentations(): array
59
    {
60
        return $this->representations;
61
    }
62
63
    /**
64
     * @param array $side_values
65
     * @param array|null $k_bitrate_values
66
     * @return $this
67
     */
68
    public function autoGenerateRepresentations(array $side_values = null, array $k_bitrate_values = null)
69
    {
70
        $this->checkFormat();
71
        $this->representations = (new AutoRepresentations($this->getMedia()->probe(), $side_values, $k_bitrate_values))->get();
0 ignored issues
show
Bug introduced by
It seems like getMedia() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

71
        $this->representations = (new AutoRepresentations($this->/** @scrutinizer ignore-call */ getMedia()->probe(), $side_values, $k_bitrate_values))->get();
Loading history...
72
73
        return $this;
74
    }
75
76
    /**
77
     * check whether format is set or nor
78
     */
79
    private function checkFormat()
80
    {
81
        if (!$this->format) {
82
            throw new InvalidArgumentException('First you must set the format of the video');
83
        }
84
    }
85
}