DisplayRule::setDisplayRule()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
c 0
b 0
f 0
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
}