Completed
Pull Request — master (#34)
by Krzysztof
02:14
created

NamedFilterModelCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 1
dl 0
loc 48
ccs 12
cts 12
cp 1
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __get() 0 4 1
A __set() 0 4 1
A addNamedFilterModel() 0 8 1
A getNamedFilterModel() 0 6 2
1
<?php
2
3
namespace KGzocha\Searcher\FilterModel\Collection;
4
5
use KGzocha\Searcher\FilterModel\FilterModelInterface;
6
7
/**
8
 * @author Krzysztof Gzocha <[email protected]>
9
 * @package KGzocha\Searcher\FilterModel\Collection
10
 */
11
class NamedFilterModelCollection extends FilterModelCollection implements
12
    NamedFilterModelCollectionInterface
13
{
14
    /**
15
     * @param string $name
16
     * @return null|FilterModelInterface
17
     */
18 1
    public function __get($name)
19
    {
20 1
        return $this->getNamedFilterModel($name);
21
    }
22
23
    /**
24
     * @param string $name
25
     * @param FilterModelInterface $value
26
     */
27 1
    public function __set($name, FilterModelInterface $value)
28
    {
29 1
        $this->addNamedFilterModel($name, $value);
30 1
    }
31
32
    /**
33
     * @param string $name
34
     * @param FilterModelInterface $filterModel
35
     *
36
     * @return $this
37
     */
38 2
    public function addNamedFilterModel(
39
        $name,
40
        FilterModelInterface $filterModel
41
    ) {
42 2
        $this->filterModels[$name] = $filterModel;
43
44 2
        return $this;
45
    }
46
47
    /**
48
     * @param string $name
49
     *
50
     * @return null|FilterModelInterface
51
     */
52 1
    public function getNamedFilterModel($name)
53
    {
54 1
        return array_key_exists($name, $this->filterModels)
55 1
            ? $this->filterModels[$name]
56 1
            : null;
57
    }
58
}
59