Passed
Push — master ( ec49ae...a933aa )
by Amin
05:42
created

Representations::addRepresentation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 1
b 1
f 0
cc 1
nc 1
nop 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\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
     * @return $this
25
     */
26
    public function addRepresentations()
27
    {
28
        $this->checkFormat();
29
        $reps = is_array(func_get_arg(0)) ? func_get_arg(0) : func_get_args();
30
31
        foreach ($reps as $rep) {
32
            if (!$rep instanceof Representation) {
33
                throw new InvalidArgumentException('Representations must be instance of Representation object');
34
            }
35
        }
36
37
        $this->representations = $reps;
38
        return $this;
39
    }
40
41
    /**
42
     * @return array
43
     */
44
    public function getRepresentations(): array
45
    {
46
        return $this->representations;
47
    }
48
49
    /**
50
     * @param array $side_values
51
     * @param array|null $k_bitrate_values
52
     * @return $this
53
     */
54
    public function autoGenerateRepresentations(array $side_values = null, array $k_bitrate_values = null)
55
    {
56
        $this->checkFormat();
57
        $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

57
        $this->representations = (new AutoRepresentations($this->/** @scrutinizer ignore-call */ getMedia()->probe(), $side_values, $k_bitrate_values))->get();
Loading history...
58
59
        return $this;
60
    }
61
62
    /**
63
     * check whether format is set or nor
64
     */
65
    private function checkFormat()
66
    {
67
        if (!$this->format) {
68
            throw new InvalidArgumentException('First you must set the format of the video');
69
        }
70
    }
71
}