@@ -113,7 +113,6 @@ |
||
| 113 | 113 | /** |
| 114 | 114 | * Set field value using provided default. |
| 115 | 115 | * |
| 116 | - * @param mixed $default |
|
| 117 | 116 | * @return void |
| 118 | 117 | */ |
| 119 | 118 | abstract public function setValueFromDefault(); |
@@ -2,8 +2,8 @@ |
||
| 2 | 2 | |
| 3 | 3 | namespace Helmut\Forms; |
| 4 | 4 | |
| 5 | -use Helmut\Forms\Utility\Str; |
|
| 6 | 5 | use Helmut\Forms\Utility\Reflect; |
| 6 | +use Helmut\Forms\Utility\Str; |
|
| 7 | 7 | |
| 8 | 8 | abstract class Field { |
| 9 | 9 | |
@@ -179,9 +179,11 @@ discard block |
||
| 179 | 179 | { |
| 180 | 180 | $values = $this->getValue(); |
| 181 | 181 | |
| 182 | - if (is_null($values)) $values = []; |
|
| 183 | - |
|
| 184 | - else if ( ! is_array($values)) $values = [$this->name => $values]; |
|
| 182 | + if (is_null($values)) { |
|
| 183 | + $values = []; |
|
| 184 | + } else if ( ! is_array($values)) { |
|
| 185 | + $values = [$this->name => $values]; |
|
| 186 | + } |
|
| 185 | 187 | |
| 186 | 188 | return $values; |
| 187 | 189 | } |
@@ -196,7 +198,9 @@ discard block |
||
| 196 | 198 | { |
| 197 | 199 | $properties = $this->renderWith(); |
| 198 | 200 | |
| 199 | - if (is_null($properties)) $properties = []; |
|
| 201 | + if (is_null($properties)) { |
|
| 202 | + $properties = []; |
|
| 203 | + } |
|
| 200 | 204 | |
| 201 | 205 | return $properties; |
| 202 | 206 | } |
@@ -210,9 +214,11 @@ discard block |
||
| 210 | 214 | { |
| 211 | 215 | $buttons = $this->getButtonName(); |
| 212 | 216 | |
| 213 | - if (is_null($buttons)) $buttons = []; |
|
| 214 | - |
|
| 215 | - else if ( ! is_array($buttons)) $buttons = [$buttons]; |
|
| 217 | + if (is_null($buttons)) { |
|
| 218 | + $buttons = []; |
|
| 219 | + } else if ( ! is_array($buttons)) { |
|
| 220 | + $buttons = [$buttons]; |
|
| 221 | + } |
|
| 216 | 222 | |
| 217 | 223 | return $buttons; |
| 218 | 224 | } |
@@ -224,7 +230,9 @@ discard block |
||
| 224 | 230 | */ |
| 225 | 231 | public function setFromDefault() |
| 226 | 232 | { |
| 227 | - if ( ! is_null($this->default)) $this->setValueFromDefault(); |
|
| 233 | + if ( ! is_null($this->default)) { |
|
| 234 | + $this->setValueFromDefault(); |
|
| 235 | + } |
|
| 228 | 236 | } |
| 229 | 237 | |
| 230 | 238 | /** |
@@ -369,7 +377,9 @@ discard block |
||
| 369 | 377 | return false; |
| 370 | 378 | } |
| 371 | 379 | |
| 372 | - if (isset($this->errors[$method])) unset($this->errors[$method]); |
|
| 380 | + if (isset($this->errors[$method])) { |
|
| 381 | + unset($this->errors[$method]); |
|
| 382 | + } |
|
| 373 | 383 | |
| 374 | 384 | return true; |
| 375 | 385 | } |
@@ -411,7 +421,9 @@ discard block |
||
| 411 | 421 | */ |
| 412 | 422 | public function error($message) |
| 413 | 423 | { |
| 414 | - if ( ! isset($this->errors['userDefined'])) $this->errors['userDefined'] = []; |
|
| 424 | + if ( ! isset($this->errors['userDefined'])) { |
|
| 425 | + $this->errors['userDefined'] = []; |
|
| 426 | + } |
|
| 415 | 427 | |
| 416 | 428 | $this->errors['userDefined'][] = $message; |
| 417 | 429 | } |
@@ -25,14 +25,14 @@ |
||
| 25 | 25 | |
| 26 | 26 | public function setChecked() |
| 27 | 27 | { |
| 28 | - $this->default = true; |
|
| 29 | - return $this; |
|
| 28 | + $this->default = true; |
|
| 29 | + return $this; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | public function setUnchecked() |
| 33 | 33 | { |
| 34 | - $this->default = false; |
|
| 35 | - return $this; |
|
| 34 | + $this->default = false; |
|
| 35 | + return $this; |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | public function setValueFromDefault() |
@@ -84,14 +84,18 @@ discard block |
||
| 84 | 84 | public function setValueFromDefault() |
| 85 | 85 | { |
| 86 | 86 | foreach (array_keys($this->options) as $key) { |
| 87 | - if (isset($this->default[$key])) $this->values[$key] = $this->default[$key] ? true : false; |
|
| 87 | + if (isset($this->default[$key])) { |
|
| 88 | + $this->values[$key] = $this->default[$key] ? true : false; |
|
| 89 | + } |
|
| 88 | 90 | } |
| 89 | 91 | } |
| 90 | 92 | |
| 91 | 93 | public function setValueFromModel($model) |
| 92 | 94 | { |
| 93 | 95 | foreach (array_keys($this->options) as $key) { |
| 94 | - if (property_exists($model, $this->name.'_'.$key)) $this->values[$key] = $model->{$this->name.'_'.$key} ? true : false; |
|
| 96 | + if (property_exists($model, $this->name.'_'.$key)) { |
|
| 97 | + $this->values[$key] = $model->{$this->name.'_'.$key} ? true : false; |
|
| 98 | + } |
|
| 95 | 99 | } |
| 96 | 100 | |
| 97 | 101 | } |
@@ -106,7 +110,9 @@ discard block |
||
| 106 | 110 | public function fillModelWithValue($model) |
| 107 | 111 | { |
| 108 | 112 | foreach (array_keys($this->options) as $key) { |
| 109 | - if (property_exists($model, $this->name.'_'.$key)) $model->{$this->name.'_'.$key} = $this->values[$key] ? 1 : 0; |
|
| 113 | + if (property_exists($model, $this->name.'_'.$key)) { |
|
| 114 | + $model->{$this->name.'_'.$key} = $this->values[$key] ? 1 : 0; |
|
| 115 | + } |
|
| 110 | 116 | } |
| 111 | 117 | } |
| 112 | 118 | |
@@ -115,7 +121,9 @@ discard block |
||
| 115 | 121 | $checked = false; |
| 116 | 122 | |
| 117 | 123 | foreach (array_keys($this->options) as $key) { |
| 118 | - if ($this->values[$key]) $checked = true; |
|
| 124 | + if ($this->values[$key]) { |
|
| 125 | + $checked = true; |
|
| 126 | + } |
|
| 119 | 127 | } |
| 120 | 128 | |
| 121 | 129 | return $checked; |
@@ -52,7 +52,9 @@ discard block |
||
| 52 | 52 | |
| 53 | 53 | public function setValueFromModel($model) |
| 54 | 54 | { |
| 55 | - if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
| 55 | + if (property_exists($model, $this->name)) { |
|
| 56 | + $this->value = $model->{$this->name}; |
|
| 57 | + } |
|
| 56 | 58 | } |
| 57 | 59 | |
| 58 | 60 | public function setValueFromRequest($request) |
@@ -62,7 +64,9 @@ discard block |
||
| 62 | 64 | |
| 63 | 65 | public function fillModelWithValue($model) |
| 64 | 66 | { |
| 65 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 67 | + if (property_exists($model, $this->name)) { |
|
| 68 | + $model->{$this->name} = $this->value; |
|
| 69 | + } |
|
| 66 | 70 | } |
| 67 | 71 | |
| 68 | 72 | public function validateRequired() |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function setValueFromModel($model) |
| 33 | 33 | { |
| 34 | - if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
| 34 | + if (property_exists($model, $this->name)) { |
|
| 35 | + $this->value = $model->{$this->name}; |
|
| 36 | + } |
|
| 35 | 37 | } |
| 36 | 38 | |
| 37 | 39 | public function setValueFromRequest($request) |
@@ -41,7 +43,9 @@ discard block |
||
| 41 | 43 | |
| 42 | 44 | public function fillModelWithValue($model) |
| 43 | 45 | { |
| 44 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 46 | + if (property_exists($model, $this->name)) { |
|
| 47 | + $model->{$this->name} = $this->value; |
|
| 48 | + } |
|
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | public function validate() |
@@ -38,15 +38,23 @@ discard block |
||
| 38 | 38 | |
| 39 | 39 | public function setValueFromDefault() |
| 40 | 40 | { |
| 41 | - if (isset($this->default['first'])) $this->value_first = $this->default['first']; |
|
| 42 | - if (isset($this->default['surname'])) $this->value_surname = $this->default['surname']; |
|
| 41 | + if (isset($this->default['first'])) { |
|
| 42 | + $this->value_first = $this->default['first']; |
|
| 43 | + } |
|
| 44 | + if (isset($this->default['surname'])) { |
|
| 45 | + $this->value_surname = $this->default['surname']; |
|
| 46 | + } |
|
| 43 | 47 | $this->value = trim($this->value_first.' '.$this->value_surname); |
| 44 | 48 | } |
| 45 | 49 | |
| 46 | 50 | public function setValueFromModel($model) |
| 47 | 51 | { |
| 48 | - if (property_exists($model, $this->name.'_first')) $this->value_first = $model->{$this->name.'_first'}; |
|
| 49 | - if (property_exists($model, $this->name.'_surname')) $this->value_surname = $model->{$this->name.'_surname'}; |
|
| 52 | + if (property_exists($model, $this->name.'_first')) { |
|
| 53 | + $this->value_first = $model->{$this->name.'_first'}; |
|
| 54 | + } |
|
| 55 | + if (property_exists($model, $this->name.'_surname')) { |
|
| 56 | + $this->value_surname = $model->{$this->name.'_surname'}; |
|
| 57 | + } |
|
| 50 | 58 | $this->value = trim($this->value_first.' '.$this->value_surname); |
| 51 | 59 | } |
| 52 | 60 | |
@@ -59,9 +67,15 @@ discard block |
||
| 59 | 67 | |
| 60 | 68 | public function fillModelWithValue($model) |
| 61 | 69 | { |
| 62 | - if (property_exists($model, $this->name.'_first')) $model->{$this->name.'_first'} = $this->value_first; |
|
| 63 | - if (property_exists($model, $this->name.'_surname')) $model->{$this->name.'_surname'} = $this->value_surname; |
|
| 64 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 70 | + if (property_exists($model, $this->name.'_first')) { |
|
| 71 | + $model->{$this->name.'_first'} = $this->value_first; |
|
| 72 | + } |
|
| 73 | + if (property_exists($model, $this->name.'_surname')) { |
|
| 74 | + $model->{$this->name.'_surname'} = $this->value_surname; |
|
| 75 | + } |
|
| 76 | + if (property_exists($model, $this->name)) { |
|
| 77 | + $model->{$this->name} = $this->value; |
|
| 78 | + } |
|
| 65 | 79 | } |
| 66 | 80 | |
| 67 | 81 | public function validateRequired() |
@@ -41,7 +41,9 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | public function setValueFromModel($model) |
| 43 | 43 | { |
| 44 | - if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
| 44 | + if (property_exists($model, $this->name)) { |
|
| 45 | + $this->value = $model->{$this->name}; |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | public function setValueFromRequest($request) |
@@ -51,7 +53,9 @@ discard block |
||
| 51 | 53 | |
| 52 | 54 | public function fillModelWithValue($model) |
| 53 | 55 | { |
| 54 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 56 | + if (property_exists($model, $this->name)) { |
|
| 57 | + $model->{$this->name} = $this->value; |
|
| 58 | + } |
|
| 55 | 59 | } |
| 56 | 60 | |
| 57 | 61 | public function validate() |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function setValueFromModel($model) |
| 33 | 33 | { |
| 34 | - if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
| 34 | + if (property_exists($model, $this->name)) { |
|
| 35 | + $this->value = $model->{$this->name}; |
|
| 36 | + } |
|
| 35 | 37 | } |
| 36 | 38 | |
| 37 | 39 | public function setValueFromRequest($request) |
@@ -41,7 +43,9 @@ discard block |
||
| 41 | 43 | |
| 42 | 44 | public function fillModelWithValue($model) |
| 43 | 45 | { |
| 44 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 46 | + if (property_exists($model, $this->name)) { |
|
| 47 | + $model->{$this->name} = $this->value; |
|
| 48 | + } |
|
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | public function validateRequired() |
@@ -31,7 +31,9 @@ discard block |
||
| 31 | 31 | |
| 32 | 32 | public function setValueFromModel($model) |
| 33 | 33 | { |
| 34 | - if (property_exists($model, $this->name)) $this->value = $model->{$this->name}; |
|
| 34 | + if (property_exists($model, $this->name)) { |
|
| 35 | + $this->value = $model->{$this->name}; |
|
| 36 | + } |
|
| 35 | 37 | } |
| 36 | 38 | |
| 37 | 39 | public function setValueFromRequest($request) |
@@ -41,7 +43,9 @@ discard block |
||
| 41 | 43 | |
| 42 | 44 | public function fillModelWithValue($model) |
| 43 | 45 | { |
| 44 | - if (property_exists($model, $this->name)) $model->{$this->name} = $this->value; |
|
| 46 | + if (property_exists($model, $this->name)) { |
|
| 47 | + $model->{$this->name} = $this->value; |
|
| 48 | + } |
|
| 45 | 49 | } |
| 46 | 50 | |
| 47 | 51 | public function validateRequired() |