HeaderTabellaExtension::sortClass()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 18
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 0
Metric Value
cc 5
eloc 12
nc 4
nop 2
dl 0
loc 18
ccs 10
cts 10
cp 1
crap 5
rs 9.5555
c 0
b 0
f 0
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