ConditionalStrategy   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 41
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldBeApplied() 0 3 1
A strategy() 0 3 1
A __construct() 0 6 1
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