@@ -26,19 +26,19 @@ discard block |
||
26 | 26 | */ |
27 | 27 | trait Traits_Optionable |
28 | 28 | { |
29 | - /** |
|
30 | - * @var array |
|
31 | - */ |
|
29 | + /** |
|
30 | + * @var array |
|
31 | + */ |
|
32 | 32 | protected $options; |
33 | 33 | |
34 | - /** |
|
35 | - * Sets an option to the specified value. This can be any |
|
36 | - * kind of variable type, including objects, as needed. |
|
37 | - * |
|
38 | - * @param string $name |
|
39 | - * @param mixed $default |
|
40 | - * @return Interface_Optionable |
|
41 | - */ |
|
34 | + /** |
|
35 | + * Sets an option to the specified value. This can be any |
|
36 | + * kind of variable type, including objects, as needed. |
|
37 | + * |
|
38 | + * @param string $name |
|
39 | + * @param mixed $default |
|
40 | + * @return Interface_Optionable |
|
41 | + */ |
|
42 | 42 | public function setOption(string $name, $value) |
43 | 43 | { |
44 | 44 | if(!isset($this->options)) { |
@@ -49,13 +49,13 @@ discard block |
||
49 | 49 | return $this; |
50 | 50 | } |
51 | 51 | |
52 | - /** |
|
53 | - * Sets a collection of options at once, from an |
|
54 | - * associative array. |
|
55 | - * |
|
56 | - * @param array $options |
|
57 | - * @return Interface_Optionable |
|
58 | - */ |
|
52 | + /** |
|
53 | + * Sets a collection of options at once, from an |
|
54 | + * associative array. |
|
55 | + * |
|
56 | + * @param array $options |
|
57 | + * @return Interface_Optionable |
|
58 | + */ |
|
59 | 59 | public function setOptions(array $options) |
60 | 60 | { |
61 | 61 | foreach($options as $name => $value) { |
@@ -65,16 +65,16 @@ discard block |
||
65 | 65 | return $this; |
66 | 66 | } |
67 | 67 | |
68 | - /** |
|
69 | - * Retrieves an option's value. |
|
70 | - * |
|
71 | - * NOTE: Use the specialized type getters to ensure an option |
|
72 | - * contains the expected type (for ex. getArrayOption()). |
|
73 | - * |
|
74 | - * @param string $name |
|
75 | - * @param mixed $default The default value to return if the option does not exist. |
|
76 | - * @return mixed |
|
77 | - */ |
|
68 | + /** |
|
69 | + * Retrieves an option's value. |
|
70 | + * |
|
71 | + * NOTE: Use the specialized type getters to ensure an option |
|
72 | + * contains the expected type (for ex. getArrayOption()). |
|
73 | + * |
|
74 | + * @param string $name |
|
75 | + * @param mixed $default The default value to return if the option does not exist. |
|
76 | + * @return mixed |
|
77 | + */ |
|
78 | 78 | public function getOption(string $name, $default=null) |
79 | 79 | { |
80 | 80 | if(!isset($this->options)) { |
@@ -88,16 +88,16 @@ discard block |
||
88 | 88 | return $default; |
89 | 89 | } |
90 | 90 | |
91 | - /** |
|
92 | - * Enforces that the option value is a string. Numbers are converted |
|
93 | - * to string, strings are passed through, and all other types will |
|
94 | - * return the default value. The default value is also returned if |
|
95 | - * the string is empty. |
|
96 | - * |
|
97 | - * @param string $name |
|
98 | - * @param string $default Used if the option does not exist, is invalid, or empty. |
|
99 | - * @return string |
|
100 | - */ |
|
91 | + /** |
|
92 | + * Enforces that the option value is a string. Numbers are converted |
|
93 | + * to string, strings are passed through, and all other types will |
|
94 | + * return the default value. The default value is also returned if |
|
95 | + * the string is empty. |
|
96 | + * |
|
97 | + * @param string $name |
|
98 | + * @param string $default Used if the option does not exist, is invalid, or empty. |
|
99 | + * @return string |
|
100 | + */ |
|
101 | 101 | public function getStringOption(string $name, string $default='') : string |
102 | 102 | { |
103 | 103 | $value = $this->getOption($name, false); |
@@ -109,15 +109,15 @@ discard block |
||
109 | 109 | return $default; |
110 | 110 | } |
111 | 111 | |
112 | - /** |
|
113 | - * Treats the option value as a boolean value: will return |
|
114 | - * true if the value actually is a boolean true. |
|
115 | - * |
|
116 | - * NOTE: boolean string representations are not accepted. |
|
117 | - * |
|
118 | - * @param string $name |
|
119 | - * @return bool |
|
120 | - */ |
|
112 | + /** |
|
113 | + * Treats the option value as a boolean value: will return |
|
114 | + * true if the value actually is a boolean true. |
|
115 | + * |
|
116 | + * NOTE: boolean string representations are not accepted. |
|
117 | + * |
|
118 | + * @param string $name |
|
119 | + * @return bool |
|
120 | + */ |
|
121 | 121 | public function getBoolOption(string $name, bool $default=false) : bool |
122 | 122 | { |
123 | 123 | if($this->getOption($name) === true) { |
@@ -127,15 +127,15 @@ discard block |
||
127 | 127 | return $default; |
128 | 128 | } |
129 | 129 | |
130 | - /** |
|
131 | - * Treats the option value as an integer value: will return |
|
132 | - * valid integer values (also from integer strings), or the |
|
133 | - * default value otherwise. |
|
134 | - * |
|
135 | - * @param string $name |
|
136 | - * @param int $default |
|
137 | - * @return int |
|
138 | - */ |
|
130 | + /** |
|
131 | + * Treats the option value as an integer value: will return |
|
132 | + * valid integer values (also from integer strings), or the |
|
133 | + * default value otherwise. |
|
134 | + * |
|
135 | + * @param string $name |
|
136 | + * @param int $default |
|
137 | + * @return int |
|
138 | + */ |
|
139 | 139 | public function getIntOption(string $name, int $default=0) : int |
140 | 140 | { |
141 | 141 | $value = $this->getOption($name); |
@@ -146,14 +146,14 @@ discard block |
||
146 | 146 | return $default; |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Treats an option as an array, and returns its value |
|
151 | - * only if it contains an array - otherwise, an empty |
|
152 | - * array is returned. |
|
153 | - * |
|
154 | - * @param string $name |
|
155 | - * @return array |
|
156 | - */ |
|
149 | + /** |
|
150 | + * Treats an option as an array, and returns its value |
|
151 | + * only if it contains an array - otherwise, an empty |
|
152 | + * array is returned. |
|
153 | + * |
|
154 | + * @param string $name |
|
155 | + * @return array |
|
156 | + */ |
|
157 | 157 | public function getArrayOption(string $name) : array |
158 | 158 | { |
159 | 159 | $val = $this->getOption($name); |
@@ -164,13 +164,13 @@ discard block |
||
164 | 164 | return array(); |
165 | 165 | } |
166 | 166 | |
167 | - /** |
|
168 | - * Checks whether the specified option exists - even |
|
169 | - * if it has a NULL value. |
|
170 | - * |
|
171 | - * @param string $name |
|
172 | - * @return bool |
|
173 | - */ |
|
167 | + /** |
|
168 | + * Checks whether the specified option exists - even |
|
169 | + * if it has a NULL value. |
|
170 | + * |
|
171 | + * @param string $name |
|
172 | + * @return bool |
|
173 | + */ |
|
174 | 174 | public function hasOption(string $name) : bool |
175 | 175 | { |
176 | 176 | if(!isset($this->options)) { |
@@ -180,10 +180,10 @@ discard block |
||
180 | 180 | return array_key_exists($name, $this->options); |
181 | 181 | } |
182 | 182 | |
183 | - /** |
|
184 | - * Returns all options in one associative array. |
|
185 | - * @return array |
|
186 | - */ |
|
183 | + /** |
|
184 | + * Returns all options in one associative array. |
|
185 | + * @return array |
|
186 | + */ |
|
187 | 187 | public function getOptions() : array |
188 | 188 | { |
189 | 189 | if(!isset($this->options)) { |
@@ -193,24 +193,24 @@ discard block |
||
193 | 193 | return $this->options; |
194 | 194 | } |
195 | 195 | |
196 | - /** |
|
197 | - * Checks whether the option's value is the one specified. |
|
198 | - * |
|
199 | - * @param string $name |
|
200 | - * @param mixed $value |
|
201 | - * @return bool |
|
202 | - */ |
|
196 | + /** |
|
197 | + * Checks whether the option's value is the one specified. |
|
198 | + * |
|
199 | + * @param string $name |
|
200 | + * @param mixed $value |
|
201 | + * @return bool |
|
202 | + */ |
|
203 | 203 | public function isOption(string $name, $value) : bool |
204 | 204 | { |
205 | 205 | return $this->getOption($name) === $value; |
206 | 206 | } |
207 | 207 | |
208 | - /** |
|
209 | - * Retrieves the default available options as an |
|
210 | - * associative array with option name => value pairs. |
|
211 | - * |
|
212 | - * @return array |
|
213 | - */ |
|
208 | + /** |
|
209 | + * Retrieves the default available options as an |
|
210 | + * associative array with option name => value pairs. |
|
211 | + * |
|
212 | + * @return array |
|
213 | + */ |
|
214 | 214 | abstract public function getDefaultOptions() : array; |
215 | 215 | } |
216 | 216 | |
@@ -228,24 +228,24 @@ discard block |
||
228 | 228 | */ |
229 | 229 | interface Interface_Optionable |
230 | 230 | { |
231 | - /** |
|
232 | - * @param string $name |
|
233 | - * @param mixed $value |
|
234 | - * @return Interface_Optionable |
|
235 | - */ |
|
231 | + /** |
|
232 | + * @param string $name |
|
233 | + * @param mixed $value |
|
234 | + * @return Interface_Optionable |
|
235 | + */ |
|
236 | 236 | function setOption(string $name, $value); |
237 | 237 | |
238 | - /** |
|
239 | - * @param string $name |
|
240 | - * @param mixed $default |
|
241 | - * @return Interface_Optionable |
|
242 | - */ |
|
238 | + /** |
|
239 | + * @param string $name |
|
240 | + * @param mixed $default |
|
241 | + * @return Interface_Optionable |
|
242 | + */ |
|
243 | 243 | function getOption(string $name, $default=null); |
244 | 244 | |
245 | - /** |
|
246 | - * @param array $options |
|
247 | - * @return Interface_Optionable |
|
248 | - */ |
|
245 | + /** |
|
246 | + * @param array $options |
|
247 | + * @return Interface_Optionable |
|
248 | + */ |
|
249 | 249 | function setOptions(array $options); |
250 | 250 | function getOptions() : array; |
251 | 251 | function isOption(string $name, $value) : bool; |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public function setOption(string $name, $value) |
43 | 43 | { |
44 | - if(!isset($this->options)) { |
|
44 | + if (!isset($this->options)) { |
|
45 | 45 | $this->options = $this->getDefaultOptions(); |
46 | 46 | } |
47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | */ |
59 | 59 | public function setOptions(array $options) |
60 | 60 | { |
61 | - foreach($options as $name => $value) { |
|
61 | + foreach ($options as $name => $value) { |
|
62 | 62 | $this->setOption($name, $value); |
63 | 63 | } |
64 | 64 | |
@@ -75,13 +75,13 @@ discard block |
||
75 | 75 | * @param mixed $default The default value to return if the option does not exist. |
76 | 76 | * @return mixed |
77 | 77 | */ |
78 | - public function getOption(string $name, $default=null) |
|
78 | + public function getOption(string $name, $default = null) |
|
79 | 79 | { |
80 | - if(!isset($this->options)) { |
|
80 | + if (!isset($this->options)) { |
|
81 | 81 | $this->options = $this->getDefaultOptions(); |
82 | 82 | } |
83 | 83 | |
84 | - if(isset($this->options[$name])) { |
|
84 | + if (isset($this->options[$name])) { |
|
85 | 85 | return $this->options[$name]; |
86 | 86 | } |
87 | 87 | |
@@ -98,11 +98,11 @@ discard block |
||
98 | 98 | * @param string $default Used if the option does not exist, is invalid, or empty. |
99 | 99 | * @return string |
100 | 100 | */ |
101 | - public function getStringOption(string $name, string $default='') : string |
|
101 | + public function getStringOption(string $name, string $default = '') : string |
|
102 | 102 | { |
103 | 103 | $value = $this->getOption($name, false); |
104 | 104 | |
105 | - if((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
105 | + if ((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
106 | 106 | return (string)$value; |
107 | 107 | } |
108 | 108 | |
@@ -118,9 +118,9 @@ discard block |
||
118 | 118 | * @param string $name |
119 | 119 | * @return bool |
120 | 120 | */ |
121 | - public function getBoolOption(string $name, bool $default=false) : bool |
|
121 | + public function getBoolOption(string $name, bool $default = false) : bool |
|
122 | 122 | { |
123 | - if($this->getOption($name) === true) { |
|
123 | + if ($this->getOption($name) === true) { |
|
124 | 124 | return true; |
125 | 125 | } |
126 | 126 | |
@@ -136,10 +136,10 @@ discard block |
||
136 | 136 | * @param int $default |
137 | 137 | * @return int |
138 | 138 | */ |
139 | - public function getIntOption(string $name, int $default=0) : int |
|
139 | + public function getIntOption(string $name, int $default = 0) : int |
|
140 | 140 | { |
141 | 141 | $value = $this->getOption($name); |
142 | - if(ConvertHelper::isInteger($value)) { |
|
142 | + if (ConvertHelper::isInteger($value)) { |
|
143 | 143 | return (int)$value; |
144 | 144 | } |
145 | 145 | |
@@ -157,7 +157,7 @@ discard block |
||
157 | 157 | public function getArrayOption(string $name) : array |
158 | 158 | { |
159 | 159 | $val = $this->getOption($name); |
160 | - if(is_array($val)) { |
|
160 | + if (is_array($val)) { |
|
161 | 161 | return $val; |
162 | 162 | } |
163 | 163 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | */ |
174 | 174 | public function hasOption(string $name) : bool |
175 | 175 | { |
176 | - if(!isset($this->options)) { |
|
176 | + if (!isset($this->options)) { |
|
177 | 177 | $this->options = $this->getDefaultOptions(); |
178 | 178 | } |
179 | 179 | |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | */ |
187 | 187 | public function getOptions() : array |
188 | 188 | { |
189 | - if(!isset($this->options)) { |
|
189 | + if (!isset($this->options)) { |
|
190 | 190 | $this->options = $this->getDefaultOptions(); |
191 | 191 | } |
192 | 192 | |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | * @param mixed $default |
241 | 241 | * @return Interface_Optionable |
242 | 242 | */ |
243 | - function getOption(string $name, $default=null); |
|
243 | + function getOption(string $name, $default = null); |
|
244 | 244 | |
245 | 245 | /** |
246 | 246 | * @param array $options |