Completed
Push — master ( 280bdf...d8eac9 )
by Alexis
10:56
created

ElasticaSorterExtension   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
c 1
b 0
f 1
lcom 1
cbo 4
dl 0
loc 45
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFunctions() 0 13 1
A clearSort() 0 4 1
A displaySort() 0 11 1
A getName() 0 4 1
1
<?php
2
3
namespace Alpixel\Bundle\ElasticaUtilsBundle\Twig\Extension;
4
5
use Alpixel\Bundle\ElasticaUtilsBundle\Services\ElasticaQuerySorter;
6
use Symfony\Component\DependencyInjection\ContainerBuilder;
7
use Symfony\Component\Yaml\Parser;
8
9
class ElasticaSorterExtension extends \Twig_Extension
10
{
11
    protected $sorter;
12
13
    public function __construct(ElasticaQuerySorter $sorter)
14
    {
15
        $this->sorter = $sorter;
16
    }
17
18
    public function getFunctions()
19
    {
20
        return array(
21
            new \Twig_SimpleFunction('elastica_sort', array($this, 'displaySort'), array(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
22
                'is_safe' => array('html'),
23
                'needs_environment' => true
24
            )),
25
            new \Twig_SimpleFunction('elastica_clear_sort', array($this, 'clearSort'), array(
0 ignored issues
show
Deprecated Code introduced by
The class Twig_SimpleFunction has been deprecated with message: to be removed in 3.0

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
26
                'is_safe' => array('html'),
27
                'needs_environment' => true
28
            )),
29
        );
30
    }
31
32
    public function clearSort(\Twig_Environment $twig)
33
    {
34
        return $twig->render('AlpixelElasticaUtilsBundle:blocks:clear_sort.html.twig');
35
    }
36
37
    public function displaySort(\Twig_Environment $twig, $label, $sortKey)
38
    {
39
        $isCurrentSort = ($this->sorter->fetchData('sortBy') == $sortKey);
40
41
        return $twig->render('AlpixelElasticaUtilsBundle:blocks:sort_link.html.twig', array(
42
            'label'     => $label,
43
            'isCurrent' => $isCurrentSort,
44
            'sortKey'   => $sortKey,
45
            'sortOrder' => $this->sorter->fetchData('sortOrder'),
46
        ));
47
    }
48
49
    public function getName()
50
    {
51
        return 'alpixel_elastica_sorter_extension';
52
    }
53
}
54