Passed
Pull Request — master (#57)
by Kyle
12:41
created

CanHide::hideWhen()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace KyleMassacre\Menus\Traits;
4
5
use Closure;
6
7
trait CanHide
8
{
9
    /**
10
     * @var Closure
11
     */
12
    protected Closure $hideWhen;
13
14
    /**
15
     * Set hide condition for current menu item.
16
     *
17
     * @param  Closure
18
     * @return self
19
     */
20
    public function hideWhen(Closure $callback): self
21
    {
22
        $this->hideWhen = $callback;
23
24
        return $this;
25
    }
26
27
    /**
28
     * Determine whether the menu item is hidden.
29
     *
30
     * @return boolean
31
     */
32
    public function hidden(): bool
33
    {
34
        if (is_null($this->hideWhen)) {
35
            return false;
36
        }
37
38
        return call_user_func($this->hideWhen) == true;
39
    }
40
}
41