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

SubSpec   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 65
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 65
ccs 0
cts 13
cp 0
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 6 1
A filter() 0 4 1
A getDefaultMessage() 0 6 1
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