HeaderTabellaExtension   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 15
dl 0
loc 36
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A sortClass() 0 18 5
A getFunctions() 0 4 1
1
<?php
2
3
namespace Cdf\BiCoreBundle\Twig\Extension;
4
5
use Twig\Extension\AbstractExtension;
6
use Twig\TwigFunction;
7
8
class HeaderTabellaExtension extends AbstractExtension
9
{
10
11
    /**
12
     * {@inheritdoc}
13
     */
14 1
    public function getFunctions(): array
15
    {
16 1
        return array(
17 1
            new TwigFunction('sort_class', [$this, 'sortClass']),
18 1
        );
19
    }
20
    /**
21
     *
22
     * @param string $colonneordinamento
23
     * @param array<mixed> $modellocampo
24
     * @return string
25
     */
26 7
    public function sortClass(string $colonneordinamento, array $modellocampo): string
27
    {
28 7
        if (true === $modellocampo['association'] || true === $modellocampo['campoextra']) {
29 4
            $sorttype = '';
30
        } else {
31 7
            $cursort = json_decode($colonneordinamento, true);
32 7
            if (array_key_exists($modellocampo['nomecampo'], $cursort)) {
33 6
                if ('ASC' == $cursort[$modellocampo['nomecampo']]) {
34 1
                    $sorttype = 'sorting_asc';
35
                } else {
36 6
                    $sorttype = 'sorting_desc';
37
                }
38
            } else {
39 7
                $sorttype = 'sorting';
40
            }
41
        }
42
43 7
        return $sorttype;
44
    }
45
}
46