Passed
Push — master ( ac0e9d...b23da5 )
by Amin
04:21
created

Representations::addRepresentation()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 1
b 1
f 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\AutoReps;
15
use Streaming\Exception\InvalidArgumentException;
16
use Streaming\RepresentationInterface;
17
use Streaming\RepsCollection;
18
19
trait Representations
20
{
21
    /** @var RepsCollection */
22
    protected $reps;
23
24
    /**
25
     * add a representation
26
     * @param RepresentationInterface $rep
27
     * @return $this
28
     */
29
    public function addRepresentation(RepresentationInterface $rep)
30
    {
31
        $this->reps->add($rep);
32
        return $this;
33
    }
34
35
    /**
36
     * add representations using an array
37
     * @param array $reps
38
     * @return $this
39
     */
40
    public function addRepresentations(array $reps)
41
    {
42
        array_walk($reps, [$this, 'addRepresentation']);
43
        return $this;
44
    }
45
46
    /**
47
     * @param array|null $sides
48
     * @param array|null $k_bitrate
49
     * @param string $sort
50
     * @return $this
51
     */
52
    public function autoGenerateRepresentations(array $sides = null, array $k_bitrate = null, string $sort = "asc")
53
    {
54
        if (!$this->format) {
55
            throw new InvalidArgumentException('First you must set the format of the video');
56
        }
57
58
        $reps = new AutoReps($this->getMedia(), $this->getFormat(), $sides, $k_bitrate);
0 ignored issues
show
Bug introduced by
It seems like getFormat() 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
        $reps = new AutoReps($this->getMedia(), $this->/** @scrutinizer ignore-call */ getFormat(), $sides, $k_bitrate);
Loading history...
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
        $reps = new AutoReps($this->/** @scrutinizer ignore-call */ getMedia(), $this->getFormat(), $sides, $k_bitrate);
Loading history...
59
        $reps->sort($sort);
60
61
        foreach ($reps as $rep) {
62
            $this->addRepresentation($rep);
63
        }
64
65
        return $this;
66
    }
67
68
    /**
69
     * @return RepsCollection
70
     */
71
    public function getRepresentations(): RepsCollection
72
    {
73
        return $this->reps;
74
    }
75
}