@@ -159,7 +159,7 @@ |
||
| 159 | 159 | /** |
| 160 | 160 | * Filter the list of components |
| 161 | 161 | * |
| 162 | - * @param function $callable |
|
| 162 | + * @param \Closure $callable |
|
| 163 | 163 | * @return array |
| 164 | 164 | */ |
| 165 | 165 | private function filter( $callable ) |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * |
| 20 | 20 | * @param array $components |
| 21 | 21 | */ |
| 22 | - public function __construct( array $components = array() ) |
|
| 22 | + public function __construct(array $components = array()) |
|
| 23 | 23 | { |
| 24 | 24 | $this->add_components($components); |
| 25 | 25 | } |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | * @param string $name |
| 31 | 31 | * @return AbstractComponent |
| 32 | 32 | */ |
| 33 | - public function get_by_name( $name ) |
|
| 33 | + public function get_by_name($name) |
|
| 34 | 34 | { |
| 35 | 35 | $filtered = $this->filter(function($c) use ($name) { |
| 36 | 36 | return $c instanceof ValueComponentInterface && $c->name === $name; |
| 37 | 37 | }); |
| 38 | - if(count($filtered) < 1) |
|
| 38 | + if (count($filtered) < 1) |
|
| 39 | 39 | { |
| 40 | 40 | throw new \RuntimeException("No component with the name <b>$name</b> could be found."); |
| 41 | 41 | } |
@@ -48,7 +48,7 @@ discard block |
||
| 48 | 48 | * @param string $type |
| 49 | 49 | * @return AbstractComponent[] |
| 50 | 50 | */ |
| 51 | - public function get_by_type( $type ) |
|
| 51 | + public function get_by_type($type) |
|
| 52 | 52 | { |
| 53 | 53 | return $this->filter(function($c) use ($type) { |
| 54 | 54 | return $c->component_type === $type; |
@@ -107,9 +107,9 @@ discard block |
||
| 107 | 107 | * @param AbstractComponent[] $components |
| 108 | 108 | * @return void |
| 109 | 109 | */ |
| 110 | - public function add_components( array $components ) |
|
| 110 | + public function add_components(array $components) |
|
| 111 | 111 | { |
| 112 | - foreach( $components as $component ) |
|
| 112 | + foreach ($components as $component) |
|
| 113 | 113 | { |
| 114 | 114 | $this->add_component($component); |
| 115 | 115 | } |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | * @param AbstractComponent[] $args |
| 122 | 122 | * @return void |
| 123 | 123 | */ |
| 124 | - public function add_component( array $args ) |
|
| 124 | + public function add_component(array $args) |
|
| 125 | 125 | { |
| 126 | - if(!array_key_exists('type', $args)) |
|
| 126 | + if (!array_key_exists('type', $args)) |
|
| 127 | 127 | { |
| 128 | 128 | throw new \RuntimeException("Component configuration arrays must have a <b>type</b> argument"); |
| 129 | 129 | } |
@@ -140,16 +140,16 @@ discard block |
||
| 140 | 140 | * @param AbstractComponent $comp |
| 141 | 141 | * @return void |
| 142 | 142 | */ |
| 143 | - private function verify_name_uniqueness( AbstractComponent $comp ) |
|
| 143 | + private function verify_name_uniqueness(AbstractComponent $comp) |
|
| 144 | 144 | { |
| 145 | - if(!($comp instanceof ValueComponentInterface)) |
|
| 145 | + if (!($comp instanceof ValueComponentInterface)) |
|
| 146 | 146 | { |
| 147 | 147 | return; |
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | foreach ($this->components as $c) |
| 151 | 151 | { |
| 152 | - if($c->name === $comp->name) |
|
| 152 | + if ($c->name === $comp->name) |
|
| 153 | 153 | { |
| 154 | 154 | throw new \RuntimeException("Duplicate component name detected for the name <b>{$c->name}</b>."); |
| 155 | 155 | } |
@@ -162,7 +162,7 @@ discard block |
||
| 162 | 162 | * @param function $callable |
| 163 | 163 | * @return array |
| 164 | 164 | */ |
| 165 | - private function filter( $callable ) |
|
| 165 | + private function filter($callable) |
|
| 166 | 166 | { |
| 167 | 167 | return array_filter($this->components, $callable); |
| 168 | 168 | } |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | /** |
| 130 | 130 | * Get all components. |
| 131 | 131 | * |
| 132 | - * @return array |
|
| 132 | + * @return AbstractComponent[] |
|
| 133 | 133 | */ |
| 134 | 134 | public function get_component_list() |
| 135 | 135 | { |
@@ -163,7 +163,7 @@ discard block |
||
| 163 | 163 | /** |
| 164 | 164 | * Check if the given component is disabled. |
| 165 | 165 | * |
| 166 | - * @param UI\AbstractComponent $component |
|
| 166 | + * @param ValueComponentInterface $component |
|
| 167 | 167 | * @return boolean |
| 168 | 168 | */ |
| 169 | 169 | private function is_disabled( $component ) |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | /** |
| 180 | 180 | * Filter the component's value using its filter function (if applicable) |
| 181 | 181 | * |
| 182 | - * @param UI\AbstractComponent $component |
|
| 182 | + * @param ValueComponentInterface $component |
|
| 183 | 183 | */ |
| 184 | 184 | private function filter( $component ) |
| 185 | 185 | { |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * If the value is invalid, the old value is used, and an error message is |
| 202 | 202 | * saved into the errors array as component_name => error_message. |
| 203 | 203 | * |
| 204 | - * @param UI\AbstractComponent $component The component to validate. |
|
| 204 | + * @param ValueComponentInterface $component The component to validate. |
|
| 205 | 205 | */ |
| 206 | 206 | private function validate( $component ) |
| 207 | 207 | { |
@@ -59,9 +59,9 @@ discard block |
||
| 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 |
||
| 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; |
@@ -107,7 +107,7 @@ discard block |
||
| 107 | 107 | */ |
| 108 | 108 | public function reset() |
| 109 | 109 | { |
| 110 | - foreach( $this->component_list->get_value_components() as $c ) |
|
| 110 | + foreach ($this->component_list->get_value_components() as $c) |
|
| 111 | 111 | { |
| 112 | 112 | $c->value = $c->default; |
| 113 | 113 | $this->final_instance[$c->name] = $c->default; |
@@ -143,21 +143,21 @@ discard block |
||
| 143 | 143 | * |
| 144 | 144 | * @param ValueComponentInterface $component The component to validate. |
| 145 | 145 | */ |
| 146 | - private function update_component( ValueComponentInterface $component ) |
|
| 146 | + private function update_component(ValueComponentInterface $component) |
|
| 147 | 147 | { |
| 148 | 148 | $component->value = $this->final_instance[$component->name]; |
| 149 | 149 | |
| 150 | 150 | // Skip if this field is disabled |
| 151 | - if( $this->is_disabled($component) ) |
|
| 151 | + if ($this->is_disabled($component)) |
|
| 152 | 152 | { |
| 153 | 153 | return; |
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | // Apply user-defined filter |
| 157 | - $this->filter( $component ); |
|
| 157 | + $this->filter($component); |
|
| 158 | 158 | |
| 159 | 159 | // Validate value |
| 160 | - $this->validate( $component ); |
|
| 160 | + $this->validate($component); |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | * @param UI\AbstractComponent $component |
| 167 | 167 | * @return boolean |
| 168 | 168 | */ |
| 169 | - private function is_disabled( $component ) |
|
| 169 | + private function is_disabled($component) |
|
| 170 | 170 | { |
| 171 | 171 | return |
| 172 | 172 | $component instanceof DisableableComponentInterface && |
@@ -181,13 +181,13 @@ discard block |
||
| 181 | 181 | * |
| 182 | 182 | * @param UI\AbstractComponent $component |
| 183 | 183 | */ |
| 184 | - private function filter( $component ) |
|
| 184 | + private function filter($component) |
|
| 185 | 185 | { |
| 186 | - if( $component instanceof FilterableComponentInterface ) |
|
| 186 | + if ($component instanceof FilterableComponentInterface) |
|
| 187 | 187 | { |
| 188 | 188 | $filter = $component->filter; |
| 189 | 189 | |
| 190 | - if( is_callable( $filter ) ) |
|
| 190 | + if (is_callable($filter)) |
|
| 191 | 191 | { |
| 192 | 192 | $component->value = \call_user_func_array($filter, array($this->final_instance[$component->name])); |
| 193 | 193 | $this->final_instance[$component->name] = $component->value; |
@@ -203,22 +203,22 @@ discard block |
||
| 203 | 203 | * |
| 204 | 204 | * @param UI\AbstractComponent $component The component to validate. |
| 205 | 205 | */ |
| 206 | - private function validate( $component ) |
|
| 206 | + private function validate($component) |
|
| 207 | 207 | { |
| 208 | - if( !($component instanceof ValidatableComponentInterface) ) return; |
|
| 208 | + if (!($component instanceof ValidatableComponentInterface)) return; |
|
| 209 | 209 | |
| 210 | 210 | $name = $component->name; |
| 211 | 211 | $validate = $component->validation; |
| 212 | 212 | |
| 213 | 213 | $component->validity = $component::VALID; |
| 214 | 214 | |
| 215 | - if(is_callable($validate)) |
|
| 215 | + if (is_callable($validate)) |
|
| 216 | 216 | { |
| 217 | 217 | $error = ''; |
| 218 | 218 | $valid = \call_user_func_array($validate, array($this->final_instance[$name], &$error)); |
| 219 | 219 | |
| 220 | 220 | // Invalid input, use old instance or default value |
| 221 | - if ( true !== $valid ) |
|
| 221 | + if (true !== $valid) |
|
| 222 | 222 | { |
| 223 | 223 | $this->errors[$name] = $error ? $error : ValidatableComponentInterface::DEFAULT_MESSAGE; |
| 224 | 224 | $component->value = $this->old_instance[$name]; |
@@ -237,7 +237,7 @@ discard block |
||
| 237 | 237 | { |
| 238 | 238 | $defaults = array(); |
| 239 | 239 | |
| 240 | - foreach( $this->component_list->get_value_components() as $component ) |
|
| 240 | + foreach ($this->component_list->get_value_components() as $component) |
|
| 241 | 241 | { |
| 242 | 242 | $defaults[$component->name] = $component->default; |
| 243 | 243 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | * |
| 39 | 39 | * @param array $model |
| 40 | 40 | */ |
| 41 | - public function __construct( array $model = array() ) |
|
| 41 | + public function __construct(array $model = array()) |
|
| 42 | 42 | { |
| 43 | 43 | parent::__construct($model); |
| 44 | 44 | |
@@ -79,24 +79,24 @@ discard block |
||
| 79 | 79 | * |
| 80 | 80 | * @return array |
| 81 | 81 | */ |
| 82 | - public function set_model( $model ) |
|
| 82 | + public function set_model($model) |
|
| 83 | 83 | { |
| 84 | 84 | // Check that the required arguments are provided. |
| 85 | - foreach( $this->required_arguments() as $key ) |
|
| 85 | + foreach ($this->required_arguments() as $key) |
|
| 86 | 86 | { |
| 87 | - if ( !isset($model[$key]) ) |
|
| 87 | + if (!isset($model[$key])) |
|
| 88 | 88 | { |
| 89 | 89 | throw new \RuntimeException('The required argument "'.$key.'" was not provided for '.get_called_class()); |
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
| 93 | 93 | // Assign the name of the component as the id if no id was specified |
| 94 | - if( !isset($model['id']) && isset($model['name']) ) |
|
| 94 | + if (!isset($model['id']) && isset($model['name'])) |
|
| 95 | 95 | { |
| 96 | 96 | $model['id'] = $model['name']; |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - $this->model = array_merge( $this->default_model(), $model ); |
|
| 99 | + $this->model = array_merge($this->default_model(), $model); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * |
| 116 | 116 | * @param string $class |
| 117 | 117 | */ |
| 118 | - public function add_html_class( $class ) |
|
| 118 | + public function add_html_class($class) |
|
| 119 | 119 | { |
| 120 | - if( !in_array($class, $this->html_classes) ) |
|
| 120 | + if (!in_array($class, $this->html_classes)) |
|
| 121 | 121 | { |
| 122 | 122 | $this->html_classes[] = $class; |
| 123 | 123 | } |
@@ -129,14 +129,14 @@ discard block |
||
| 129 | 129 | * |
| 130 | 130 | * @param string $class |
| 131 | 131 | */ |
| 132 | - public function remove_html_class( $class ) |
|
| 132 | + public function remove_html_class($class) |
|
| 133 | 133 | { |
| 134 | 134 | $i = 0; |
| 135 | - foreach( $this->html_classes as $c ) |
|
| 135 | + foreach ($this->html_classes as $c) |
|
| 136 | 136 | { |
| 137 | - if( $c === $class ) |
|
| 137 | + if ($c === $class) |
|
| 138 | 138 | { |
| 139 | - array_splice($this->html_classes,$i,1); |
|
| 139 | + array_splice($this->html_classes, $i, 1); |
|
| 140 | 140 | break; |
| 141 | 141 | } |
| 142 | 142 | $i++; |
@@ -148,10 +148,10 @@ discard block |
||
| 148 | 148 | * |
| 149 | 149 | * @param type $validity |
| 150 | 150 | */ |
| 151 | - Public function set_validity( $validity ) |
|
| 151 | + Public function set_validity($validity) |
|
| 152 | 152 | { |
| 153 | 153 | $this->validity = $validity; |
| 154 | - if($validity === $this::INVALID) |
|
| 154 | + if ($validity === $this::INVALID) |
|
| 155 | 155 | { |
| 156 | 156 | $this->add_html_class('amarkal-ui-component-error'); |
| 157 | 157 | } |
@@ -174,7 +174,7 @@ discard block |
||
| 174 | 174 | * |
| 175 | 175 | * {@inheritdoc} |
| 176 | 176 | */ |
| 177 | - public function render( $echo = false ) |
|
| 177 | + public function render($echo = false) |
|
| 178 | 178 | { |
| 179 | 179 | $this->enqueue_scripts(); |
| 180 | 180 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | include dirname(__FILE__).'/AbstractComponent.phtml'; |
| 183 | 183 | $html = ob_get_clean(); |
| 184 | 184 | |
| 185 | - if( !$echo ) |
|
| 185 | + if (!$echo) |
|
| 186 | 186 | { |
| 187 | 187 | return $html; |
| 188 | 188 | } |