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

GrigliaRegoleUtils::setSingolaRegola()   B

Complexity

Conditions 8
Paths 12

Size

Total Lines 19
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 8.125

Importance

Changes 0
Metric Value
cc 8
eloc 12
nc 12
nop 2
dl 0
loc 19
ccs 14
cts 16
cp 0.875
crap 8.125
rs 7.7777
c 0
b 0
f 0
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
use Fi\CoreBundle\Controller\FiUtilita;
6
7
class GrigliaRegoleUtils
8
{
9
10 1
    public static function getTipoRegola(&$tipo, &$regola, $parametri)
11
    {
12 1
        $doctrine = $parametri['doctrine'];
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...
13 1
        $nometabella = $parametri['nometabella'];
14 1
        $entityName = $parametri['entityName'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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 1
        $bundle = $parametri['bundle'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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
17 1
        $elencocampi = $doctrine->getClassMetadata($entityName)->getFieldNames();
18
19 1
        if (strrpos($regola['field'], '.') == 0) {
20 1
            if (in_array($regola['field'], $elencocampi) === true) {
21 1
                $type = $doctrine->getClassMetadata($entityName)->getFieldMapping($regola['field']);
22 1
                $tipo = $type['type'];
23
24
                //Si aggiunge l'alias al campo altrimenti da Doctrine2 fallisce la query
25 1
                $regola['field'] = $nometabella . '.' . $regola['field'];
26 1
            }
27 1
        } else {
28
            //Altrimenti stiamo analizzando il campo di una tabella in leftjoin pertanto si cercano le informazioni sul tipo
29
            //dei campi nella tabella "joinata"
30 1
            $tablejoined = substr($regola['field'], 0, strrpos($regola['field'], '.'));
31 1
            $fieldjoined = substr($regola['field'], strrpos($regola['field'], '.') + 1);
32
33 1
            $entityNametablejoined = $bundle . ':' . $tablejoined;
34
35 1
            $type = $doctrine->getClassMetadata($entityNametablejoined)->getFieldMapping($fieldjoined);
36 1
            $tipo = $type['type'];
37
        }
38 1
    }
39
40 1
    public static function getRegolaPerData(&$regola)
41
    {
42 1
        if (isset($regola) && count($regola) > 0) {
43 1
            if ((substr($regola['data'], 0, 1) == "'") && (substr($regola['data'], strlen($regola['data']) - 1, 1) == "'")) {
44
                $regola['data'] = substr($regola['data'], 1, strlen($regola['data']) - 2);
45
            }
46 1
        }
47 1
    }
48
49 1
    public static function setRegole(&$q, &$primo, $parametri = array())
0 ignored issues
show
Unused Code introduced by
The parameter $primo is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

49
    public static function setRegole(&$q, /** @scrutinizer ignore-unused */ &$primo, $parametri = array())

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
50
    {
51 1
        $regole = $parametri['regole'];
52 1
        $tipof = $parametri['tipof'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
53 1
        $tipo = null;
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...
54 1
        foreach ($regole as $regola) {
55
            //Se il campo non ha il . significa che è necessario aggiungere il nometabella
56 1
            self::getTipoRegola($tipo, $regola, $parametri);
57
58 1
            $regola = self::setSingolaRegola($tipo, $regola);
59 1
            if (!$regola) {
60
                continue;
61
            }
62 1
            if ($tipof == 'OR') {
63
                $condizioneOR = $regola['field'] . ' ' .
64
                        GrigliaUtils::$decodificaop[$regola['op']] . ' ' .
65
                        GrigliaUtils::$precarattere[$regola['op']] .
66
                        str_replace("'", "''", $regola['data']) .
67
                        GrigliaUtils::$postcarattere[$regola['op']];
68
                $q->orWhere($condizioneOR);
69
            } else {
70 1
                $condizioneAND = $regola['field'] . ' ' .
71 1
                        GrigliaUtils::$decodificaop[$regola['op']] . ' ' .
72 1
                        GrigliaUtils::$precarattere[$regola['op']] .
73 1
                        str_replace("'", "''", $regola['data']) .
74 1
                        GrigliaUtils::$postcarattere[$regola['op']];
75 1
                $q->andWhere($condizioneAND);
76
            }
77 1
        }
78 1
    }
79
80 1
    public static function setSingolaRegola($tipo, $regola)
81
    {
82 1
        if (!$tipo || $tipo == "integer" || $tipo == "float") {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal integer 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...
Coding Style Comprehensibility introduced by
The string literal float 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...
83 1
            GrigliaUtils::setVettoriPerNumero();
84 1
        }
85 1
        if ($tipo == 'date' || $tipo == 'datetime') {
86 1
            GrigliaUtils::setVettoriPerData();
87 1
            $regola['data'] = FiUtilita::data2db($regola['data']);
88 1
        } elseif ($tipo == 'string') {
89 1
            GrigliaUtils::setVettoriPerStringa();
90 1
            $regola['field'] = 'lower(' . $regola['field'] . ')';
91 1
        }
92 1
        if ($tipo == 'boolean') {
93
            self::setTipoBoolean($regola, $tipo);
94
        }
95
96 1
        self::getRegolaPerData($regola);
97
98 1
        return $regola;
99
    }
100
101
    public static function setTipoBoolean(&$regola, $tipo)
102
    {
103
        if ($regola['data'] === 'false' || $regola['data'] === false) {
104
            GrigliaUtils::setVettoriPerBoolean();
105
            $regola['op'] = 'eq';
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...
106
            $regola['data'] = "0";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 0 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...
107
        }
108
        if ($regola['data'] === 'true' || $regola['data'] === true) {
109
            GrigliaUtils::setVettoriPerBoolean();
110
            $regola['op'] = 'eq';
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...
111
            $regola['data'] = "1";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal 1 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...
112
        }
113
        if ($tipo == 'boolean' && $regola['data'] == 'null') {
114
            $regola = array();
115
        }
116
    }
117
118 13
    public static function campiesclusi($parametri = array())
119
    {
120 13
        if (!isset($parametri['nometabella'])) {
121
            return false;
122
        }
123
124 13
        $output = GrigliaParametriUtils::getOuputType($parametri);
125
126 13
        $nometabella = $parametri['nometabella'];
127
128 13
        $doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri);
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...
129 13
        $doctrineficore = GrigliaParametriUtils::getDoctrineFiCoreByEm($parametri, $doctrine);
130 13
        $container = $parametri['container'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
131
132 13
        $gestionepermessi = $container->get("ficorebundle.gestionepermessi");
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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 Comprehensibility introduced by
The string literal ficorebundle.gestionepermessi 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 13
        $operatorecorrente = $gestionepermessi->utentecorrente();
134
135 13
        $escludi = array();
136 13
        $q = GrigliaUtils::getUserCustomTableFields($doctrineficore, $nometabella, $operatorecorrente);
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...
137 13
        if (!$q) {
138 9
            return $escludi;
139
        }
140
141 4
        foreach ($q as $riga) {
142 4
            $campo = GrigliaUtils::getCampiEsclusi($riga, $output);
143 4
            if ($campo) {
144
                $escludi[] = $campo;
145
            }
146 4
        }
147
148 4
        return $escludi;
149
    }
150
}
151