HasMedia   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
eloc 7
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addImage() 0 7 2
A getImageAttributeName() 0 7 2
1
<?php
2
3
namespace Owowagency\LaravelMedia\Resources\Concerns;
4
5
trait HasMedia
6
{
7
    /**
8
     * Adds the image when loaded.
9
     *
10
     * @param  array  &$data
11
     * @return void
12
     */
13
    private function addImage(array &$data): void
14
    {
15
        if (! $this->resource->relationLoaded('media')) {
16
            return;
17
        }
18
19
        $data[$this->getImageAttributeName()] = resource($this->resource->media->first());
20
    }
21
22
    /**
23
     * Get the attribute name for the image.
24
     *
25
     * @return string
26
     */
27
    private function getImageAttributeName(): string
28
    {
29
        if (property_exists($this, 'imageAttributeName')) {
30
            return $this->imageAttributeName;
31
        }
32
33
        return 'image';
34
    }
35
}
36