AdvancedMedia::make()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
rs 10
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