Passed
Pull Request — master (#232)
by Pascal
03:52
created

InteractsWithHttpHeaders   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 38
rs 10
wmc 5

4 Methods

Rating   Name   Duplication   Size   Complexity  
A compileHeaders() 0 11 2
A getHeaders() 0 3 1
A mergeBeforePathInput() 0 8 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
    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 array_merge(
28
            array_slice($input, 0, $key),
29
            $values,
30
            array_slice($input, $key)
31
        );
32
    }
33
34
    public static function compileHeaders(array $headers = []): array
35
    {
36
        if (empty($headers)) {
37
            return [];
38
        }
39
40
        $headers = Collection::make($headers)->map(function ($value, $key) {
41
            return "{$key}: {$value}";
42
        })->filter()->push("")->implode("\r\n");
43
44
        return ['-headers', $headers];
45
    }
46
}
47