ViewFactory   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 78
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 1
dl 0
loc 78
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A set() 0 4 1
A has() 0 4 1
A add() 0 6 2
A get() 0 8 2
A remove() 0 8 2
A all() 0 4 1
A clear() 0 4 1
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