Completed
Push — master ( 7a35bc...7eff79 )
by Krzysztof
05:49 queued 02:58
created

NamedCriteriaCollection::getNamedCriteria()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
ccs 4
cts 4
cp 1
cc 2
eloc 4
nc 2
nop 1
crap 2
1
<?php
2
3
namespace KGzocha\Searcher\Criteria\Collection;
4
5
use KGzocha\Searcher\Criteria\CriteriaInterface;
6
7
/**
8
 * @author Krzysztof Gzocha <[email protected]>
9
 */
10
class NamedCriteriaCollection extends CriteriaCollection implements
11
    NamedCriteriaCollectionInterface
12
{
13
    /**
14
     * @param string $name
15
     *
16
     * @return null|CriteriaInterface
17
     */
18 1
    public function __get($name)
19
    {
20 1
        return $this->getNamedCriteria($name);
21
    }
22
23
    /**
24
     * @param string                 $name
25
     * @param CriteriaInterface $value
26
     */
27 1
    public function __set($name, CriteriaInterface $value)
28
    {
29 1
        $this->addNamedCriteria($name, $value);
30 1
    }
31
32
    /**
33
     * @param string                 $name
34
     * @param CriteriaInterface $filterModel
35
     *
36
     * @return $this
37
     */
38 2
    public function addNamedCriteria(
39
        $name,
40
        CriteriaInterface $filterModel
41
    ) {
42 2
        $this->criteria[$name] = $filterModel;
43
44 2
        return $this;
45
    }
46
47
    /**
48
     * @param string $name
49
     *
50
     * @return null|CriteriaInterface
51
     */
52 1
    public function getNamedCriteria($name)
53
    {
54 1
        return array_key_exists($name, $this->criteria)
55 1
            ? $this->criteria[$name]
56 1
            : null;
57
    }
58
}
59