Passed
Pull Request — master (#232)
by Pascal
02:29
created

InteractsWithHttpHeaders::getHeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\FFMpeg;
4
5
use Illuminate\Support\Collection;
6
7
trait InteractsWithHttpHeaders
8
{
9
    protected $headers = [];
10
11
    public function getHeaders(): array
12
    {
13
        return $this->headers;
14
    }
15
16
    public function setHeaders(array $headers = []): self
17
    {
18
        $this->headers = $headers;
19
20
        return $this;
21
    }
22
23
    protected static function mergeBeforePathInput(array $input, string $path, array $values = []): array
24
    {
25
        $key = array_search($path, $input) - 1;
26
27
        return static::mergeBeforeKey($input, $key, $values);
28
    }
29
30
    protected static function mergeBeforeKey(array $input, int $key, array $values = []): array
31
    {
32
        return array_merge(
33
            array_slice($input, 0, $key),
34
            $values,
35
            array_slice($input, $key)
36
        );
37
    }
38
39
    public static function compileHeaders(array $headers = []): array
40
    {
41
        if (empty($headers)) {
42
            return [];
43
        }
44
45
        $headers = Collection::make($headers)->map(function ($value, $key) {
46
            return "{$key}: {$value}";
47
        })->filter()->push("")->implode("\r\n");
48
49
        return ['-headers', $headers];
50
    }
51
}
52