Completed
Push — refactoring ( 84ac1f...ab1ebc )
by Oleg
04:25
created

Item   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 62
wmc 6
lcom 1
cbo 6
ccs 17
cts 17
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 2
A getLink() 0 4 1
A buildAttributes() 0 8 2
A isActive() 0 7 1
1
<?php
2
3
namespace Malezha\Menu\Entity;
4
5
use Malezha\Menu\Traits\DisplayRule;
6
use Malezha\Menu\Traits\HasAttributes;
7
use Malezha\Menu\Traits\IsUrlEqual;
8
9
class Item
10
{
11
    use HasAttributes, DisplayRule, IsUrlEqual;
12
13
    /**
14
     * @var Link
15
     */
16
    protected $link;
17
18
    /**
19
     * @var Builder
20
     */
21
    protected $builder;
22
23
    /**
24
     * @param Builder $builder
25
     * @param string $name
26
     * @param array $attributes
27
     * @param string $title
28
     * @param string $url
29
     * @param array $linkAttributes
30
     */
31 10
    function __construct(Builder $builder, $name, $attributes = [], $title = '', $url = '#', $linkAttributes = [])
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
32
    {
33 10
        $title = empty($title) ? $name : $title;
34 10
        $this->builder = $builder;
35 10
        $this->attributes = new Attributes($attributes);
36 10
        $this->link = new Link($title, $url, $linkAttributes);
37 10
    }
38
39
    /**
40
     * @return Link
41
     */
42 5
    public function getLink()
43
    {
44 5
        return $this->link;
45
    }
46
47
    /**
48
     * @param array $attributes
49
     * @return string
50
     */
51 3
    public function buildAttributes($attributes = [])
52
    {
53 3
        $attributes = $this->isActive() ?
54 3
            Attributes::mergeArrayValues($this->builder->activeAttributes()->all(), $attributes) :
55 3
            $attributes;
56
57 3
        return $this->attributes->build($attributes);
58
    }
59
60
    /**
61
     * @return bool
62
     */
63 3
    public function isActive()
64
    {
65 3
        $currentUrl = app('request')->url();
66 3
        $url = url($this->getLink()->getUrl());
67
        
68 3
        return $this->isUrlEqual($url, $currentUrl);
69
    }
70
}