@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | |
83 | 83 | $contents = file_get_contents($file); |
84 | 84 | |
85 | - if($contents === false) |
|
85 | + if ($contents === false) |
|
86 | 86 | { |
87 | 87 | throw new FileHelper_Exception( |
88 | 88 | 'Cannot load serialized content from file.', |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | |
97 | 97 | $result = @unserialize($contents); |
98 | 98 | |
99 | - if($result !== false) { |
|
99 | + if ($result !== false) { |
|
100 | 100 | return $result; |
101 | 101 | } |
102 | 102 | |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | |
113 | 113 | public static function deleteTree($rootFolder) |
114 | 114 | { |
115 | - if(!file_exists($rootFolder)) { |
|
115 | + if (!file_exists($rootFolder)) { |
|
116 | 116 | return true; |
117 | 117 | } |
118 | 118 | |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | */ |
154 | 154 | public static function createFolder($path) |
155 | 155 | { |
156 | - if(is_dir($path) || mkdir($path, 0777, true)) { |
|
156 | + if (is_dir($path) || mkdir($path, 0777, true)) { |
|
157 | 157 | return; |
158 | 158 | } |
159 | 159 | |
@@ -188,11 +188,11 @@ discard block |
||
188 | 188 | |
189 | 189 | if ($item->isDir()) |
190 | 190 | { |
191 | - FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target . '/' . $baseName); |
|
191 | + FileHelper::copyTree(str_replace('\\', '/', $itemPath), $target.'/'.$baseName); |
|
192 | 192 | } |
193 | - else if($item->isFile()) |
|
193 | + else if ($item->isFile()) |
|
194 | 194 | { |
195 | - self::copyFile($itemPath, $target . '/' . $baseName); |
|
195 | + self::copyFile($itemPath, $target.'/'.$baseName); |
|
196 | 196 | } |
197 | 197 | } |
198 | 198 | } |
@@ -217,7 +217,7 @@ discard block |
||
217 | 217 | { |
218 | 218 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
219 | 219 | |
220 | - if(!is_readable($sourcePath)) |
|
220 | + if (!is_readable($sourcePath)) |
|
221 | 221 | { |
222 | 222 | throw new FileHelper_Exception( |
223 | 223 | sprintf('Source file [%s] to copy is not readable.', basename($sourcePath)), |
@@ -231,11 +231,11 @@ discard block |
||
231 | 231 | |
232 | 232 | $targetFolder = dirname($targetPath); |
233 | 233 | |
234 | - if(!file_exists($targetFolder)) |
|
234 | + if (!file_exists($targetFolder)) |
|
235 | 235 | { |
236 | 236 | self::createFolder($targetFolder); |
237 | 237 | } |
238 | - else if(!is_writable($targetFolder)) |
|
238 | + else if (!is_writable($targetFolder)) |
|
239 | 239 | { |
240 | 240 | throw new FileHelper_Exception( |
241 | 241 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | ); |
248 | 248 | } |
249 | 249 | |
250 | - if(copy($sourcePath, $targetPath)) { |
|
250 | + if (copy($sourcePath, $targetPath)) { |
|
251 | 251 | return; |
252 | 252 | } |
253 | 253 | |
@@ -274,11 +274,11 @@ discard block |
||
274 | 274 | */ |
275 | 275 | public static function deleteFile(string $filePath) : void |
276 | 276 | { |
277 | - if(!file_exists($filePath)) { |
|
277 | + if (!file_exists($filePath)) { |
|
278 | 278 | return; |
279 | 279 | } |
280 | 280 | |
281 | - if(unlink($filePath)) { |
|
281 | + if (unlink($filePath)) { |
|
282 | 282 | return; |
283 | 283 | } |
284 | 284 | |
@@ -302,10 +302,10 @@ discard block |
||
302 | 302 | * @return \parseCSV |
303 | 303 | * @todo Move this to the CSV helper. |
304 | 304 | */ |
305 | - public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : \parseCSV |
|
305 | + public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : \parseCSV |
|
306 | 306 | { |
307 | - if($delimiter==='') { $delimiter = ';'; } |
|
308 | - if($enclosure==='') { $enclosure = '"'; } |
|
307 | + if ($delimiter === '') { $delimiter = ';'; } |
|
308 | + if ($enclosure === '') { $enclosure = '"'; } |
|
309 | 309 | |
310 | 310 | $parser = new \parseCSV(null, null, null, array()); |
311 | 311 | |
@@ -333,11 +333,11 @@ discard block |
||
333 | 333 | * @see parseCSVFile() |
334 | 334 | * @see FileHelper::ERROR_PARSING_CSV |
335 | 335 | */ |
336 | - public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
336 | + public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
337 | 337 | { |
338 | 338 | $parser = self::createCSVParser($delimiter, $enclosure, $escape, $heading); |
339 | 339 | $result = $parser->parse_string(/** @scrutinizer ignore-type */ $csv); |
340 | - if(is_array($result)) { |
|
340 | + if (is_array($result)) { |
|
341 | 341 | return $result; |
342 | 342 | } |
343 | 343 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
367 | 367 | * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
368 | 368 | */ |
369 | - public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
369 | + public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
370 | 370 | { |
371 | 371 | $content = self::readContents($filePath); |
372 | 372 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | public static function detectMimeType(string $fileName) : ?string |
384 | 384 | { |
385 | 385 | $ext = self::getExtension($fileName); |
386 | - if(empty($ext)) { |
|
386 | + if (empty($ext)) { |
|
387 | 387 | return null; |
388 | 388 | } |
389 | 389 | |
@@ -404,11 +404,11 @@ discard block |
||
404 | 404 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
405 | 405 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
406 | 406 | */ |
407 | - public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true) |
|
407 | + public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true) |
|
408 | 408 | { |
409 | 409 | self::requireFileExists($filePath); |
410 | 410 | |
411 | - if(empty($fileName)) { |
|
411 | + if (empty($fileName)) { |
|
412 | 412 | $fileName = basename($filePath); |
413 | 413 | } |
414 | 414 | |
@@ -426,10 +426,10 @@ discard block |
||
426 | 426 | |
427 | 427 | header("Cache-Control: public", true); |
428 | 428 | header("Content-Description: File Transfer", true); |
429 | - header("Content-Type: " . $mime, true); |
|
429 | + header("Content-Type: ".$mime, true); |
|
430 | 430 | |
431 | 431 | $disposition = 'inline'; |
432 | - if($asAttachment) { |
|
432 | + if ($asAttachment) { |
|
433 | 433 | $disposition = 'attachment'; |
434 | 434 | } |
435 | 435 | |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | requireCURL(); |
458 | 458 | |
459 | 459 | $ch = curl_init(); |
460 | - if(!is_resource($ch)) |
|
460 | + if (!is_resource($ch)) |
|
461 | 461 | { |
462 | 462 | throw new FileHelper_Exception( |
463 | 463 | 'Could not initialize a new cURL instance.', |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | |
479 | 479 | $output = curl_exec($ch); |
480 | 480 | |
481 | - if($output === false) { |
|
481 | + if ($output === false) { |
|
482 | 482 | throw new FileHelper_Exception( |
483 | 483 | 'Unable to open URL', |
484 | 484 | sprintf( |
@@ -492,7 +492,7 @@ discard block |
||
492 | 492 | |
493 | 493 | curl_close($ch); |
494 | 494 | |
495 | - if(is_string($output)) |
|
495 | + if (is_string($output)) |
|
496 | 496 | { |
497 | 497 | return $output; |
498 | 498 | } |
@@ -514,7 +514,7 @@ discard block |
||
514 | 514 | */ |
515 | 515 | public static function isPHPFile($pathOrDirIterator) |
516 | 516 | { |
517 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
517 | + if (self::getExtension($pathOrDirIterator) == 'php') { |
|
518 | 518 | return true; |
519 | 519 | } |
520 | 520 | |
@@ -531,14 +531,14 @@ discard block |
||
531 | 531 | */ |
532 | 532 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
533 | 533 | { |
534 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
534 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
535 | 535 | $filename = $pathOrDirIterator->getFilename(); |
536 | 536 | } else { |
537 | 537 | $filename = basename($pathOrDirIterator); |
538 | 538 | } |
539 | 539 | |
540 | 540 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
541 | - if($lowercase) { |
|
541 | + if ($lowercase) { |
|
542 | 542 | $ext = mb_strtolower($ext); |
543 | 543 | } |
544 | 544 | |
@@ -560,13 +560,13 @@ discard block |
||
560 | 560 | public static function getFilename($pathOrDirIterator, $extension = true) |
561 | 561 | { |
562 | 562 | $path = $pathOrDirIterator; |
563 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
563 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
564 | 564 | $path = $pathOrDirIterator->getFilename(); |
565 | 565 | } |
566 | 566 | |
567 | 567 | $path = self::normalizePath($path); |
568 | 568 | |
569 | - if(!$extension) { |
|
569 | + if (!$extension) { |
|
570 | 570 | return pathinfo($path, PATHINFO_FILENAME); |
571 | 571 | } |
572 | 572 | |
@@ -584,12 +584,12 @@ discard block |
||
584 | 584 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
585 | 585 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
586 | 586 | */ |
587 | - public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
|
587 | + public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null) |
|
588 | 588 | { |
589 | 589 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
590 | 590 | |
591 | 591 | $content = file_get_contents($file); |
592 | - if(!$content) { |
|
592 | + if (!$content) { |
|
593 | 593 | throw new FileHelper_Exception( |
594 | 594 | 'Cannot get file contents', |
595 | 595 | sprintf( |
@@ -600,12 +600,12 @@ discard block |
||
600 | 600 | ); |
601 | 601 | } |
602 | 602 | |
603 | - if(isset($targetEncoding)) { |
|
603 | + if (isset($targetEncoding)) { |
|
604 | 604 | $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding); |
605 | 605 | } |
606 | 606 | |
607 | 607 | $json = json_decode($content, true); |
608 | - if($json === false || $json === NULL) { |
|
608 | + if ($json === false || $json === NULL) { |
|
609 | 609 | throw new FileHelper_Exception( |
610 | 610 | 'Cannot decode json data', |
611 | 611 | sprintf( |
@@ -645,13 +645,13 @@ discard block |
||
645 | 645 | |
646 | 646 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
647 | 647 | |
648 | - while(strstr($name, ' ')) { |
|
648 | + while (strstr($name, ' ')) { |
|
649 | 649 | $name = str_replace(' ', ' ', $name); |
650 | 650 | } |
651 | 651 | |
652 | 652 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
653 | 653 | |
654 | - while(strstr($name, '..')) { |
|
654 | + while (strstr($name, '..')) { |
|
655 | 655 | $name = str_replace('..', '.', $name); |
656 | 656 | } |
657 | 657 | |
@@ -683,7 +683,7 @@ discard block |
||
683 | 683 | * @return array An indexed array with files. |
684 | 684 | * @see FileHelper::createFileFinder() |
685 | 685 | */ |
686 | - public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
|
686 | + public static function findHTMLFiles(string $targetFolder, array $options = array()) : array |
|
687 | 687 | { |
688 | 688 | return self::findFiles($targetFolder, array('html'), $options); |
689 | 689 | } |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | * @return array An indexed array of PHP files. |
701 | 701 | * @see FileHelper::createFileFinder() |
702 | 702 | */ |
703 | - public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
|
703 | + public static function findPHPFiles(string $targetFolder, array $options = array()) : array |
|
704 | 704 | { |
705 | 705 | return self::findFiles($targetFolder, array('php'), $options); |
706 | 706 | } |
@@ -720,22 +720,22 @@ discard block |
||
720 | 720 | * @return array |
721 | 721 | * @see FileHelper::createFileFinder() |
722 | 722 | */ |
723 | - public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
|
723 | + public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array |
|
724 | 724 | { |
725 | 725 | $finder = self::createFileFinder($targetFolder); |
726 | 726 | |
727 | 727 | $finder->setPathmodeStrip(); |
728 | 728 | |
729 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
729 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
730 | 730 | { |
731 | 731 | $finder->setPathmodeRelative(); |
732 | 732 | } |
733 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
733 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
734 | 734 | { |
735 | 735 | $finder->setPathmodeAbsolute(); |
736 | 736 | } |
737 | 737 | |
738 | - if(isset($options['strip-extension'])) |
|
738 | + if (isset($options['strip-extension'])) |
|
739 | 739 | { |
740 | 740 | $finder->stripExtensions(); |
741 | 741 | } |
@@ -753,12 +753,12 @@ discard block |
||
753 | 753 | * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
754 | 754 | * @return string |
755 | 755 | */ |
756 | - public static function removeExtension(string $filename, bool $keepPath=false) : string |
|
756 | + public static function removeExtension(string $filename, bool $keepPath = false) : string |
|
757 | 757 | { |
758 | 758 | // normalize paths to allow windows style slashes even on nix servers |
759 | 759 | $filename = self::normalizePath($filename); |
760 | 760 | |
761 | - if(!$keepPath) |
|
761 | + if (!$keepPath) |
|
762 | 762 | { |
763 | 763 | return pathinfo($filename, PATHINFO_FILENAME); |
764 | 764 | } |
@@ -791,7 +791,7 @@ discard block |
||
791 | 791 | public static function detectUTFBom(string $filename) : ?string |
792 | 792 | { |
793 | 793 | $fp = fopen($filename, 'r'); |
794 | - if($fp === false) |
|
794 | + if ($fp === false) |
|
795 | 795 | { |
796 | 796 | throw new FileHelper_Exception( |
797 | 797 | 'Cannot open file for reading', |
@@ -806,10 +806,10 @@ discard block |
||
806 | 806 | |
807 | 807 | $boms = self::getUTFBOMs(); |
808 | 808 | |
809 | - foreach($boms as $bom => $value) |
|
809 | + foreach ($boms as $bom => $value) |
|
810 | 810 | { |
811 | 811 | $length = mb_strlen($value); |
812 | - if(mb_substr($text, 0, $length) == $value) { |
|
812 | + if (mb_substr($text, 0, $length) == $value) { |
|
813 | 813 | return $bom; |
814 | 814 | } |
815 | 815 | } |
@@ -828,13 +828,13 @@ discard block |
||
828 | 828 | */ |
829 | 829 | public static function getUTFBOMs() |
830 | 830 | { |
831 | - if(!isset(self::$utfBoms)) { |
|
831 | + if (!isset(self::$utfBoms)) { |
|
832 | 832 | self::$utfBoms = array( |
833 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
834 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
835 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
836 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
837 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
833 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
834 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
835 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
836 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
837 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
838 | 838 | ); |
839 | 839 | } |
840 | 840 | |
@@ -855,7 +855,7 @@ discard block |
||
855 | 855 | $encodings = self::getKnownUnicodeEncodings(); |
856 | 856 | |
857 | 857 | $keep = array(); |
858 | - foreach($encodings as $string) |
|
858 | + foreach ($encodings as $string) |
|
859 | 859 | { |
860 | 860 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
861 | 861 | |
@@ -902,16 +902,16 @@ discard block |
||
902 | 902 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
903 | 903 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
904 | 904 | */ |
905 | - public static function saveAsJSON($data, string $file, bool $pretty=false) |
|
905 | + public static function saveAsJSON($data, string $file, bool $pretty = false) |
|
906 | 906 | { |
907 | 907 | $options = null; |
908 | - if($pretty) { |
|
908 | + if ($pretty) { |
|
909 | 909 | $options = JSON_PRETTY_PRINT; |
910 | 910 | } |
911 | 911 | |
912 | 912 | $json = json_encode($data, $options); |
913 | 913 | |
914 | - if($json===false) |
|
914 | + if ($json === false) |
|
915 | 915 | { |
916 | 916 | $errorCode = json_last_error(); |
917 | 917 | |
@@ -937,14 +937,14 @@ discard block |
||
937 | 937 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
938 | 938 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
939 | 939 | */ |
940 | - public static function saveFile(string $filePath, string $content='') : void |
|
940 | + public static function saveFile(string $filePath, string $content = '') : void |
|
941 | 941 | { |
942 | 942 | $filePath = self::normalizePath($filePath); |
943 | 943 | |
944 | 944 | // target file already exists |
945 | - if(file_exists($filePath)) |
|
945 | + if (file_exists($filePath)) |
|
946 | 946 | { |
947 | - if(!is_writable($filePath)) |
|
947 | + if (!is_writable($filePath)) |
|
948 | 948 | { |
949 | 949 | throw new FileHelper_Exception( |
950 | 950 | sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)), |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | // create the folder as needed |
965 | 965 | self::createFolder($targetFolder); |
966 | 966 | |
967 | - if(!is_writable($targetFolder)) |
|
967 | + if (!is_writable($targetFolder)) |
|
968 | 968 | { |
969 | 969 | throw new FileHelper_Exception( |
970 | 970 | sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)), |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | } |
978 | 978 | } |
979 | 979 | |
980 | - if(is_dir($filePath)) |
|
980 | + if (is_dir($filePath)) |
|
981 | 981 | { |
982 | 982 | throw new FileHelper_Exception( |
983 | 983 | sprintf('Cannot save file: the target [%s] is a directory.', basename($filePath)), |
@@ -989,7 +989,7 @@ discard block |
||
989 | 989 | ); |
990 | 990 | } |
991 | 991 | |
992 | - if(file_put_contents($filePath, $content) !== false) { |
|
992 | + if (file_put_contents($filePath, $content) !== false) { |
|
993 | 993 | return; |
994 | 994 | } |
995 | 995 | |
@@ -1027,7 +1027,7 @@ discard block |
||
1027 | 1027 | { |
1028 | 1028 | static $checked = array(); |
1029 | 1029 | |
1030 | - if(isset($checked[$command])) { |
|
1030 | + if (isset($checked[$command])) { |
|
1031 | 1031 | return $checked[$command]; |
1032 | 1032 | } |
1033 | 1033 | |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | |
1041 | 1041 | $os = strtolower(PHP_OS_FAMILY); |
1042 | 1042 | |
1043 | - if(!isset($osCommands[$os])) |
|
1043 | + if (!isset($osCommands[$os])) |
|
1044 | 1044 | { |
1045 | 1045 | throw new FileHelper_Exception( |
1046 | 1046 | 'Unsupported OS for CLI commands', |
@@ -1066,7 +1066,7 @@ discard block |
||
1066 | 1066 | $pipes |
1067 | 1067 | ); |
1068 | 1068 | |
1069 | - if($process === false) { |
|
1069 | + if ($process === false) { |
|
1070 | 1070 | $checked[$command] = false; |
1071 | 1071 | return false; |
1072 | 1072 | } |
@@ -1097,7 +1097,7 @@ discard block |
||
1097 | 1097 | */ |
1098 | 1098 | public static function checkPHPFileSyntax($path) |
1099 | 1099 | { |
1100 | - if(!self::canMakePHPCalls()) { |
|
1100 | + if (!self::canMakePHPCalls()) { |
|
1101 | 1101 | return true; |
1102 | 1102 | } |
1103 | 1103 | |
@@ -1108,7 +1108,7 @@ discard block |
||
1108 | 1108 | // when the validation is successful, the first entry |
1109 | 1109 | // in the array contains the success message. When it |
1110 | 1110 | // is invalid, the first entry is always empty. |
1111 | - if(!empty($output[0])) { |
|
1111 | + if (!empty($output[0])) { |
|
1112 | 1112 | return true; |
1113 | 1113 | } |
1114 | 1114 | |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | public static function getModifiedDate($path) |
1130 | 1130 | { |
1131 | 1131 | $time = filemtime($path); |
1132 | - if($time !== false) { |
|
1132 | + if ($time !== false) { |
|
1133 | 1133 | $date = new \DateTime(); |
1134 | 1134 | $date->setTimestamp($time); |
1135 | 1135 | return $date; |
@@ -1158,7 +1158,7 @@ discard block |
||
1158 | 1158 | */ |
1159 | 1159 | public static function getSubfolders($targetFolder, $options = array()) |
1160 | 1160 | { |
1161 | - if(!is_dir($targetFolder)) |
|
1161 | + if (!is_dir($targetFolder)) |
|
1162 | 1162 | { |
1163 | 1163 | throw new FileHelper_Exception( |
1164 | 1164 | 'Target folder does not exist', |
@@ -1182,29 +1182,29 @@ discard block |
||
1182 | 1182 | |
1183 | 1183 | $d = new \DirectoryIterator($targetFolder); |
1184 | 1184 | |
1185 | - foreach($d as $item) |
|
1185 | + foreach ($d as $item) |
|
1186 | 1186 | { |
1187 | - if($item->isDir() && !$item->isDot()) |
|
1187 | + if ($item->isDir() && !$item->isDot()) |
|
1188 | 1188 | { |
1189 | 1189 | $name = $item->getFilename(); |
1190 | 1190 | |
1191 | - if(!$options['absolute-path']) { |
|
1191 | + if (!$options['absolute-path']) { |
|
1192 | 1192 | $result[] = $name; |
1193 | 1193 | } else { |
1194 | 1194 | $result[] = $targetFolder.'/'.$name; |
1195 | 1195 | } |
1196 | 1196 | |
1197 | - if(!$options['recursive']) |
|
1197 | + if (!$options['recursive']) |
|
1198 | 1198 | { |
1199 | 1199 | continue; |
1200 | 1200 | } |
1201 | 1201 | |
1202 | 1202 | $subs = self::getSubfolders($targetFolder.'/'.$name, $options); |
1203 | - foreach($subs as $sub) |
|
1203 | + foreach ($subs as $sub) |
|
1204 | 1204 | { |
1205 | 1205 | $relative = $name.'/'.$sub; |
1206 | 1206 | |
1207 | - if(!$options['absolute-path']) { |
|
1207 | + if (!$options['absolute-path']) { |
|
1208 | 1208 | $result[] = $relative; |
1209 | 1209 | } else { |
1210 | 1210 | $result[] = $targetFolder.'/'.$relative; |
@@ -1254,7 +1254,7 @@ discard block |
||
1254 | 1254 | $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. |
1255 | 1255 | $size = floatval(preg_replace('/[^0-9\.]/', '', $size)); // Remove the non-numeric characters from the size. |
1256 | 1256 | |
1257 | - if($unit) |
|
1257 | + if ($unit) |
|
1258 | 1258 | { |
1259 | 1259 | // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. |
1260 | 1260 | return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); |
@@ -1273,7 +1273,7 @@ discard block |
||
1273 | 1273 | * @param int $depth The folder depth to reduce the path to |
1274 | 1274 | * @return string |
1275 | 1275 | */ |
1276 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
1276 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
1277 | 1277 | { |
1278 | 1278 | $path = self::normalizePath($path); |
1279 | 1279 | |
@@ -1281,17 +1281,17 @@ discard block |
||
1281 | 1281 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
1282 | 1282 | $tokens = array_values($tokens); // re-index keys |
1283 | 1283 | |
1284 | - if(empty($tokens)) { |
|
1284 | + if (empty($tokens)) { |
|
1285 | 1285 | return ''; |
1286 | 1286 | } |
1287 | 1287 | |
1288 | 1288 | // remove the drive if present |
1289 | - if(strstr($tokens[0], ':')) { |
|
1289 | + if (strstr($tokens[0], ':')) { |
|
1290 | 1290 | array_shift($tokens); |
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | // path was only the drive |
1294 | - if(count($tokens) == 0) { |
|
1294 | + if (count($tokens) == 0) { |
|
1295 | 1295 | return ''; |
1296 | 1296 | } |
1297 | 1297 | |
@@ -1300,8 +1300,8 @@ discard block |
||
1300 | 1300 | |
1301 | 1301 | // reduce the path to the specified depth |
1302 | 1302 | $length = count($tokens); |
1303 | - if($length > $depth) { |
|
1304 | - $tokens = array_slice($tokens, $length-$depth); |
|
1303 | + if ($length > $depth) { |
|
1304 | + $tokens = array_slice($tokens, $length - $depth); |
|
1305 | 1305 | } |
1306 | 1306 | |
1307 | 1307 | // append the last element again |
@@ -1349,14 +1349,14 @@ discard block |
||
1349 | 1349 | * |
1350 | 1350 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1351 | 1351 | */ |
1352 | - public static function requireFileExists(string $path, $errorCode=null) : string |
|
1352 | + public static function requireFileExists(string $path, $errorCode = null) : string |
|
1353 | 1353 | { |
1354 | 1354 | $result = realpath($path); |
1355 | - if($result !== false) { |
|
1355 | + if ($result !== false) { |
|
1356 | 1356 | return $result; |
1357 | 1357 | } |
1358 | 1358 | |
1359 | - if($errorCode === null) { |
|
1359 | + if ($errorCode === null) { |
|
1360 | 1360 | $errorCode = self::ERROR_FILE_DOES_NOT_EXIST; |
1361 | 1361 | } |
1362 | 1362 | |
@@ -1385,15 +1385,15 @@ discard block |
||
1385 | 1385 | |
1386 | 1386 | $file = new \SplFileObject($path); |
1387 | 1387 | |
1388 | - if($file->eof()) { |
|
1388 | + if ($file->eof()) { |
|
1389 | 1389 | return ''; |
1390 | 1390 | } |
1391 | 1391 | |
1392 | - $targetLine = $lineNumber-1; |
|
1392 | + $targetLine = $lineNumber - 1; |
|
1393 | 1393 | |
1394 | 1394 | $file->seek($targetLine); |
1395 | 1395 | |
1396 | - if($file->key() !== $targetLine) { |
|
1396 | + if ($file->key() !== $targetLine) { |
|
1397 | 1397 | return null; |
1398 | 1398 | } |
1399 | 1399 | |
@@ -1419,7 +1419,7 @@ discard block |
||
1419 | 1419 | $number = $spl->key(); |
1420 | 1420 | |
1421 | 1421 | // if seeking to the end the cursor is still at 0, there are no lines. |
1422 | - if($number === 0) |
|
1422 | + if ($number === 0) |
|
1423 | 1423 | { |
1424 | 1424 | // since it's a very small file, to get reliable results, |
1425 | 1425 | // we read its contents and use that to determine what |
@@ -1427,13 +1427,13 @@ discard block |
||
1427 | 1427 | // that this is not pactical to solve with the SplFileObject. |
1428 | 1428 | $content = file_get_contents($path); |
1429 | 1429 | |
1430 | - if(empty($content)) { |
|
1430 | + if (empty($content)) { |
|
1431 | 1431 | return 0; |
1432 | 1432 | } |
1433 | 1433 | } |
1434 | 1434 | |
1435 | 1435 | // return the line number we were able to reach + 1 (key is zero-based) |
1436 | - return $number+1; |
|
1436 | + return $number + 1; |
|
1437 | 1437 | } |
1438 | 1438 | |
1439 | 1439 | /** |
@@ -1480,13 +1480,13 @@ discard block |
||
1480 | 1480 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
1481 | 1481 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1482 | 1482 | */ |
1483 | - public static function readLines(string $filePath, int $amount=0) : array |
|
1483 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
1484 | 1484 | { |
1485 | 1485 | self::requireFileExists($filePath); |
1486 | 1486 | |
1487 | 1487 | $fn = fopen($filePath, "r"); |
1488 | 1488 | |
1489 | - if($fn === false) |
|
1489 | + if ($fn === false) |
|
1490 | 1490 | { |
1491 | 1491 | throw new FileHelper_Exception( |
1492 | 1492 | 'Could not open file for reading.', |
@@ -1502,19 +1502,19 @@ discard block |
||
1502 | 1502 | $counter = 0; |
1503 | 1503 | $first = true; |
1504 | 1504 | |
1505 | - while(!feof($fn)) |
|
1505 | + while (!feof($fn)) |
|
1506 | 1506 | { |
1507 | 1507 | $counter++; |
1508 | 1508 | |
1509 | 1509 | $line = fgets($fn); |
1510 | 1510 | |
1511 | 1511 | // can happen with zero length files |
1512 | - if($line === false) { |
|
1512 | + if ($line === false) { |
|
1513 | 1513 | continue; |
1514 | 1514 | } |
1515 | 1515 | |
1516 | 1516 | // the first line may contain a unicode BOM marker. |
1517 | - if($first) |
|
1517 | + if ($first) |
|
1518 | 1518 | { |
1519 | 1519 | $line = ConvertHelper::stripUTFBom($line); |
1520 | 1520 | $first = false; |
@@ -1522,7 +1522,7 @@ discard block |
||
1522 | 1522 | |
1523 | 1523 | $result[] = $line; |
1524 | 1524 | |
1525 | - if($amount > 0 && $counter == $amount) { |
|
1525 | + if ($amount > 0 && $counter == $amount) { |
|
1526 | 1526 | break; |
1527 | 1527 | } |
1528 | 1528 | } |
@@ -1548,7 +1548,7 @@ discard block |
||
1548 | 1548 | |
1549 | 1549 | $result = file_get_contents($filePath); |
1550 | 1550 | |
1551 | - if($result !== false) { |
|
1551 | + if ($result !== false) { |
|
1552 | 1552 | return $result; |
1553 | 1553 | } |
1554 | 1554 | |
@@ -1578,7 +1578,7 @@ discard block |
||
1578 | 1578 | { |
1579 | 1579 | $actual = realpath($path); |
1580 | 1580 | |
1581 | - if($actual === false) |
|
1581 | + if ($actual === false) |
|
1582 | 1582 | { |
1583 | 1583 | throw new FileHelper_Exception( |
1584 | 1584 | 'Folder does not exist', |
@@ -1590,7 +1590,7 @@ discard block |
||
1590 | 1590 | ); |
1591 | 1591 | } |
1592 | 1592 | |
1593 | - if(is_dir($path)) |
|
1593 | + if (is_dir($path)) |
|
1594 | 1594 | { |
1595 | 1595 | return self::normalizePath($actual); |
1596 | 1596 | } |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | |
242 | 242 | $output = curl_exec($ch); |
243 | 243 | |
244 | - if(isset($this->logfilePointer)) |
|
244 | + if (isset($this->logfilePointer)) |
|
245 | 245 | { |
246 | 246 | fclose($this->logfilePointer); |
247 | 247 | } |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | // CURL will complain about an empty response when the |
254 | 254 | // server sends a 100-continue code. That should not be |
255 | 255 | // regarded as an error. |
256 | - if($output === false && $this->response->getCode() !== 100) |
|
256 | + if ($output === false && $this->response->getCode() !== 100) |
|
257 | 257 | { |
258 | 258 | $curlCode = curl_errno($ch); |
259 | 259 | |
@@ -289,7 +289,7 @@ discard block |
||
289 | 289 | { |
290 | 290 | $ch = curl_init(); |
291 | 291 | |
292 | - if(!is_resource($ch)) |
|
292 | + if (!is_resource($ch)) |
|
293 | 293 | { |
294 | 294 | throw new RequestHelper_Exception( |
295 | 295 | 'Could not initialize a new cURL instance.', |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | } |
300 | 300 | |
301 | 301 | $this->setHeader('Content-Length', (string)$this->boundaries->getContentLength()); |
302 | - $this->setHeader('Content-Type', 'multipart/form-data; boundary=' . $this->mimeBoundary); |
|
302 | + $this->setHeader('Content-Type', 'multipart/form-data; boundary='.$this->mimeBoundary); |
|
303 | 303 | |
304 | 304 | curl_setopt($ch, CURLOPT_POST, true); |
305 | 305 | curl_setopt($ch, CURLOPT_URL, $url->getNormalizedWithoutAuth()); |
@@ -312,18 +312,18 @@ discard block |
||
312 | 312 | |
313 | 313 | $loggingEnabled = $this->configureLogging($ch); |
314 | 314 | |
315 | - if(!$loggingEnabled) |
|
315 | + if (!$loggingEnabled) |
|
316 | 316 | { |
317 | 317 | curl_setopt($ch, CURLINFO_HEADER_OUT, true); |
318 | 318 | } |
319 | 319 | |
320 | - if($this->verifySSL) |
|
320 | + if ($this->verifySSL) |
|
321 | 321 | { |
322 | 322 | curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); |
323 | 323 | curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); |
324 | 324 | } |
325 | 325 | |
326 | - if($url->hasUsername()) |
|
326 | + if ($url->hasUsername()) |
|
327 | 327 | { |
328 | 328 | curl_setopt($ch, CURLOPT_USERNAME, $url->getUsername()); |
329 | 329 | curl_setopt($ch, CURLOPT_PASSWORD, $url->getPassword()); |
@@ -338,14 +338,14 @@ discard block |
||
338 | 338 | */ |
339 | 339 | protected function configureLogging($ch) : bool |
340 | 340 | { |
341 | - if(empty($this->logfile)) |
|
341 | + if (empty($this->logfile)) |
|
342 | 342 | { |
343 | 343 | return false; |
344 | 344 | } |
345 | 345 | |
346 | 346 | $res = fopen($this->logfile, 'w+'); |
347 | 347 | |
348 | - if($res === false) |
|
348 | + if ($res === false) |
|
349 | 349 | { |
350 | 350 | throw new RequestHelper_Exception( |
351 | 351 | 'Cannot open logfile for writing.', |
@@ -375,7 +375,7 @@ discard block |
||
375 | 375 | |
376 | 376 | $this->setHeader('Expect', ''); |
377 | 377 | |
378 | - foreach($this->headers as $name => $value) { |
|
378 | + foreach ($this->headers as $name => $value) { |
|
379 | 379 | $result[] = $name.': '.$value; |
380 | 380 | } |
381 | 381 | |
@@ -392,7 +392,7 @@ discard block |
||
392 | 392 | { |
393 | 393 | $response = $this->getResponse(); |
394 | 394 | |
395 | - if($response !== null) { |
|
395 | + if ($response !== null) { |
|
396 | 396 | return $response->getHeaders(); |
397 | 397 | } |
398 | 398 | |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | */ |
429 | 429 | public function getHeader(string $name) : string |
430 | 430 | { |
431 | - if(isset($this->headers[$name])) |
|
431 | + if (isset($this->headers[$name])) |
|
432 | 432 | { |
433 | 433 | return $this->headers[$name]; |
434 | 434 | } |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | { |
69 | 69 | $string = strval($string); |
70 | 70 | |
71 | - if(!empty($string)) |
|
71 | + if (!empty($string)) |
|
72 | 72 | { |
73 | 73 | $this->strings[] = $string; |
74 | 74 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | { |
148 | 148 | array_unshift($arguments, $format); |
149 | 149 | |
150 | - if(!class_exists('\AppLocalize\Localization')) |
|
150 | + if (!class_exists('\AppLocalize\Localization')) |
|
151 | 151 | { |
152 | 152 | return $this->sf(...$arguments); |
153 | 153 | } |
@@ -288,10 +288,10 @@ discard block |
||
288 | 288 | * @param bool $newTab |
289 | 289 | * @return $this |
290 | 290 | */ |
291 | - public function link(string $label, string $url, bool $newTab=false) : StringBuilder |
|
291 | + public function link(string $label, string $url, bool $newTab = false) : StringBuilder |
|
292 | 292 | { |
293 | 293 | $target = ''; |
294 | - if($newTab) { |
|
294 | + if ($newTab) { |
|
295 | 295 | $target = ' target="_blank"'; |
296 | 296 | } |
297 | 297 | |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | */ |
338 | 338 | protected function spanned($string, $classes) : StringBuilder |
339 | 339 | { |
340 | - if(!is_array($classes)) |
|
340 | + if (!is_array($classes)) |
|
341 | 341 | { |
342 | 342 | $classes = array(strval($classes)); |
343 | 343 | } |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | |
244 | 244 | if (!empty($text)) { |
245 | 245 | $fragment = $this->dom->createDocumentFragment(); |
246 | - if(!@$fragment->appendXML($text)) { |
|
246 | + if (!@$fragment->appendXML($text)) { |
|
247 | 247 | throw new XMLHelper_Exception( |
248 | 248 | 'Cannot append XML fragment', |
249 | 249 | sprintf( |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @param array<string,mixed> $attributes |
286 | 286 | * @return DOMNode |
287 | 287 | */ |
288 | - public function createRoot(string $name, array $attributes=array()) |
|
288 | + public function createRoot(string $name, array $attributes = array()) |
|
289 | 289 | { |
290 | 290 | $root = $this->dom->appendChild($this->dom->createElement($name)); |
291 | 291 | $this->addAttributes($root, $attributes); |
@@ -311,8 +311,8 @@ discard block |
||
311 | 311 | $string = str_replace('<', 'LT_ESCAPE', $string); |
312 | 312 | $string = str_replace('>', 'GT_ESCAPE', $string); |
313 | 313 | |
314 | - $string = str_replace(' ',' ', $string); |
|
315 | - $string = str_replace('&','&', $string); |
|
314 | + $string = str_replace(' ', ' ', $string); |
|
315 | + $string = str_replace('&', '&', $string); |
|
316 | 316 | |
317 | 317 | return $string; |
318 | 318 | } |
@@ -331,9 +331,9 @@ discard block |
||
331 | 331 | */ |
332 | 332 | public static function downloadXML(string $xml, string $filename = 'download.xml') : void |
333 | 333 | { |
334 | - if(!headers_sent() && !self::$simulation) |
|
334 | + if (!headers_sent() && !self::$simulation) |
|
335 | 335 | { |
336 | - header('Content-Disposition: attachment; filename="' . $filename . '"'); |
|
336 | + header('Content-Disposition: attachment; filename="'.$filename.'"'); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | echo $xml; |
@@ -347,12 +347,12 @@ discard block |
||
347 | 347 | */ |
348 | 348 | public static function displayXML(string $xml) : void |
349 | 349 | { |
350 | - if(!headers_sent() && !self::$simulation) |
|
350 | + if (!headers_sent() && !self::$simulation) |
|
351 | 351 | { |
352 | 352 | header('Content-Type:text/xml; charset=utf-8'); |
353 | 353 | } |
354 | 354 | |
355 | - if(self::$simulation) |
|
355 | + if (self::$simulation) |
|
356 | 356 | { |
357 | 357 | $xml = '<pre>'.htmlspecialchars($xml).'</pre>'; |
358 | 358 | } |
@@ -370,16 +370,16 @@ discard block |
||
370 | 370 | * @param array<string,string> $customInfo Associative array with name => value pairs for custom tags to add to the output xml |
371 | 371 | * @see buildErrorXML() |
372 | 372 | */ |
373 | - public static function displayErrorXML($code, string $message, string $title, array $customInfo=array()) |
|
373 | + public static function displayErrorXML($code, string $message, string $title, array $customInfo = array()) |
|
374 | 374 | { |
375 | - if(!headers_sent() && !self::$simulation) { |
|
376 | - header('HTTP/1.1 400 Bad Request: ' . $title, true, 400); |
|
375 | + if (!headers_sent() && !self::$simulation) { |
|
376 | + header('HTTP/1.1 400 Bad Request: '.$title, true, 400); |
|
377 | 377 | } |
378 | 378 | |
379 | 379 | self::displayXML(self::buildErrorXML($code, $message, $title, $customInfo)); |
380 | 380 | } |
381 | 381 | |
382 | - public static function setSimulation(bool $simulate=true) : void |
|
382 | + public static function setSimulation(bool $simulate = true) : void |
|
383 | 383 | { |
384 | 384 | self::$simulation = $simulate; |
385 | 385 | } |
@@ -428,7 +428,7 @@ discard block |
||
428 | 428 | * @param array<string,string> $customInfo |
429 | 429 | * @return string |
430 | 430 | */ |
431 | - public static function buildErrorXML($code, string $message, string $title, array $customInfo=array()) |
|
431 | + public static function buildErrorXML($code, string $message, string $title, array $customInfo = array()) |
|
432 | 432 | { |
433 | 433 | $xml = new DOMDocument('1.0', 'UTF-8'); |
434 | 434 | $xml->formatOutput = true; |
@@ -442,7 +442,7 @@ discard block |
||
442 | 442 | $helper->addTextTag($root, 'title', $title); |
443 | 443 | $helper->addTextTag($root, 'request_uri', $_SERVER['REQUEST_URI']); |
444 | 444 | |
445 | - foreach($customInfo as $name => $value) { |
|
445 | + foreach ($customInfo as $name => $value) { |
|
446 | 446 | $helper->addTextTag($root, $name, $value); |
447 | 447 | } |
448 | 448 |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public static function json($subject) : string |
110 | 110 | { |
111 | - if(!is_string($subject)) |
|
111 | + if (!is_string($subject)) |
|
112 | 112 | { |
113 | 113 | $subject = json_encode($subject, JSON_PRETTY_PRINT); |
114 | 114 | } |
@@ -125,9 +125,9 @@ discard block |
||
125 | 125 | * @param bool $formatSource Whether to format the source with indentation to make it readable. |
126 | 126 | * @return string |
127 | 127 | */ |
128 | - public static function xml(string $xml, bool $formatSource=false) : string |
|
128 | + public static function xml(string $xml, bool $formatSource = false) : string |
|
129 | 129 | { |
130 | - if($formatSource) |
|
130 | + if ($formatSource) |
|
131 | 131 | { |
132 | 132 | $dom = new DOMDocument(); |
133 | 133 | $dom->preserveWhiteSpace = false; |
@@ -148,9 +148,9 @@ discard block |
||
148 | 148 | * @param bool $formatSource |
149 | 149 | * @return string |
150 | 150 | */ |
151 | - public static function html(string $html, bool $formatSource=false) : string |
|
151 | + public static function html(string $html, bool $formatSource = false) : string |
|
152 | 152 | { |
153 | - if($formatSource) |
|
153 | + if ($formatSource) |
|
154 | 154 | { |
155 | 155 | $dom = new DOMDocument(); |
156 | 156 | $dom->preserveWhiteSpace = false; |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | */ |
49 | 49 | private function initUnits() : void |
50 | 50 | { |
51 | - if(isset(self::$units)) |
|
51 | + if (isset(self::$units)) |
|
52 | 52 | { |
53 | 53 | return; |
54 | 54 | } |
@@ -90,12 +90,12 @@ discard block |
||
90 | 90 | public function toString() : string |
91 | 91 | { |
92 | 92 | // specifically handle zero |
93 | - if($this->seconds <= 0) |
|
93 | + if ($this->seconds <= 0) |
|
94 | 94 | { |
95 | - return '0 ' . t('seconds'); |
|
95 | + return '0 '.t('seconds'); |
|
96 | 96 | } |
97 | 97 | |
98 | - if($this->seconds < 1) |
|
98 | + if ($this->seconds < 1) |
|
99 | 99 | { |
100 | 100 | return t('less than a second'); |
101 | 101 | } |
@@ -104,12 +104,12 @@ discard block |
||
104 | 104 | |
105 | 105 | $last = array_pop($tokens); |
106 | 106 | |
107 | - if(empty($tokens)) |
|
107 | + if (empty($tokens)) |
|
108 | 108 | { |
109 | 109 | return $last; |
110 | 110 | } |
111 | 111 | |
112 | - return implode(', ', $tokens) . ' ' . t('and') . ' ' . $last; |
|
112 | + return implode(', ', $tokens).' '.t('and').' '.$last; |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | /** |
@@ -122,18 +122,18 @@ discard block |
||
122 | 122 | $seconds = $this->seconds; |
123 | 123 | $tokens = array(); |
124 | 124 | |
125 | - foreach(self::$units as $def) |
|
125 | + foreach (self::$units as $def) |
|
126 | 126 | { |
127 | 127 | $unitValue = intval($seconds / $def['value']); |
128 | 128 | |
129 | - if($unitValue <= 0) |
|
129 | + if ($unitValue <= 0) |
|
130 | 130 | { |
131 | 131 | continue; |
132 | 132 | } |
133 | 133 | |
134 | - $item = strval($unitValue) . ' '; |
|
134 | + $item = strval($unitValue).' '; |
|
135 | 135 | |
136 | - if(abs($unitValue) > 1) |
|
136 | + if (abs($unitValue) > 1) |
|
137 | 137 | { |
138 | 138 | $item .= $def['plural']; |
139 | 139 | } |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | 'fragment' |
78 | 78 | ); |
79 | 79 | |
80 | - foreach($parts as $part) |
|
80 | + foreach ($parts as $part) |
|
81 | 81 | { |
82 | 82 | $method = 'render_'.$part; |
83 | 83 | $result[] = (string)$this->$method(); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | |
89 | 89 | protected function render_scheme() : string |
90 | 90 | { |
91 | - if(!$this->info->hasScheme()) { |
|
91 | + if (!$this->info->hasScheme()) { |
|
92 | 92 | return ''; |
93 | 93 | } |
94 | 94 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | |
104 | 104 | protected function render_username() : string |
105 | 105 | { |
106 | - if(!$this->info->hasUsername()) { |
|
106 | + if (!$this->info->hasUsername()) { |
|
107 | 107 | return ''; |
108 | 108 | } |
109 | 109 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | |
120 | 120 | protected function render_host() : string |
121 | 121 | { |
122 | - if(!$this->info->hasHost()) { |
|
122 | + if (!$this->info->hasHost()) { |
|
123 | 123 | return ''; |
124 | 124 | } |
125 | 125 | |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | |
132 | 132 | protected function render_port() : string |
133 | 133 | { |
134 | - if(!$this->info->hasPort()) { |
|
134 | + if (!$this->info->hasPort()) { |
|
135 | 135 | return ''; |
136 | 136 | } |
137 | 137 | |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | |
145 | 145 | protected function render_path() : string |
146 | 146 | { |
147 | - if(!$this->info->hasPath()) { |
|
147 | + if (!$this->info->hasPath()) { |
|
148 | 148 | return ''; |
149 | 149 | } |
150 | 150 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | { |
170 | 170 | $previous = $this->info->isParamExclusionEnabled(); |
171 | 171 | |
172 | - if($previous) |
|
172 | + if ($previous) |
|
173 | 173 | { |
174 | 174 | $this->info->setParamExclusion(false); |
175 | 175 | } |
@@ -185,19 +185,19 @@ discard block |
||
185 | 185 | { |
186 | 186 | $params = $this->resolveParams(); |
187 | 187 | |
188 | - if(empty($params)) { |
|
188 | + if (empty($params)) { |
|
189 | 189 | return ''; |
190 | 190 | } |
191 | 191 | |
192 | 192 | $tokens = array(); |
193 | 193 | $excluded = array(); |
194 | 194 | |
195 | - if($this->info->isParamExclusionEnabled()) |
|
195 | + if ($this->info->isParamExclusionEnabled()) |
|
196 | 196 | { |
197 | 197 | $excluded = $this->info->getExcludedParams(); |
198 | 198 | } |
199 | 199 | |
200 | - foreach($params as $param => $value) |
|
200 | + foreach ($params as $param => $value) |
|
201 | 201 | { |
202 | 202 | // If the parameter is numeric, it will automatically |
203 | 203 | // be an integer, so we need the conversion here. |
@@ -218,7 +218,7 @@ discard block |
||
218 | 218 | |
219 | 219 | $tag = $this->resolveTag($excluded, $param); |
220 | 220 | |
221 | - if(!empty($tag)) |
|
221 | + if (!empty($tag)) |
|
222 | 222 | { |
223 | 223 | $tokens[] = sprintf($tag, $parts); |
224 | 224 | } |
@@ -232,13 +232,13 @@ discard block |
||
232 | 232 | protected function resolveTag(array $excluded, string $paramName) : string |
233 | 233 | { |
234 | 234 | // regular, non-excluded parameter |
235 | - if(!isset($excluded[$paramName])) |
|
235 | + if (!isset($excluded[$paramName])) |
|
236 | 236 | { |
237 | 237 | return '<span class="link-param">%s</span>'; |
238 | 238 | } |
239 | 239 | |
240 | 240 | // highlight excluded parameters is disabled, ignore this parameter |
241 | - if(!$this->info->isHighlightExcludeEnabled()) |
|
241 | + if (!$this->info->isHighlightExcludeEnabled()) |
|
242 | 242 | { |
243 | 243 | return ''; |
244 | 244 | } |
@@ -254,7 +254,7 @@ discard block |
||
254 | 254 | |
255 | 255 | protected function render_fragment() : string |
256 | 256 | { |
257 | - if(!$this->info->hasFragment()) { |
|
257 | + if (!$this->info->hasFragment()) { |
|
258 | 258 | return ''; |
259 | 259 | } |
260 | 260 | |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | { |
270 | 270 | $cssFolder = realpath(__DIR__.'/../../css'); |
271 | 271 | |
272 | - if($cssFolder === false) { |
|
272 | + if ($cssFolder === false) { |
|
273 | 273 | throw new BaseException( |
274 | 274 | 'Cannot find package CSS folder.', |
275 | 275 | null, |
@@ -56,9 +56,9 @@ discard block |
||
56 | 56 | * @param mixed $value |
57 | 57 | * @param array|null $serialized |
58 | 58 | */ |
59 | - public function __construct($value, $serialized=null) |
|
59 | + public function __construct($value, $serialized = null) |
|
60 | 60 | { |
61 | - if(is_array($serialized)) |
|
61 | + if (is_array($serialized)) |
|
62 | 62 | { |
63 | 63 | $this->parseSerialized($serialized); |
64 | 64 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | */ |
105 | 105 | protected function parseSerialized(array $serialized) : void |
106 | 106 | { |
107 | - if(!isset($serialized['string']) || !isset($serialized['type']) || !isset($serialized['options'])) |
|
107 | + if (!isset($serialized['string']) || !isset($serialized['type']) || !isset($serialized['options'])) |
|
108 | 108 | { |
109 | 109 | throw new BaseException( |
110 | 110 | 'Invalid variable info serialized data.', |
@@ -126,12 +126,12 @@ discard block |
||
126 | 126 | |
127 | 127 | // Gettype will return a string like "Resource(closed)" when |
128 | 128 | // working with a resource that has already been closed. |
129 | - if(strstr($this->type, 'resource')) |
|
129 | + if (strstr($this->type, 'resource')) |
|
130 | 130 | { |
131 | 131 | $this->type = self::TYPE_RESOURCE; |
132 | 132 | } |
133 | 133 | |
134 | - if(is_array($value) && is_callable($value)) { |
|
134 | + if (is_array($value) && is_callable($value)) { |
|
135 | 135 | $this->type = self::TYPE_CALLABLE; |
136 | 136 | } |
137 | 137 | |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | * @param bool $enable |
170 | 170 | * @return VariableInfo |
171 | 171 | */ |
172 | - public function enableType(bool $enable=true) : VariableInfo |
|
172 | + public function enableType(bool $enable = true) : VariableInfo |
|
173 | 173 | { |
174 | 174 | return $this->setOption('prepend-type', $enable); |
175 | 175 | } |
@@ -178,9 +178,9 @@ discard block |
||
178 | 178 | { |
179 | 179 | $converted = $this->string; |
180 | 180 | |
181 | - if($this->getOption('prepend-type') === true && !$this->isNull()) |
|
181 | + if ($this->getOption('prepend-type') === true && !$this->isNull()) |
|
182 | 182 | { |
183 | - if($this->isString()) |
|
183 | + if ($this->isString()) |
|
184 | 184 | { |
185 | 185 | $converted = '"'.$converted.'"'; |
186 | 186 | } |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * @param int $tabSize The amount of spaces per tab. |
51 | 51 | * @return string |
52 | 52 | */ |
53 | - public static function tabs2spaces(string $string, int $tabSize=4) : string |
|
53 | + public static function tabs2spaces(string $string, int $tabSize = 4) : string |
|
54 | 54 | { |
55 | 55 | return str_replace("\t", str_repeat(' ', $tabSize), $string); |
56 | 56 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | * @param int $tabSize The amount of spaces per tab in the source string. |
63 | 63 | * @return string |
64 | 64 | */ |
65 | - public static function spaces2tabs(string $string, int $tabSize=4) : string |
|
65 | + public static function spaces2tabs(string $string, int $tabSize = 4) : string |
|
66 | 66 | { |
67 | 67 | return str_replace(str_repeat(' ', $tabSize), "\t", $string); |
68 | 68 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | { |
105 | 105 | $converter = new ConvertHelper_DurationConverter(); |
106 | 106 | |
107 | - if($datefrom instanceof \DateTime) |
|
107 | + if ($datefrom instanceof \DateTime) |
|
108 | 108 | { |
109 | 109 | $converter->setDateFrom($datefrom); |
110 | 110 | } |
@@ -113,11 +113,11 @@ discard block |
||
113 | 113 | $converter->setDateFrom(self::timestamp2date($datefrom)); |
114 | 114 | } |
115 | 115 | |
116 | - if($dateto instanceof \DateTime) |
|
116 | + if ($dateto instanceof \DateTime) |
|
117 | 117 | { |
118 | 118 | $converter->setDateTo($dateto); |
119 | 119 | } |
120 | - else if($dateto > 0) |
|
120 | + else if ($dateto > 0) |
|
121 | 121 | { |
122 | 122 | $converter->setDateTo(self::timestamp2date($dateto)); |
123 | 123 | } |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | * @deprecated Use the Highlighter class directly instead. |
148 | 148 | * @see Highlighter::xml() |
149 | 149 | */ |
150 | - public static function highlight_xml(string $xml, bool $formatSource=false) : string |
|
150 | + public static function highlight_xml(string $xml, bool $formatSource = false) : string |
|
151 | 151 | { |
152 | 152 | return Highlighter::xml($xml, $formatSource); |
153 | 153 | } |
@@ -208,16 +208,16 @@ discard block |
||
208 | 208 | return $text; |
209 | 209 | } |
210 | 210 | |
211 | - $text = trim(mb_substr($text, 0, $targetLength)) . $append; |
|
211 | + $text = trim(mb_substr($text, 0, $targetLength)).$append; |
|
212 | 212 | |
213 | 213 | return $text; |
214 | 214 | } |
215 | 215 | |
216 | - public static function var_dump($var, $html=true) : string |
|
216 | + public static function var_dump($var, $html = true) : string |
|
217 | 217 | { |
218 | 218 | $info = parseVariable($var); |
219 | 219 | |
220 | - if($html) { |
|
220 | + if ($html) { |
|
221 | 221 | return $info->toHTML(); |
222 | 222 | } |
223 | 223 | |
@@ -232,11 +232,11 @@ discard block |
||
232 | 232 | * @param bool $html Whether to style the dump as HTML. |
233 | 233 | * @return string |
234 | 234 | */ |
235 | - public static function print_r($var, bool $return=false, bool $html=true) : string |
|
235 | + public static function print_r($var, bool $return = false, bool $html = true) : string |
|
236 | 236 | { |
237 | 237 | $result = parseVariable($var)->enableType()->toString(); |
238 | 238 | |
239 | - if($html) |
|
239 | + if ($html) |
|
240 | 240 | { |
241 | 241 | $result = |
242 | 242 | '<pre style="background:#fff;color:#333;padding:16px;border:solid 1px #bbb;border-radius:4px">'. |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | '</pre>'; |
245 | 245 | } |
246 | 246 | |
247 | - if(!$return) |
|
247 | + if (!$return) |
|
248 | 248 | { |
249 | 249 | echo $result; |
250 | 250 | } |
@@ -275,17 +275,17 @@ discard block |
||
275 | 275 | */ |
276 | 276 | public static function string2bool($string) : bool |
277 | 277 | { |
278 | - if($string === '' || $string === null || !is_scalar($string)) |
|
278 | + if ($string === '' || $string === null || !is_scalar($string)) |
|
279 | 279 | { |
280 | 280 | return false; |
281 | 281 | } |
282 | 282 | |
283 | - if(is_bool($string)) |
|
283 | + if (is_bool($string)) |
|
284 | 284 | { |
285 | 285 | return $string; |
286 | 286 | } |
287 | 287 | |
288 | - if(array_key_exists($string, self::$booleanStrings)) |
|
288 | + if (array_key_exists($string, self::$booleanStrings)) |
|
289 | 289 | { |
290 | 290 | return self::$booleanStrings[$string]; |
291 | 291 | } |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | public static function date2listLabel(\DateTime $date, $includeTime = false, $shortMonth = false) |
341 | 341 | { |
342 | 342 | $today = new \DateTime(); |
343 | - if($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
343 | + if ($date->format('d.m.Y') == $today->format('d.m.Y')) { |
|
344 | 344 | $label = t('Today'); |
345 | 345 | } else { |
346 | - $label = $date->format('d') . '. ' . self::month2string((int)$date->format('m'), $shortMonth) . ' '; |
|
346 | + $label = $date->format('d').'. '.self::month2string((int)$date->format('m'), $shortMonth).' '; |
|
347 | 347 | if ($date->format('Y') != date('Y')) { |
348 | 348 | $label .= $date->format('Y'); |
349 | 349 | } |
@@ -503,12 +503,12 @@ discard block |
||
503 | 503 | $output = ''; |
504 | 504 | $split = str_split($unicodeChar); |
505 | 505 | |
506 | - foreach($split as $octet) |
|
506 | + foreach ($split as $octet) |
|
507 | 507 | { |
508 | 508 | $ordInt = ord($octet); |
509 | 509 | // Convert from int (base 10) to hex (base 16), for PHP \x syntax |
510 | 510 | $ordHex = base_convert((string)$ordInt, 10, 16); |
511 | - $output .= '\x' . $ordHex; |
|
511 | + $output .= '\x'.$ordHex; |
|
512 | 512 | } |
513 | 513 | |
514 | 514 | return $output; |
@@ -541,19 +541,19 @@ discard block |
||
541 | 541 | |
542 | 542 | protected static function convertScalarForComparison($scalar) |
543 | 543 | { |
544 | - if($scalar === '' || is_null($scalar)) { |
|
544 | + if ($scalar === '' || is_null($scalar)) { |
|
545 | 545 | return null; |
546 | 546 | } |
547 | 547 | |
548 | - if(is_bool($scalar)) { |
|
548 | + if (is_bool($scalar)) { |
|
549 | 549 | return self::bool2string($scalar); |
550 | 550 | } |
551 | 551 | |
552 | - if(is_array($scalar)) { |
|
552 | + if (is_array($scalar)) { |
|
553 | 553 | $scalar = md5(serialize($scalar)); |
554 | 554 | } |
555 | 555 | |
556 | - if($scalar !== null && !is_scalar($scalar)) { |
|
556 | + if ($scalar !== null && !is_scalar($scalar)) { |
|
557 | 557 | throw new ConvertHelper_Exception( |
558 | 558 | 'Not a scalar value in comparison', |
559 | 559 | null, |
@@ -602,7 +602,7 @@ discard block |
||
602 | 602 | public static function bool2string($boolean, bool $yesno = false) : string |
603 | 603 | { |
604 | 604 | // allow 'yes', 'true', 'no', 'false' string notations as well |
605 | - if(!is_bool($boolean)) { |
|
605 | + if (!is_bool($boolean)) { |
|
606 | 606 | $boolean = self::string2bool($boolean); |
607 | 607 | } |
608 | 608 | |
@@ -643,15 +643,15 @@ discard block |
||
643 | 643 | public static function array2attributeString($array) |
644 | 644 | { |
645 | 645 | $tokens = array(); |
646 | - foreach($array as $attr => $value) { |
|
647 | - if($value == '' || $value == null) { |
|
646 | + foreach ($array as $attr => $value) { |
|
647 | + if ($value == '' || $value == null) { |
|
648 | 648 | continue; |
649 | 649 | } |
650 | 650 | |
651 | 651 | $tokens[] = $attr.'="'.$value.'"'; |
652 | 652 | } |
653 | 653 | |
654 | - if(empty($tokens)) { |
|
654 | + if (empty($tokens)) { |
|
655 | 655 | return ''; |
656 | 656 | } |
657 | 657 | |
@@ -666,10 +666,10 @@ discard block |
||
666 | 666 | * @param string $string |
667 | 667 | * @return string |
668 | 668 | */ |
669 | - public static function string2attributeJS($string, $quoted=true) |
|
669 | + public static function string2attributeJS($string, $quoted = true) |
|
670 | 670 | { |
671 | 671 | $converted = addslashes(htmlspecialchars(strip_tags($string), ENT_QUOTES, 'UTF-8')); |
672 | - if($quoted) { |
|
672 | + if ($quoted) { |
|
673 | 673 | $converted = "'".$converted."'"; |
674 | 674 | } |
675 | 675 | |
@@ -687,11 +687,11 @@ discard block |
||
687 | 687 | */ |
688 | 688 | public static function isBoolean($value) : bool |
689 | 689 | { |
690 | - if(is_bool($value)) { |
|
690 | + if (is_bool($value)) { |
|
691 | 691 | return true; |
692 | 692 | } |
693 | 693 | |
694 | - if(!is_scalar($value)) { |
|
694 | + if (!is_scalar($value)) { |
|
695 | 695 | return false; |
696 | 696 | } |
697 | 697 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | public static function array2styleString(array $subject) : string |
708 | 708 | { |
709 | 709 | $tokens = array(); |
710 | - foreach($subject as $name => $value) { |
|
710 | + foreach ($subject as $name => $value) { |
|
711 | 711 | $tokens[] = $name.':'.$value; |
712 | 712 | } |
713 | 713 | |
@@ -765,7 +765,7 @@ discard block |
||
765 | 765 | * |
766 | 766 | * @see JSHelper::buildRegexStatement() |
767 | 767 | */ |
768 | - public static function regex2js(string $regex, string $statementType=JSHelper::JS_REGEX_OBJECT) |
|
768 | + public static function regex2js(string $regex, string $statementType = JSHelper::JS_REGEX_OBJECT) |
|
769 | 769 | { |
770 | 770 | return JSHelper::buildRegexStatement($regex, $statementType); |
771 | 771 | } |
@@ -782,11 +782,11 @@ discard block |
||
782 | 782 | * @throws ConvertHelper_Exception |
783 | 783 | * @return string |
784 | 784 | */ |
785 | - public static function var2json($variable, int $options=0, int $depth=512) : string |
|
785 | + public static function var2json($variable, int $options = 0, int $depth = 512) : string |
|
786 | 786 | { |
787 | 787 | $result = json_encode($variable, $options, $depth); |
788 | 788 | |
789 | - if($result !== false) { |
|
789 | + if ($result !== false) { |
|
790 | 790 | return $result; |
791 | 791 | } |
792 | 792 | |
@@ -811,10 +811,10 @@ discard block |
||
811 | 811 | public static function stripUTFBom($string) |
812 | 812 | { |
813 | 813 | $boms = FileHelper::getUTFBOMs(); |
814 | - foreach($boms as $bomChars) { |
|
814 | + foreach ($boms as $bomChars) { |
|
815 | 815 | $length = mb_strlen($bomChars); |
816 | 816 | $text = mb_substr($string, 0, $length); |
817 | - if($text==$bomChars) { |
|
817 | + if ($text == $bomChars) { |
|
818 | 818 | return mb_substr($string, $length); |
819 | 819 | } |
820 | 820 | } |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | */ |
832 | 832 | public static function string2utf8($string) |
833 | 833 | { |
834 | - if(!self::isStringASCII($string)) { |
|
834 | + if (!self::isStringASCII($string)) { |
|
835 | 835 | return \ForceUTF8\Encoding::toUTF8($string); |
836 | 836 | } |
837 | 837 | |
@@ -849,11 +849,11 @@ discard block |
||
849 | 849 | */ |
850 | 850 | public static function isStringASCII($string) : bool |
851 | 851 | { |
852 | - if($string === '' || $string === NULL) { |
|
852 | + if ($string === '' || $string === NULL) { |
|
853 | 853 | return true; |
854 | 854 | } |
855 | 855 | |
856 | - if(!is_string($string)) { |
|
856 | + if (!is_string($string)) { |
|
857 | 857 | return false; |
858 | 858 | } |
859 | 859 | |
@@ -893,7 +893,7 @@ discard block |
||
893 | 893 | * @param array $options |
894 | 894 | * @return float |
895 | 895 | */ |
896 | - public static function matchString($source, $target, $options=array()) |
|
896 | + public static function matchString($source, $target, $options = array()) |
|
897 | 897 | { |
898 | 898 | $defaults = array( |
899 | 899 | 'maxLevenshtein' => 10, |
@@ -903,12 +903,12 @@ discard block |
||
903 | 903 | $options = array_merge($defaults, $options); |
904 | 904 | |
905 | 905 | // avoid doing this via levenshtein |
906 | - if($source == $target) { |
|
906 | + if ($source == $target) { |
|
907 | 907 | return 100; |
908 | 908 | } |
909 | 909 | |
910 | 910 | $diff = levenshtein($source, $target); |
911 | - if($diff > $options['maxLevenshtein']) { |
|
911 | + if ($diff > $options['maxLevenshtein']) { |
|
912 | 912 | return 0; |
913 | 913 | } |
914 | 914 | |
@@ -992,24 +992,24 @@ discard block |
||
992 | 992 | * @see ConvertHelper::INTERVAL_HOURS |
993 | 993 | * @see ConvertHelper::INTERVAL_DAYS |
994 | 994 | */ |
995 | - public static function interval2total(\DateInterval $interval, $unit=self::INTERVAL_SECONDS) : int |
|
995 | + public static function interval2total(\DateInterval $interval, $unit = self::INTERVAL_SECONDS) : int |
|
996 | 996 | { |
997 | 997 | $total = (int)$interval->format('%a'); |
998 | 998 | if ($unit == self::INTERVAL_DAYS) { |
999 | 999 | return $total; |
1000 | 1000 | } |
1001 | 1001 | |
1002 | - $total = ($total * 24) + ((int)$interval->h ); |
|
1002 | + $total = ($total * 24) + ((int)$interval->h); |
|
1003 | 1003 | if ($unit == self::INTERVAL_HOURS) { |
1004 | 1004 | return $total; |
1005 | 1005 | } |
1006 | 1006 | |
1007 | - $total = ($total * 60) + ((int)$interval->i ); |
|
1007 | + $total = ($total * 60) + ((int)$interval->i); |
|
1008 | 1008 | if ($unit == self::INTERVAL_MINUTES) { |
1009 | 1009 | return $total; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - $total = ($total * 60) + ((int)$interval->s ); |
|
1012 | + $total = ($total * 60) + ((int)$interval->s); |
|
1013 | 1013 | if ($unit == self::INTERVAL_SECONDS) { |
1014 | 1014 | return $total; |
1015 | 1015 | } |
@@ -1038,13 +1038,13 @@ discard block |
||
1038 | 1038 | * @param bool $short |
1039 | 1039 | * @return string|NULL |
1040 | 1040 | */ |
1041 | - public static function date2dayName(\DateTime $date, bool $short=false) |
|
1041 | + public static function date2dayName(\DateTime $date, bool $short = false) |
|
1042 | 1042 | { |
1043 | 1043 | $day = $date->format('l'); |
1044 | 1044 | $invariant = self::getDayNamesInvariant(); |
1045 | 1045 | |
1046 | 1046 | $idx = array_search($day, $invariant); |
1047 | - if($idx !== false) { |
|
1047 | + if ($idx !== false) { |
|
1048 | 1048 | $localized = self::getDayNames($short); |
1049 | 1049 | return $localized[$idx]; |
1050 | 1050 | } |
@@ -1067,10 +1067,10 @@ discard block |
||
1067 | 1067 | * @param bool $short |
1068 | 1068 | * @return array |
1069 | 1069 | */ |
1070 | - public static function getDayNames(bool $short=false) : array |
|
1070 | + public static function getDayNames(bool $short = false) : array |
|
1071 | 1071 | { |
1072 | - if($short) { |
|
1073 | - if(!isset(self::$daysShort)) { |
|
1072 | + if ($short) { |
|
1073 | + if (!isset(self::$daysShort)) { |
|
1074 | 1074 | self::$daysShort = array( |
1075 | 1075 | t('Mon'), |
1076 | 1076 | t('Tue'), |
@@ -1085,7 +1085,7 @@ discard block |
||
1085 | 1085 | return self::$daysShort; |
1086 | 1086 | } |
1087 | 1087 | |
1088 | - if(!isset(self::$days)) { |
|
1088 | + if (!isset(self::$days)) { |
|
1089 | 1089 | self::$days = array( |
1090 | 1090 | t('Monday'), |
1091 | 1091 | t('Tuesday'), |
@@ -1110,17 +1110,17 @@ discard block |
||
1110 | 1110 | */ |
1111 | 1111 | public static function implodeWithAnd(array $list, $sep = ', ', $conjunction = null) |
1112 | 1112 | { |
1113 | - if(empty($list)) { |
|
1113 | + if (empty($list)) { |
|
1114 | 1114 | return ''; |
1115 | 1115 | } |
1116 | 1116 | |
1117 | - if(empty($conjunction)) { |
|
1117 | + if (empty($conjunction)) { |
|
1118 | 1118 | $conjunction = t('and'); |
1119 | 1119 | } |
1120 | 1120 | |
1121 | 1121 | $last = array_pop($list); |
1122 | - if($list) { |
|
1123 | - return implode($sep, $list) . $conjunction . ' ' . $last; |
|
1122 | + if ($list) { |
|
1123 | + return implode($sep, $list).$conjunction.' '.$last; |
|
1124 | 1124 | } |
1125 | 1125 | |
1126 | 1126 | return $last; |
@@ -1139,7 +1139,7 @@ discard block |
||
1139 | 1139 | public static function string2array(string $string) : array |
1140 | 1140 | { |
1141 | 1141 | $result = preg_split('//u', $string, null, PREG_SPLIT_NO_EMPTY); |
1142 | - if($result !== false) { |
|
1142 | + if ($result !== false) { |
|
1143 | 1143 | return $result; |
1144 | 1144 | } |
1145 | 1145 | |
@@ -1154,12 +1154,12 @@ discard block |
||
1154 | 1154 | */ |
1155 | 1155 | public static function isStringHTML(string $string) : bool |
1156 | 1156 | { |
1157 | - if(preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
1157 | + if (preg_match('%<[a-z/][\s\S]*>%siU', $string)) { |
|
1158 | 1158 | return true; |
1159 | 1159 | } |
1160 | 1160 | |
1161 | 1161 | $decoded = html_entity_decode($string); |
1162 | - if($decoded !== $string) { |
|
1162 | + if ($decoded !== $string) { |
|
1163 | 1163 | return true; |
1164 | 1164 | } |
1165 | 1165 | |
@@ -1268,14 +1268,14 @@ discard block |
||
1268 | 1268 | * @param bool $caseInsensitive |
1269 | 1269 | * @return ConvertHelper_StringMatch[] |
1270 | 1270 | */ |
1271 | - public static function findString(string $needle, string $haystack, bool $caseInsensitive=false) |
|
1271 | + public static function findString(string $needle, string $haystack, bool $caseInsensitive = false) |
|
1272 | 1272 | { |
1273 | - if($needle === '') { |
|
1273 | + if ($needle === '') { |
|
1274 | 1274 | return array(); |
1275 | 1275 | } |
1276 | 1276 | |
1277 | 1277 | $function = 'mb_strpos'; |
1278 | - if($caseInsensitive) { |
|
1278 | + if ($caseInsensitive) { |
|
1279 | 1279 | $function = 'mb_stripos'; |
1280 | 1280 | } |
1281 | 1281 | |
@@ -1283,7 +1283,7 @@ discard block |
||
1283 | 1283 | $positions = array(); |
1284 | 1284 | $length = mb_strlen($needle); |
1285 | 1285 | |
1286 | - while( ($pos = $function($haystack, $needle, $pos)) !== false) |
|
1286 | + while (($pos = $function($haystack, $needle, $pos)) !== false) |
|
1287 | 1287 | { |
1288 | 1288 | $match = mb_substr($haystack, $pos, $length); |
1289 | 1289 | $positions[] = new ConvertHelper_StringMatch($pos, $match); |
@@ -1303,7 +1303,7 @@ discard block |
||
1303 | 1303 | */ |
1304 | 1304 | public static function explodeTrim(string $delimiter, string $string) : array |
1305 | 1305 | { |
1306 | - if(empty($string) || empty($delimiter)) { |
|
1306 | + if (empty($string) || empty($delimiter)) { |
|
1307 | 1307 | return array(); |
1308 | 1308 | } |
1309 | 1309 | |
@@ -1311,8 +1311,8 @@ discard block |
||
1311 | 1311 | $tokens = array_map('trim', $tokens); |
1312 | 1312 | |
1313 | 1313 | $keep = array(); |
1314 | - foreach($tokens as $token) { |
|
1315 | - if($token !== '') { |
|
1314 | + foreach ($tokens as $token) { |
|
1315 | + if ($token !== '') { |
|
1316 | 1316 | $keep[] = $token; |
1317 | 1317 | } |
1318 | 1318 | } |
@@ -1330,11 +1330,11 @@ discard block |
||
1330 | 1330 | */ |
1331 | 1331 | public static function detectEOLCharacter(string $subjectString) : ?ConvertHelper_EOL |
1332 | 1332 | { |
1333 | - if(empty($subjectString)) { |
|
1333 | + if (empty($subjectString)) { |
|
1334 | 1334 | return null; |
1335 | 1335 | } |
1336 | 1336 | |
1337 | - if(!isset(self::$eolChars)) |
|
1337 | + if (!isset(self::$eolChars)) |
|
1338 | 1338 | { |
1339 | 1339 | $cr = chr((int)hexdec('0d')); |
1340 | 1340 | $lf = chr((int)hexdec('0a')); |
@@ -1365,18 +1365,18 @@ discard block |
||
1365 | 1365 | |
1366 | 1366 | $max = 0; |
1367 | 1367 | $results = array(); |
1368 | - foreach(self::$eolChars as $def) |
|
1368 | + foreach (self::$eolChars as $def) |
|
1369 | 1369 | { |
1370 | 1370 | $amount = substr_count($subjectString, $def['char']); |
1371 | 1371 | |
1372 | - if($amount > $max) |
|
1372 | + if ($amount > $max) |
|
1373 | 1373 | { |
1374 | 1374 | $max = $amount; |
1375 | 1375 | $results[] = $def; |
1376 | 1376 | } |
1377 | 1377 | } |
1378 | 1378 | |
1379 | - if(empty($results)) { |
|
1379 | + if (empty($results)) { |
|
1380 | 1380 | return null; |
1381 | 1381 | } |
1382 | 1382 | |
@@ -1396,9 +1396,9 @@ discard block |
||
1396 | 1396 | */ |
1397 | 1397 | public static function arrayRemoveKeys(array &$array, array $keys) : void |
1398 | 1398 | { |
1399 | - foreach($keys as $key) |
|
1399 | + foreach ($keys as $key) |
|
1400 | 1400 | { |
1401 | - if(array_key_exists($key, $array)) { |
|
1401 | + if (array_key_exists($key, $array)) { |
|
1402 | 1402 | unset($array[$key]); |
1403 | 1403 | } |
1404 | 1404 | } |
@@ -1413,17 +1413,17 @@ discard block |
||
1413 | 1413 | */ |
1414 | 1414 | public static function isInteger($value) : bool |
1415 | 1415 | { |
1416 | - if(is_int($value)) { |
|
1416 | + if (is_int($value)) { |
|
1417 | 1417 | return true; |
1418 | 1418 | } |
1419 | 1419 | |
1420 | 1420 | // booleans get converted to numbers, so they would |
1421 | 1421 | // actually match the regex. |
1422 | - if(is_bool($value)) { |
|
1422 | + if (is_bool($value)) { |
|
1423 | 1423 | return false; |
1424 | 1424 | } |
1425 | 1425 | |
1426 | - if(is_string($value) && $value !== '') { |
|
1426 | + if (is_string($value) && $value !== '') { |
|
1427 | 1427 | return preg_match('/\A-?\d+\z/', $value) === 1; |
1428 | 1428 | } |
1429 | 1429 |