@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * |
60 | 60 | * @param array $components An array of arrays of component arguments |
61 | 61 | */ |
62 | - public function __construct( array $components = array() ) |
|
62 | + public function __construct(array $components = array()) |
|
63 | 63 | { |
64 | 64 | $this->add_components($components); |
65 | 65 | } |
@@ -81,18 +81,18 @@ discard block |
||
81 | 81 | * |
82 | 82 | * @return array The updated values array. |
83 | 83 | */ |
84 | - public function update( array $new_instance = array(), array $old_instance = array() ) |
|
84 | + public function update(array $new_instance = array(), array $old_instance = array()) |
|
85 | 85 | { |
86 | - $this->old_instance = array_merge($this->get_defaults(),$old_instance); |
|
87 | - $this->new_instance = array_merge($this->old_instance,$new_instance); |
|
86 | + $this->old_instance = array_merge($this->get_defaults(), $old_instance); |
|
87 | + $this->new_instance = array_merge($this->old_instance, $new_instance); |
|
88 | 88 | $this->final_instance = $this->new_instance; |
89 | 89 | |
90 | - foreach ( $this->components as $component ) |
|
90 | + foreach ($this->components as $component) |
|
91 | 91 | { |
92 | 92 | // Update individual fields, as well as the composite parent field. |
93 | - if ( $component instanceof ValueComponentInterface ) |
|
93 | + if ($component instanceof ValueComponentInterface) |
|
94 | 94 | { |
95 | - $this->update_component( $component ); |
|
95 | + $this->update_component($component); |
|
96 | 96 | } |
97 | 97 | } |
98 | 98 | |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function reset() |
108 | 108 | { |
109 | - foreach( $this->components as $c ) |
|
109 | + foreach ($this->components as $c) |
|
110 | 110 | { |
111 | 111 | $c->value = $c->default; |
112 | 112 | $this->final_instance[$c->name] = $c->default; |
@@ -131,10 +131,10 @@ discard block |
||
131 | 131 | * @param array $args The component arguments |
132 | 132 | * @throws \RuntimeException If a component with the same name has already been registered |
133 | 133 | */ |
134 | - public function add_component( array $args ) |
|
134 | + public function add_component(array $args) |
|
135 | 135 | { |
136 | 136 | $name = $args['name']; |
137 | - if(array_key_exists($name, $this->components)) |
|
137 | + if (array_key_exists($name, $this->components)) |
|
138 | 138 | { |
139 | 139 | throw new \RuntimeException("A component with the name <b>$name</b> has already been created"); |
140 | 140 | } |
@@ -146,9 +146,9 @@ discard block |
||
146 | 146 | * |
147 | 147 | * @param array $components |
148 | 148 | */ |
149 | - public function add_components( array $components ) |
|
149 | + public function add_components(array $components) |
|
150 | 150 | { |
151 | - foreach( $components as $component ) |
|
151 | + foreach ($components as $component) |
|
152 | 152 | { |
153 | 153 | $this->add_component($component); |
154 | 154 | } |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | * @param string $name |
161 | 161 | * @return UI\AbstractComponent |
162 | 162 | */ |
163 | - public function get_component( $name ) |
|
163 | + public function get_component($name) |
|
164 | 164 | { |
165 | 165 | return $this->components[$name]; |
166 | 166 | } |
@@ -182,21 +182,21 @@ discard block |
||
182 | 182 | * |
183 | 183 | * @param ValueComponentInterface $component The component to validate. |
184 | 184 | */ |
185 | - private function update_component( ValueComponentInterface $component ) |
|
185 | + private function update_component(ValueComponentInterface $component) |
|
186 | 186 | { |
187 | 187 | $component->value = $this->final_instance[$component->name]; |
188 | 188 | |
189 | 189 | // Skip if this field is disabled |
190 | - if( $this->is_disabled($component) ) |
|
190 | + if ($this->is_disabled($component)) |
|
191 | 191 | { |
192 | 192 | return; |
193 | 193 | } |
194 | 194 | |
195 | 195 | // Apply user-defined filter |
196 | - $this->filter( $component ); |
|
196 | + $this->filter($component); |
|
197 | 197 | |
198 | 198 | // Validate value |
199 | - $this->validate( $component ); |
|
199 | + $this->validate($component); |
|
200 | 200 | } |
201 | 201 | |
202 | 202 | /** |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | * @param UI\AbstractComponent $component |
206 | 206 | * @return boolean |
207 | 207 | */ |
208 | - private function is_disabled( $component ) |
|
208 | + private function is_disabled($component) |
|
209 | 209 | { |
210 | 210 | return |
211 | 211 | $component instanceof DisableableComponentInterface && |
@@ -220,13 +220,13 @@ discard block |
||
220 | 220 | * |
221 | 221 | * @param UI\AbstractComponent $component |
222 | 222 | */ |
223 | - private function filter( $component ) |
|
223 | + private function filter($component) |
|
224 | 224 | { |
225 | - if( $component instanceof FilterableComponentInterface ) |
|
225 | + if ($component instanceof FilterableComponentInterface) |
|
226 | 226 | { |
227 | 227 | $filter = $component->filter; |
228 | 228 | |
229 | - if( is_callable( $filter ) ) |
|
229 | + if (is_callable($filter)) |
|
230 | 230 | { |
231 | 231 | $component->value = \call_user_func_array($filter, array($this->final_instance[$component->name])); |
232 | 232 | $this->final_instance[$component->name] = $component->value; |
@@ -242,22 +242,22 @@ discard block |
||
242 | 242 | * |
243 | 243 | * @param UI\AbstractComponent $component The component to validate. |
244 | 244 | */ |
245 | - private function validate( $component ) |
|
245 | + private function validate($component) |
|
246 | 246 | { |
247 | - if( !($component instanceof ValidatableComponentInterface) ) return; |
|
247 | + if (!($component instanceof ValidatableComponentInterface)) return; |
|
248 | 248 | |
249 | 249 | $name = $component->name; |
250 | 250 | $validate = $component->validation; |
251 | 251 | |
252 | 252 | $component->validity = $component::VALID; |
253 | 253 | |
254 | - if(is_callable($validate)) |
|
254 | + if (is_callable($validate)) |
|
255 | 255 | { |
256 | 256 | $error = ''; |
257 | 257 | $valid = \call_user_func_array($validate, array($this->final_instance[$name], &$error)); |
258 | 258 | |
259 | 259 | // Invalid input, use old instance or default value |
260 | - if ( true !== $valid ) |
|
260 | + if (true !== $valid) |
|
261 | 261 | { |
262 | 262 | $this->errors[$name] = $error ? $error : ValidatableComponentInterface::DEFAULT_MESSAGE; |
263 | 263 | $component->value = $this->old_instance[$name]; |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | { |
277 | 277 | $defaults = array(); |
278 | 278 | |
279 | - foreach( $this->components as $component ) |
|
279 | + foreach ($this->components as $component) |
|
280 | 280 | { |
281 | 281 | $defaults[$component->name] = $component->default; |
282 | 282 | } |