MediaResourceCollection::toArray()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php
2
3
namespace Owowagency\LaravelMedia\Resources;
4
5
use Illuminate\Http\Resources\Json\ResourceCollection;
6
7
class MediaResourceCollection extends ResourceCollection
8
{
9
    /**
10
     * Force the resource to use its own array structure instead of possible
11
     * exceptions.
12
     *
13
     * @var bool
14
     */
15
    public $forceMediaResource = false;
16
17
    /**
18
     * Create a new resource instance.
19
     *
20
     * @param  mixed  $resource
21
     * @param  bool  $forceMediaResource
22
     */
23
    public function __construct($resource, bool $forceMediaResource = false)
24
    {
25
        parent::__construct($resource);
26
27
        $this->forceMediaResource = $forceMediaResource;
28
    }
29
30
    /**
31
     * Transform the resource collection into an array.
32
     *
33
     * @param  \Illuminate\Http\Request  $request
34
     * @return array
35
     */
36
    public function toArray($request): array
37
    {
38
        return $this->resource->map(function (MediaResource $resource) use ($request) {
0 ignored issues
show
Unused Code introduced by
The import $request is not used and could be removed.

This check looks for imports that have been defined, but are not used in the scope.

Loading history...
39
            $resource->forceMediaResource = $this->forceMediaResource;
40
41
            return $resource;
42
        })->toArray();
43
    }
44
}
45