Completed
Pull Request — master (#217)
by Alain
07:00
created

Template   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Test Coverage

Coverage 83.33%

Importance

Changes 0
Metric Value
wmc 10
lcom 2
cbo 0
dl 0
loc 55
ccs 20
cts 24
cp 0.8333
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A setRouteGenerator() 0 4 1
A setOptions() 0 4 1
A getOptions() 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 42
    public function __construct()
25
    {
26 42
        $this->initializeOptions();
27 42
    }
28
29 42
    public function setRouteGenerator($routeGenerator)
30
    {
31 42
        $this->routeGenerator = $routeGenerator;
32 42
    }
33
34 42
    public function setOptions(array $options)
35
    {
36 42
        $this->options = array_merge($this->options, $options);
37 42
    }
38
39
    public function getOptions()
40
    {
41
        return $this->options;
42
    }
43
    
44 42
    private function initializeOptions()
45
    {
46 42
        $this->options = static::$defaultOptions;
47 42
    }
48
49 42
    protected function generateRoute($page)
50
    {
51 42
        return call_user_func($this->getRouteGenerator(), $page);
52
    }
53
54 42
    private function getRouteGenerator()
55
    {
56 42
        if (!$this->routeGenerator) {
57
            throw new \RuntimeException('There is no route generator.');
58
        }
59
60 42
        return $this->routeGenerator;
61
    }
62
63 42
    protected function option($name)
64
    {
65 42
        if (!isset($this->options[$name])) {
66
            throw new \InvalidArgumentException(sprintf('The option "%s" does not exist.', $name));
67
        }
68
69 42
        return $this->options[$name];
70
    }
71
}
72