Completed
Push — master ( 916f6f...ea2a7d )
by Jean-Christophe
03:42
created

BaseTrait::setVariations()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 2
eloc 4
nc 2
nop 1
1
<?php
2
3
namespace Ajax\semantic\html\base\traits;
4
5
use Ajax\semantic\html\base\constants\Size;
6
use Ajax\semantic\html\base\constants\Color;
7
8
trait BaseTrait {
9
	protected $_variations=[ ];
10
	protected $_states=[ ];
11
	protected $_baseClass;
12
13
	protected abstract function setPropertyCtrl($name, $value, $typeCtrl);
14
15
	protected abstract function addToPropertyCtrl($name, $value, $typeCtrl);
16
17
	public abstract function addToProperty($name, $value, $separator=" ");
18
19
	public function addVariation($variation) {
20
		return $this->addToPropertyCtrl("class", $variation, $this->_variations);
21
	}
22
23
	public function addState($state) {
24
		return $this->addToPropertyCtrl("class", $state, $this->_states);
25
	}
26
27
	public function setVariation($variation) {
28
		$this->setPropertyCtrl("class", $variation, $this->_variations);
29
		return $this->addToProperty("class", $this->_baseClass);
30
	}
31
32
	public function setState($state) {
33
		$this->setPropertyCtrl("class", $state, $this->_states);
34
		return $this->addToProperty("class", $this->_baseClass);
35
	}
36
37
	public function setVariations($variations=array()) {
38
		foreach ( $variations as $variation ) {
39
			$this->setVariation($variation);
40
		}
41
		return $this;
42
	}
43
44
	public function setStates($states=array()) {
45
		foreach ( $states as $state ) {
46
			$this->setState($state);
47
		}
48
		return $this;
49
	}
50
51
	/**
52
	 *
53
	 * {@inheritDoc}
54
	 *
55
	 * @see \Ajax\common\html\HtmlSingleElement::setSize()
56
	 */
57
	public function setSize($size) {
58
		return $this->addToPropertyCtrl("class", $size, Size::getConstants());
59
	}
60
61
	/**
62
	 * show it is currently unable to be interacted with
63
	 * @return \Ajax\semantic\html\elements\HtmlSemDoubleElement
64
	 */
65
	public function setDisabled() {
66
		return $this->addToProperty("class", "disabled");
67
	}
68
69
	/**
70
	 *
71
	 * @param string $color
72
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
73
	 */
74
	public function setColor($color) {
75
		return $this->addToPropertyCtrl("class", $color, Color::getConstants());
76
	}
77
78
	/**
79
	 *
80
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
81
	 */
82
	public function setFluid() {
83
		return $this->addToProperty("class", "fluid");
84
	}
85
86
	/**
87
	 * can be formatted to appear on dark backgrounds
88
	 */
89
	public function setInverted() {
90
		return $this->addToProperty("class", "inverted");
91
	}
92
93
	public function setCircular() {
94
		return $this->addToProperty("class", "circular");
95
	}
96
}