Passed
Pull Request — master (#92)
by Fèvre
13:40 queued 08:22
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
3
namespace Xetaravel\Models\Presenters;
4
5
trait ShopItemPresenter
6
{
7
    /**
8
     * The default banner used when there is no banner for the item.
9
     *
10
     * @var string
11
     */
12
    protected string $defaultIcon = '/images/shop/default_icon.svg';
13
14
    /**
15
     * Get the icon.
16
     *
17
     * @return string
18
     */
19
    public function getItemIconAttribute(): string
20
    {
21
        return $this->parseMedia('item.icon');
22
    }
23
24
    /**
25
     * Parse a media and return it if isset or return the default banner.
26
     *
27
     * @param string $type The type of the media to get.
28
     *
29
     * @return string
30
     */
31
    protected function parseMedia(string $type): string
0 ignored issues
show
Unused Code introduced by
The parameter $type is not used and could be removed. ( Ignorable by Annotation )

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

31
    protected function parseMedia(/** @scrutinizer ignore-unused */ string $type): string

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
32
    {
33
        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

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