@@ -89,7 +89,7 @@ |
||
| 89 | 89 | /** |
| 90 | 90 | * Catch a POST value by the field key |
| 91 | 91 | * |
| 92 | - * @return true on success or false on failure |
|
| 92 | + * @return boolean on success or false on failure |
|
| 93 | 93 | */ |
| 94 | 94 | |
| 95 | 95 | public function post() { |
@@ -31,9 +31,9 @@ |
||
| 31 | 31 | |
| 32 | 32 | if (preg_match(REGEX_FORM_FIELD_KEY, $key)) { |
| 33 | 33 | |
| 34 | - $prefix = (('' !== $this->form->getName()) ? ($this->form->getName() . '_') : ''); |
|
| 34 | + $prefix = (('' !== $this->form->getName()) ? ($this->form->getName().'_') : ''); |
|
| 35 | 35 | |
| 36 | - $this->key = $key; $this->name = ($prefix . $key); $this->id = str_replace('_', '-', $this->name); |
|
| 36 | + $this->key = $key; $this->name = ($prefix.$key); $this->id = str_replace('_', '-', $this->name); |
|
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | # Set configuration |
@@ -57,11 +57,17 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | # Set appearance |
| 59 | 59 | |
| 60 | - if ($this->disabled) $data['disabled'] = 'disabled'; |
|
| 60 | + if ($this->disabled) { |
|
| 61 | + $data['disabled'] = 'disabled'; |
|
| 62 | + } |
|
| 61 | 63 | |
| 62 | - if ($this->required) $data['data-required'] = 'required'; |
|
| 64 | + if ($this->required) { |
|
| 65 | + $data['data-required'] = 'required'; |
|
| 66 | + } |
|
| 63 | 67 | |
| 64 | - if ($this->error) $data['data-error'] = 'error'; |
|
| 68 | + if ($this->error) { |
|
| 69 | + $data['data-error'] = 'error'; |
|
| 70 | + } |
|
| 65 | 71 | |
| 66 | 72 | # ------------------------ |
| 67 | 73 | |
@@ -76,7 +82,9 @@ discard block |
||
| 76 | 82 | |
| 77 | 83 | public function post() : bool { |
| 78 | 84 | |
| 79 | - if ($this->posted || $this->disabled || ('' === $this->key)) return false; |
|
| 85 | + if ($this->posted || $this->disabled || ('' === $this->key)) { |
|
| 86 | + return false; |
|
| 87 | + } |
|
| 80 | 88 | |
| 81 | 89 | $this->error = (!$this->setValue(Request::post($this->name)) && $this->required); |
| 82 | 90 | |
@@ -148,7 +148,7 @@ |
||
| 148 | 148 | /** |
| 149 | 149 | * Set a value |
| 150 | 150 | * |
| 151 | - * @return true if the result value is not empty, otherwise false |
|
| 151 | + * @return boolean if the result value is not empty, otherwise false |
|
| 152 | 152 | */ |
| 153 | 153 | |
| 154 | 154 | public function setValue(string $value) { |
@@ -82,9 +82,13 @@ discard block |
||
| 82 | 82 | |
| 83 | 83 | $tag = $this->getTag('textarea', [], $this->value); |
| 84 | 84 | |
| 85 | - if ($this->rows > 0) $tag->setAttribute('rows', $this->rows); |
|
| 85 | + if ($this->rows > 0) { |
|
| 86 | + $tag->setAttribute('rows', $this->rows); |
|
| 87 | + } |
|
| 86 | 88 | |
| 87 | - if ($this->cols > 0) $tag->setAttribute('cols', $this->cols); |
|
| 89 | + if ($this->cols > 0) { |
|
| 90 | + $tag->setAttribute('cols', $this->cols); |
|
| 91 | + } |
|
| 88 | 92 | |
| 89 | 93 | # ------------------------ |
| 90 | 94 | |
@@ -97,9 +101,11 @@ discard block |
||
| 97 | 101 | |
| 98 | 102 | private function processSpaces() { |
| 99 | 103 | |
| 100 | - if ($this->spaces === 'strip') $this->value = Str::stripSpaces($this->value); |
|
| 101 | - |
|
| 102 | - else if ($this->spaces === 'single') $this->value = Str::singleSpaces($this->value); |
|
| 104 | + if ($this->spaces === 'strip') { |
|
| 105 | + $this->value = Str::stripSpaces($this->value); |
|
| 106 | + } else if ($this->spaces === 'single') { |
|
| 107 | + $this->value = Str::singleSpaces($this->value); |
|
| 108 | + } |
|
| 103 | 109 | } |
| 104 | 110 | |
| 105 | 111 | /** |
@@ -108,9 +114,11 @@ discard block |
||
| 108 | 114 | |
| 109 | 115 | private function processConvert() { |
| 110 | 116 | |
| 111 | - if ($this->convert === 'url') $this->value = Str::toUrl($this->value, $this->maxlength); |
|
| 112 | - |
|
| 113 | - else if ($this->convert === 'var') $this->value = Str::toVar($this->value, $this->maxlength); |
|
| 117 | + if ($this->convert === 'url') { |
|
| 118 | + $this->value = Str::toUrl($this->value, $this->maxlength); |
|
| 119 | + } else if ($this->convert === 'var') { |
|
| 120 | + $this->value = Str::toVar($this->value, $this->maxlength); |
|
| 121 | + } |
|
| 114 | 122 | } |
| 115 | 123 | |
| 116 | 124 | /** |
@@ -119,9 +127,11 @@ discard block |
||
| 119 | 127 | |
| 120 | 128 | private function processTransform() { |
| 121 | 129 | |
| 122 | - if ($this->transform === 'lower') $this->value = Str::toLower($this->value); |
|
| 123 | - |
|
| 124 | - else if ($this->transform === 'upper') $this->value = Str::toUpper($this->value); |
|
| 130 | + if ($this->transform === 'lower') { |
|
| 131 | + $this->value = Str::toLower($this->value); |
|
| 132 | + } else if ($this->transform === 'upper') { |
|
| 133 | + $this->value = Str::toUpper($this->value); |
|
| 134 | + } |
|
| 125 | 135 | } |
| 126 | 136 | |
| 127 | 137 | /** |
@@ -183,27 +193,39 @@ discard block |
||
| 183 | 193 | |
| 184 | 194 | # Process hidden field |
| 185 | 195 | |
| 186 | - if ($this->type === FORM_FIELD_HIDDEN) return $this->getHidden()->getBlock(); |
|
| 196 | + if ($this->type === FORM_FIELD_HIDDEN) { |
|
| 197 | + return $this->getHidden()->getBlock(); |
|
| 198 | + } |
|
| 187 | 199 | |
| 188 | 200 | # Process visible field |
| 189 | 201 | |
| 190 | - else if ($this->type === FORM_FIELD_PASSWORD) $tag = $this->getPassword(); |
|
| 191 | - |
|
| 192 | - else if ($this->type === FORM_FIELD_CAPTCHA) $tag = $this->getCaptcha(); |
|
| 193 | - |
|
| 194 | - else if ($this->type === FORM_FIELD_TEXTAREA) $tag = $this->getTextarea(); |
|
| 195 | - |
|
| 196 | - else $tag = $this->getText(); |
|
| 202 | + else if ($this->type === FORM_FIELD_PASSWORD) { |
|
| 203 | + $tag = $this->getPassword(); |
|
| 204 | + } else if ($this->type === FORM_FIELD_CAPTCHA) { |
|
| 205 | + $tag = $this->getCaptcha(); |
|
| 206 | + } else if ($this->type === FORM_FIELD_TEXTAREA) { |
|
| 207 | + $tag = $this->getTextarea(); |
|
| 208 | + } else { |
|
| 209 | + $tag = $this->getText(); |
|
| 210 | + } |
|
| 197 | 211 | |
| 198 | 212 | # Set appearance |
| 199 | 213 | |
| 200 | - if ($this->maxlength > 0) $tag->setAttribute('maxlength', $this->maxlength); |
|
| 214 | + if ($this->maxlength > 0) { |
|
| 215 | + $tag->setAttribute('maxlength', $this->maxlength); |
|
| 216 | + } |
|
| 201 | 217 | |
| 202 | - if ('' !== $this->placeholder) $tag->setAttribute('placeholder', $this->placeholder); |
|
| 218 | + if ('' !== $this->placeholder) { |
|
| 219 | + $tag->setAttribute('placeholder', $this->placeholder); |
|
| 220 | + } |
|
| 203 | 221 | |
| 204 | - if ($this->readonly) $tag->setAttribute('readonly', 'readonly'); |
|
| 222 | + if ($this->readonly) { |
|
| 223 | + $tag->setAttribute('readonly', 'readonly'); |
|
| 224 | + } |
|
| 205 | 225 | |
| 206 | - if ($this->autofocus) $tag->setAttribute('autofocus', 'autofocus'); |
|
| 226 | + if ($this->autofocus) { |
|
| 227 | + $tag->setAttribute('autofocus', 'autofocus'); |
|
| 228 | + } |
|
| 207 | 229 | |
| 208 | 230 | # ------------------------ |
| 209 | 231 | |
@@ -56,7 +56,7 @@ |
||
| 56 | 56 | /** |
| 57 | 57 | * Get a FILE-param value |
| 58 | 58 | * |
| 59 | - * @return the array with file info or false if the param does not exist |
|
| 59 | + * @return string array with file info or false if the param does not exist |
|
| 60 | 60 | */ |
| 61 | 61 | |
| 62 | 62 | public static function file(string $name) { |
@@ -2,23 +2,23 @@ |
||
| 2 | 2 | |
| 3 | 3 | # Date formats |
| 4 | 4 | |
| 5 | -define('DATE_FORMAT_STANDART', 'd.m.Y'); |
|
| 6 | -define('DATE_FORMAT_MYSQL', 'Y-m-d'); |
|
| 7 | -define('DATE_FORMAT_DATETIME', 'd.m.Y, H:i'); |
|
| 8 | -define('DATE_FORMAT_W3C', 'Y-m-d\TH:i:sP'); |
|
| 5 | +define('DATE_FORMAT_STANDART', 'd.m.Y'); |
|
| 6 | +define('DATE_FORMAT_MYSQL', 'Y-m-d'); |
|
| 7 | +define('DATE_FORMAT_DATETIME', 'd.m.Y, H:i'); |
|
| 8 | +define('DATE_FORMAT_W3C', 'Y-m-d\TH:i:sP'); |
|
| 9 | 9 | |
| 10 | 10 | # Form fields |
| 11 | 11 | |
| 12 | -define('FORM_FIELD_HIDDEN', 'hidden'); |
|
| 13 | -define('FORM_FIELD_PASSWORD', 'password'); |
|
| 14 | -define('FORM_FIELD_CAPTCHA', 'captcha'); |
|
| 15 | -define('FORM_FIELD_TEXT', 'text'); |
|
| 16 | -define('FORM_FIELD_TEXTAREA', 'textarea'); |
|
| 12 | +define('FORM_FIELD_HIDDEN', 'hidden'); |
|
| 13 | +define('FORM_FIELD_PASSWORD', 'password'); |
|
| 14 | +define('FORM_FIELD_CAPTCHA', 'captcha'); |
|
| 15 | +define('FORM_FIELD_TEXT', 'text'); |
|
| 16 | +define('FORM_FIELD_TEXTAREA', 'textarea'); |
|
| 17 | 17 | |
| 18 | 18 | # String pools |
| 19 | 19 | |
| 20 | -define('STR_POOL_DEFAULT', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
|
| 21 | -define('STR_POOL_LATIN', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
| 22 | -define('STR_POOL_LATIN_LOWER', 'abcdefghijklmnopqrstuvwxyz'); |
|
| 23 | -define('STR_POOL_LATIN_UPPER', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
| 24 | -define('STR_POOL_NUMERIC', '0123456789'); |
|
| 20 | +define('STR_POOL_DEFAULT', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789'); |
|
| 21 | +define('STR_POOL_LATIN', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
| 22 | +define('STR_POOL_LATIN_LOWER', 'abcdefghijklmnopqrstuvwxyz'); |
|
| 23 | +define('STR_POOL_LATIN_UPPER', 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'); |
|
| 24 | +define('STR_POOL_NUMERIC', '0123456789'); |
|
@@ -2,60 +2,60 @@ |
||
| 2 | 2 | |
| 3 | 3 | # Status codes |
| 4 | 4 | |
| 5 | -define('STATUS_CODE_100', 100); |
|
| 6 | -define('STATUS_CODE_101', 101); |
|
| 7 | -define('STATUS_CODE_102', 102); |
|
| 5 | +define('STATUS_CODE_100', 100); |
|
| 6 | +define('STATUS_CODE_101', 101); |
|
| 7 | +define('STATUS_CODE_102', 102); |
|
| 8 | 8 | |
| 9 | -define('STATUS_CODE_200', 200); |
|
| 10 | -define('STATUS_CODE_201', 201); |
|
| 11 | -define('STATUS_CODE_202', 202); |
|
| 12 | -define('STATUS_CODE_203', 203); |
|
| 13 | -define('STATUS_CODE_204', 204); |
|
| 14 | -define('STATUS_CODE_205', 205); |
|
| 15 | -define('STATUS_CODE_206', 206); |
|
| 16 | -define('STATUS_CODE_207', 207); |
|
| 17 | -define('STATUS_CODE_226', 226); |
|
| 9 | +define('STATUS_CODE_200', 200); |
|
| 10 | +define('STATUS_CODE_201', 201); |
|
| 11 | +define('STATUS_CODE_202', 202); |
|
| 12 | +define('STATUS_CODE_203', 203); |
|
| 13 | +define('STATUS_CODE_204', 204); |
|
| 14 | +define('STATUS_CODE_205', 205); |
|
| 15 | +define('STATUS_CODE_206', 206); |
|
| 16 | +define('STATUS_CODE_207', 207); |
|
| 17 | +define('STATUS_CODE_226', 226); |
|
| 18 | 18 | |
| 19 | -define('STATUS_CODE_300', 300); |
|
| 20 | -define('STATUS_CODE_301', 301); |
|
| 21 | -define('STATUS_CODE_302', 302); |
|
| 22 | -define('STATUS_CODE_303', 303); |
|
| 23 | -define('STATUS_CODE_304', 304); |
|
| 24 | -define('STATUS_CODE_305', 305); |
|
| 25 | -define('STATUS_CODE_307', 307); |
|
| 19 | +define('STATUS_CODE_300', 300); |
|
| 20 | +define('STATUS_CODE_301', 301); |
|
| 21 | +define('STATUS_CODE_302', 302); |
|
| 22 | +define('STATUS_CODE_303', 303); |
|
| 23 | +define('STATUS_CODE_304', 304); |
|
| 24 | +define('STATUS_CODE_305', 305); |
|
| 25 | +define('STATUS_CODE_307', 307); |
|
| 26 | 26 | |
| 27 | -define('STATUS_CODE_400', 400); |
|
| 28 | -define('STATUS_CODE_401', 401); |
|
| 29 | -define('STATUS_CODE_402', 402); |
|
| 30 | -define('STATUS_CODE_403', 403); |
|
| 31 | -define('STATUS_CODE_404', 404); |
|
| 32 | -define('STATUS_CODE_405', 405); |
|
| 33 | -define('STATUS_CODE_406', 406); |
|
| 34 | -define('STATUS_CODE_407', 407); |
|
| 35 | -define('STATUS_CODE_408', 408); |
|
| 36 | -define('STATUS_CODE_409', 409); |
|
| 37 | -define('STATUS_CODE_410', 410); |
|
| 38 | -define('STATUS_CODE_411', 411); |
|
| 39 | -define('STATUS_CODE_412', 412); |
|
| 40 | -define('STATUS_CODE_413', 413); |
|
| 41 | -define('STATUS_CODE_414', 414); |
|
| 42 | -define('STATUS_CODE_415', 415); |
|
| 43 | -define('STATUS_CODE_416', 416); |
|
| 44 | -define('STATUS_CODE_417', 417); |
|
| 45 | -define('STATUS_CODE_422', 422); |
|
| 46 | -define('STATUS_CODE_423', 423); |
|
| 47 | -define('STATUS_CODE_424', 424); |
|
| 48 | -define('STATUS_CODE_425', 425); |
|
| 49 | -define('STATUS_CODE_426', 426); |
|
| 50 | -define('STATUS_CODE_449', 449); |
|
| 27 | +define('STATUS_CODE_400', 400); |
|
| 28 | +define('STATUS_CODE_401', 401); |
|
| 29 | +define('STATUS_CODE_402', 402); |
|
| 30 | +define('STATUS_CODE_403', 403); |
|
| 31 | +define('STATUS_CODE_404', 404); |
|
| 32 | +define('STATUS_CODE_405', 405); |
|
| 33 | +define('STATUS_CODE_406', 406); |
|
| 34 | +define('STATUS_CODE_407', 407); |
|
| 35 | +define('STATUS_CODE_408', 408); |
|
| 36 | +define('STATUS_CODE_409', 409); |
|
| 37 | +define('STATUS_CODE_410', 410); |
|
| 38 | +define('STATUS_CODE_411', 411); |
|
| 39 | +define('STATUS_CODE_412', 412); |
|
| 40 | +define('STATUS_CODE_413', 413); |
|
| 41 | +define('STATUS_CODE_414', 414); |
|
| 42 | +define('STATUS_CODE_415', 415); |
|
| 43 | +define('STATUS_CODE_416', 416); |
|
| 44 | +define('STATUS_CODE_417', 417); |
|
| 45 | +define('STATUS_CODE_422', 422); |
|
| 46 | +define('STATUS_CODE_423', 423); |
|
| 47 | +define('STATUS_CODE_424', 424); |
|
| 48 | +define('STATUS_CODE_425', 425); |
|
| 49 | +define('STATUS_CODE_426', 426); |
|
| 50 | +define('STATUS_CODE_449', 449); |
|
| 51 | 51 | |
| 52 | -define('STATUS_CODE_500', 500); |
|
| 53 | -define('STATUS_CODE_501', 501); |
|
| 54 | -define('STATUS_CODE_502', 502); |
|
| 55 | -define('STATUS_CODE_503', 503); |
|
| 56 | -define('STATUS_CODE_504', 504); |
|
| 57 | -define('STATUS_CODE_505', 505); |
|
| 58 | -define('STATUS_CODE_506', 506); |
|
| 59 | -define('STATUS_CODE_507', 507); |
|
| 60 | -define('STATUS_CODE_509', 509); |
|
| 61 | -define('STATUS_CODE_510', 510); |
|
| 52 | +define('STATUS_CODE_500', 500); |
|
| 53 | +define('STATUS_CODE_501', 501); |
|
| 54 | +define('STATUS_CODE_502', 502); |
|
| 55 | +define('STATUS_CODE_503', 503); |
|
| 56 | +define('STATUS_CODE_504', 504); |
|
| 57 | +define('STATUS_CODE_505', 505); |
|
| 58 | +define('STATUS_CODE_506', 506); |
|
| 59 | +define('STATUS_CODE_507', 507); |
|
| 60 | +define('STATUS_CODE_509', 509); |
|
| 61 | +define('STATUS_CODE_510', 510); |
|
@@ -14,7 +14,7 @@ |
||
| 14 | 14 | define('REGEX_TEMPLATE_COMPONENT_NAME', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
| 15 | 15 | |
| 16 | 16 | define('REGEX_TEMPLATE_STRUCTURE', '/(?s){[ ]*(!)?[ ]*(block|for|widget)[ ]*:[ ]*([a-zA-Z0-9_]+)[ ]*' . |
| 17 | - '(?:\/[ ]*}|}(.*?){[ ]*\/[ ]*\2[ ]*:[ ]*\3[ ]*})/'); |
|
| 17 | + '(?:\/[ ]*}|}(.*?){[ ]*\/[ ]*\2[ ]*:[ ]*\3[ ]*})/'); |
|
| 18 | 18 | |
| 19 | 19 | define('REGEX_TEMPLATE_VARIABLE', '/\$([a-zA-Z0-9_]+)\$/'); |
| 20 | 20 | define('REGEX_TEMPLATE_PHRASE', '/\%([a-zA-Z0-9_]+)\%/'); |
@@ -2,19 +2,19 @@ |
||
| 2 | 2 | |
| 3 | 3 | # Form expressions |
| 4 | 4 | |
| 5 | -define('REGEX_FORM_NAME', '/^[a-zA-Z][a-zA-Z0-9]*$/'); |
|
| 6 | -define('REGEX_FORM_FIELD_KEY', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
| 5 | +define('REGEX_FORM_NAME', '/^[a-zA-Z][a-zA-Z0-9]*$/'); |
|
| 6 | +define('REGEX_FORM_FIELD_KEY', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
| 7 | 7 | |
| 8 | 8 | # Language expressions |
| 9 | 9 | |
| 10 | -define('REGEX_LANGUAGE_PHRASE_NAME', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
| 10 | +define('REGEX_LANGUAGE_PHRASE_NAME', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
| 11 | 11 | |
| 12 | 12 | # Template expressions |
| 13 | 13 | |
| 14 | -define('REGEX_TEMPLATE_COMPONENT_NAME', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
| 14 | +define('REGEX_TEMPLATE_COMPONENT_NAME', '/^(?![0-9_])(?!.*_$)(?!.*_{2,})[a-zA-Z0-9_]+$/'); |
|
| 15 | 15 | |
| 16 | -define('REGEX_TEMPLATE_STRUCTURE', '/(?s){[ ]*(!)?[ ]*(block|for|widget)[ ]*:[ ]*([a-zA-Z0-9_]+)[ ]*' . |
|
| 16 | +define('REGEX_TEMPLATE_STRUCTURE', '/(?s){[ ]*(!)?[ ]*(block|for|widget)[ ]*:[ ]*([a-zA-Z0-9_]+)[ ]*'. |
|
| 17 | 17 | '(?:\/[ ]*}|}(.*?){[ ]*\/[ ]*\2[ ]*:[ ]*\3[ ]*})/'); |
| 18 | 18 | |
| 19 | -define('REGEX_TEMPLATE_VARIABLE', '/\$([a-zA-Z0-9_]+)\$/'); |
|
| 20 | -define('REGEX_TEMPLATE_PHRASE', '/\%([a-zA-Z0-9_]+)\%/'); |
|
| 19 | +define('REGEX_TEMPLATE_VARIABLE', '/\$([a-zA-Z0-9_]+)\$/'); |
|
| 20 | +define('REGEX_TEMPLATE_PHRASE', '/\%([a-zA-Z0-9_]+)\%/'); |
|
@@ -17,11 +17,17 @@ discard block |
||
| 17 | 17 | |
| 18 | 18 | public static function forceInt($number, int $min = 0, int $max = 0) { |
| 19 | 19 | |
| 20 | - if (!is_numeric($number) || (($number = intval($number)) < 0)) $number = 0; |
|
| 20 | + if (!is_numeric($number) || (($number = intval($number)) < 0)) { |
|
| 21 | + $number = 0; |
|
| 22 | + } |
|
| 21 | 23 | |
| 22 | - if (($min > 0) && ($number < $min)) return $min; |
|
| 24 | + if (($min > 0) && ($number < $min)) { |
|
| 25 | + return $min; |
|
| 26 | + } |
|
| 23 | 27 | |
| 24 | - if (($max > 0) && ($number > $max)) return $max; |
|
| 28 | + if (($max > 0) && ($number > $max)) { |
|
| 29 | + return $max; |
|
| 30 | + } |
|
| 25 | 31 | |
| 26 | 32 | # ------------------------ |
| 27 | 33 | |
@@ -34,11 +40,17 @@ discard block |
||
| 34 | 40 | |
| 35 | 41 | public static function forceFloat($number, float $min = 0, float $max = 0, int $decimals = 0) { |
| 36 | 42 | |
| 37 | - if (!is_numeric($number) || (($number = floatval($number)) < 0)) $number = 0; |
|
| 43 | + if (!is_numeric($number) || (($number = floatval($number)) < 0)) { |
|
| 44 | + $number = 0; |
|
| 45 | + } |
|
| 38 | 46 | |
| 39 | - if (($min > 0) && ($number < $min)) $number = $min; |
|
| 47 | + if (($min > 0) && ($number < $min)) { |
|
| 48 | + $number = $min; |
|
| 49 | + } |
|
| 40 | 50 | |
| 41 | - if (($max > 0) && ($number > $max)) $number = $max; |
|
| 51 | + if (($max > 0) && ($number > $max)) { |
|
| 52 | + $number = $max; |
|
| 53 | + } |
|
| 42 | 54 | |
| 43 | 55 | $number = floatval(number_format($number, $decimals, '.', '')); |
| 44 | 56 | |
@@ -55,9 +67,11 @@ discard block |
||
| 55 | 67 | |
| 56 | 68 | $number = (($number >= 0) ? $number : 0); $exponents = [0 => 'Bytes', 'KB', 'MB', 'GB', 'TB']; |
| 57 | 69 | |
| 58 | - foreach ($exponents as $exponent => $text) if ($number < pow(1024, ($exponent + 1))) { |
|
| 70 | + foreach ($exponents as $exponent => $text) { |
|
| 71 | + if ($number < pow(1024, ($exponent + 1))) { |
|
| 59 | 72 | |
| 60 | 73 | $number = number_format(($number / pow(1024, $exponent)), (($exponent < 2) ? $exponent : 2)); |
| 74 | + } |
|
| 61 | 75 | |
| 62 | 76 | return (floatval($number) . ' ' . $text); |
| 63 | 77 | } |
@@ -79,13 +93,21 @@ discard block |
||
| 79 | 93 | |
| 80 | 94 | $last_1 = substr($number, ($length - 1), 1); $last_2 = substr($number, ($length - 2), 2); |
| 81 | 95 | |
| 82 | - if (($last_2 >= 11) && ($last_2 <= 20)) return $form_5; |
|
| 96 | + if (($last_2 >= 11) && ($last_2 <= 20)) { |
|
| 97 | + return $form_5; |
|
| 98 | + } |
|
| 83 | 99 | |
| 84 | - if ($last_1 == 1) return $form_1; |
|
| 100 | + if ($last_1 == 1) { |
|
| 101 | + return $form_1; |
|
| 102 | + } |
|
| 85 | 103 | |
| 86 | - if (($last_1 >= 2) && ($last_1 <= 4)) return $form_3; |
|
| 104 | + if (($last_1 >= 2) && ($last_1 <= 4)) { |
|
| 105 | + return $form_3; |
|
| 106 | + } |
|
| 87 | 107 | |
| 88 | - if (($last_1 >= 5) || ($last_1 == 0)) return $form_5; |
|
| 108 | + if (($last_1 >= 5) || ($last_1 == 0)) { |
|
| 109 | + return $form_5; |
|
| 110 | + } |
|
| 89 | 111 | } |
| 90 | 112 | } |
| 91 | 113 | } |
@@ -19,7 +19,9 @@ |
||
| 19 | 19 | |
| 20 | 20 | protected static function init(string $file_name) { |
| 21 | 21 | |
| 22 | - if (is_array($range = Explorer::include($file_name))) static::$range = $range; |
|
| 22 | + if (is_array($range = Explorer::include($file_name))) { |
|
| 23 | + static::$range = $range; |
|
| 24 | + } |
|
| 23 | 25 | } |
| 24 | 26 | |
| 25 | 27 | /** |
@@ -30,7 +30,9 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | public static function stringify(SimpleXMLElement $xml) { |
| 32 | 32 | |
| 33 | - if (false === ($xml = dom_import_simplexml($xml))) return false; |
|
| 33 | + if (false === ($xml = dom_import_simplexml($xml))) { |
|
| 34 | + return false; |
|
| 35 | + } |
|
| 34 | 36 | |
| 35 | 37 | $dom = $xml->ownerDocument; $dom->formatOutput = true; |
| 36 | 38 | |
@@ -47,7 +49,9 @@ discard block |
||
| 47 | 49 | |
| 48 | 50 | public static function load(string $file_name) { |
| 49 | 51 | |
| 50 | - if (false === ($contents = Explorer::getContents($file_name))) return false; |
|
| 52 | + if (false === ($contents = Explorer::getContents($file_name))) { |
|
| 53 | + return false; |
|
| 54 | + } |
|
| 51 | 55 | |
| 52 | 56 | return self::parse($contents); |
| 53 | 57 | } |
@@ -60,7 +64,9 @@ discard block |
||
| 60 | 64 | |
| 61 | 65 | public static function save(string $file_name, SimpleXMLElement $xml) { |
| 62 | 66 | |
| 63 | - if (false === ($xml = self::stringify($xml))) return false; |
|
| 67 | + if (false === ($xml = self::stringify($xml))) { |
|
| 68 | + return false; |
|
| 69 | + } |
|
| 64 | 70 | |
| 65 | 71 | return Explorer::putContents($file_name, $xml); |
| 66 | 72 | } |