PaginationExtension::renderPagination()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 14
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
cc 2
eloc 10
nc 1
nop 4
crap 2
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
10
namespace AnimeDb\Bundle\PaginationBundle\Twig\Extension;
11
12
use AnimeDb\Bundle\PaginationBundle\Service\Configuration;
13
14
class PaginationExtension extends \Twig_Extension
15
{
16
    /**
17
     * @var string
18
     */
19
    protected $template = '';
20
21
    /**
22
     * @param string $template
23
     */
24 5
    public function __construct($template)
25
    {
26 5
        $this->template = $template;
27 5
    }
28
29
    /**
30
     * @return array
31
     */
32 1
    public function getFunctions()
33
    {
34
        return [
35 1
            new \Twig_SimpleFunction(
36 1
                'pagination_render',
37 1
                [$this, 'renderPagination'],
38 1
                ['is_safe' => ['html'], 'needs_environment' => true]
39 1
            ),
40 1
        ];
41
    }
42
43
    /**
44
     * @param \Twig_Environment $env
45
     * @param Configuration $pagination
46
     * @param string $template
47
     * @param array $view_params
48
     *
49
     * @return string
50
     */
51 3
    public function renderPagination(
52
        \Twig_Environment $env,
53
        Configuration $pagination,
54
        $template = null,
55
        array $view_params = []
56
    ) {
57 3
        return $env->render(
58 3
            $template ?: $this->template,
59 3
            array_merge(
60 3
                $view_params,
61 3
                ['pagination' => $pagination->getView()]
62 3
            )
63 3
        );
64
    }
65
66
    /**
67
     * @return string
68
     */
69 1
    public function getName()
70
    {
71 1
        return 'anime_db_pagination_extension';
72
    }
73
}
74