VariacaoController   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 7
lcom 0
cbo 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A s_adicionar_variacao() 0 19 4
A desativar_variacoes() 0 14 3
1
<?php
2
3
class VariacaoController extends AppController {
4
5
	public function s_adicionar_variacao($variacoes, $produto_id, $usuario_id) {
6
		if (empty($variacoes) || empty($produto_id)) {
7
			return false;
8
		}
9
10
		foreach ($variacoes as $i => $variacao) {
11
			$this->Variacao->create();
12
13
			$dados['produto_id']    = $produto_id;
0 ignored issues
show
Coding Style Comprehensibility introduced by
$dados was never initialized. Although not strictly required by PHP, it is generally a good practice to add $dados = 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...
14
			$dados['usuario_id']    = $usuario_id;
15
			$dados['nome_variacao'] = $variacao['variacao'];
16
			$dados['estoque']		= $variacao['estoque'];
17
			$dados['ativo']			= 1;
18
19
			$this->Variacao->save($dados);
20
		} 
21
22
		return true;
23
	}
24
25
	public function desativar_variacoes($id) {
26
		if (empty($id)) {
27
			return false;
28
		}
29
30
		$dados = array ('ativo' => '0');
31
		$parametros = array ('produto_id' => $id);
32
33
		if (!$this->Variacao->updateAll($dados, $parametros)) {
34
			return false;
35
		}
36
37
		return true;
38
	}
39
40
}