Passed
Push — master ( d9abc4...b424d1 )
by Andrea
17:14
created

precondizioniToPrecondizioniAvanzate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3.0416

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 10
cts 12
cp 0.8333
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 3
crap 3.0416
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
use Fi\CoreBundle\Controller\FiUtilita;
6
7
class GrigliaDatiPrecondizioniUtils
8
{
9
10 5
    public static function setPrecondizioni(&$q, $parametri = array())
11
    {
12 5
        $request = $parametri['request'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 15 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...
13 5
        $precondizioniAvanzate = GrigliaDatiPrecondizioniUtils::mergePrecondizioni($parametri);
14 5
        $doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 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...
15 5
        $bundle = $parametri['nomebundle'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 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...
16 5
        $nometabella = $parametri['nometabella'];
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...
17 5
        $entityName = $bundle . ':' . $nometabella;
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...
18 5
        $regoleprecondizioni = array();
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...
19 5
        $filtri = json_decode($request->get('filters'), true);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 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...
20
        /* dal filtro prende il tipo di operatore (AND o OR sono i due fin qui gestiti) */
21 5
        $operatorelogicofiltrigriglia = $filtri['groupOp'];
22
        /* prende un vettore con tutte le ricerche */
23 5
        $regolegriglia = isset($filtri['rules']) ? $filtri['rules'] : array();
24 5
        foreach ($precondizioniAvanzate as $elem) {
25 4
            $nometabellaprecondizione = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
26 4
            $nomecampoprecondizione = '';
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...
27 4
            $valorecampoprecondizione = '';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
28 4
            $operatoreprecondizione = '=';
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...
29 4
            $operatorelogicoprecondizione = '';
30 4
            foreach ($elem as $keypre => $valuepre) {
31
                switch ($keypre) {
32 4
                    case 'nometabella':
33 4
                        $nometabellaprecondizione = $valuepre;
34 4
                        break;
35 4
                    case 'nomecampo':
36 4
                        $nomecampoprecondizione = $valuepre;
37 4
                        break;
38 4
                    case 'operatore':
39 4
                        $array_operatori = array('=' => 'eq', '<>' => 'ne', '<' => 'lt',
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...
40 4
                            '<=' => 'le', '>' => 'gt', '>=' => 'ge',
41 4
                            'LIKE' => 'bw', 'NOT LIKE' => 'bn', 'IN' => 'in', 'NOT IN' => 'ni',
42 4
                            'LIKE' => 'eq', 'NOT LIKE' => 'en',
43 4
                            'LIKE' => 'cn', 'NOT LIKE' => 'nc', 'IS' => 'nu', 'IS NOT' => 'nn');
44 4
                        $operatoreprecondizione = $array_operatori[strtoupper($valuepre)];
45 4
                        break;
46 4
                    case 'valorecampo':
47 4
                        if (is_array($valuepre)) {
48 1
                            $type = $doctrine->getClassMetadata($entityName)->getFieldMapping($nomecampoprecondizione);
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...
49 1
                            $valorecampoprecondizione = self::elaboravalorecampo($type, $valuepre);
50 1
                        } else {
51 4
                            $valorecampoprecondizione = $valuepre;
52
                        }
53 4
                        break;
54 1
                    case 'operatorelogico':
55 1
                        $operatorelogicoprecondizione = strtoupper($valuepre);
56 1
                        break;
57
                    default:
58
                        break;
59
                }
60 4
            }
61
62 4
            $regoleprecondizioni[] = array(
63 4
                'field' => sprintf("%s.%s", $nometabellaprecondizione, $nomecampoprecondizione),
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal %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...
64 4
                'op' => $operatoreprecondizione,
65 4
                'data' => $valorecampoprecondizione,
66 4
                'typof' => $operatorelogicoprecondizione);
67 5
        }
68
69 5
        $regolefiltri = array_merge($regoleprecondizioni, $regolegriglia);
70
71 5
        self::setOperatoreLogicoGlobale($regolefiltri, $operatorelogicofiltrigriglia);
72
73
        /**/
74
        $regole = array(
75 5
            'regole' => $regolefiltri,
76 5
            'doctrine' => $doctrine,
77 5
            'nometabella' => $nometabella,
78 5
            'entityName' => $entityName,
79
            'bundle' => $bundle
80 5
        );
81
82 5
        GrigliaRegoleUtils::setRegole($q, $regole);
83 5
    }
84
85 5
    private static function setOperatoreLogicoGlobale(&$regolefiltri, $operatorelogicofiltrigriglia)
86
    {
87 5
        $operatore = 'AND';
88 5
        if ($operatorelogicofiltrigriglia == 'OR') {
89 1
            $operatore = 'OR';
90 1
        } else {
91
            //Se c'è anche una sola condizione in OR, diventano tutte in OR
92 5
            foreach (array_keys($regolefiltri) as $key) {
93 4
                if (isset($regolefiltri[$key]["typof"]) && $regolefiltri[$key]["typof"] == 'OR') {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal typof 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...
94 1
                    $operatore = 'OR';
95 1
                    break;
96
                }
97 5
            }
98
        }
99 5
        foreach (array_keys($regolefiltri) as $key) {
100 4
            $regolefiltri[$key]["typof"] = $operatore;
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal typof 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...
101 5
        }
102 5
    }
103
104 1
    private static function elaboravalorecampo($type, $valuepre)
105
    {
106 1
        $tipo = $type['type'];
107 1
        if ($tipo && ($tipo == 'date' || $tipo == 'datetime')) {
108
            GrigliaUtils::setVettoriPerData();
109
            foreach ($valuepre as $chiave => $valore) {
110
                $valuepre[$chiave] = FiUtilita::data2db($valore);
111
            }
112
            return implode(', ', $valuepre);
113 1
        } elseif ($tipo && $tipo == 'string') {
114 1
            GrigliaUtils::setVettoriPerStringa();
115 1
            foreach ($valuepre as $chiave => $valore) {
116 1
                $valuepre[$chiave] = strtolower($valore);
117 1
            }
118 1
            return implode(', ', $valuepre);
119
        } else {
120 1
            GrigliaUtils::setVettoriPerNumero();
121 1
            return implode(', ', $valuepre);
122
        }
123
    }
124
125 5
    public static function mergePrecondizioni($parametri)
126
    {
127 5
        $precondizioni = GrigliaDatiUtils::getDatiPrecondizioni($parametri);
128
129 5
        $precondizioniAvanzate = GrigliaDatiUtils::getDatiPrecondizioniAvanzate($parametri);
130
131 5
        foreach ($precondizioni as $campoprecondizione => $valoreprecondizione) {
132 1
            if (strpos($campoprecondizione, ".") === false) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal . 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...
133 1
                $nometabellaprecondizione = $parametri['nometabella'];
134 1
                $nomecampoprecondizione = $campoprecondizione;
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...
135 1
            } else {
136
                $nometabellaprecondizione = substr($campoprecondizione, 0, strrpos($campoprecondizione, '.'));
137
                $nomecampoprecondizione = substr($campoprecondizione, strrpos($campoprecondizione, '.') + 1);
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...
138
            }
139 1
            $precondizioniAvanzate[] = array('nometabella' => $nometabellaprecondizione,
140 1
                'nomecampo' => $nomecampoprecondizione,
141 1
                'operatore' => '=',
142 1
                'valorecampo' => $valoreprecondizione);
143 5
        }
144 5
        return $precondizioniAvanzate;
145
    }
146
}
147