Completed
Push — master ( 0576d5...c4f381 )
by Askupa
01:58
created
ComponentFactory.php 3 patches
Doc Comments   +7 added lines, -4 removed lines patch added patch discarded remove patch
@@ -50,6 +50,9 @@  discard block
 block discarded – undo
50 50
         else throw new \RuntimeException("A component of type '$type' has already been registered.");
51 51
     }
52 52
     
53
+    /**
54
+     * @param string $path
55
+     */
53 56
     public static function get_url( $path )
54 57
     {
55 58
         $url  = str_replace( ABSPATH, '', $path );
@@ -58,8 +61,8 @@  discard block
 block discarded – undo
58 61
     
59 62
     /**
60 63
      * 
61
-     * @param type $type
62
-     * @param type $props
64
+     * @param string $type
65
+     * @param type string
63 66
      * @throws \RuntimeException
64 67
      */
65 68
     private static function create_core_component( $type, $props )
@@ -85,8 +88,8 @@  discard block
 block discarded – undo
85 88
     
86 89
     /**
87 90
      * 
88
-     * @param type $type
89
-     * @param type $props
91
+     * @param string $type
92
+     * @param type string
90 93
      * @throws \RuntimeException
91 94
      */
92 95
     private static function create_registered_component( $type, $props )
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 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,19 +41,19 @@  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
         }
50 50
         else throw new \RuntimeException("A component of type '$type' has already been registered.");
51 51
     }
52 52
     
53
-    public static function get_url( $path )
53
+    public static function get_url($path)
54 54
     {
55
-        $url  = str_replace( ABSPATH, '', $path );
56
-        return esc_url_raw( site_url( $url ) );
55
+        $url = str_replace(ABSPATH, '', $path);
56
+        return esc_url_raw(site_url($url));
57 57
     }
58 58
     
59 59
     /**
@@ -62,15 +62,15 @@  discard block
 block discarded – undo
62 62
      * @param type $props
63 63
      * @throws \RuntimeException
64 64
      */
65
-    private static function create_core_component( $type, $props )
65
+    private static function create_core_component($type, $props)
66 66
     {
67 67
         $file_name  = __DIR__."/components/$type/controller.php";
68 68
         $class_name = 'Amarkal\\UI\\Component_'.$type;
69 69
         
70 70
         // Load one of the core components
71
-        if(!class_exists($class_name))
71
+        if (!class_exists($class_name))
72 72
         {
73
-            if( file_exists( $file_name ) ) 
73
+            if (file_exists($file_name)) 
74 74
             {
75 75
                 require_once $file_name;
76 76
             }
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
      * @param type $props
90 90
      * @throws \RuntimeException
91 91
      */
92
-    private static function create_registered_component( $type, $props )
92
+    private static function create_registered_component($type, $props)
93 93
     {
94
-        if(in_array($type, self::$registered_components))
94
+        if (in_array($type, self::$registered_components))
95 95
         {
96 96
             $class_name = self::$registered_components[$type];
97 97
             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
     public static function get_url( $path )
@@ -73,8 +74,7 @@  discard block
 block discarded – undo
73 74
             if( file_exists( $file_name ) ) 
74 75
             {
75 76
                 require_once $file_name;
76
-            }
77
-            else 
77
+            } else 
78 78
             {
79 79
                 throw new \RuntimeException("A component of type '$type' does not exist.");
80 80
             }
Please login to merge, or discard this patch.
functions.php 1 patch
Spacing   +13 added lines, -13 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,21 +47,21 @@  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
60 60
      */
61 61
     function amarkal_ui_register_scripts()
62 62
     {
63
-        \wp_register_script('amarkal-ui',Amarkal\UI\ComponentFactory::get_url(__DIR__.'/assets/js/amarkal-ui.min.js'),array('jquery'),false,true);
64
-        \wp_register_style('amarkal-ui',Amarkal\UI\ComponentFactory::get_url(__DIR__.'/assets/css/amarkal-ui.min.css'),array());
63
+        \wp_register_script('amarkal-ui', Amarkal\UI\ComponentFactory::get_url(__DIR__.'/assets/js/amarkal-ui.min.js'), array('jquery'), false, true);
64
+        \wp_register_style('amarkal-ui', Amarkal\UI\ComponentFactory::get_url(__DIR__.'/assets/css/amarkal-ui.min.css'), array());
65 65
     }
66
-    \add_action('admin_init','amarkal_ui_register_scripts');
66
+    \add_action('admin_init', 'amarkal_ui_register_scripts');
67 67
 }
68 68
\ No newline at end of file
Please login to merge, or discard this patch.
AbstractComponent.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
      * 
32 32
      * @param array $model
33 33
      */
34
-    public function __construct( array $model = array() ) 
34
+    public function __construct(array $model = array()) 
35 35
     {
36 36
         parent::__construct($model);
37 37
         $this->on_created();
@@ -66,24 +66,24 @@  discard block
 block discarded – undo
66 66
      * 
67 67
      * @return array
68 68
      */
69
-    public function set_model( $model )
69
+    public function set_model($model)
70 70
     {
71 71
         // Check that the required arguments are provided.
72
-        foreach( $this->required_arguments() as $key )
72
+        foreach ($this->required_arguments() as $key)
73 73
         {
74
-            if ( !isset($model[$key]) )
74
+            if (!isset($model[$key]))
75 75
             {
76 76
                 throw new \RuntimeException('The required argument "'.$key.'" was not provided for '.get_called_class());
77 77
             }
78 78
         }
79 79
         
80 80
         // Assign the name of the component as the id if no id was specified
81
-        if( !isset($model['id']) )
81
+        if (!isset($model['id']))
82 82
         {
83 83
             $model['id'] = $model['name'];
84 84
         }
85 85
         
86
-        $this->model = array_merge( $this->default_model(), $model );
86
+        $this->model = array_merge($this->default_model(), $model);
87 87
     }
88 88
     
89 89
     /**
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
         );
106 106
     }
107 107
     
108
-    public function render( $echo = false )
108
+    public function render($echo = false)
109 109
     {
110 110
         $this->enqueue_scripts();
111 111
         return parent::render($echo);
Please login to merge, or discard this patch.