Passed
Push — master ( 2a39ec...3b6c56 )
by Andrea
03:42
created

GrigliaDatiMultiUtils::getTotalPages()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 2
dl 0
loc 4
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Fi\CoreBundle\Utils;
4
5
use Doctrine\ORM\Tools\Pagination\Paginator;
6
7
class GrigliaDatiMultiUtils
8
{
9 6
    public static function getTotalPages($quanti, &$limit)
10
    {
11
        /* calcola in mumero di pagine totali necessarie */
12 6
        return ceil($quanti / ($limit == 0 ? 1 : $limit));
13
    }
14
15 6
    public static function getLimit(&$limit)
16
    {
17 6
        return $limit ? $limit : 1;
18
    }
19
20 6
    public static function prepareQuery($parametri, &$q, &$sidx, &$sord, &$page, &$limit, &$quanti)
21
    {
22 6
        $output = GrigliaParametriUtils::getOuputType($parametri);
23 6
        $nospan = GrigliaDatiUtils::getDatiNospan($parametri);
24
        /* su quale campo fare l'ordinamento */
25
        /* conta il numero di record di risposta
0 ignored issues
show
Unused Code Comprehensibility introduced by
36% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
26
          $query_tutti_records = $q->getQuery();
27
          $quanti = count($query_tutti_records->getSingleScalarResult()); */
28
29 6
        $paginator = new Paginator($q, true);
30 6
        $quanti = count($paginator);
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...
31
32
        /* imposta l'offset, ovvero il record dal quale iniziare a visualizzare i dati */
33 6
        $offset = ($limit * ($page - 1));
34
35
        /* se si mandano i dati in stampa non tiene conto di limite e offset ovvero risponde con tutti i dati */
36 6
        if ($output != 'stampa') {
37
            /* se nospan non tiene conto di limite e offset ovvero risponde con tutti i dati */
38 6
            if (!($nospan)) {
39
                /* Imposta il limite ai record da estrarre */
40 6
                $q = ($limit ? $q->setMaxResults($limit) : $q);
41
                /* E imposta il primo record da visualizzare (per la paginazione) */
42 6
                $q = ($offset ? $q->setFirstResult($offset) : $q);
43
            }
44
        } else {
45
            if ($quanti > 1000) {
46
                set_time_limit(960);
47
                ini_set('memory_limit', '2048M');
48
            }
49
        }
50
51 6
        if ($sidx) {
52 6
            $q->orderBy($sidx, $sord);
53
        }
54
        /* Dall'oggetto querybuilder si ottiene la query da eseguire */
55 6
        $query_paginata = $q->getQuery();
56
57
        /* Object -> $q = $query_paginata->getResult(); */
0 ignored issues
show
Unused Code Comprehensibility introduced by
47% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
58
        /* Array */
59
        /* Si ottiene un array con tutti i records */
60 6
        $q = $query_paginata->getArrayResult();
61
62
        /* Se il limire non è stato impostato si mette 1 (per calcolare la paginazione) */
63 6
        $limit = self::getLimit($limit);
64 6
    }
65
66 6
    public static function buildRowGriglia(&$singolo, &$vettoreriga, &$vettorerisposta)
67
    {
68
69
        /* Si costruisce la risposta json per la jqgrid */
70 6
        ksort($vettoreriga);
71 6
        $vettorerigasorted = array();
72 6
        foreach ($vettoreriga as $value) {
73 6
            $vettorerigasorted[] = $value;
74
        }
75 6
        $vettorerisposta['rows'][] = array('id' => $singolo['id'], 'cell' => $vettorerigasorted);
76 6
        unset($vettoreriga);
77 6
    }
78
79 6
    public static function setOrdineColonneDatiGriglia(&$ordinecolonne, &$nomecampo, &$indice, &$indicecolonna)
80
    {
81 6
        if (isset($ordinecolonne)) {
82 1
            $indicecolonna = array_search($nomecampo, $ordinecolonne);
83 1
            if ($indicecolonna === false) {
84 1
                if ($indice === 0) {
85 1
                    $indice = count($ordinecolonne);
86
                }
87 1
                ++$indice;
88 1
                $indicecolonna = $indice;
89
            } else {
90 1
                if ($indicecolonna > $indice) {
91 1
                    $indice = $indicecolonna;
92
                }
93
            }
94
        } else {
95 5
            ++$indice;
96 5
            $indicecolonna = $indice;
97
        }
98 6
    }
99
100 6
    public static function buildDatiGriglia($parametri, &$vettoreriga, &$singolo, &$nomecampo, &$indice, &$indicecolonna, &$singolocampo)
101
    {
102 6
        $doctrine = GrigliaParametriUtils::getDoctrineByEm($parametri);
103
104 6
        $bundle = $parametri['nomebundle'];
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...
105 6
        $nometabella = $parametri['nometabella'];
106
        
107 6
        $tabellej = $parametri["tabellej"];
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...
Coding Style Comprehensibility introduced by
The string literal tabellej 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...
108 6
        $decodifiche = $parametri["decodifiche"];
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...
Coding Style Comprehensibility introduced by
The string literal decodifiche 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...
109 6
        $escludere = $parametri["escludere"];
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...
Coding Style Comprehensibility introduced by
The string literal escludere 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...
110 6
        $escludereutente = $parametri["escludereutente"];
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal escludereutente 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...
111 6
        $ordinecolonne = $parametri["ordinecolonne"];
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...
Coding Style Comprehensibility introduced by
The string literal ordinecolonne 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
        /* Si controlla se il campo è da escludere o meno */
114 6
        if ((!isset($escludere) || !(in_array($nomecampo, $escludere))) && (!isset($escludereutente) || !(in_array($nomecampo, $escludereutente)))) {
115 6
            if (isset($tabellej[$nomecampo])) {
116 3
                self::tabellejNomecampoNormalizzato($tabellej, $nomecampo);
117
                /* Per ogni campo si cattura il valore dall'array che torna doctrine */
118 3
                foreach ($tabellej[$nomecampo]['campi'] as $campoelencato) {
119
                    /* Object -> $fields = $singolo->get($tabellej[$nomecampo]["tabella"]) ?
0 ignored issues
show
Unused Code Comprehensibility introduced by
72% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
120
                      $singolo->get($tabellej[$nomecampo]["tabella"])->get($campoelencato): ""; */
121
                    /* array */
122
123 3
                    self::setOrdineColonneDatiGriglia($ordinecolonne, $nomecampo, $indice, $indicecolonna);
124
                    
125 3
                    $parametriCampoElencato = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 18 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...
126 3
                    $parametriCampoElencato['tabellej'] = $tabellej;
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...
127 3
                    $parametriCampoElencato['nomecampo'] = $nomecampo;
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...
128 3
                    $parametriCampoElencato['campoelencato'] = $campoelencato;
129 3
                    $parametriCampoElencato['vettoreriga'] = $vettoreriga;
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...
130 3
                    $parametriCampoElencato['singolo'] = $singolo;
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...
131 3
                    $parametriCampoElencato['doctrine'] = $doctrine;
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...
132 3
                    $parametriCampoElencato['bundle'] = $bundle;
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...
133 3
                    $parametriCampoElencato['ordinecampo'] = $indicecolonna;
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...
134 3
                    $parametriCampoElencato['decodifiche'] = $decodifiche;
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
136 3
                    $vettoreriga = GrigliaDatiUtils::campoElencato($parametriCampoElencato);
137
                }
138
            } else {
139 6
                self::setOrdineColonneDatiGriglia($ordinecolonne, $nomecampo, $indice, $indicecolonna);
140
                $parametriGrglia = array(
141 6
                    'singolocampo' => $singolocampo,
142 6
                    'tabella' => $bundle.':'.$nometabella,
143 6
                    'nomecampo' => $nomecampo,
144 6
                    'doctrine' => $doctrine,
145 6
                    'ordinecampo' => $indicecolonna,
146 6
                    'decodifiche' => $decodifiche,
147
                );
148 6
                GrigliaDatiUtils::valorizzaVettore($vettoreriga, $parametriGrglia);
149
            }
150
        }
151 6
    }
152
153 3
    public static function tabellejNomecampoNormalizzato(&$tabellej, $nomecampo)
154
    {
155 3
        if (is_object($tabellej[$nomecampo])) {
156
            $tabellej[$nomecampo] = get_object_vars($tabellej[$nomecampo]);
157
        }
158 3
    }
159
160 12
    public static function getWidthColonna(&$singoloalias, $colonna)
161
    {
162 12
        $moltiplicatorelarghezza = GrigliaUtils::MOLTIPLICATORELARGHEZZA;
163 12
        $larghezzamassima = GrigliaUtils::LARGHEZZAMASSIMA;
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...
164 12
        $singoloaliaslunghezza = self::getLunghezzaSingoloAlias($singoloalias);
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...
165 12
        $larghezzacalc = self::getLunghezzaSingoloAliasCalc($singoloalias, $colonna);
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...
166 12
        $moltiplicatore = self::getMoltiplicatoreColonna($singoloaliaslunghezza, $colonna, $moltiplicatorelarghezza);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 10 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...
167 12
        $larghezzaricalcolata = ($moltiplicatore > $larghezzamassima ? $larghezzamassima : $larghezzacalc);
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...
168 12
        $widthcampo = isset($singoloaliaslunghezza) ? $singoloaliaslunghezza : $larghezzaricalcolata;
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...
169
170 12
        return $widthcampo;
171
    }
172
173 12
    public static function getLunghezzaSingoloAlias(&$singoloalias)
174
    {
175 12
        return isset($singoloalias['lunghezza']) ? $singoloalias['lunghezza'] : null;
176
    }
177
178 12
    public static function getLunghezzaSingoloAliasCalc(&$singoloalias, $colonna)
179
    {
180 12
        return isset($singoloalias['lunghezza']) ? $singoloalias['lunghezza'] : $colonna['length'] * GrigliaUtils::MOLTIPLICATORELARGHEZZA;
181
    }
182
183 12
    public static function getMoltiplicatoreColonna(&$singoloaliaslunghezza, $colonna, $moltiplicatorelarghezza)
184
    {
185 12
        return isset($singoloaliaslunghezza) ? $singoloaliaslunghezza : $colonna['length'] * $moltiplicatorelarghezza;
186
    }
187
}
188