Completed
Push — master ( 2ff726...1b8ace )
by Andrea
09:31
created

FiUtilita::proSelect()   B

Complexity

Conditions 4
Paths 4

Size

Total Lines 23
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 4.0039

Importance

Changes 0
Metric Value
dl 0
loc 23
ccs 15
cts 16
cp 0.9375
rs 8.7972
c 0
b 0
f 0
cc 4
eloc 15
nc 4
nop 1
crap 4.0039
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
        $restotminuti = array();
0 ignored issues
show
Unused Code introduced by
$restotminuti is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
38
        $resminuti = 0;
0 ignored issues
show
Unused Code introduced by
$resminuti is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
39
        $resore = 0;
0 ignored issues
show
Unused Code introduced by
$resore is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
40
41
        $minuti = $parametri['minuti'];
42
43
        $totminuti = array_sum($minuti);
44
        $resminuti = $totminuti % 60;
45
        $resore = ($totminuti - $resminuti) / 60;
46
47
        $restotminuti = array('ore' => $resore, 'minuti' => $resminuti);
48
49
        return $restotminuti;
50
    }
51
52
    /**
53
     * @param array  $parametri
54
     * @param string $parametri["tipo"]
0 ignored issues
show
Documentation introduced by
There is no parameter named $parametri["tipo"]. Did you maybe mean $parametri?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
55
     *
56
     * @return Array("segnouno"=>"xx", "segnodue"=>"yy") dove segnodue non obbligatorio
0 ignored issues
show
Documentation introduced by
The doc-type Array("segnouno"=>"xx", could not be parsed: Expected "|" or "end of type", but got "(" at position 5. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
57
     */
58
    public function operatoreQuery($parametri = array())
59
    {
60
        $risposta = array();
61
62
        if (isset($parametri['tipo'])) {
63
            $tipocampo = $parametri['tipo'];
64
        } else {
65
            return array('segnouno' => '=');
66
        }
67
68
        switch ($tipocampo) {
69
            case 'date':
70
            case 'integer':
71
            case 'double':
72
                $operatore = '>=';
73
                $operatoredue = '<=';
74
                break;
75
            case 'string':
76
            case 'text':
77
                $operatore = 'LIKE';
78
                break;
79
            default:
80
                $operatore = '=';
81
                break;
82
        }
83
84
        $risposta['segnouno'] = $operatore;
85
        if (isset($operatoredue)) {
86
            $risposta['segnodue'] = $operatoredue;
87
        }
88
89
        return $risposta;
90
    }
91
92 2
    public static function data2db($giorno, $invertito = false, $senzalinea = false)
93
    {
94 2
        if ($giorno == '') {
95
            return null;
96
        }
97
98 2
        if (substr($giorno, 4, 1) == '-') {
99 1
            return $giorno;
100
        }
101
102 1
        $barragiorno = strpos($giorno, '/');
103 1
        $gg = substr($giorno, 0, $barragiorno);
104 1
        $restante = substr($giorno, $barragiorno + 1);
105
106 1
        $barra = strpos($restante, '/');
107 1
        $mm = substr($restante, 0, $barra);
108 1
        $aaaa = substr($restante, $barra + 1);
109
110 1
        $appogg = ($invertito ? $mm : $gg);
111 1
        $mm = ($invertito ? $gg : $mm);
112 1
        $gg = $appogg;
113
114 1
        $formattata = self::getDataFormattata($aaaa, $mm, $gg, $senzalinea);
115
116 1
        return $formattata;
117
    }
118
119 1
    private static function getDataFormattata($aaaa, $mm, $gg, $senzalinea)
120
    {
121 1
        $separatore = ($senzalinea ? '' : '-');
122
123 1
        $nuovadata = $aaaa . $separatore . $mm . $separatore . $gg;
124
125 1
        return strlen($gg) == 0 ? '' : $nuovadata;
126
    }
127
128
    public static function db2data($giorno, $senzalinea = false)
129
    {
130
        if (substr($giorno, 2, 1) == '/') {
131
            return $giorno;
132
        }
133
134
        if ($senzalinea) {
135
            $formattata = self::senzalinea($giorno);
136
        } else {
137
            $barra = strpos($giorno, '-');
138
            $aaaa = substr($giorno, 0, $barra);
139
            $restante = substr($giorno, $barra + 1);
140
            $barra = strpos($restante, '-');
141
            $mm = substr($restante, 0, $barra);
142
            $gg = substr($restante, $barra + 1);
143
144
            $formattata = (strlen($gg) == 0 ? '' : "$gg/$mm/$aaaa");
145
        }
146
147
        return $formattata;
148
    }
