Completed
Push — master ( a0b85b...774d12 )
by Wanderson
20:21
created

Select::__toString()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
dl 0
loc 7
rs 9.4285
c 1
b 0
f 1
cc 2
eloc 6
nc 2
nop 0
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