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

FiUtilita::data2db()   B

Complexity

Conditions 5
Paths 6

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 14
CRAP Score 5.0488

Importance

Changes 0
Metric Value
dl 0
loc 25
ccs 14
cts 16
cp 0.875
rs 8.439
c 0
b 0
f 0
cc 5
eloc 15
nc 6
nop 3
crap 5.0488
1
<?php
2
3
namespace Fi\CoreBundle\Controller;
4
5
/*
6
 * Insieme di funzioni utili
7
 * FiUtilita.
8
 *
9
 * @author Emidio Picariello
10
 */
11
12
use Fi\CoreBundle\DependencyInjection\PercentualiStringhe;
13
14
class FiUtilita
15
{
16
17
    public function percentualiConfrontoStringheVettore($parametri = array())
18
    {
19
        $percentuali = new PercentualiStringhe();
20
21
        return $percentuali->percentualiConfrontoStringheVettore($parametri);
22
    }
23
24 1
    public function percentualiConfrontoStringhe($parametri = array())
25
    {
26 1
        $percentuali = new PercentualiStringhe();
27
28 1
        return $percentuali->percentualiConfrontoStringhe($parametri);
29
    }
30
31
    public function sommaMinuti($parametri = array())
32
    {
33
        //parametri obbligatori
34
        if (!isset($parametri['minuti'])) {
35
            return false;
36
        }
37
        $minuti = $parametri['minuti'];
38
39
        $totminuti = array_sum($minuti);
40
        $resminuti = $totminuti % 60;
41
        $resore = ($totminuti - $resminuti) / 60;
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...
42
43
        $restotminuti = array('ore' => $resore, 'minuti' => $resminuti);
44
45
        return $restotminuti;
46
    }
47
48
    /**
49
     * @param array  $parametri
50
     * string $parametri["tipo"]
51
     *
52
     * @return Array("segnouno"=>"xx", "segnodue"=>"yy") dove segnodue non obbligatorio
53
     */
54
    public function operatoreQuery($parametri = array())
55
    {
56
        $risposta = array();
57
58
        if (isset($parametri['tipo'])) {
59
            $tipocampo = $parametri['tipo'];
60
        } else {
61
            return array('segnouno' => '=');
62
        }
63
64
        switch ($tipocampo) {
65
            case 'date':
66
            case 'integer':
67
            case 'double':
68
                $operatore = '>=';
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...
69
                $operatoredue = '<=';
70
                break;
71
            case 'string':
72
            case 'text':
73
                $operatore = 'LIKE';
74
                break;
75
            default:
76
                $operatore = '=';
77
                break;
78
        }
79
80
        $risposta['segnouno'] = $operatore;
81
        if (isset($operatoredue)) {
82
            $risposta['segnodue'] = $operatoredue;
83
        }
84
85
        return $risposta;
86
    }
87
88 1
    public static function data2db($giorno, $invertito = false, $senzalinea = false)
89
    {
90 1
        if ($giorno == '') {
91
            return null;
92
        }
93
94 1
        if (substr($giorno, 4, 1) == '-') {
95
            return $giorno;
96
        }
97
98 1
        $barragiorno = strpos($giorno, '/');
99 1
        $gg = substr($giorno, 0, $barragiorno);
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...
100 1
        $restante = substr($giorno, $barragiorno + 1);
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...
101
102 1
        $barra = strpos($restante, '/');
103 1
        $mm = substr($restante, 0, $barra);
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...
104 1
        $aaaa = substr($restante, $barra + 1);
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...
105
106 1
        $appogg = ($invertito ? $mm : $gg);
107 1
        $mm = ($invertito ? $gg : $mm);
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...
108 1
        $gg = $appogg;
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...
109
110 1
        $formattata = self::getDataFormattata($aaaa, $mm, $gg, $senzalinea);
111
112 1
        return $formattata;
113
    }
114
115 1
    private static function getDataFormattata($aaaa, $mm, $gg, $senzalinea)
116
    {
117 1
        $separatore = ($senzalinea ? '' : '-');
118
119 1
        $nuovadata = $aaaa . $separatore . $mm . $separatore . $gg;
120
121 1
        return strlen($gg) == 0 ? '' : $nuovadata;
122
    }
123
124
    public static function db2data($giorno, $senzalinea = false)
125
    {
126
        if (substr($giorno, 2, 1) == '/') {
127
            return $giorno;
128
        }
129
130
        if ($senzalinea) {
131
            $formattata = self::senzalinea($giorno);
132
        } else {
133
            $barra = strpos($giorno, '-');
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...
134
            $aaaa = substr($giorno, 0, $barra);
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...
135
            $restante = substr($giorno, $barra + 1);
136
            $barra = strpos($restante, '-');
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...
137
            $mm = substr($restante, 0, $barra);
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...
138
            $gg = substr($restante, $barra + 1);
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...
139
140
            $formattata = (strlen($gg) == 0 ? '' : "$gg/$mm/$aaaa");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $gg 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 $mm 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 $aaaa 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...
141
        }
142
143
        return $formattata;
144
    }
145
146
    private static function senzalinea($giorno)
147
    {
148
        $aaaa = substr($giorno, 0, 4);
149
        $mm = substr($giorno, 4, 2);
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...
150
        $gg = substr($giorno, 6, 2);
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...
151
152
        $formattata = (strlen($gg) == 0 ? '' : "$gg/$mm/$aaaa");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $gg 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 $mm 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 $aaaa 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...
153
154
        return $formattata;
155
    }
156
157
    /**
158
     * @param array  $parametri
159
     * string $parametri["nomecodice"]      default = "codice"
160
     * string $parametri["nomedescrizione"] default = "descrizione"
161
     * array  $parametri["elementi"]        Array([0]=>("codice"=>1, "descrizione"=>"blaa"), [1]=>...)
162
     * string $parametri["selezionato"]     opzionale
163
     *
164
     * @return string
165
     */
166 1
    public function proSelect($parametri = array())
167
    {
168 1
        $stringaproselect = '';
169 1
        if (!isset($parametri['elementi'])) {
170
            return false;
171
        }
172
173
        //parametri obbligatori
174 1
        $elementi = $parametri['elementi'];
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...
175 1
        $attributi = $this->getProSelectAttribute($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...
176 1
        $selezionato = $attributi['selezionato'];
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...
177 1
        $nomecodice = $attributi['nomecodice'];
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...
178 1
        $nomedescrizione = $attributi['nomedescrizione'];
179
180 1
        foreach ($elementi as $elemento) {
181 1
            $elementonomecodice = $elemento[$nomecodice];
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...
182 1
            $elementonomedescrizione = $elemento[$nomedescrizione];
183 1
            $elementoselezionato = ($elementonomecodice === $selezionato ? " selected='yes'" : '');
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...
184 1
            $stringaproselect .= '<option value="' . $elementonomecodice . '"' . $elementoselezionato . '>' . $elementonomedescrizione . '</option>';
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...
185 1
        }
186
187 1
        return $stringaproselect;
188
    }
189
190 1
    public function getProSelectAttribute($parametri)
191
    {
192 1
        $arrayritorno = array();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 20 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...
193 1
        $arrayritorno['selezionato'] = (isset($parametri['selezionato']) ? $parametri['selezionato'] : false);
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...
194 1
        $arrayritorno['nomecodice'] = (isset($parametri['nomecodice']) ? $parametri['nomecodice'] : 'codice');
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...
195 1
        $arrayritorno['nomedescrizione'] = (isset($parametri['nomedescrizione']) ? $parametri['nomedescrizione'] : 'descrizione');
196
197 1
        return $arrayritorno;
198
    }
199
200
    /**
201
     * @param $parametri["vettore"]
202
     * @param $parametri["chiave"]
203
     * @param $parametri["valore"]
204
     *
205
     * @return $vettorenuovo
206
     */
207
    public function cancellaDaVettore($parametri = array())
208
    {
209
210
        //parametri obbligatori
211
        if (isset($parametri['vettore'])) {
212
            $vettore = $parametri['vettore'];
213
        } else {
214
            return false;
215
        }
216
217
        //parametri obbligatori
218
        if (isset($parametri['chiave'])) {
219
            $chiave = $parametri['chiave'];
220
        } else {
221
            return $vettore;
222
        }
223
224
        //parametri obbligatori
225
        if (isset($parametri['valore'])) {
226
            $valore = $parametri['valore'];
227
        } else {
228
            return $vettore;
229
        }
230
231
        $vettorenuovo = array();
232
233
        foreach ($vettore as $elemento) {
234
            if (!($elemento[$chiave] == $valore)) {
235
                $vettorenuovo[] = $elemento;
236
            }
237
        }
238
        return $vettorenuovo;
239
    }
240
}
241