Completed
Push — master ( d9dcaa...e7a507 )
by Askupa
01:21
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.
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   +14 added lines, -14 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,13 +47,13 @@  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
 
56
-if(!function_exists('amarkal_ui_register_scripts'))
56
+if (!function_exists('amarkal_ui_register_scripts'))
57 57
 {
58 58
     /**
59 59
      * Register Amarkal UI styles & scripts. These scripts are later enqueued by
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
      */
62 62
     function amarkal_ui_register_scripts()
63 63
     {
64
-        \wp_register_script('amarkal-ui',Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-ui.min.js'),array('jquery'),false,true);
65
-        \wp_register_script('ace-editor','https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.8/ace.js',array('jquery'),false,true);
66
-        \wp_register_style('amarkal-ui',Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-ui.min.css'),array());
64
+        \wp_register_script('amarkal-ui', Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/js/dist/amarkal-ui.min.js'), array('jquery'), false, true);
65
+        \wp_register_script('ace-editor', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.8/ace.js', array('jquery'), false, true);
66
+        \wp_register_style('amarkal-ui', Amarkal\Core\Utility::path_to_url(__DIR__.'/assets/css/dist/amarkal-ui.min.css'), array());
67 67
     }
68
-    \add_action('admin_init','amarkal_ui_register_scripts');
68
+    \add_action('admin_init', 'amarkal_ui_register_scripts');
69 69
 }
70 70
\ 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.
ComponentFactory.php 2 patches
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.
Form.php 2 patches
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.
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.
Template.php 2 patches
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.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -25,9 +25,9 @@  discard block
 block discarded – undo
25 25
      * @param array $model
26 26
      * @param string $template_path
27 27
      */
28
-    public function __construct( array $model = array(), $template_path = null ) 
28
+    public function __construct(array $model = array(), $template_path = null) 
29 29
     {
30
-        $this->set_model( $model );
30
+        $this->set_model($model);
31 31
         $this->template = $template_path;
32 32
     }
33 33
     
@@ -38,9 +38,9 @@  discard block
 block discarded – undo
38 38
      * 
39 39
      * @return mixed the argument's value.
40 40
      */
41
-    public function __get( $name ) 
41
+    public function __get($name) 
42 42
     {
43
-        if( isset( $this->model[$name] ) )
43
+        if (isset($this->model[$name]))
44 44
         {
45 45
             return $this->model[$name];
46 46
         }
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
      * 
55 55
      * @return mixed the settings' argument value.
56 56
      */
57
-    public function __set( $name, $value )
57
+    public function __set($name, $value)
58 58
     {
59 59
         $this->model[$name] = $value;
60 60
     }
@@ -65,7 +65,7 @@  discard block
 block discarded – undo
65 65
      * @param string $name The argument's name.
66 66
      * @return boolean Whether this arguments exists or not.
67 67
      */
68
-    public function __isset( $name )
68
+    public function __isset($name)
69 69
     {
70 70
         return isset($this->model[$name]);
71 71
     }
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
      * 
86 86
      * @return array
87 87
      */
88
-    public function set_model( $model )
88
+    public function set_model($model)
89 89
     {
90 90
         $this->model = $model;
91 91
     }
@@ -106,22 +106,22 @@  discard block
 block discarded – undo
106 106
      * @return string The rendered template.
107 107
      * @throws TemplateNotFoundException Thrown if the template file cannot be found.
108 108
      */
109
-    public function render( $echo = false )
109
+    public function render($echo = false)
110 110
     {
111 111
         $rendered_html = '';
112 112
         
113
-        if( file_exists( $this->get_template_path() ) ) 
113
+        if (file_exists($this->get_template_path())) 
114 114
         {
115 115
             ob_start();
116
-            include( $this->get_template_path() );
116
+            include($this->get_template_path());
117 117
             $rendered_html = ob_get_clean();
118 118
         } 
119 119
         else 
120 120
         {
121
-            throw new \RuntimeException( "Error: cannot render HTML, template file not found at " . $this->get_template_path() );
121
+            throw new \RuntimeException("Error: cannot render HTML, template file not found at ".$this->get_template_path());
122 122
         }
123 123
         
124
-        if( !$echo )
124
+        if (!$echo)
125 125
         {
126 126
             return $rendered_html;
127 127
         }
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 'AbstractComponent.php';
Please login to merge, or discard this patch.
components/number/controller.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
             'required'      => false,
28 28
             'readonly'      => false,
29 29
             'default'       => null,
30
-            'filter'        => array( $this, 'filter' ),
31
-            'validation'    => array( $this, 'validation' )
30
+            'filter'        => array($this, 'filter'),
31
+            'validation'    => array($this, 'validation')
32 32
         );
33 33
     }
34 34
     
@@ -37,19 +37,19 @@  discard block
 block discarded – undo
37 37
         return floatval($v);
38 38
     }
39 39
     
40
-    public function validation($v,&$e)
40
+    public function validation($v, &$e)
41 41
     {
42 42
         $max = $this->max;
43 43
         $min = $this->min;
44 44
         
45
-        if(null !== $max && $v > $max)
45
+        if (null !== $max && $v > $max)
46 46
         {
47
-            $e = sprintf( __("Value must be less than %d",'amarkal'), $max);
47
+            $e = sprintf(__("Value must be less than %d", 'amarkal'), $max);
48 48
         }
49 49
 
50
-        if(null !== $min && $v < $min) 
50
+        if (null !== $min && $v < $min) 
51 51
         {
52
-            $e = sprintf( __("Value must be greater than %d",'amarkal'), $min);
52
+            $e = sprintf(__("Value must be greater than %d", 'amarkal'), $min);
53 53
         }
54 54
 
55 55
         return $e ? false : true;
Please login to merge, or discard this patch.
components/switch/controller.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -47,7 +47,9 @@
 block discarded – undo
47 47
      */
48 48
     public function filter($v)
49 49
     {
50
-        if($v !== 'on') return 'off';
50
+        if($v !== 'on') {
51
+            return 'off';
52
+        }
51 53
         return 'on';
52 54
     }
53 55
 }
54 56
\ No newline at end of file
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@  discard block
 block discarded – undo
21 21
             'disabled'      => false,
22 22
             'readonly'      => false,
23 23
             'default'       => null,
24
-            'filter'        => array( $this, 'filter' )
24
+            'filter'        => array($this, 'filter')
25 25
         );
26 26
     }
27 27
     
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function filter($v)
48 48
     {
49
-        if($v !== 'on') return 'off';
49
+        if ($v !== 'on') return 'off';
50 50
         return 'on';
51 51
     }
52 52
 }
53 53
\ No newline at end of file
Please login to merge, or discard this patch.