Completed
Pull Request — master (#57)
by
unknown
01:32
created

CanHide   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A hideWhen() 0 6 1
A hidden() 0 8 2
1
<?php
2
3
namespace Nwidart\Menus\Traits;
4
5
use Closure;
6
7
trait CanHide
8
{
9
    /**
10
     * @var Closure
11
     */
12
    protected $hideWhen;
13
14
    /**
15
     * Set hide condition for current menu item.
16
     *
17
     * @param  Closure
18
     * @return boolean
19
     */
20
    public function hideWhen(Closure $callback)
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()
33
    {
34
        if (is_null($this->hideWhen)) {
35
            return false;
36
        }
37
38
        return call_user_func($this->hideWhen) == true;
39
    }
40
}
41