DisplayRule::canDisplay()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

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