Passed
Push — master ( 71234a...e5baf6 )
by Jhao
01:45
created

LanguageCondition::apply()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
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 1
dl 0
loc 5
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 LanguageCondition implements Condition
21
{
22
    /** @var string */
23
    private $language;
24
25
    /** @var callable */
26
    private $callback;
27
28 1
    public function __construct(string $language, callable $callback)
29
    {
30 1
        $this->language = $language;
31 1
        $this->callback = $callback;
32 1
    }
33
34 1
    public function isMatch(string $language): bool
35
    {
36 1
        return $this->language === $language;
37
    }
38
39 1
    public function apply(LabelContract $label): LabelContract
40
    {
41 1
        \call_user_func($this->callback, $label);
42
43 1
        return $label;
44
    }
45
}
46