Completed
Push — master ( bcd23f...ead358 )
by Askupa
01:57
created
components/select/controller.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
     
22 22
     public function required_arguments()
23 23
     {
24
-        return array('name','data');
24
+        return array('name', 'data');
25 25
     }
26 26
     
27 27
     public function get_template_path() 
Please login to merge, or discard this patch.
AbstractComponent.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * 
14 14
      * @param array $model
15 15
      */
16
-    public function __construct( array $model = array() ) 
16
+    public function __construct(array $model = array()) 
17 17
     {
18 18
         parent::__construct($model);
19 19
         $this->on_created();
@@ -48,24 +48,24 @@  discard block
 block discarded – undo
48 48
      * 
49 49
      * @return array
50 50
      */
51
-    public function set_model( $model )
51
+    public function set_model($model)
52 52
     {
53 53
         // Check that the required arguments are provided.
54
-        foreach( $this->required_arguments() as $key )
54
+        foreach ($this->required_arguments() as $key)
55 55
         {
56
-            if ( !isset($model[$key]) )
56
+            if (!isset($model[$key]))
57 57
             {
58 58
                 throw new \RuntimeException('The required argument "'.$key.'" was not provided for '.get_called_class());
59 59
             }
60 60
         }
61 61
         
62 62
         // Assign the name of the component as the id if no id was specified
63
-        if( !isset($model['id']) )
63
+        if (!isset($model['id']))
64 64
         {
65 65
             $model['id'] = $model['name'];
66 66
         }
67 67
         
68
-        $this->model = array_merge( $this->default_model(), $model );
68
+        $this->model = array_merge($this->default_model(), $model);
69 69
     }
70 70
     
71 71
     /**
Please login to merge, or discard this patch.
AbstractController.php 2 patches
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -15,9 +15,9 @@  discard block
 block discarded – undo
15 15
      * 
16 16
      * @param array $model
17 17
      */
18
-    public function __construct( array $model = array() ) 
18
+    public function __construct(array $model = array()) 
19 19
     {
20
-        $this->set_model( $model );
20
+        $this->set_model($model);
21 21
     }
22 22
     
23 23
     /**
@@ -27,9 +27,9 @@  discard block
 block discarded – undo
27 27
      * 
28 28
      * @return mixed the argument's value.
29 29
      */
30
-    public function __get( $name ) 
30
+    public function __get($name) 
31 31
     {
32
-        if( isset( $this->model[$name] ) )
32
+        if (isset($this->model[$name]))
33 33
         {
34 34
             return $this->model[$name];
35 35
         }
@@ -43,7 +43,7 @@  discard block
 block discarded – undo
43 43
      * 
44 44
      * @return mixed the settings' argument value.
45 45
      */
46
-    public function __set( $name, $value )
46
+    public function __set($name, $value)
47 47
     {
48 48
         $this->model[$name] = $value;
49 49
     }
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
      * 
64 64
      * @return array
65 65
      */
66
-    public function set_model( $model )
66
+    public function set_model($model)
67 67
     {
68 68
         $this->model = $model;
69 69
     }
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
      * @return string The rendered template.
82 82
      * @throws TemplateNotFoundException Thrown if the template file cannot be found.
83 83
      */
84
-    public function render( $echo = false ){
84
+    public function render($echo = false) {
85 85
         
86 86
         $rendered_html = '';
87 87
         
88
-        if( file_exists( $this->get_template_path() ) ) 
88
+        if (file_exists($this->get_template_path())) 
89 89
         {
90 90
             ob_start();
91
-            include( $this->get_template_path() );
91
+            include($this->get_template_path());
92 92
             $rendered_html = ob_get_clean();
93 93
         } 
94 94
         else 
95 95
         {
96
-            throw new \RuntimeException( "Error: cannot render HTML, template file not found at " . $this->get_template_path() );
96
+            throw new \RuntimeException("Error: cannot render HTML, template file not found at ".$this->get_template_path());
97 97
         }
98 98
         
99
-        if( !$echo )
99
+        if (!$echo)
100 100
         {
101 101
             return $rendered_html;
102 102
         }
Please login to merge, or discard this patch.
Braces   +1 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,8 +90,7 @@
 block discarded – undo
90 90
             ob_start();
91 91
             include( $this->get_template_path() );
92 92
             $rendered_html = ob_get_clean();
93
-        } 
94
-        else 
93
+        } else 
95 94
         {
96 95
             throw new \RuntimeException( "Error: cannot render HTML, template file not found at " . $this->get_template_path() );
97 96
         }
Please login to merge, or discard this patch.
functions.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -17,7 +17,9 @@
 block discarded – undo
17 17
 /**
18 18
  * Prevent loading the library more than once
19 19
  */
20
-if( defined( 'AMARKAL_UI' ) ) return false;
20
+if( defined( 'AMARKAL_UI' ) ) {
21
+    return false;
22
+}
21 23
 define( 'AMARKAL_UI', true );
22 24
 
23 25
 if(!function_exists('amarkal_ui_render'))
Please login to merge, or discard this patch.
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -12,15 +12,15 @@  discard block
 block discarded – undo
12 12
  */
13 13
 
14 14
 // Prevent direct file access
15
-defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
15
+defined('ABSPATH') or die('No script kiddies please!');
16 16
 
17 17
 /**
18 18
  * Prevent loading the library more than once
19 19
  */
20
-if( defined( 'AMARKAL_UI' ) ) return false;
21
-define( 'AMARKAL_UI', true );
20
+if (defined('AMARKAL_UI')) return false;
21
+define('AMARKAL_UI', true);
22 22
 
23
-if(!function_exists('amarkal_ui_render'))
23
+if (!function_exists('amarkal_ui_render'))
24 24
 {
25 25
     /**
26 26
      * Render a UI component.
@@ -30,14 +30,14 @@  discard block
 block discarded – undo
30 30
      * @param array $props The component's properties
31 31
      * @return string The rendered HTML
32 32
      */
33
-    function amarkal_ui_render( $type, array $props = array() )
33
+    function amarkal_ui_render($type, array $props = array())
34 34
     {
35
-        $component = Amarkal\UI\ComponentFactory::create( $type, $props );
35
+        $component = Amarkal\UI\ComponentFactory::create($type, $props);
36 36
         return $component->render();
37 37
     }
38 38
 }
39 39
 
40
-if(!function_exists('amarkal_ui_register_component'))
40
+if (!function_exists('amarkal_ui_register_component'))
41 41
 {
42 42
     /**
43 43
      * Register a custom UI component. The registered component's class should
@@ -47,8 +47,8 @@  discard block
 block discarded – undo
47 47
      * to one of the core component's type, it will override the core component.
48 48
      * @param string $class_name The component's class name.
49 49
      */
50
-    function amarkal_ui_register_component( $type, $class_name )
50
+    function amarkal_ui_register_component($type, $class_name)
51 51
     {
52
-        Amarkal\UI\ComponentFactory::register( $type, $class_name );
52
+        Amarkal\UI\ComponentFactory::register($type, $class_name);
53 53
     }
54 54
 }
55 55
\ No newline at end of file
Please login to merge, or discard this patch.
composer.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@
 block discarded – undo
6 6
  */
7 7
 
8 8
 // Prevent direct file access
9
-defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
9
+defined('ABSPATH') or die('No script kiddies please!');
10 10
 
11 11
 // Load module functions
12 12
 require_once 'functions.php';
13 13
\ No newline at end of file
Please login to merge, or discard this patch.
bootstrap.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -6,13 +6,13 @@
 block discarded – undo
6 6
  */
7 7
 
8 8
 // Prevent direct file access
9
-defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
9
+defined('ABSPATH') or die('No script kiddies please!');
10 10
 
11 11
 /**
12 12
  * Load module functions. If this amarkal module has not been loaded, 
13 13
  * functions.php will not return false.
14 14
  */
15
-if(false !== (require_once 'functions.php'))
15
+if (false !== (require_once 'functions.php'))
16 16
 {
17 17
     // Load required classes if not using composer
18 18
     require_once 'Renderer.php';
Please login to merge, or discard this patch.
ComponentFactory.php 3 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -52,8 +52,8 @@  discard block
 block discarded – undo
52 52
     
53 53
     /**
54 54
      * 
55
-     * @param type $type
56
-     * @param type $props
55
+     * @param string $type
56
+     * @param type string
57 57
      * @throws \RuntimeException
58 58
      */
59 59
     private static function create_core_component( $type, $props )
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
     
80 80
     /**
81 81
      * 
82
-     * @param type $type
83
-     * @param type $props
82
+     * @param string $type
83
+     * @param type string
84 84
      * @throws \RuntimeException
85 85
      */
86 86
     private static function create_registered_component( $type, $props )
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
      * @param array $props
21 21
      * @return AbstractComponent
22 22
      */
23
-    public static function create( $type, array $props )
23
+    public static function create($type, array $props)
24 24
     {
25 25
         try {
26 26
             $component = self::create_registered_component($type, $props);
@@ -41,9 +41,9 @@  discard block
 block discarded – undo
41 41
      * @param string $class_name
42 42
      * @throws \RuntimeException
43 43
      */
44
-    public static function register( $type, $class_name )
44
+    public static function register($type, $class_name)
45 45
     {
46
-        if( !in_array($type, self::$registered_components) )
46
+        if (!in_array($type, self::$registered_components))
47 47
         {
48 48
             self::$registered_components[$type] = $class_name;
49 49
         }
@@ -56,15 +56,15 @@  discard block
 block discarded – undo
56 56
      * @param type $props
57 57
      * @throws \RuntimeException
58 58
      */
59
-    private static function create_core_component( $type, $props )
59
+    private static function create_core_component($type, $props)
60 60
     {
61 61
         $file_name  = __DIR__."/components/$type/controller.php";
62 62
         $class_name = 'Amarkal\\UI\\Component_'.$type;
63 63
         
64 64
         // Load one of the core components
65
-        if(!class_exists($class_name))
65
+        if (!class_exists($class_name))
66 66
         {
67
-            if( file_exists( $file_name ) ) 
67
+            if (file_exists($file_name)) 
68 68
             {
69 69
                 require_once $file_name;
70 70
             }
@@ -83,9 +83,9 @@  discard block
 block discarded – undo
83 83
      * @param type $props
84 84
      * @throws \RuntimeException
85 85
      */
86
-    private static function create_registered_component( $type, $props )
86
+    private static function create_registered_component($type, $props)
87 87
     {
88
-        if(in_array($type, self::$registered_components))
88
+        if (in_array($type, self::$registered_components))
89 89
         {
90 90
             $class_name = self::$registered_components[$type];
91 91
             return new $class_name($props);
Please login to merge, or discard this patch.
Braces   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -46,8 +46,9 @@  discard block
 block discarded – undo
46 46
         if( !in_array($type, self::$registered_components) )
47 47
         {
48 48
             self::$registered_components[$type] = $class_name;
49
+        } else {
50
+            throw new \RuntimeException("A component of type '$type' has already been registered.");
49 51
         }
50
-        else throw new \RuntimeException("A component of type '$type' has already been registered.");
51 52
     }
52 53
     
53 54
     /**
@@ -67,8 +68,7 @@  discard block
 block discarded – undo
67 68
             if( file_exists( $file_name ) ) 
68 69
             {
69 70
                 require_once $file_name;
70
-            }
71
-            else 
71
+            } else 
72 72
             {
73 73
                 throw new \RuntimeException("A component of type '$type' does not exist.");
74 74
             }
Please login to merge, or discard this patch.
components/text/controller.php 1 patch
Indentation   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -8,9 +8,9 @@
 block discarded – undo
8 8
 class Component_text
9 9
 extends AbstractComponent
10 10
 implements ValueComponentInterface, 
11
-           DisableableComponentInterface,
12
-           FilterableComponentInterface,
13
-           ValidatableComponentInterface
11
+            DisableableComponentInterface,
12
+            FilterableComponentInterface,
13
+            ValidatableComponentInterface
14 14
 {
15 15
     public function default_model() 
16 16
     {
Please login to merge, or discard this patch.
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.