Completed
Push — master ( b72a1b...c69b4e )
by Peter
07:49
created

PaginationExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

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