Completed
Push — master ( 2d8113...25118b )
by Peter
02:55
created

PaginationExtension::render()   A

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