Passed
Push — master ( 6834ea...3ef1e7 )
by Tomasz
02:24
created

ConditionalStrategy::shouldBeApplied()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace Hop\Validator\Strategy\StructureField;
6
7
use Hop\Validator\Strategy\Strategy;
8
9
/**
10
 * Class ConditionalStrategy
11
 * @package Hop\Validator\Strategy\StructureField
12
 */
13
final class ConditionalStrategy
14
{
15
    /**
16
     * @var Strategy
17
     */
18
    private $strategy;
19
20
    /**
21
     * @var callable
22
     */
23
    private $condition;
24
25
    /**
26
     * ConditionalStrategy constructor.
27
     * @param Strategy $strategy
28
     * @param callable $condition
29
     */
30 2
    public function __construct(
31
        Strategy $strategy,
32
        callable $condition
33
    ) {
34 2
        $this->strategy = $strategy;
35 2
        $this->condition = $condition;
36 2
    }
37
38
    /**
39
     * @return Strategy
40
     */
41 1
    public function strategy(): Strategy
42
    {
43 1
        return $this->strategy;
44
    }
45
46
47
    /**
48
     * @param mixed $data
49
     * @return bool
50
     */
51 2
    public function shouldBeApplied($data): bool
52
    {
53 2
        return ($this->condition)($data) === true;
54
    }
55
}
56