@@ -17,7 +17,9 @@ |
||
| 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')) |
@@ -52,8 +52,8 @@ discard block |
||
| 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 |
||
| 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 ) |
@@ -46,8 +46,9 @@ discard block |
||
| 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 |
||
| 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 | } |
@@ -202,7 +202,9 @@ |
||
| 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; |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | * Get a component by its name. |
| 138 | 138 | * |
| 139 | 139 | * @param string $name |
| 140 | - * @return UI\AbstractComponent |
|
| 140 | + * @return AbstractComponent |
|
| 141 | 141 | */ |
| 142 | 142 | public function get_component( $name ) |
| 143 | 143 | { |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | /** |
| 148 | 148 | * Get all components. |
| 149 | 149 | * |
| 150 | - * @return array |
|
| 150 | + * @return AbstractComponent[] |
|
| 151 | 151 | */ |
| 152 | 152 | public function get_components() |
| 153 | 153 | { |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | /** |
| 182 | 182 | * Check if the given component is disabled. |
| 183 | 183 | * |
| 184 | - * @param UI\AbstractComponent $component |
|
| 184 | + * @param ValueComponentInterface $component |
|
| 185 | 185 | * @return boolean |
| 186 | 186 | */ |
| 187 | 187 | private function is_disabled( $component ) |
@@ -197,7 +197,7 @@ discard block |
||
| 197 | 197 | /** |
| 198 | 198 | * Filter the component's value using its filter function (if applicable) |
| 199 | 199 | * |
| 200 | - * @param UI\AbstractComponent $component |
|
| 200 | + * @param ValueComponentInterface $component |
|
| 201 | 201 | */ |
| 202 | 202 | private function filter( $component ) |
| 203 | 203 | { |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | * If the value is invalid, the old value is used, and an error message is |
| 220 | 220 | * saved into the errors array as component_name => error_message. |
| 221 | 221 | * |
| 222 | - * @param UI\AbstractComponent $component The component to validate. |
|
| 222 | + * @param ValueComponentInterface $component The component to validate. |
|
| 223 | 223 | */ |
| 224 | 224 | private function validate( $component ) |
| 225 | 225 | { |
@@ -90,8 +90,7 @@ |
||
| 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 | } |
@@ -123,7 +123,7 @@ |
||
| 123 | 123 | /** |
| 124 | 124 | * |
| 125 | 125 | * @param type $args |
| 126 | - * @return type |
|
| 126 | + * @return AbstractComponent |
|
| 127 | 127 | */ |
| 128 | 128 | private function create_component( $args ) |
| 129 | 129 | { |
@@ -43,7 +43,7 @@ |
||
| 43 | 43 | * handle this. |
| 44 | 44 | * |
| 45 | 45 | * @param [string] $v |
| 46 | - * @return void |
|
| 46 | + * @return string |
|
| 47 | 47 | */ |
| 48 | 48 | public function filter($v) |
| 49 | 49 | { |
@@ -47,7 +47,9 @@ |
||
| 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 |
@@ -45,7 +45,7 @@ |
||
| 45 | 45 | * will handle this. |
| 46 | 46 | * |
| 47 | 47 | * @param [string] $v |
| 48 | - * @return void |
|
| 48 | + * @return double |
|
| 49 | 49 | */ |
| 50 | 50 | public function filter($v) |
| 51 | 51 | { |