Template   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 90.91%

Importance

Changes 0
Metric Value
dl 0
loc 50
c 0
b 0
f 0
wmc 9
lcom 2
cbo 0
ccs 20
cts 22
cp 0.9091
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setRouteGenerator() 0 4 1
A setOptions() 0 4 1
A initializeOptions() 0 4 1
A generateRoute() 0 4 1
A getRouteGenerator() 0 8 2
A option() 0 8 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\Template;
13
14
/**
15
 * @author Pablo Díez <[email protected]>
16
 */
17
abstract class Template implements TemplateInterface
18
{
19
    protected static $defaultOptions = array();
20
21
    private $routeGenerator;
22
    private $options;
23
24 52
    public function __construct()
25
    {
26 52
        $this->initializeOptions();
27 52
    }
28
29 52
    public function setRouteGenerator($routeGenerator)
30
    {
31 52
        $this->routeGenerator = $routeGenerator;
32 52
    }
33
34 52
    public function setOptions(array $options)
35
    {
36 52
        $this->options = array_merge($this->options, $options);
37 52
    }
38
39 52
    private function initializeOptions()
40
    {
41 52
        $this->options = static::$defaultOptions;
42 52
    }
43
44 52
    protected function generateRoute($page)
45
    {
46 52
        return call_user_func($this->getRouteGenerator(), $page);
47
    }
48
49 52
    private function getRouteGenerator()
50
    {
51 52
        if (!$this->routeGenerator) {
52
            throw new \RuntimeException('There is no route generator.');
53
        }
54
55 52
        return $this->routeGenerator;
56
    }
57
58 52
    protected function option($name)
59
    {
60 52
        if (!isset($this->options[$name])) {
61
            throw new \InvalidArgumentException(sprintf('The option "%s" does not exist.', $name));
62
        }
63
64 52
        return $this->options[$name];
65
    }
66
}
67