Completed
Push — master ( a0b85b...774d12 )
by Wanderson
20:21
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 active() 0 5 2
A __construct() 0 4 1
A __toString() 0 7 2
1
<?php
2
3
/**
4
 * Select
5
 * Auxilia nas <select>
6
 *
7
 */
8
9
namespace Win\Html\Form;
10
11
class Select {
12
13
	protected $options;
14
	private $current;
15
16
	/**
17
	 * Retorna selected="true" se os valores são iguais
18
	 * @param mixed $value1
19
	 * @param mixed $value2
20
	 */
21
	public static function active($value1, $value2 = true) {
22
		if ($value1 == $value2) {
23
			return 'selected="true"';
24
		}
25
	}
26
27
	/**
28
	 * Cria um select com options, selecionando automatico
29
	 * @param string[] $options
30
	 * @param string $current
31
	 */
32
	public function __construct($options, $current = '') {
33
		$this->options = $options;
34
		$this->current = $current;
35
	}
36
37
	/**
38
	 * Exibe os options do select
39
	 * @return string
40
	 */
41
	public function __toString() {
42
		$html = '';
43
		foreach ($this->options as $option):
44
			$html .= '<option ' . static::active($option, $this->current) . ' value="' . $option . '">' . $option . '</option>';
45
		endforeach;
46
		return $html;
47
	}
48
49
}
50