Passed
Push — shop ( c2aba6...5180ff )
by Fèvre
04:54
created

ShopItemPresenter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
dl 0
loc 33
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getItemIconAttribute() 0 3 1
A parseMedia() 0 7 2
1
<?php
2
namespace Xetaravel\Models\Presenters;
3
4
trait ShopItemPresenter
5
{
6
    /**
7
     * The default banner used when there is no banner for the item.
8
     *
9
     * @var string
10
     */
11
    protected string $defaultIcon = '/images/shop/default_icon.svg';
12
13
    /**
14
     * Get the icon.
15
     *
16
     * @return string
17
     */
18
    public function getItemIconAttribute(): string
19
    {
20
        return $this->parseMedia('item.icon');
21
    }
22
23
    /**
24
     * Parse a media and return it if isset or return the default banner.
25
     *
26
     * @param string $type The type of the media to get.
27
     *
28
     * @return string
29
     */
30
    protected function parseMedia(string $type): string
31
    {
32
        if (isset($this->getMedia('item')[0])) {
0 ignored issues
show
Bug introduced by
It seems like getMedia() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        if (isset($this->/** @scrutinizer ignore-call */ getMedia('item')[0])) {
Loading history...
33
            return $this->getMedia('item')[0]->getUrl($type);
34
        }
35
36
        return $this->defaultIcon;
37
    }
38
}
39