Passed
Push — master ( 99ebfd...98eb66 )
by Andrea
109:16 queued 44:44
created

precondizioniToPrecondizioniAvanzate()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 0
cts 0
cp 0
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 11
nc 3
nop 3
crap 12
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
use Fi\CoreBundle\Controller\FiUtilita;
6
7
class GrigliaDatiPrecondizioniUtils
8
{
9
10 2
    public static function setPrecondizioniAvanzate(&$q, &$primo, $parametri = array())
11
    {
12 2
        $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...
13 2
        $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...
14 2
        $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...
15 2
        $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...
16 2
        $precondizioniAvanzate = $parametri['precondizioniAvanzate'];
17 2
        $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...
18
19 2
        foreach ($precondizioniAvanzate as $elem) {
20 2
            $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...
21 2
            $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...
22 2
            $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...
23 2
            $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...
24 2
            $operatorelogicoprecondizione = '';
25 2
            foreach ($elem as $keypre => $valuepre) {
26
                switch ($keypre) {
27 2
                    case 'nometabella':
28 2
                        $nometabellaprecondizione = $valuepre;
29 2
                        break;
30 2
                    case 'nomecampo':
31 2
                        $nomecampoprecondizione = $valuepre;
32 2
                        break;
33 2
                    case 'operatore':
34 2
                        $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...
35 2
                            '<=' => 'le', '>' => 'gt', '>=' => 'ge',
36 2
                            'LIKE' => 'bw', 'NOT LIKE' => 'bn', 'IN' => 'in', 'NOT IN' => 'ni',
37 2
                            'LIKE' => 'eq', 'NOT LIKE' => 'en',
38 2
                            'LIKE' => 'cn', 'NOT LIKE' => 'nc', 'IS' => 'nu', 'IS NOT' => 'nn');
39 2
                        $operatoreprecondizione = $array_operatori[strtoupper($valuepre)];
40 2
                        break;
41 2
                    case 'valorecampo':
42 2
                        if (is_array($valuepre)) {
43 1
                            $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...
44 1
                            $valorecampoprecondizione = self::elaboravalorecampo($type, $valuepre);
45 1
                        } else {
46 2
                            $valorecampoprecondizione = $valuepre;
47
                        }
48 2
                        break;
49
                    case 'operatorelogico':
50
                        $operatorelogicoprecondizione = strtoupper($valuepre);
51
                        break;
52
                    default:
53
                        break;
54
                }
55 2
            }
56
57 2
            $regole[] = array(
58 2
                '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...
59 2
                'op' => $operatoreprecondizione,
60 2
                'data' => $valorecampoprecondizione,
61 2
                'typof' => $operatorelogicoprecondizione);
62 2
        }
63
        $regolearray = array(
64 2
            'regole' => $regole,
65 2
            'doctrine' => $doctrine,
66 2
            'nometabella' => $nometabella,
67 2
            'entityName' => $entityName,
68
            'bundle' => $bundle
69 2
        );
70 2
        GrigliaRegoleUtils::setRegole($q, $primo, $regolearray);
71 2
    }
72
73 1
    private static function elaboravalorecampo($type, $valuepre)
74
    {
75 1
        $tipo = $type['type'];
76 1
        if ($tipo && ($tipo == 'date' || $tipo == 'datetime')) {
77
            GrigliaUtils::setVettoriPerData();
78
            foreach ($valuepre as $chiave => $valore) {
79
                $valuepre[$chiave] = FiUtilita::data2db($valore);
80
            }
81
            return implode(', ', $valuepre);
82 1
        } elseif ($tipo && $tipo == 'string') {
83 1
            GrigliaUtils::setVettoriPerStringa();
84 1
            foreach ($valuepre as $chiave => $valore) {
85 1
                $valuepre[$chiave] = strtolower($valore);
86 1
            }
87 1
            return implode(', ', $valuepre);
88
        } else {
89 1
            GrigliaUtils::setVettoriPerNumero();
90 1
            return implode(', ', $valuepre);
91
        }
92
    }
93
94
    public static function precondizioniToPrecondizioniAvanzate($precondizioni, &$precondizioniAvanzate, $nometabella)
95
    {
96
        foreach ($precondizioni as $campoprecondizione => $valoreprecondizione) {
97
            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...
98
                $nometabellaprecondizione = $nometabella;
99
                $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...
100
            } else {
101
                $nometabellaprecondizione = substr($campoprecondizione, 0, strrpos($campoprecondizione, '.'));
102
                $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...
103
            }
104
            $precondizioniAvanzate[] = array('nometabella' => $nometabellaprecondizione,
105
                'nomecampo' => $nomecampoprecondizione,
106
                'operatore' => '=',
107
                'valorecampo' => $valoreprecondizione);
108
        }
109
    }
110
}
111