149
150
    private static function senzalinea($giorno)
151
    {
152
        $aaaa = substr($giorno, 0, 4);
153
        $mm = substr($giorno, 4, 2);
154
        $gg = substr($giorno, 6, 2);
155
156
        $formattata = (strlen($gg) == 0 ? '' : "$gg/$mm/$aaaa");
157
158
        return $formattata;
159
    }
160
161
    /**
162
     * @param array  $parametri
163
     * @param string $parametri["nomecodice"]      default = "codice"
0 ignored issues
show
Documentation introduced by
There is no parameter named $parametri["nomecodice"]. Did you maybe mean $parametri?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
164
     * @param string $parametri["nomedescrizione"] default = "descrizione"
0 ignored issues
show
Documentation introduced by
There is no parameter named $parametri["nomedescrizione"]. Did you maybe mean $parametri?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
165
     * @param array  $parametri["elementi"]        Array([0]=>("codice"=>1, "descrizione"=>"blaa"), [1]=>...)
0 ignored issues
show
Documentation introduced by
There is no parameter named $parametri["elementi"]. Did you maybe mean $parametri?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
166
     * @param string $parametri["selezionato"]     opzionale
0 ignored issues
show
Documentation introduced by
There is no parameter named $parametri["selezionato"]. Did you maybe mean $parametri?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.

Consider the following example. The parameter $ireland is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $ireland
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was changed, but the annotation was not.

Loading history...
167
     *
168
     * @return string
169
     */
170 1
    public function proSelect($parametri = array())
171
    {
172 1
        $stringaproselect = '';
173 1
        if (!isset($parametri['elementi'])) {
174
            return false;
175
        }
176
177
        //parametri obbligatori
178 1
        $elementi = $parametri['elementi'];
179 1
        $attributi = $this->getProSelectAttribute($parametri);
180 1
        $selezionato = $attributi['selezionato'];
181 1
        $nomecodice = $attributi['nomecodice'];
182 1
        $nomedescrizione = $attributi['nomedescrizione'];
183
184 1
        foreach ($elementi as $elemento) {
185 1
            $elementonomecodice = $elemento[$nomecodice];
186 1
            $elementonomedescrizione = $elemento[$nomedescrizione];
187 1
            $elementoselezionato = ($elementonomecodice === $selezionato ? " selected='yes'" : '');
188 1
            $stringaproselect .= '<option value="' . $elementonomecodice . '"' . $elementoselezionato . '>' . $elementonomedescrizione . '</option>';
189 1
        }
190
191 1
        return $stringaproselect;
192
    }
193
194 1
    public function getProSelectAttribute($parametri)
195
    {
196 1
        $arrayritorno = array();
197 1
        $arrayritorno['selezionato'] = (isset($parametri['selezionato']) ? $parametri['selezionato'] : false);
198 1
        $arrayritorno['nomecodice'] = (isset($parametri['nomecodice']) ? $parametri['nomecodice'] : 'codice');
199 1
        $arrayritorno['nomedescrizione'] = (isset($parametri['nomedescrizione']) ? $parametri['nomedescrizione'] : 'descrizione');
200
201 1
        return $arrayritorno;
202
    }
203
204
    /**
205
     * @param $parametri["vettore"]
206
     * @param $parametri["chiave"]
207
     * @param $parametri["valore"]
208
     *
209
     * @return $vettorenuovo
0 ignored issues
show
Documentation introduced by
The doc-type $vettorenuovo could not be parsed: Unknown type name "$vettorenuovo" at position 0. (view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
210
     */
211
    public function cancellaDaVettore($parametri = array())
212
    {
213
214
        //parametri obbligatori
215
        if (isset($parametri['vettore'])) {
216
            $vettore = $parametri['vettore'];
217
        } else {
218
            return false;
219
        }
220
221
        //parametri obbligatori
222
        if (isset($parametri['chiave'])) {
223
            $chiave = $parametri['chiave'];
224
        } else {
225
            return $vettore;
226
        }
227
228
        //parametri obbligatori
229
        if (isset($parametri['valore'])) {
230
            $valore = $parametri['valore'];
231
        } else {
232
            return $vettore;
233
        }
234
235
        $vettorenuovo = array();
236
237
        foreach ($vettore as $elemento) {
238
            if (!($elemento[$chiave] == $valore)) {
239
                $vettorenuovo[] = $elemento;
240
            }
241
        }
242
        return $vettorenuovo;
243
    }
244
}
245