@@ -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 | |
@@ -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 | } |
@@ -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 | } |
@@ -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); |
@@ -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 | |
@@ -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; |
@@ -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 | |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @param int $code |
| 32 | 32 | * @param \Exception $previous |
| 33 | 33 | */ |
| 34 | - public function __construct(string $message, $details=null, $code=null, $previous=null) |
|
| 34 | + public function __construct(string $message, $details = null, $code = null, $previous = null) |
|
| 35 | 35 | { |
| 36 | 36 | parent::__construct($message, $code, $previous); |
| 37 | 37 | |
@@ -44,7 +44,7 @@ discard block |
||
| 44 | 44 | */ |
| 45 | 45 | public function getDetails() : string |
| 46 | 46 | { |
| 47 | - if($this->details !== null) { |
|
| 47 | + if ($this->details !== null) { |
|
| 48 | 48 | return $this->details; |
| 49 | 49 | } |
| 50 | 50 | |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | */ |
| 58 | 58 | public function display() |
| 59 | 59 | { |
| 60 | - if(!headers_sent()) { |
|
| 60 | + if (!headers_sent()) { |
|
| 61 | 61 | header('Content-type:text/plain; charset=utf-8'); |
| 62 | 62 | } |
| 63 | 63 | |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | { |
| 86 | 86 | throw new BaseException(''); |
| 87 | 87 | } |
| 88 | - catch(BaseException $e) |
|
| 88 | + catch (BaseException $e) |
|
| 89 | 89 | { |
| 90 | 90 | echo self::createInfo($e)->toString(); |
| 91 | 91 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | { |
| 101 | 101 | throw new BaseException(''); |
| 102 | 102 | } |
| 103 | - catch(BaseException $e) |
|
| 103 | + catch (BaseException $e) |
|
| 104 | 104 | { |
| 105 | 105 | echo '<pre style="background:#fff;font-family:monospace;font-size:14px;color:#444;padding:16px;border:solid 1px #999;border-radius:4px;">'; |
| 106 | 106 | echo self::createInfo($e)->toString(); |