TwitterBootstrapTemplate   A
last analyzed

Complexity

Total Complexity 19

Size/Duplication

Total Lines 130
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 19
lcom 1
cbo 1
dl 0
loc 130
ccs 53
cts 53
cp 1
rs 10
c 0
b 0
f 0

16 Methods

Rating   Name   Duplication   Size   Complexity  
A container() 0 6 1
A page() 0 6 1
A pageWithText() 0 6 1
A pageWithTextAndClass() 0 6 1
A previousDisabled() 0 7 1
A previousDisabledClass() 0 4 1
A previousEnabled() 0 8 1
A nextDisabled() 0 7 1
A nextDisabledClass() 0 4 1
A nextEnabled() 0 8 1
A first() 0 4 1
A last() 0 4 1
A current() 0 7 1
A separator() 0 7 1
A linkLi() 0 7 3
A spanLi() 0 6 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
class TwitterBootstrapTemplate extends Template
18
{
19
    static protected $defaultOptions = array(
20
        'prev_message'        => '&larr; Previous',
21
        'next_message'        => 'Next &rarr;',
22
        'dots_message'        => '&hellip;',
23
        'active_suffix'       => '',
24
        'css_container_class' => 'pagination',
25
        'css_prev_class'      => 'prev',
26
        'css_next_class'      => 'next',
27
        'css_disabled_class'  => 'disabled',
28
        'css_dots_class'      => 'disabled',
29
        'css_active_class'    => 'active',
30
        'rel_previous'        => 'prev',
31
        'rel_next'            => 'next'
32
    );
33
34 11
    public function container()
35
    {
36 11
        return sprintf('<div class="%s"><ul>%%pages%%</ul></div>',
37 11
            $this->option('css_container_class')
38
        );
39
    }
40
41 31
    public function page($page)
42
    {
43 31
        $text = $page;
44
45 31
        return $this->pageWithText($page, $text);
46
    }
47
48 31
    public function pageWithText($page, $text)
49
    {
50 31
        $class = null;
51
52 31
        return $this->pageWithTextAndClass($page, $text, $class);
53
    }
54
55 31
    private function pageWithTextAndClass($page, $text, $class, $rel = null)
56
    {
57 31
        $href = $this->generateRoute($page);
58
59 31
        return $this->linkLi($class, $href, $text, $rel);
60
    }
61
62 6
    public function previousDisabled()
63
    {
64 6
        $class = $this->previousDisabledClass();
65 6
        $text = $this->option('prev_message');
66
67 6
        return $this->spanLi($class, $text);
68
    }
69
70 6
    private function previousDisabledClass()
71
    {
72 6
        return $this->option('css_prev_class').' '.$this->option('css_disabled_class');
73
    }
74
75 25
    public function previousEnabled($page)
76
    {
77 25
        $text = $this->option('prev_message');
78 25
        $class = $this->option('css_prev_class');
79 25
        $rel = $this->option('rel_previous');
80
81 25
        return $this->pageWithTextAndClass($page, $text, $class, $rel);
82
    }
83
84 3
    public function nextDisabled()
85
    {
86 3
        $class = $this->nextDisabledClass();
87 3
        $text = $this->option('next_message');
88
89 3
        return $this->spanLi($class, $text);
90
    }
91
92 3
    private function nextDisabledClass()
93
    {
94 3
        return $this->option('css_next_class').' '.$this->option('css_disabled_class');
95
    }
96
97 28
    public function nextEnabled($page)
98
    {
99 28
        $text = $this->option('next_message');
100 28
        $class = $this->option('css_next_class');
101 28
        $rel = $this->option('rel_next');
102
103 28
        return $this->pageWithTextAndClass($page, $text, $class, $rel);
104
    }
105
106 22
    public function first()
107
    {
108 22
        return $this->page(1);
109
    }
110
111 25
    public function last($page)
112
    {
113 25
        return $this->page($page);
114
    }
115
116 31
    public function current($page)
117
    {
118 31
        $text = trim($page.' '.$this->option('active_suffix'));
119 31
        $class = $this->option('css_active_class');
120
121 31
        return $this->spanLi($class, $text);
122
    }
123
124 31
    public function separator()
125
    {
126 31
        $class = $this->option('css_dots_class');
127 31
        $text = $this->option('dots_message');
128
129 31
        return $this->spanLi($class, $text);
130
    }
131
132 21
    protected function linkLi($class, $href, $text, $rel = null)
133
    {
134 21
        $liClass = $class ? sprintf(' class="%s"', $class) : '';
135 21
        $rel = $rel ? sprintf(' rel="%s"', $rel) : '';
136
137 21
        return sprintf('<li%s><a href="%s"%s>%s</a></li>', $liClass, $href, $rel, $text);
138
    }
139
140 21
    protected function spanLi($class, $text)
141
    {
142 21
        $liClass = $class ? sprintf(' class="%s"', $class) : '';
143
144 21
        return sprintf('<li%s><span>%s</span></li>', $liClass, $text);
145
    }
146
}
147