Completed
Push — master ( 64cc65...e3f897 )
by Amin
03:07
created

Representations::autoGenerateRepresentations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 10
rs 10
c 0
b 0
f 0
cc 2
nc 2
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\Traits;
13
14
use Streaming\AutoRepresentations;
15
use Streaming\Exception\Exception;
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
     * @throws Exception
27
     */
28
    public function addRepresentation(Representation $rep)
29
    {
30
        if (!$this->format) {
31
            throw new Exception('Format has not been set');
32
        }
33
34
        $this->representations[] = $rep;
35
        return $this;
36
    }
37
38
    /**
39
     * @return array
40
     */
41
    public function getRepresentations(): array
42
    {
43
        return $this->representations;
44
    }
45
46
    /**
47
     * @param array $side_values
48
     * @param array|null $k_bitrate_values
49
     * @return $this
50
     * @throws Exception
51
     */
52
    public function autoGenerateRepresentations(array $side_values = null, array $k_bitrate_values = null)
53
    {
54
        if (!$this->format) {
55
            throw new Exception('Format has not been set');
56
        }
57
58
        $this->representations = (new AutoRepresentations($this->getMedia()->probe(), $side_values, $k_bitrate_values))
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

58
        $this->representations = (new AutoRepresentations($this->/** @scrutinizer ignore-call */ getMedia()->probe(), $side_values, $k_bitrate_values))
Loading history...
59
            ->get();
60
61
        return $this;
62
    }
63
}