AdvancedMedia   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A make() 0 3 1
A buildCommand() 0 21 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 InteractsWithBeforeSavingCallbacks;
11
    use InteractsWithHttpHeaders;
12
13
    /**
14
     * Create a new instance of this class with the instance of the underlying library.
15
     *
16
     * @param \FFMpeg\Media\AdvancedMedia $media
17
     * @return self
18
     */
19
    public static function make(MediaAdvancedMedia $media): self
20
    {
21
        return new static($media->getInputs(), $media->getFFMpegDriver(), FFProbe::make($media->getFFProbe()));
22
    }
23
24
    /**
25
     * Builds the command using the underlying library and then
26
     * prepends every input with its own set of headers.
27
     *
28
     * @return array
29
     */
30
    protected function buildCommand()
31
    {
32
        $command = parent::buildCommand();
33
34
        $inputKey = array_search(Arr::first($this->getInputs()), $command) - 1;
35
36
        foreach ($this->getInputs() as $key => $path) {
37
            $headers = $this->headers[$key];
38
39
            if (empty($headers)) {
40
                $inputKey += 2;
41
                continue;
42
            }
43
44
            $command = static::mergeBeforeKey($command, $inputKey, static::compileHeaders($headers));
45
            $inputKey += 4;
46
        }
47
48
        $command = $this->rebuildCommandWithCallbacks($command);
49
50
        return $command;
51
    }
52
}
53