Completed
Push — master ( e9bdcb...b0560a )
by Jean-Christophe
04:52
created

BaseTrait::setVariations()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 9
Code Lines 7

Duplication

Lines 9
Ratio 100 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 9
loc 9
rs 9.6666
cc 3
eloc 7
nc 4
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
use Ajax\semantic\html\base\constants\Direction;
8
9
trait BaseTrait {
10
	protected $_variations=[ ];
11
	protected $_states=[ ];
12
	protected $_baseClass;
13
14
	protected abstract function setPropertyCtrl($name, $value, $typeCtrl);
15
16
	protected abstract function addToPropertyCtrl($name, $value, $typeCtrl);
17
18
	protected abstract function addToPropertyCtrlCheck($name, $value, $typeCtrl);
19
20
	public abstract function addToProperty($name, $value, $separator=" ");
21
22
	public function addVariation($variation) {
23
		return $this->addToPropertyCtrlCheck("class", $variation, $this->_variations);
24
	}
25
26
	public function addState($state) {
27
		return $this->addToPropertyCtrlCheck("class", $state, $this->_states);
28
	}
29
30
	public function setVariation($variation) {
31
		$this->setPropertyCtrl("class", $variation, $this->_variations);
32
		return $this->addToProperty("class", $this->_baseClass);
33
	}
34
35 View Code Duplication
	public function setVariations($variations) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
36
		$this->setProperty("class", $this->_baseClass);
0 ignored issues
show
Bug introduced by
The method setProperty() does not exist on Ajax\semantic\html\base\traits\BaseTrait. Did you maybe mean setPropertyCtrl()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
37
		if (\is_string($variations))
38
			$variations=\explode(" ", $variations);
39
		foreach ( $variations as $variation ) {
40
			$this->addVariation($variation);
41
		}
42
		return $this;
43
	}
44
45
	public function setState($state) {
46
		$this->setPropertyCtrl("class", $state, $this->_states);
47
		return $this->addToProperty("class", $this->_baseClass);
48
	}
49
50
	public function addVariations($variations=array()) {
51
		if (\is_string($variations))
52
			$variations=\explode(" ", $variations);
53
		foreach ( $variations as $variation ) {
54
			$this->addVariation($variation);
55
		}
56
		return $this;
57
	}
58
59
	public function addStates($states=array()) {
60
		if (\is_string($states))
61
			$states=\explode(" ", $states);
62
		foreach ( $states as $state ) {
63
			$this->addState($state);
64
		}
65
		return $this;
66
	}
67
68 View Code Duplication
	public function setStates($states) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
		$this->setProperty("class", $this->_baseClass);
0 ignored issues
show
Bug introduced by
The method setProperty() does not exist on Ajax\semantic\html\base\traits\BaseTrait. Did you maybe mean setPropertyCtrl()?

This check marks calls to methods that do not seem to exist on an object.

This is most likely the result of a method being renamed without all references to it being renamed likewise.

Loading history...
70
		if (\is_string($states))
71
			$states=\explode(" ", $states);
72
		foreach ( $states as $state ) {
73
			$this->addState($state);
74
		}
75
		return $this;
76
	}
77
78
	/**
79
	 *
80
	 * {@inheritDoc}
81
	 *
82
	 * @see \Ajax\common\html\HtmlSingleElement::setSize()
83
	 */
84
	public function setSize($size) {
85
		return $this->addToPropertyCtrl("class", $size, Size::getConstants());
86
	}
87
88
	/**
89
	 * show it is currently unable to be interacted with
90
	 * @return \Ajax\semantic\html\elements\HtmlSemDoubleElement
91
	 */
92
	public function setDisabled() {
93
		return $this->addToProperty("class", "disabled");
94
	}
95
96
	/**
97
	 *
98
	 * @param string $color
99
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
100
	 */
101
	public function setColor($color) {
102
		return $this->addToPropertyCtrl("class", $color, Color::getConstants());
103
	}
104
105
	/**
106
	 *
107
	 * @return \Ajax\semantic\html\base\HtmlSemDoubleElement
108
	 */
109
	public function setFluid() {
110
		return $this->addToProperty("class", "fluid");
111
	}
112
113
	/**
114
	 * can be formatted to appear on dark backgrounds
115
	 */
116
	public function setInverted() {
117
		return $this->addToProperty("class", "inverted");
118
	}
119
120
	public function setCircular() {
121
		return $this->addToProperty("class", "circular");
122
	}
123
124
	public function setFloated($direction="right") {
125
		return $this->addToPropertyCtrl("class", $direction . " floated", Direction::getConstantValues("floated"));
126
	}
127
128
	public function floatRight() {
129
		return $this->setFloated();
130
	}
131
132
	public function floatLeft() {
133
		return $this->setFloated("left");
134
	}
135
136
	public function getBaseClass() {
137
		return $this->_baseClass;
138
	}
139
}