Completed
Push — master ( 665333...49dc1a )
by Yaro
18:38 queued 08:40
created

Breadcrumbs::isEmptyForHistoryPage()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
ccs 2
cts 2
cp 1
cc 3
nc 3
nop 0
crap 3
1
<?php
2
3
namespace Yaro\Jarboe\ViewComponents\Breadcrumbs;
4
5
class Breadcrumbs implements BreadcrumbsInterface
6
{
7
    private $position = 0;
8
    private $crumbs = [];
9
10 6
    public function add(Crumb $crumb): BreadcrumbsInterface
11
    {
12 6
        array_push($this->crumbs, $crumb);
13
14 6
        return $this;
15
    }
16
17 5
    public function isEmptyForListPage(): bool
18
    {
19
        /** @var Crumb $crumb */
20 5
        foreach ($this->crumbs as $crumb) {
21 4
            if ($crumb->shouldBeShownOnListPage()) {
22 2
                return false;
23
            }
24
        }
25
26 3
        return true;
27
    }
28
29 5
    public function isEmptyForCreatePage(): bool
30
    {
31
        /** @var Crumb $crumb */
32 5
        foreach ($this->crumbs as $crumb) {
33 4
            if ($crumb->shouldBeShownOnCreatePage()) {
34 2
                return false;
35
            }
36
        }
37
38 3
        return true;
39
    }
40
41 5
    public function isEmptyForEditPage(): bool
42
    {
43
        /** @var Crumb $crumb */
44 5
        foreach ($this->crumbs as $crumb) {
45 4
            if ($crumb->shouldBeShownOnEditPage()) {
46 2
                return false;
47
            }
48
        }
49
50 3
        return true;
51
    }
52
53
    public function isEmptyForHistoryPage(): bool
54
    {
55
        /** @var Crumb $crumb */
56
        foreach ($this->crumbs as $crumb) {
57
            if ($crumb->shouldBeShownOnHistoryPage()) {
58
                return false;
59 1
            }
60
        }
61 1
62
        return true;
63
    }
64
65
    /**
66
     * Return the current element
67
     * @link https://php.net/manual/en/iterator.current.php
68
     * @return mixed Can return any type.
69
     * @since 5.0.0
70 1
     */
71
    public function current()
72 1
    {
73 1
        return $this->crumbs[$this->key()];
74
    }
75
76
    /**
77
     * Move forward to next element
78
     * @link https://php.net/manual/en/iterator.next.php
79
     * @return void Any returned value is ignored.
80
     * @since 5.0.0
81 1
     */
82
    public function next()
83 1
    {
84
        $this->position++;
85
    }
86
87
    /**
88
     * Return the key of the current element
89
     * @link https://php.net/manual/en/iterator.key.php
90
     * @return mixed scalar on success, or null on failure.
0 ignored issues
show
Documentation introduced by
Consider making the return type a bit more specific; maybe use integer.

This check looks for the generic type array as a return type and suggests a more specific type. This type is inferred from the actual code.

Loading history...
91
     * @since 5.0.0
92
     */
93 1
    public function key()
94
    {
95 1
        return $this->position;
96
    }
97
98
    /**
99
     * Checks if current position is valid
100
     * @link https://php.net/manual/en/iterator.valid.php
101
     * @return bool The return value will be casted to boolean and then evaluated.
102
     * Returns true on success or false on failure.
103
     * @since 5.0.0
104 1
     */
105
    public function valid()
106 1
    {
107 1
        return isset($this->crumbs[$this->key()]);
108
    }
109
110
    /**
111
     * Rewind the Iterator to the first element
112
     * @link https://php.net/manual/en/iterator.rewind.php
113
     * @return void Any returned value is ignored.
114
     * @since 5.0.0
115
     */
116
    public function rewind()
117
    {
118
        $this->position = 0;
119
    }
120
}
121