Completed
Push — master ( 578d73...cb0792 )
by Reginaldo
33:30
created

OrcamentoController   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 111
Duplicated Lines 15.32 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 17
loc 111
rs 10
wmc 4
lcom 1
cbo 2

4 Methods

Rating   Name   Duplication   Size   Complexity  
A listar_cadastros() 17 17 1
A salvar_orcamento() 0 4 1
A pdf() 0 17 1
A pegar_venda_como_html() 0 65 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
require_once(ROOT . DS . 'vendor' . DS . 'autoload.php');
4
5
use Dompdf\Dompdf;
6
7
class OrcamentoController extends AppController 
8
{
9
10 View Code Duplication
	public function listar_cadastros()
11
	{
12
		$this->layout = 'wadmin';
13
14
		$this->loadModel('Venda');
15
16
		$this->set('vendas', $this->Venda->find('all',
17
				array('conditions' =>
18
					array(
19
						'ativo' => 1,
20
						'id_usuario' => $this->instancia,
21
						'orcamento' => 1
22
					)
23
				)
24
			)
25
		);
26
	}
27
28
	public function salvar_orcamento()
29
	{
30
		$this->layout = 'wadmin';
31
	}
32
33
	public function pdf($vendaId)
0 ignored issues
show
Unused Code introduced by
The parameter $vendaId 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...
34
	{
35
		// instantiate and use the dompdf class
36
		$dompdf = new Dompdf();
37
38
		$html = $this->pegar_venda_como_html();
39
40
		$dompdf->loadHtml($html);
41
42
		$dompdf->setPaper('A4');
43
44
		$dompdf->render();
45
46
		$dompdf->stream();
47
48
		exit;
0 ignored issues
show
Coding Style Compatibility introduced by
The method pdf() 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...
49
	}
50
51
	public function pegar_venda_como_html()
52
	{
53
		$html = '';
54
		$html .= '<html>';
55
		$html .= '<head>';
56
		$html .= '	<title></title>';
57
		$html .= '</head>';
58
		$html .= '<body>';
59
		$html .= '';
60
		$html .= '	<table style="background-color: #cacaca;"  width="100%" valign="center" align="center">';
61
		$html .= '		<tr align="center">';
62
		$html .= '			<td>';
63
		$html .= '				<h2>Orçamento Pedido #1</h2>';
64
		$html .= '			</td>';
65
		$html .= '		</tr> ';
66
		$html .= '	</table>';
67
		$html .= '	<br>';
68
		$html .= '	<table width="100%" valign="center" align="center">';
69
		$html .= '		<tr  style="background-color: #ccc;">';
70
		$html .= '			<td>Total: </td>';
71
		$html .= '			<td>R$ 24,55</td>';
72
		$html .= '		</tr>';
73
		$html .= '		<tr  style="background-color: #fff;">';
74
		$html .= '			<td>Desconto: </td>';
75
		$html .= '			<td>R$ 4,55</td>';
76
		$html .= '		</tr>';
77
		$html .= '		<tr  style="background-color: #ccc;">';
78
		$html .= '			<td>Valor a Pagar: </td>';
79
		$html .= '			<td>R$ 4,55</td>';
80
		$html .= '		</tr>';
81
		$html .= '	</table>';
82
		$html .= '	<br>';
83
		$html .= '	<table  width="100%" valign="center" align="center">';
84
		$html .= '		<tr style="background-color: #cacaca;" align="center">';
85
		$html .= '			<td>';
86
		$html .= '				<h2>Produtos</h2>';
87
		$html .= '			</td>';
88
		$html .= '		</tr> ';
89
		$html .= '	</table>';
90
		$html .= '	<br>';
91
		$html .= '	<table  width="100%" valign="center" align="center">';
92
		$html .= '		<tr>';
93
		$html .= '			<td>';
94
		$html .= '				<table width="100%" valign="center" align="center">';
95
		$html .= '					<tr style="background-color: #cacaca;">';
96
		$html .= '						<td>Nome Produto</td>';
97
		$html .= '						<td>Quantidade</td>';
98
		$html .= '						<td>Valor</td>';
99
		$html .= '					</tr>';
100
		$html .= '';
101
		$html .= '					<tr>';
102
		$html .= '						<td>Alicate 14"</td>';
103
		$html .= '						<td>1</td>';
104
		$html .= '						<td>R$ 23,00</td>';
105
		$html .= '					</tr>';
106
		$html .= '				</table>';
107
		$html .= '			</td>';
108
		$html .= '		</tr>';
109
		$html .= '	</table>';
110
		$html .= '';
111
		$html .= '</body>';
112
		$html .= '</html>';
113
114
		return $html;
115
	}
116
117
}