Completed
Push — 3.x ( 664d3e...80a626 )
by Hari
11s
created

SubSpec::getDefaultMessage()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 0
cts 4
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
crap 2
1
<?php
2
/**
3
 * This file is part of Aura for PHP.
4
 *
5
 * @license http://opensource.org/licenses/bsd-license.php BSD
6
 *
7
 */
8
9
namespace Aura\Filter\Spec;
10
11
use Aura\Filter\SubjectFilter;
12
13
/**
14
 * A specification for a "sub" subject
15
 *
16
 * @package Aura.Filter
17
 *
18
 */
19
class SubSpec extends Spec
20
{
21
    /**
22
     * Subject Filter
23
     *
24
     * @var SubjectFitler
25
     *
26
     * @access protected
27
     */
28
    protected $filter;
29
30
    /**
31
     * __construct
32
     *
33
     * @param SubjectFilter $filter The filter to apply to the sub subject
34
     *
35
     * @access public
36
     */
37
    public function __construct(SubjectFilter $filter)
38
    {
39
        $this->filter = $filter;
0 ignored issues
show
Documentation Bug introduced by
It seems like $filter of type object<Aura\Filter\SubjectFilter> is incompatible with the declared type object<Aura\Filter\Spec\SubjectFitler> of property $filter.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40
    }
41
42
    /**
43
     * Apply sub filter to sub subject
44
     *
45
     * @param mixed $subject parent subject
46
     *
47
     * @return bool
48
     *
49
     * @access public
50
     */
51
    public function __invoke($subject)
52
    {
53
        $field = $this->field;
54
        $values =& $subject->$field;
55
        return $this->filter->apply($values);
56
    }
57
58
    /**
59
     * Get the Subject filter
60
     *
61
     * @return SubjectFilter
62
     *
63
     * @access public
64
     */
65
    public function filter()
66
    {
67
        return $this->filter;
68
    }
69
70
    /**
71
     * Returns the default failure message for this rule specification.
72
     *
73
     * @return array
74
     *
75
     * @access protected
76
     */
77
    protected function getDefaultMessage()
78
    {
79
        return $this->filter
80
            ->getFailures()
81
            ->getMessages();
82
    }
83
}
84