Passed
Pull Request — master (#262)
by Pascal
02:54
created

InteractsWithHttpHeaders   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A compileHeaders() 0 11 2
A getHeaders() 0 3 1
A setHeaders() 0 5 1
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use Illuminate\Support\Collection;
6
7
trait InteractsWithHttpHeaders
8
{
9
    use InteractsWithInputPath;
10
11
    /**
12
     * @var array
13
     */
14
    protected $headers = [];
15
16
    public function getHeaders(): array
17
    {
18
        return $this->headers;
19
    }
20
21
    public function setHeaders(array $headers = []): self
22
    {
23
        $this->headers = $headers;
24
25
        return $this;
26
    }
27
28
    /**
29
     * Maps the headers into a key-value string for FFmpeg. Returns
30
     * an array of arguments to pass into the command.
31
     *
32
     * @param array $headers
33
     * @return array
34
     */
35
    public static function compileHeaders(array $headers = []): array
36
    {
37
        if (empty($headers)) {
38
            return [];
39
        }
40
41
        $headers = Collection::make($headers)->map(function ($value, $key) {
42
            return "{$key}: {$value}";
43
        })->filter()->push("")->implode("\r\n");
44
45
        return ['-headers', $headers];
46
    }
47
}
48