Passed
Push — master ( 9b3357...4668c8 )
by Andrea
18:03
created

GrigliaFiltriUtils::traduciFiltri()   B

Complexity

Conditions 5
Paths 8

Size

Total Lines 31
Code Lines 24

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 23
CRAP Score 5.0128

Importance

Changes 0
Metric Value
cc 5
eloc 24
nc 8
nop 1
dl 0
loc 31
ccs 23
cts 25
cp 0.92
crap 5.0128
rs 8.439
c 0
b 0
f 0
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
class GrigliaFiltriUtils
6
{
7
    /**
8
     * Funzione alla quale si passano i filtri nel formato gestito da jqGrid e
9
     * che restituisce una stringa che contiene la descrizione in linguaggio
10
     * naturale.
11
     *
12
     * @param array   $parametri
13
     *
14
     * @return string
15
     */
16 2
    public static function traduciFiltri($parametri = array())
17
    {
18 2
        $genericofiltri = $parametri['filtri'];
19
20 2
        $filtri = isset($genericofiltri->rules) ? $genericofiltri->rules : '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 21 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...
21 2
        $tipofiltro = isset($genericofiltri->groupOp) ? $genericofiltri->groupOp : '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 17 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...
22
        GrigliaUtils::$decodificaop = array(
23 2
            'eq' => ' è uguale a ',
24 2
            'ne' => ' è diverso da ',
25 2
            'lt' => ' è inferiore a ',
26 2
            'le' => ' è inferiore o uguale a ',
27 2
            'gt' => ' è maggiore di ',
28 2
            'ge' => ' è maggiore o uguale di ',
29 2
            'bw' => ' comincia con ',
30 2
            'bn' => ' non comincia con ',
31 2
            'in' => ' è uno fra ',
32 2
            'ni' => ' non è uno fra ',
33 2
            'ew' => ' finisce con ',
34 2
            'en' => ' con finisce con ',
35 2
            'cn' => ' contiene ',
36 2
            'nc' => ' non contiene ',
37 2
            'nu' => ' è vuoto',
38 2
            'nn' => ' non è vuoto', );
39
40 2
        if (!isset($filtri) || (!$filtri)) {
41
            return '';
42
        }
43
44 2
        $filtrodescritto = self::getFiltrodescritto($filtri, $tipofiltro);
45
46 2
        return $filtrodescritto;
47
    }
48
49 2
    public static function getFiltrodescritto($filtri, $tipofiltro)
50
    {
51 2
        $filtrodescritto = ('I dati mostrati rispondono a'.($tipofiltro == 'AND' ? ' tutti i' : 'd almeno uno dei').' seguenti criteri: ');
52
53 2
        foreach ($filtri as $indice => $filtro) {
54 2
            $campo = $filtro->field;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
55 2
            $operatore = $filtro->op;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
56 2
            $data = $filtro->data;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 13 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...
57 2
            $filtrodescritto .= ($indice !== 0 ? ($tipofiltro == 'AND' ? ' e ' : ' o ') : '').
58 2
                    GrigliaUtils::toCamelCase(array('str' => $campo, 'primamaiuscola' => true)).
59 2
                    GrigliaUtils::$decodificaop[$operatore]."\"$data\"";
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $data instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
60 2
        }
61
62 2
        $filtrodescritto .= '.';
63
64 2
        return $filtrodescritto;
65
    }
66
}
67