AbstractFilter   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 92.86%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 6
c 1
b 0
f 1
lcom 0
cbo 0
dl 0
loc 58
ccs 13
cts 14
cp 0.9286
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 3
A __invoke() 0 14 3
invoke() 0 1 ?
1
<?php
2
namespace TRex\Collection;
3
4
abstract class AbstractFilter
5
{
6
    /**
7
     * @var mixed
8
     */
9
    private $value;
10
11
    /**
12
     * @var bool
13
     */
14
    private $isOneOfTheValues;
15
16
    /**
17
     * @var bool
18
     */
19
    private $isStrict;
20
21
    /**
22
     * @param mixed $value
23
     * @param bool $isOneOfTheValues
24
     * @param bool $isStrict
25
     */
26 5
    public function __construct($value, $isOneOfTheValues = false, $isStrict = true)
27
    {
28 5
        if ($isOneOfTheValues && !is_array($value)) {
29
            throw new \InvalidArgumentException('if $isOneOfTheValues is true, $value must be an array');
30
        }
31
32 5
        $this->value = $value;
33 5
        $this->isOneOfTheValues = $isOneOfTheValues;
34 5
        $this->isStrict = $isStrict;
35 5
    }
36
37
    /**
38
     * @param mixed $object
39
     * @return bool
40
     */
41 5
    public function __invoke($object)
42
    {
43 5
        $value = $this->invoke($object);
44
45 5
        if ($this->isOneOfTheValues) {
46 1
            return in_array($value, $this->value, $this->isStrict);
47
        }
48
49 4
        if ($this->isStrict) {
50 3
            return $value === $this->value;
51
        }
52
53 1
        return $value == $this->value;
54
    }
55
56
    /**
57
     * @param mixed $object
58
     * @return mixed
59
     */
60
    abstract protected function invoke($object);
61
}
62
63