Completed
Push — master ( 723848...f6a9f3 )
by Yaro
05:45
created

Crumb::showOnlyOnEditPage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 7
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
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
13
    public function __construct($title = '', $url = '')
14
    {
15
        $this->url = $url;
16
        $this->title = $title;
17
    }
18
19
    public static function make($title = '', $url = '')
20
    {
21
        return new static($title, $url);
22
    }
23
24
    public function title($title)
25
    {
26
        $this->title = $title;
27
28
        return $this;
29
    }
30
31
    public function url($url)
32
    {
33
        $this->url = $url;
34
35
        return $this;
36
    }
37
38 View Code Duplication
    public function getTitle($model = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
39
    {
40
        $callback = $this->title;
41
        if (is_callable($callback)) {
42
            return $callback($model);
43
        }
44
        return $this->title;
45
    }
46
47 View Code Duplication
    public function getUrl($model = null)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
48
    {
49
        $callback = $this->url;
50
        if (is_callable($callback)) {
51
            return $callback($model);
52
        }
53
        return $this->url;
54
    }
55
56
    public function showOnListPage(bool $shouldBeShown = true)
57
    {
58
        $this->shouldBeShownOnListPage = $shouldBeShown;
59
60
        return $this;
61
    }
62
63
    public function showOnCreatePage(bool $shouldBeShown = true)
64
    {
65
        $this->shouldBeShownOnCreatePage = $shouldBeShown;
66
67
        return $this;
68
    }
69
70
    public function showOnEditPage(bool $shouldBeShown = true)
71
    {
72
        $this->shouldBeShownOnEditPage = $shouldBeShown;
73
74
        return $this;
75
    }
76
77
    public function showOnlyOnListPage()
78
    {
79
        $this->showOnListPage(true);
80
        $this->showOnCreatePage(false);
81
        $this->showOnEditPage(false);
82
83
        return $this;
84
    }
85
86
    public function showOnlyOnCreatePage()
87
    {
88
        $this->showOnListPage(false);
89
        $this->showOnCreatePage(true);
90
        $this->showOnEditPage(false);
91
92
        return $this;
93
    }
94
95
    public function showOnlyOnEditPage()
96
    {
97
        $this->showOnListPage(false);
98
        $this->showOnCreatePage(false);
99
        $this->showOnEditPage(true);
100
101
        return $this;
102
    }
103
104
    public function shouldBeShownOnEditPage(): bool
105
    {
106
        return $this->shouldBeShownOnEditPage;
107
    }
108
109
    public function shouldBeShownOnCreatePage(): bool
110
    {
111
        return $this->shouldBeShownOnCreatePage;
112
    }
113
114
    public function shouldBeShownOnListPage(): bool
115
    {
116
        return $this->shouldBeShownOnListPage;
117
    }
118
}
119