Completed
Push — master ( 09303e...b0f758 )
by
unknown
10s queued 10s
created

InvokableFilterer   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 90
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 3
dl 0
loc 90
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 9 2
A execute() 0 4 1
A getAliases() 0 4 1
A getSpecification() 0 4 1
A withAliases() 0 4 1
A withSpecification() 0 4 1
1
<?php
2
3
namespace TraderInteractive;
4
5
use TraderInteractive\Exceptions\FilterException;
6
7
final class InvokableFilterer implements FiltererInterface
8
{
9
    /**
10
     * @var Filterer
11
     */
12
    private $filterer;
13
14
    /**
15
     * @param FiltererInterface $filterer The base filterer.
16
     */
17
    public function __construct(FiltererInterface $filterer)
18
    {
19
        $this->filterer = $filterer;
0 ignored issues
show
Documentation Bug introduced by
$filterer is of type object<TraderInteractive\FiltererInterface>, but the property $filterer was declared to be of type object<TraderInteractive\Filterer>. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
20
    }
21
22
    /**
23
     * Executes and returns the filtered value.
24
     *
25
     * @param array $value The value to filter.
26
     *
27
     * @return array The filtered value.
28
     *
29
     * @throws FilterException Thrown if an error is encountered during filtering.
30
     */
31
    public function __invoke(array $value) : array
32
    {
33
        $filterResponse = $this->filterer->execute($value);
34
        if ($filterResponse->success === false) {
35
            throw new FilterException($filterResponse->errorMessage);
36
        }
37
38
        return $filterResponse->filteredValue;
39
    }
40
41
    /**
42
     * @param mixed $input The input to filter.
43
     *
44
     * @return FilterResponse
45
     *
46
     * @see FiltererInterface::execute
47
     */
48
    public function execute(array $input) : FilterResponse
49
    {
50
        return $this->filterer->execute($input);
51
    }
52
53
    /**
54
     * @return array
55
     *
56
     * @see FiltererInterface::getAliases
57
     */
58
    public function getAliases() : array
59
    {
60
        return $this->filterer->getAliases();
61
    }
62
63
    /**
64
     * @return array
65
     *
66
     * @see FiltererInterface::getSpecification
67
     */
68
    public function getSpecification() : array
69
    {
70
        return $this->filterer->getSpecification();
71
    }
72
73
    /**
74
     * @param array $filterAliases
75
     *
76
     * @return FiltererInterface
77
     *
78
     * @see FiltererInterface::withAliases
79
     */
80
    public function withAliases(array $filterAliases) : FiltererInterface
81
    {
82
        return $this->filterer->withAliases($filterAliases);
83
    }
84
85
    /**
86
     * @param array $specification
87
     *
88
     * @return FiltererInterface
89
     *
90
     * @see FiltererInterface::withSpecification
91
     */
92
    public function withSpecification(array $specification) : FiltererInterface
93
    {
94
        return $this->filterer->withSpecification($specification);
95
    }
96
}
97