Passed
Push — master ( c09f3d...b68917 )
by Andrea
12:33
created

GrigliaDatiPrecondizioniUtils   A

Complexity

Total Complexity 20

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 59.77%

Importance

Changes 0
Metric Value
dl 0
loc 103
ccs 52
cts 87
cp 0.5977
rs 10
c 0
b 0
f 0
wmc 20

3 Methods

Rating   Name   Duplication   Size   Complexity  
B elaboravalorecampo() 0 18 8
C setPrecondizioniAvanzate() 0 62 9
A setPrecondizioni() 0 15 3
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
use Fi\CoreBundle\Controller\FiUtilita;
6
7
class GrigliaDatiPrecondizioniUtils
8
{
9
    public static function setPrecondizioni(&$q, &$primo, $parametri = array())
10
    {
11
        $precondizioni = $parametri['precondizioni'];
12
13
        $i = 1;
14
        foreach ($precondizioni as $nomecampopre => $precondizione) {
15
            if ($primo) {
16
                $q->where("$nomecampopre = :var$i");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $nomecampopre 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...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $i 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...
17
18
                $primo = false;
19
            } else {
20
                $q->andWhere("$nomecampopre = :var$i");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $nomecampopre 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...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $i 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...
21
            }
22
            $q->setParameter("var$i", $precondizione);
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $i 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...
23
            ++$i;
24
        }
25
    }
26
27 1
    public static function setPrecondizioniAvanzate(&$q, &$primo, $parametri = array())
28
    {
29 1
        $doctrine = $parametri['doctrine'];
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...
30 1
        $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...
31 1
        $entityName = $parametri['entityName'];
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...
32 1
        $bundle = $parametri['bundle'];
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...
33 1
        $precondizioniAvanzate = $parametri['precondizioniAvanzate'];
34 1
        $regole = array();
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...
35
36 1
        foreach ($precondizioniAvanzate as $elem) {
37 1
            $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...
38 1
            $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...
39 1
            $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...
40 1
            $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...
41 1
            $operatorelogicoprecondizione = '';
42 1
            foreach ($elem as $keypre => $valuepre) {
43
                switch ($keypre) {
44 1
                    case 'nometabella':
45 1
                        $nometabellaprecondizione = $valuepre;
46 1
                        break;
47 1
                    case 'nomecampo':
48 1
                        $nomecampoprecondizione = $valuepre;
49 1
                        break;
50 1
                    case 'operatore':
51 1
                        $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...
52 1
                            '<=' => 'le', '>' => 'gt', '>=' => 'ge',
53 1
                            'LIKE' => 'bw', 'NOT LIKE' => 'bn', 'IN' => 'in', 'NOT IN' => 'ni',
54 1
                            'LIKE' => 'eq', 'NOT LIKE' => 'en',
55 1
                            'LIKE' => 'cn', 'NOT LIKE' => 'nc', 'IS' => 'nu', 'IS NOT' => 'nn');
56 1
                        $operatoreprecondizione = $array_operatori[strtoupper($valuepre)];
57 1
                        break;
58 1
                    case 'valorecampo':
59 1
                        if (is_array($valuepre)) {
60
                            $type = $doctrine->getClassMetadata($parametri['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...
61
                            $valorecampoprecondizione = self::elaboravalorecampo($type, $valuepre);
62
                        } else {
63 1
                            $valorecampoprecondizione = $valuepre;
64
                        }
65 1
                        break;
66 1
                    case 'operatorelogico':
67 1
                        $operatorelogicoprecondizione = strtoupper($valuepre);
68 1
                        break;
69
                    default:
70
                        break;
71
                }
72 1
            }
73
74 1
            $regole[] = array(
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...
75 1
                'field' => "$nometabellaprecondizione.$nomecampoprecondizione",
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $nometabellaprecondizione 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...
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $nomecampoprecondizione 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...
76 1
                'op' => $operatoreprecondizione,
77 1
                'data' => $valorecampoprecondizione, );
78 1
            $tipof = $operatorelogicoprecondizione;
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...
79
            $regolearray = array(
80 1
                'regole' => $regole,
81 1
                'doctrine' => $doctrine,
82 1
                'nometabella' => $nometabella,
83 1
                'entityName' => $entityName,
84 1
                'bundle' => $bundle,
85 1
                'tipof' => $tipof,
86 1
            );
87 1
            GrigliaRegoleUtils::setRegole($q, $primo, $regolearray);
88 1
            $primo = false;
89 1
        }
90 1
    }
91
92
    private static function elaboravalorecampo($type, $valuepre)
93
    {
94
        $tipo = $type['type'];
95
        if ($tipo && ($tipo == 'date' || $tipo == 'datetime')) {
96
            GrigliaUtils::setVettoriPerData();
97
            foreach ($valuepre as $chiave => $valore) {
98
                $valuepre[$chiave] = FiUtilita::data2db($valore);
99
            }
100
            return implode(', ', $valuepre);
101
        } elseif ($tipo && $tipo == 'string') {
102
            GrigliaUtils::setVettoriPerStringa();
103
            foreach ($valuepre as $chiave => $valore) {
104
                $valuepre[$chiave] = strtolower("'" . $valore . "'");
105
            }
106
            return "'" . implode(', ', $valuepre) . "'";
107
        } else {
108
            GrigliaUtils::setVettoriPerNumero();
109
            return implode(', ', $valuepre);
110
        }
111
    }
112
}
113