Completed
Push — master ( 6292d2...03a8c3 )
by Peter
7s
created

PaginationExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.75%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
wmc 5
c 3
b 1
f 1
lcom 1
cbo 4
dl 0
loc 62
ccs 15
cts 16
cp 0.9375
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 10 1
A render() 0 14 2
A getName() 0 4 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/MIT
8
 */
9
namespace AnimeDb\Bundle\PaginationBundle\Twig\Extension;
10
11
use AnimeDb\Bundle\PaginationBundle\Service\Configuration;
12
13
/**
14
 * Class PaginationExtension.
15
 */
16
class PaginationExtension extends \Twig_Extension
17
{
18
    /**
19
     * @var string
20
     */
21
    protected $template = '';
22
23
    /**
24
     * @param string $template
25
     */
26 5
    public function __construct($template)
27
    {
28 5
        $this->template = $template;
29 5
    }
30
31
    /**
32
     * @return array
33
     */
34 1
    public function getFunctions()
35
    {
36
        return [
37
            new \Twig_SimpleFunction(
38 1
                'pagination_render',
39 1
                [$this, 'render'],
40 1
                ['is_safe' => ['html'], 'needs_environment' => true]
41
            ),
42 1
        ];
43
    }
44
45
    /**
46
     * Renders the pagination template.
47
     *
48
     * @param \Twig_Environment $env
49
     * @param Configuration $pagination
50
     * @param string $template
51
     * @param array $view_params
52
     *
53
     * @return string
54
     */
55 3
    public function render(
56
        \Twig_Environment $env,
57
        Configuration $pagination,
58 1
        $template = null,
59 1
        array $view_params = []
60
    ) {
61
        return $env->render(
62 3
            $template ?: $this->template,
63
            array_merge(
64
                $view_params,
65
                ['pagination' => $pagination->getView()]
66
            )
67
        );
68 2
    }
69
70
    /**
71
     * @return string
72
     */
73 1
    public function getName()
74
    {
75 1
        return 'anime_db_pagination_extension';
76
    }
77
}
78