Completed
Push — master ( 958b40...3f4f2c )
by Askupa
01:39
created
Form.php 1 patch
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
      * 
60 60
      * @param ComponentList $component_list
61 61
      */
62
-    public function __construct( ComponentList $component_list = null )
62
+    public function __construct(ComponentList $component_list = null)
63 63
     {
64
-        if(null === $component_list)
64
+        if (null === $component_list)
65 65
         {
66 66
             $component_list = new ComponentList();
67 67
         }
@@ -85,16 +85,16 @@  discard block
 block discarded – undo
85 85
      * 
86 86
      * @return array The updated values array.
87 87
      */
88
-    public function update( array $new_instance = array(), array $old_instance = array() )
88
+    public function update(array $new_instance = array(), array $old_instance = array())
89 89
     {
90
-        $this->old_instance   = array_merge($this->get_defaults(),$old_instance);
91
-        $this->new_instance   = array_merge($this->old_instance,$new_instance);
90
+        $this->old_instance   = array_merge($this->get_defaults(), $old_instance);
91
+        $this->new_instance   = array_merge($this->old_instance, $new_instance);
92 92
         $this->final_instance = $this->new_instance;
93 93
         
94
-        foreach ( $this->component_list->get_value_components() as $component ) 
94
+        foreach ($this->component_list->get_value_components() as $component) 
95 95
         {
96 96
             // Update individual fields, as well as the composite parent field.
97
-            $this->update_component( $component );
97
+            $this->update_component($component);
98 98
         }
99 99
         
100 100
         return $this->final_instance;
@@ -118,9 +118,9 @@  discard block
 block discarded – undo
118 118
      * @param array $components
119 119
      * @return void
120 120
      */
121
-    public function reset_components( array $components )
121
+    public function reset_components(array $components)
122 122
     {
123
-        foreach( $components as $component )
123
+        foreach ($components as $component)
124 124
         {
125 125
             $this->reset_component($component);
126 126
         }
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
      * @param AbstractComponent $component
134 134
      * @return void
135 135
      */
136
-    public function reset_component( $component )
136
+    public function reset_component($component)
137 137
     {
138 138
         $component->value = $component->default;
139 139
         $this->final_instance[$component->name] = $component->default;
@@ -168,21 +168,21 @@  discard block
 block discarded – undo
168 168
      * 
169 169
      * @param ValueComponentInterface $component The component to validate.
170 170
      */
171
-    private function update_component( ValueComponentInterface $component )
171
+    private function update_component(ValueComponentInterface $component)
172 172
     {
173 173
         $component->value = $this->final_instance[$component->name];
174 174
         
175 175
         // Skip if this field is disabled
176
-        if( $this->is_disabled($component) )
176
+        if ($this->is_disabled($component))
177 177
         {
178 178
             return;
179 179
         }
180 180
 
181 181
         // Apply user-defined filter
182
-        $this->filter( $component );
182
+        $this->filter($component);
183 183
         
184 184
         // Validate value
185
-        $this->validate( $component );
185
+        $this->validate($component);
186 186
     }
187 187
     
188 188
     /**
@@ -191,7 +191,7 @@  discard block
 block discarded – undo
191 191
      * @param UI\AbstractComponent $component
192 192
      * @return boolean
193 193
      */
194
-    private function is_disabled( $component )
194
+    private function is_disabled($component)
195 195
     {
196 196
         return 
197 197
             $component instanceof DisableableComponentInterface &&
@@ -206,13 +206,13 @@  discard block
 block discarded – undo
206 206
      * 
207 207
      * @param UI\AbstractComponent $component
208 208
      */
209
-    private function filter( $component )
209
+    private function filter($component)
210 210
     {
211
-        if( $component instanceof FilterableComponentInterface )
211
+        if ($component instanceof FilterableComponentInterface)
212 212
         {
213 213
             $filter = $component->filter;
214 214
 
215
-            if( is_callable( $filter ) ) 
215
+            if (is_callable($filter)) 
216 216
             {
217 217
                 $component->value = \call_user_func_array($filter, array($this->final_instance[$component->name]));
218 218
                 $this->final_instance[$component->name] = $component->value;
@@ -228,22 +228,22 @@  discard block
 block discarded – undo
228 228
      * 
229 229
      * @param UI\AbstractComponent $component The component to validate.
230 230
      */
231
-    private function validate( $component )
231
+    private function validate($component)
232 232
     {
233
-        if( !($component instanceof ValidatableComponentInterface) ) return;
233
+        if (!($component instanceof ValidatableComponentInterface)) return;
234 234
         
235 235
         $name     = $component->name;
236 236
         $validate = $component->validation;
237 237
         
238 238
         $component->validity = $component::VALID;
239 239
         
240
-        if(is_callable($validate))
240
+        if (is_callable($validate))
241 241
         {
242 242
             $error = '';
243 243
             $valid = \call_user_func_array($validate, array($this->final_instance[$name], &$error));
244 244
             
245 245
             // Invalid input, use old instance or default value
246
-            if ( true !== $valid ) 
246
+            if (true !== $valid) 
247 247
             {
248 248
                 $this->errors[$name]         = $error ? $error : ValidatableComponentInterface::DEFAULT_MESSAGE;
249 249
                 $component->value            = $this->old_instance[$name];
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
     {
263 263
         $defaults = array();
264 264
         
265
-        foreach( $this->component_list->get_value_components() as $component )
265
+        foreach ($this->component_list->get_value_components() as $component)
266 266
         {
267 267
             $defaults[$component->name] = $component->default;
268 268
         }
Please login to merge, or discard this patch.