Completed
Push — master ( 67c338...c7b167 )
by Wanderson
04:24
created

Select   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
lcom 0
cbo 0
dl 0
loc 39
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 7 2
A active() 0 5 2
1
<?php
2
3
/**
4
 * Select
5
 * Auxilia nas <select>
6
 * @author WebCorpore
7
 */
8
9
namespace Win\Html\Form;
10
11
class Select {
12
13
	private $options = [];
14
	private $currentValue;
15
16
	/**
17
	 * Cria o select com os <option>'s
18
	 * @param string[] $options array com titulo dos options
19
	 * @param string $currentValue option que será selecionado
20
	 */
21
	public function __construct($options = [], $currentValue = '') {
22
		$this->options = $options;
23
		$this->currentValue = $currentValue;
24
	}
25
26
	/**
27
	 * Exibe os <option>'s do select
28
	 * @return string
29
	 */
30
	public function __toString() {
31
		$html = '';
32
		foreach ($this->options as $option):
33
			$html .= '<option value="' . $option . '" ' . static::active($option, $this->currentValue) . '>' . $option . '</option>';
34
		endforeach;
35
		return $html;
36
	}
37
38
	/**
39
	 * Retorna selected="true" se os valores são iguais
40
	 * @param mixed $value1
41
	 * @param mixed $value2
42
	 */
43
	public static function active($value1, $value2 = true) {
44
		if ($value1 == $value2) {
45
			return 'selected="true"';
46
		}
47
	}
48
49
}
50