@@ -111,18 +111,18 @@ discard block |
||
| 111 | 111 | } |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | - /** |
|
| 115 | - * Adds a callback as a validation method. The callback gets the |
|
| 116 | - * value to validate as first parameter, and any additional |
|
| 117 | - * parameters passed here get appended to that. |
|
| 118 | - * |
|
| 119 | - * The callback must return boolean true or false depending on |
|
| 120 | - * whether the value is valid. |
|
| 121 | - * |
|
| 122 | - * @param mixed $callback |
|
| 123 | - * @param array $args |
|
| 124 | - * @return Request_Param |
|
| 125 | - */ |
|
| 114 | + /** |
|
| 115 | + * Adds a callback as a validation method. The callback gets the |
|
| 116 | + * value to validate as first parameter, and any additional |
|
| 117 | + * parameters passed here get appended to that. |
|
| 118 | + * |
|
| 119 | + * The callback must return boolean true or false depending on |
|
| 120 | + * whether the value is valid. |
|
| 121 | + * |
|
| 122 | + * @param mixed $callback |
|
| 123 | + * @param array $args |
|
| 124 | + * @return Request_Param |
|
| 125 | + */ |
|
| 126 | 126 | public function setCallback($callback, $args=array()) |
| 127 | 127 | { |
| 128 | 128 | if(!is_callable($callback)) { |
@@ -264,13 +264,13 @@ discard block |
||
| 264 | 264 | |
| 265 | 265 | protected $valueType = self::VALUE_TYPE_STRING; |
| 266 | 266 | |
| 267 | - /** |
|
| 268 | - * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 269 | - * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 270 | - * <code>145</code>. |
|
| 271 | - * |
|
| 272 | - * @return Request_Param |
|
| 273 | - */ |
|
| 267 | + /** |
|
| 268 | + * Sets the variable to contain a comma-separated list of integer IDs. |
|
| 269 | + * Example: <code>145,248,4556</code>. A single ID is also allowed, e.g. |
|
| 270 | + * <code>145</code>. |
|
| 271 | + * |
|
| 272 | + * @return Request_Param |
|
| 273 | + */ |
|
| 274 | 274 | public function setIDList() |
| 275 | 275 | { |
| 276 | 276 | $this->valueType = self::VALUE_TYPE_ID_LIST; |
@@ -279,13 +279,13 @@ discard block |
||
| 279 | 279 | return $this; |
| 280 | 280 | } |
| 281 | 281 | |
| 282 | - /** |
|
| 283 | - * Sets the variable to be an alias, as defined by the |
|
| 284 | - * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 285 | - * |
|
| 286 | - * @return Request_Param |
|
| 287 | - * @see RegexHelper::REGEX_ALIAS |
|
| 288 | - */ |
|
| 282 | + /** |
|
| 283 | + * Sets the variable to be an alias, as defined by the |
|
| 284 | + * {@link RegexHelper::REGEX_ALIAS} regular expression. |
|
| 285 | + * |
|
| 286 | + * @return Request_Param |
|
| 287 | + * @see RegexHelper::REGEX_ALIAS |
|
| 288 | + */ |
|
| 289 | 289 | public function setAlias() |
| 290 | 290 | { |
| 291 | 291 | return $this->setRegex(RegexHelper::REGEX_ALIAS); |
@@ -326,12 +326,12 @@ discard block |
||
| 326 | 326 | return $this->setValidation(self::VALIDATION_TYPE_ALPHA); |
| 327 | 327 | } |
| 328 | 328 | |
| 329 | - /** |
|
| 330 | - * Sets the parameter value as a string containing lowercase |
|
| 331 | - * and/or uppercase letters, as well as numbers. |
|
| 332 | - * |
|
| 333 | - * @return Request_Param |
|
| 334 | - */ |
|
| 329 | + /** |
|
| 330 | + * Sets the parameter value as a string containing lowercase |
|
| 331 | + * and/or uppercase letters, as well as numbers. |
|
| 332 | + * |
|
| 333 | + * @return Request_Param |
|
| 334 | + */ |
|
| 335 | 335 | public function setAlnum() |
| 336 | 336 | { |
| 337 | 337 | return $this->setValidation(self::VALIDATION_TYPE_ALNUM); |
@@ -359,17 +359,17 @@ discard block |
||
| 359 | 359 | return $this->setValidation(self::VALIDATION_TYPE_ENUM, $args); |
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - /** |
|
| 363 | - * Only available for array values: the parameter must be |
|
| 364 | - * an array value, and the array may only contain values |
|
| 365 | - * specified in the values array. |
|
| 366 | - * |
|
| 367 | - * Submitted values that are not in the allowed list of |
|
| 368 | - * values are stripped from the value. |
|
| 369 | - * |
|
| 370 | - * @param array $values List of allowed values |
|
| 371 | - * @return \AppUtils\Request_Param |
|
| 372 | - */ |
|
| 362 | + /** |
|
| 363 | + * Only available for array values: the parameter must be |
|
| 364 | + * an array value, and the array may only contain values |
|
| 365 | + * specified in the values array. |
|
| 366 | + * |
|
| 367 | + * Submitted values that are not in the allowed list of |
|
| 368 | + * values are stripped from the value. |
|
| 369 | + * |
|
| 370 | + * @param array $values List of allowed values |
|
| 371 | + * @return \AppUtils\Request_Param |
|
| 372 | + */ |
|
| 373 | 373 | public function setValuesList(array $values) |
| 374 | 374 | { |
| 375 | 375 | $this->setArray(); |
@@ -382,39 +382,39 @@ discard block |
||
| 382 | 382 | return $this->setValidation(self::VALIDATION_TYPE_ARRAY); |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - /** |
|
| 386 | - * Specifies that a JSON-encoded string is expected. |
|
| 387 | - * |
|
| 388 | - * NOTE: Numbers or quoted strings are technically valid |
|
| 389 | - * JSON, but are not accepted, because it is assumed |
|
| 390 | - * at least an array or object are expected. |
|
| 391 | - * |
|
| 392 | - * @return \AppUtils\Request_Param |
|
| 393 | - */ |
|
| 385 | + /** |
|
| 386 | + * Specifies that a JSON-encoded string is expected. |
|
| 387 | + * |
|
| 388 | + * NOTE: Numbers or quoted strings are technically valid |
|
| 389 | + * JSON, but are not accepted, because it is assumed |
|
| 390 | + * at least an array or object are expected. |
|
| 391 | + * |
|
| 392 | + * @return \AppUtils\Request_Param |
|
| 393 | + */ |
|
| 394 | 394 | public function setJSON() : Request_Param |
| 395 | 395 | { |
| 396 | 396 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => true)); |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Like {@link Request_Param::setJSON()}, but accepts |
|
| 401 | - * only JSON objects. Arrays will not be accepted. |
|
| 402 | - * |
|
| 403 | - * @return \AppUtils\Request_Param |
|
| 404 | - */ |
|
| 399 | + /** |
|
| 400 | + * Like {@link Request_Param::setJSON()}, but accepts |
|
| 401 | + * only JSON objects. Arrays will not be accepted. |
|
| 402 | + * |
|
| 403 | + * @return \AppUtils\Request_Param |
|
| 404 | + */ |
|
| 405 | 405 | public function setJSONObject() : Request_Param |
| 406 | 406 | { |
| 407 | 407 | return $this->setValidation(self::VALIDATION_TYPE_JSON, array('arrays' => false)); |
| 408 | 408 | } |
| 409 | 409 | |
| 410 | - /** |
|
| 411 | - * The parameter is a string boolean representation. This means |
|
| 412 | - * it can be any of the following: "yes", "true", "no", "false". |
|
| 413 | - * The value is automatically converted to a boolean when retrieving |
|
| 414 | - * the parameter. |
|
| 415 | - * |
|
| 416 | - * @return Request_Param |
|
| 417 | - */ |
|
| 410 | + /** |
|
| 411 | + * The parameter is a string boolean representation. This means |
|
| 412 | + * it can be any of the following: "yes", "true", "no", "false". |
|
| 413 | + * The value is automatically converted to a boolean when retrieving |
|
| 414 | + * the parameter. |
|
| 415 | + * |
|
| 416 | + * @return Request_Param |
|
| 417 | + */ |
|
| 418 | 418 | public function setBoolean() : Request_Param |
| 419 | 419 | { |
| 420 | 420 | $this->addCallbackFilter(array($this, 'applyFilter_boolean')); |
@@ -478,15 +478,15 @@ discard block |
||
| 478 | 478 | return $keep; |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - /** |
|
| 482 | - * Validates the request parameter as an MD5 string, |
|
| 483 | - * so that only values resembling md5 values are accepted. |
|
| 484 | - * |
|
| 485 | - * NOTE: This can only guarantee the format, not whether |
|
| 486 | - * it is an actual valid hash of something. |
|
| 487 | - * |
|
| 488 | - * @return \AppUtils\Request_Param |
|
| 489 | - */ |
|
| 481 | + /** |
|
| 482 | + * Validates the request parameter as an MD5 string, |
|
| 483 | + * so that only values resembling md5 values are accepted. |
|
| 484 | + * |
|
| 485 | + * NOTE: This can only guarantee the format, not whether |
|
| 486 | + * it is an actual valid hash of something. |
|
| 487 | + * |
|
| 488 | + * @return \AppUtils\Request_Param |
|
| 489 | + */ |
|
| 490 | 490 | public function setMD5() : Request_Param |
| 491 | 491 | { |
| 492 | 492 | return $this->setRegex(RegexHelper::REGEX_MD5); |
@@ -528,14 +528,14 @@ discard block |
||
| 528 | 528 | return $this; |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - /** |
|
| 532 | - * Retrieves the value of the request parameter, |
|
| 533 | - * applying all filters (if any) and validation |
|
| 534 | - * (if any). |
|
| 535 | - * |
|
| 536 | - * @param mixed $default |
|
| 537 | - * @return mixed |
|
| 538 | - */ |
|
| 531 | + /** |
|
| 532 | + * Retrieves the value of the request parameter, |
|
| 533 | + * applying all filters (if any) and validation |
|
| 534 | + * (if any). |
|
| 535 | + * |
|
| 536 | + * @param mixed $default |
|
| 537 | + * @return mixed |
|
| 538 | + */ |
|
| 539 | 539 | public function get($default=null) |
| 540 | 540 | { |
| 541 | 541 | $value = $this->request->getParam($this->paramName); |
@@ -565,12 +565,12 @@ discard block |
||
| 565 | 565 | return null; |
| 566 | 566 | } |
| 567 | 567 | |
| 568 | - /** |
|
| 569 | - * Validates the syntax of an URL, but not its actual validity. |
|
| 570 | - * |
|
| 571 | - * @param mixed $value |
|
| 572 | - * @return string |
|
| 573 | - */ |
|
| 568 | + /** |
|
| 569 | + * Validates the syntax of an URL, but not its actual validity. |
|
| 570 | + * |
|
| 571 | + * @param mixed $value |
|
| 572 | + * @return string |
|
| 573 | + */ |
|
| 574 | 574 | protected function validate_url($value) : string |
| 575 | 575 | { |
| 576 | 576 | if(!is_string($value)) { |
@@ -710,10 +710,10 @@ discard block |
||
| 710 | 710 | return null; |
| 711 | 711 | } |
| 712 | 712 | |
| 713 | - /** |
|
| 714 | - * Makes sure that the value is a JSON-encoded string. |
|
| 715 | - * @param string $value |
|
| 716 | - */ |
|
| 713 | + /** |
|
| 714 | + * Makes sure that the value is a JSON-encoded string. |
|
| 715 | + * @param string $value |
|
| 716 | + */ |
|
| 717 | 717 | protected function validate_json($value) |
| 718 | 718 | { |
| 719 | 719 | if(!is_string($value)) { |
@@ -730,7 +730,7 @@ discard block |
||
| 730 | 730 | if($this->validationParams['arrays'] === false) |
| 731 | 731 | { |
| 732 | 732 | if(is_object(json_decode($value))) { |
| 733 | - return $value; |
|
| 733 | + return $value; |
|
| 734 | 734 | } |
| 735 | 735 | } |
| 736 | 736 | else |
@@ -811,12 +811,12 @@ discard block |
||
| 811 | 811 | return $this; |
| 812 | 812 | } |
| 813 | 813 | |
| 814 | - /** |
|
| 815 | - * Adds a filter that trims whitespace from the request |
|
| 816 | - * parameter using the PHP <code>trim</code> function. |
|
| 817 | - * |
|
| 818 | - * @return \AppUtils\Request_Param |
|
| 819 | - */ |
|
| 814 | + /** |
|
| 815 | + * Adds a filter that trims whitespace from the request |
|
| 816 | + * parameter using the PHP <code>trim</code> function. |
|
| 817 | + * |
|
| 818 | + * @return \AppUtils\Request_Param |
|
| 819 | + */ |
|
| 820 | 820 | public function addFilterTrim() : Request_Param |
| 821 | 821 | { |
| 822 | 822 | // to guarantee we only work with strings |
@@ -825,13 +825,13 @@ discard block |
||
| 825 | 825 | return $this->addCallbackFilter('trim'); |
| 826 | 826 | } |
| 827 | 827 | |
| 828 | - /** |
|
| 829 | - * Converts the value to a string, even if it is not |
|
| 830 | - * a string value. Complex types like arrays and objects |
|
| 831 | - * are converted to an empty string. |
|
| 832 | - * |
|
| 833 | - * @return \AppUtils\Request_Param |
|
| 834 | - */ |
|
| 828 | + /** |
|
| 829 | + * Converts the value to a string, even if it is not |
|
| 830 | + * a string value. Complex types like arrays and objects |
|
| 831 | + * are converted to an empty string. |
|
| 832 | + * |
|
| 833 | + * @return \AppUtils\Request_Param |
|
| 834 | + */ |
|
| 835 | 835 | public function addStringFilter() : Request_Param |
| 836 | 836 | { |
| 837 | 837 | return $this->addCallbackFilter(array($this, 'applyFilter_string')); |
@@ -881,12 +881,12 @@ discard block |
||
| 881 | 881 | return $this->addCallbackFilter('strip_tags', array($allowedTags)); |
| 882 | 882 | } |
| 883 | 883 | |
| 884 | - /** |
|
| 885 | - * Adds a filter that strips all whitespace from the |
|
| 886 | - * request parameter, from spaces to tabs and newlines. |
|
| 887 | - * |
|
| 888 | - * @return \AppUtils\Request_Param |
|
| 889 | - */ |
|
| 884 | + /** |
|
| 885 | + * Adds a filter that strips all whitespace from the |
|
| 886 | + * request parameter, from spaces to tabs and newlines. |
|
| 887 | + * |
|
| 888 | + * @return \AppUtils\Request_Param |
|
| 889 | + */ |
|
| 890 | 890 | public function addStripWhitespaceFilter() : Request_Param |
| 891 | 891 | { |
| 892 | 892 | // to ensure we only work with strings. |
@@ -895,14 +895,14 @@ discard block |
||
| 895 | 895 | return $this->addCallbackFilter(array($this, 'applyFilter_stripWhitespace')); |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - /** |
|
| 899 | - * Adds a filter that transforms comma separated values |
|
| 900 | - * into an array of values. |
|
| 901 | - * |
|
| 902 | - * @param bool $trimEntries Trim whitespace from each entry? |
|
| 903 | - * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 904 | - * @return \AppUtils\Request_Param |
|
| 905 | - */ |
|
| 898 | + /** |
|
| 899 | + * Adds a filter that transforms comma separated values |
|
| 900 | + * into an array of values. |
|
| 901 | + * |
|
| 902 | + * @param bool $trimEntries Trim whitespace from each entry? |
|
| 903 | + * @param bool $stripEmptyEntries Remove empty entries from the array? |
|
| 904 | + * @return \AppUtils\Request_Param |
|
| 905 | + */ |
|
| 906 | 906 | public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
| 907 | 907 | { |
| 908 | 908 | $this->setArray(); |
@@ -916,12 +916,12 @@ discard block |
||
| 916 | 916 | ); |
| 917 | 917 | } |
| 918 | 918 | |
| 919 | - /** |
|
| 920 | - * Adds a filter that encodes all HTML special characters |
|
| 921 | - * using the PHP <code>htmlspecialchars</code> function. |
|
| 922 | - * |
|
| 923 | - * @return \AppUtils\Request_Param |
|
| 924 | - */ |
|
| 919 | + /** |
|
| 920 | + * Adds a filter that encodes all HTML special characters |
|
| 921 | + * using the PHP <code>htmlspecialchars</code> function. |
|
| 922 | + * |
|
| 923 | + * @return \AppUtils\Request_Param |
|
| 924 | + */ |
|
| 925 | 925 | public function addHTMLSpecialcharsFilter() : Request_Param |
| 926 | 926 | { |
| 927 | 927 | return $this->addCallbackFilter('htmlspecialchars', array(ENT_QUOTES, 'UTF-8')); |
@@ -934,14 +934,14 @@ discard block |
||
| 934 | 934 | |
| 935 | 935 | protected $required = false; |
| 936 | 936 | |
| 937 | - /** |
|
| 938 | - * Marks this request parameter as required. To use this feature, |
|
| 939 | - * you have to call the request's {@link Request::validate()} |
|
| 940 | - * method. |
|
| 941 | - * |
|
| 942 | - * @return Request_Param |
|
| 943 | - * @see Request::validate() |
|
| 944 | - */ |
|
| 937 | + /** |
|
| 938 | + * Marks this request parameter as required. To use this feature, |
|
| 939 | + * you have to call the request's {@link Request::validate()} |
|
| 940 | + * method. |
|
| 941 | + * |
|
| 942 | + * @return Request_Param |
|
| 943 | + * @see Request::validate() |
|
| 944 | + */ |
|
| 945 | 945 | public function makeRequired() : Request_Param |
| 946 | 946 | { |
| 947 | 947 | $this->required = true; |
@@ -123,9 +123,9 @@ discard block |
||
| 123 | 123 | * @param array $args |
| 124 | 124 | * @return Request_Param |
| 125 | 125 | */ |
| 126 | - public function setCallback($callback, $args=array()) |
|
| 126 | + public function setCallback($callback, $args = array()) |
|
| 127 | 127 | { |
| 128 | - if(!is_callable($callback)) { |
|
| 128 | + if (!is_callable($callback)) { |
|
| 129 | 129 | throw new Request_Exception( |
| 130 | 130 | 'Not a valid callback', |
| 131 | 131 | 'The specified callback is not a valid callable entity.', |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | array_unshift($args, $value); |
| 149 | 149 | |
| 150 | 150 | $result = call_user_func_array($this->validationParams['callback'], $args); |
| 151 | - if($result !== false) { |
|
| 151 | + if ($result !== false) { |
|
| 152 | 152 | return $value; |
| 153 | 153 | } |
| 154 | 154 | |
@@ -175,13 +175,13 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | // go through all enqueued validations in turn, each time |
| 177 | 177 | // replacing the value with the adjusted, validated value. |
| 178 | - foreach($this->validations as $validateDef) |
|
| 178 | + foreach ($this->validations as $validateDef) |
|
| 179 | 179 | { |
| 180 | 180 | $this->validationType = $validateDef['type']; |
| 181 | 181 | $this->validationParams = $validateDef['params']; |
| 182 | 182 | |
| 183 | 183 | // and now, see if we have to validate the value as well |
| 184 | - $method = 'validate_' . $this->validationType; |
|
| 184 | + $method = 'validate_'.$this->validationType; |
|
| 185 | 185 | if (!method_exists($this, $method)) { |
| 186 | 186 | throw new Request_Exception( |
| 187 | 187 | 'Unknown validation type.', |
@@ -195,19 +195,19 @@ discard block |
||
| 195 | 195 | ); |
| 196 | 196 | } |
| 197 | 197 | |
| 198 | - if($this->valueType === self::VALUE_TYPE_ID_LIST) |
|
| 198 | + if ($this->valueType === self::VALUE_TYPE_ID_LIST) |
|
| 199 | 199 | { |
| 200 | - if(!is_array($value)) { |
|
| 200 | + if (!is_array($value)) { |
|
| 201 | 201 | $value = explode(',', $value); |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | $keep = array(); |
| 205 | - foreach($value as $subval) |
|
| 205 | + foreach ($value as $subval) |
|
| 206 | 206 | { |
| 207 | 207 | $subval = trim($subval); |
| 208 | 208 | $subval = $this->$method($subval); |
| 209 | 209 | |
| 210 | - if($subval !== null) { |
|
| 210 | + if ($subval !== null) { |
|
| 211 | 211 | $keep[] = intval($subval); |
| 212 | 212 | } |
| 213 | 213 | } |
@@ -423,7 +423,7 @@ discard block |
||
| 423 | 423 | |
| 424 | 424 | protected function applyFilter_boolean($value) |
| 425 | 425 | { |
| 426 | - if($value == 'yes' || $value == 'true') { |
|
| 426 | + if ($value == 'yes' || $value == 'true') { |
|
| 427 | 427 | return true; |
| 428 | 428 | } |
| 429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | |
| 438 | 438 | protected function applyFilter_string($value) |
| 439 | 439 | { |
| 440 | - if(!is_scalar($value)) { |
|
| 440 | + if (!is_scalar($value)) { |
|
| 441 | 441 | return ''; |
| 442 | 442 | } |
| 443 | 443 | |
@@ -446,29 +446,29 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | protected function applyFilter_commaSeparated($value, bool $trimEntries, bool $stripEmptyEntries) |
| 448 | 448 | { |
| 449 | - if(is_array($value)) { |
|
| 449 | + if (is_array($value)) { |
|
| 450 | 450 | return $value; |
| 451 | 451 | } |
| 452 | 452 | |
| 453 | - if($value === '' || $value === null || !is_string($value)) { |
|
| 453 | + if ($value === '' || $value === null || !is_string($value)) { |
|
| 454 | 454 | return array(); |
| 455 | 455 | } |
| 456 | 456 | |
| 457 | 457 | $result = explode(',', $value); |
| 458 | 458 | |
| 459 | - if(!$trimEntries && !$stripEmptyEntries) { |
|
| 459 | + if (!$trimEntries && !$stripEmptyEntries) { |
|
| 460 | 460 | return $result; |
| 461 | 461 | } |
| 462 | 462 | |
| 463 | 463 | $keep = array(); |
| 464 | 464 | |
| 465 | - foreach($result as $entry) |
|
| 465 | + foreach ($result as $entry) |
|
| 466 | 466 | { |
| 467 | - if($trimEntries === true) { |
|
| 467 | + if ($trimEntries === true) { |
|
| 468 | 468 | $entry = trim($entry); |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - if($stripEmptyEntries === true && $entry === '') { |
|
| 471 | + if ($stripEmptyEntries === true && $entry === '') { |
|
| 472 | 472 | continue; |
| 473 | 473 | } |
| 474 | 474 | |
@@ -536,10 +536,10 @@ discard block |
||
| 536 | 536 | * @param mixed $default |
| 537 | 537 | * @return mixed |
| 538 | 538 | */ |
| 539 | - public function get($default=null) |
|
| 539 | + public function get($default = null) |
|
| 540 | 540 | { |
| 541 | 541 | $value = $this->request->getParam($this->paramName); |
| 542 | - if($value !== null && $value !== '') { |
|
| 542 | + if ($value !== null && $value !== '') { |
|
| 543 | 543 | return $value; |
| 544 | 544 | } |
| 545 | 545 | |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | */ |
| 559 | 559 | protected function validate_integer($value) : ?int |
| 560 | 560 | { |
| 561 | - if(ConvertHelper::isInteger($value)) { |
|
| 561 | + if (ConvertHelper::isInteger($value)) { |
|
| 562 | 562 | return intval($value); |
| 563 | 563 | } |
| 564 | 564 | |
@@ -573,12 +573,12 @@ discard block |
||
| 573 | 573 | */ |
| 574 | 574 | protected function validate_url($value) : string |
| 575 | 575 | { |
| 576 | - if(!is_string($value)) { |
|
| 576 | + if (!is_string($value)) { |
|
| 577 | 577 | return ''; |
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | $info = parse_url($value); |
| 581 | - if(isset($info['host'])) { |
|
| 581 | + if (isset($info['host'])) { |
|
| 582 | 582 | return $value; |
| 583 | 583 | } |
| 584 | 584 | |
@@ -594,7 +594,7 @@ discard block |
||
| 594 | 594 | */ |
| 595 | 595 | protected function validate_numeric($value) : ?float |
| 596 | 596 | { |
| 597 | - if(is_numeric($value)) { |
|
| 597 | + if (is_numeric($value)) { |
|
| 598 | 598 | return $value * 1; |
| 599 | 599 | } |
| 600 | 600 | |
@@ -610,7 +610,7 @@ discard block |
||
| 610 | 610 | */ |
| 611 | 611 | protected function validate_regex($value) : ?string |
| 612 | 612 | { |
| 613 | - if(!is_scalar($value)) { |
|
| 613 | + if (!is_scalar($value)) { |
|
| 614 | 614 | return null; |
| 615 | 615 | } |
| 616 | 616 | |
@@ -618,13 +618,13 @@ discard block |
||
| 618 | 618 | // is a boolan, which is converted to an integer when |
| 619 | 619 | // converted to string, which in turn can be validated |
| 620 | 620 | // with a regex. |
| 621 | - if(is_bool($value)) { |
|
| 621 | + if (is_bool($value)) { |
|
| 622 | 622 | return null; |
| 623 | 623 | } |
| 624 | 624 | |
| 625 | 625 | $value = (string)$value; |
| 626 | 626 | |
| 627 | - if(preg_match($this->validationParams['regex'], $value)) { |
|
| 627 | + if (preg_match($this->validationParams['regex'], $value)) { |
|
| 628 | 628 | return $value; |
| 629 | 629 | } |
| 630 | 630 | |
@@ -640,11 +640,11 @@ discard block |
||
| 640 | 640 | */ |
| 641 | 641 | protected function validate_alpha($value) |
| 642 | 642 | { |
| 643 | - if(!is_scalar($value)) { |
|
| 643 | + if (!is_scalar($value)) { |
|
| 644 | 644 | return null; |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - if(preg_match('/\A[a-zA-Z]+\z/', $value)) { |
|
| 647 | + if (preg_match('/\A[a-zA-Z]+\z/', $value)) { |
|
| 648 | 648 | return $value; |
| 649 | 649 | } |
| 650 | 650 | |
@@ -653,13 +653,13 @@ discard block |
||
| 653 | 653 | |
| 654 | 654 | protected function validate_valueslist($value) |
| 655 | 655 | { |
| 656 | - if(!is_array($value)) { |
|
| 656 | + if (!is_array($value)) { |
|
| 657 | 657 | return array(); |
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | $keep = array(); |
| 661 | - foreach($value as $item) { |
|
| 662 | - if(in_array($item, $this->validationParams)) { |
|
| 661 | + foreach ($value as $item) { |
|
| 662 | + if (in_array($item, $this->validationParams)) { |
|
| 663 | 663 | $keep[] = $item; |
| 664 | 664 | } |
| 665 | 665 | } |
@@ -716,26 +716,26 @@ discard block |
||
| 716 | 716 | */ |
| 717 | 717 | protected function validate_json($value) |
| 718 | 718 | { |
| 719 | - if(!is_string($value)) { |
|
| 719 | + if (!is_string($value)) { |
|
| 720 | 720 | return ''; |
| 721 | 721 | } |
| 722 | 722 | |
| 723 | 723 | $value = trim($value); |
| 724 | 724 | |
| 725 | - if(empty($value)) { |
|
| 725 | + if (empty($value)) { |
|
| 726 | 726 | return ''; |
| 727 | 727 | } |
| 728 | 728 | |
| 729 | 729 | // strictly validate for objects? |
| 730 | - if($this->validationParams['arrays'] === false) |
|
| 730 | + if ($this->validationParams['arrays'] === false) |
|
| 731 | 731 | { |
| 732 | - if(is_object(json_decode($value))) { |
|
| 732 | + if (is_object(json_decode($value))) { |
|
| 733 | 733 | return $value; |
| 734 | 734 | } |
| 735 | 735 | } |
| 736 | 736 | else |
| 737 | 737 | { |
| 738 | - if(is_array(json_decode($value, true))) { |
|
| 738 | + if (is_array(json_decode($value, true))) { |
|
| 739 | 739 | return $value; |
| 740 | 740 | } |
| 741 | 741 | } |
@@ -756,7 +756,7 @@ discard block |
||
| 756 | 756 | { |
| 757 | 757 | $total = count($this->filters); |
| 758 | 758 | for ($i = 0; $i < $total; $i++) { |
| 759 | - $method = 'applyFilter_' . $this->filters[$i]['type']; |
|
| 759 | + $method = 'applyFilter_'.$this->filters[$i]['type']; |
|
| 760 | 760 | $value = $this->$method($value, $this->filters[$i]['params']); |
| 761 | 761 | } |
| 762 | 762 | |
@@ -903,7 +903,7 @@ discard block |
||
| 903 | 903 | * @param bool $stripEmptyEntries Remove empty entries from the array? |
| 904 | 904 | * @return \AppUtils\Request_Param |
| 905 | 905 | */ |
| 906 | - public function addCommaSeparatedFilter(bool $trimEntries=true, bool $stripEmptyEntries=true) : Request_Param |
|
| 906 | + public function addCommaSeparatedFilter(bool $trimEntries = true, bool $stripEmptyEntries = true) : Request_Param |
|
| 907 | 907 | { |
| 908 | 908 | $this->setArray(); |
| 909 | 909 | |
@@ -50,20 +50,20 @@ discard block |
||
| 50 | 50 | |
| 51 | 51 | } |
| 52 | 52 | |
| 53 | - /** |
|
| 54 | - * Creates and returns a new instance of the CSV builder which |
|
| 55 | - * can be used to build CSV from scratch. |
|
| 56 | - * |
|
| 57 | - * @return CSVHelper_Builder |
|
| 58 | - */ |
|
| 53 | + /** |
|
| 54 | + * Creates and returns a new instance of the CSV builder which |
|
| 55 | + * can be used to build CSV from scratch. |
|
| 56 | + * |
|
| 57 | + * @return CSVHelper_Builder |
|
| 58 | + */ |
|
| 59 | 59 | public static function createBuilder() |
| 60 | 60 | { |
| 61 | 61 | return new CSVHelper_Builder(); |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - /** |
|
| 65 | - * @var string |
|
| 66 | - */ |
|
| 64 | + /** |
|
| 65 | + * @var string |
|
| 66 | + */ |
|
| 67 | 67 | protected $csv = ''; |
| 68 | 68 | |
| 69 | 69 | protected $data = array(); |
@@ -72,16 +72,16 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | protected $headersPosition = self::HEADERS_NONE; |
| 74 | 74 | |
| 75 | - /** |
|
| 76 | - * Loads CSV data from a string. |
|
| 77 | - * |
|
| 78 | - * Note: Use the {@link hasErrors()} method to |
|
| 79 | - * check if the string could be parsed correctly |
|
| 80 | - * afterwards. |
|
| 81 | - * |
|
| 82 | - * @param string $string |
|
| 83 | - * @return CSVHelper |
|
| 84 | - */ |
|
| 75 | + /** |
|
| 76 | + * Loads CSV data from a string. |
|
| 77 | + * |
|
| 78 | + * Note: Use the {@link hasErrors()} method to |
|
| 79 | + * check if the string could be parsed correctly |
|
| 80 | + * afterwards. |
|
| 81 | + * |
|
| 82 | + * @param string $string |
|
| 83 | + * @return CSVHelper |
|
| 84 | + */ |
|
| 85 | 85 | public function loadString($string) |
| 86 | 86 | { |
| 87 | 87 | // remove any UTF byte order marks that may still be present in the string |
@@ -95,20 +95,20 @@ discard block |
||
| 95 | 95 | return $this; |
| 96 | 96 | } |
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Loads CSV data from a file. |
|
| 100 | - * |
|
| 101 | - * Note: Use the {@link hasErrors()} method to |
|
| 102 | - * check if the string could be parsed correctly |
|
| 103 | - * afterwards. |
|
| 104 | - * |
|
| 105 | - * @param string $file |
|
| 106 | - * @throws FileHelper_Exception |
|
| 107 | - * @return CSVHelper |
|
| 108 | - * |
|
| 109 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 110 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 111 | - */ |
|
| 98 | + /** |
|
| 99 | + * Loads CSV data from a file. |
|
| 100 | + * |
|
| 101 | + * Note: Use the {@link hasErrors()} method to |
|
| 102 | + * check if the string could be parsed correctly |
|
| 103 | + * afterwards. |
|
| 104 | + * |
|
| 105 | + * @param string $file |
|
| 106 | + * @throws FileHelper_Exception |
|
| 107 | + * @return CSVHelper |
|
| 108 | + * |
|
| 109 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 110 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 111 | + */ |
|
| 112 | 112 | public function loadFile(string $file) : CSVHelper |
| 113 | 113 | { |
| 114 | 114 | $csv = FileHelper::readContents($file); |
@@ -122,28 +122,28 @@ discard block |
||
| 122 | 122 | |
| 123 | 123 | protected $rowCount = 0; |
| 124 | 124 | |
| 125 | - /** |
|
| 126 | - * Specifies that headers are positioned on top, horizontally. |
|
| 127 | - * @return CSVHelper |
|
| 128 | - */ |
|
| 125 | + /** |
|
| 126 | + * Specifies that headers are positioned on top, horizontally. |
|
| 127 | + * @return CSVHelper |
|
| 128 | + */ |
|
| 129 | 129 | public function setHeadersTop() |
| 130 | 130 | { |
| 131 | 131 | return $this->setHeadersPosition(self::HEADERS_TOP); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Specifies that headers are positioned on the left, vertically. |
|
| 136 | - * @return CSVHelper |
|
| 137 | - */ |
|
| 134 | + /** |
|
| 135 | + * Specifies that headers are positioned on the left, vertically. |
|
| 136 | + * @return CSVHelper |
|
| 137 | + */ |
|
| 138 | 138 | public function setHeadersLeft() |
| 139 | 139 | { |
| 140 | 140 | return $this->setHeadersPosition(self::HEADERS_LEFT); |
| 141 | 141 | } |
| 142 | 142 | |
| 143 | - /** |
|
| 144 | - * Specifies that there are no headers in the file (default). |
|
| 145 | - * @return CSVHelper |
|
| 146 | - */ |
|
| 143 | + /** |
|
| 144 | + * Specifies that there are no headers in the file (default). |
|
| 145 | + * @return CSVHelper |
|
| 146 | + */ |
|
| 147 | 147 | public function setHeadersNone() |
| 148 | 148 | { |
| 149 | 149 | return $this->setHeadersPosition(self::HEADERS_NONE); |
@@ -173,18 +173,18 @@ discard block |
||
| 173 | 173 | return false; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Specifies where the headers are positioned in the |
|
| 178 | - * CSV, or turns them off entirely. Use the class constants |
|
| 179 | - * to ensure the value is correct. |
|
| 180 | - * |
|
| 181 | - * @param string $position |
|
| 182 | - * @throws CSVHelper_Exception |
|
| 183 | - * @return CSVHelper |
|
| 184 | - * @see CSVHelper::HEADERS_LEFT |
|
| 185 | - * @see CSVHelper::HEADERS_TOP |
|
| 186 | - * @see CSVHelper::HEADERS_NONE |
|
| 187 | - */ |
|
| 176 | + /** |
|
| 177 | + * Specifies where the headers are positioned in the |
|
| 178 | + * CSV, or turns them off entirely. Use the class constants |
|
| 179 | + * to ensure the value is correct. |
|
| 180 | + * |
|
| 181 | + * @param string $position |
|
| 182 | + * @throws CSVHelper_Exception |
|
| 183 | + * @return CSVHelper |
|
| 184 | + * @see CSVHelper::HEADERS_LEFT |
|
| 185 | + * @see CSVHelper::HEADERS_TOP |
|
| 186 | + * @see CSVHelper::HEADERS_NONE |
|
| 187 | + */ |
|
| 188 | 188 | public function setHeadersPosition($position) |
| 189 | 189 | { |
| 190 | 190 | $validPositions = array( |
@@ -211,13 +211,13 @@ discard block |
||
| 211 | 211 | return $this; |
| 212 | 212 | } |
| 213 | 213 | |
| 214 | - /** |
|
| 215 | - * Resets all internal data, allowing to start entirely anew |
|
| 216 | - * with a new file, or to start building a new CSV file from |
|
| 217 | - * scratch. |
|
| 218 | - * |
|
| 219 | - * @return CSVHelper |
|
| 220 | - */ |
|
| 214 | + /** |
|
| 215 | + * Resets all internal data, allowing to start entirely anew |
|
| 216 | + * with a new file, or to start building a new CSV file from |
|
| 217 | + * scratch. |
|
| 218 | + * |
|
| 219 | + * @return CSVHelper |
|
| 220 | + */ |
|
| 221 | 221 | public function reset() |
| 222 | 222 | { |
| 223 | 223 | $this->data = array(); |
@@ -234,19 +234,19 @@ discard block |
||
| 234 | 234 | return $this->data; |
| 235 | 235 | } |
| 236 | 236 | |
| 237 | - /** |
|
| 238 | - * Retrieves the row at the specified index. |
|
| 239 | - * If there is no data at the index, this will |
|
| 240 | - * return an array populated with empty strings |
|
| 241 | - * for all available columns. |
|
| 242 | - * |
|
| 243 | - * Tip: Use the {@link rowExists()} method to check |
|
| 244 | - * whether the specified row exists. |
|
| 245 | - * |
|
| 246 | - * @param integer $index |
|
| 247 | - * @return array() |
|
| 248 | - * @see rowExists() |
|
| 249 | - */ |
|
| 237 | + /** |
|
| 238 | + * Retrieves the row at the specified index. |
|
| 239 | + * If there is no data at the index, this will |
|
| 240 | + * return an array populated with empty strings |
|
| 241 | + * for all available columns. |
|
| 242 | + * |
|
| 243 | + * Tip: Use the {@link rowExists()} method to check |
|
| 244 | + * whether the specified row exists. |
|
| 245 | + * |
|
| 246 | + * @param integer $index |
|
| 247 | + * @return array() |
|
| 248 | + * @see rowExists() |
|
| 249 | + */ |
|
| 250 | 250 | public function getRow($index) |
| 251 | 251 | { |
| 252 | 252 | if(isset($this->data[$index])) { |
@@ -256,63 +256,63 @@ discard block |
||
| 256 | 256 | return array_fill(0, $this->rowCount, ''); |
| 257 | 257 | } |
| 258 | 258 | |
| 259 | - /** |
|
| 260 | - * Checks whether the specified row exists in the data set. |
|
| 261 | - * @param integer $index |
|
| 262 | - * @return boolean |
|
| 263 | - */ |
|
| 259 | + /** |
|
| 260 | + * Checks whether the specified row exists in the data set. |
|
| 261 | + * @param integer $index |
|
| 262 | + * @return boolean |
|
| 263 | + */ |
|
| 264 | 264 | public function rowExists($index) |
| 265 | 265 | { |
| 266 | 266 | return isset($this->data[$index]); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Counts the amount of rows in the parsed CSV, |
|
| 271 | - * excluding the headers if any, depending on |
|
| 272 | - * their position. |
|
| 273 | - * |
|
| 274 | - * @return integer |
|
| 275 | - */ |
|
| 269 | + /** |
|
| 270 | + * Counts the amount of rows in the parsed CSV, |
|
| 271 | + * excluding the headers if any, depending on |
|
| 272 | + * their position. |
|
| 273 | + * |
|
| 274 | + * @return integer |
|
| 275 | + */ |
|
| 276 | 276 | public function countRows() |
| 277 | 277 | { |
| 278 | 278 | return $this->rowCount; |
| 279 | 279 | } |
| 280 | 280 | |
| 281 | - /** |
|
| 282 | - * Counts the amount of rows in the parsed CSV, |
|
| 283 | - * excluding the headers if any, depending on |
|
| 284 | - * their position. |
|
| 285 | - * |
|
| 286 | - * @return integer |
|
| 287 | - */ |
|
| 281 | + /** |
|
| 282 | + * Counts the amount of rows in the parsed CSV, |
|
| 283 | + * excluding the headers if any, depending on |
|
| 284 | + * their position. |
|
| 285 | + * |
|
| 286 | + * @return integer |
|
| 287 | + */ |
|
| 288 | 288 | public function countColumns() |
| 289 | 289 | { |
| 290 | 290 | return $this->columnCount; |
| 291 | 291 | } |
| 292 | 292 | |
| 293 | - /** |
|
| 294 | - * Retrieves the headers, if any. Specify the position of the |
|
| 295 | - * headers first to ensure this works correctly. |
|
| 296 | - * |
|
| 297 | - * @return array Indexed array with header names. |
|
| 298 | - */ |
|
| 293 | + /** |
|
| 294 | + * Retrieves the headers, if any. Specify the position of the |
|
| 295 | + * headers first to ensure this works correctly. |
|
| 296 | + * |
|
| 297 | + * @return array Indexed array with header names. |
|
| 298 | + */ |
|
| 299 | 299 | public function getHeaders() |
| 300 | 300 | { |
| 301 | 301 | return $this->headers; |
| 302 | 302 | } |
| 303 | 303 | |
| 304 | - /** |
|
| 305 | - * Retrieves the column at the specified index. If there |
|
| 306 | - * is no column at the index, this returns an array |
|
| 307 | - * populated with empty strings. |
|
| 308 | - * |
|
| 309 | - * Tip: Use the {@link columnExists()} method to check |
|
| 310 | - * whether a column exists. |
|
| 311 | - * |
|
| 312 | - * @param integer $index |
|
| 313 | - * @return string[] |
|
| 314 | - * @see columnExists() |
|
| 315 | - */ |
|
| 304 | + /** |
|
| 305 | + * Retrieves the column at the specified index. If there |
|
| 306 | + * is no column at the index, this returns an array |
|
| 307 | + * populated with empty strings. |
|
| 308 | + * |
|
| 309 | + * Tip: Use the {@link columnExists()} method to check |
|
| 310 | + * whether a column exists. |
|
| 311 | + * |
|
| 312 | + * @param integer $index |
|
| 313 | + * @return string[] |
|
| 314 | + * @see columnExists() |
|
| 315 | + */ |
|
| 316 | 316 | public function getColumn($index) |
| 317 | 317 | { |
| 318 | 318 | $data = array(); |
@@ -328,11 +328,11 @@ discard block |
||
| 328 | 328 | return $data; |
| 329 | 329 | } |
| 330 | 330 | |
| 331 | - /** |
|
| 332 | - * Checks whether the specified column exists in the data set. |
|
| 333 | - * @param integer $index |
|
| 334 | - * @return boolean |
|
| 335 | - */ |
|
| 331 | + /** |
|
| 332 | + * Checks whether the specified column exists in the data set. |
|
| 333 | + * @param integer $index |
|
| 334 | + * @return boolean |
|
| 335 | + */ |
|
| 336 | 336 | public function columnExists($index) |
| 337 | 337 | { |
| 338 | 338 | if($index < $this->columnCount) { |
@@ -396,22 +396,22 @@ discard block |
||
| 396 | 396 | } |
| 397 | 397 | } |
| 398 | 398 | |
| 399 | - /** |
|
| 400 | - * Checks whether any errors have been encountered |
|
| 401 | - * while parsing the CSV. |
|
| 402 | - * |
|
| 403 | - * @return boolean |
|
| 404 | - * @see getErrorMessages() |
|
| 405 | - */ |
|
| 399 | + /** |
|
| 400 | + * Checks whether any errors have been encountered |
|
| 401 | + * while parsing the CSV. |
|
| 402 | + * |
|
| 403 | + * @return boolean |
|
| 404 | + * @see getErrorMessages() |
|
| 405 | + */ |
|
| 406 | 406 | public function hasErrors() |
| 407 | 407 | { |
| 408 | 408 | return !empty($this->errors); |
| 409 | 409 | } |
| 410 | 410 | |
| 411 | - /** |
|
| 412 | - * Retrieves all error messages. |
|
| 413 | - * @return array |
|
| 414 | - */ |
|
| 411 | + /** |
|
| 412 | + * Retrieves all error messages. |
|
| 413 | + * @return array |
|
| 414 | + */ |
|
| 415 | 415 | public function getErrorMessages() |
| 416 | 416 | { |
| 417 | 417 | return $this->errors; |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | |
| 167 | 167 | public function isHeadersPosition($position) |
| 168 | 168 | { |
| 169 | - if($this->headersPosition === $position) { |
|
| 169 | + if ($this->headersPosition === $position) { |
|
| 170 | 170 | return true; |
| 171 | 171 | } |
| 172 | 172 | |
@@ -193,7 +193,7 @@ discard block |
||
| 193 | 193 | self::HEADERS_TOP |
| 194 | 194 | ); |
| 195 | 195 | |
| 196 | - if(!in_array($position, $validPositions)) { |
|
| 196 | + if (!in_array($position, $validPositions)) { |
|
| 197 | 197 | throw new CSVHelper_Exception( |
| 198 | 198 | 'Invalid headers position', |
| 199 | 199 | sprintf( |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | public function getRow($index) |
| 251 | 251 | { |
| 252 | - if(isset($this->data[$index])) { |
|
| 252 | + if (isset($this->data[$index])) { |
|
| 253 | 253 | return $this->data[$index]; |
| 254 | 254 | } |
| 255 | 255 | |
@@ -316,9 +316,9 @@ discard block |
||
| 316 | 316 | public function getColumn($index) |
| 317 | 317 | { |
| 318 | 318 | $data = array(); |
| 319 | - for($i=0; $i < $this->rowCount; $i++) { |
|
| 319 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
| 320 | 320 | $value = ''; |
| 321 | - if(isset($this->data[$i][$index])) { |
|
| 321 | + if (isset($this->data[$i][$index])) { |
|
| 322 | 322 | $value = $this->data[$i][$index]; |
| 323 | 323 | } |
| 324 | 324 | |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | public function columnExists($index) |
| 337 | 337 | { |
| 338 | - if($index < $this->columnCount) { |
|
| 338 | + if ($index < $this->columnCount) { |
|
| 339 | 339 | return true; |
| 340 | 340 | } |
| 341 | 341 | |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | { |
| 347 | 347 | $this->reset(); |
| 348 | 348 | |
| 349 | - if(empty(trim($this->csv))) { |
|
| 349 | + if (empty(trim($this->csv))) { |
|
| 350 | 350 | $this->addError('Tried to parse an empty CSV string.'); |
| 351 | 351 | return; |
| 352 | 352 | } |
@@ -361,12 +361,12 @@ discard block |
||
| 361 | 361 | $parser->delimiter = $this->detectSeparator(); |
| 362 | 362 | |
| 363 | 363 | $result = $parser->parse_string(/** @scrutinizer ignore-type */ $this->csv); |
| 364 | - if(!$result) { |
|
| 364 | + if (!$result) { |
|
| 365 | 365 | $this->addError('The CSV string could not be parsed.'); |
| 366 | 366 | return; |
| 367 | 367 | } |
| 368 | 368 | |
| 369 | - switch($this->headersPosition) |
|
| 369 | + switch ($this->headersPosition) |
|
| 370 | 370 | { |
| 371 | 371 | case self::HEADERS_TOP: |
| 372 | 372 | $this->headers = array_shift($result); |
@@ -375,7 +375,7 @@ discard block |
||
| 375 | 375 | case self::HEADERS_LEFT: |
| 376 | 376 | $keep = array(); |
| 377 | 377 | $total = count($result); |
| 378 | - for($i=0; $i < $total; $i++) { |
|
| 378 | + for ($i = 0; $i < $total; $i++) { |
|
| 379 | 379 | $row = $result[$i]; |
| 380 | 380 | $this->headers[] = array_shift($row); |
| 381 | 381 | $keep[] = $row; |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | $this->data = $result; |
| 389 | 389 | $this->rowCount = count($this->data); |
| 390 | 390 | |
| 391 | - for($i=0; $i < $this->rowCount; $i++) { |
|
| 391 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
| 392 | 392 | $amount = count($this->data[$i]); |
| 393 | - if($amount > $this->columnCount) { |
|
| 393 | + if ($amount > $this->columnCount) { |
|
| 394 | 394 | $this->columnCount = $amount; |
| 395 | 395 | } |
| 396 | 396 | } |
@@ -434,8 +434,8 @@ discard block |
||
| 434 | 434 | ',,' => ',' |
| 435 | 435 | ); |
| 436 | 436 | |
| 437 | - foreach($search as $char => $separator) { |
|
| 438 | - if(strstr($this->csv, $char)) { |
|
| 437 | + foreach ($search as $char => $separator) { |
|
| 438 | + if (strstr($this->csv, $char)) { |
|
| 439 | 439 | return $separator; |
| 440 | 440 | } |
| 441 | 441 | } |
@@ -435,16 +435,16 @@ discard block |
||
| 435 | 435 | return $bytes . ' ' . t('B'); |
| 436 | 436 | } |
| 437 | 437 | |
| 438 | - /** |
|
| 439 | - * Cuts a text to the specified length if it is longer than the |
|
| 440 | - * target length. Appends a text to signify it has been cut at |
|
| 441 | - * the end of the string. |
|
| 442 | - * |
|
| 443 | - * @param string $text |
|
| 444 | - * @param int $targetLength |
|
| 445 | - * @param string $append |
|
| 446 | - * @return string |
|
| 447 | - */ |
|
| 438 | + /** |
|
| 439 | + * Cuts a text to the specified length if it is longer than the |
|
| 440 | + * target length. Appends a text to signify it has been cut at |
|
| 441 | + * the end of the string. |
|
| 442 | + * |
|
| 443 | + * @param string $text |
|
| 444 | + * @param int $targetLength |
|
| 445 | + * @param string $append |
|
| 446 | + * @return string |
|
| 447 | + */ |
|
| 448 | 448 | public static function text_cut(string $text, int $targetLength, string $append = '...') : string |
| 449 | 449 | { |
| 450 | 450 | $length = mb_strlen($text); |
@@ -514,27 +514,27 @@ discard block |
||
| 514 | 514 | return self::$booleanStrings[$string]; |
| 515 | 515 | } |
| 516 | 516 | |
| 517 | - /** |
|
| 518 | - * Whether the specified string is a boolean string or boolean value. |
|
| 519 | - * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 520 | - * |
|
| 521 | - * @param mixed $string |
|
| 522 | - * @return bool |
|
| 523 | - * @deprecated |
|
| 524 | - * @see ConvertHelper::isBoolean() |
|
| 525 | - */ |
|
| 517 | + /** |
|
| 518 | + * Whether the specified string is a boolean string or boolean value. |
|
| 519 | + * Alias for {@link ConvertHelper::isBoolean()}. |
|
| 520 | + * |
|
| 521 | + * @param mixed $string |
|
| 522 | + * @return bool |
|
| 523 | + * @deprecated |
|
| 524 | + * @see ConvertHelper::isBoolean() |
|
| 525 | + */ |
|
| 526 | 526 | public static function isBooleanString($string) : bool |
| 527 | 527 | { |
| 528 | 528 | return self::isBoolean($string); |
| 529 | 529 | } |
| 530 | 530 | |
| 531 | - /** |
|
| 532 | - * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 533 | - * |
|
| 534 | - * @param string $text |
|
| 535 | - * @return string |
|
| 536 | - * @deprecated |
|
| 537 | - */ |
|
| 531 | + /** |
|
| 532 | + * Alias for the {@\AppUtils\XMLHelper::string2xml()} method. |
|
| 533 | + * |
|
| 534 | + * @param string $text |
|
| 535 | + * @return string |
|
| 536 | + * @deprecated |
|
| 537 | + */ |
|
| 538 | 538 | public static function text_makeXMLCompliant($text) |
| 539 | 539 | { |
| 540 | 540 | return XMLHelper::string2xml($text); |
@@ -636,13 +636,13 @@ discard block |
||
| 636 | 636 | return $translit->convert($string); |
| 637 | 637 | } |
| 638 | 638 | |
| 639 | - /** |
|
| 640 | - * Retrieves the HEX character codes for all control |
|
| 641 | - * characters that the {@link stripControlCharacters()} |
|
| 642 | - * method will remove. |
|
| 643 | - * |
|
| 644 | - * @return string[] |
|
| 645 | - */ |
|
| 639 | + /** |
|
| 640 | + * Retrieves the HEX character codes for all control |
|
| 641 | + * characters that the {@link stripControlCharacters()} |
|
| 642 | + * method will remove. |
|
| 643 | + * |
|
| 644 | + * @return string[] |
|
| 645 | + */ |
|
| 646 | 646 | public static function getControlCharactersAsHex() |
| 647 | 647 | { |
| 648 | 648 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
@@ -678,13 +678,13 @@ discard block |
||
| 678 | 678 | return $stack; |
| 679 | 679 | } |
| 680 | 680 | |
| 681 | - /** |
|
| 682 | - * Retrieves an array of all control characters that |
|
| 683 | - * the {@link stripControlCharacters()} method will |
|
| 684 | - * remove, as the actual UTF-8 characters. |
|
| 685 | - * |
|
| 686 | - * @return string[] |
|
| 687 | - */ |
|
| 681 | + /** |
|
| 682 | + * Retrieves an array of all control characters that |
|
| 683 | + * the {@link stripControlCharacters()} method will |
|
| 684 | + * remove, as the actual UTF-8 characters. |
|
| 685 | + * |
|
| 686 | + * @return string[] |
|
| 687 | + */ |
|
| 688 | 688 | public static function getControlCharactersAsUTF8() |
| 689 | 689 | { |
| 690 | 690 | $chars = self::getControlCharactersAsHex(); |
@@ -697,12 +697,12 @@ discard block |
||
| 697 | 697 | return $result; |
| 698 | 698 | } |
| 699 | 699 | |
| 700 | - /** |
|
| 701 | - * Retrieves all control characters as JSON encoded |
|
| 702 | - * characters, e.g. "\u200b". |
|
| 703 | - * |
|
| 704 | - * @return string[] |
|
| 705 | - */ |
|
| 700 | + /** |
|
| 701 | + * Retrieves all control characters as JSON encoded |
|
| 702 | + * characters, e.g. "\u200b". |
|
| 703 | + * |
|
| 704 | + * @return string[] |
|
| 705 | + */ |
|
| 706 | 706 | public static function getControlCharactersAsJSON() |
| 707 | 707 | { |
| 708 | 708 | $chars = self::getControlCharactersAsHex(); |
@@ -759,20 +759,20 @@ discard block |
||
| 759 | 759 | return preg_replace(self::$controlCharsRegex, '', $string); |
| 760 | 760 | } |
| 761 | 761 | |
| 762 | - /** |
|
| 763 | - * Converts a unicode character to the PHPO notation. |
|
| 764 | - * |
|
| 765 | - * Example: |
|
| 766 | - * |
|
| 767 | - * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 768 | - * |
|
| 769 | - * Returns |
|
| 770 | - * |
|
| 771 | - * <pre>\x0</pre> |
|
| 772 | - * |
|
| 773 | - * @param string $unicodeChar |
|
| 774 | - * @return string |
|
| 775 | - */ |
|
| 762 | + /** |
|
| 763 | + * Converts a unicode character to the PHPO notation. |
|
| 764 | + * |
|
| 765 | + * Example: |
|
| 766 | + * |
|
| 767 | + * <pre>unicodeChar2php('"\u0000"')</pre> |
|
| 768 | + * |
|
| 769 | + * Returns |
|
| 770 | + * |
|
| 771 | + * <pre>\x0</pre> |
|
| 772 | + * |
|
| 773 | + * @param string $unicodeChar |
|
| 774 | + * @return string |
|
| 775 | + */ |
|
| 776 | 776 | public static function unicodeChar2php($unicodeChar) |
| 777 | 777 | { |
| 778 | 778 | $unicodeChar = json_decode($unicodeChar); |
@@ -895,25 +895,25 @@ discard block |
||
| 895 | 895 | return 'false'; |
| 896 | 896 | } |
| 897 | 897 | |
| 898 | - /** |
|
| 899 | - * Converts an associative array with attribute name > value pairs |
|
| 900 | - * to an attribute string that can be used in an HTML tag. Empty |
|
| 901 | - * attribute values are ignored. |
|
| 902 | - * |
|
| 903 | - * Example: |
|
| 904 | - * |
|
| 905 | - * array2attributeString(array( |
|
| 906 | - * 'id' => 45, |
|
| 907 | - * 'href' => 'http://www.mistralys.com' |
|
| 908 | - * )); |
|
| 909 | - * |
|
| 910 | - * Result: |
|
| 911 | - * |
|
| 912 | - * id="45" href="http://www.mistralys.com" |
|
| 913 | - * |
|
| 914 | - * @param array $array |
|
| 915 | - * @return string |
|
| 916 | - */ |
|
| 898 | + /** |
|
| 899 | + * Converts an associative array with attribute name > value pairs |
|
| 900 | + * to an attribute string that can be used in an HTML tag. Empty |
|
| 901 | + * attribute values are ignored. |
|
| 902 | + * |
|
| 903 | + * Example: |
|
| 904 | + * |
|
| 905 | + * array2attributeString(array( |
|
| 906 | + * 'id' => 45, |
|
| 907 | + * 'href' => 'http://www.mistralys.com' |
|
| 908 | + * )); |
|
| 909 | + * |
|
| 910 | + * Result: |
|
| 911 | + * |
|
| 912 | + * id="45" href="http://www.mistralys.com" |
|
| 913 | + * |
|
| 914 | + * @param array $array |
|
| 915 | + * @return string |
|
| 916 | + */ |
|
| 917 | 917 | public static function array2attributeString($array) |
| 918 | 918 | { |
| 919 | 919 | $tokens = array(); |
@@ -932,14 +932,14 @@ discard block |
||
| 932 | 932 | return ' '.implode(' ', $tokens); |
| 933 | 933 | } |
| 934 | 934 | |
| 935 | - /** |
|
| 936 | - * Converts a string so it can safely be used in a javascript |
|
| 937 | - * statement in an HTML tag: uses single quotes around the string |
|
| 938 | - * and encodes all special characters as needed. |
|
| 939 | - * |
|
| 940 | - * @param string $string |
|
| 941 | - * @return string |
|
| 942 | - */ |
|
| 935 | + /** |
|
| 936 | + * Converts a string so it can safely be used in a javascript |
|
| 937 | + * statement in an HTML tag: uses single quotes around the string |
|
| 938 | + * and encodes all special characters as needed. |
|
| 939 | + * |
|
| 940 | + * @param string $string |
|
| 941 | + * @return string |
|
| 942 | + */ |
|
| 943 | 943 | public static function string2attributeJS($string, $quoted=true) |
| 944 | 944 | { |
| 945 | 945 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
@@ -950,15 +950,15 @@ discard block |
||
| 950 | 950 | return $converted; |
| 951 | 951 | } |
| 952 | 952 | |
| 953 | - /** |
|
| 954 | - * Checks if the specified string is a boolean value, which |
|
| 955 | - * includes string representations of boolean values, like |
|
| 956 | - * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 957 | - * or <code>false</code>. |
|
| 958 | - * |
|
| 959 | - * @param mixed $value |
|
| 960 | - * @return boolean |
|
| 961 | - */ |
|
| 953 | + /** |
|
| 954 | + * Checks if the specified string is a boolean value, which |
|
| 955 | + * includes string representations of boolean values, like |
|
| 956 | + * <code>yes</code> or <code>no</code>, and <code>true</code> |
|
| 957 | + * or <code>false</code>. |
|
| 958 | + * |
|
| 959 | + * @param mixed $value |
|
| 960 | + * @return boolean |
|
| 961 | + */ |
|
| 962 | 962 | public static function isBoolean($value) : bool |
| 963 | 963 | { |
| 964 | 964 | if(is_bool($value)) { |
@@ -972,12 +972,12 @@ discard block |
||
| 972 | 972 | return array_key_exists($value, self::$booleanStrings); |
| 973 | 973 | } |
| 974 | 974 | |
| 975 | - /** |
|
| 976 | - * Converts an associative array to an HTML style attribute value string. |
|
| 977 | - * |
|
| 978 | - * @param array $subject |
|
| 979 | - * @return string |
|
| 980 | - */ |
|
| 975 | + /** |
|
| 976 | + * Converts an associative array to an HTML style attribute value string. |
|
| 977 | + * |
|
| 978 | + * @param array $subject |
|
| 979 | + * @return string |
|
| 980 | + */ |
|
| 981 | 981 | public static function array2styleString(array $subject) : string |
| 982 | 982 | { |
| 983 | 983 | $tokens = array(); |
@@ -988,23 +988,23 @@ discard block |
||
| 988 | 988 | return implode(';', $tokens); |
| 989 | 989 | } |
| 990 | 990 | |
| 991 | - /** |
|
| 992 | - * Converts a DateTime object to a timestamp, which |
|
| 993 | - * is PHP 5.2 compatible. |
|
| 994 | - * |
|
| 995 | - * @param \DateTime $date |
|
| 996 | - * @return integer |
|
| 997 | - */ |
|
| 991 | + /** |
|
| 992 | + * Converts a DateTime object to a timestamp, which |
|
| 993 | + * is PHP 5.2 compatible. |
|
| 994 | + * |
|
| 995 | + * @param \DateTime $date |
|
| 996 | + * @return integer |
|
| 997 | + */ |
|
| 998 | 998 | public static function date2timestamp(\DateTime $date) : int |
| 999 | 999 | { |
| 1000 | 1000 | return (int)$date->format('U'); |
| 1001 | 1001 | } |
| 1002 | 1002 | |
| 1003 | - /** |
|
| 1004 | - * Converts a timestamp into a DateTime instance. |
|
| 1005 | - * @param int $timestamp |
|
| 1006 | - * @return \DateTime |
|
| 1007 | - */ |
|
| 1003 | + /** |
|
| 1004 | + * Converts a timestamp into a DateTime instance. |
|
| 1005 | + * @param int $timestamp |
|
| 1006 | + * @return \DateTime |
|
| 1007 | + */ |
|
| 1008 | 1008 | public static function timestamp2date(int $timestamp) : \DateTime |
| 1009 | 1009 | { |
| 1010 | 1010 | $date = new \DateTime(); |
@@ -1012,13 +1012,13 @@ discard block |
||
| 1012 | 1012 | return $date; |
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | - /** |
|
| 1016 | - * Strips an absolute path to a file within the application |
|
| 1017 | - * to make the path relative to the application root path. |
|
| 1018 | - * |
|
| 1019 | - * @param string $path |
|
| 1020 | - * @return string |
|
| 1021 | - */ |
|
| 1015 | + /** |
|
| 1016 | + * Strips an absolute path to a file within the application |
|
| 1017 | + * to make the path relative to the application root path. |
|
| 1018 | + * |
|
| 1019 | + * @param string $path |
|
| 1020 | + * @return string |
|
| 1021 | + */ |
|
| 1022 | 1022 | public static function fileRelativize($path) |
| 1023 | 1023 | { |
| 1024 | 1024 | $path = str_replace('\\', '/', $path); |
@@ -1030,22 +1030,22 @@ discard block |
||
| 1030 | 1030 | |
| 1031 | 1031 | const JS_REGEX_JSON = 'json'; |
| 1032 | 1032 | |
| 1033 | - /** |
|
| 1034 | - * Takes a regular expression and attempts to convert it to |
|
| 1035 | - * its javascript equivalent. Returns an array containing the |
|
| 1036 | - * format string itself (without start and end characters), |
|
| 1037 | - * and the modifiers. |
|
| 1038 | - * |
|
| 1039 | - * This is intended to be used with the RegExp object, for ex: |
|
| 1040 | - * |
|
| 1041 | - * <script> |
|
| 1042 | - * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
| 1043 | - * var reg = new RegExp(expression.format, expression.modifiers); |
|
| 1044 | - * </script> |
|
| 1045 | - * |
|
| 1046 | - * @param string $regex |
|
| 1047 | - * @return array |
|
| 1048 | - */ |
|
| 1033 | + /** |
|
| 1034 | + * Takes a regular expression and attempts to convert it to |
|
| 1035 | + * its javascript equivalent. Returns an array containing the |
|
| 1036 | + * format string itself (without start and end characters), |
|
| 1037 | + * and the modifiers. |
|
| 1038 | + * |
|
| 1039 | + * This is intended to be used with the RegExp object, for ex: |
|
| 1040 | + * |
|
| 1041 | + * <script> |
|
| 1042 | + * var expression = <?php echo json_encode(ConvertHelper::regex2js('/ab+c/i')) ?>; |
|
| 1043 | + * var reg = new RegExp(expression.format, expression.modifiers); |
|
| 1044 | + * </script> |
|
| 1045 | + * |
|
| 1046 | + * @param string $regex |
|
| 1047 | + * @return array |
|
| 1048 | + */ |
|
| 1049 | 1049 | public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
| 1050 | 1050 | { |
| 1051 | 1051 | $regex = trim($regex); |
@@ -1091,12 +1091,12 @@ discard block |
||
| 1091 | 1091 | ); |
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | - /** |
|
| 1095 | - * Strips all known UTF byte order marks from the specified string. |
|
| 1096 | - * |
|
| 1097 | - * @param string $string |
|
| 1098 | - * @return string |
|
| 1099 | - */ |
|
| 1094 | + /** |
|
| 1095 | + * Strips all known UTF byte order marks from the specified string. |
|
| 1096 | + * |
|
| 1097 | + * @param string $string |
|
| 1098 | + * @return string |
|
| 1099 | + */ |
|
| 1100 | 1100 | public static function stripUTFBom($string) |
| 1101 | 1101 | { |
| 1102 | 1102 | $boms = FileHelper::getUTFBOMs(); |
@@ -1111,13 +1111,13 @@ discard block |
||
| 1111 | 1111 | return $string; |
| 1112 | 1112 | } |
| 1113 | 1113 | |
| 1114 | - /** |
|
| 1115 | - * Converts a string to valid utf8, regardless |
|
| 1116 | - * of the string's encoding(s). |
|
| 1117 | - * |
|
| 1118 | - * @param string $string |
|
| 1119 | - * @return string |
|
| 1120 | - */ |
|
| 1114 | + /** |
|
| 1115 | + * Converts a string to valid utf8, regardless |
|
| 1116 | + * of the string's encoding(s). |
|
| 1117 | + * |
|
| 1118 | + * @param string $string |
|
| 1119 | + * @return string |
|
| 1120 | + */ |
|
| 1121 | 1121 | public static function string2utf8($string) |
| 1122 | 1122 | { |
| 1123 | 1123 | if(!self::isStringASCII($string)) { |
@@ -1127,15 +1127,15 @@ discard block |
||
| 1127 | 1127 | return $string; |
| 1128 | 1128 | } |
| 1129 | 1129 | |
| 1130 | - /** |
|
| 1131 | - * Checks whether the specified string is an ASCII |
|
| 1132 | - * string, without any special or UTF8 characters. |
|
| 1133 | - * Note: empty strings and NULL are considered ASCII. |
|
| 1134 | - * Any variable types other than strings are not. |
|
| 1135 | - * |
|
| 1136 | - * @param string $string |
|
| 1137 | - * @return boolean |
|
| 1138 | - */ |
|
| 1130 | + /** |
|
| 1131 | + * Checks whether the specified string is an ASCII |
|
| 1132 | + * string, without any special or UTF8 characters. |
|
| 1133 | + * Note: empty strings and NULL are considered ASCII. |
|
| 1134 | + * Any variable types other than strings are not. |
|
| 1135 | + * |
|
| 1136 | + * @param string $string |
|
| 1137 | + * @return boolean |
|
| 1138 | + */ |
|
| 1139 | 1139 | public static function isStringASCII($string) |
| 1140 | 1140 | { |
| 1141 | 1141 | if($string === '' || $string === NULL) { |
@@ -1160,22 +1160,22 @@ discard block |
||
| 1160 | 1160 | return $url; |
| 1161 | 1161 | } |
| 1162 | 1162 | |
| 1163 | - /** |
|
| 1164 | - * Calculates a percentage match of the source string with the target string. |
|
| 1165 | - * |
|
| 1166 | - * Options are: |
|
| 1167 | - * |
|
| 1168 | - * - maxLevenshtein, default: 10 |
|
| 1169 | - * Any levenshtein results above this value are ignored. |
|
| 1170 | - * |
|
| 1171 | - * - precision, default: 1 |
|
| 1172 | - * The precision of the percentage float value |
|
| 1173 | - * |
|
| 1174 | - * @param string $source |
|
| 1175 | - * @param string $target |
|
| 1176 | - * @param array $options |
|
| 1177 | - * @return float |
|
| 1178 | - */ |
|
| 1163 | + /** |
|
| 1164 | + * Calculates a percentage match of the source string with the target string. |
|
| 1165 | + * |
|
| 1166 | + * Options are: |
|
| 1167 | + * |
|
| 1168 | + * - maxLevenshtein, default: 10 |
|
| 1169 | + * Any levenshtein results above this value are ignored. |
|
| 1170 | + * |
|
| 1171 | + * - precision, default: 1 |
|
| 1172 | + * The precision of the percentage float value |
|
| 1173 | + * |
|
| 1174 | + * @param string $source |
|
| 1175 | + * @param string $target |
|
| 1176 | + * @param array $options |
|
| 1177 | + * @return float |
|
| 1178 | + */ |
|
| 1179 | 1179 | public static function matchString($source, $target, $options=array()) |
| 1180 | 1180 | { |
| 1181 | 1181 | $defaults = array( |
@@ -1259,14 +1259,14 @@ discard block |
||
| 1259 | 1259 | |
| 1260 | 1260 | const INTERVAL_SECONDS = 'seconds'; |
| 1261 | 1261 | |
| 1262 | - /** |
|
| 1263 | - * Calculates the total amount of days / hours / minutes or seconds |
|
| 1264 | - * of a date interval object and returns the value. |
|
| 1265 | - * |
|
| 1266 | - * @param \DateInterval $interval |
|
| 1267 | - * @param string $unit |
|
| 1268 | - * @return integer |
|
| 1269 | - */ |
|
| 1262 | + /** |
|
| 1263 | + * Calculates the total amount of days / hours / minutes or seconds |
|
| 1264 | + * of a date interval object and returns the value. |
|
| 1265 | + * |
|
| 1266 | + * @param \DateInterval $interval |
|
| 1267 | + * @param string $unit |
|
| 1268 | + * @return integer |
|
| 1269 | + */ |
|
| 1270 | 1270 | public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
| 1271 | 1271 | { |
| 1272 | 1272 | $total = $interval->format('%a'); |
@@ -1304,13 +1304,13 @@ discard block |
||
| 1304 | 1304 | 'Sunday' |
| 1305 | 1305 | ); |
| 1306 | 1306 | |
| 1307 | - /** |
|
| 1308 | - * Converts a date to the corresponding day name. |
|
| 1309 | - * |
|
| 1310 | - * @param \DateTime $date |
|
| 1311 | - * @param string $short |
|
| 1312 | - * @return string|NULL |
|
| 1313 | - */ |
|
| 1307 | + /** |
|
| 1308 | + * Converts a date to the corresponding day name. |
|
| 1309 | + * |
|
| 1310 | + * @param \DateTime $date |
|
| 1311 | + * @param string $short |
|
| 1312 | + * @return string|NULL |
|
| 1313 | + */ |
|
| 1314 | 1314 | public static function date2dayName(\DateTime $date, $short=false) |
| 1315 | 1315 | { |
| 1316 | 1316 | $day = $date->format('l'); |
@@ -1325,21 +1325,21 @@ discard block |
||
| 1325 | 1325 | return null; |
| 1326 | 1326 | } |
| 1327 | 1327 | |
| 1328 | - /** |
|
| 1329 | - * Retrieves a list of english day names. |
|
| 1330 | - * @return string[] |
|
| 1331 | - */ |
|
| 1328 | + /** |
|
| 1329 | + * Retrieves a list of english day names. |
|
| 1330 | + * @return string[] |
|
| 1331 | + */ |
|
| 1332 | 1332 | public static function getDayNamesInvariant() |
| 1333 | 1333 | { |
| 1334 | 1334 | return self::$daysInvariant; |
| 1335 | 1335 | } |
| 1336 | 1336 | |
| 1337 | - /** |
|
| 1338 | - * Retrieves the day names list for the current locale. |
|
| 1339 | - * |
|
| 1340 | - * @param string $short |
|
| 1341 | - * @return string[] |
|
| 1342 | - */ |
|
| 1337 | + /** |
|
| 1338 | + * Retrieves the day names list for the current locale. |
|
| 1339 | + * |
|
| 1340 | + * @param string $short |
|
| 1341 | + * @return string[] |
|
| 1342 | + */ |
|
| 1343 | 1343 | public static function getDayNames($short=false) |
| 1344 | 1344 | { |
| 1345 | 1345 | if($short) { |
@@ -1399,16 +1399,16 @@ discard block |
||
| 1399 | 1399 | return $last; |
| 1400 | 1400 | } |
| 1401 | 1401 | |
| 1402 | - /** |
|
| 1403 | - * Splits a string into an array of all characters it is composed of. |
|
| 1404 | - * Unicode character safe. |
|
| 1405 | - * |
|
| 1406 | - * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1407 | - * characters. |
|
| 1408 | - * |
|
| 1409 | - * @param string $string |
|
| 1410 | - * @return array |
|
| 1411 | - */ |
|
| 1402 | + /** |
|
| 1403 | + * Splits a string into an array of all characters it is composed of. |
|
| 1404 | + * Unicode character safe. |
|
| 1405 | + * |
|
| 1406 | + * NOTE: Spaces and newlines (both \r and \n) are also considered single |
|
| 1407 | + * characters. |
|
| 1408 | + * |
|
| 1409 | + * @param string $string |
|
| 1410 | + * @return array |
|
| 1411 | + */ |
|
| 1412 | 1412 | public static function string2array(string $string) : array |
| 1413 | 1413 | { |
| 1414 | 1414 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
@@ -1419,12 +1419,12 @@ discard block |
||
| 1419 | 1419 | return array(); |
| 1420 | 1420 | } |
| 1421 | 1421 | |
| 1422 | - /** |
|
| 1423 | - * Checks whether the specified string contains HTML code. |
|
| 1424 | - * |
|
| 1425 | - * @param string $string |
|
| 1426 | - * @return boolean |
|
| 1427 | - */ |
|
| 1422 | + /** |
|
| 1423 | + * Checks whether the specified string contains HTML code. |
|
| 1424 | + * |
|
| 1425 | + * @param string $string |
|
| 1426 | + * @return boolean |
|
| 1427 | + */ |
|
| 1428 | 1428 | public static function isStringHTML(string $string) : bool |
| 1429 | 1429 | { |
| 1430 | 1430 | if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
@@ -1439,18 +1439,18 @@ discard block |
||
| 1439 | 1439 | return false; |
| 1440 | 1440 | } |
| 1441 | 1441 | |
| 1442 | - /** |
|
| 1443 | - * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1444 | - * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1445 | - * are no calculated correctly. |
|
| 1446 | - * |
|
| 1447 | - * @param string $str |
|
| 1448 | - * @param int $width |
|
| 1449 | - * @param string $break |
|
| 1450 | - * @param bool $cut |
|
| 1451 | - * @return string |
|
| 1452 | - * @see https://stackoverflow.com/a/4988494/2298192 |
|
| 1453 | - */ |
|
| 1442 | + /** |
|
| 1443 | + * UTF8-safe wordwrap method: works like the regular wordwrap |
|
| 1444 | + * PHP function but compatible with UTF8. Otherwise the lengths |
|
| 1445 | + * are no calculated correctly. |
|
| 1446 | + * |
|
| 1447 | + * @param string $str |
|
| 1448 | + * @param int $width |
|
| 1449 | + * @param string $break |
|
| 1450 | + * @param bool $cut |
|
| 1451 | + * @return string |
|
| 1452 | + * @see https://stackoverflow.com/a/4988494/2298192 |
|
| 1453 | + */ |
|
| 1454 | 1454 | public static function wordwrap($str, $width = 75, $break = "\n", $cut = false) |
| 1455 | 1455 | { |
| 1456 | 1456 | $lines = explode($break, $str); |
@@ -1496,27 +1496,27 @@ discard block |
||
| 1496 | 1496 | return implode($break, $lines); |
| 1497 | 1497 | } |
| 1498 | 1498 | |
| 1499 | - /** |
|
| 1500 | - * Calculates the byte length of a string, taking into |
|
| 1501 | - * account any unicode characters. |
|
| 1502 | - * |
|
| 1503 | - * @param string $string |
|
| 1504 | - * @return int |
|
| 1505 | - * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1506 | - */ |
|
| 1499 | + /** |
|
| 1500 | + * Calculates the byte length of a string, taking into |
|
| 1501 | + * account any unicode characters. |
|
| 1502 | + * |
|
| 1503 | + * @param string $string |
|
| 1504 | + * @return int |
|
| 1505 | + * @see https://stackoverflow.com/a/9718273/2298192 |
|
| 1506 | + */ |
|
| 1507 | 1507 | public static function string2bytes($string) |
| 1508 | 1508 | { |
| 1509 | 1509 | return mb_strlen($string, '8bit'); |
| 1510 | 1510 | } |
| 1511 | 1511 | |
| 1512 | - /** |
|
| 1513 | - * Creates a short, 8-character long hash for the specified string. |
|
| 1514 | - * |
|
| 1515 | - * WARNING: Not cryptographically safe. |
|
| 1516 | - * |
|
| 1517 | - * @param string $string |
|
| 1518 | - * @return string |
|
| 1519 | - */ |
|
| 1512 | + /** |
|
| 1513 | + * Creates a short, 8-character long hash for the specified string. |
|
| 1514 | + * |
|
| 1515 | + * WARNING: Not cryptographically safe. |
|
| 1516 | + * |
|
| 1517 | + * @param string $string |
|
| 1518 | + * @return string |
|
| 1519 | + */ |
|
| 1520 | 1520 | public static function string2shortHash($string) |
| 1521 | 1521 | { |
| 1522 | 1522 | return hash('crc32', $string, false); |
@@ -1542,23 +1542,23 @@ discard block |
||
| 1542 | 1542 | return ConvertHelper_ThrowableInfo::fromThrowable($e); |
| 1543 | 1543 | } |
| 1544 | 1544 | |
| 1545 | - /** |
|
| 1546 | - * Parses the specified query string like the native |
|
| 1547 | - * function <code>parse_str</code>, without the key |
|
| 1548 | - * naming limitations. |
|
| 1549 | - * |
|
| 1550 | - * Using parse_str, dots or spaces in key names are |
|
| 1551 | - * replaced by underscores. This method keeps all names |
|
| 1552 | - * intact. |
|
| 1553 | - * |
|
| 1554 | - * It still uses the parse_str implementation as it |
|
| 1555 | - * is tested and tried, but fixes the parameter names |
|
| 1556 | - * after parsing, as needed. |
|
| 1557 | - * |
|
| 1558 | - * @param string $queryString |
|
| 1559 | - * @return array |
|
| 1560 | - * @see https://www.php.net/manual/en/function.parse-str.php |
|
| 1561 | - */ |
|
| 1545 | + /** |
|
| 1546 | + * Parses the specified query string like the native |
|
| 1547 | + * function <code>parse_str</code>, without the key |
|
| 1548 | + * naming limitations. |
|
| 1549 | + * |
|
| 1550 | + * Using parse_str, dots or spaces in key names are |
|
| 1551 | + * replaced by underscores. This method keeps all names |
|
| 1552 | + * intact. |
|
| 1553 | + * |
|
| 1554 | + * It still uses the parse_str implementation as it |
|
| 1555 | + * is tested and tried, but fixes the parameter names |
|
| 1556 | + * after parsing, as needed. |
|
| 1557 | + * |
|
| 1558 | + * @param string $queryString |
|
| 1559 | + * @return array |
|
| 1560 | + * @see https://www.php.net/manual/en/function.parse-str.php |
|
| 1561 | + */ |
|
| 1562 | 1562 | public static function parseQueryString(string $queryString) : array |
| 1563 | 1563 | { |
| 1564 | 1564 | // allow HTML entities notation |
@@ -1598,16 +1598,16 @@ discard block |
||
| 1598 | 1598 | $placeholders = array(); |
| 1599 | 1599 | foreach($paramNames as $paramName) |
| 1600 | 1600 | { |
| 1601 | - // create a unique placeholder name |
|
| 1602 | - $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
| 1601 | + // create a unique placeholder name |
|
| 1602 | + $placeholder = '__PLACEHOLDER'.$counter.'__'; |
|
| 1603 | 1603 | |
| 1604 | - // store the placeholder name to replace later |
|
| 1605 | - $table[$placeholder] = $paramName; |
|
| 1604 | + // store the placeholder name to replace later |
|
| 1605 | + $table[$placeholder] = $paramName; |
|
| 1606 | 1606 | |
| 1607 | - // add the placeholder to replace in the query string before parsing |
|
| 1608 | - $placeholders[$paramName.'='] = $placeholder.'='; |
|
| 1607 | + // add the placeholder to replace in the query string before parsing |
|
| 1608 | + $placeholders[$paramName.'='] = $placeholder.'='; |
|
| 1609 | 1609 | |
| 1610 | - $counter++; |
|
| 1610 | + $counter++; |
|
| 1611 | 1611 | } |
| 1612 | 1612 | |
| 1613 | 1613 | // next challenge: replacing the parameter names by placeholders |
@@ -1634,23 +1634,23 @@ discard block |
||
| 1634 | 1634 | |
| 1635 | 1635 | foreach($parsed as $name => $value) |
| 1636 | 1636 | { |
| 1637 | - $keep[$table[$name]] = $value; |
|
| 1637 | + $keep[$table[$name]] = $value; |
|
| 1638 | 1638 | } |
| 1639 | 1639 | |
| 1640 | 1640 | return $keep; |
| 1641 | 1641 | } |
| 1642 | 1642 | |
| 1643 | - /** |
|
| 1644 | - * Searches for needle in the specified string, and returns a list |
|
| 1645 | - * of all occurrences, including the matched string. The matched |
|
| 1646 | - * string is useful when doing a case insensitive search, as it |
|
| 1647 | - * shows the exact matched case of needle. |
|
| 1648 | - * |
|
| 1649 | - * @param string $needle |
|
| 1650 | - * @param string $haystack |
|
| 1651 | - * @param bool $caseInsensitive |
|
| 1652 | - * @return ConvertHelper_StringMatch[] |
|
| 1653 | - */ |
|
| 1643 | + /** |
|
| 1644 | + * Searches for needle in the specified string, and returns a list |
|
| 1645 | + * of all occurrences, including the matched string. The matched |
|
| 1646 | + * string is useful when doing a case insensitive search, as it |
|
| 1647 | + * shows the exact matched case of needle. |
|
| 1648 | + * |
|
| 1649 | + * @param string $needle |
|
| 1650 | + * @param string $haystack |
|
| 1651 | + * @param bool $caseInsensitive |
|
| 1652 | + * @return ConvertHelper_StringMatch[] |
|
| 1653 | + */ |
|
| 1654 | 1654 | public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
| 1655 | 1655 | { |
| 1656 | 1656 | if($needle === '') { |
@@ -1676,14 +1676,14 @@ discard block |
||
| 1676 | 1676 | return $positions; |
| 1677 | 1677 | } |
| 1678 | 1678 | |
| 1679 | - /** |
|
| 1680 | - * Like explode, but trims all entries, and removes |
|
| 1681 | - * empty entries from the resulting array. |
|
| 1682 | - * |
|
| 1683 | - * @param string $delimiter |
|
| 1684 | - * @param string $string |
|
| 1685 | - * @return string[] |
|
| 1686 | - */ |
|
| 1679 | + /** |
|
| 1680 | + * Like explode, but trims all entries, and removes |
|
| 1681 | + * empty entries from the resulting array. |
|
| 1682 | + * |
|
| 1683 | + * @param string $delimiter |
|
| 1684 | + * @param string $string |
|
| 1685 | + * @return string[] |
|
| 1686 | + */ |
|
| 1687 | 1687 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1688 | 1688 | { |
| 1689 | 1689 | if(empty($string) || empty($delimiter)) { |
@@ -1705,12 +1705,12 @@ discard block |
||
| 1705 | 1705 | |
| 1706 | 1706 | protected static $eolChars; |
| 1707 | 1707 | |
| 1708 | - /** |
|
| 1709 | - * Detects the most used end-of-line character in the subject string. |
|
| 1710 | - * |
|
| 1711 | - * @param string $str The string to check. |
|
| 1712 | - * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1713 | - */ |
|
| 1708 | + /** |
|
| 1709 | + * Detects the most used end-of-line character in the subject string. |
|
| 1710 | + * |
|
| 1711 | + * @param string $str The string to check. |
|
| 1712 | + * @return NULL|ConvertHelper_EOL The detected EOL instance, or NULL if none has been detected. |
|
| 1713 | + */ |
|
| 1714 | 1714 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1715 | 1715 | { |
| 1716 | 1716 | if(empty($subjectString)) { |
@@ -1722,27 +1722,27 @@ discard block |
||
| 1722 | 1722 | $cr = chr((int)hexdec('0d')); |
| 1723 | 1723 | $lf = chr((int)hexdec('0a')); |
| 1724 | 1724 | |
| 1725 | - self::$eolChars = array( |
|
| 1726 | - array( |
|
| 1727 | - 'char' => $cr.$lf, |
|
| 1728 | - 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1729 | - 'description' => t('Carriage return followed by a line feed'), |
|
| 1730 | - ), |
|
| 1731 | - array( |
|
| 1732 | - 'char' => $lf.$cr, |
|
| 1733 | - 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1734 | - 'description' => t('Line feed followed by a carriage return'), |
|
| 1735 | - ), |
|
| 1736 | - array( |
|
| 1737 | - 'char' => $lf, |
|
| 1738 | - 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1739 | - 'description' => t('Line feed'), |
|
| 1740 | - ), |
|
| 1741 | - array( |
|
| 1742 | - 'char' => $cr, |
|
| 1743 | - 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1744 | - 'description' => t('Carriage Return'), |
|
| 1745 | - ), |
|
| 1725 | + self::$eolChars = array( |
|
| 1726 | + array( |
|
| 1727 | + 'char' => $cr.$lf, |
|
| 1728 | + 'type' => ConvertHelper_EOL::TYPE_CRLF, |
|
| 1729 | + 'description' => t('Carriage return followed by a line feed'), |
|
| 1730 | + ), |
|
| 1731 | + array( |
|
| 1732 | + 'char' => $lf.$cr, |
|
| 1733 | + 'type' => ConvertHelper_EOL::TYPE_LFCR, |
|
| 1734 | + 'description' => t('Line feed followed by a carriage return'), |
|
| 1735 | + ), |
|
| 1736 | + array( |
|
| 1737 | + 'char' => $lf, |
|
| 1738 | + 'type' => ConvertHelper_EOL::TYPE_LF, |
|
| 1739 | + 'description' => t('Line feed'), |
|
| 1740 | + ), |
|
| 1741 | + array( |
|
| 1742 | + 'char' => $cr, |
|
| 1743 | + 'type' => ConvertHelper_EOL::TYPE_CR, |
|
| 1744 | + 'description' => t('Carriage Return'), |
|
| 1745 | + ), |
|
| 1746 | 1746 | ); |
| 1747 | 1747 | } |
| 1748 | 1748 | |
@@ -1770,13 +1770,13 @@ discard block |
||
| 1770 | 1770 | ); |
| 1771 | 1771 | } |
| 1772 | 1772 | |
| 1773 | - /** |
|
| 1774 | - * Removes the specified keys from the target array, |
|
| 1775 | - * if they exist. |
|
| 1776 | - * |
|
| 1777 | - * @param array $array |
|
| 1778 | - * @param array $keys |
|
| 1779 | - */ |
|
| 1773 | + /** |
|
| 1774 | + * Removes the specified keys from the target array, |
|
| 1775 | + * if they exist. |
|
| 1776 | + * |
|
| 1777 | + * @param array $array |
|
| 1778 | + * @param array $keys |
|
| 1779 | + */ |
|
| 1780 | 1780 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1781 | 1781 | { |
| 1782 | 1782 | foreach($keys as $key) |
@@ -1787,11 +1787,11 @@ discard block |
||
| 1787 | 1787 | } |
| 1788 | 1788 | } |
| 1789 | 1789 | |
| 1790 | - /** |
|
| 1791 | - * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1792 | - * @param mixed $value |
|
| 1793 | - * @return bool |
|
| 1794 | - */ |
|
| 1790 | + /** |
|
| 1791 | + * Checks if the specified variable is an integer or a string containing an integer. |
|
| 1792 | + * @param mixed $value |
|
| 1793 | + * @return bool |
|
| 1794 | + */ |
|
| 1795 | 1795 | public static function isInteger($value) : bool |
| 1796 | 1796 | { |
| 1797 | 1797 | if(is_int($value)) { |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | $amount = substr_count($line, "\t") - $min; |
| 69 | 69 | $line = trim($line); |
| 70 | 70 | if ($amount >= 1) { |
| 71 | - $line = str_repeat("\t", $amount) . $line; |
|
| 71 | + $line = str_repeat("\t", $amount).$line; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | $converted[] = $line; |
@@ -140,10 +140,10 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | // specifically handle zero |
| 142 | 142 | if ($seconds <= 0) { |
| 143 | - return '0 ' . t('seconds'); |
|
| 143 | + return '0 '.t('seconds'); |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | - if($seconds < 1) { |
|
| 146 | + if ($seconds < 1) { |
|
| 147 | 147 | return t('less than a second'); |
| 148 | 148 | } |
| 149 | 149 | |
@@ -151,7 +151,7 @@ discard block |
||
| 151 | 151 | foreach ($units as $def) { |
| 152 | 152 | $quot = intval($seconds / $def['value']); |
| 153 | 153 | if ($quot) { |
| 154 | - $item = $quot . ' '; |
|
| 154 | + $item = $quot.' '; |
|
| 155 | 155 | if (abs($quot) > 1) { |
| 156 | 156 | $item .= $def['plural']; |
| 157 | 157 | } else { |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | return $last; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
| 171 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -185,11 +185,11 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | public static function duration2string($datefrom, $dateto = -1) |
| 187 | 187 | { |
| 188 | - if($datefrom instanceof \DateTime) { |
|
| 188 | + if ($datefrom instanceof \DateTime) { |
|
| 189 | 189 | $datefrom = ConvertHelper::date2timestamp($datefrom); |
| 190 | 190 | } |
| 191 | 191 | |
| 192 | - if($dateto instanceof \DateTime) { |
|
| 192 | + if ($dateto instanceof \DateTime) { |
|
| 193 | 193 | $dateto = ConvertHelper::date2timestamp($dateto); |
| 194 | 194 | } |
| 195 | 195 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | $interval = ""; |
| 211 | 211 | |
| 212 | 212 | $future = false; |
| 213 | - if($difference < 0) { |
|
| 213 | + if ($difference < 0) { |
|
| 214 | 214 | $difference = $difference * -1; |
| 215 | 215 | $future = true; |
| 216 | 216 | } |
@@ -285,7 +285,7 @@ discard block |
||
| 285 | 285 | $day = (int)date("j", $dateto); |
| 286 | 286 | $year = (int)date("Y", $datefrom); |
| 287 | 287 | |
| 288 | - while(mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $dateto) |
|
| 288 | + while (mktime($hour, $min, $sec, $month + ($months_difference), $day, $year) < $dateto) |
|
| 289 | 289 | { |
| 290 | 290 | $months_difference++; |
| 291 | 291 | } |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | $datediff--; |
| 301 | 301 | } |
| 302 | 302 | |
| 303 | - if($future) { |
|
| 303 | + if ($future) { |
|
| 304 | 304 | $result = ($datediff == 1) ? t('In one month', $datediff) : t('In %1s months', $datediff); |
| 305 | 305 | } else { |
| 306 | 306 | $result = ($datediff == 1) ? t('One month ago', $datediff) : t('%1s months ago', $datediff); |
@@ -309,7 +309,7 @@ discard block |
||
| 309 | 309 | |
| 310 | 310 | case "y": |
| 311 | 311 | $datediff = floor($difference / 60 / 60 / 24 / 365); |
| 312 | - if($future) { |
|
| 312 | + if ($future) { |
|
| 313 | 313 | $result = ($datediff == 1) ? t('In one year', $datediff) : t('In %1s years', $datediff); |
| 314 | 314 | } else { |
| 315 | 315 | $result = ($datediff == 1) ? t('One year ago', $datediff) : t('%1s years ago', $datediff); |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | case "d": |
| 320 | 320 | $datediff = floor($difference / 60 / 60 / 24); |
| 321 | - if($future) { |
|
| 321 | + if ($future) { |
|
| 322 | 322 | $result = ($datediff == 1) ? t('In one day', $datediff) : t('In %1s days', $datediff); |
| 323 | 323 | } else { |
| 324 | 324 | $result = ($datediff == 1) ? t('One day ago', $datediff) : t('%1s days ago', $datediff); |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | |
| 328 | 328 | case "ww": |
| 329 | 329 | $datediff = floor($difference / 60 / 60 / 24 / 7); |
| 330 | - if($future) { |
|
| 330 | + if ($future) { |
|
| 331 | 331 | $result = ($datediff == 1) ? t('In one week', $datediff) : t('In %1s weeks', $datediff); |
| 332 | 332 | } else { |
| 333 | 333 | $result = ($datediff == 1) ? t('One week ago', $datediff) : t('%1s weeks ago', $datediff); |
@@ -336,7 +336,7 @@ discard block |
||
| 336 | 336 | |
| 337 | 337 | case "h": |
| 338 | 338 | $datediff = floor($difference / 60 / 60); |
| 339 | - if($future) { |
|
| 339 | + if ($future) { |
|
| 340 | 340 | $result = ($datediff == 1) ? t('In one hour', $datediff) : t('In %1s hours', $datediff); |
| 341 | 341 | } else { |
| 342 | 342 | $result = ($datediff == 1) ? t('One hour ago', $datediff) : t('%1s hours ago', $datediff); |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | |
| 346 | 346 | case "n": |
| 347 | 347 | $datediff = floor($difference / 60); |
| 348 | - if($future) { |
|
| 348 | + if ($future) { |
|
| 349 | 349 | $result = ($datediff == 1) ? t('In one minute', $datediff) : t('In %1s minutes', $datediff); |
| 350 | 350 | } else { |
| 351 | 351 | $result = ($datediff == 1) ? t('One minute ago', $datediff) : t('%1s minutes ago', $datediff); |
@@ -354,7 +354,7 @@ discard block |
||
| 354 | 354 | |
| 355 | 355 | case "s": |
| 356 | 356 | $datediff = $difference; |
| 357 | - if($future) { |
|
| 357 | + if ($future) { |
|
| 358 | 358 | $result = ($datediff == 1) ? t('In one second', $datediff) : t('In %1s seconds', $datediff); |
| 359 | 359 | } else { |
| 360 | 360 | $result = ($datediff == 1) ? t('One second ago', $datediff) : t('%1s seconds ago', $datediff); |
@@ -377,9 +377,9 @@ discard block |
||
| 377 | 377 | return $geshi->parse_code(); |
| 378 | 378 | } |
| 379 | 379 | |
| 380 | - public static function highlight_xml($xml, $formatSource=false) |
|
| 380 | + public static function highlight_xml($xml, $formatSource = false) |
|
| 381 | 381 | { |
| 382 | - if($formatSource) |
|
| 382 | + if ($formatSource) |
|
| 383 | 383 | { |
| 384 | 384 | $dom = new \DOMDocument(); |
| 385 | 385 | $dom->loadXML($xml); |
@@ -417,22 +417,22 @@ discard block |
||
| 417 | 417 | $terabyte = $gigabyte * 1024; |
| 418 | 418 | |
| 419 | 419 | if (($bytes >= 0) && ($bytes < $kilobyte)) { |
| 420 | - return $bytes . ' ' . t('B'); |
|
| 420 | + return $bytes.' '.t('B'); |
|
| 421 | 421 | |
| 422 | 422 | } elseif (($bytes >= $kilobyte) && ($bytes < $megabyte)) { |
| 423 | - return round($bytes / $kilobyte, $precision) . ' ' . t('Kb'); |
|
| 423 | + return round($bytes / $kilobyte, $precision).' '.t('Kb'); |
|
| 424 | 424 | |
| 425 | 425 | } elseif (($bytes >= $megabyte) && ($bytes < $gigabyte)) { |
| 426 | - return round($bytes / $megabyte, $precision) . ' ' . t('Mb'); |
|
| 426 | + return round($bytes / $megabyte, $precision).' '.t('Mb'); |
|
| 427 | 427 | |
| 428 | 428 | } elseif (($bytes >= $gigabyte) && ($bytes < $terabyte)) { |
| 429 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Gb'); |
|
| 429 | + return round($bytes / $gigabyte, $precision).' '.t('Gb'); |
|
| 430 | 430 | |
| 431 | 431 | } elseif ($bytes >= $terabyte) { |
| 432 | - return round($bytes / $gigabyte, $precision) . ' ' . t('Tb'); |
|
| 432 | + return round($bytes / $gigabyte, $precision).' '.t('Tb'); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | - return $bytes . ' ' . t('B'); |
|
| 435 | + return $bytes.' '.t('B'); |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | /** |
@@ -452,34 +452,34 @@ discard block |
||
| 452 | 452 | return $text; |
| 453 | 453 | } |
| 454 | 454 | |
| 455 | - $text = trim(mb_substr($text, 0, $targetLength)) . $append; |
|
| 455 | + $text = trim(mb_substr($text, 0, $targetLength)).$append; |
|
| 456 | 456 | |
| 457 | 457 | return $text; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | - public static function var_dump($var, $html=true) |
|
| 460 | + public static function var_dump($var, $html = true) |
|
| 461 | 461 | { |
| 462 | 462 | $info = parseVariable($var); |
| 463 | 463 | |
| 464 | - if($html) { |
|
| 464 | + if ($html) { |
|
| 465 | 465 | return $info->toHTML(); |
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | return $info->toString(); |
| 469 | 469 | } |
| 470 | 470 | |
| 471 | - public static function print_r($var, $return=false, $html=true) |
|
| 471 | + public static function print_r($var, $return = false, $html = true) |
|
| 472 | 472 | { |
| 473 | 473 | $result = self::var_dump($var, $html); |
| 474 | 474 | |
| 475 | - if($html) { |
|
| 475 | + if ($html) { |
|
| 476 | 476 | $result = |
| 477 | 477 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
| 478 | 478 | $result. |
| 479 | 479 | '</pre>'; |
| 480 | 480 | } |
| 481 | 481 | |
| 482 | - if($return) { |
|
| 482 | + if ($return) { |
|
| 483 | 483 | return $result; |
| 484 | 484 | } |
| 485 | 485 | |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | |
| 500 | 500 | public static function string2bool($string) |
| 501 | 501 | { |
| 502 | - if($string === '' || $string === null) { |
|
| 502 | + if ($string === '' || $string === null) { |
|
| 503 | 503 | return false; |
| 504 | 504 | } |
| 505 | 505 | |
@@ -554,10 +554,10 @@ discard block |
||
| 554 | 554 | public static function date2listLabel(\DateTime $date, $includeTime = false, $shortMonth = false) |
| 555 | 555 | { |
| 556 | 556 | $today = new \DateTime(); |
| 557 | - if($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
| 557 | + if ($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
| 558 | 558 | $label = t('Today'); |
| 559 | 559 | } else { |
| 560 | - $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
|
| 560 | + $label = $date->format('d').'. '.self::month2string((int)$date->format('m'), $shortMonth).' '; |
|
| 561 | 561 | if ($date->format('Y') != date('Y')) { |
| 562 | 562 | $label .= $date->format('Y'); |
| 563 | 563 | } |
@@ -648,28 +648,28 @@ discard block |
||
| 648 | 648 | $hexAlphabet = array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'); |
| 649 | 649 | |
| 650 | 650 | $stack = array(); |
| 651 | - foreach(self::$controlChars as $char) |
|
| 651 | + foreach (self::$controlChars as $char) |
|
| 652 | 652 | { |
| 653 | 653 | $tokens = explode('-', $char); |
| 654 | 654 | $start = $tokens[0]; |
| 655 | 655 | $end = $tokens[1]; |
| 656 | 656 | $prefix = substr($start, 0, 3); |
| 657 | 657 | $range = array(); |
| 658 | - foreach($hexAlphabet as $number) { |
|
| 658 | + foreach ($hexAlphabet as $number) { |
|
| 659 | 659 | $range[] = $prefix.$number; |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | 662 | $use = false; |
| 663 | - foreach($range as $number) { |
|
| 664 | - if($number == $start) { |
|
| 663 | + foreach ($range as $number) { |
|
| 664 | + if ($number == $start) { |
|
| 665 | 665 | $use = true; |
| 666 | 666 | } |
| 667 | 667 | |
| 668 | - if($use) { |
|
| 668 | + if ($use) { |
|
| 669 | 669 | $stack[] = $number; |
| 670 | 670 | } |
| 671 | 671 | |
| 672 | - if($number == $end) { |
|
| 672 | + if ($number == $end) { |
|
| 673 | 673 | break; |
| 674 | 674 | } |
| 675 | 675 | } |
@@ -690,7 +690,7 @@ discard block |
||
| 690 | 690 | $chars = self::getControlCharactersAsHex(); |
| 691 | 691 | |
| 692 | 692 | $result = array(); |
| 693 | - foreach($chars as $char) { |
|
| 693 | + foreach ($chars as $char) { |
|
| 694 | 694 | $result[] = hex2bin($char); |
| 695 | 695 | } |
| 696 | 696 | |
@@ -708,14 +708,14 @@ discard block |
||
| 708 | 708 | $chars = self::getControlCharactersAsHex(); |
| 709 | 709 | |
| 710 | 710 | $result = array(); |
| 711 | - foreach($chars as $char) { |
|
| 711 | + foreach ($chars as $char) { |
|
| 712 | 712 | $result[] = '\u'.strtolower($char); |
| 713 | 713 | } |
| 714 | 714 | |
| 715 | 715 | return $result; |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | - protected static $controlChars = array( |
|
| 718 | + protected static $controlChars = array( |
|
| 719 | 719 | '0000-0008', // control chars |
| 720 | 720 | '000E-000F', // control chars |
| 721 | 721 | '0010-001F', // control chars |
@@ -737,19 +737,19 @@ discard block |
||
| 737 | 737 | */ |
| 738 | 738 | public static function stripControlCharacters(string $string) : string |
| 739 | 739 | { |
| 740 | - if(empty($string)) { |
|
| 740 | + if (empty($string)) { |
|
| 741 | 741 | return $string; |
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | // create the regex from the unicode characters list |
| 745 | - if(!isset(self::$controlCharsRegex)) |
|
| 745 | + if (!isset(self::$controlCharsRegex)) |
|
| 746 | 746 | { |
| 747 | 747 | $chars = self::getControlCharactersAsHex(); |
| 748 | 748 | |
| 749 | 749 | // we use the notation \x{0000} to specify the unicode character key |
| 750 | 750 | // in the regular expression. |
| 751 | 751 | $stack = array(); |
| 752 | - foreach($chars as $char) { |
|
| 752 | + foreach ($chars as $char) { |
|
| 753 | 753 | $stack[] = '\x{'.$char.'}'; |
| 754 | 754 | } |
| 755 | 755 | |
@@ -783,7 +783,7 @@ discard block |
||
| 783 | 783 | $ordInt = ord($octet); |
| 784 | 784 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
| 785 | 785 | $ordHex = base_convert($ordInt, 10, 16); |
| 786 | - $output .= '\x' . $ordHex; |
|
| 786 | + $output .= '\x'.$ordHex; |
|
| 787 | 787 | } |
| 788 | 788 | return $output; |
| 789 | 789 | } |
@@ -815,19 +815,19 @@ discard block |
||
| 815 | 815 | |
| 816 | 816 | protected static function convertScalarForComparison($scalar) |
| 817 | 817 | { |
| 818 | - if($scalar === '' || is_null($scalar)) { |
|
| 818 | + if ($scalar === '' || is_null($scalar)) { |
|
| 819 | 819 | return null; |
| 820 | 820 | } |
| 821 | 821 | |
| 822 | - if(is_bool($scalar)) { |
|
| 822 | + if (is_bool($scalar)) { |
|
| 823 | 823 | return self::bool2string($scalar); |
| 824 | 824 | } |
| 825 | 825 | |
| 826 | - if(is_array($scalar)) { |
|
| 826 | + if (is_array($scalar)) { |
|
| 827 | 827 | $scalar = md5(serialize($scalar)); |
| 828 | 828 | } |
| 829 | 829 | |
| 830 | - if($scalar !== null && !is_scalar($scalar)) { |
|
| 830 | + if ($scalar !== null && !is_scalar($scalar)) { |
|
| 831 | 831 | throw new ConvertHelper_Exception( |
| 832 | 832 | 'Not a scalar value in comparison', |
| 833 | 833 | null, |
@@ -876,7 +876,7 @@ discard block |
||
| 876 | 876 | public static function bool2string($boolean, bool $yesno = false) : string |
| 877 | 877 | { |
| 878 | 878 | // allow 'yes', 'true', 'no', 'false' string notations as well |
| 879 | - if(!is_bool($boolean)) { |
|
| 879 | + if (!is_bool($boolean)) { |
|
| 880 | 880 | $boolean = self::string2bool($boolean); |
| 881 | 881 | } |
| 882 | 882 | |
@@ -917,15 +917,15 @@ discard block |
||
| 917 | 917 | public static function array2attributeString($array) |
| 918 | 918 | { |
| 919 | 919 | $tokens = array(); |
| 920 | - foreach($array as $attr => $value) { |
|
| 921 | - if($value == '' || $value == null) { |
|
| 920 | + foreach ($array as $attr => $value) { |
|
| 921 | + if ($value == '' || $value == null) { |
|
| 922 | 922 | continue; |
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | $tokens[] = $attr.'="'.$value.'"'; |
| 926 | 926 | } |
| 927 | 927 | |
| 928 | - if(empty($tokens)) { |
|
| 928 | + if (empty($tokens)) { |
|
| 929 | 929 | return ''; |
| 930 | 930 | } |
| 931 | 931 | |
@@ -940,10 +940,10 @@ discard block |
||
| 940 | 940 | * @param string $string |
| 941 | 941 | * @return string |
| 942 | 942 | */ |
| 943 | - public static function string2attributeJS($string, $quoted=true) |
|
| 943 | + public static function string2attributeJS($string, $quoted = true) |
|
| 944 | 944 | { |
| 945 | 945 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
| 946 | - if($quoted) { |
|
| 946 | + if ($quoted) { |
|
| 947 | 947 | $converted = "'".$converted."'"; |
| 948 | 948 | } |
| 949 | 949 | |
@@ -961,11 +961,11 @@ discard block |
||
| 961 | 961 | */ |
| 962 | 962 | public static function isBoolean($value) : bool |
| 963 | 963 | { |
| 964 | - if(is_bool($value)) { |
|
| 964 | + if (is_bool($value)) { |
|
| 965 | 965 | return true; |
| 966 | 966 | } |
| 967 | 967 | |
| 968 | - if(!is_scalar($value)) { |
|
| 968 | + if (!is_scalar($value)) { |
|
| 969 | 969 | return false; |
| 970 | 970 | } |
| 971 | 971 | |
@@ -981,7 +981,7 @@ discard block |
||
| 981 | 981 | public static function array2styleString(array $subject) : string |
| 982 | 982 | { |
| 983 | 983 | $tokens = array(); |
| 984 | - foreach($subject as $name => $value) { |
|
| 984 | + foreach ($subject as $name => $value) { |
|
| 985 | 985 | $tokens[] = $name.':'.$value; |
| 986 | 986 | } |
| 987 | 987 | |
@@ -1046,7 +1046,7 @@ discard block |
||
| 1046 | 1046 | * @param string $regex |
| 1047 | 1047 | * @return array |
| 1048 | 1048 | */ |
| 1049 | - public static function regex2js($regex, $return=self::JS_REGEX_OBJECT) |
|
| 1049 | + public static function regex2js($regex, $return = self::JS_REGEX_OBJECT) |
|
| 1050 | 1050 | { |
| 1051 | 1051 | $regex = trim($regex); |
| 1052 | 1052 | $separator = substr($regex, 0, 1); |
@@ -1054,7 +1054,7 @@ discard block |
||
| 1054 | 1054 | array_shift($parts); |
| 1055 | 1055 | |
| 1056 | 1056 | $modifiers = array_pop($parts); |
| 1057 | - if($modifiers == $separator) { |
|
| 1057 | + if ($modifiers == $separator) { |
|
| 1058 | 1058 | $modifiers = ''; |
| 1059 | 1059 | } |
| 1060 | 1060 | |
@@ -1070,14 +1070,14 @@ discard block |
||
| 1070 | 1070 | // convert the anchors that are not supported in js regexes |
| 1071 | 1071 | $format = str_replace(array('\\A', '\\Z', '\\z'), array('^', '$', ''), $format); |
| 1072 | 1072 | |
| 1073 | - if($return==self::JS_REGEX_JSON) { |
|
| 1073 | + if ($return == self::JS_REGEX_JSON) { |
|
| 1074 | 1074 | return json_encode(array( |
| 1075 | 1075 | 'format' => $format, |
| 1076 | 1076 | 'modifiers' => $modifiers |
| 1077 | 1077 | )); |
| 1078 | 1078 | } |
| 1079 | 1079 | |
| 1080 | - if(!empty($modifiers)) { |
|
| 1080 | + if (!empty($modifiers)) { |
|
| 1081 | 1081 | return sprintf( |
| 1082 | 1082 | 'new RegExp(%s, %s)', |
| 1083 | 1083 | json_encode($format), |
@@ -1100,10 +1100,10 @@ discard block |
||
| 1100 | 1100 | public static function stripUTFBom($string) |
| 1101 | 1101 | { |
| 1102 | 1102 | $boms = FileHelper::getUTFBOMs(); |
| 1103 | - foreach($boms as $bomChars) { |
|
| 1103 | + foreach ($boms as $bomChars) { |
|
| 1104 | 1104 | $length = mb_strlen($bomChars); |
| 1105 | 1105 | $text = mb_substr($string, 0, $length); |
| 1106 | - if($text==$bomChars) { |
|
| 1106 | + if ($text == $bomChars) { |
|
| 1107 | 1107 | return mb_substr($string, $length); |
| 1108 | 1108 | } |
| 1109 | 1109 | } |
@@ -1120,7 +1120,7 @@ discard block |
||
| 1120 | 1120 | */ |
| 1121 | 1121 | public static function string2utf8($string) |
| 1122 | 1122 | { |
| 1123 | - if(!self::isStringASCII($string)) { |
|
| 1123 | + if (!self::isStringASCII($string)) { |
|
| 1124 | 1124 | return \ForceUTF8\Encoding::toUTF8($string); |
| 1125 | 1125 | } |
| 1126 | 1126 | |
@@ -1138,11 +1138,11 @@ discard block |
||
| 1138 | 1138 | */ |
| 1139 | 1139 | public static function isStringASCII($string) |
| 1140 | 1140 | { |
| 1141 | - if($string === '' || $string === NULL) { |
|
| 1141 | + if ($string === '' || $string === NULL) { |
|
| 1142 | 1142 | return true; |
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | - if(!is_string($string)) { |
|
| 1145 | + if (!is_string($string)) { |
|
| 1146 | 1146 | return false; |
| 1147 | 1147 | } |
| 1148 | 1148 | |
@@ -1176,7 +1176,7 @@ discard block |
||
| 1176 | 1176 | * @param array $options |
| 1177 | 1177 | * @return float |
| 1178 | 1178 | */ |
| 1179 | - public static function matchString($source, $target, $options=array()) |
|
| 1179 | + public static function matchString($source, $target, $options = array()) |
|
| 1180 | 1180 | { |
| 1181 | 1181 | $defaults = array( |
| 1182 | 1182 | 'maxLevenshtein' => 10, |
@@ -1186,12 +1186,12 @@ discard block |
||
| 1186 | 1186 | $options = array_merge($defaults, $options); |
| 1187 | 1187 | |
| 1188 | 1188 | // avoid doing this via levenshtein |
| 1189 | - if($source == $target) { |
|
| 1189 | + if ($source == $target) { |
|
| 1190 | 1190 | return 100; |
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | $diff = levenshtein($source, $target); |
| 1194 | - if($diff > $options['maxLevenshtein']) { |
|
| 1194 | + if ($diff > $options['maxLevenshtein']) { |
|
| 1195 | 1195 | return 0; |
| 1196 | 1196 | } |
| 1197 | 1197 | |
@@ -1205,8 +1205,8 @@ discard block |
||
| 1205 | 1205 | |
| 1206 | 1206 | $offset = 0; |
| 1207 | 1207 | $keep = array(); |
| 1208 | - foreach($tokens as $token) { |
|
| 1209 | - if($interval->$token > 0) { |
|
| 1208 | + foreach ($tokens as $token) { |
|
| 1209 | + if ($interval->$token > 0) { |
|
| 1210 | 1210 | $keep = array_slice($tokens, $offset); |
| 1211 | 1211 | break; |
| 1212 | 1212 | } |
@@ -1215,16 +1215,16 @@ discard block |
||
| 1215 | 1215 | } |
| 1216 | 1216 | |
| 1217 | 1217 | $parts = array(); |
| 1218 | - foreach($keep as $token) |
|
| 1218 | + foreach ($keep as $token) |
|
| 1219 | 1219 | { |
| 1220 | 1220 | $value = $interval->$token; |
| 1221 | 1221 | $label = ''; |
| 1222 | 1222 | |
| 1223 | 1223 | $suffix = 'p'; |
| 1224 | - if($value == 1) { $suffix = 's'; } |
|
| 1224 | + if ($value == 1) { $suffix = 's'; } |
|
| 1225 | 1225 | $token .= $suffix; |
| 1226 | 1226 | |
| 1227 | - switch($token) { |
|
| 1227 | + switch ($token) { |
|
| 1228 | 1228 | case 'ys': $label = t('1 year'); break; |
| 1229 | 1229 | case 'yp': $label = t('%1$s years', $value); break; |
| 1230 | 1230 | case 'ms': $label = t('1 month'); break; |
@@ -1242,7 +1242,7 @@ discard block |
||
| 1242 | 1242 | $parts[] = $label; |
| 1243 | 1243 | } |
| 1244 | 1244 | |
| 1245 | - if(count($parts) == 1) { |
|
| 1245 | + if (count($parts) == 1) { |
|
| 1246 | 1246 | return $parts[0]; |
| 1247 | 1247 | } |
| 1248 | 1248 | |
@@ -1267,23 +1267,23 @@ discard block |
||
| 1267 | 1267 | * @param string $unit |
| 1268 | 1268 | * @return integer |
| 1269 | 1269 | */ |
| 1270 | - public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) |
|
| 1270 | + public static function interval2total(\DateInterval $interval, $unit = self::INTERVAL_SECONDS) |
|
| 1271 | 1271 | { |
| 1272 | 1272 | $total = $interval->format('%a'); |
| 1273 | 1273 | if ($unit == self::INTERVAL_DAYS) { |
| 1274 | 1274 | return $total; |
| 1275 | 1275 | } |
| 1276 | 1276 | |
| 1277 | - $total = ($total * 24) + ($interval->h ); |
|
| 1277 | + $total = ($total * 24) + ($interval->h); |
|
| 1278 | 1278 | if ($unit == self::INTERVAL_HOURS) { |
| 1279 | 1279 | return $total; |
| 1280 | 1280 | } |
| 1281 | 1281 | |
| 1282 | - $total = ($total * 60) + ($interval->i ); |
|
| 1282 | + $total = ($total * 60) + ($interval->i); |
|
| 1283 | 1283 | if ($unit == self::INTERVAL_MINUTES) |
| 1284 | 1284 | return $total; |
| 1285 | 1285 | |
| 1286 | - $total = ($total * 60) + ($interval->s ); |
|
| 1286 | + $total = ($total * 60) + ($interval->s); |
|
| 1287 | 1287 | if ($unit == self::INTERVAL_SECONDS) |
| 1288 | 1288 | return $total; |
| 1289 | 1289 | |
@@ -1311,13 +1311,13 @@ discard block |
||
| 1311 | 1311 | * @param string $short |
| 1312 | 1312 | * @return string|NULL |
| 1313 | 1313 | */ |
| 1314 | - public static function date2dayName(\DateTime $date, $short=false) |
|
| 1314 | + public static function date2dayName(\DateTime $date, $short = false) |
|
| 1315 | 1315 | { |
| 1316 | 1316 | $day = $date->format('l'); |
| 1317 | 1317 | $invariant = self::getDayNamesInvariant(); |
| 1318 | 1318 | |
| 1319 | 1319 | $idx = array_search($day, $invariant); |
| 1320 | - if($idx !== false) { |
|
| 1320 | + if ($idx !== false) { |
|
| 1321 | 1321 | $localized = self::getDayNames($short); |
| 1322 | 1322 | return $localized[$idx]; |
| 1323 | 1323 | } |
@@ -1340,10 +1340,10 @@ discard block |
||
| 1340 | 1340 | * @param string $short |
| 1341 | 1341 | * @return string[] |
| 1342 | 1342 | */ |
| 1343 | - public static function getDayNames($short=false) |
|
| 1343 | + public static function getDayNames($short = false) |
|
| 1344 | 1344 | { |
| 1345 | - if($short) { |
|
| 1346 | - if(!isset(self::$daysShort)) { |
|
| 1345 | + if ($short) { |
|
| 1346 | + if (!isset(self::$daysShort)) { |
|
| 1347 | 1347 | self::$daysShort = array( |
| 1348 | 1348 | t('Mon'), |
| 1349 | 1349 | t('Tue'), |
@@ -1358,7 +1358,7 @@ discard block |
||
| 1358 | 1358 | return self::$daysShort; |
| 1359 | 1359 | } |
| 1360 | 1360 | |
| 1361 | - if(!isset(self::$days)) { |
|
| 1361 | + if (!isset(self::$days)) { |
|
| 1362 | 1362 | self::$days = array( |
| 1363 | 1363 | t('Monday'), |
| 1364 | 1364 | t('Tuesday'), |
@@ -1383,17 +1383,17 @@ discard block |
||
| 1383 | 1383 | */ |
| 1384 | 1384 | public static function implodeWithAnd(array $list, $sep = ', ', $conjunction = null) |
| 1385 | 1385 | { |
| 1386 | - if(empty($list)) { |
|
| 1386 | + if (empty($list)) { |
|
| 1387 | 1387 | return ''; |
| 1388 | 1388 | } |
| 1389 | 1389 | |
| 1390 | - if(empty($conjunction)) { |
|
| 1390 | + if (empty($conjunction)) { |
|
| 1391 | 1391 | $conjunction = t('and'); |
| 1392 | 1392 | } |
| 1393 | 1393 | |
| 1394 | 1394 | $last = array_pop($list); |
| 1395 | - if($list) { |
|
| 1396 | - return implode($sep, $list) . $conjunction . ' ' . $last; |
|
| 1395 | + if ($list) { |
|
| 1396 | + return implode($sep, $list).$conjunction.' '.$last; |
|
| 1397 | 1397 | } |
| 1398 | 1398 | |
| 1399 | 1399 | return $last; |
@@ -1412,7 +1412,7 @@ discard block |
||
| 1412 | 1412 | public static function string2array(string $string) : array |
| 1413 | 1413 | { |
| 1414 | 1414 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
| 1415 | - if($result !== false) { |
|
| 1415 | + if ($result !== false) { |
|
| 1416 | 1416 | return $result; |
| 1417 | 1417 | } |
| 1418 | 1418 | |
@@ -1427,12 +1427,12 @@ discard block |
||
| 1427 | 1427 | */ |
| 1428 | 1428 | public static function isStringHTML(string $string) : bool |
| 1429 | 1429 | { |
| 1430 | - if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
| 1430 | + if (preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
| 1431 | 1431 | return true; |
| 1432 | 1432 | } |
| 1433 | 1433 | |
| 1434 | 1434 | $decoded = html_entity_decode($string); |
| 1435 | - if($decoded !== $string) { |
|
| 1435 | + if ($decoded !== $string) { |
|
| 1436 | 1436 | return true; |
| 1437 | 1437 | } |
| 1438 | 1438 | |
@@ -1569,7 +1569,7 @@ discard block |
||
| 1569 | 1569 | // extract parameter names from the query string |
| 1570 | 1570 | $result = array(); |
| 1571 | 1571 | preg_match_all('/&?([^&]+)=.*/sixU', $queryString, $result, PREG_PATTERN_ORDER); |
| 1572 | - if(isset($result[1])) { |
|
| 1572 | + if (isset($result[1])) { |
|
| 1573 | 1573 | $paramNames = $result[1]; |
| 1574 | 1574 | } |
| 1575 | 1575 | |
@@ -1592,11 +1592,11 @@ discard block |
||
| 1592 | 1592 | // possible naming conflicts like having both parameters "foo.bar" |
| 1593 | 1593 | // and "foo_bar" in the query string: since "foo.bar" would be converted |
| 1594 | 1594 | // to "foo_bar", one of the two would be replaced. |
| 1595 | - if($fixRequired) |
|
| 1595 | + if ($fixRequired) |
|
| 1596 | 1596 | { |
| 1597 | 1597 | $counter = 1; |
| 1598 | 1598 | $placeholders = array(); |
| 1599 | - foreach($paramNames as $paramName) |
|
| 1599 | + foreach ($paramNames as $paramName) |
|
| 1600 | 1600 | { |
| 1601 | 1601 | // create a unique placeholder name |
| 1602 | 1602 | $placeholder = '__PLACEHOLDER'.$counter.'__'; |
@@ -1626,13 +1626,13 @@ discard block |
||
| 1626 | 1626 | parse_str($queryString, $parsed); |
| 1627 | 1627 | |
| 1628 | 1628 | // do any of the parameter names need to be fixed? |
| 1629 | - if(!$fixRequired) { |
|
| 1629 | + if (!$fixRequired) { |
|
| 1630 | 1630 | return $parsed; |
| 1631 | 1631 | } |
| 1632 | 1632 | |
| 1633 | 1633 | $keep = array(); |
| 1634 | 1634 | |
| 1635 | - foreach($parsed as $name => $value) |
|
| 1635 | + foreach ($parsed as $name => $value) |
|
| 1636 | 1636 | { |
| 1637 | 1637 | $keep[$table[$name]] = $value; |
| 1638 | 1638 | } |
@@ -1651,14 +1651,14 @@ discard block |
||
| 1651 | 1651 | * @param bool $caseInsensitive |
| 1652 | 1652 | * @return ConvertHelper_StringMatch[] |
| 1653 | 1653 | */ |
| 1654 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
|
| 1654 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false) |
|
| 1655 | 1655 | { |
| 1656 | - if($needle === '') { |
|
| 1656 | + if ($needle === '') { |
|
| 1657 | 1657 | return array(); |
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | $function = 'mb_strpos'; |
| 1661 | - if($caseInsensitive) { |
|
| 1661 | + if ($caseInsensitive) { |
|
| 1662 | 1662 | $function = 'mb_stripos'; |
| 1663 | 1663 | } |
| 1664 | 1664 | |
@@ -1666,7 +1666,7 @@ discard block |
||
| 1666 | 1666 | $positions = array(); |
| 1667 | 1667 | $length = mb_strlen($needle); |
| 1668 | 1668 | |
| 1669 | - while( ($pos = $function($haystack, $needle, $pos)) !== false) |
|
| 1669 | + while (($pos = $function($haystack, $needle, $pos)) !== false) |
|
| 1670 | 1670 | { |
| 1671 | 1671 | $match = mb_substr($haystack, $pos, $length); |
| 1672 | 1672 | $positions[] = new ConvertHelper_StringMatch($pos, $match); |
@@ -1686,7 +1686,7 @@ discard block |
||
| 1686 | 1686 | */ |
| 1687 | 1687 | public static function explodeTrim(string $delimiter, string $string) : array |
| 1688 | 1688 | { |
| 1689 | - if(empty($string) || empty($delimiter)) { |
|
| 1689 | + if (empty($string) || empty($delimiter)) { |
|
| 1690 | 1690 | return array(); |
| 1691 | 1691 | } |
| 1692 | 1692 | |
@@ -1694,8 +1694,8 @@ discard block |
||
| 1694 | 1694 | $tokens = array_map('trim', $tokens); |
| 1695 | 1695 | |
| 1696 | 1696 | $keep = array(); |
| 1697 | - foreach($tokens as $token) { |
|
| 1698 | - if($token !== '') { |
|
| 1697 | + foreach ($tokens as $token) { |
|
| 1698 | + if ($token !== '') { |
|
| 1699 | 1699 | $keep[] = $token; |
| 1700 | 1700 | } |
| 1701 | 1701 | } |
@@ -1713,11 +1713,11 @@ discard block |
||
| 1713 | 1713 | */ |
| 1714 | 1714 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
| 1715 | 1715 | { |
| 1716 | - if(empty($subjectString)) { |
|
| 1716 | + if (empty($subjectString)) { |
|
| 1717 | 1717 | return null; |
| 1718 | 1718 | } |
| 1719 | 1719 | |
| 1720 | - if(!isset(self::$eolChars)) |
|
| 1720 | + if (!isset(self::$eolChars)) |
|
| 1721 | 1721 | { |
| 1722 | 1722 | $cr = chr((int)hexdec('0d')); |
| 1723 | 1723 | $lf = chr((int)hexdec('0a')); |
@@ -1748,18 +1748,18 @@ discard block |
||
| 1748 | 1748 | |
| 1749 | 1749 | $max = 0; |
| 1750 | 1750 | $results = array(); |
| 1751 | - foreach(self::$eolChars as $def) |
|
| 1751 | + foreach (self::$eolChars as $def) |
|
| 1752 | 1752 | { |
| 1753 | 1753 | $amount = substr_count($subjectString, $def['char']); |
| 1754 | 1754 | |
| 1755 | - if($amount > $max) |
|
| 1755 | + if ($amount > $max) |
|
| 1756 | 1756 | { |
| 1757 | 1757 | $max = $amount; |
| 1758 | 1758 | $results[] = $def; |
| 1759 | 1759 | } |
| 1760 | 1760 | } |
| 1761 | 1761 | |
| 1762 | - if(empty($results)) { |
|
| 1762 | + if (empty($results)) { |
|
| 1763 | 1763 | return null; |
| 1764 | 1764 | } |
| 1765 | 1765 | |
@@ -1779,9 +1779,9 @@ discard block |
||
| 1779 | 1779 | */ |
| 1780 | 1780 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
| 1781 | 1781 | { |
| 1782 | - foreach($keys as $key) |
|
| 1782 | + foreach ($keys as $key) |
|
| 1783 | 1783 | { |
| 1784 | - if(array_key_exists($key, $array)) { |
|
| 1784 | + if (array_key_exists($key, $array)) { |
|
| 1785 | 1785 | unset($array[$key]); |
| 1786 | 1786 | } |
| 1787 | 1787 | } |
@@ -1794,11 +1794,11 @@ discard block |
||
| 1794 | 1794 | */ |
| 1795 | 1795 | public static function isInteger($value) : bool |
| 1796 | 1796 | { |
| 1797 | - if(is_int($value)) { |
|
| 1797 | + if (is_int($value)) { |
|
| 1798 | 1798 | return true; |
| 1799 | 1799 | } |
| 1800 | 1800 | |
| 1801 | - if(is_string($value)) { |
|
| 1801 | + if (is_string($value)) { |
|
| 1802 | 1802 | return preg_match('/\A\d+\z/', $value); |
| 1803 | 1803 | } |
| 1804 | 1804 | |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | */ |
| 114 | 114 | public function getNextPage() : int |
| 115 | 115 | { |
| 116 | - if($this->next === 0) { |
|
| 116 | + if ($this->next === 0) { |
|
| 117 | 117 | return $this->last; |
| 118 | 118 | } |
| 119 | 119 | |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | */ |
| 138 | 138 | public function getPreviousPage() : int |
| 139 | 139 | { |
| 140 | - if($this->prev === 0) { |
|
| 140 | + if ($this->prev === 0) { |
|
| 141 | 141 | return 1; |
| 142 | 142 | } |
| 143 | 143 | |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | // adjust the adjacent value if it exceeds the |
| 183 | 183 | // total amount of pages |
| 184 | 184 | $adjacentTotal = ($adjacent * 2) + 1; |
| 185 | - if($adjacentTotal > $this->last) |
|
| 185 | + if ($adjacentTotal > $this->last) |
|
| 186 | 186 | { |
| 187 | 187 | $adjacent = (int)floor($this->last / 2); |
| 188 | 188 | } |
@@ -195,13 +195,13 @@ discard block |
||
| 195 | 195 | $back = 0; |
| 196 | 196 | $fwd = 0; |
| 197 | 197 | |
| 198 | - if($maxBack >= $adjacent) { |
|
| 198 | + if ($maxBack >= $adjacent) { |
|
| 199 | 199 | $back = $adjacent; |
| 200 | 200 | } else { |
| 201 | 201 | $back = $maxBack; |
| 202 | 202 | } |
| 203 | 203 | |
| 204 | - if($maxFwd >= $adjacent) { |
|
| 204 | + if ($maxFwd >= $adjacent) { |
|
| 205 | 205 | $fwd = $adjacent; |
| 206 | 206 | } else { |
| 207 | 207 | $fwd = $maxFwd; |
@@ -217,16 +217,16 @@ discard block |
||
| 217 | 217 | $fwd += $backDiff; |
| 218 | 218 | $back += $fwdDiff; |
| 219 | 219 | |
| 220 | - if($fwd > $maxFwd) { $fwd = $maxFwd; } |
|
| 221 | - if($back > $maxBack) { $back = $maxBack; } |
|
| 220 | + if ($fwd > $maxFwd) { $fwd = $maxFwd; } |
|
| 221 | + if ($back > $maxBack) { $back = $maxBack; } |
|
| 222 | 222 | |
| 223 | 223 | // calculate the first and last page in the list |
| 224 | 224 | $prev = $this->current - $back; |
| 225 | 225 | $next = $this->current + $fwd; |
| 226 | 226 | |
| 227 | 227 | // failsafe so we stay within the bounds |
| 228 | - if($prev < 1) { $prev = 1; } |
|
| 229 | - if($next > $this->last) { $next = $this->last; } |
|
| 228 | + if ($prev < 1) { $prev = 1; } |
|
| 229 | + if ($next > $this->last) { $next = $this->last; } |
|
| 230 | 230 | |
| 231 | 231 | // create and return the page numbers list |
| 232 | 232 | $numbers = range($prev, $next); |
@@ -319,11 +319,11 @@ discard block |
||
| 319 | 319 | { |
| 320 | 320 | $pages = (int)ceil($this->total / $this->perPage); |
| 321 | 321 | |
| 322 | - if($this->current < 1) |
|
| 322 | + if ($this->current < 1) |
|
| 323 | 323 | { |
| 324 | 324 | $this->current = 1; |
| 325 | 325 | } |
| 326 | - else if($this->current > $pages) |
|
| 326 | + else if ($this->current > $pages) |
|
| 327 | 327 | { |
| 328 | 328 | $this->current = $pages; |
| 329 | 329 | } |
@@ -331,19 +331,19 @@ discard block |
||
| 331 | 331 | $this->last = $pages; |
| 332 | 332 | |
| 333 | 333 | $nextPage = $this->current + 1; |
| 334 | - if($nextPage <= $pages) { |
|
| 334 | + if ($nextPage <= $pages) { |
|
| 335 | 335 | $this->next = $nextPage; |
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | $prevPage = $this->current - 1; |
| 339 | - if($prevPage > 0) { |
|
| 339 | + if ($prevPage > 0) { |
|
| 340 | 340 | $this->prev = $prevPage; |
| 341 | 341 | } |
| 342 | 342 | |
| 343 | 343 | $this->offsetStart = ($this->current - 1) * $this->perPage; |
| 344 | 344 | |
| 345 | 345 | $this->offsetEnd = $this->offsetStart + $this->perPage; |
| 346 | - if($this->offsetEnd > ($this->total - 1)) { |
|
| 346 | + if ($this->offsetEnd > ($this->total - 1)) { |
|
| 347 | 347 | $this->offsetEnd = ($this->total - 1); |
| 348 | 348 | } |
| 349 | 349 | } |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | return $this->buildURL($params, $dispatcher); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * Retrieves the name of the current dispatcher script / page. |
|
| 113 | - * This is made to be extended and implemented in a subclass. |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 111 | + /** |
|
| 112 | + * Retrieves the name of the current dispatcher script / page. |
|
| 113 | + * This is made to be extended and implemented in a subclass. |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | 117 | public function getDispatcher() : string |
| 118 | 118 | { |
| 119 | 119 | return ''; |
@@ -200,13 +200,13 @@ discard block |
||
| 200 | 200 | return $this->knownParams[$name]; |
| 201 | 201 | } |
| 202 | 202 | |
| 203 | - /** |
|
| 204 | - * Retrieves a previously registered parameter instance. |
|
| 205 | - * |
|
| 206 | - * @param string $name |
|
| 207 | - * @throws Request_Exception |
|
| 208 | - * @return Request_Param |
|
| 209 | - */ |
|
| 203 | + /** |
|
| 204 | + * Retrieves a previously registered parameter instance. |
|
| 205 | + * |
|
| 206 | + * @param string $name |
|
| 207 | + * @throws Request_Exception |
|
| 208 | + * @return Request_Param |
|
| 209 | + */ |
|
| 210 | 210 | public function getRegisteredParam(string $name) : Request_Param |
| 211 | 211 | { |
| 212 | 212 | if(isset($this->knownParams[$name])) { |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | ); |
| 224 | 224 | } |
| 225 | 225 | |
| 226 | - /** |
|
| 227 | - * Checks whether a parameter with the specified name |
|
| 228 | - * has been registered. |
|
| 229 | - * |
|
| 230 | - * @param string $name |
|
| 231 | - * @return bool |
|
| 232 | - */ |
|
| 226 | + /** |
|
| 227 | + * Checks whether a parameter with the specified name |
|
| 228 | + * has been registered. |
|
| 229 | + * |
|
| 230 | + * @param string $name |
|
| 231 | + * @return bool |
|
| 232 | + */ |
|
| 233 | 233 | public function hasRegisteredParam(string $name) : bool |
| 234 | 234 | { |
| 235 | 235 | return isset($this->knownParams[$name]); |
@@ -358,14 +358,14 @@ discard block |
||
| 358 | 358 | return false; |
| 359 | 359 | } |
| 360 | 360 | |
| 361 | - /** |
|
| 362 | - * Removes a single parameter from the request. |
|
| 363 | - * If the parameter has been registered, also |
|
| 364 | - * removes the registration info. |
|
| 365 | - * |
|
| 366 | - * @param string $name |
|
| 367 | - * @return Request |
|
| 368 | - */ |
|
| 361 | + /** |
|
| 362 | + * Removes a single parameter from the request. |
|
| 363 | + * If the parameter has been registered, also |
|
| 364 | + * removes the registration info. |
|
| 365 | + * |
|
| 366 | + * @param string $name |
|
| 367 | + * @return Request |
|
| 368 | + */ |
|
| 369 | 369 | public function removeParam(string $name) : Request |
| 370 | 370 | { |
| 371 | 371 | if(isset($_REQUEST[$name])) { |
@@ -379,12 +379,12 @@ discard block |
||
| 379 | 379 | return $this; |
| 380 | 380 | } |
| 381 | 381 | |
| 382 | - /** |
|
| 383 | - * Removes several parameters from the request. |
|
| 384 | - * |
|
| 385 | - * @param string[] $names |
|
| 386 | - * @return Request |
|
| 387 | - */ |
|
| 382 | + /** |
|
| 383 | + * Removes several parameters from the request. |
|
| 384 | + * |
|
| 385 | + * @param string[] $names |
|
| 386 | + * @return Request |
|
| 387 | + */ |
|
| 388 | 388 | public function removeParams(array $names) : Request |
| 389 | 389 | { |
| 390 | 390 | foreach($names as $name) { |
@@ -449,18 +449,18 @@ discard block |
||
| 449 | 449 | return $val; |
| 450 | 450 | } |
| 451 | 451 | |
| 452 | - /** |
|
| 453 | - * Treats the request parameter as a JSON string, and |
|
| 454 | - * if it exists and contains valid JSON, returns the |
|
| 455 | - * decoded JSON value as an array (default). |
|
| 456 | - * |
|
| 457 | - * @param string $name |
|
| 458 | - * @param bool $assoc |
|
| 459 | - * @return array|object |
|
| 460 | - * |
|
| 461 | - * @see Request::getJSONAssoc() |
|
| 462 | - * @see Request::getJSONObject() |
|
| 463 | - */ |
|
| 452 | + /** |
|
| 453 | + * Treats the request parameter as a JSON string, and |
|
| 454 | + * if it exists and contains valid JSON, returns the |
|
| 455 | + * decoded JSON value as an array (default). |
|
| 456 | + * |
|
| 457 | + * @param string $name |
|
| 458 | + * @param bool $assoc |
|
| 459 | + * @return array|object |
|
| 460 | + * |
|
| 461 | + * @see Request::getJSONAssoc() |
|
| 462 | + * @see Request::getJSONObject() |
|
| 463 | + */ |
|
| 464 | 464 | public function getJSON(string $name, bool $assoc=true) |
| 465 | 465 | { |
| 466 | 466 | $value = $this->getParam($name); |
@@ -485,13 +485,13 @@ discard block |
||
| 485 | 485 | return new \stdClass(); |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - /** |
|
| 489 | - * Like {@link Request::getJSON()}, but omitting the second |
|
| 490 | - * parameter. Use this for more readable code. |
|
| 491 | - * |
|
| 492 | - * @param string $name |
|
| 493 | - * @return array |
|
| 494 | - */ |
|
| 488 | + /** |
|
| 489 | + * Like {@link Request::getJSON()}, but omitting the second |
|
| 490 | + * parameter. Use this for more readable code. |
|
| 491 | + * |
|
| 492 | + * @param string $name |
|
| 493 | + * @return array |
|
| 494 | + */ |
|
| 495 | 495 | public function getJSONAssoc(string $name) : array |
| 496 | 496 | { |
| 497 | 497 | $result = $this->getJSON($name); |
@@ -502,13 +502,13 @@ discard block |
||
| 502 | 502 | return array(); |
| 503 | 503 | } |
| 504 | 504 | |
| 505 | - /** |
|
| 506 | - * Like {@link Request::getJSON()}, but omitting the second |
|
| 507 | - * parameter. Use this for more readable code. |
|
| 508 | - * |
|
| 509 | - * @param string $name |
|
| 510 | - * @return object |
|
| 511 | - */ |
|
| 505 | + /** |
|
| 506 | + * Like {@link Request::getJSON()}, but omitting the second |
|
| 507 | + * parameter. Use this for more readable code. |
|
| 508 | + * |
|
| 509 | + * @param string $name |
|
| 510 | + * @return object |
|
| 511 | + */ |
|
| 512 | 512 | public function getJSONObject(string $name) : object |
| 513 | 513 | { |
| 514 | 514 | $result = $this->getJSON($name, false); |
@@ -519,12 +519,12 @@ discard block |
||
| 519 | 519 | return new \stdClass(); |
| 520 | 520 | } |
| 521 | 521 | |
| 522 | - /** |
|
| 523 | - * Sends a JSON response with the correct headers. |
|
| 524 | - * |
|
| 525 | - * @param array|string $data |
|
| 526 | - * @param bool $exit Whether to exit the script afterwards. |
|
| 527 | - */ |
|
| 522 | + /** |
|
| 523 | + * Sends a JSON response with the correct headers. |
|
| 524 | + * |
|
| 525 | + * @param array|string $data |
|
| 526 | + * @param bool $exit Whether to exit the script afterwards. |
|
| 527 | + */ |
|
| 528 | 528 | public static function sendJSON($data, bool $exit=true) |
| 529 | 529 | { |
| 530 | 530 | $payload = $data; |
@@ -544,12 +544,12 @@ discard block |
||
| 544 | 544 | } |
| 545 | 545 | } |
| 546 | 546 | |
| 547 | - /** |
|
| 548 | - * Sends HTML to the browser with the correct headers. |
|
| 549 | - * |
|
| 550 | - * @param string $html |
|
| 551 | - * @param bool $exit Whether to exit the script afterwards. |
|
| 552 | - */ |
|
| 547 | + /** |
|
| 548 | + * Sends HTML to the browser with the correct headers. |
|
| 549 | + * |
|
| 550 | + * @param string $html |
|
| 551 | + * @param bool $exit Whether to exit the script afterwards. |
|
| 552 | + */ |
|
| 553 | 553 | public static function sendHTML(string $html, bool $exit=true) |
| 554 | 554 | { |
| 555 | 555 | header('Cache-Control: no-cache, must-revalidate'); |
@@ -564,16 +564,16 @@ discard block |
||
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | |
| 567 | - /** |
|
| 568 | - * Creates a new instance of the URL comparer, which can check |
|
| 569 | - * whether the specified URLs match, regardless of the order in |
|
| 570 | - * which the query parameters are, if any. |
|
| 571 | - * |
|
| 572 | - * @param string $sourceURL |
|
| 573 | - * @param string $targetURL |
|
| 574 | - * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 575 | - * @return Request_URLComparer |
|
| 576 | - */ |
|
| 567 | + /** |
|
| 568 | + * Creates a new instance of the URL comparer, which can check |
|
| 569 | + * whether the specified URLs match, regardless of the order in |
|
| 570 | + * which the query parameters are, if any. |
|
| 571 | + * |
|
| 572 | + * @param string $sourceURL |
|
| 573 | + * @param string $targetURL |
|
| 574 | + * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
|
| 575 | + * @return Request_URLComparer |
|
| 576 | + */ |
|
| 577 | 577 | public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
| 578 | 578 | { |
| 579 | 579 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
@@ -582,10 +582,10 @@ discard block |
||
| 582 | 582 | return $comparer; |
| 583 | 583 | } |
| 584 | 584 | |
| 585 | - /** |
|
| 586 | - * Retrieves the full URL that was used to access the current page. |
|
| 587 | - * @return string |
|
| 588 | - */ |
|
| 585 | + /** |
|
| 586 | + * Retrieves the full URL that was used to access the current page. |
|
| 587 | + * @return string |
|
| 588 | + */ |
|
| 589 | 589 | public function getCurrentURL() : string |
| 590 | 590 | { |
| 591 | 591 | return $_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; |
@@ -74,11 +74,11 @@ discard block |
||
| 74 | 74 | public function getParam($name, $default = null) |
| 75 | 75 | { |
| 76 | 76 | $value = $default; |
| 77 | - if(isset($_REQUEST[$name])) { |
|
| 77 | + if (isset($_REQUEST[$name])) { |
|
| 78 | 78 | $value = $_REQUEST[$name]; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | - if(isset($this->knownParams[$name])) { |
|
| 81 | + if (isset($this->knownParams[$name])) { |
|
| 82 | 82 | $value = $this->knownParams[$name]->validate($value); |
| 83 | 83 | } |
| 84 | 84 | |
@@ -121,8 +121,8 @@ discard block |
||
| 121 | 121 | |
| 122 | 122 | public function getRefreshParams($params = array(), $exclude = array()) |
| 123 | 123 | { |
| 124 | - if(empty($params)) { $params = array(); } |
|
| 125 | - if(empty($exclude)) { $exclude = array(); } |
|
| 124 | + if (empty($params)) { $params = array(); } |
|
| 125 | + if (empty($exclude)) { $exclude = array(); } |
|
| 126 | 126 | |
| 127 | 127 | $vars = $_REQUEST; |
| 128 | 128 | |
@@ -142,8 +142,8 @@ discard block |
||
| 142 | 142 | // remove the quickform form variable if present, to |
| 143 | 143 | // avoid redirect loops when using the refresh URL in |
| 144 | 144 | // a page in which a form has been submitted. |
| 145 | - foreach($names as $name) { |
|
| 146 | - if(strstr($name, '_qf__')) { |
|
| 145 | + foreach ($names as $name) { |
|
| 146 | + if (strstr($name, '_qf__')) { |
|
| 147 | 147 | unset($vars[$name]); |
| 148 | 148 | break; |
| 149 | 149 | } |
@@ -170,13 +170,13 @@ discard block |
||
| 170 | 170 | * @param string $dispatcher Relative path to script to use for the URL. Append trailing slash if needed. |
| 171 | 171 | * @return string |
| 172 | 172 | */ |
| 173 | - public function buildURL($params = array(), string $dispatcher='') |
|
| 173 | + public function buildURL($params = array(), string $dispatcher = '') |
|
| 174 | 174 | { |
| 175 | - $url = rtrim(APP_URL, '/') . '/' . $dispatcher; |
|
| 175 | + $url = rtrim(APP_URL, '/').'/'.$dispatcher; |
|
| 176 | 176 | |
| 177 | 177 | // append any leftover parameters to the end of the URL |
| 178 | 178 | if (!empty($params)) { |
| 179 | - $url .= '?' . http_build_query($params, null, '&'); |
|
| 179 | + $url .= '?'.http_build_query($params, null, '&'); |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | return $url; |
@@ -192,7 +192,7 @@ discard block |
||
| 192 | 192 | */ |
| 193 | 193 | public function registerParam($name) |
| 194 | 194 | { |
| 195 | - if(!isset($this->knownParams[$name])) { |
|
| 195 | + if (!isset($this->knownParams[$name])) { |
|
| 196 | 196 | $param = new Request_Param($this, $name); |
| 197 | 197 | $this->knownParams[$name] = $param; |
| 198 | 198 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function getRegisteredParam(string $name) : Request_Param |
| 211 | 211 | { |
| 212 | - if(isset($this->knownParams[$name])) { |
|
| 212 | + if (isset($this->knownParams[$name])) { |
|
| 213 | 213 | return $this->knownParams[$name]; |
| 214 | 214 | } |
| 215 | 215 | |
@@ -276,12 +276,12 @@ discard block |
||
| 276 | 276 | { |
| 277 | 277 | $entry['type'] = $matches[1]; |
| 278 | 278 | |
| 279 | - if(isset($matches[2]) && !empty($matches[2])) |
|
| 279 | + if (isset($matches[2]) && !empty($matches[2])) |
|
| 280 | 280 | { |
| 281 | 281 | $params = ConvertHelper::parseQueryString($matches[2]); |
| 282 | 282 | $entry['params'] = $params; |
| 283 | 283 | |
| 284 | - if(isset($params['q'])) { |
|
| 284 | + if (isset($params['q'])) { |
|
| 285 | 285 | $entry['quality'] = (double)$params['q']; |
| 286 | 286 | } |
| 287 | 287 | } |
@@ -334,7 +334,7 @@ discard block |
||
| 334 | 334 | { |
| 335 | 335 | $_REQUEST[$name] = $value; |
| 336 | 336 | |
| 337 | - if(isset($this->knownParams[$name])) { |
|
| 337 | + if (isset($this->knownParams[$name])) { |
|
| 338 | 338 | unset($this->knownParams[$name]); |
| 339 | 339 | } |
| 340 | 340 | |
@@ -368,11 +368,11 @@ discard block |
||
| 368 | 368 | */ |
| 369 | 369 | public function removeParam(string $name) : Request |
| 370 | 370 | { |
| 371 | - if(isset($_REQUEST[$name])) { |
|
| 371 | + if (isset($_REQUEST[$name])) { |
|
| 372 | 372 | unset($_REQUEST[$name]); |
| 373 | 373 | } |
| 374 | 374 | |
| 375 | - if(isset($this->knownParams[$name])) { |
|
| 375 | + if (isset($this->knownParams[$name])) { |
|
| 376 | 376 | unset($this->knownParams[$name]); |
| 377 | 377 | } |
| 378 | 378 | |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | */ |
| 388 | 388 | public function removeParams(array $names) : Request |
| 389 | 389 | { |
| 390 | - foreach($names as $name) { |
|
| 390 | + foreach ($names as $name) { |
|
| 391 | 391 | $this->removeParam($name); |
| 392 | 392 | } |
| 393 | 393 | |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | * @param string $name |
| 404 | 404 | * @return bool |
| 405 | 405 | */ |
| 406 | - public function getBool($name, $default=false) |
|
| 406 | + public function getBool($name, $default = false) |
|
| 407 | 407 | { |
| 408 | 408 | $value = $this->getParam($name, $default); |
| 409 | - if(ConvertHelper::isBoolean($value)) { |
|
| 409 | + if (ConvertHelper::isBoolean($value)) { |
|
| 410 | 410 | return ConvertHelper::string2bool($value); |
| 411 | 411 | } |
| 412 | 412 | |
@@ -415,9 +415,9 @@ discard block |
||
| 415 | 415 | |
| 416 | 416 | public function validate() |
| 417 | 417 | { |
| 418 | - foreach($this->knownParams as $param) { |
|
| 418 | + foreach ($this->knownParams as $param) { |
|
| 419 | 419 | $name = $param->getName(); |
| 420 | - if($param->isRequired() && !$this->hasParam($name)) { |
|
| 420 | + if ($param->isRequired() && !$this->hasParam($name)) { |
|
| 421 | 421 | throw new Request_Exception( |
| 422 | 422 | 'Missing request parameter '.$name, |
| 423 | 423 | sprintf( |
@@ -439,10 +439,10 @@ discard block |
||
| 439 | 439 | * @param mixed $default |
| 440 | 440 | * @return string |
| 441 | 441 | */ |
| 442 | - public function getFilteredParam($name, $default=null) |
|
| 442 | + public function getFilteredParam($name, $default = null) |
|
| 443 | 443 | { |
| 444 | 444 | $val = $this->getParam($name, $default); |
| 445 | - if(is_string($val)) { |
|
| 445 | + if (is_string($val)) { |
|
| 446 | 446 | $val = htmlspecialchars(trim(strip_tags($val)), ENT_QUOTES, 'UTF-8'); |
| 447 | 447 | } |
| 448 | 448 | |
@@ -461,24 +461,24 @@ discard block |
||
| 461 | 461 | * @see Request::getJSONAssoc() |
| 462 | 462 | * @see Request::getJSONObject() |
| 463 | 463 | */ |
| 464 | - public function getJSON(string $name, bool $assoc=true) |
|
| 464 | + public function getJSON(string $name, bool $assoc = true) |
|
| 465 | 465 | { |
| 466 | 466 | $value = $this->getParam($name); |
| 467 | 467 | |
| 468 | - if(!empty($value) && is_string($value)) |
|
| 468 | + if (!empty($value) && is_string($value)) |
|
| 469 | 469 | { |
| 470 | 470 | $data = json_decode($value, $assoc); |
| 471 | 471 | |
| 472 | - if($assoc && is_array($data)) { |
|
| 472 | + if ($assoc && is_array($data)) { |
|
| 473 | 473 | return $data; |
| 474 | 474 | } |
| 475 | 475 | |
| 476 | - if(is_object($data)) { |
|
| 476 | + if (is_object($data)) { |
|
| 477 | 477 | return $data; |
| 478 | 478 | } |
| 479 | 479 | } |
| 480 | 480 | |
| 481 | - if($assoc) { |
|
| 481 | + if ($assoc) { |
|
| 482 | 482 | return array(); |
| 483 | 483 | } |
| 484 | 484 | |
@@ -495,7 +495,7 @@ discard block |
||
| 495 | 495 | public function getJSONAssoc(string $name) : array |
| 496 | 496 | { |
| 497 | 497 | $result = $this->getJSON($name); |
| 498 | - if(is_array($result)) { |
|
| 498 | + if (is_array($result)) { |
|
| 499 | 499 | return $result; |
| 500 | 500 | } |
| 501 | 501 | |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | public function getJSONObject(string $name) : object |
| 513 | 513 | { |
| 514 | 514 | $result = $this->getJSON($name, false); |
| 515 | - if(is_object($result)) { |
|
| 515 | + if (is_object($result)) { |
|
| 516 | 516 | return $result; |
| 517 | 517 | } |
| 518 | 518 | |
@@ -525,10 +525,10 @@ discard block |
||
| 525 | 525 | * @param array|string $data |
| 526 | 526 | * @param bool $exit Whether to exit the script afterwards. |
| 527 | 527 | */ |
| 528 | - public static function sendJSON($data, bool $exit=true) |
|
| 528 | + public static function sendJSON($data, bool $exit = true) |
|
| 529 | 529 | { |
| 530 | 530 | $payload = $data; |
| 531 | - if(!is_string($payload)) { |
|
| 531 | + if (!is_string($payload)) { |
|
| 532 | 532 | $payload = json_encode($payload); |
| 533 | 533 | } |
| 534 | 534 | |
@@ -538,7 +538,7 @@ discard block |
||
| 538 | 538 | |
| 539 | 539 | echo $payload; |
| 540 | 540 | |
| 541 | - if($exit) |
|
| 541 | + if ($exit) |
|
| 542 | 542 | { |
| 543 | 543 | exit; |
| 544 | 544 | } |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | * @param string $html |
| 551 | 551 | * @param bool $exit Whether to exit the script afterwards. |
| 552 | 552 | */ |
| 553 | - public static function sendHTML(string $html, bool $exit=true) |
|
| 553 | + public static function sendHTML(string $html, bool $exit = true) |
|
| 554 | 554 | { |
| 555 | 555 | header('Cache-Control: no-cache, must-revalidate'); |
| 556 | 556 | header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | |
| 559 | 559 | echo $html; |
| 560 | 560 | |
| 561 | - if($exit) |
|
| 561 | + if ($exit) |
|
| 562 | 562 | { |
| 563 | 563 | exit; |
| 564 | 564 | } |
@@ -574,7 +574,7 @@ discard block |
||
| 574 | 574 | * @param array $limitParams Whether to limit the comparison to these specific parameter names (if present) |
| 575 | 575 | * @return Request_URLComparer |
| 576 | 576 | */ |
| 577 | - public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams=array()) : Request_URLComparer |
|
| 577 | + public function createURLComparer(string $sourceURL, string $targetURL, array $limitParams = array()) : Request_URLComparer |
|
| 578 | 578 | { |
| 579 | 579 | $comparer = new Request_URLComparer($this, $sourceURL, $targetURL); |
| 580 | 580 | $comparer->addLimitParams($limitParams); |
@@ -14,49 +14,49 @@ discard block |
||
| 14 | 14 | const CONTEXT_COMMAND_LINE = 'cli'; |
| 15 | 15 | const CONTEXT_WEB = 'web'; |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * @var \Throwable |
|
| 19 | - */ |
|
| 17 | + /** |
|
| 18 | + * @var \Throwable |
|
| 19 | + */ |
|
| 20 | 20 | protected $exception; |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * @var ConvertHelper_ThrowableInfo_Call[] |
|
| 24 | - */ |
|
| 22 | + /** |
|
| 23 | + * @var ConvertHelper_ThrowableInfo_Call[] |
|
| 24 | + */ |
|
| 25 | 25 | protected $calls = array(); |
| 26 | 26 | |
| 27 | - /** |
|
| 28 | - * @var integer |
|
| 29 | - */ |
|
| 27 | + /** |
|
| 28 | + * @var integer |
|
| 29 | + */ |
|
| 30 | 30 | protected $code; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $message; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var integer |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var integer |
|
| 39 | + */ |
|
| 40 | 40 | protected $callsCount = 0; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var ConvertHelper_ThrowableInfo |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var ConvertHelper_ThrowableInfo |
|
| 44 | + */ |
|
| 45 | 45 | protected $previous; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var string |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var string |
|
| 49 | + */ |
|
| 50 | 50 | protected $referer = ''; |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * @var \DateTime |
|
| 54 | - */ |
|
| 52 | + /** |
|
| 53 | + * @var \DateTime |
|
| 54 | + */ |
|
| 55 | 55 | protected $date; |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @var string |
|
| 59 | - */ |
|
| 57 | + /** |
|
| 58 | + * @var string |
|
| 59 | + */ |
|
| 60 | 60 | protected $context = self::CONTEXT_WEB; |
| 61 | 61 | |
| 62 | 62 | protected function __construct($subject) |
@@ -103,16 +103,16 @@ discard block |
||
| 103 | 103 | return isset($this->previous); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Retrieves the information on the previous exception. |
|
| 108 | - * |
|
| 109 | - * NOTE: Throws an exception if there is no previous |
|
| 110 | - * exception. Use hasPrevious() first to avoid this. |
|
| 111 | - * |
|
| 112 | - * @throws ConvertHelper_Exception |
|
| 113 | - * @return ConvertHelper_ThrowableInfo |
|
| 114 | - * @see ConvertHelper_ThrowableInfo::ERROR_NO_PREVIOUS_EXCEPTION |
|
| 115 | - */ |
|
| 106 | + /** |
|
| 107 | + * Retrieves the information on the previous exception. |
|
| 108 | + * |
|
| 109 | + * NOTE: Throws an exception if there is no previous |
|
| 110 | + * exception. Use hasPrevious() first to avoid this. |
|
| 111 | + * |
|
| 112 | + * @throws ConvertHelper_Exception |
|
| 113 | + * @return ConvertHelper_ThrowableInfo |
|
| 114 | + * @see ConvertHelper_ThrowableInfo::ERROR_NO_PREVIOUS_EXCEPTION |
|
| 115 | + */ |
|
| 116 | 116 | public function getPrevious() : ConvertHelper_ThrowableInfo |
| 117 | 117 | { |
| 118 | 118 | if(isset($this->previous)) { |
@@ -131,9 +131,9 @@ discard block |
||
| 131 | 131 | return !empty($this->code); |
| 132 | 132 | } |
| 133 | 133 | |
| 134 | - /** |
|
| 135 | - * Improved textonly exception trace. |
|
| 136 | - */ |
|
| 134 | + /** |
|
| 135 | + * Improved textonly exception trace. |
|
| 136 | + */ |
|
| 137 | 137 | public function toString() : string |
| 138 | 138 | { |
| 139 | 139 | $calls = $this->getCalls(); |
@@ -161,73 +161,73 @@ discard block |
||
| 161 | 161 | return $string; |
| 162 | 162 | } |
| 163 | 163 | |
| 164 | - /** |
|
| 165 | - * Retrieves the URL of the page in which the exception |
|
| 166 | - * was thrown, if applicable: in CLI context, this will |
|
| 167 | - * return an empty string. |
|
| 168 | - * |
|
| 169 | - * @return string |
|
| 170 | - */ |
|
| 164 | + /** |
|
| 165 | + * Retrieves the URL of the page in which the exception |
|
| 166 | + * was thrown, if applicable: in CLI context, this will |
|
| 167 | + * return an empty string. |
|
| 168 | + * |
|
| 169 | + * @return string |
|
| 170 | + */ |
|
| 171 | 171 | public function getReferer() : string |
| 172 | 172 | { |
| 173 | 173 | return $this->referer; |
| 174 | 174 | } |
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Whether the exception occurred in a command line context. |
|
| 178 | - * @return bool |
|
| 179 | - */ |
|
| 176 | + /** |
|
| 177 | + * Whether the exception occurred in a command line context. |
|
| 178 | + * @return bool |
|
| 179 | + */ |
|
| 180 | 180 | public function isCommandLine() : bool |
| 181 | 181 | { |
| 182 | 182 | return $this->getContext() === self::CONTEXT_COMMAND_LINE; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - /** |
|
| 186 | - * Whether the exception occurred during an http request. |
|
| 187 | - * @return bool |
|
| 188 | - */ |
|
| 185 | + /** |
|
| 186 | + * Whether the exception occurred during an http request. |
|
| 187 | + * @return bool |
|
| 188 | + */ |
|
| 189 | 189 | public function isWebRequest() : bool |
| 190 | 190 | { |
| 191 | 191 | return $this->getContext() === self::CONTEXT_WEB; |
| 192 | 192 | } |
| 193 | 193 | |
| 194 | - /** |
|
| 195 | - * Retrieves the context identifier, i.e. if the exception |
|
| 196 | - * occurred in a command line context or regular web request. |
|
| 197 | - * |
|
| 198 | - * @return string |
|
| 199 | - * |
|
| 200 | - * @see ConvertHelper_ThrowableInfo::isCommandLine() |
|
| 201 | - * @see ConvertHelper_ThrowableInfo::isWebRequest() |
|
| 202 | - * @see ConvertHelper_ThrowableInfo::CONTEXT_COMMAND_LINE |
|
| 203 | - * @see ConvertHelper_ThrowableInfo::CONTEXT_WEB |
|
| 204 | - */ |
|
| 194 | + /** |
|
| 195 | + * Retrieves the context identifier, i.e. if the exception |
|
| 196 | + * occurred in a command line context or regular web request. |
|
| 197 | + * |
|
| 198 | + * @return string |
|
| 199 | + * |
|
| 200 | + * @see ConvertHelper_ThrowableInfo::isCommandLine() |
|
| 201 | + * @see ConvertHelper_ThrowableInfo::isWebRequest() |
|
| 202 | + * @see ConvertHelper_ThrowableInfo::CONTEXT_COMMAND_LINE |
|
| 203 | + * @see ConvertHelper_ThrowableInfo::CONTEXT_WEB |
|
| 204 | + */ |
|
| 205 | 205 | public function getContext() : string |
| 206 | 206 | { |
| 207 | 207 | return $this->context; |
| 208 | 208 | } |
| 209 | 209 | |
| 210 | - /** |
|
| 211 | - * Retrieves the date of the exception, and approximate time: |
|
| 212 | - * since exceptions do not store time, this is captured the |
|
| 213 | - * moment the ThrowableInfo is created. |
|
| 214 | - * |
|
| 215 | - * @return \DateTime |
|
| 216 | - */ |
|
| 210 | + /** |
|
| 211 | + * Retrieves the date of the exception, and approximate time: |
|
| 212 | + * since exceptions do not store time, this is captured the |
|
| 213 | + * moment the ThrowableInfo is created. |
|
| 214 | + * |
|
| 215 | + * @return \DateTime |
|
| 216 | + */ |
|
| 217 | 217 | public function getDate() : \DateTime |
| 218 | 218 | { |
| 219 | 219 | return $this->date; |
| 220 | 220 | } |
| 221 | 221 | |
| 222 | - /** |
|
| 223 | - * Serializes all information on the exception to an |
|
| 224 | - * associative array. This can be saved (file, database, |
|
| 225 | - * session...), and later be restored into a throwable |
|
| 226 | - * info instance using the fromSerialized() method. |
|
| 227 | - * |
|
| 228 | - * @return array |
|
| 229 | - * @see ConvertHelper_ThrowableInfo::fromSerialized() |
|
| 230 | - */ |
|
| 222 | + /** |
|
| 223 | + * Serializes all information on the exception to an |
|
| 224 | + * associative array. This can be saved (file, database, |
|
| 225 | + * session...), and later be restored into a throwable |
|
| 226 | + * info instance using the fromSerialized() method. |
|
| 227 | + * |
|
| 228 | + * @return array |
|
| 229 | + * @see ConvertHelper_ThrowableInfo::fromSerialized() |
|
| 230 | + */ |
|
| 231 | 231 | public function serialize() : array |
| 232 | 232 | { |
| 233 | 233 | $result = array( |
@@ -254,24 +254,24 @@ discard block |
||
| 254 | 254 | return $result; |
| 255 | 255 | } |
| 256 | 256 | |
| 257 | - /** |
|
| 258 | - * Sets the maximum folder depth to show in the |
|
| 259 | - * file paths, to avoid them being too long. |
|
| 260 | - * |
|
| 261 | - * @param int $depth |
|
| 262 | - * @return ConvertHelper_ThrowableInfo |
|
| 263 | - */ |
|
| 257 | + /** |
|
| 258 | + * Sets the maximum folder depth to show in the |
|
| 259 | + * file paths, to avoid them being too long. |
|
| 260 | + * |
|
| 261 | + * @param int $depth |
|
| 262 | + * @return ConvertHelper_ThrowableInfo |
|
| 263 | + */ |
|
| 264 | 264 | public function setFolderDepth(int $depth) : ConvertHelper_ThrowableInfo |
| 265 | 265 | { |
| 266 | 266 | return $this->setOption('folder-depth', $depth); |
| 267 | 267 | } |
| 268 | 268 | |
| 269 | - /** |
|
| 270 | - * Retrieves the current folder depth option value. |
|
| 271 | - * |
|
| 272 | - * @return int |
|
| 273 | - * @see ConvertHelper_ThrowableInfo::setFolderDepth() |
|
| 274 | - */ |
|
| 269 | + /** |
|
| 270 | + * Retrieves the current folder depth option value. |
|
| 271 | + * |
|
| 272 | + * @return int |
|
| 273 | + * @see ConvertHelper_ThrowableInfo::setFolderDepth() |
|
| 274 | + */ |
|
| 275 | 275 | public function getFolderDepth() : int |
| 276 | 276 | { |
| 277 | 277 | $depth = $this->getOption('folder-depth'); |
@@ -282,19 +282,19 @@ discard block |
||
| 282 | 282 | return 2; |
| 283 | 283 | } |
| 284 | 284 | |
| 285 | - /** |
|
| 286 | - * Retrieves all function calls that led to the error. |
|
| 287 | - * @return ConvertHelper_ThrowableInfo_Call[] |
|
| 288 | - */ |
|
| 285 | + /** |
|
| 286 | + * Retrieves all function calls that led to the error. |
|
| 287 | + * @return ConvertHelper_ThrowableInfo_Call[] |
|
| 288 | + */ |
|
| 289 | 289 | public function getCalls() |
| 290 | 290 | { |
| 291 | 291 | return $this->calls; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - /** |
|
| 295 | - * Returns the amount of function and method calls in the stack trace. |
|
| 296 | - * @return int |
|
| 297 | - */ |
|
| 294 | + /** |
|
| 295 | + * Returns the amount of function and method calls in the stack trace. |
|
| 296 | + * @return int |
|
| 297 | + */ |
|
| 298 | 298 | public function countCalls() : int |
| 299 | 299 | { |
| 300 | 300 | return $this->callsCount; |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | |
| 62 | 62 | protected function __construct($subject) |
| 63 | 63 | { |
| 64 | - if(is_array($subject)) |
|
| 64 | + if (is_array($subject)) |
|
| 65 | 65 | { |
| 66 | 66 | $this->parseSerialized($subject); |
| 67 | 67 | } |
@@ -115,7 +115,7 @@ discard block |
||
| 115 | 115 | */ |
| 116 | 116 | public function getPrevious() : ConvertHelper_ThrowableInfo |
| 117 | 117 | { |
| 118 | - if(isset($this->previous)) { |
|
| 118 | + if (isset($this->previous)) { |
|
| 119 | 119 | return $this->previous; |
| 120 | 120 | } |
| 121 | 121 | |
@@ -140,18 +140,18 @@ discard block |
||
| 140 | 140 | |
| 141 | 141 | $string = 'Exception'; |
| 142 | 142 | |
| 143 | - if($this->hasCode()) { |
|
| 143 | + if ($this->hasCode()) { |
|
| 144 | 144 | $string .= ' #'.$this->code; |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | 147 | $string .= ': '.$this->getMessage().PHP_EOL; |
| 148 | 148 | |
| 149 | - foreach($calls as $call) |
|
| 149 | + foreach ($calls as $call) |
|
| 150 | 150 | { |
| 151 | 151 | $string .= $call->toString().PHP_EOL; |
| 152 | 152 | } |
| 153 | 153 | |
| 154 | - if($this->hasPrevious()) |
|
| 154 | + if ($this->hasPrevious()) |
|
| 155 | 155 | { |
| 156 | 156 | $string .= PHP_EOL.PHP_EOL. |
| 157 | 157 | 'Previous error:'.PHP_EOL.PHP_EOL. |
@@ -242,11 +242,11 @@ discard block |
||
| 242 | 242 | 'previous' => null, |
| 243 | 243 | ); |
| 244 | 244 | |
| 245 | - if($this->hasPrevious()) { |
|
| 246 | - $result['previous'] = $this->previous->serialize(); |
|
| 245 | + if ($this->hasPrevious()) { |
|
| 246 | + $result['previous'] = $this->previous->serialize(); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | - foreach($this->calls as $call) |
|
| 249 | + foreach ($this->calls as $call) |
|
| 250 | 250 | { |
| 251 | 251 | $result['calls'][] = $call->serialize(); |
| 252 | 252 | } |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | public function getFolderDepth() : int |
| 276 | 276 | { |
| 277 | 277 | $depth = $this->getOption('folder-depth'); |
| 278 | - if(!empty($depth)) { |
|
| 278 | + if (!empty($depth)) { |
|
| 279 | 279 | return $depth; |
| 280 | 280 | } |
| 281 | 281 | |
@@ -311,12 +311,12 @@ discard block |
||
| 311 | 311 | |
| 312 | 312 | $this->setOptions($serialized['options']); |
| 313 | 313 | |
| 314 | - if(!empty($serialized['previous'])) |
|
| 314 | + if (!empty($serialized['previous'])) |
|
| 315 | 315 | { |
| 316 | 316 | $this->previous = ConvertHelper_ThrowableInfo::fromSerialized($serialized['previous']); |
| 317 | 317 | } |
| 318 | 318 | |
| 319 | - foreach($serialized['calls'] as $def) |
|
| 319 | + foreach ($serialized['calls'] as $def) |
|
| 320 | 320 | { |
| 321 | 321 | $this->calls[] = ConvertHelper_ThrowableInfo_Call::fromSerialized($this, $def); |
| 322 | 322 | } |
@@ -328,16 +328,16 @@ discard block |
||
| 328 | 328 | $this->message = $e->getMessage(); |
| 329 | 329 | $this->code = intval($e->getCode()); |
| 330 | 330 | |
| 331 | - if(!isset($_REQUEST) || !isset($_REQUEST['REQUEST_URI'])) { |
|
| 331 | + if (!isset($_REQUEST) || !isset($_REQUEST['REQUEST_URI'])) { |
|
| 332 | 332 | $this->context = self::CONTEXT_COMMAND_LINE; |
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | $previous = $e->getPrevious(); |
| 336 | - if(!empty($previous)) { |
|
| 336 | + if (!empty($previous)) { |
|
| 337 | 337 | $this->previous = ConvertHelper::throwable2info($previous); |
| 338 | 338 | } |
| 339 | 339 | |
| 340 | - if(isset($_SERVER) && isset($_SERVER['REQUEST_URI'])) { |
|
| 340 | + if (isset($_SERVER) && isset($_SERVER['REQUEST_URI'])) { |
|
| 341 | 341 | $this->referer = $_SERVER['REQUEST_URI']; |
| 342 | 342 | } |
| 343 | 343 | |
@@ -351,7 +351,7 @@ discard block |
||
| 351 | 351 | |
| 352 | 352 | $idx = 1; |
| 353 | 353 | |
| 354 | - foreach($trace as $entry) |
|
| 354 | + foreach ($trace as $entry) |
|
| 355 | 355 | { |
| 356 | 356 | $this->calls[] = ConvertHelper_ThrowableInfo_Call::fromTrace($this, $idx, $entry); |
| 357 | 357 | |
@@ -29,19 +29,19 @@ discard block |
||
| 29 | 29 | const TYPE_LF = 'LF'; |
| 30 | 30 | const TYPE_CR = 'CR'; |
| 31 | 31 | |
| 32 | - /** |
|
| 33 | - * @var string |
|
| 34 | - */ |
|
| 32 | + /** |
|
| 33 | + * @var string |
|
| 34 | + */ |
|
| 35 | 35 | protected $char; |
| 36 | 36 | |
| 37 | - /** |
|
| 38 | - * @var string |
|
| 39 | - */ |
|
| 37 | + /** |
|
| 38 | + * @var string |
|
| 39 | + */ |
|
| 40 | 40 | protected $type; |
| 41 | 41 | |
| 42 | - /** |
|
| 43 | - * @var string |
|
| 44 | - */ |
|
| 42 | + /** |
|
| 43 | + * @var string |
|
| 44 | + */ |
|
| 45 | 45 | protected $description; |
| 46 | 46 | |
| 47 | 47 | public function __construct(string $char, string $type, string $description) |
@@ -51,33 +51,33 @@ discard block |
||
| 51 | 51 | $this->description = $description; |
| 52 | 52 | } |
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * The actual EOL character. |
|
| 56 | - * @return string |
|
| 57 | - */ |
|
| 54 | + /** |
|
| 55 | + * The actual EOL character. |
|
| 56 | + * @return string |
|
| 57 | + */ |
|
| 58 | 58 | public function getCharacter() : string |
| 59 | 59 | { |
| 60 | 60 | return $this->char; |
| 61 | 61 | } |
| 62 | 62 | |
| 63 | - /** |
|
| 64 | - * A more detailed, human readable description of the character. |
|
| 65 | - * @return string |
|
| 66 | - */ |
|
| 63 | + /** |
|
| 64 | + * A more detailed, human readable description of the character. |
|
| 65 | + * @return string |
|
| 66 | + */ |
|
| 67 | 67 | public function getDescription() : string |
| 68 | 68 | { |
| 69 | 69 | return $this->description; |
| 70 | 70 | } |
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * The EOL character type, e.g. "CR+LF", "CR"... |
|
| 74 | - * @return string |
|
| 75 | - * |
|
| 76 | - * @see ConvertHelper_EOL::TYPE_CR |
|
| 77 | - * @see ConvertHelper_EOL::TYPE_CRLF |
|
| 78 | - * @see ConvertHelper_EOL::TYPE_LF |
|
| 79 | - * @see ConvertHelper_EOL::TYPE_LFCR |
|
| 80 | - */ |
|
| 72 | + /** |
|
| 73 | + * The EOL character type, e.g. "CR+LF", "CR"... |
|
| 74 | + * @return string |
|
| 75 | + * |
|
| 76 | + * @see ConvertHelper_EOL::TYPE_CR |
|
| 77 | + * @see ConvertHelper_EOL::TYPE_CRLF |
|
| 78 | + * @see ConvertHelper_EOL::TYPE_LF |
|
| 79 | + * @see ConvertHelper_EOL::TYPE_LFCR |
|
| 80 | + */ |
|
| 81 | 81 | public function getType() : string |
| 82 | 82 | { |
| 83 | 83 | return $this->type; |
@@ -32,25 +32,25 @@ discard block |
||
| 32 | 32 | self::TYPE_CALLABLE => 'cf5e20' |
| 33 | 33 | ); |
| 34 | 34 | |
| 35 | - /** |
|
| 36 | - * @var string |
|
| 37 | - */ |
|
| 35 | + /** |
|
| 36 | + * @var string |
|
| 37 | + */ |
|
| 38 | 38 | protected $string; |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @var mixed |
|
| 42 | - */ |
|
| 40 | + /** |
|
| 41 | + * @var mixed |
|
| 42 | + */ |
|
| 43 | 43 | protected $value; |
| 44 | 44 | |
| 45 | - /** |
|
| 46 | - * @var string |
|
| 47 | - */ |
|
| 45 | + /** |
|
| 46 | + * @var string |
|
| 47 | + */ |
|
| 48 | 48 | protected $type; |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param mixed $value |
|
| 52 | - * @param array|null $serialized |
|
| 53 | - */ |
|
| 50 | + /** |
|
| 51 | + * @param mixed $value |
|
| 52 | + * @param array|null $serialized |
|
| 53 | + */ |
|
| 54 | 54 | public function __construct($value, $serialized=null) |
| 55 | 55 | { |
| 56 | 56 | if(is_array($serialized)) |
@@ -63,26 +63,26 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - /** |
|
| 67 | - * Creates a new variable info instance from a PHP variable |
|
| 68 | - * of any type. |
|
| 69 | - * |
|
| 70 | - * @param mixed $variable |
|
| 71 | - * @return VariableInfo |
|
| 72 | - */ |
|
| 66 | + /** |
|
| 67 | + * Creates a new variable info instance from a PHP variable |
|
| 68 | + * of any type. |
|
| 69 | + * |
|
| 70 | + * @param mixed $variable |
|
| 71 | + * @return VariableInfo |
|
| 72 | + */ |
|
| 73 | 73 | public static function fromVariable($variable) : VariableInfo |
| 74 | 74 | { |
| 75 | 75 | return new VariableInfo($variable); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Restores a variable info instance using a previously serialized |
|
| 80 | - * array using the serialize() method. |
|
| 81 | - * |
|
| 82 | - * @param array $serialized |
|
| 83 | - * @return VariableInfo |
|
| 84 | - * @see VariableInfo::serialize() |
|
| 85 | - */ |
|
| 78 | + /** |
|
| 79 | + * Restores a variable info instance using a previously serialized |
|
| 80 | + * array using the serialize() method. |
|
| 81 | + * |
|
| 82 | + * @param array $serialized |
|
| 83 | + * @return VariableInfo |
|
| 84 | + * @see VariableInfo::serialize() |
|
| 85 | + */ |
|
| 86 | 86 | public static function fromSerialized(array $serialized) : VariableInfo |
| 87 | 87 | { |
| 88 | 88 | return new VariableInfo(null, $serialized); |
@@ -108,12 +108,12 @@ discard block |
||
| 108 | 108 | $this->string = $this->_toString(); |
| 109 | 109 | } |
| 110 | 110 | |
| 111 | - /** |
|
| 112 | - * The variable type - this is the same string that |
|
| 113 | - * is returned by the PHP function `gettype`. |
|
| 114 | - * |
|
| 115 | - * @return string |
|
| 116 | - */ |
|
| 111 | + /** |
|
| 112 | + * The variable type - this is the same string that |
|
| 113 | + * is returned by the PHP function `gettype`. |
|
| 114 | + * |
|
| 115 | + * @return string |
|
| 116 | + */ |
|
| 117 | 117 | public function getType() : string |
| 118 | 118 | { |
| 119 | 119 | return $this->type; |
@@ -127,13 +127,13 @@ discard block |
||
| 127 | 127 | ); |
| 128 | 128 | } |
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Whether to prepend the variable type before the value, |
|
| 132 | - * like the var_dump function. Example: <code>string "Some text"</code>. |
|
| 133 | - * |
|
| 134 | - * @param bool $enable |
|
| 135 | - * @return VariableInfo |
|
| 136 | - */ |
|
| 130 | + /** |
|
| 131 | + * Whether to prepend the variable type before the value, |
|
| 132 | + * like the var_dump function. Example: <code>string "Some text"</code>. |
|
| 133 | + * |
|
| 134 | + * @param bool $enable |
|
| 135 | + * @return VariableInfo |
|
| 136 | + */ |
|
| 137 | 137 | public function enableType(bool $enable=true) : VariableInfo |
| 138 | 138 | { |
| 139 | 139 | return $this->setOption('prepend-type', $enable); |
@@ -51,9 +51,9 @@ discard block |
||
| 51 | 51 | * @param mixed $value |
| 52 | 52 | * @param array|null $serialized |
| 53 | 53 | */ |
| 54 | - public function __construct($value, $serialized=null) |
|
| 54 | + public function __construct($value, $serialized = null) |
|
| 55 | 55 | { |
| 56 | - if(is_array($serialized)) |
|
| 56 | + if (is_array($serialized)) |
|
| 57 | 57 | { |
| 58 | 58 | $this->parseSerialized($serialized); |
| 59 | 59 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $this->value = $value; |
| 102 | 102 | $this->type = strtolower(gettype($value)); |
| 103 | 103 | |
| 104 | - if(is_array($value) && is_callable($value)) { |
|
| 104 | + if (is_array($value) && is_callable($value)) { |
|
| 105 | 105 | $this->type = self::TYPE_CALLABLE; |
| 106 | 106 | } |
| 107 | 107 | |
@@ -134,7 +134,7 @@ discard block |
||
| 134 | 134 | * @param bool $enable |
| 135 | 135 | * @return VariableInfo |
| 136 | 136 | */ |
| 137 | - public function enableType(bool $enable=true) : VariableInfo |
|
| 137 | + public function enableType(bool $enable = true) : VariableInfo |
|
| 138 | 138 | { |
| 139 | 139 | return $this->setOption('prepend-type', $enable); |
| 140 | 140 | } |
@@ -143,9 +143,9 @@ discard block |
||
| 143 | 143 | { |
| 144 | 144 | $converted = $this->string; |
| 145 | 145 | |
| 146 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 146 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 147 | 147 | { |
| 148 | - if($this->isString()) |
|
| 148 | + if ($this->isString()) |
|
| 149 | 149 | { |
| 150 | 150 | $converted = '"'.$converted.'"'; |
| 151 | 151 | } |
@@ -177,16 +177,16 @@ discard block |
||
| 177 | 177 | |
| 178 | 178 | $converted = $this->$varMethod(); |
| 179 | 179 | |
| 180 | - if($format === 'HTML') |
|
| 180 | + if ($format === 'HTML') |
|
| 181 | 181 | { |
| 182 | 182 | $converted = '<span style="color:#'.self::$colors[$type].'" class="variable-value-'.$this->type.'">'.$converted.'</span>'; |
| 183 | 183 | } |
| 184 | 184 | |
| 185 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 185 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 186 | 186 | { |
| 187 | 187 | $typeLabel = $type; |
| 188 | 188 | |
| 189 | - switch($format) |
|
| 189 | + switch ($format) |
|
| 190 | 190 | { |
| 191 | 191 | case 'HTML': |
| 192 | 192 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$type.'</span> '; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | { |
| 213 | 213 | $string = ''; |
| 214 | 214 | |
| 215 | - if(is_string($this->value[0])) { |
|
| 215 | + if (is_string($this->value[0])) { |
|
| 216 | 216 | $string .= $this->value[0].'::'; |
| 217 | 217 | } else { |
| 218 | 218 | $string .= get_class($this->value[0]).'->'; |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | str_replace(' ', '-', $this->type) |
| 340 | 340 | ); |
| 341 | 341 | |
| 342 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 342 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
| 343 | 343 | { |
| 344 | 344 | $typeLabel = '<span style="color:#1c2eb1" class="variable-type">'.$this->type.'</span> '; |
| 345 | 345 | $converted = $typeLabel.' '.$converted; |
@@ -31,9 +31,9 @@ |
||
| 31 | 31 | |
| 32 | 32 | const PATH_MODE_STRIP = 'strip'; |
| 33 | 33 | |
| 34 | - /** |
|
| 35 | - * @var string |
|
| 36 | - */ |
|
| 34 | + /** |
|
| 35 | + * @var string |
|
| 36 | + */ |
|
| 37 | 37 | protected $path; |
| 38 | 38 | |
| 39 | 39 | public function __construct(string $path) |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | * @see FileHelper_FileFinder |
| 8 | 8 | */ |
| 9 | 9 | |
| 10 | -declare(strict_types = 1); |
|
| 10 | +declare(strict_types=1); |
|
| 11 | 11 | |
| 12 | 12 | namespace AppUtils; |
| 13 | 13 | |
@@ -125,7 +125,7 @@ discard block |
||
| 125 | 125 | |
| 126 | 126 | public function getAll() : array |
| 127 | 127 | { |
| 128 | - if(!isset($this->found)) { |
|
| 128 | + if (!isset($this->found)) { |
|
| 129 | 129 | $this->find($this->path, true); |
| 130 | 130 | } |
| 131 | 131 | |
@@ -150,25 +150,25 @@ discard block |
||
| 150 | 150 | |
| 151 | 151 | protected $found; |
| 152 | 152 | |
| 153 | - protected function find($path, $isRoot=false) |
|
| 153 | + protected function find($path, $isRoot = false) |
|
| 154 | 154 | { |
| 155 | - if($isRoot) { |
|
| 155 | + if ($isRoot) { |
|
| 156 | 156 | $this->found = array(); |
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | $d = new \DirectoryIterator($path); |
| 160 | - foreach($d as $item) |
|
| 160 | + foreach ($d as $item) |
|
| 161 | 161 | { |
| 162 | - if($item->isDir()) |
|
| 162 | + if ($item->isDir()) |
|
| 163 | 163 | { |
| 164 | - if($this->getOption('recursive') === true && !$item->isDot()) { |
|
| 164 | + if ($this->getOption('recursive') === true && !$item->isDot()) { |
|
| 165 | 165 | $this->find($item->getPathname()); |
| 166 | 166 | } |
| 167 | 167 | } |
| 168 | 168 | else |
| 169 | 169 | { |
| 170 | 170 | $file = $this->filterFile($item->getPathname()); |
| 171 | - if($file) { |
|
| 171 | + if ($file) { |
|
| 172 | 172 | $this->found[] = $file; |
| 173 | 173 | } |
| 174 | 174 | } |
@@ -184,20 +184,20 @@ discard block |
||
| 184 | 184 | $include = $this->getOption('include-extensions'); |
| 185 | 185 | $exclude = $this->getOption('exclude-extensions'); |
| 186 | 186 | |
| 187 | - if(!empty($include)) |
|
| 187 | + if (!empty($include)) |
|
| 188 | 188 | { |
| 189 | - if(!in_array($info['extension'], $include)) { |
|
| 189 | + if (!in_array($info['extension'], $include)) { |
|
| 190 | 190 | return false; |
| 191 | 191 | } |
| 192 | 192 | } |
| 193 | - else if(!empty($exclude)) |
|
| 193 | + else if (!empty($exclude)) |
|
| 194 | 194 | { |
| 195 | - if(in_array($info['extension'], $exclude)) { |
|
| 195 | + if (in_array($info['extension'], $exclude)) { |
|
| 196 | 196 | return false; |
| 197 | 197 | } |
| 198 | 198 | } |
| 199 | 199 | |
| 200 | - switch($this->getOption('pathmode')) |
|
| 200 | + switch ($this->getOption('pathmode')) |
|
| 201 | 201 | { |
| 202 | 202 | case self::PATH_MODE_STRIP: |
| 203 | 203 | $path = basename($path); |
@@ -213,13 +213,13 @@ discard block |
||
| 213 | 213 | break; |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | - if($this->getOption('strip-extensions') === true) |
|
| 216 | + if ($this->getOption('strip-extensions') === true) |
|
| 217 | 217 | { |
| 218 | 218 | $path = str_replace('.'.$info['extension'], '', $path); |
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | $replace = $this->getOption('slash-replacement'); |
| 222 | - if(!empty($replace)) { |
|
| 222 | + if (!empty($replace)) { |
|
| 223 | 223 | $path = str_replace('/', $replace, $path); |
| 224 | 224 | } |
| 225 | 225 | |