BooleanCondition::__construct()   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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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