Completed
Push — master ( bcd23f...ead358 )
by Askupa
01:57
created
Form.php 3 patches
Doc Comments   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
     /**
161 161
      * Check if the given component is disabled.
162 162
      * 
163
-     * @param UI\AbstractComponent $component
163
+     * @param ValueComponentInterface $component
164 164
      * @return boolean
165 165
      */
166 166
     private function is_disabled( $component )
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
     /**
177 177
      * Filter the component's value using its filter function (if applicable)
178 178
      * 
179
-     * @param UI\AbstractComponent $component
179
+     * @param ValueComponentInterface $component
180 180
      */
181 181
     private function filter( $component )
182 182
     {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
      * If the value is invalid, the old value is used, and an error message is
199 199
      * saved into the errors array as component_name => error_message.
200 200
      * 
201
-     * @param UI\AbstractComponent $component The component to validate.
201
+     * @param ValueComponentInterface $component The component to validate.
202 202
      */
203 203
     private function validate( $component )
204 204
     {
Please login to merge, or discard this patch.
Spacing   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -59,12 +59,12 @@  discard block
 block discarded – undo
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
-        foreach( $components as $args )
64
+        foreach ($components as $args)
65 65
         {
66 66
             $name = $args['name'];
67
-            if(array_key_exists($name, $components))
67
+            if (array_key_exists($name, $components))
68 68
             {
69 69
                 throw new \RuntimeException("A component with the name <b>$name</b> has already been created");
70 70
             }
@@ -89,18 +89,18 @@  discard block
 block discarded – undo
89 89
      * 
90 90
      * @return array The updated values array.
91 91
      */
92
-    public function update( array $new_instance, array $old_instance = array() )
92
+    public function update(array $new_instance, array $old_instance = array())
93 93
     {
94
-        $this->old_instance   = array_merge($this->get_defaults(),$old_instance);
95
-        $this->new_instance   = array_merge($this->old_instance,$new_instance);
94
+        $this->old_instance   = array_merge($this->get_defaults(), $old_instance);
95
+        $this->new_instance   = array_merge($this->old_instance, $new_instance);
96 96
         $this->final_instance = $this->new_instance;
97 97
         
98
-        foreach ( $this->components as $component ) 
98
+        foreach ($this->components as $component) 
99 99
         {
100 100
             // Update individual fields, as well as the composite parent field.
101
-            if ( $component instanceof ValueComponentInterface )
101
+            if ($component instanceof ValueComponentInterface)
102 102
             {
103
-                $this->update_component( $component );
103
+                $this->update_component($component);
104 104
             }
105 105
         }
106 106
         
@@ -114,7 +114,7 @@  discard block
 block discarded – undo
114 114
      */
115 115
     public function reset()
116 116
     {
117
-        foreach( $this->components as $c )
117
+        foreach ($this->components as $c)
118 118
         {
119 119
             $c->value = $c->default;
120 120
             $this->final_instance[$c->name] = $c->default;
@@ -140,21 +140,21 @@  discard block
 block discarded – undo
140 140
      * 
141 141
      * @param ValueComponentInterface $component The component to validate.
142 142
      */
143
-    private function update_component( ValueComponentInterface $component )
143
+    private function update_component(ValueComponentInterface $component)
144 144
     {
145 145
         $component->value = $this->final_instance[$component->name];
146 146
         
147 147
         // Skip if this field is disabled
148
-        if( $this->is_disabled($component) )
148
+        if ($this->is_disabled($component))
149 149
         {
150 150
             return;
151 151
         }
152 152
         
153 153
         // Apply user-defined filter
154
-        $this->filter( $component );
154
+        $this->filter($component);
155 155
         
156 156
         // Validate value
157
-        $this->validate( $component );
157
+        $this->validate($component);
158 158
     }
159 159
     
160 160
     /**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
      * @param UI\AbstractComponent $component
164 164
      * @return boolean
165 165
      */
166
-    private function is_disabled( $component )
166
+    private function is_disabled($component)
167 167
     {
168 168
         return 
169 169
             $component instanceof DisableableComponentInterface &&
@@ -178,15 +178,15 @@  discard block
 block discarded – undo
178 178
      * 
179 179
      * @param UI\AbstractComponent $component
180 180
      */
181
-    private function filter( $component )
181
+    private function filter($component)
182 182
     {
183
-        if( $component instanceof FilterableComponentInterface )
183
+        if ($component instanceof FilterableComponentInterface)
184 184
         {
185 185
             $filter = $component->filter;
186 186
 
187
-            if( is_callable( $filter ) ) 
187
+            if (is_callable($filter)) 
188 188
             {
189
-                $component->value = $filter( $this->final_instance[$component->name] );
189
+                $component->value = $filter($this->final_instance[$component->name]);
190 190
                 $this->final_instance[$component->name] = $component->value;
191 191
             }
192 192
         }
@@ -200,9 +200,9 @@  discard block
 block discarded – undo
200 200
      * 
201 201
      * @param UI\AbstractComponent $component The component to validate.
202 202
      */
203
-    private function validate( $component )
203
+    private function validate($component)
204 204
     {
205
-        if( !($component instanceof ValidatableComponentInterface) ) return;
205
+        if (!($component instanceof ValidatableComponentInterface)) return;
206 206
         
207 207
         $name     = $component->name;
208 208
         $validate = $component->validation;
@@ -210,12 +210,12 @@  discard block
 block discarded – undo
210 210
         
211 211
         $component->validity = $component::VALID;
212 212
         
213
-        if(is_callable($validate))
213
+        if (is_callable($validate))
214 214
         {
215 215
             $valid = $validate($this->new_instance[$name]);
216 216
             
217 217
             // Invalid input, use old instance or default value
218
-            if ( true !== $valid ) 
218
+            if (true !== $valid) 
219 219
             {
220 220
                 $this->errors[$name]         = $valid;
221 221
                 $component->value            = $this->old_instance[$name];
@@ -234,7 +234,7 @@  discard block
 block discarded – undo
234 234
     {
235 235
         $defaults = array();
236 236
         
237
-        foreach( $this->components as $component )
237
+        foreach ($this->components as $component)
238 238
         {
239 239
             $defaults[$component->name] = $component->default;
240 240
         }
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -202,7 +202,9 @@
 block discarded – undo
202 202
      */
203 203
     private function validate( $component )
204 204
     {
205
-        if( !($component instanceof ValidatableComponentInterface) ) return;
205
+        if( !($component instanceof ValidatableComponentInterface) ) {
206
+            return;
207
+        }
206 208
         
207 209
         $name     = $component->name;
208 210
         $validate = $component->validation;
Please login to merge, or discard this patch.