Nav   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 33
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A items() 0 12 3
A render() 0 3 1
A __construct() 0 4 1
1
<?php
2
declare(strict_types=1);
3
4
namespace Thinktomorrow\Chief\App\View\Components;
5
6
use Illuminate\Support\Collection;
7
use Illuminate\View\Component;
8
use Thinktomorrow\Chief\Admin\Nav\Nav as NavItems;
9
10
final class Nav extends Component
11
{
12
    public ?string $title;
13
14
    /** @var NavItems */
15
    private NavItems $nav;
16
17
    public function __construct(NavItems $nav, ?string $title = null)
18
    {
19
        $this->title = $title;
20
        $this->nav = $nav;
21
    }
22
23
    /**
24
     * @return \Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
25
     */
26
    public function render()
27
    {
28
        return view('chief::components.nav.index');
29
    }
30
31
    public function items(): Collection
32
    {
33
        // Attribute bag is filled at moment of method call (inside the component view)
34
        if ($this->attributes->has('untagged')) {
35
            return collect($this->nav->untagged()->all());
0 ignored issues
show
Bug introduced by
$this->nav->untagged()->all() of type array is incompatible with the type Illuminate\Contracts\Support\Arrayable expected by parameter $value of collect(). ( Ignorable by Annotation )

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

35
            return collect(/** @scrutinizer ignore-type */ $this->nav->untagged()->all());
Loading history...
36
        }
37
38
        if ($this->attributes->has('tagged')) {
39
            return collect($this->nav->tagged(explode(',', $this->attributes->get('tagged')))->all());
0 ignored issues
show
Bug introduced by
It seems like $this->attributes->get('tagged') can also be of type null; however, parameter $string of explode() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

39
            return collect($this->nav->tagged(explode(',', /** @scrutinizer ignore-type */ $this->attributes->get('tagged')))->all());
Loading history...
40
        }
41
42
        return collect($this->nav->all());
43
    }
44
}
45