Passed
Push — master ( 3ee3fe...b14545 )
by Amin
04:48
created

Representation::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 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\Exception;
16
17
trait Representation
18
{
19
    /** @var array */
20
    protected $representations = [];
21
22
    /**
23
     * @param Representation $representation
24
     * @return $this
25
     * @throws Exception
26
     */
27
    public function addRepresentation(Representation $representation)
28
    {
29
        if (!$this->format) {
30
            throw new Exception('Format has not been set');
31
        }
32
33
        $this->representations[] = $representation;
34
        return $this;
35
    }
36
37
    /**
38
     * @return array
39
     */
40
    public function getRepresentations(): array
41
    {
42
        return $this->representations;
43
    }
44
45
    /**
46
     * @return $this
47
     * @throws Exception
48
     */
49
    public function autoGenerateRepresentations()
50
    {
51
        if (!$this->format) {
52
            throw new Exception('Format has not been set');
53
        }
54
55
        $this->representations = (new AutoRepresentations($this->media->getFirstStream()))
56
            ->get();
57
58
        return $this;
59
    }
60
61
}