| Conditions | 1 |
| Paths | 1 |
| Total Lines | 22 |
| Code Lines | 10 |
| Lines | 22 |
| Ratio | 100 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 19 | View Code Duplication | public function cancelar($id_venda, $id_cliente) { |
|
| 20 | $response = $this->LancamentoVenda->find('first', array( |
||
| 21 | 'conditions' => array( |
||
| 22 | 'LancamentoVenda.venda_id' => $id_venda |
||
| 23 | ) |
||
| 24 | ) |
||
| 25 | ); |
||
| 26 | |||
| 27 | $this->LancamentoVenda->id = $response['LancamentoVenda']['id']; |
||
| 28 | |||
| 29 | $this->LancamentoVenda->save( |
||
| 30 | ['valor_pago' => 0] |
||
| 31 | ); |
||
| 32 | |||
| 33 | echo json_encode( |
||
| 34 | [ |
||
| 35 | 'valor' => $response['LancamentoVenda']['valor'] |
||
| 36 | ] |
||
| 37 | ); |
||
| 38 | exit; |
||
| 39 | |||
| 40 | } |
||
| 41 | |||
| 64 | } |
Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.
Let’s take a look at an example:
As you can see in this example, the array
$myArrayis initialized the first time when the foreach loop is entered. You can also see that the value of thebarkey is only written conditionally; thus, its value might result from a previous iteration.This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.