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

AdvancedMedia   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A buildCommand() 0 19 3
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