@@ -8,9 +8,9 @@ |
||
8 | 8 | class Component_number |
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 $component_type = 'number'; |
16 | 16 |
@@ -27,8 +27,8 @@ discard block |
||
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 |
||
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; |
@@ -8,9 +8,9 @@ |
||
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 $component_type = 'text'; |
16 | 16 |
@@ -8,7 +8,7 @@ |
||
8 | 8 | class Component_radio |
9 | 9 | extends AbstractComponent |
10 | 10 | implements ValueComponentInterface, |
11 | - DisableableComponentInterface |
|
11 | + DisableableComponentInterface |
|
12 | 12 | { |
13 | 13 | public $component_type = 'radio'; |
14 | 14 |
@@ -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 | { |
@@ -8,8 +8,8 @@ |
||
8 | 8 | class Component_switch |
9 | 9 | extends AbstractComponent |
10 | 10 | implements ValueComponentInterface, |
11 | - DisableableComponentInterface, |
|
12 | - FilterableComponentInterface |
|
11 | + DisableableComponentInterface, |
|
12 | + FilterableComponentInterface |
|
13 | 13 | { |
14 | 14 | public $component_type = 'switch'; |
15 | 15 |
@@ -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 |
@@ -21,7 +21,7 @@ discard block |
||
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 |
||
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 |
@@ -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 | { |
@@ -8,8 +8,8 @@ |
||
8 | 8 | class Component_slider |
9 | 9 | extends AbstractComponent |
10 | 10 | implements ValueComponentInterface, |
11 | - DisableableComponentInterface, |
|
12 | - FilterableComponentInterface |
|
11 | + DisableableComponentInterface, |
|
12 | + FilterableComponentInterface |
|
13 | 13 | { |
14 | 14 | public $component_type = 'slider'; |
15 | 15 |
@@ -25,13 +25,13 @@ |
||
25 | 25 | 'min' => null, |
26 | 26 | 'max' => null, |
27 | 27 | 'step' => 1, |
28 | - 'filter' => array( $this, 'filter' ) |
|
28 | + 'filter' => array($this, 'filter') |
|
29 | 29 | ); |
30 | 30 | } |
31 | 31 | |
32 | 32 | public function required_arguments() |
33 | 33 | { |
34 | - return array('name','min','max'); |
|
34 | + return array('name', 'min', 'max'); |
|
35 | 35 | } |
36 | 36 | |
37 | 37 | public function get_template_path() |
@@ -29,7 +29,7 @@ |
||
29 | 29 | |
30 | 30 | public function required_arguments() |
31 | 31 | { |
32 | - return array('request_url','label_start'); |
|
32 | + return array('request_url', 'label_start'); |
|
33 | 33 | } |
34 | 34 | |
35 | 35 | public function get_template_path() |
@@ -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 | } |
@@ -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 | } |
@@ -8,8 +8,8 @@ |
||
8 | 8 | class Component_toggle |
9 | 9 | extends AbstractComponent |
10 | 10 | implements ValueComponentInterface, |
11 | - FilterableComponentInterface, |
|
12 | - DisableableComponentInterface |
|
11 | + FilterableComponentInterface, |
|
12 | + DisableableComponentInterface |
|
13 | 13 | { |
14 | 14 | public $component_type = 'toggle'; |
15 | 15 |
@@ -24,13 +24,13 @@ discard block |
||
24 | 24 | 'multi' => false, |
25 | 25 | 'data' => array(), |
26 | 26 | 'default' => array(), |
27 | - 'filter' => array( $this, 'filter' ) |
|
27 | + 'filter' => array($this, 'filter') |
|
28 | 28 | ); |
29 | 29 | } |
30 | 30 | |
31 | 31 | public function required_arguments() |
32 | 32 | { |
33 | - return array('name','data'); |
|
33 | + return array('name', 'data'); |
|
34 | 34 | } |
35 | 35 | |
36 | 36 | public function get_template_path() |
@@ -49,16 +49,16 @@ discard block |
||
49 | 49 | */ |
50 | 50 | public function filter($v) |
51 | 51 | { |
52 | - if($this->multi && !\is_array($v)) |
|
52 | + if ($this->multi && !\is_array($v)) |
|
53 | 53 | { |
54 | 54 | return \explode(',', $v); |
55 | 55 | } |
56 | 56 | return $v; |
57 | 57 | } |
58 | 58 | |
59 | - protected function is_selected( $value ) |
|
59 | + protected function is_selected($value) |
|
60 | 60 | { |
61 | - if($this->multi) |
|
61 | + if ($this->multi) |
|
62 | 62 | { |
63 | 63 | return \in_array($value, $this->value); |
64 | 64 | } |