MediaImageResource::addConversions()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 2
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Owowagency\LaravelMedia\Resources;
4
5
class MediaImageResource extends MediaResource
6
{
7
    /**
8
     * Transform the resource into an array.
9
     *
10
     * @param  \Illuminate\Http\Request  $request
11
     * @return array
12
     */
13
    public function toArray($request): array
14
    {
15
        $data = [
16
            'original' => $this->getUrl(),
17
        ];
18
19
        $this->addConversions($data);
20
21
        return $data;
22
    }
23
24
    /**
25
     * Adds the conversions to the data that is being returned as array.
26
     *
27
     * @param  array  &$data
28
     * @return void
29
     */
30
    public function addConversions(array &$data): void
31
    {
32
        foreach ($this->resource->getMediaConversionNames() as $name) {
33
            $data[$name] = $this->getUrl($name);
34
        }
35
    }
36
}
37