@@ -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) |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | public static function detectMimeType($fileName) : ?string |
| 209 | 209 | { |
| 210 | 210 | $ext = self::getExtension($fileName); |
| 211 | - if(empty($ext)) { |
|
| 211 | + if (empty($ext)) { |
|
| 212 | 212 | return null; |
| 213 | 213 | } |
| 214 | 214 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 253 | 253 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
| 254 | 254 | */ |
| 255 | - public static function sendFile($filePath, ?string $fileName = null, bool $asAttachment=true) : void |
|
| 255 | + public static function sendFile($filePath, ?string $fileName = null, bool $asAttachment = true) : void |
|
| 256 | 256 | { |
| 257 | 257 | self::getFileInfo($filePath)->getDownloader()->send($fileName, $asAttachment); |
| 258 | 258 | } |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | * @throws FileHelper_Exception |
| 270 | 270 | * @see FileHelper::ERROR_CANNOT_OPEN_URL |
| 271 | 271 | */ |
| 272 | - public static function downloadFile(string $url, int $timeout=0, bool $SSLEnabled=false) : string |
|
| 272 | + public static function downloadFile(string $url, int $timeout = 0, bool $SSLEnabled = false) : string |
|
| 273 | 273 | { |
| 274 | 274 | return FileDownloader::factory($url) |
| 275 | 275 | ->setTimeout($timeout) |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | { |
| 325 | 325 | $info = self::getPathInfo($pathOrDirIterator); |
| 326 | 326 | |
| 327 | - if($extension === true || $info instanceof FolderInfo) |
|
| 327 | + if ($extension === true || $info instanceof FolderInfo) |
|
| 328 | 328 | { |
| 329 | 329 | return $info->getName(); |
| 330 | 330 | } |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
| 347 | 347 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
| 348 | 348 | */ |
| 349 | - public static function parseJSONFile($file, string $targetEncoding='', $sourceEncoding=null) : array |
|
| 349 | + public static function parseJSONFile($file, string $targetEncoding = '', $sourceEncoding = null) : array |
|
| 350 | 350 | { |
| 351 | 351 | return JSONFile::factory($file) |
| 352 | 352 | ->setTargetEncoding($targetEncoding) |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | * @throws FileHelper_Exception |
| 400 | 400 | * @see FileHelper::createFileFinder() |
| 401 | 401 | */ |
| 402 | - public static function findHTMLFiles($targetFolder, array $options=array()) : array |
|
| 402 | + public static function findHTMLFiles($targetFolder, array $options = array()) : array |
|
| 403 | 403 | { |
| 404 | 404 | return self::findFiles($targetFolder, array('html'), $options); |
| 405 | 405 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | * @throws FileHelper_Exception |
| 419 | 419 | * @see FileHelper::createFileFinder() |
| 420 | 420 | */ |
| 421 | - public static function findPHPFiles($targetFolder, array $options=array()) : array |
|
| 421 | + public static function findPHPFiles($targetFolder, array $options = array()) : array |
|
| 422 | 422 | { |
| 423 | 423 | return self::findFiles($targetFolder, array('php'), $options); |
| 424 | 424 | } |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | * @see FileHelper::createFileFinder() |
| 441 | 441 | * @deprecated Use the file finder instead. |
| 442 | 442 | */ |
| 443 | - public static function findFiles($targetFolder, array $extensions=array(), array $options=array()) : array |
|
| 443 | + public static function findFiles($targetFolder, array $extensions = array(), array $options = array()) : array |
|
| 444 | 444 | { |
| 445 | 445 | $finder = self::createFileFinder($targetFolder); |
| 446 | 446 | |
@@ -450,16 +450,16 @@ discard block |
||
| 450 | 450 | |
| 451 | 451 | $finder->setPathmodeStrip(); |
| 452 | 452 | |
| 453 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 453 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
| 454 | 454 | { |
| 455 | 455 | $finder->setPathmodeRelative(); |
| 456 | 456 | } |
| 457 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 457 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
| 458 | 458 | { |
| 459 | 459 | $finder->setPathmodeAbsolute(); |
| 460 | 460 | } |
| 461 | 461 | |
| 462 | - if(isset($options['strip-extension'])) |
|
| 462 | + if (isset($options['strip-extension'])) |
|
| 463 | 463 | { |
| 464 | 464 | $finder->stripExtensions(); |
| 465 | 465 | } |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | * @return string |
| 479 | 479 | * @throws FileHelper_Exception |
| 480 | 480 | */ |
| 481 | - public static function removeExtension($filename, bool $keepPath=false) : string |
|
| 481 | + public static function removeExtension($filename, bool $keepPath = false) : string |
|
| 482 | 482 | { |
| 483 | 483 | return self::getFileInfo($filename)->removeExtension($keepPath); |
| 484 | 484 | } |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | public static function createUnicodeHandling() : UnicodeHandling |
| 492 | 492 | { |
| 493 | - if(!isset(self::$unicodeHandling)) |
|
| 493 | + if (!isset(self::$unicodeHandling)) |
|
| 494 | 494 | { |
| 495 | 495 | self::$unicodeHandling = new UnicodeHandling(); |
| 496 | 496 | } |
@@ -524,7 +524,7 @@ discard block |
||
| 524 | 524 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 525 | 525 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 526 | 526 | */ |
| 527 | - public static function saveAsJSON($data, $file, bool $pretty=false) : JSONFile |
|
| 527 | + public static function saveAsJSON($data, $file, bool $pretty = false) : JSONFile |
|
| 528 | 528 | { |
| 529 | 529 | return JSONFile::factory($file)->putData($data, $pretty); |
| 530 | 530 | } |
@@ -542,7 +542,7 @@ discard block |
||
| 542 | 542 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
| 543 | 543 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
| 544 | 544 | */ |
| 545 | - public static function saveFile($filePath, string $content='') : FileInfo |
|
| 545 | + public static function saveFile($filePath, string $content = '') : FileInfo |
|
| 546 | 546 | { |
| 547 | 547 | return self::getFileInfo($filePath)->putContents($content); |
| 548 | 548 | } |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | * @param int $depth The folder depth to reduce the path to |
| 655 | 655 | * @return string |
| 656 | 656 | */ |
| 657 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
| 657 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
| 658 | 658 | { |
| 659 | 659 | return PathRelativizer::relativizeByDepth($path, $depth); |
| 660 | 660 | } |
@@ -693,7 +693,7 @@ discard block |
||
| 693 | 693 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 694 | 694 | * @see FileHelper::ERROR_REAL_PATH_NOT_FOUND |
| 695 | 695 | */ |
| 696 | - public static function requireFileExists($path, ?int $errorCode=null) : string |
|
| 696 | + public static function requireFileExists($path, ?int $errorCode = null) : string |
|
| 697 | 697 | { |
| 698 | 698 | return self::getPathInfo($path) |
| 699 | 699 | ->requireIsFile() |
@@ -707,7 +707,7 @@ discard block |
||
| 707 | 707 | * @return string |
| 708 | 708 | * @throws FileHelper_Exception |
| 709 | 709 | */ |
| 710 | - public static function requireFileReadable($path, ?int $errorCode=null) : string |
|
| 710 | + public static function requireFileReadable($path, ?int $errorCode = null) : string |
|
| 711 | 711 | { |
| 712 | 712 | return self::getPathInfo($path) |
| 713 | 713 | ->requireIsFile() |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
| 786 | 786 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
| 787 | 787 | */ |
| 788 | - public static function readLines($filePath, int $amount=0) : array |
|
| 788 | + public static function readLines($filePath, int $amount = 0) : array |
|
| 789 | 789 | { |
| 790 | 790 | return self::getFileInfo($filePath) |
| 791 | 791 | ->getLineReader() |
@@ -835,7 +835,7 @@ discard block |
||
| 835 | 835 | * |
| 836 | 836 | * @throws FileHelper_Exception |
| 837 | 837 | */ |
| 838 | - public static function createPathsReducer(array $paths=array()) : PathsReducer |
|
| 838 | + public static function createPathsReducer(array $paths = array()) : PathsReducer |
|
| 839 | 839 | { |
| 840 | 840 | return new PathsReducer($paths); |
| 841 | 841 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public static function factory($path) : JSONFile |
| 45 | 45 | { |
| 46 | - if($path instanceof self) { |
|
| 46 | + if ($path instanceof self) { |
|
| 47 | 47 | return $path; |
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | $instance = self::createInstance($path); |
| 51 | 51 | |
| 52 | - if($instance instanceof self) { |
|
| 52 | + if ($instance instanceof self) { |
|
| 53 | 53 | return $instance; |
| 54 | 54 | } |
| 55 | 55 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | |
| 129 | 129 | private function convertEncoding(string $contents) : string |
| 130 | 130 | { |
| 131 | - if(!empty($this->targetEncoding)) |
|
| 131 | + if (!empty($this->targetEncoding)) |
|
| 132 | 132 | { |
| 133 | 133 | return (string)mb_convert_encoding( |
| 134 | 134 | $contents, |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | { |
| 151 | 151 | $options = null; |
| 152 | 152 | |
| 153 | - if($pretty) |
|
| 153 | + if ($pretty) |
|
| 154 | 154 | { |
| 155 | 155 | $options = JSON_PRETTY_PRINT; |
| 156 | 156 | } |
@@ -101,8 +101,7 @@ discard block |
||
| 101 | 101 | 512, |
| 102 | 102 | JSON_THROW_ON_ERROR |
| 103 | 103 | ); |
| 104 | - } |
|
| 105 | - catch (JsonException $e) |
|
| 104 | + } catch (JsonException $e) |
|
| 106 | 105 | { |
| 107 | 106 | throw new FileHelper_Exception( |
| 108 | 107 | 'Cannot decode json data', |
@@ -162,8 +161,7 @@ discard block |
||
| 162 | 161 | $this->putContents($json); |
| 163 | 162 | |
| 164 | 163 | return $this; |
| 165 | - } |
|
| 166 | - catch (JsonException $e) |
|
| 164 | + } catch (JsonException $e) |
|
| 167 | 165 | { |
| 168 | 166 | throw new FileHelper_Exception( |
| 169 | 167 | 'An error occurred while encoding a data set to JSON.', |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | |
| 97 | 97 | $path = realpath($this->path); |
| 98 | 98 | |
| 99 | - if($path !== false) |
|
| 99 | + if ($path !== false) |
|
| 100 | 100 | { |
| 101 | 101 | return FileHelper::normalizePath($path); |
| 102 | 102 | } |
@@ -115,14 +115,14 @@ discard block |
||
| 115 | 115 | * @return $this |
| 116 | 116 | * @throws FileHelper_Exception |
| 117 | 117 | */ |
| 118 | - private function requireTrue(bool $condition, string $conditionLabel, ?int $errorCode=null) : self |
|
| 118 | + private function requireTrue(bool $condition, string $conditionLabel, ?int $errorCode = null) : self |
|
| 119 | 119 | { |
| 120 | - if($condition === true) |
|
| 120 | + if ($condition === true) |
|
| 121 | 121 | { |
| 122 | 122 | return $this; |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - if($errorCode === null) |
|
| 125 | + if ($errorCode === null) |
|
| 126 | 126 | { |
| 127 | 127 | $errorCode = FileHelper::ERROR_FILE_DOES_NOT_EXIST; |
| 128 | 128 | } |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | * @return $this |
| 140 | 140 | * @throws FileHelper_Exception |
| 141 | 141 | */ |
| 142 | - public function requireExists(?int $errorCode=null) : self |
|
| 142 | + public function requireExists(?int $errorCode = null) : self |
|
| 143 | 143 | { |
| 144 | 144 | return $this->requireTrue( |
| 145 | 145 | !empty($this->path) && realpath($this->path) !== false, |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @return $this |
| 154 | 154 | * @throws FileHelper_Exception |
| 155 | 155 | */ |
| 156 | - public function requireReadable(?int $errorCode=null) : self |
|
| 156 | + public function requireReadable(?int $errorCode = null) : self |
|
| 157 | 157 | { |
| 158 | 158 | $this->requireExists($errorCode); |
| 159 | 159 | |
@@ -169,7 +169,7 @@ discard block |
||
| 169 | 169 | * @return $this |
| 170 | 170 | * @throws FileHelper_Exception |
| 171 | 171 | */ |
| 172 | - public function requireWritable(?int $errorCode=null) : self |
|
| 172 | + public function requireWritable(?int $errorCode = null) : self |
|
| 173 | 173 | { |
| 174 | 174 | return $this->requireTrue( |
| 175 | 175 | $this->isWritable(), |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | */ |
| 187 | 187 | public function requireIsFile() : FileInfo |
| 188 | 188 | { |
| 189 | - if($this instanceof FileInfo) |
|
| 189 | + if ($this instanceof FileInfo) |
|
| 190 | 190 | { |
| 191 | 191 | return $this; |
| 192 | 192 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function requireIsFolder() : FolderInfo |
| 211 | 211 | { |
| 212 | - if($this instanceof FolderInfo) |
|
| 212 | + if ($this instanceof FolderInfo) |
|
| 213 | 213 | { |
| 214 | 214 | return $this; |
| 215 | 215 | } |
@@ -230,12 +230,12 @@ discard block |
||
| 230 | 230 | */ |
| 231 | 231 | public static function type2string($path) : string |
| 232 | 232 | { |
| 233 | - if($path instanceof PathInfoInterface) |
|
| 233 | + if ($path instanceof PathInfoInterface) |
|
| 234 | 234 | { |
| 235 | 235 | return $path->getPath(); |
| 236 | 236 | } |
| 237 | 237 | |
| 238 | - if($path instanceof SplFileInfo) |
|
| 238 | + if ($path instanceof SplFileInfo) |
|
| 239 | 239 | { |
| 240 | 240 | return $path->getPathname(); |
| 241 | 241 | } |
@@ -257,19 +257,19 @@ discard block |
||
| 257 | 257 | */ |
| 258 | 258 | public static function resolveType($path) : PathInfoInterface |
| 259 | 259 | { |
| 260 | - if($path instanceof PathInfoInterface) |
|
| 260 | + if ($path instanceof PathInfoInterface) |
|
| 261 | 261 | { |
| 262 | 262 | return $path; |
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | $path = self::type2string($path); |
| 266 | 266 | |
| 267 | - if(FolderInfo::is_dir($path)) |
|
| 267 | + if (FolderInfo::is_dir($path)) |
|
| 268 | 268 | { |
| 269 | 269 | return FolderInfo::factory($path); |
| 270 | 270 | } |
| 271 | 271 | |
| 272 | - if(FileInfo::is_file($path)) |
|
| 272 | + if (FileInfo::is_file($path)) |
|
| 273 | 273 | { |
| 274 | 274 | return FileInfo::factory($path); |
| 275 | 275 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | public function getModifiedDate() : ?DateTime |
| 328 | 328 | { |
| 329 | 329 | $time = filemtime($this->getPath()); |
| 330 | - if($time === false) { |
|
| 330 | + if ($time === false) { |
|
| 331 | 331 | return null; |
| 332 | 332 | } |
| 333 | 333 | |
@@ -44,20 +44,20 @@ discard block |
||
| 44 | 44 | |
| 45 | 45 | protected FolderInfo $path; |
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * @var string[] |
|
| 49 | - */ |
|
| 47 | + /** |
|
| 48 | + * @var string[] |
|
| 49 | + */ |
|
| 50 | 50 | protected array $found = array(); |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The path must exist when the class is instantiated: its |
|
| 54 | - * real path will be determined to work with. |
|
| 55 | - * |
|
| 56 | - * @param string|PathInfoInterface|SplFileInfo $path The absolute path to the target folder. |
|
| 57 | - * |
|
| 58 | - * @throws FileHelper_Exception |
|
| 59 | - * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 60 | - */ |
|
| 52 | + /** |
|
| 53 | + * The path must exist when the class is instantiated: its |
|
| 54 | + * real path will be determined to work with. |
|
| 55 | + * |
|
| 56 | + * @param string|PathInfoInterface|SplFileInfo $path The absolute path to the target folder. |
|
| 57 | + * |
|
| 58 | + * @throws FileHelper_Exception |
|
| 59 | + * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
| 60 | + */ |
|
| 61 | 61 | public function __construct($path) |
| 62 | 62 | { |
| 63 | 63 | $this->path = AbstractPathInfo::resolveType($path)->requireExists()->requireIsFolder(); |
@@ -75,11 +75,11 @@ discard block |
||
| 75 | 75 | ); |
| 76 | 76 | } |
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Enables extension stripping, to return file names without extension. |
|
| 80 | - * |
|
| 81 | - * @return FileFinder |
|
| 82 | - */ |
|
| 78 | + /** |
|
| 79 | + * Enables extension stripping, to return file names without extension. |
|
| 80 | + * |
|
| 81 | + * @return FileFinder |
|
| 82 | + */ |
|
| 83 | 83 | public function stripExtensions() : FileFinder |
| 84 | 84 | { |
| 85 | 85 | return $this->setOption('strip-extensions', true); |
@@ -96,46 +96,46 @@ discard block |
||
| 96 | 96 | return $this->setOption('recursive', $enabled); |
| 97 | 97 | } |
| 98 | 98 | |
| 99 | - /** |
|
| 100 | - * Retrieves all extensions that were added to |
|
| 101 | - * the list of included extensions. |
|
| 102 | - * |
|
| 103 | - * @return string[] |
|
| 104 | - */ |
|
| 99 | + /** |
|
| 100 | + * Retrieves all extensions that were added to |
|
| 101 | + * the list of included extensions. |
|
| 102 | + * |
|
| 103 | + * @return string[] |
|
| 104 | + */ |
|
| 105 | 105 | public function getIncludeExtensions() : array |
| 106 | 106 | { |
| 107 | 107 | return $this->getArrayOption(self::OPTION_INCLUDE_EXTENSIONS); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - /** |
|
| 111 | - * Includes a single extension in the file search: only |
|
| 112 | - * files with this extension will be used in the results. |
|
| 113 | - * |
|
| 114 | - * NOTE: Included extensions take precedence before excluded |
|
| 115 | - * extensions. If any excluded extensions are specified, they |
|
| 116 | - * will be ignored. |
|
| 117 | - * |
|
| 118 | - * @param string $extension Extension name, without dot (`php` for example). |
|
| 119 | - * @return FileFinder |
|
| 120 | - * @see FileFinder::includeExtensions() |
|
| 121 | - */ |
|
| 110 | + /** |
|
| 111 | + * Includes a single extension in the file search: only |
|
| 112 | + * files with this extension will be used in the results. |
|
| 113 | + * |
|
| 114 | + * NOTE: Included extensions take precedence before excluded |
|
| 115 | + * extensions. If any excluded extensions are specified, they |
|
| 116 | + * will be ignored. |
|
| 117 | + * |
|
| 118 | + * @param string $extension Extension name, without dot (`php` for example). |
|
| 119 | + * @return FileFinder |
|
| 120 | + * @see FileFinder::includeExtensions() |
|
| 121 | + */ |
|
| 122 | 122 | public function includeExtension(string $extension) : FileFinder |
| 123 | 123 | { |
| 124 | 124 | return $this->includeExtensions(array($extension)); |
| 125 | 125 | } |
| 126 | 126 | |
| 127 | - /** |
|
| 128 | - * Includes several extensions in the file search: only |
|
| 129 | - * files with these extensions wil be used in the results. |
|
| 130 | - * |
|
| 131 | - * NOTE: Included extensions take precedence before excluded |
|
| 132 | - * extensions. If any excluded extensions are specified, they |
|
| 133 | - * will be ignored. |
|
| 134 | - * |
|
| 135 | - * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 136 | - * @return FileFinder |
|
| 137 | - * @see FileFinder::includeExtension() |
|
| 138 | - */ |
|
| 127 | + /** |
|
| 128 | + * Includes several extensions in the file search: only |
|
| 129 | + * files with these extensions wil be used in the results. |
|
| 130 | + * |
|
| 131 | + * NOTE: Included extensions take precedence before excluded |
|
| 132 | + * extensions. If any excluded extensions are specified, they |
|
| 133 | + * will be ignored. |
|
| 134 | + * |
|
| 135 | + * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 136 | + * @return FileFinder |
|
| 137 | + * @see FileFinder::includeExtension() |
|
| 138 | + */ |
|
| 139 | 139 | public function includeExtensions(array $extensions) : FileFinder |
| 140 | 140 | { |
| 141 | 141 | $items = $this->getIncludeExtensions(); |
@@ -146,37 +146,37 @@ discard block |
||
| 146 | 146 | return $this; |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Retrieves a list of all extensions currently set as |
|
| 151 | - * excluded from the search. |
|
| 152 | - * |
|
| 153 | - * @return string[] |
|
| 154 | - */ |
|
| 149 | + /** |
|
| 150 | + * Retrieves a list of all extensions currently set as |
|
| 151 | + * excluded from the search. |
|
| 152 | + * |
|
| 153 | + * @return string[] |
|
| 154 | + */ |
|
| 155 | 155 | public function getExcludeExtensions() : array |
| 156 | 156 | { |
| 157 | 157 | return $this->getArrayOption(self::OPTION_EXCLUDE_EXTENSIONS); |
| 158 | 158 | } |
| 159 | 159 | |
| 160 | - /** |
|
| 161 | - * Excludes a single extension from the search. |
|
| 162 | - * |
|
| 163 | - * @param string $extension Extension name, without dot (`php` for example). |
|
| 164 | - * @return FileFinder |
|
| 165 | - * @see FileFinder::excludeExtensions() |
|
| 166 | - */ |
|
| 160 | + /** |
|
| 161 | + * Excludes a single extension from the search. |
|
| 162 | + * |
|
| 163 | + * @param string $extension Extension name, without dot (`php` for example). |
|
| 164 | + * @return FileFinder |
|
| 165 | + * @see FileFinder::excludeExtensions() |
|
| 166 | + */ |
|
| 167 | 167 | public function excludeExtension(string $extension) : FileFinder |
| 168 | 168 | { |
| 169 | 169 | return $this->excludeExtensions(array($extension)); |
| 170 | 170 | } |
| 171 | 171 | |
| 172 | - /** |
|
| 173 | - * Add several extensions to the list of extensions to |
|
| 174 | - * exclude from the file search. |
|
| 175 | - * |
|
| 176 | - * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 177 | - * @return FileFinder |
|
| 178 | - * @see FileFinder::excludeExtension() |
|
| 179 | - */ |
|
| 172 | + /** |
|
| 173 | + * Add several extensions to the list of extensions to |
|
| 174 | + * exclude from the file search. |
|
| 175 | + * |
|
| 176 | + * @param string[] $extensions Extension names, without dot (`php` for example). |
|
| 177 | + * @return FileFinder |
|
| 178 | + * @see FileFinder::excludeExtension() |
|
| 179 | + */ |
|
| 180 | 180 | public function excludeExtensions(array $extensions) : FileFinder |
| 181 | 181 | { |
| 182 | 182 | $items = $this->getExcludeExtensions(); |
@@ -187,52 +187,52 @@ discard block |
||
| 187 | 187 | return $this; |
| 188 | 188 | } |
| 189 | 189 | |
| 190 | - /** |
|
| 191 | - * In this mode, the entire path to the file will be stripped, |
|
| 192 | - * leaving only the file name in the files list. |
|
| 193 | - * |
|
| 194 | - * @return FileFinder |
|
| 195 | - */ |
|
| 190 | + /** |
|
| 191 | + * In this mode, the entire path to the file will be stripped, |
|
| 192 | + * leaving only the file name in the files list. |
|
| 193 | + * |
|
| 194 | + * @return FileFinder |
|
| 195 | + */ |
|
| 196 | 196 | public function setPathmodeStrip() : FileFinder |
| 197 | 197 | { |
| 198 | 198 | return $this->setPathmode(self::PATH_MODE_STRIP); |
| 199 | 199 | } |
| 200 | 200 | |
| 201 | - /** |
|
| 202 | - * In this mode, only the path relative to the source folder |
|
| 203 | - * will be included in the files list. |
|
| 204 | - * |
|
| 205 | - * @return FileFinder |
|
| 206 | - */ |
|
| 201 | + /** |
|
| 202 | + * In this mode, only the path relative to the source folder |
|
| 203 | + * will be included in the files list. |
|
| 204 | + * |
|
| 205 | + * @return FileFinder |
|
| 206 | + */ |
|
| 207 | 207 | public function setPathmodeRelative() : FileFinder |
| 208 | 208 | { |
| 209 | 209 | return $this->setPathmode(self::PATH_MODE_RELATIVE); |
| 210 | 210 | } |
| 211 | 211 | |
| 212 | - /** |
|
| 213 | - * In this mode, the full, absolute paths to the files will |
|
| 214 | - * be included in the files list. |
|
| 215 | - * |
|
| 216 | - * @return FileFinder |
|
| 217 | - */ |
|
| 212 | + /** |
|
| 213 | + * In this mode, the full, absolute paths to the files will |
|
| 214 | + * be included in the files list. |
|
| 215 | + * |
|
| 216 | + * @return FileFinder |
|
| 217 | + */ |
|
| 218 | 218 | public function setPathmodeAbsolute() : FileFinder |
| 219 | 219 | { |
| 220 | 220 | return $this->setPathmode(self::PATH_MODE_ABSOLUTE); |
| 221 | 221 | } |
| 222 | 222 | |
| 223 | - /** |
|
| 224 | - * This sets a character or string to replace the slashes |
|
| 225 | - * in the paths with. |
|
| 226 | - * |
|
| 227 | - * This is used for example in the `getPHPClassNames()` |
|
| 228 | - * method, to return files from subfolders as class names |
|
| 229 | - * using the "_" character: |
|
| 230 | - * |
|
| 231 | - * Subfolder/To/File.php => Subfolder_To_File.php |
|
| 232 | - * |
|
| 233 | - * @param string $character |
|
| 234 | - * @return FileFinder |
|
| 235 | - */ |
|
| 223 | + /** |
|
| 224 | + * This sets a character or string to replace the slashes |
|
| 225 | + * in the paths with. |
|
| 226 | + * |
|
| 227 | + * This is used for example in the `getPHPClassNames()` |
|
| 228 | + * method, to return files from subfolders as class names |
|
| 229 | + * using the "_" character: |
|
| 230 | + * |
|
| 231 | + * Subfolder/To/File.php => Subfolder_To_File.php |
|
| 232 | + * |
|
| 233 | + * @param string $character |
|
| 234 | + * @return FileFinder |
|
| 235 | + */ |
|
| 236 | 236 | public function setSlashReplacement(string $character) : FileFinder |
| 237 | 237 | { |
| 238 | 238 | return $this->setOption('slash-replacement', $character); |
@@ -255,12 +255,12 @@ discard block |
||
| 255 | 255 | return $this->setOption(self::OPTION_PATHMODE, $mode); |
| 256 | 256 | } |
| 257 | 257 | |
| 258 | - /** |
|
| 259 | - * Retrieves a list of all matching file names/paths, |
|
| 260 | - * depending on the selected options. |
|
| 261 | - * |
|
| 262 | - * @return string[] |
|
| 263 | - */ |
|
| 258 | + /** |
|
| 259 | + * Retrieves a list of all matching file names/paths, |
|
| 260 | + * depending on the selected options. |
|
| 261 | + * |
|
| 262 | + * @return string[] |
|
| 263 | + */ |
|
| 264 | 264 | public function getAll() : array |
| 265 | 265 | { |
| 266 | 266 | $this->find((string)$this->path, true); |
@@ -268,24 +268,24 @@ discard block |
||
| 268 | 268 | return $this->found; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Retrieves only PHP files. Can be combined with other |
|
| 273 | - * options like enabling recursion into sub-folders. |
|
| 274 | - * |
|
| 275 | - * @return string[] |
|
| 276 | - */ |
|
| 271 | + /** |
|
| 272 | + * Retrieves only PHP files. Can be combined with other |
|
| 273 | + * options like enabling recursion into sub-folders. |
|
| 274 | + * |
|
| 275 | + * @return string[] |
|
| 276 | + */ |
|
| 277 | 277 | public function getPHPFiles() : array |
| 278 | 278 | { |
| 279 | 279 | $this->includeExtensions(array('php')); |
| 280 | 280 | return $this->getAll(); |
| 281 | 281 | } |
| 282 | 282 | |
| 283 | - /** |
|
| 284 | - * Generates PHP class names from file paths: it replaces |
|
| 285 | - * slashes with underscores, and removes file extensions. |
|
| 286 | - * |
|
| 287 | - * @return string[] An array of PHP file names without extension. |
|
| 288 | - */ |
|
| 283 | + /** |
|
| 284 | + * Generates PHP class names from file paths: it replaces |
|
| 285 | + * slashes with underscores, and removes file extensions. |
|
| 286 | + * |
|
| 287 | + * @return string[] An array of PHP file names without extension. |
|
| 288 | + */ |
|
| 289 | 289 | public function getPHPClassNames() : array |
| 290 | 290 | { |
| 291 | 291 | $this->includeExtensions(array('php')); |
@@ -356,13 +356,13 @@ discard block |
||
| 356 | 356 | return $path; |
| 357 | 357 | } |
| 358 | 358 | |
| 359 | - /** |
|
| 360 | - * Checks whether the specified extension is allowed |
|
| 361 | - * with the current settings. |
|
| 362 | - * |
|
| 363 | - * @param string $extension |
|
| 364 | - * @return bool |
|
| 365 | - */ |
|
| 359 | + /** |
|
| 360 | + * Checks whether the specified extension is allowed |
|
| 361 | + * with the current settings. |
|
| 362 | + * |
|
| 363 | + * @param string $extension |
|
| 364 | + * @return bool |
|
| 365 | + */ |
|
| 366 | 366 | protected function filterExclusion(string $extension) : bool |
| 367 | 367 | { |
| 368 | 368 | $include = $this->getOption(self::OPTION_INCLUDE_EXTENSIONS); |
@@ -382,12 +382,12 @@ discard block |
||
| 382 | 382 | return true; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - /** |
|
| 386 | - * Adjusts the path according to the selected path mode. |
|
| 387 | - * |
|
| 388 | - * @param string $path |
|
| 389 | - * @return string |
|
| 390 | - */ |
|
| 385 | + /** |
|
| 386 | + * Adjusts the path according to the selected path mode. |
|
| 387 | + * |
|
| 388 | + * @param string $path |
|
| 389 | + * @return string |
|
| 390 | + */ |
|
| 391 | 391 | protected function filterPath(string $path) : string |
| 392 | 392 | { |
| 393 | 393 | switch($this->getStringOption(self::OPTION_PATHMODE)) |
@@ -35,11 +35,11 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | protected $classes = array(); |
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * @param PHPFile $path The path to the PHP file to parse. |
|
| 40 | - * @throws FileHelper_Exception |
|
| 41 | - * @see FileHelper::findPHPClasses() |
|
| 42 | - */ |
|
| 38 | + /** |
|
| 39 | + * @param PHPFile $path The path to the PHP file to parse. |
|
| 40 | + * @throws FileHelper_Exception |
|
| 41 | + * @see FileHelper::findPHPClasses() |
|
| 42 | + */ |
|
| 43 | 43 | public function __construct(PHPFile $path) |
| 44 | 44 | { |
| 45 | 45 | $this->file = $path |
@@ -49,58 +49,58 @@ discard block |
||
| 49 | 49 | $this->parseFile(); |
| 50 | 50 | } |
| 51 | 51 | |
| 52 | - /** |
|
| 53 | - * The name of the namespace of the classes in the file, if any. |
|
| 54 | - * @return string |
|
| 55 | - */ |
|
| 52 | + /** |
|
| 53 | + * The name of the namespace of the classes in the file, if any. |
|
| 54 | + * @return string |
|
| 55 | + */ |
|
| 56 | 56 | public function getNamespace() : string |
| 57 | 57 | { |
| 58 | 58 | return $this->namespace; |
| 59 | 59 | } |
| 60 | 60 | |
| 61 | - /** |
|
| 62 | - * Whether the file contains a namespace. |
|
| 63 | - * @return bool |
|
| 64 | - */ |
|
| 61 | + /** |
|
| 62 | + * Whether the file contains a namespace. |
|
| 63 | + * @return bool |
|
| 64 | + */ |
|
| 65 | 65 | public function hasNamespace() : bool |
| 66 | 66 | { |
| 67 | 67 | return !empty($this->namespace); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - /** |
|
| 71 | - * The absolute path to the file. |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 70 | + /** |
|
| 71 | + * The absolute path to the file. |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | 74 | public function getPath() : string |
| 75 | 75 | { |
| 76 | 76 | return $this->file->getPath(); |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | - /** |
|
| 80 | - * Whether any classes were found in the file. |
|
| 81 | - * @return bool |
|
| 82 | - */ |
|
| 79 | + /** |
|
| 80 | + * Whether any classes were found in the file. |
|
| 81 | + * @return bool |
|
| 82 | + */ |
|
| 83 | 83 | public function hasClasses() : bool |
| 84 | 84 | { |
| 85 | 85 | return !empty($this->classes); |
| 86 | 86 | } |
| 87 | 87 | |
| 88 | - /** |
|
| 89 | - * The names of the classes that were found in the file (with namespace if any). |
|
| 90 | - * @return string[] |
|
| 91 | - */ |
|
| 88 | + /** |
|
| 89 | + * The names of the classes that were found in the file (with namespace if any). |
|
| 90 | + * @return string[] |
|
| 91 | + */ |
|
| 92 | 92 | public function getClassNames() : array |
| 93 | 93 | { |
| 94 | 94 | return array_keys($this->classes); |
| 95 | 95 | } |
| 96 | 96 | |
| 97 | - /** |
|
| 98 | - * Retrieves all classes that were detected in the file, |
|
| 99 | - * which can be used to retrieve more information about |
|
| 100 | - * them. |
|
| 101 | - * |
|
| 102 | - * @return FileHelper_PHPClassInfo_Class[] |
|
| 103 | - */ |
|
| 97 | + /** |
|
| 98 | + * Retrieves all classes that were detected in the file, |
|
| 99 | + * which can be used to retrieve more information about |
|
| 100 | + * them. |
|
| 101 | + * |
|
| 102 | + * @return FileHelper_PHPClassInfo_Class[] |
|
| 103 | + */ |
|
| 104 | 104 | public function getClasses() : array |
| 105 | 105 | { |
| 106 | 106 | return array_values($this->classes); |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
| 149 | - /** |
|
| 150 | - * Strips all whitespace from the string, replacing it with |
|
| 151 | - * regular spaces (newlines, tabs, etc.). |
|
| 152 | - * |
|
| 153 | - * @param string $string |
|
| 154 | - * @return string |
|
| 155 | - */ |
|
| 149 | + /** |
|
| 150 | + * Strips all whitespace from the string, replacing it with |
|
| 151 | + * regular spaces (newlines, tabs, etc.). |
|
| 152 | + * |
|
| 153 | + * @param string $string |
|
| 154 | + * @return string |
|
| 155 | + */ |
|
| 156 | 156 | protected function stripWhitespace(string $string) : string |
| 157 | 157 | { |
| 158 | 158 | return preg_replace('/\s/', ' ', $string); |
@@ -112,25 +112,25 @@ |
||
| 112 | 112 | |
| 113 | 113 | $result = array(); |
| 114 | 114 | preg_match_all('/namespace\s+([^;]+);/ix', $code, $result, PREG_PATTERN_ORDER); |
| 115 | - if(isset($result[0][0])) { |
|
| 115 | + if (isset($result[0][0])) { |
|
| 116 | 116 | $this->namespace = trim($result[1][0]); |
| 117 | 117 | } |
| 118 | 118 | |
| 119 | 119 | $result = array(); |
| 120 | 120 | preg_match_all('/(abstract|final)\s+(class|trait)\s+([\sa-z\d\\\\_,]+){|(class|trait)\s+([\sa-z\d\\\\_,]+){/ix', $code, $result, PREG_PATTERN_ORDER); |
| 121 | 121 | |
| 122 | - if(!isset($result[0][0])) { |
|
| 122 | + if (!isset($result[0][0])) { |
|
| 123 | 123 | return; |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | $indexes = array_keys($result[0]); |
| 127 | 127 | |
| 128 | - foreach($indexes as $idx) |
|
| 128 | + foreach ($indexes as $idx) |
|
| 129 | 129 | { |
| 130 | 130 | $keyword = $result[1][$idx]; |
| 131 | 131 | $declaration = $result[3][$idx]; |
| 132 | 132 | $type = $result[2][$idx]; |
| 133 | - if(empty($keyword)) { |
|
| 133 | + if (empty($keyword)) { |
|
| 134 | 134 | $type = $result[4][$idx]; |
| 135 | 135 | $declaration = $result[5][$idx]; |
| 136 | 136 | } |
@@ -24,7 +24,7 @@ |
||
| 24 | 24 | interface PathInfoInterface |
| 25 | 25 | { |
| 26 | 26 | public function getName() : string; |
| 27 | - public function getExtension(bool $lowercase=true) : string; |
|
| 27 | + public function getExtension(bool $lowercase = true) : string; |
|
| 28 | 28 | public function getPath() : string; |
| 29 | 29 | public function getFolderPath() : string; |
| 30 | 30 | public function exists() : bool; |
@@ -50,7 +50,7 @@ discard block |
||
| 50 | 50 | */ |
| 51 | 51 | public static function factory($path) : FileInfo |
| 52 | 52 | { |
| 53 | - if($path instanceof self) { |
|
| 53 | + if ($path instanceof self) { |
|
| 54 | 54 | return $path; |
| 55 | 55 | } |
| 56 | 56 | |
@@ -67,12 +67,12 @@ discard block |
||
| 67 | 67 | $pathString = AbstractPathInfo::type2string($path); |
| 68 | 68 | $key = $pathString.';'.static::class; |
| 69 | 69 | |
| 70 | - if(!isset(self::$infoCache[$key])) |
|
| 70 | + if (!isset(self::$infoCache[$key])) |
|
| 71 | 71 | { |
| 72 | 72 | $class = static::class; |
| 73 | 73 | $instance = new $class($pathString); |
| 74 | 74 | |
| 75 | - if(!$instance instanceof self) { |
|
| 75 | + if (!$instance instanceof self) { |
|
| 76 | 76 | throw new FileHelper_Exception( |
| 77 | 77 | 'Invalid class' |
| 78 | 78 | ); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | { |
| 107 | 107 | parent::__construct($path); |
| 108 | 108 | |
| 109 | - if(!self::is_file($this->path)) |
|
| 109 | + if (!self::is_file($this->path)) |
|
| 110 | 110 | { |
| 111 | 111 | throw new FileHelper_Exception( |
| 112 | 112 | 'Not a file path', |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | $path = trim($path); |
| 122 | 122 | |
| 123 | - if(empty($path)) |
|
| 123 | + if (empty($path)) |
|
| 124 | 124 | { |
| 125 | 125 | return false; |
| 126 | 126 | } |
@@ -128,9 +128,9 @@ discard block |
||
| 128 | 128 | return is_file($path) || pathinfo($path, PATHINFO_EXTENSION) !== ''; |
| 129 | 129 | } |
| 130 | 130 | |
| 131 | - public function removeExtension(bool $keepPath=false) : string |
|
| 131 | + public function removeExtension(bool $keepPath = false) : string |
|
| 132 | 132 | { |
| 133 | - if(!$keepPath) |
|
| 133 | + if (!$keepPath) |
|
| 134 | 134 | { |
| 135 | 135 | return (string)pathinfo($this->getName(), PATHINFO_FILENAME); |
| 136 | 136 | } |
@@ -144,11 +144,11 @@ discard block |
||
| 144 | 144 | return implode('/', $parts); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - public function getExtension(bool $lowercase=true) : string |
|
| 147 | + public function getExtension(bool $lowercase = true) : string |
|
| 148 | 148 | { |
| 149 | 149 | $ext = (string)pathinfo($this->path, PATHINFO_EXTENSION); |
| 150 | 150 | |
| 151 | - if($lowercase) |
|
| 151 | + if ($lowercase) |
|
| 152 | 152 | { |
| 153 | 153 | $ext = mb_strtolower($ext); |
| 154 | 154 | } |
@@ -169,12 +169,12 @@ discard block |
||
| 169 | 169 | */ |
| 170 | 170 | public function delete() : FileInfo |
| 171 | 171 | { |
| 172 | - if(!$this->exists()) |
|
| 172 | + if (!$this->exists()) |
|
| 173 | 173 | { |
| 174 | 174 | return $this; |
| 175 | 175 | } |
| 176 | 176 | |
| 177 | - if(unlink($this->path)) |
|
| 177 | + if (unlink($this->path)) |
|
| 178 | 178 | { |
| 179 | 179 | return $this; |
| 180 | 180 | } |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | { |
| 202 | 202 | $target = $this->checkCopyPrerequisites($targetPath); |
| 203 | 203 | |
| 204 | - if(copy($this->path, (string)$target)) |
|
| 204 | + if (copy($this->path, (string)$target)) |
|
| 205 | 205 | { |
| 206 | 206 | return $target; |
| 207 | 207 | } |
@@ -253,7 +253,7 @@ discard block |
||
| 253 | 253 | */ |
| 254 | 254 | public function getLineReader() : LineReader |
| 255 | 255 | { |
| 256 | - if($this->lineReader !== null) |
|
| 256 | + if ($this->lineReader !== null) |
|
| 257 | 257 | { |
| 258 | 258 | $this->lineReader = new LineReader($this); |
| 259 | 259 | } |
@@ -272,7 +272,7 @@ discard block |
||
| 272 | 272 | |
| 273 | 273 | $result = file_get_contents($this->getPath()); |
| 274 | 274 | |
| 275 | - if($result !== false) { |
|
| 275 | + if ($result !== false) { |
|
| 276 | 276 | return $result; |
| 277 | 277 | } |
| 278 | 278 | |
@@ -294,7 +294,7 @@ discard block |
||
| 294 | 294 | */ |
| 295 | 295 | public function putContents(string $content) : FileInfo |
| 296 | 296 | { |
| 297 | - if($this->exists()) |
|
| 297 | + if ($this->exists()) |
|
| 298 | 298 | { |
| 299 | 299 | $this->requireWritable(); |
| 300 | 300 | } |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | ->requireWritable(); |
| 306 | 306 | } |
| 307 | 307 | |
| 308 | - if(file_put_contents($this->path, $content) !== false) |
|
| 308 | + if (file_put_contents($this->path, $content) !== false) |
|
| 309 | 309 | { |
| 310 | 310 | return $this; |
| 311 | 311 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | */ |
| 336 | 336 | private function createFolder() : FileInfo |
| 337 | 337 | { |
| 338 | - if(!$this->exists()) |
|
| 338 | + if (!$this->exists()) |
|
| 339 | 339 | { |
| 340 | 340 | FolderInfo::factory($this->getFolderPath()) |
| 341 | 341 | ->create() |
@@ -42,8 +42,7 @@ discard block |
||
| 42 | 42 | { |
| 43 | 43 | $info->delete(); |
| 44 | 44 | return true; |
| 45 | - } |
|
| 46 | - catch (FileHelper_Exception $e) |
|
| 45 | + } catch (FileHelper_Exception $e) |
|
| 47 | 46 | { |
| 48 | 47 | |
| 49 | 48 | } |
@@ -78,8 +77,7 @@ discard block |
||
| 78 | 77 | try |
| 79 | 78 | { |
| 80 | 79 | FileHelper::deleteFile($item); |
| 81 | - } |
|
| 82 | - catch (FileHelper_Exception $e) |
|
| 80 | + } catch (FileHelper_Exception $e) |
|
| 83 | 81 | { |
| 84 | 82 | return false; |
| 85 | 83 | } |
@@ -125,8 +123,7 @@ discard block |
||
| 125 | 123 | if ($item->isFolder()) |
| 126 | 124 | { |
| 127 | 125 | self::copy($item, $target . '/' . $item->getName()); |
| 128 | - } |
|
| 129 | - else if($item->isFile()) |
|
| 126 | + } else if($item->isFile()) |
|
| 130 | 127 | { |
| 131 | 128 | $item |
| 132 | 129 | ->requireIsFile() |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | public static function factory($path) : SerializedFile |
| 34 | 34 | { |
| 35 | - if($path instanceof self) { |
|
| 35 | + if ($path instanceof self) { |
|
| 36 | 36 | return $path; |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | 39 | $instance = self::createInstance($path); |
| 40 | 40 | |
| 41 | - if($instance instanceof self) { |
|
| 41 | + if ($instance instanceof self) { |
|
| 42 | 42 | return $instance; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | ) |
| 74 | 74 | ); |
| 75 | 75 | |
| 76 | - if($result !== false) { |
|
| 76 | + if ($result !== false) { |
|
| 77 | 77 | return $result; |
| 78 | 78 | } |
| 79 | 79 | |