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

CanHide   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 32
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hideWhen() 0 5 1
A hidden() 0 7 2
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