Completed
Pull Request — master (#80)
by Reginaldo
20:15
created

LancamentoVendasController::aprovar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 21
Code Lines 10

Duplication

Lines 21
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 2
dl 21
loc 21
rs 9.3142
c 0
b 0
f 0
1
<?php
2
3
class LancamentoVendasController extends AppController {
4
5
	public function salvar_lancamento($id_venda, $dados, $valor_total, $id_usuario) {
6
		$lancamento['venda_id']   = $id_venda;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$lancamento was never initialized. Although not strictly required by PHP, it is generally a good practice to add $lancamento = array(); before regardless.

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:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key 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.

Loading history...
7
		$lancamento['valor'] = $valor_total;
8
		$lancamento['valor_pago'] = $valor_total;
9
		$lancamento['data_pgt']   = date('Y-m-d');
10
		$lancamento['ativo']	  = 1;
11
		$lancamento['usuario_id'] = $id_usuario;
12
		$lancamento['forma_pagamento'] = $dados['forma_pagamento'];
13
14
		$this->LancamentoVenda->save($lancamento);
15
16
		return true;
17
 	}
18
19 View Code Duplication
 	public function cancelar($id_venda, $id_cliente) {
0 ignored issues
show
Unused Code introduced by
The parameter $id_cliente is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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;
0 ignored issues
show
Coding Style Compatibility introduced by
The method cancelar() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
39
40
 	}
41
42 View Code Duplication
 	public function aprovar($id_venda, $id_cliente) {
0 ignored issues
show
Unused Code introduced by
The parameter $id_cliente is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
43
 		$response = $this->LancamentoVenda->find('first', array(
44
    			'conditions' => array(
45
    				'LancamentoVenda.venda_id' => $id_venda
46
    			)
47
    		)
48
    	);
49
50
 		$this->LancamentoVenda->id = $response['LancamentoVenda']['id'];
51
52
 		$this->LancamentoVenda->save(
53
 			['valor_pago' => $response['LancamentoVenda']['valor']]
54
 		);
55
 		
56
 		echo json_encode(
57
 			[
58
 				'valor' => $response['LancamentoVenda']['valor']
59
 			]
60
 		);
61
 		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method aprovar() contains an exit expression.

An exit expression should only be used in rare cases. For example, if you write a short command line script.

In most cases however, using an exit expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.

Loading history...
62
 	}
63
64
}