Conditions | 19 |
Paths | 132 |
Total Lines | 45 |
Code Lines | 21 |
Lines | 9 |
Ratio | 20 % |
Tests | 0 |
CRAP Score | 380 |
Changes | 2 | ||
Bugs | 0 | Features | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
110 | public function checkArrSpesa($arrSpesa) |
||
111 | { |
||
112 | if(empty($arrSpesa)){ |
||
113 | $this->AddError("Dati spesa mancanti"); |
||
114 | }else{ |
||
115 | |||
116 | $arrFlagOperazione = FlagOperazione::getCostants(); |
||
117 | |||
118 | // Controllo interno array spesa |
||
119 | foreach($arrSpesa as $rigaSpesa){ |
||
120 | |||
121 | if(count($rigaSpesa)<6){ |
||
122 | $this->AddError("Dati spesa incompleti"); |
||
123 | } |
||
124 | |||
125 | foreach($rigaSpesa as $campo => $valore){ |
||
126 | |||
127 | // generico per campo mancante obbligatorio |
||
128 | if($valore == "" && $campo != "flagPagamentoAnticipato"){ // flagPagamentoAnticipato e' facoltativo |
||
129 | $this->AddError("Dato spesa mancante campo: ".$campo); |
||
130 | } |
||
131 | |||
132 | if ($campo == "dataEmissione" || $campo == "dataPagamento") { |
||
133 | $this->checkDataValida($campo, $valore); |
||
134 | } |
||
135 | |||
136 | View Code Duplication | if($campo == "flagOperazione" && (!in_array($valore, $arrFlagOperazione)) ){ |
|
1 ignored issue
–
show
|
|||
137 | $this->AddError("<b>".$valore."</b> - Flag Operazione (flagOperazione) non valido. Codici validi: ".implode(", ",$arrFlagOperazione)); |
||
138 | } |
||
139 | |||
140 | if($campo == "cfCittadino" && !$this->objCFChecker->isFormallyCorrect($valore)){ |
||
141 | $this->AddError("<b>".$valore."</b> - Codice fiscale (cfCittadino) cittadino non valido"); |
||
142 | } |
||
143 | |||
144 | View Code Duplication | if($campo == "dispositivo" && (!is_numeric($valore) || strlen($valore) > 3) ){ |
|
1 ignored issue
–
show
|
|||
145 | $this->AddError("<b>".$valore."</b> - Codice dispositivo (dispositivo) non valido: deve essere numerico, al massimo di 3 cifre"); |
||
146 | } |
||
147 | |||
148 | View Code Duplication | if($campo == "numDocumento" && (!is_numeric($valore) || strlen($valore) > 20) ){ |
|
1 ignored issue
–
show
|
|||
149 | $this->AddError("<b>".$valore."</b> - Numero documento (numDocumento) non valido: deve essere numerico, al massimo di 20 cifre"); |
||
150 | } |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | |||
210 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.