Passed
Push — master ( ce89ba...4bc45e )
by Andrea
11:12
created

setPrecondizioniAvanzate()   C

Complexity

Conditions 9
Paths 9

Size

Total Lines 61
Code Lines 52

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 48
CRAP Score 9.111

Importance

Changes 0
Metric Value
dl 0
loc 61
ccs 48
cts 54
cp 0.8889
rs 6.7603
c 0
b 0
f 0
cc 9
eloc 52
nc 9
nop 3
crap 9.111

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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