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

Representation   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 12
c 1
b 1
f 0
dl 0
loc 42
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A autoGenerateRepresentations() 0 10 2
A addRepresentation() 0 8 2
A getRepresentations() 0 3 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\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
}