Completed
Branch master (49dc1a)
by Yaro
01:42
created

Crumb   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 148
Duplicated Lines 35.14 %

Coupling/Cohesion

Components 3
Dependencies 0

Test Coverage

Coverage 87.88%

Importance

Changes 0
Metric Value
wmc 20
lcom 3
cbo 0
dl 52
loc 148
ccs 58
cts 66
cp 0.8788
rs 10
c 0
b 0
f 0

18 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A make() 0 4 1
A title() 0 6 1
A url() 0 6 1
A getTitle() 8 8 2
A getUrl() 8 8 2
A showOnListPage() 0 6 1
A showOnCreatePage() 0 6 1
A showOnEditPage() 0 6 1
A showOnHistoryPage() 0 6 1
A showOnlyOnListPage() 9 9 1
A showOnlyOnCreatePage() 9 9 1
A showOnlyOnEditPage() 9 9 1
A showOnlyOnHistoryPage() 9 9 1
A shouldBeShownOnEditPage() 0 4 1
A shouldBeShownOnCreatePage() 0 4 1
A shouldBeShownOnListPage() 0 4 1
A shouldBeShownOnHistoryPage() 0 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace Yaro\Jarboe\ViewComponents\Breadcrumbs;
4
5
class Crumb
6
{
7
    private $url;
8
    private $title;
9
    private $shouldBeShownOnListPage = true;
10
    private $shouldBeShownOnCreatePage = true;
11
    private $shouldBeShownOnEditPage = true;
12
    private $shouldBeShowOnHistoryPage = true;
13
14 9
    public function __construct($title = '', $url = '')
15
    {
16 9
        $this->url = $url;
17 9
        $this->title = $title;
18 9
    }
19
20 9
    public static function make($title = '', $url = '')
21
    {
22 9
        return new static($title, $url);
23
    }
24
25 1
    public function title($title)
26
    {
27 1
        $this->title = $title;
28
29 1
        return $this;
30
    }
31
32 1
    public function url($url)
33
    {
34 1
        $this->url = $url;
35
36 1
        return $this;
37
    }
38
39
    /**
40
     * @param null $model
41
     * @return string
42
     */
43 1 View Code Duplication
    public function getTitle($model = null)
44
    {
45 1
        $callback = $this->title;
46 1
        if (is_callable($callback)) {
47 1
            return $callback($model);
48
        }
49 1
        return $this->title;
50
    }
51
52
    /**
53
     * @param null $model
54
     * @return string
55
     */
56 1 View Code Duplication
    public function getUrl($model = null)
57
    {
58 1
        $callback = $this->url;
59 1
        if (is_callable($callback)) {
60 1
            return $callback($model);
61
        }
62 1
        return $this->url;
63
    }
64
65 4
    public function showOnListPage(bool $shouldBeShown = true)
66
    {
67 4
        $this->shouldBeShownOnListPage = $shouldBeShown;
68
69 4
        return $this;
70
    }
71
72 4
    public function showOnCreatePage(bool $shouldBeShown = true)
73
    {
74 4
        $this->shouldBeShownOnCreatePage = $shouldBeShown;
75
76 4
        return $this;
77
    }
78
79 4
    public function showOnEditPage(bool $shouldBeShown = true)
80
    {
81 4
        $this->shouldBeShownOnEditPage = $shouldBeShown;
82
83 4
        return $this;
84
    }
85
    
86 4
    public function showOnHistoryPage(bool $shouldBeShown = true)
87
    {
88 4
        $this->showOnHistoryPage = $shouldBeShown;
0 ignored issues
show
Bug introduced by
The property showOnHistoryPage does not seem to exist. Did you mean shouldBeShowOnHistoryPage?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
89
90 4
        return $this;
91
    }
92
93 2 View Code Duplication
    public function showOnlyOnListPage()
94
    {
95 2
        $this->showOnListPage(true);
96 2
        $this->showOnCreatePage(false);
97 2
        $this->showOnEditPage(false);
98 2
        $this->showOnHistoryPage(false);
99
100 2
        return $this;
101
    }
102
103 2 View Code Duplication
    public function showOnlyOnCreatePage()
104
    {
105 2
        $this->showOnListPage(false);
106 2
        $this->showOnCreatePage(true);
107 2
        $this->showOnEditPage(false);
108 2
        $this->showOnHistoryPage(false);
109
110 2
        return $this;
111
    }
112
113 2 View Code Duplication
    public function showOnlyOnEditPage()
114
    {
115 2
        $this->showOnListPage(false);
116 2
        $this->showOnCreatePage(false);
117 2
        $this->showOnEditPage(true);
118 2
        $this->showOnHistoryPage(false);
119
120 2
        return $this;
121
    }
122
123 View Code Duplication
    public function showOnlyOnHistoryPage()
124
    {
125
        $this->showOnListPage(false);
126
        $this->showOnCreatePage(false);
127
        $this->showOnEditPage(false);
128
        $this->showOnHistoryPage(true);
129
130
        return $this;
131
    }
132
133 5
    public function shouldBeShownOnEditPage(): bool
134
    {
135 5
        return $this->shouldBeShownOnEditPage;
136
    }
137
138 5
    public function shouldBeShownOnCreatePage(): bool
139
    {
140 5
        return $this->shouldBeShownOnCreatePage;
141
    }
142
143 5
    public function shouldBeShownOnListPage(): bool
144
    {
145 5
        return $this->shouldBeShownOnListPage;
146
    }
147
148
    public function shouldBeShownOnHistoryPage(): bool
149
    {
150
        return $this->shouldBeShowOnHistoryPage;
151
    }
152
}
153