Passed
Push — master ( 762047...d9abc4 )
by Andrea
19:59 queued 13s
created

GrigliaFiltriUtils   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Test Coverage

Coverage 94.87%

Importance

Changes 0
Metric Value
wmc 10
dl 0
loc 61
ccs 37
cts 39
cp 0.9487
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B traduciFiltri() 0 31 5
B getFiltrodescritto() 0 18 5
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 2
    public static function getFiltrodescritto($filtri, $tipofiltro)
49
    {
50 2
        $filtrodescritto = ('I dati mostrati rispondono a' . ($tipofiltro == 'AND' ? ' tutti i' : 'd almeno uno dei') . ' seguenti criteri: ');
51
52 2
        foreach ($filtri as $indice => $filtro) {
53 2
            $campo = $filtro->field;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 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...
54 2
            $operatore = $filtro->op;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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
            $data = $filtro->data;
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...
56 2
            $strtipofiltro = ($indice !== 0 ? ($tipofiltro == 'AND' ? ' e ' : ' o ') : '');
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 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
            $strcampo = GrigliaUtils::toCamelCase(array('str' => $campo, 'primamaiuscola' => true));
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...
58 2
            $stroperatore = GrigliaUtils::$decodificaop[$operatore];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
59 2
            $strdata = "\"$data\"";
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 9 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...
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
            $filtrodescritto = sprintf("%s%s%s%s%s", $filtrodescritto, $strtipofiltro, $strcampo, $stroperatore, $strdata);
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal %s%s%s%s%s does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
61 2
        }
62
63 2
        $filtrodescritto .= '.';
64
65 2
        return $filtrodescritto;
66
    }
67
}
68