Passed
Push — master ( 6309f1...8af892 )
by Pascal
02:12
created

MediaCollection::getHeaders()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 5
rs 10
1
<?php
2
3
namespace ProtoneMedia\LaravelFFMpeg\Filesystem;
4
5
use Illuminate\Support\Collection;
6
use Illuminate\Support\Traits\ForwardsCalls;
7
8
/**
9
 * @mixin \Illuminate\Support\Collection
10
 */
11
class MediaCollection
12
{
13
    use ForwardsCalls;
14
15
    /**
16
     * @var \Illuminate\Support\Collection
17
     */
18
    private $items;
19
20
    public function __construct(array $items = [])
21
    {
22
        $this->items = new Collection($items);
23
    }
24
25
    public static function make(array $items = []): self
26
    {
27
        return new static($items);
28
    }
29
30
    /**
31
     * Returns an array with all locals paths of the Media items.
32
     */
33
    public function getLocalPaths(): array
34
    {
35
        return $this->items->map->getLocalPath()->all();
36
    }
37
38
    /**
39
     * Returns an array with all headers of the Media items.
40
     */
41
    public function getHeaders(): array
42
    {
43
        return $this->items->map(function ($media) {
44
            return $media instanceof MediaOnNetwork ? $media->getHeaders() : [];
45
        })->all();
46
    }
47
48
    public function collection(): Collection
49
    {
50
        return $this->items;
51
    }
52
53
    /**
54
     * Count the number of items in the collection.
55
     *
56
     * @return int
57
     */
58
    public function count(): int
59
    {
60
        return $this->items->count();
61
    }
62
63
    public function __call($method, $parameters)
64
    {
65
        return $this->forwardCallTo($this->collection(), $method, $parameters);
66
    }
67
}
68