Passed
Push — master ( 80923f...9fa0e9 )
by Andrea
16:11
created

TabellaDecoderTrait   A

Complexity

Total Complexity 18

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Test Coverage

Coverage 98.04%

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 91
ccs 50
cts 51
cp 0.9804
rs 10
c 0
b 0
f 0
wmc 18

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getFieldValue() 0 6 2
A getDescrizioneFiltro() 0 4 2
A getOperator() 0 17 4
A generaAlias() 0 22 5
A getAliasGenerato() 0 3 1
A findFieldnameByAlias() 0 10 2
A findAliasByTablename() 0 10 2
1
<?php
2
3
namespace Cdf\BiCoreBundle\Utils\Tabella;
4
5
use Doctrine\Common\Collections\Expr\Comparison;
6
7
trait TabellaDecoderTrait
8
{
9
    private $aliasGenerati;
10
    private $decodificaAlias;
11
12 3
    protected function getDescrizioneFiltro(&$descrizionefiltri, $filtrocorrente, $criteria)
13
    {
14 3
        if (false === $filtrocorrente['prefiltro']) {
15 2
            $descrizionefiltri = $descrizionefiltri.', '.$criteria->getDescrizioneFiltro();
16
        }
17 3
    }
18
19 4
    protected function getFieldValue($fieldvalue)
20
    {
21 4
        if (isset($fieldvalue['date'])) {
22 1
            return new \Datetime($fieldvalue['date']);
23
        } else {
24 4
            return $fieldvalue;
25
        }
26
    }
27
28 4
    protected function getOperator($operator)
29
    {
30 4
        switch (strtoupper($operator)) {
31 4
            case 'LIKE':
32 1
                $operator = Comparison::CONTAINS;
33 1
                break;
34 4
            case 'IN':
35 1
                $operator = Comparison::IN;
36 1
                break;
37 4
            case 'NOT IN':
38 1
                $operator = Comparison::NIN;
39 1
                break;
40
            default:
41 4
                break;
42
        }
43
44 4
        return $operator;
45
    }
46
47 12
    protected function generaAlias($nometabella, $nomepadre = false, $ancestors = array())
48
    {
49 12
        $nometabellapulito = preg_replace('/[^a-z0-9\.]/i', '', $nometabella);
50 12
        $primalettera = strtolower(substr($nometabellapulito, 0, 1));
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
51 12
        if ($nomepadre && !in_array($nomepadre, $ancestors)) {
52
            $ancestors[] = $nomepadre;
53
        }
54 12
        if (!in_array($nometabella, $ancestors)) {
55 12
            $ancestors[] = $nometabella;
56
        }
57
58 12
        if (isset($this->aliasGenerati[$primalettera])) {
59 3
            $risposta = $primalettera.$this->aliasGenerati[$primalettera];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 27 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
60 3
            $this->aliasGenerati[$primalettera] = $this->aliasGenerati[$primalettera] + 1;
61
        } else {
62 12
            $risposta = $primalettera;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 27 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
63 12
            $this->aliasGenerati[$primalettera] = 1;
64
        }
65
66 12
        $this->decodificaAlias[ucfirst(implode('.', $ancestors))] = array('alias' => $risposta);
67
68 12
        return $risposta;
69
    }
70
71 4
    protected function findAliasByTablename($tablename)
72
    {
73 4
        if (!array_key_exists($tablename, $this->decodificaAlias)) {
74 1
            $ex = 'BiCore: table or association '.$tablename." not found, did you mean one of these:\n".
75 1
                    implode("\n", array_keys($this->decodificaAlias)).
76 1
                    ' ?';
77 1
            throw new \Exception($ex);
78
        }
79
80 4
        return $this->getAliasGenerato($tablename);
81
    }
82
83 4
    protected function findFieldnameByAlias($nomecampo)
84
    {
85 4
        if (!array_key_exists($nomecampo, $this->configurazionecolonnetabella)) {
86 1
            $ex = 'BiCore: field or association '.$nomecampo." not found, did you mean one of these:\n".
87 1
                    implode("\n", array_keys($this->configurazionecolonnetabella)).
88 1
                    ' ?';
89 1
            throw new \Exception($ex);
90
        }
91
92 3
        return $this->configurazionecolonnetabella[$nomecampo];
93
    }
94
95 10
    public function getAliasGenerato($tablename)
96
    {
97 10
        return $this->decodificaAlias[$tablename]['alias'];
98
    }
99
}
100