@@ -49,13 +49,13 @@ |
||
| 49 | 49 | |
| 50 | 50 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 51 | 51 | |
| 52 | - while(strpos($name, ' ') !== false) { |
|
| 52 | + while (strpos($name, ' ') !== false) { |
|
| 53 | 53 | $name = str_replace(' ', ' ', $name); |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
| 57 | 57 | |
| 58 | - while(strpos($name, '..') !== false) { |
|
| 58 | + while (strpos($name, '..') !== false) { |
|
| 59 | 59 | $name = str_replace('..', '.', $name); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | * @param string[] $paths |
| 37 | 37 | * @throws FileHelper_Exception |
| 38 | 38 | */ |
| 39 | - public function __construct(array $paths=array()) |
|
| 39 | + public function __construct(array $paths = array()) |
|
| 40 | 40 | { |
| 41 | 41 | $this->addPaths($paths); |
| 42 | 42 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | */ |
| 50 | 50 | public function addPaths(array $paths) : PathsReducer |
| 51 | 51 | { |
| 52 | - foreach($paths as $path) { |
|
| 52 | + foreach ($paths as $path) { |
|
| 53 | 53 | $this->addPath($path); |
| 54 | 54 | } |
| 55 | 55 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | { |
| 67 | 67 | $path = FileHelper::normalizePath($path); |
| 68 | 68 | |
| 69 | - if(!in_array($path, $this->paths, true)) { |
|
| 69 | + if (!in_array($path, $this->paths, true)) { |
|
| 70 | 70 | $this->paths[] = $path; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -83,11 +83,11 @@ discard block |
||
| 83 | 83 | { |
| 84 | 84 | $split = $this->splitPaths(); |
| 85 | 85 | |
| 86 | - if(empty($split)) { |
|
| 86 | + if (empty($split)) { |
|
| 87 | 87 | return array(); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - while($this->shiftPart($split) === true) {} |
|
| 90 | + while ($this->shiftPart($split) === true) {} |
|
| 91 | 91 | |
| 92 | 92 | return $this->joinPaths($split); |
| 93 | 93 | } |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | $result = array(); |
| 102 | 102 | |
| 103 | 103 | foreach ($split as $entry) { |
| 104 | - if(!empty($entry)) { |
|
| 104 | + if (!empty($entry)) { |
|
| 105 | 105 | $result[] = implode('/', $entry); |
| 106 | 106 | } |
| 107 | 107 | } |
@@ -118,22 +118,22 @@ discard block |
||
| 118 | 118 | $current = null; |
| 119 | 119 | $result = array(); |
| 120 | 120 | |
| 121 | - foreach($split as $entry) |
|
| 121 | + foreach ($split as $entry) |
|
| 122 | 122 | { |
| 123 | - if(empty($entry)) { |
|
| 123 | + if (empty($entry)) { |
|
| 124 | 124 | return false; |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | $part = array_shift($entry); |
| 128 | - if(empty($entry)) { |
|
| 128 | + if (empty($entry)) { |
|
| 129 | 129 | return false; |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | - if($current === null) { |
|
| 132 | + if ($current === null) { |
|
| 133 | 133 | $current = $part; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | - if($part !== $current) { |
|
| 136 | + if ($part !== $current) { |
|
| 137 | 137 | return false; |
| 138 | 138 | } |
| 139 | 139 | |
@@ -152,9 +152,9 @@ discard block |
||
| 152 | 152 | { |
| 153 | 153 | $split = array(); |
| 154 | 154 | |
| 155 | - foreach($this->paths as $path) { |
|
| 155 | + foreach ($this->paths as $path) { |
|
| 156 | 156 | $entry = ConvertHelper::explodeTrim('/', $path); |
| 157 | - if(!empty($entry)) { |
|
| 157 | + if (!empty($entry)) { |
|
| 158 | 158 | $split[] = $entry; |
| 159 | 159 | } |
| 160 | 160 | } |
@@ -516,8 +516,7 @@ |
||
| 516 | 516 | if(isset($options['relative-path']) && $options['relative-path'] === true) |
| 517 | 517 | { |
| 518 | 518 | $finder->setPathmodeRelative(); |
| 519 | - } |
|
| 520 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 519 | + } else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 521 | 520 | { |
| 522 | 521 | $finder->setPathmodeAbsolute(); |
| 523 | 522 | } |
@@ -73,18 +73,18 @@ discard block |
||
| 73 | 73 | public const ERROR_PATH_NOT_WRITABLE = 340039; |
| 74 | 74 | public const ERROR_PATH_INVALID = 340040; |
| 75 | 75 | |
| 76 | - /** |
|
| 77 | - * Opens a serialized file and returns the unserialized data. |
|
| 78 | - * |
|
| 79 | - * @param string|PathInfoInterface|SplFileInfo $file |
|
| 80 | - * @throws FileHelper_Exception |
|
| 81 | - * @return array<int|string,mixed> |
|
| 82 | - * @see SerializedFile::parse() |
|
| 83 | - * |
|
| 84 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 85 | - * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
| 86 | - * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
| 87 | - */ |
|
| 76 | + /** |
|
| 77 | + * Opens a serialized file and returns the unserialized data. |
|
| 78 | + * |
|
| 79 | + * @param string|PathInfoInterface|SplFileInfo $file |
|
| 80 | + * @throws FileHelper_Exception |
|
| 81 | + * @return array<int|string,mixed> |
|
| 82 | + * @see SerializedFile::parse() |
|
| 83 | + * |
|
| 84 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 85 | + * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
| 86 | + * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
| 87 | + */ |
|
| 88 | 88 | public static function parseSerializedFile($file) : array |
| 89 | 89 | { |
| 90 | 90 | return SerializedFile::factory($file)->parse(); |
@@ -103,13 +103,13 @@ discard block |
||
| 103 | 103 | return FolderTree::delete($rootFolder); |
| 104 | 104 | } |
| 105 | 105 | |
| 106 | - /** |
|
| 107 | - * Create a folder, if it does not exist yet. |
|
| 108 | - * |
|
| 109 | - * @param string|PathInfoInterface $path |
|
| 110 | - * @throws FileHelper_Exception |
|
| 111 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 112 | - */ |
|
| 106 | + /** |
|
| 107 | + * Create a folder, if it does not exist yet. |
|
| 108 | + * |
|
| 109 | + * @param string|PathInfoInterface $path |
|
| 110 | + * @throws FileHelper_Exception |
|
| 111 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 112 | + */ |
|
| 113 | 113 | public static function createFolder($path) : FolderInfo |
| 114 | 114 | { |
| 115 | 115 | return self::getFolderInfo($path)->create(); |
@@ -138,36 +138,36 @@ discard block |
||
| 138 | 138 | FolderTree::copy($source, $target); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | - /** |
|
| 142 | - * Copies a file to the target location. Includes checks |
|
| 143 | - * for most error sources, like the source file not being |
|
| 144 | - * readable. Automatically creates the target folder if it |
|
| 145 | - * does not exist yet. |
|
| 146 | - * |
|
| 147 | - * @param string|PathInfoInterface|SplFileInfo $sourcePath |
|
| 148 | - * @param string|PathInfoInterface|SplFileInfo $targetPath |
|
| 149 | - * @throws FileHelper_Exception |
|
| 150 | - * |
|
| 151 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 152 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
| 153 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
| 154 | - * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
| 155 | - * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
| 156 | - */ |
|
| 141 | + /** |
|
| 142 | + * Copies a file to the target location. Includes checks |
|
| 143 | + * for most error sources, like the source file not being |
|
| 144 | + * readable. Automatically creates the target folder if it |
|
| 145 | + * does not exist yet. |
|
| 146 | + * |
|
| 147 | + * @param string|PathInfoInterface|SplFileInfo $sourcePath |
|
| 148 | + * @param string|PathInfoInterface|SplFileInfo $targetPath |
|
| 149 | + * @throws FileHelper_Exception |
|
| 150 | + * |
|
| 151 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
| 152 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
| 153 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
| 154 | + * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
| 155 | + * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
| 156 | + */ |
|
| 157 | 157 | public static function copyFile($sourcePath, $targetPath) : void |
| 158 | 158 | { |
| 159 | 159 | self::getFileInfo($sourcePath)->copyTo($targetPath); |
| 160 | 160 | } |
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Deletes the target file. Ignored if it cannot be found, |
|
| 164 | - * and throws an exception if it fails. |
|
| 165 | - * |
|
| 166 | - * @param string|PathInfoInterface|SplFileInfo $filePath |
|
| 167 | - * @throws FileHelper_Exception |
|
| 168 | - * |
|
| 169 | - * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 170 | - */ |
|
| 162 | + /** |
|
| 163 | + * Deletes the target file. Ignored if it cannot be found, |
|
| 164 | + * and throws an exception if it fails. |
|
| 165 | + * |
|
| 166 | + * @param string|PathInfoInterface|SplFileInfo $filePath |
|
| 167 | + * @throws FileHelper_Exception |
|
| 168 | + * |
|
| 169 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
| 170 | + */ |
|
| 171 | 171 | public static function deleteFile($filePath) : void |
| 172 | 172 | { |
| 173 | 173 | self::getFileInfo($filePath)->delete(); |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | */ |
| 289 | 289 | public static function isPHPFile($filePath) : bool |
| 290 | 290 | { |
| 291 | - return self::getExtension($filePath) === 'php'; |
|
| 291 | + return self::getExtension($filePath) === 'php'; |
|
| 292 | 292 | } |
| 293 | 293 | |
| 294 | 294 | /** |
@@ -354,16 +354,16 @@ discard block |
||
| 354 | 354 | ->parse(); |
| 355 | 355 | } |
| 356 | 356 | |
| 357 | - /** |
|
| 358 | - * Corrects common formatting mistakes when users enter |
|
| 359 | - * file names, like too many spaces, dots and the like. |
|
| 360 | - * |
|
| 361 | - * NOTE: if the file name contains a path, the path is |
|
| 362 | - * stripped, leaving only the file name. |
|
| 363 | - * |
|
| 364 | - * @param string $name |
|
| 365 | - * @return string |
|
| 366 | - */ |
|
| 357 | + /** |
|
| 358 | + * Corrects common formatting mistakes when users enter |
|
| 359 | + * file names, like too many spaces, dots and the like. |
|
| 360 | + * |
|
| 361 | + * NOTE: if the file name contains a path, the path is |
|
| 362 | + * stripped, leaving only the file name. |
|
| 363 | + * |
|
| 364 | + * @param string $name |
|
| 365 | + * @return string |
|
| 366 | + */ |
|
| 367 | 367 | public static function fixFileName(string $name) : string |
| 368 | 368 | { |
| 369 | 369 | return NameFixer::fixName($name); |
@@ -423,23 +423,23 @@ discard block |
||
| 423 | 423 | return self::findFiles($targetFolder, array('php'), $options); |
| 424 | 424 | } |
| 425 | 425 | |
| 426 | - /** |
|
| 427 | - * Finds files according to the specified options. |
|
| 428 | - * |
|
| 429 | - * NOTE: This method only exists for backwards compatibility. |
|
| 430 | - * Use the {@see FileHelper::createFileFinder()} method instead, |
|
| 431 | - * which offers an object-oriented interface that is much easier |
|
| 432 | - * to use. |
|
| 433 | - * |
|
| 434 | - * @param string|PathInfoInterface|SplFileInfo $targetFolder |
|
| 435 | - * @param string[] $extensions |
|
| 436 | - * @param array<string,mixed> $options |
|
| 437 | - * @throws FileHelper_Exception |
|
| 438 | - * @return string[] |
|
| 439 | - * |
|
| 440 | - * @see FileHelper::createFileFinder() |
|
| 441 | - * @deprecated Use the file finder instead. |
|
| 442 | - */ |
|
| 426 | + /** |
|
| 427 | + * Finds files according to the specified options. |
|
| 428 | + * |
|
| 429 | + * NOTE: This method only exists for backwards compatibility. |
|
| 430 | + * Use the {@see FileHelper::createFileFinder()} method instead, |
|
| 431 | + * which offers an object-oriented interface that is much easier |
|
| 432 | + * to use. |
|
| 433 | + * |
|
| 434 | + * @param string|PathInfoInterface|SplFileInfo $targetFolder |
|
| 435 | + * @param string[] $extensions |
|
| 436 | + * @param array<string,mixed> $options |
|
| 437 | + * @throws FileHelper_Exception |
|
| 438 | + * @return string[] |
|
| 439 | + * |
|
| 440 | + * @see FileHelper::createFileFinder() |
|
| 441 | + * @deprecated Use the file finder instead. |
|
| 442 | + */ |
|
| 443 | 443 | public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
| 444 | 444 | { |
| 445 | 445 | $finder = self::createFileFinder($targetFolder); |
@@ -498,13 +498,13 @@ discard block |
||
| 498 | 498 | return self::$unicodeHandling; |
| 499 | 499 | } |
| 500 | 500 | |
| 501 | - /** |
|
| 502 | - * Normalizes the slash style in a file or folder path, |
|
| 503 | - * by replacing any anti-slashes with forward slashes. |
|
| 504 | - * |
|
| 505 | - * @param string $path |
|
| 506 | - * @return string |
|
| 507 | - */ |
|
| 501 | + /** |
|
| 502 | + * Normalizes the slash style in a file or folder path, |
|
| 503 | + * by replacing any anti-slashes with forward slashes. |
|
| 504 | + * |
|
| 505 | + * @param string $path |
|
| 506 | + * @return string |
|
| 507 | + */ |
|
| 508 | 508 | public static function normalizePath(string $path) : string |
| 509 | 509 | { |
| 510 | 510 | return str_replace(array('\\', '//'), array('/', '/'), $path); |
@@ -629,70 +629,70 @@ discard block |
||
| 629 | 629 | ->getPaths(); |
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - /** |
|
| 633 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
| 634 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 635 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
| 636 | - * be modified at runtime, they are the hard limits for uploads. |
|
| 637 | - * |
|
| 638 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 639 | - * |
|
| 640 | - * @return int Will return <code>-1</code> if no limit. |
|
| 641 | - */ |
|
| 632 | + /** |
|
| 633 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
| 634 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
| 635 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
| 636 | + * be modified at runtime, they are the hard limits for uploads. |
|
| 637 | + * |
|
| 638 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
| 639 | + * |
|
| 640 | + * @return int Will return <code>-1</code> if no limit. |
|
| 641 | + */ |
|
| 642 | 642 | public static function getMaxUploadFilesize() : int |
| 643 | 643 | { |
| 644 | 644 | return UploadFileSizeInfo::getFileSize(); |
| 645 | 645 | } |
| 646 | 646 | |
| 647 | - /** |
|
| 648 | - * Makes a path relative using a folder depth: will reduce the |
|
| 649 | - * length of the path so that only the amount of folders defined |
|
| 650 | - * in the <code>$depth</code> attribute are shown below the actual |
|
| 651 | - * folder or file in the path. |
|
| 652 | - * |
|
| 653 | - * @param string $path The absolute or relative path |
|
| 654 | - * @param int $depth The folder depth to reduce the path to |
|
| 655 | - * @return string |
|
| 656 | - */ |
|
| 647 | + /** |
|
| 648 | + * Makes a path relative using a folder depth: will reduce the |
|
| 649 | + * length of the path so that only the amount of folders defined |
|
| 650 | + * in the <code>$depth</code> attribute are shown below the actual |
|
| 651 | + * folder or file in the path. |
|
| 652 | + * |
|
| 653 | + * @param string $path The absolute or relative path |
|
| 654 | + * @param int $depth The folder depth to reduce the path to |
|
| 655 | + * @return string |
|
| 656 | + */ |
|
| 657 | 657 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
| 658 | 658 | { |
| 659 | 659 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 660 | 660 | } |
| 661 | 661 | |
| 662 | - /** |
|
| 663 | - * Makes the specified path relative to another path, |
|
| 664 | - * by removing one from the other if found. Also |
|
| 665 | - * normalizes the path to use forward slashes. |
|
| 666 | - * |
|
| 667 | - * Example: |
|
| 668 | - * |
|
| 669 | - * <pre> |
|
| 670 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 671 | - * </pre> |
|
| 672 | - * |
|
| 673 | - * Result: <code>to/file.txt</code> |
|
| 674 | - * |
|
| 675 | - * @param string $path |
|
| 676 | - * @param string $relativeTo |
|
| 677 | - * @return string |
|
| 678 | - */ |
|
| 662 | + /** |
|
| 663 | + * Makes the specified path relative to another path, |
|
| 664 | + * by removing one from the other if found. Also |
|
| 665 | + * normalizes the path to use forward slashes. |
|
| 666 | + * |
|
| 667 | + * Example: |
|
| 668 | + * |
|
| 669 | + * <pre> |
|
| 670 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
| 671 | + * </pre> |
|
| 672 | + * |
|
| 673 | + * Result: <code>to/file.txt</code> |
|
| 674 | + * |
|
| 675 | + * @param string $path |
|
| 676 | + * @param string $relativeTo |
|
| 677 | + * @return string |
|
| 678 | + */ |
|
| 679 | 679 | public static function relativizePath(string $path, string $relativeTo) : string |
| 680 | 680 | { |
| 681 | 681 | return PathRelativizer::relativize($path, $relativeTo); |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - /** |
|
| 685 | - * Checks that the target file exists, and throws an exception |
|
| 686 | - * if it does not. |
|
| 687 | - * |
|
| 688 | - * @param string|SplFileInfo $path |
|
| 689 | - * @param int|NULL $errorCode Optional custom error code |
|
| 690 | - * @throws FileHelper_Exception |
|
| 691 | - * @return string The real path to the file |
|
| 692 | - * |
|
| 693 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 694 | - * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
|
| 695 | - */ |
|
| 684 | + /** |
|
| 685 | + * Checks that the target file exists, and throws an exception |
|
| 686 | + * if it does not. |
|
| 687 | + * |
|
| 688 | + * @param string|SplFileInfo $path |
|
| 689 | + * @param int|NULL $errorCode Optional custom error code |
|
| 690 | + * @throws FileHelper_Exception |
|
| 691 | + * @return string The real path to the file |
|
| 692 | + * |
|
| 693 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 694 | + * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
|
| 695 | + */ |
|
| 696 | 696 | public static function requireFileExists($path, ?int $errorCode=null) : string |
| 697 | 697 | { |
| 698 | 698 | return self::getPathInfo($path) |
@@ -715,18 +715,18 @@ discard block |
||
| 715 | 715 | ->getPath(); |
| 716 | 716 | } |
| 717 | 717 | |
| 718 | - /** |
|
| 719 | - * Reads a specific line number from the target file and returns its |
|
| 720 | - * contents, if the file has such a line. Does so with little memory |
|
| 721 | - * usage, as the file is not read entirely into memory. |
|
| 722 | - * |
|
| 723 | - * @param string|PathInfoInterface|SplFileInfo $path |
|
| 724 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 725 | - * @return string|NULL Will return null if the requested line does not exist. |
|
| 726 | - * @throws FileHelper_Exception |
|
| 727 | - * |
|
| 728 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 729 | - */ |
|
| 718 | + /** |
|
| 719 | + * Reads a specific line number from the target file and returns its |
|
| 720 | + * contents, if the file has such a line. Does so with little memory |
|
| 721 | + * usage, as the file is not read entirely into memory. |
|
| 722 | + * |
|
| 723 | + * @param string|PathInfoInterface|SplFileInfo $path |
|
| 724 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
| 725 | + * @return string|NULL Will return null if the requested line does not exist. |
|
| 726 | + * @throws FileHelper_Exception |
|
| 727 | + * |
|
| 728 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 729 | + */ |
|
| 730 | 730 | public static function getLineFromFile($path, int $lineNumber) : ?string |
| 731 | 731 | { |
| 732 | 732 | return self::getFileInfo($path)->getLine($lineNumber); |
@@ -792,33 +792,33 @@ discard block |
||
| 792 | 792 | ->getLines($amount); |
| 793 | 793 | } |
| 794 | 794 | |
| 795 | - /** |
|
| 796 | - * Reads all content from a file. |
|
| 797 | - * |
|
| 798 | - * @param string|PathInfoInterface|SplFileInfo $filePath |
|
| 799 | - * @throws FileHelper_Exception |
|
| 800 | - * @return string |
|
| 801 | - * |
|
| 802 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 803 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 804 | - */ |
|
| 795 | + /** |
|
| 796 | + * Reads all content from a file. |
|
| 797 | + * |
|
| 798 | + * @param string|PathInfoInterface|SplFileInfo $filePath |
|
| 799 | + * @throws FileHelper_Exception |
|
| 800 | + * @return string |
|
| 801 | + * |
|
| 802 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
| 803 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
| 804 | + */ |
|
| 805 | 805 | public static function readContents($filePath) : string |
| 806 | 806 | { |
| 807 | 807 | return self::getFileInfo($filePath)->getContents(); |
| 808 | 808 | } |
| 809 | 809 | |
| 810 | - /** |
|
| 811 | - * Ensures that the target path exists on disk, and is a folder. |
|
| 812 | - * |
|
| 813 | - * @param string|PathInfoInterface|SplFileInfo $path |
|
| 814 | - * @return string The real path, with normalized slashes. |
|
| 815 | - * @throws FileHelper_Exception |
|
| 816 | - * |
|
| 817 | - * @see FileHelper::normalizePath() |
|
| 818 | - * |
|
| 819 | - * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
| 820 | - * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 821 | - */ |
|
| 810 | + /** |
|
| 811 | + * Ensures that the target path exists on disk, and is a folder. |
|
| 812 | + * |
|
| 813 | + * @param string|PathInfoInterface|SplFileInfo $path |
|
| 814 | + * @return string The real path, with normalized slashes. |
|
| 815 | + * @throws FileHelper_Exception |
|
| 816 | + * |
|
| 817 | + * @see FileHelper::normalizePath() |
|
| 818 | + * |
|
| 819 | + * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
| 820 | + * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 821 | + */ |
|
| 822 | 822 | public static function requireFolderExists($path) : string |
| 823 | 823 | { |
| 824 | 824 | return self::getFolderInfo($path) |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | public static function detectMimeType($fileName) : ?string |
| 208 | 208 | { |
| 209 | 209 | $ext = self::getExtension($fileName); |
| 210 | - if(empty($ext)) { |
|
| 210 | + if (empty($ext)) { |
|
| 211 | 211 | return null; |
| 212 | 212 | } |
| 213 | 213 | |
@@ -251,7 +251,7 @@ discard block |
||
| 251 | 251 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 252 | 252 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
| 253 | 253 | */ |
| 254 | - public static function sendFile($filePath, ?string $fileName = null, bool $asAttachment=true) : void |
|
| 254 | + public static function sendFile($filePath, ?string $fileName = null, bool $asAttachment = true) : void |
|
| 255 | 255 | { |
| 256 | 256 | self::getFileInfo($filePath)->getDownloader()->send($fileName, $asAttachment); |
| 257 | 257 | } |
@@ -268,7 +268,7 @@ discard block |
||
| 268 | 268 | * @throws FileHelper_Exception |
| 269 | 269 | * @see FileHelper::ERROR_CANNOT_OPEN_URL |
| 270 | 270 | */ |
| 271 | - public static function downloadFile(string $url, int $timeout=0, bool $SSLEnabled=false) : string |
|
| 271 | + public static function downloadFile(string $url, int $timeout = 0, bool $SSLEnabled = false) : string |
|
| 272 | 272 | { |
| 273 | 273 | return FileDownloader::factory($url) |
| 274 | 274 | ->setTimeout($timeout) |
@@ -323,7 +323,7 @@ discard block |
||
| 323 | 323 | { |
| 324 | 324 | $info = self::getPathInfo($pathOrDirIterator); |
| 325 | 325 | |
| 326 | - if($extension === true || $info instanceof FolderInfo) |
|
| 326 | + if ($extension === true || $info instanceof FolderInfo) |
|
| 327 | 327 | { |
| 328 | 328 | return $info->getName(); |
| 329 | 329 | } |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
| 346 | 346 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
| 347 | 347 | */ |
| 348 | - public static function parseJSONFile($file, string $targetEncoding='', $sourceEncoding=null) : array |
|
| 348 | + public static function parseJSONFile($file, string $targetEncoding = '', $sourceEncoding = null) : array |
|
| 349 | 349 | { |
| 350 | 350 | return JSONFile::factory($file) |
| 351 | 351 | ->setTargetEncoding($targetEncoding) |
@@ -398,7 +398,7 @@ discard block |
||
| 398 | 398 | * @throws FileHelper_Exception |
| 399 | 399 | * @see FileHelper::createFileFinder() |
| 400 | 400 | */ |
| 401 | - public static function findHTMLFiles($targetFolder, array $options=array()) : array |
|
| 401 | + public static function findHTMLFiles($targetFolder, array $options = array()) : array |
|
| 402 | 402 | { |
| 403 | 403 | return self::findFiles($targetFolder, array('html'), $options); |
| 404 | 404 | } |
@@ -417,7 +417,7 @@ discard block |
||
| 417 | 417 | * @throws FileHelper_Exception |
| 418 | 418 | * @see FileHelper::createFileFinder() |
| 419 | 419 | */ |
| 420 | - public static function findPHPFiles($targetFolder, array $options=array()) : array |
|
| 420 | + public static function findPHPFiles($targetFolder, array $options = array()) : array |
|
| 421 | 421 | { |
| 422 | 422 | return self::findFiles($targetFolder, array('php'), $options); |
| 423 | 423 | } |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | * @see FileHelper::createFileFinder() |
| 440 | 440 | * @deprecated Use the file finder instead. |
| 441 | 441 | */ |
| 442 | - public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
|
| 442 | + public static function findFiles($targetFolder, array $extensions = array(), array $options = array()) : array |
|
| 443 | 443 | { |
| 444 | 444 | $finder = self::createFileFinder($targetFolder); |
| 445 | 445 | |
@@ -449,16 +449,16 @@ discard block |
||
| 449 | 449 | |
| 450 | 450 | $finder->setPathmodeStrip(); |
| 451 | 451 | |
| 452 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 452 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 453 | 453 | { |
| 454 | 454 | $finder->setPathmodeRelative(); |
| 455 | 455 | } |
| 456 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 456 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 457 | 457 | { |
| 458 | 458 | $finder->setPathmodeAbsolute(); |
| 459 | 459 | } |
| 460 | 460 | |
| 461 | - if(isset($options['strip-extension'])) |
|
| 461 | + if (isset($options['strip-extension'])) |
|
| 462 | 462 | { |
| 463 | 463 | $finder->stripExtensions(); |
| 464 | 464 | } |
@@ -477,16 +477,16 @@ discard block |
||
| 477 | 477 | * @return string |
| 478 | 478 | * @throws FileHelper_Exception |
| 479 | 479 | */ |
| 480 | - public static function removeExtension($filename, bool $keepPath=false) : string |
|
| 480 | + public static function removeExtension($filename, bool $keepPath = false) : string |
|
| 481 | 481 | { |
| 482 | 482 | $path = self::getPathInfo($filename); |
| 483 | 483 | |
| 484 | - if($path instanceof FileInfo) |
|
| 484 | + if ($path instanceof FileInfo) |
|
| 485 | 485 | { |
| 486 | 486 | return $path->removeExtension($keepPath); |
| 487 | 487 | } |
| 488 | 488 | |
| 489 | - if($keepPath) |
|
| 489 | + if ($keepPath) |
|
| 490 | 490 | { |
| 491 | 491 | return $filename; |
| 492 | 492 | } |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | |
| 502 | 502 | public static function createUnicodeHandling() : UnicodeHandling |
| 503 | 503 | { |
| 504 | - if(!isset(self::$unicodeHandling)) |
|
| 504 | + if (!isset(self::$unicodeHandling)) |
|
| 505 | 505 | { |
| 506 | 506 | self::$unicodeHandling = new UnicodeHandling(); |
| 507 | 507 | } |
@@ -535,7 +535,7 @@ discard block |
||
| 535 | 535 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 536 | 536 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 537 | 537 | */ |
| 538 | - public static function saveAsJSON($data, $file, bool $pretty=false) : JSONFile |
|
| 538 | + public static function saveAsJSON($data, $file, bool $pretty = false) : JSONFile |
|
| 539 | 539 | { |
| 540 | 540 | return JSONFile::factory($file)->putData($data, $pretty); |
| 541 | 541 | } |
@@ -553,7 +553,7 @@ discard block |
||
| 553 | 553 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 554 | 554 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 555 | 555 | */ |
| 556 | - public static function saveFile($filePath, string $content='') : FileInfo |
|
| 556 | + public static function saveFile($filePath, string $content = '') : FileInfo |
|
| 557 | 557 | { |
| 558 | 558 | return self::getFileInfo($filePath)->putContents($content); |
| 559 | 559 | } |
@@ -665,7 +665,7 @@ discard block |
||
| 665 | 665 | * @param int $depth The folder depth to reduce the path to |
| 666 | 666 | * @return string |
| 667 | 667 | */ |
| 668 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
| 668 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
| 669 | 669 | { |
| 670 | 670 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 671 | 671 | } |
@@ -704,7 +704,7 @@ discard block |
||
| 704 | 704 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 705 | 705 | * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
| 706 | 706 | */ |
| 707 | - public static function requireFileExists($path, ?int $errorCode=null) : string |
|
| 707 | + public static function requireFileExists($path, ?int $errorCode = null) : string |
|
| 708 | 708 | { |
| 709 | 709 | return self::getPathInfo($path) |
| 710 | 710 | ->requireIsFile() |
@@ -718,7 +718,7 @@ discard block |
||
| 718 | 718 | * @return string |
| 719 | 719 | * @throws FileHelper_Exception |
| 720 | 720 | */ |
| 721 | - public static function requireFileReadable($path, ?int $errorCode=null) : string |
|
| 721 | + public static function requireFileReadable($path, ?int $errorCode = null) : string |
|
| 722 | 722 | { |
| 723 | 723 | return self::getPathInfo($path) |
| 724 | 724 | ->requireIsFile() |
@@ -796,7 +796,7 @@ discard block |
||
| 796 | 796 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 797 | 797 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
| 798 | 798 | */ |
| 799 | - public static function readLines($filePath, int $amount=0) : array |
|
| 799 | + public static function readLines($filePath, int $amount = 0) : array |
|
| 800 | 800 | { |
| 801 | 801 | return self::getFileInfo($filePath) |
| 802 | 802 | ->getLineReader() |
@@ -846,7 +846,7 @@ discard block |
||
| 846 | 846 | * |
| 847 | 847 | * @throws FileHelper_Exception |
| 848 | 848 | */ |
| 849 | - public static function createPathsReducer(array $paths=array()) : PathsReducer |
|
| 849 | + public static function createPathsReducer(array $paths = array()) : PathsReducer |
|
| 850 | 850 | { |
| 851 | 851 | return new PathsReducer($paths); |
| 852 | 852 | } |
@@ -74,7 +74,7 @@ |
||
| 74 | 74 | * @param bool $enabled |
| 75 | 75 | * @return $this |
| 76 | 76 | */ |
| 77 | - public function prop(string $name, bool $enabled=true) : self |
|
| 77 | + public function prop(string $name, bool $enabled = true) : self |
|
| 78 | 78 | { |
| 79 | 79 | $this->getAttributes()->prop($name, $enabled); |
| 80 | 80 | return $this; |
@@ -25,9 +25,9 @@ discard block |
||
| 25 | 25 | */ |
| 26 | 26 | trait Traits_Classable |
| 27 | 27 | { |
| 28 | - /** |
|
| 29 | - * @var string[] |
|
| 30 | - */ |
|
| 28 | + /** |
|
| 29 | + * @var string[] |
|
| 30 | + */ |
|
| 31 | 31 | protected array $classes = array(); |
| 32 | 32 | |
| 33 | 33 | public function hasClasses() : bool |
@@ -82,30 +82,30 @@ discard block |
||
| 82 | 82 | return $this; |
| 83 | 83 | } |
| 84 | 84 | |
| 85 | - /** |
|
| 86 | - * Retrieves a list of all classes, if any. |
|
| 87 | - * |
|
| 88 | - * @return string[] |
|
| 89 | - */ |
|
| 85 | + /** |
|
| 86 | + * Retrieves a list of all classes, if any. |
|
| 87 | + * |
|
| 88 | + * @return string[] |
|
| 89 | + */ |
|
| 90 | 90 | public function getClasses() : array |
| 91 | 91 | { |
| 92 | 92 | return $this->classes; |
| 93 | 93 | } |
| 94 | 94 | |
| 95 | - /** |
|
| 96 | - * Renders the class names list as space-separated string for use in an HTML tag. |
|
| 97 | - * |
|
| 98 | - * @return string |
|
| 99 | - */ |
|
| 95 | + /** |
|
| 96 | + * Renders the class names list as space-separated string for use in an HTML tag. |
|
| 97 | + * |
|
| 98 | + * @return string |
|
| 99 | + */ |
|
| 100 | 100 | public function classesToString() : string |
| 101 | 101 | { |
| 102 | 102 | return implode(' ', $this->classes); |
| 103 | 103 | } |
| 104 | 104 | |
| 105 | - /** |
|
| 106 | - * Renders the "class" attribute string for inserting into an HTML tag. |
|
| 107 | - * @return string |
|
| 108 | - */ |
|
| 105 | + /** |
|
| 106 | + * Renders the "class" attribute string for inserting into an HTML tag. |
|
| 107 | + * @return string |
|
| 108 | + */ |
|
| 109 | 109 | public function classesToAttribute() : string |
| 110 | 110 | { |
| 111 | 111 | if(!empty($this->classes)) |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function addClass($name) |
| 43 | 43 | { |
| 44 | - if(!in_array($name, $this->classes, true)) { |
|
| 44 | + if (!in_array($name, $this->classes, true)) { |
|
| 45 | 45 | $this->classes[] = $name; |
| 46 | 46 | } |
| 47 | 47 | |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | */ |
| 55 | 55 | public function addClasses(array $names) : self |
| 56 | 56 | { |
| 57 | - foreach($names as $name) { |
|
| 57 | + foreach ($names as $name) { |
|
| 58 | 58 | $this->addClass($name); |
| 59 | 59 | } |
| 60 | 60 | |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | { |
| 75 | 75 | $idx = array_search($name, $this->classes, true); |
| 76 | 76 | |
| 77 | - if($idx !== false) { |
|
| 77 | + if ($idx !== false) { |
|
| 78 | 78 | unset($this->classes[$idx]); |
| 79 | 79 | sort($this->classes); |
| 80 | 80 | } |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | */ |
| 109 | 109 | public function classesToAttribute() : string |
| 110 | 110 | { |
| 111 | - if(!empty($this->classes)) |
|
| 111 | + if (!empty($this->classes)) |
|
| 112 | 112 | { |
| 113 | 113 | return sprintf( |
| 114 | 114 | ' class="%s" ', |
@@ -26,9 +26,9 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | trait Traits_Optionable |
| 28 | 28 | { |
| 29 | - /** |
|
| 30 | - * @var array<string,mixed>|NULL |
|
| 31 | - */ |
|
| 29 | + /** |
|
| 30 | + * @var array<string,mixed>|NULL |
|
| 31 | + */ |
|
| 32 | 32 | protected ?array $options = null; |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -49,13 +49,13 @@ discard block |
||
| 49 | 49 | return $this; |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * Sets a collection of options at once, from an |
|
| 54 | - * associative array. |
|
| 55 | - * |
|
| 56 | - * @param array<string,mixed> $options |
|
| 57 | - * @return $this |
|
| 58 | - */ |
|
| 52 | + /** |
|
| 53 | + * Sets a collection of options at once, from an |
|
| 54 | + * associative array. |
|
| 55 | + * |
|
| 56 | + * @param array<string,mixed> $options |
|
| 57 | + * @return $this |
|
| 58 | + */ |
|
| 59 | 59 | public function setOptions(array $options) : self |
| 60 | 60 | { |
| 61 | 61 | foreach($options as $name => $value) { |
@@ -65,16 +65,16 @@ discard block |
||
| 65 | 65 | return $this; |
| 66 | 66 | } |
| 67 | 67 | |
| 68 | - /** |
|
| 69 | - * Retrieves an option's value. |
|
| 70 | - * |
|
| 71 | - * NOTE: Use the specialized type getters to ensure an option |
|
| 72 | - * contains the expected type (for ex. getArrayOption()). |
|
| 73 | - * |
|
| 74 | - * @param string $name |
|
| 75 | - * @param mixed $default The default value to return if the option does not exist. |
|
| 76 | - * @return mixed |
|
| 77 | - */ |
|
| 68 | + /** |
|
| 69 | + * Retrieves an option's value. |
|
| 70 | + * |
|
| 71 | + * NOTE: Use the specialized type getters to ensure an option |
|
| 72 | + * contains the expected type (for ex. getArrayOption()). |
|
| 73 | + * |
|
| 74 | + * @param string $name |
|
| 75 | + * @param mixed $default The default value to return if the option does not exist. |
|
| 76 | + * @return mixed |
|
| 77 | + */ |
|
| 78 | 78 | public function getOption(string $name, $default=null) |
| 79 | 79 | { |
| 80 | 80 | if(!isset($this->options)) |
@@ -85,16 +85,16 @@ discard block |
||
| 85 | 85 | return $this->options[$name] ?? $default; |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * Enforces that the option value is a string. Numbers are converted |
|
| 90 | - * to string, strings are passed through, and all other types will |
|
| 91 | - * return the default value. The default value is also returned if |
|
| 92 | - * the string is empty. |
|
| 93 | - * |
|
| 94 | - * @param string $name |
|
| 95 | - * @param string $default Used if the option does not exist, is invalid, or empty. |
|
| 96 | - * @return string |
|
| 97 | - */ |
|
| 88 | + /** |
|
| 89 | + * Enforces that the option value is a string. Numbers are converted |
|
| 90 | + * to string, strings are passed through, and all other types will |
|
| 91 | + * return the default value. The default value is also returned if |
|
| 92 | + * the string is empty. |
|
| 93 | + * |
|
| 94 | + * @param string $name |
|
| 95 | + * @param string $default Used if the option does not exist, is invalid, or empty. |
|
| 96 | + * @return string |
|
| 97 | + */ |
|
| 98 | 98 | public function getStringOption(string $name, string $default='') : string |
| 99 | 99 | { |
| 100 | 100 | $value = $this->getOption($name, false); |
@@ -126,15 +126,15 @@ discard block |
||
| 126 | 126 | return $default; |
| 127 | 127 | } |
| 128 | 128 | |
| 129 | - /** |
|
| 130 | - * Treats the option value as an integer value: will return |
|
| 131 | - * valid integer values (also from integer strings), or the |
|
| 132 | - * default value otherwise. |
|
| 133 | - * |
|
| 134 | - * @param string $name |
|
| 135 | - * @param int $default |
|
| 136 | - * @return int |
|
| 137 | - */ |
|
| 129 | + /** |
|
| 130 | + * Treats the option value as an integer value: will return |
|
| 131 | + * valid integer values (also from integer strings), or the |
|
| 132 | + * default value otherwise. |
|
| 133 | + * |
|
| 134 | + * @param string $name |
|
| 135 | + * @param int $default |
|
| 136 | + * @return int |
|
| 137 | + */ |
|
| 138 | 138 | public function getIntOption(string $name, int $default=0) : int |
| 139 | 139 | { |
| 140 | 140 | $value = $this->getOption($name); |
@@ -145,14 +145,14 @@ discard block |
||
| 145 | 145 | return $default; |
| 146 | 146 | } |
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Treats an option as an array, and returns its value |
|
| 150 | - * only if it contains an array - otherwise, an empty |
|
| 151 | - * array is returned. |
|
| 152 | - * |
|
| 153 | - * @param string $name |
|
| 154 | - * @return array<int|string,mixed> |
|
| 155 | - */ |
|
| 148 | + /** |
|
| 149 | + * Treats an option as an array, and returns its value |
|
| 150 | + * only if it contains an array - otherwise, an empty |
|
| 151 | + * array is returned. |
|
| 152 | + * |
|
| 153 | + * @param string $name |
|
| 154 | + * @return array<int|string,mixed> |
|
| 155 | + */ |
|
| 156 | 156 | public function getArrayOption(string $name) : array |
| 157 | 157 | { |
| 158 | 158 | $val = $this->getOption($name); |
@@ -163,13 +163,13 @@ discard block |
||
| 163 | 163 | return array(); |
| 164 | 164 | } |
| 165 | 165 | |
| 166 | - /** |
|
| 167 | - * Checks whether the specified option exists - even |
|
| 168 | - * if it has a NULL value. |
|
| 169 | - * |
|
| 170 | - * @param string $name |
|
| 171 | - * @return bool |
|
| 172 | - */ |
|
| 166 | + /** |
|
| 167 | + * Checks whether the specified option exists - even |
|
| 168 | + * if it has a NULL value. |
|
| 169 | + * |
|
| 170 | + * @param string $name |
|
| 171 | + * @return bool |
|
| 172 | + */ |
|
| 173 | 173 | public function hasOption(string $name) : bool |
| 174 | 174 | { |
| 175 | 175 | if(!isset($this->options)) { |
@@ -179,11 +179,11 @@ discard block |
||
| 179 | 179 | return array_key_exists($name, $this->options); |
| 180 | 180 | } |
| 181 | 181 | |
| 182 | - /** |
|
| 183 | - * Returns all options in one associative array. |
|
| 184 | - * |
|
| 185 | - * @return array<string,mixed> |
|
| 186 | - */ |
|
| 182 | + /** |
|
| 183 | + * Returns all options in one associative array. |
|
| 184 | + * |
|
| 185 | + * @return array<string,mixed> |
|
| 186 | + */ |
|
| 187 | 187 | public function getOptions() : array |
| 188 | 188 | { |
| 189 | 189 | if(!isset($this->options)) { |
@@ -193,13 +193,13 @@ discard block |
||
| 193 | 193 | return $this->options; |
| 194 | 194 | } |
| 195 | 195 | |
| 196 | - /** |
|
| 197 | - * Checks whether the option's value is the one specified. |
|
| 198 | - * |
|
| 199 | - * @param string $name |
|
| 200 | - * @param mixed $value |
|
| 201 | - * @return bool |
|
| 202 | - */ |
|
| 196 | + /** |
|
| 197 | + * Checks whether the option's value is the one specified. |
|
| 198 | + * |
|
| 199 | + * @param string $name |
|
| 200 | + * @param mixed $value |
|
| 201 | + * @return bool |
|
| 202 | + */ |
|
| 203 | 203 | public function isOption(string $name, $value) : bool |
| 204 | 204 | { |
| 205 | 205 | return $this->getOption($name) === $value; |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | public function setOption(string $name, $value) : self |
| 43 | 43 | { |
| 44 | - if(!isset($this->options)) { |
|
| 44 | + if (!isset($this->options)) { |
|
| 45 | 45 | $this->options = $this->getDefaultOptions(); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | */ |
| 59 | 59 | public function setOptions(array $options) : self |
| 60 | 60 | { |
| 61 | - foreach($options as $name => $value) { |
|
| 61 | + foreach ($options as $name => $value) { |
|
| 62 | 62 | $this->setOption($name, $value); |
| 63 | 63 | } |
| 64 | 64 | |
@@ -75,9 +75,9 @@ discard block |
||
| 75 | 75 | * @param mixed $default The default value to return if the option does not exist. |
| 76 | 76 | * @return mixed |
| 77 | 77 | */ |
| 78 | - public function getOption(string $name, $default=null) |
|
| 78 | + public function getOption(string $name, $default = null) |
|
| 79 | 79 | { |
| 80 | - if(!isset($this->options)) |
|
| 80 | + if (!isset($this->options)) |
|
| 81 | 81 | { |
| 82 | 82 | $this->options = $this->getDefaultOptions(); |
| 83 | 83 | } |
@@ -95,11 +95,11 @@ discard block |
||
| 95 | 95 | * @param string $default Used if the option does not exist, is invalid, or empty. |
| 96 | 96 | * @return string |
| 97 | 97 | */ |
| 98 | - public function getStringOption(string $name, string $default='') : string |
|
| 98 | + public function getStringOption(string $name, string $default = '') : string |
|
| 99 | 99 | { |
| 100 | 100 | $value = $this->getOption($name, false); |
| 101 | 101 | |
| 102 | - if((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
| 102 | + if ((is_string($value) || is_numeric($value)) && !empty($value)) { |
|
| 103 | 103 | return (string)$value; |
| 104 | 104 | } |
| 105 | 105 | |
@@ -116,9 +116,9 @@ discard block |
||
| 116 | 116 | * @param bool $default |
| 117 | 117 | * @return bool |
| 118 | 118 | */ |
| 119 | - public function getBoolOption(string $name, bool $default=false) : bool |
|
| 119 | + public function getBoolOption(string $name, bool $default = false) : bool |
|
| 120 | 120 | { |
| 121 | - if($this->getOption($name) === true) |
|
| 121 | + if ($this->getOption($name) === true) |
|
| 122 | 122 | { |
| 123 | 123 | return true; |
| 124 | 124 | } |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | * @param int $default |
| 136 | 136 | * @return int |
| 137 | 137 | */ |
| 138 | - public function getIntOption(string $name, int $default=0) : int |
|
| 138 | + public function getIntOption(string $name, int $default = 0) : int |
|
| 139 | 139 | { |
| 140 | 140 | $value = $this->getOption($name); |
| 141 | - if(ConvertHelper::isInteger($value)) { |
|
| 141 | + if (ConvertHelper::isInteger($value)) { |
|
| 142 | 142 | return (int)$value; |
| 143 | 143 | } |
| 144 | 144 | |
@@ -156,7 +156,7 @@ discard block |
||
| 156 | 156 | public function getArrayOption(string $name) : array |
| 157 | 157 | { |
| 158 | 158 | $val = $this->getOption($name); |
| 159 | - if(is_array($val)) { |
|
| 159 | + if (is_array($val)) { |
|
| 160 | 160 | return $val; |
| 161 | 161 | } |
| 162 | 162 | |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | */ |
| 173 | 173 | public function hasOption(string $name) : bool |
| 174 | 174 | { |
| 175 | - if(!isset($this->options)) { |
|
| 175 | + if (!isset($this->options)) { |
|
| 176 | 176 | $this->options = $this->getDefaultOptions(); |
| 177 | 177 | } |
| 178 | 178 | |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | public function getOptions() : array |
| 188 | 188 | { |
| 189 | - if(!isset($this->options)) { |
|
| 189 | + if (!isset($this->options)) { |
|
| 190 | 190 | $this->options = $this->getDefaultOptions(); |
| 191 | 191 | } |
| 192 | 192 | |
@@ -56,12 +56,12 @@ |
||
| 56 | 56 | */ |
| 57 | 57 | public static function value2string($value) : string |
| 58 | 58 | { |
| 59 | - if($value === true) |
|
| 59 | + if ($value === true) |
|
| 60 | 60 | { |
| 61 | 61 | return 'true'; |
| 62 | 62 | } |
| 63 | 63 | |
| 64 | - if($value === false) |
|
| 64 | + if ($value === false) |
|
| 65 | 65 | { |
| 66 | 66 | return 'false'; |
| 67 | 67 | } |
@@ -53,7 +53,7 @@ |
||
| 53 | 53 | * @param bool $enabled |
| 54 | 54 | * @return $this |
| 55 | 55 | */ |
| 56 | - public function prop(string $name, bool $enabled=true) : self; |
|
| 56 | + public function prop(string $name, bool $enabled = true) : self; |
|
| 57 | 57 | |
| 58 | 58 | /** |
| 59 | 59 | * @param string $name |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | * @param mixed $default The default value to return if the option does not exist. |
| 46 | 46 | * @return mixed |
| 47 | 47 | */ |
| 48 | - public function getOption(string $name, $default=null); |
|
| 48 | + public function getOption(string $name, $default = null); |
|
| 49 | 49 | |
| 50 | 50 | /** |
| 51 | 51 | * @param string $name |
@@ -53,11 +53,11 @@ discard block |
||
| 53 | 53 | */ |
| 54 | 54 | public function getArrayOption(string $name) : array; |
| 55 | 55 | |
| 56 | - public function getIntOption(string $name, int $default=0) : int; |
|
| 56 | + public function getIntOption(string $name, int $default = 0) : int; |
|
| 57 | 57 | |
| 58 | - public function getBoolOption(string $name, bool $default=false) : bool; |
|
| 58 | + public function getBoolOption(string $name, bool $default = false) : bool; |
|
| 59 | 59 | |
| 60 | - public function getStringOption(string $name, string $default='') : string; |
|
| 60 | + public function getStringOption(string $name, string $default = '') : string; |
|
| 61 | 61 | |
| 62 | 62 | /** |
| 63 | 63 | * Sets a collection of options at once, from an |