Passed
Push — master ( 6309f1...8af892 )
by Pascal
02:12
created

AdvancedMedia::buildCommand()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 10
c 1
b 0
f 0
nc 3
nop 0
dl 0
loc 19
rs 9.9332
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use FFMpeg\Media\AdvancedMedia as MediaAdvancedMedia;
6
use Illuminate\Support\Arr;
7
8
class AdvancedMedia extends MediaAdvancedMedia
9
{
10
    use InteractsWithHttpHeaders;
11
12
    /**
13
     * Create a new instance of this class with the instance of the underlying library.
14
     *
15
     * @param \FFMpeg\Media\AdvancedMedia $media
16
     * @return self
17
     */
18
    public static function make(MediaAdvancedMedia $media): self
19
    {
20
        return new static($media->getInputs(), $media->getFFMpegDriver(), FFProbe::make($media->getFFProbe()));
21
    }
22
23
    /**
24
     * Builds the command using the underlying library and then
25
     * prepends every input with its own set of headers.
26
     *
27
     * @return array
28
     */
29
    protected function buildCommand()
30
    {
31
        $command = parent::buildCommand();
32
33
        $inputKey = array_search(Arr::first($this->getInputs()), $command) - 1;
34
35
        foreach ($this->getInputs() as $key => $path) {
36
            $headers = $this->headers[$key];
37
38
            if (empty($headers)) {
39
                $inputKey += 2;
40
                continue;
41
            }
42
43
            $command = static::mergeBeforeKey($command, $inputKey, static::compileHeaders($headers));
44
            $inputKey += 4;
45
        }
46
47
        return $command;
48
    }
49
}
50