BooleanCondition   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 24
ccs 9
cts 9
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 5 1
A __construct() 0 4 1
A isTruthy() 0 3 1
1
<?php
2
3
/**
4
 * This file is part of PhpAidc LabelPrinter package.
5
 *
6
 * © Appwilio (https://appwilio.com)
7
 * © JhaoDa (https://github.com/jhaoda)
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
declare(strict_types=1);
14
15
namespace PhpAidc\LabelPrinter\Label;
16
17
use PhpAidc\LabelPrinter\Contract\Condition;
18
use PhpAidc\LabelPrinter\Contract\Label as LabelContract;
19
20
final class BooleanCondition implements Condition
21
{
22
    /** @var mixed */
23
    private $value;
24
25
    /** @var callable */
26
    private $callback;
27
28 2
    public function __construct($value, callable $callback)
29
    {
30 2
        $this->value = $value;
31 2
        $this->callback = $callback;
32 2
    }
33
34 2
    public function isTruthy(): bool
35
    {
36 2
        return (bool) $this->value;
37
    }
38
39 1
    public function apply(LabelContract $label): LabelContract
40
    {
41 1
        \call_user_func($this->callback, $label, $this->value);
42
43 1
        return $label;
44
    }
45
}
46