ViewFactory::get()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the Pagerfanta package.
5
 *
6
 * (c) Pablo Díez <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Pagerfanta\View;
13
14
use Pagerfanta\Exception\InvalidArgumentException;
15
16
/**
17
 * ViewFactory.
18
 *
19
 * @author Pablo Díez <[email protected]>
20
 */
21
class ViewFactory implements ViewFactoryInterface
22
{
23
    private $views;
24
25
    /**
26
     * Constructor.
27
     */
28 1
    public function __construct()
29
    {
30 1
        $this->views = array();
31 1
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36 1
    public function set($name, ViewInterface $view)
37
    {
38 1
        $this->views[$name] = $view;
39 1
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44 1
    public function has($name)
45
    {
46 1
        return isset($this->views[$name]);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52 1
    public function add(array $views)
53
    {
54 1
        foreach ($views as $name => $view) {
55 1
            $this->set($name, $view);
56
        }
57 1
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    public function get($name)
63
    {
64 1
        if (!$this->has($name)) {
65 1
            throw new InvalidArgumentException(sprintf('The view "%s" does not exist.', $name));
66
        }
67
68 1
        return $this->views[$name];
69
    }
70
71
    /**
72
     * {@inheritdoc}
73
     */
74 1
    public function remove($name)
75
    {
76 1
        if (!$this->has($name)) {
77 1
            throw new InvalidArgumentException(sprintf('The view "%s" does not exist.', $name));
78
        }
79
80 1
        unset($this->views[$name]);
81 1
    }
82
83
    /**
84
     * {@inheritdoc}
85
     */
86 1
    public function all()
87
    {
88 1
        return $this->views;
89
    }
90
91
    /**
92
     * {@inheritdoc}
93
     */
94 1
    public function clear()
95
    {
96 1
        $this->views = array();
97 1
    }
98
}
99