DisplayRule   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 32
rs 10
c 0
b 0
f 0
ccs 7
cts 7
cp 1
wmc 3
lcom 1
cbo 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A canDisplay() 0 8 2
A setDisplayRule() 0 4 1
1
<?php
2
namespace Malezha\Menu\Traits;
3
4
/**
5
 * Class DisplayRule
6
 * @package Malezha\Menu\Traits
7
 */
8
trait DisplayRule
9
{
10
    /**
11
     * @var bool|callable
12
     */
13
    protected $displayRule = true;
14
15
    /**
16
     * Set boolean or callback, witch return boolean to determine whether to display or not this item.
17
     * Callback will be called each time rendering item.
18
     *
19
     * @param bool|callable $rule
20
     */
21 27
    public function setDisplayRule($rule)
22
    {
23 27
        $this->displayRule = $rule;
24 27
    }
25
26
    /**
27
     * The element should be rendered?
28
     *
29
     * @return bool
30
     */
31 13
    public function canDisplay()
32
    {
33 13
        if (is_callable($this->displayRule)) {
34 1
            return (bool) call_user_func($this->displayRule);
35
        }
36
        
37 13
        return (bool) $this->displayRule;
38
    }
39
}