HasMedia::getImageAttributeName()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 7
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 0
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