@@ -170,7 +170,7 @@ discard block |
||
170 | 170 | |
171 | 171 | public function isHeadersPosition($position) |
172 | 172 | { |
173 | - if($this->headersPosition === $position) { |
|
173 | + if ($this->headersPosition === $position) { |
|
174 | 174 | return true; |
175 | 175 | } |
176 | 176 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | self::HEADERS_TOP |
198 | 198 | ); |
199 | 199 | |
200 | - if(!in_array($position, $validPositions)) { |
|
200 | + if (!in_array($position, $validPositions)) { |
|
201 | 201 | throw new CSVHelper_Exception( |
202 | 202 | 'Invalid headers position', |
203 | 203 | sprintf( |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | */ |
254 | 254 | public function getRow($index) |
255 | 255 | { |
256 | - if(isset($this->data[$index])) { |
|
256 | + if (isset($this->data[$index])) { |
|
257 | 257 | return $this->data[$index]; |
258 | 258 | } |
259 | 259 | |
@@ -320,9 +320,9 @@ discard block |
||
320 | 320 | public function getColumn($index) |
321 | 321 | { |
322 | 322 | $data = array(); |
323 | - for($i=0; $i < $this->rowCount; $i++) { |
|
323 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
324 | 324 | $value = ''; |
325 | - if(isset($this->data[$i][$index])) { |
|
325 | + if (isset($this->data[$i][$index])) { |
|
326 | 326 | $value = $this->data[$i][$index]; |
327 | 327 | } |
328 | 328 | |
@@ -339,7 +339,7 @@ discard block |
||
339 | 339 | */ |
340 | 340 | public function columnExists($index) |
341 | 341 | { |
342 | - if($index < $this->columnCount) { |
|
342 | + if ($index < $this->columnCount) { |
|
343 | 343 | return true; |
344 | 344 | } |
345 | 345 | |
@@ -350,7 +350,7 @@ discard block |
||
350 | 350 | { |
351 | 351 | $this->reset(); |
352 | 352 | |
353 | - if(empty(trim($this->csv))) { |
|
353 | + if (empty(trim($this->csv))) { |
|
354 | 354 | $this->addError('Tried to parse an empty CSV string.'); |
355 | 355 | return; |
356 | 356 | } |
@@ -362,14 +362,14 @@ discard block |
||
362 | 362 | |
363 | 363 | $parser = self::createParser(); |
364 | 364 | |
365 | - if(!$parser->parse($this->csv)) { |
|
365 | + if (!$parser->parse($this->csv)) { |
|
366 | 366 | $this->addError('The CSV string could not be parsed.'); |
367 | 367 | return; |
368 | 368 | } |
369 | 369 | |
370 | 370 | $result = $parser->data; |
371 | 371 | |
372 | - switch($this->headersPosition) |
|
372 | + switch ($this->headersPosition) |
|
373 | 373 | { |
374 | 374 | case self::HEADERS_TOP: |
375 | 375 | $this->headers = array_shift($result); |
@@ -378,7 +378,7 @@ discard block |
||
378 | 378 | case self::HEADERS_LEFT: |
379 | 379 | $keep = array(); |
380 | 380 | $total = count($result); |
381 | - for($i=0; $i < $total; $i++) { |
|
381 | + for ($i = 0; $i < $total; $i++) { |
|
382 | 382 | $row = $result[$i]; |
383 | 383 | $this->headers[] = array_shift($row); |
384 | 384 | $keep[] = $row; |
@@ -391,9 +391,9 @@ discard block |
||
391 | 391 | $this->data = $result; |
392 | 392 | $this->rowCount = count($this->data); |
393 | 393 | |
394 | - for($i=0; $i < $this->rowCount; $i++) { |
|
394 | + for ($i = 0; $i < $this->rowCount; $i++) { |
|
395 | 395 | $amount = count($this->data[$i]); |
396 | - if($amount > $this->columnCount) { |
|
396 | + if ($amount > $this->columnCount) { |
|
397 | 397 | $this->columnCount = $amount; |
398 | 398 | } |
399 | 399 | } |
@@ -437,8 +437,8 @@ discard block |
||
437 | 437 | ',,' => ',' |
438 | 438 | ); |
439 | 439 | |
440 | - foreach($search as $char => $separator) { |
|
441 | - if(strstr($this->csv, $char)) { |
|
440 | + foreach ($search as $char => $separator) { |
|
441 | + if (strstr($this->csv, $char)) { |
|
442 | 442 | return $separator; |
443 | 443 | } |
444 | 444 | } |
@@ -452,11 +452,11 @@ discard block |
||
452 | 452 | * @param string $delimiter |
453 | 453 | * @return Csv |
454 | 454 | */ |
455 | - public static function createParser(string $delimiter=self::DELIMITER_AUTO) : Csv |
|
455 | + public static function createParser(string $delimiter = self::DELIMITER_AUTO) : Csv |
|
456 | 456 | { |
457 | 457 | $csv = new Csv(); |
458 | 458 | |
459 | - if($delimiter !== self::DELIMITER_AUTO) { |
|
459 | + if ($delimiter !== self::DELIMITER_AUTO) { |
|
460 | 460 | $csv->delimiter = $delimiter; |
461 | 461 | } |
462 | 462 | |
@@ -482,7 +482,7 @@ discard block |
||
482 | 482 | $parser = self::createParser(); |
483 | 483 | $result = $parser->parse($path); |
484 | 484 | |
485 | - if($result === true) { |
|
485 | + if ($result === true) { |
|
486 | 486 | return $parser->data; |
487 | 487 | } |
488 | 488 | |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | $parser = self::createParser(); |
513 | 513 | $result = $parser->parse($string); |
514 | 514 | |
515 | - if($result === true) { |
|
515 | + if ($result === true) { |
|
516 | 516 | return $parser->data; |
517 | 517 | } |
518 | 518 |
@@ -52,32 +52,32 @@ discard block |
||
52 | 52 | const ERROR_PATH_IS_NOT_A_FOLDER = 340034; |
53 | 53 | const ERROR_CANNOT_WRITE_TO_FOLDER = 340035; |
54 | 54 | |
55 | - /** |
|
56 | - * Opens a serialized file and returns the unserialized data. |
|
57 | - * |
|
58 | - * @param string $file |
|
59 | - * @throws FileHelper_Exception |
|
60 | - * @return array |
|
61 | - * @deprecated Use parseSerializedFile() instead. |
|
62 | - * @see FileHelper::parseSerializedFile() |
|
63 | - */ |
|
55 | + /** |
|
56 | + * Opens a serialized file and returns the unserialized data. |
|
57 | + * |
|
58 | + * @param string $file |
|
59 | + * @throws FileHelper_Exception |
|
60 | + * @return array |
|
61 | + * @deprecated Use parseSerializedFile() instead. |
|
62 | + * @see FileHelper::parseSerializedFile() |
|
63 | + */ |
|
64 | 64 | public static function openUnserialized(string $file) : array |
65 | 65 | { |
66 | 66 | return self::parseSerializedFile($file); |
67 | 67 | } |
68 | 68 | |
69 | - /** |
|
70 | - * Opens a serialized file and returns the unserialized data. |
|
71 | - * |
|
72 | - * @param string $file |
|
73 | - * @throws FileHelper_Exception |
|
74 | - * @return array |
|
75 | - * @see FileHelper::parseSerializedFile() |
|
76 | - * |
|
77 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
78 | - * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
79 | - * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
80 | - */ |
|
69 | + /** |
|
70 | + * Opens a serialized file and returns the unserialized data. |
|
71 | + * |
|
72 | + * @param string $file |
|
73 | + * @throws FileHelper_Exception |
|
74 | + * @return array |
|
75 | + * @see FileHelper::parseSerializedFile() |
|
76 | + * |
|
77 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
78 | + * @see FileHelper::ERROR_SERIALIZED_FILE_CANNOT_BE_READ |
|
79 | + * @see FileHelper::ERROR_SERIALIZED_FILE_UNSERIALZE_FAILED |
|
80 | + */ |
|
81 | 81 | public static function parseSerializedFile(string $file) |
82 | 82 | { |
83 | 83 | self::requireFileExists($file); |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | return rmdir($rootFolder); |
147 | 147 | } |
148 | 148 | |
149 | - /** |
|
150 | - * Create a folder, if it does not exist yet. |
|
151 | - * |
|
152 | - * @param string $path |
|
153 | - * @throws FileHelper_Exception |
|
154 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
155 | - */ |
|
149 | + /** |
|
150 | + * Create a folder, if it does not exist yet. |
|
151 | + * |
|
152 | + * @param string $path |
|
153 | + * @throws FileHelper_Exception |
|
154 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
155 | + */ |
|
156 | 156 | public static function createFolder($path) |
157 | 157 | { |
158 | 158 | if(is_dir($path) || mkdir($path, 0777, true)) { |
@@ -199,22 +199,22 @@ discard block |
||
199 | 199 | } |
200 | 200 | } |
201 | 201 | |
202 | - /** |
|
203 | - * Copies a file to the target location. Includes checks |
|
204 | - * for most error sources, like the source file not being |
|
205 | - * readable. Automatically creates the target folder if it |
|
206 | - * does not exist yet. |
|
207 | - * |
|
208 | - * @param string $sourcePath |
|
209 | - * @param string $targetPath |
|
210 | - * @throws FileHelper_Exception |
|
211 | - * |
|
212 | - * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
213 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
214 | - * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
215 | - * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
216 | - * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
217 | - */ |
|
202 | + /** |
|
203 | + * Copies a file to the target location. Includes checks |
|
204 | + * for most error sources, like the source file not being |
|
205 | + * readable. Automatically creates the target folder if it |
|
206 | + * does not exist yet. |
|
207 | + * |
|
208 | + * @param string $sourcePath |
|
209 | + * @param string $targetPath |
|
210 | + * @throws FileHelper_Exception |
|
211 | + * |
|
212 | + * @see FileHelper::ERROR_CANNOT_CREATE_FOLDER |
|
213 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_FOUND |
|
214 | + * @see FileHelper::ERROR_SOURCE_FILE_NOT_READABLE |
|
215 | + * @see FileHelper::ERROR_TARGET_COPY_FOLDER_NOT_WRITABLE |
|
216 | + * @see FileHelper::ERROR_CANNOT_COPY_FILE |
|
217 | + */ |
|
218 | 218 | public static function copyFile(string $sourcePath, string $targetPath) : void |
219 | 219 | { |
220 | 220 | self::requireFileExists($sourcePath, self::ERROR_SOURCE_FILE_NOT_FOUND); |
@@ -254,15 +254,15 @@ discard block |
||
254 | 254 | ); |
255 | 255 | } |
256 | 256 | |
257 | - /** |
|
258 | - * Deletes the target file. Ignored if it cannot be found, |
|
259 | - * and throws an exception if it fails. |
|
260 | - * |
|
261 | - * @param string $filePath |
|
262 | - * @throws FileHelper_Exception |
|
263 | - * |
|
264 | - * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
265 | - */ |
|
257 | + /** |
|
258 | + * Deletes the target file. Ignored if it cannot be found, |
|
259 | + * and throws an exception if it fails. |
|
260 | + * |
|
261 | + * @param string $filePath |
|
262 | + * @throws FileHelper_Exception |
|
263 | + * |
|
264 | + * @see FileHelper::ERROR_CANNOT_DELETE_FILE |
|
265 | + */ |
|
266 | 266 | public static function deleteFile(string $filePath) : void |
267 | 267 | { |
268 | 268 | if(!file_exists($filePath)) { |
@@ -284,15 +284,15 @@ discard block |
||
284 | 284 | } |
285 | 285 | |
286 | 286 | /** |
287 | - * Creates a new CSV parser instance and returns it. |
|
288 | - * |
|
289 | - * @param string $delimiter |
|
290 | - * @param string $enclosure |
|
291 | - * @param string $escape |
|
292 | - * @param bool $heading |
|
293 | - * @return Csv |
|
287 | + * Creates a new CSV parser instance and returns it. |
|
288 | + * |
|
289 | + * @param string $delimiter |
|
290 | + * @param string $enclosure |
|
291 | + * @param string $escape |
|
292 | + * @param bool $heading |
|
293 | + * @return Csv |
|
294 | 294 | * @see CSVHelper::createParser() |
295 | - */ |
|
295 | + */ |
|
296 | 296 | public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : Csv |
297 | 297 | { |
298 | 298 | if($delimiter==='') { $delimiter = ';'; } |
@@ -305,21 +305,21 @@ discard block |
||
305 | 305 | return $parser; |
306 | 306 | } |
307 | 307 | |
308 | - /** |
|
309 | - * Parses all lines in the specified string and returns an |
|
310 | - * indexed array with all csv values in each line. |
|
311 | - * |
|
312 | - * @param string $csv |
|
313 | - * @param string $delimiter |
|
314 | - * @param string $enclosure |
|
315 | - * @param string $escape |
|
316 | - * @param bool $heading |
|
317 | - * @return array |
|
318 | - * @throws FileHelper_Exception |
|
319 | - * |
|
320 | - * @see parseCSVFile() |
|
321 | - * @see FileHelper::ERROR_PARSING_CSV |
|
322 | - */ |
|
308 | + /** |
|
309 | + * Parses all lines in the specified string and returns an |
|
310 | + * indexed array with all csv values in each line. |
|
311 | + * |
|
312 | + * @param string $csv |
|
313 | + * @param string $delimiter |
|
314 | + * @param string $enclosure |
|
315 | + * @param string $escape |
|
316 | + * @param bool $heading |
|
317 | + * @return array |
|
318 | + * @throws FileHelper_Exception |
|
319 | + * |
|
320 | + * @see parseCSVFile() |
|
321 | + * @see FileHelper::ERROR_PARSING_CSV |
|
322 | + */ |
|
323 | 323 | public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
324 | 324 | { |
325 | 325 | $parser = self::createCSVParser($delimiter, $enclosure, '\\', $heading); |
@@ -490,31 +490,31 @@ discard block |
||
490 | 490 | ); |
491 | 491 | } |
492 | 492 | |
493 | - /** |
|
494 | - * Verifies whether the target file is a PHP file. The path |
|
495 | - * to the file can be a path to a file as a string, or a |
|
496 | - * DirectoryIterator object instance. |
|
497 | - * |
|
498 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
499 | - * @return boolean |
|
500 | - */ |
|
493 | + /** |
|
494 | + * Verifies whether the target file is a PHP file. The path |
|
495 | + * to the file can be a path to a file as a string, or a |
|
496 | + * DirectoryIterator object instance. |
|
497 | + * |
|
498 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
499 | + * @return boolean |
|
500 | + */ |
|
501 | 501 | public static function isPHPFile($pathOrDirIterator) |
502 | 502 | { |
503 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
504 | - return true; |
|
505 | - } |
|
503 | + if(self::getExtension($pathOrDirIterator) == 'php') { |
|
504 | + return true; |
|
505 | + } |
|
506 | 506 | |
507 | - return false; |
|
507 | + return false; |
|
508 | 508 | } |
509 | 509 | |
510 | - /** |
|
511 | - * Retrieves the extension of the specified file. Can be a path |
|
512 | - * to a file as a string, or a DirectoryIterator object instance. |
|
513 | - * |
|
514 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
515 | - * @param bool $lowercase |
|
516 | - * @return string |
|
517 | - */ |
|
510 | + /** |
|
511 | + * Retrieves the extension of the specified file. Can be a path |
|
512 | + * to a file as a string, or a DirectoryIterator object instance. |
|
513 | + * |
|
514 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
515 | + * @param bool $lowercase |
|
516 | + * @return string |
|
517 | + */ |
|
518 | 518 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
519 | 519 | { |
520 | 520 | if($pathOrDirIterator instanceof \DirectoryIterator) { |
@@ -525,51 +525,51 @@ discard block |
||
525 | 525 | |
526 | 526 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
527 | 527 | if($lowercase) { |
528 | - $ext = mb_strtolower($ext); |
|
528 | + $ext = mb_strtolower($ext); |
|
529 | 529 | } |
530 | 530 | |
531 | 531 | return $ext; |
532 | 532 | } |
533 | 533 | |
534 | - /** |
|
535 | - * Retrieves the file name from a path, with or without extension. |
|
536 | - * The path to the file can be a string, or a DirectoryIterator object |
|
537 | - * instance. |
|
538 | - * |
|
539 | - * In case of folders, behaves like the pathinfo function: returns |
|
540 | - * the name of the folder. |
|
541 | - * |
|
542 | - * @param string|\DirectoryIterator $pathOrDirIterator |
|
543 | - * @param bool $extension |
|
544 | - * @return string |
|
545 | - */ |
|
534 | + /** |
|
535 | + * Retrieves the file name from a path, with or without extension. |
|
536 | + * The path to the file can be a string, or a DirectoryIterator object |
|
537 | + * instance. |
|
538 | + * |
|
539 | + * In case of folders, behaves like the pathinfo function: returns |
|
540 | + * the name of the folder. |
|
541 | + * |
|
542 | + * @param string|\DirectoryIterator $pathOrDirIterator |
|
543 | + * @param bool $extension |
|
544 | + * @return string |
|
545 | + */ |
|
546 | 546 | public static function getFilename($pathOrDirIterator, $extension = true) |
547 | 547 | { |
548 | 548 | $path = $pathOrDirIterator; |
549 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
550 | - $path = $pathOrDirIterator->getFilename(); |
|
551 | - } |
|
549 | + if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
550 | + $path = $pathOrDirIterator->getFilename(); |
|
551 | + } |
|
552 | 552 | |
553 | - $path = self::normalizePath($path); |
|
553 | + $path = self::normalizePath($path); |
|
554 | 554 | |
555 | - if(!$extension) { |
|
556 | - return pathinfo($path, PATHINFO_FILENAME); |
|
557 | - } |
|
555 | + if(!$extension) { |
|
556 | + return pathinfo($path, PATHINFO_FILENAME); |
|
557 | + } |
|
558 | 558 | |
559 | - return pathinfo($path, PATHINFO_BASENAME); |
|
559 | + return pathinfo($path, PATHINFO_BASENAME); |
|
560 | 560 | } |
561 | 561 | |
562 | - /** |
|
563 | - * Tries to read the contents of the target file and |
|
564 | - * treat it as JSON to return the decoded JSON data. |
|
565 | - * |
|
566 | - * @param string $file |
|
567 | - * @throws FileHelper_Exception |
|
568 | - * @return array |
|
569 | - * |
|
570 | - * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
571 | - * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
572 | - */ |
|
562 | + /** |
|
563 | + * Tries to read the contents of the target file and |
|
564 | + * treat it as JSON to return the decoded JSON data. |
|
565 | + * |
|
566 | + * @param string $file |
|
567 | + * @throws FileHelper_Exception |
|
568 | + * @return array |
|
569 | + * |
|
570 | + * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
|
571 | + * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
|
572 | + */ |
|
573 | 573 | public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
574 | 574 | { |
575 | 575 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
@@ -605,16 +605,16 @@ discard block |
||
605 | 605 | return $json; |
606 | 606 | } |
607 | 607 | |
608 | - /** |
|
609 | - * Corrects common formatting mistakes when users enter |
|
610 | - * file names, like too many spaces, dots and the like. |
|
611 | - * |
|
612 | - * NOTE: if the file name contains a path, the path is |
|
613 | - * stripped, leaving only the file name. |
|
614 | - * |
|
615 | - * @param string $name |
|
616 | - * @return string |
|
617 | - */ |
|
608 | + /** |
|
609 | + * Corrects common formatting mistakes when users enter |
|
610 | + * file names, like too many spaces, dots and the like. |
|
611 | + * |
|
612 | + * NOTE: if the file name contains a path, the path is |
|
613 | + * stripped, leaving only the file name. |
|
614 | + * |
|
615 | + * @param string $name |
|
616 | + * @return string |
|
617 | + */ |
|
618 | 618 | public static function fixFileName(string $name) : string |
619 | 619 | { |
620 | 620 | $name = trim($name); |
@@ -644,68 +644,68 @@ discard block |
||
644 | 644 | return $name; |
645 | 645 | } |
646 | 646 | |
647 | - /** |
|
648 | - * Creates an instance of the file finder, which is an easier |
|
649 | - * alternative to the other manual findFile methods, since all |
|
650 | - * options can be set by chaining. |
|
651 | - * |
|
652 | - * @param string $path |
|
653 | - * @return FileHelper_FileFinder |
|
654 | - */ |
|
647 | + /** |
|
648 | + * Creates an instance of the file finder, which is an easier |
|
649 | + * alternative to the other manual findFile methods, since all |
|
650 | + * options can be set by chaining. |
|
651 | + * |
|
652 | + * @param string $path |
|
653 | + * @return FileHelper_FileFinder |
|
654 | + */ |
|
655 | 655 | public static function createFileFinder(string $path) : FileHelper_FileFinder |
656 | 656 | { |
657 | 657 | return new FileHelper_FileFinder($path); |
658 | 658 | } |
659 | 659 | |
660 | - /** |
|
661 | - * Searches for all HTML files in the target folder. |
|
662 | - * |
|
663 | - * NOTE: This method only exists for backwards compatibility. |
|
664 | - * Use the `createFileFinder()` method instead, which offers |
|
665 | - * an object oriented interface that is much easier to use. |
|
666 | - * |
|
667 | - * @param string $targetFolder |
|
668 | - * @param array $options |
|
669 | - * @return array An indexed array with files. |
|
670 | - * @see FileHelper::createFileFinder() |
|
671 | - */ |
|
660 | + /** |
|
661 | + * Searches for all HTML files in the target folder. |
|
662 | + * |
|
663 | + * NOTE: This method only exists for backwards compatibility. |
|
664 | + * Use the `createFileFinder()` method instead, which offers |
|
665 | + * an object oriented interface that is much easier to use. |
|
666 | + * |
|
667 | + * @param string $targetFolder |
|
668 | + * @param array $options |
|
669 | + * @return array An indexed array with files. |
|
670 | + * @see FileHelper::createFileFinder() |
|
671 | + */ |
|
672 | 672 | public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
673 | 673 | { |
674 | 674 | return self::findFiles($targetFolder, array('html'), $options); |
675 | 675 | } |
676 | 676 | |
677 | - /** |
|
678 | - * Searches for all PHP files in the target folder. |
|
679 | - * |
|
680 | - * NOTE: This method only exists for backwards compatibility. |
|
681 | - * Use the `createFileFinder()` method instead, which offers |
|
682 | - * an object oriented interface that is much easier to use. |
|
683 | - * |
|
684 | - * @param string $targetFolder |
|
685 | - * @param array $options |
|
686 | - * @return array An indexed array of PHP files. |
|
687 | - * @see FileHelper::createFileFinder() |
|
688 | - */ |
|
677 | + /** |
|
678 | + * Searches for all PHP files in the target folder. |
|
679 | + * |
|
680 | + * NOTE: This method only exists for backwards compatibility. |
|
681 | + * Use the `createFileFinder()` method instead, which offers |
|
682 | + * an object oriented interface that is much easier to use. |
|
683 | + * |
|
684 | + * @param string $targetFolder |
|
685 | + * @param array $options |
|
686 | + * @return array An indexed array of PHP files. |
|
687 | + * @see FileHelper::createFileFinder() |
|
688 | + */ |
|
689 | 689 | public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
690 | 690 | { |
691 | 691 | return self::findFiles($targetFolder, array('php'), $options); |
692 | 692 | } |
693 | 693 | |
694 | - /** |
|
695 | - * Finds files according to the specified options. |
|
696 | - * |
|
697 | - * NOTE: This method only exists for backwards compatibility. |
|
698 | - * Use the `createFileFinder()` method instead, which offers |
|
699 | - * an object oriented interface that is much easier to use. |
|
700 | - * |
|
701 | - * @param string $targetFolder |
|
702 | - * @param array $extensions |
|
703 | - * @param array $options |
|
704 | - * @param array $files |
|
705 | - * @throws FileHelper_Exception |
|
706 | - * @return array |
|
707 | - * @see FileHelper::createFileFinder() |
|
708 | - */ |
|
694 | + /** |
|
695 | + * Finds files according to the specified options. |
|
696 | + * |
|
697 | + * NOTE: This method only exists for backwards compatibility. |
|
698 | + * Use the `createFileFinder()` method instead, which offers |
|
699 | + * an object oriented interface that is much easier to use. |
|
700 | + * |
|
701 | + * @param string $targetFolder |
|
702 | + * @param array $extensions |
|
703 | + * @param array $options |
|
704 | + * @param array $files |
|
705 | + * @throws FileHelper_Exception |
|
706 | + * @return array |
|
707 | + * @see FileHelper::createFileFinder() |
|
708 | + */ |
|
709 | 709 | public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
710 | 710 | { |
711 | 711 | $finder = self::createFileFinder($targetFolder); |
@@ -731,14 +731,14 @@ discard block |
||
731 | 731 | return $finder->getAll(); |
732 | 732 | } |
733 | 733 | |
734 | - /** |
|
735 | - * Removes the extension from the specified path or file name, |
|
736 | - * if any, and returns the name without the extension. |
|
737 | - * |
|
738 | - * @param string $filename |
|
739 | - * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
|
740 | - * @return string |
|
741 | - */ |
|
734 | + /** |
|
735 | + * Removes the extension from the specified path or file name, |
|
736 | + * if any, and returns the name without the extension. |
|
737 | + * |
|
738 | + * @param string $filename |
|
739 | + * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
|
740 | + * @return string |
|
741 | + */ |
|
742 | 742 | public static function removeExtension(string $filename, bool $keepPath=false) : string |
743 | 743 | { |
744 | 744 | // normalize paths to allow windows style slashes even on nix servers |
@@ -758,22 +758,22 @@ discard block |
||
758 | 758 | return implode('/', $parts); |
759 | 759 | } |
760 | 760 | |
761 | - /** |
|
762 | - * Detects the UTF BOM in the target file, if any. Returns |
|
763 | - * the encoding matching the BOM, which can be any of the |
|
764 | - * following: |
|
765 | - * |
|
766 | - * <ul> |
|
767 | - * <li>UTF32-BE</li> |
|
768 | - * <li>UTF32-LE</li> |
|
769 | - * <li>UTF16-BE</li> |
|
770 | - * <li>UTF16-LE</li> |
|
771 | - * <li>UTF8</li> |
|
772 | - * </ul> |
|
773 | - * |
|
774 | - * @param string $filename |
|
775 | - * @return string|NULL |
|
776 | - */ |
|
761 | + /** |
|
762 | + * Detects the UTF BOM in the target file, if any. Returns |
|
763 | + * the encoding matching the BOM, which can be any of the |
|
764 | + * following: |
|
765 | + * |
|
766 | + * <ul> |
|
767 | + * <li>UTF32-BE</li> |
|
768 | + * <li>UTF32-LE</li> |
|
769 | + * <li>UTF16-BE</li> |
|
770 | + * <li>UTF16-LE</li> |
|
771 | + * <li>UTF8</li> |
|
772 | + * </ul> |
|
773 | + * |
|
774 | + * @param string $filename |
|
775 | + * @return string|NULL |
|
776 | + */ |
|
777 | 777 | public static function detectUTFBom(string $filename) : ?string |
778 | 778 | { |
779 | 779 | $fp = fopen($filename, 'r'); |
@@ -805,13 +805,13 @@ discard block |
||
805 | 805 | |
806 | 806 | protected static $utfBoms; |
807 | 807 | |
808 | - /** |
|
809 | - * Retrieves a list of all UTF byte order mark character |
|
810 | - * sequences, as an assocative array with UTF encoding => bom sequence |
|
811 | - * pairs. |
|
812 | - * |
|
813 | - * @return array |
|
814 | - */ |
|
808 | + /** |
|
809 | + * Retrieves a list of all UTF byte order mark character |
|
810 | + * sequences, as an assocative array with UTF encoding => bom sequence |
|
811 | + * pairs. |
|
812 | + * |
|
813 | + * @return array |
|
814 | + */ |
|
815 | 815 | public static function getUTFBOMs() |
816 | 816 | { |
817 | 817 | if(!isset(self::$utfBoms)) { |
@@ -827,15 +827,15 @@ discard block |
||
827 | 827 | return self::$utfBoms; |
828 | 828 | } |
829 | 829 | |
830 | - /** |
|
831 | - * Checks whether the specified encoding is a valid |
|
832 | - * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
833 | - * Also accounts for alternate way to write the, like |
|
834 | - * "UTF-8", and omitting little/big endian suffixes. |
|
835 | - * |
|
836 | - * @param string $encoding |
|
837 | - * @return boolean |
|
838 | - */ |
|
830 | + /** |
|
831 | + * Checks whether the specified encoding is a valid |
|
832 | + * unicode encoding, for example "UTF16-LE" or "UTF8". |
|
833 | + * Also accounts for alternate way to write the, like |
|
834 | + * "UTF-8", and omitting little/big endian suffixes. |
|
835 | + * |
|
836 | + * @param string $encoding |
|
837 | + * @return boolean |
|
838 | + */ |
|
839 | 839 | public static function isValidUnicodeEncoding(string $encoding) : bool |
840 | 840 | { |
841 | 841 | $encodings = self::getKnownUnicodeEncodings(); |
@@ -854,40 +854,40 @@ discard block |
||
854 | 854 | return in_array($encoding, $keep); |
855 | 855 | } |
856 | 856 | |
857 | - /** |
|
858 | - * Retrieves a list of all known unicode file encodings. |
|
859 | - * @return array |
|
860 | - */ |
|
857 | + /** |
|
858 | + * Retrieves a list of all known unicode file encodings. |
|
859 | + * @return array |
|
860 | + */ |
|
861 | 861 | public static function getKnownUnicodeEncodings() |
862 | 862 | { |
863 | 863 | return array_keys(self::getUTFBOMs()); |
864 | 864 | } |
865 | 865 | |
866 | - /** |
|
867 | - * Normalizes the slash style in a file or folder path, |
|
868 | - * by replacing any antislashes with forward slashes. |
|
869 | - * |
|
870 | - * @param string $path |
|
871 | - * @return string |
|
872 | - */ |
|
866 | + /** |
|
867 | + * Normalizes the slash style in a file or folder path, |
|
868 | + * by replacing any antislashes with forward slashes. |
|
869 | + * |
|
870 | + * @param string $path |
|
871 | + * @return string |
|
872 | + */ |
|
873 | 873 | public static function normalizePath(string $path) : string |
874 | 874 | { |
875 | 875 | return str_replace(array('\\', '//'), array('/', '/'), $path); |
876 | 876 | } |
877 | 877 | |
878 | - /** |
|
879 | - * Saves the specified data to a file, JSON encoded. |
|
880 | - * |
|
881 | - * @param mixed $data |
|
882 | - * @param string $file |
|
883 | - * @param bool $pretty |
|
884 | - * @throws FileHelper_Exception |
|
885 | - * |
|
886 | - * @see FileHelper::ERROR_JSON_ENCODE_ERROR |
|
887 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
888 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
889 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
890 | - */ |
|
878 | + /** |
|
879 | + * Saves the specified data to a file, JSON encoded. |
|
880 | + * |
|
881 | + * @param mixed $data |
|
882 | + * @param string $file |
|
883 | + * @param bool $pretty |
|
884 | + * @throws FileHelper_Exception |
|
885 | + * |
|
886 | + * @see FileHelper::ERROR_JSON_ENCODE_ERROR |
|
887 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
888 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
889 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
890 | + */ |
|
891 | 891 | public static function saveAsJSON($data, string $file, bool $pretty=false) |
892 | 892 | { |
893 | 893 | $options = null; |
@@ -911,18 +911,18 @@ discard block |
||
911 | 911 | self::saveFile($file, $json); |
912 | 912 | } |
913 | 913 | |
914 | - /** |
|
915 | - * Saves the specified content to the target file, creating |
|
916 | - * the file and the folder as necessary. |
|
917 | - * |
|
918 | - * @param string $filePath |
|
919 | - * @param string $content |
|
920 | - * @throws FileHelper_Exception |
|
921 | - * |
|
922 | - * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
923 | - * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
924 | - * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
925 | - */ |
|
914 | + /** |
|
915 | + * Saves the specified content to the target file, creating |
|
916 | + * the file and the folder as necessary. |
|
917 | + * |
|
918 | + * @param string $filePath |
|
919 | + * @param string $content |
|
920 | + * @throws FileHelper_Exception |
|
921 | + * |
|
922 | + * @see FileHelper::ERROR_SAVE_FOLDER_NOT_WRITABLE |
|
923 | + * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
|
924 | + * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
|
925 | + */ |
|
926 | 926 | public static function saveFile(string $filePath, string $content='') : void |
927 | 927 | { |
928 | 928 | $filePath = self::normalizePath($filePath); |
@@ -989,12 +989,12 @@ discard block |
||
989 | 989 | ); |
990 | 990 | } |
991 | 991 | |
992 | - /** |
|
993 | - * Checks whether it is possible to run PHP command |
|
994 | - * line commands. |
|
995 | - * |
|
996 | - * @return boolean |
|
997 | - */ |
|
992 | + /** |
|
993 | + * Checks whether it is possible to run PHP command |
|
994 | + * line commands. |
|
995 | + * |
|
996 | + * @return boolean |
|
997 | + */ |
|
998 | 998 | public static function canMakePHPCalls() : bool |
999 | 999 | { |
1000 | 1000 | return self::cliCommandExists('php'); |
@@ -1071,16 +1071,16 @@ discard block |
||
1071 | 1071 | return $result; |
1072 | 1072 | } |
1073 | 1073 | |
1074 | - /** |
|
1075 | - * Validates a PHP file's syntax. |
|
1076 | - * |
|
1077 | - * NOTE: This will fail silently if the PHP command line |
|
1078 | - * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
1079 | - * to check this beforehand as needed. |
|
1080 | - * |
|
1081 | - * @param string $path |
|
1082 | - * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
1083 | - */ |
|
1074 | + /** |
|
1075 | + * Validates a PHP file's syntax. |
|
1076 | + * |
|
1077 | + * NOTE: This will fail silently if the PHP command line |
|
1078 | + * is not available. Use {@link FileHelper::canMakePHPCalls()} |
|
1079 | + * to check this beforehand as needed. |
|
1080 | + * |
|
1081 | + * @param string $path |
|
1082 | + * @return boolean|array A boolean true if the file is valid, an array with validation messages otherwise. |
|
1083 | + */ |
|
1084 | 1084 | public static function checkPHPFileSyntax($path) |
1085 | 1085 | { |
1086 | 1086 | if(!self::canMakePHPCalls()) { |
@@ -1104,14 +1104,14 @@ discard block |
||
1104 | 1104 | return $output; |
1105 | 1105 | } |
1106 | 1106 | |
1107 | - /** |
|
1108 | - * Retrieves the last modified date for the specified file or folder. |
|
1109 | - * |
|
1110 | - * Note: If the target does not exist, returns null. |
|
1111 | - * |
|
1112 | - * @param string $path |
|
1113 | - * @return \DateTime|NULL |
|
1114 | - */ |
|
1107 | + /** |
|
1108 | + * Retrieves the last modified date for the specified file or folder. |
|
1109 | + * |
|
1110 | + * Note: If the target does not exist, returns null. |
|
1111 | + * |
|
1112 | + * @param string $path |
|
1113 | + * @return \DateTime|NULL |
|
1114 | + */ |
|
1115 | 1115 | public static function getModifiedDate($path) |
1116 | 1116 | { |
1117 | 1117 | $time = filemtime($path); |
@@ -1124,24 +1124,24 @@ discard block |
||
1124 | 1124 | return null; |
1125 | 1125 | } |
1126 | 1126 | |
1127 | - /** |
|
1128 | - * Retrieves the names of all subfolders in the specified path. |
|
1129 | - * |
|
1130 | - * Available options: |
|
1131 | - * |
|
1132 | - * - recursive: true/false |
|
1133 | - * Whether to search for subfolders recursively. |
|
1134 | - * |
|
1135 | - * - absolute-paths: true/false |
|
1136 | - * Whether to return a list of absolute paths. |
|
1137 | - * |
|
1138 | - * @param string $targetFolder |
|
1139 | - * @param array $options |
|
1140 | - * @throws FileHelper_Exception |
|
1141 | - * @return string[] |
|
1142 | - * |
|
1143 | - * @todo Move this to a separate class. |
|
1144 | - */ |
|
1127 | + /** |
|
1128 | + * Retrieves the names of all subfolders in the specified path. |
|
1129 | + * |
|
1130 | + * Available options: |
|
1131 | + * |
|
1132 | + * - recursive: true/false |
|
1133 | + * Whether to search for subfolders recursively. |
|
1134 | + * |
|
1135 | + * - absolute-paths: true/false |
|
1136 | + * Whether to return a list of absolute paths. |
|
1137 | + * |
|
1138 | + * @param string $targetFolder |
|
1139 | + * @param array $options |
|
1140 | + * @throws FileHelper_Exception |
|
1141 | + * @return string[] |
|
1142 | + * |
|
1143 | + * @todo Move this to a separate class. |
|
1144 | + */ |
|
1145 | 1145 | public static function getSubfolders($targetFolder, $options = array()) |
1146 | 1146 | { |
1147 | 1147 | if(!is_dir($targetFolder)) |
@@ -1202,16 +1202,16 @@ discard block |
||
1202 | 1202 | return $result; |
1203 | 1203 | } |
1204 | 1204 | |
1205 | - /** |
|
1206 | - * Retrieves the maximum allowed upload file size, in bytes. |
|
1207 | - * Takes into account the PHP ini settings <code>post_max_size</code> |
|
1208 | - * and <code>upload_max_filesize</code>. Since these cannot |
|
1209 | - * be modified at runtime, they are the hard limits for uploads. |
|
1210 | - * |
|
1211 | - * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
1212 | - * |
|
1213 | - * @return int Will return <code>-1</code> if no limit. |
|
1214 | - */ |
|
1205 | + /** |
|
1206 | + * Retrieves the maximum allowed upload file size, in bytes. |
|
1207 | + * Takes into account the PHP ini settings <code>post_max_size</code> |
|
1208 | + * and <code>upload_max_filesize</code>. Since these cannot |
|
1209 | + * be modified at runtime, they are the hard limits for uploads. |
|
1210 | + * |
|
1211 | + * NOTE: Based on binary values, where 1KB = 1024 Bytes. |
|
1212 | + * |
|
1213 | + * @return int Will return <code>-1</code> if no limit. |
|
1214 | + */ |
|
1215 | 1215 | public static function getMaxUploadFilesize() : int |
1216 | 1216 | { |
1217 | 1217 | static $max_size = -1; |
@@ -1249,16 +1249,16 @@ discard block |
||
1249 | 1249 | return round($size); |
1250 | 1250 | } |
1251 | 1251 | |
1252 | - /** |
|
1253 | - * Makes a path relative using a folder depth: will reduce the |
|
1254 | - * length of the path so that only the amount of folders defined |
|
1255 | - * in the <code>$depth</code> attribute are shown below the actual |
|
1256 | - * folder or file in the path. |
|
1257 | - * |
|
1258 | - * @param string $path The absolute or relative path |
|
1259 | - * @param int $depth The folder depth to reduce the path to |
|
1260 | - * @return string |
|
1261 | - */ |
|
1252 | + /** |
|
1253 | + * Makes a path relative using a folder depth: will reduce the |
|
1254 | + * length of the path so that only the amount of folders defined |
|
1255 | + * in the <code>$depth</code> attribute are shown below the actual |
|
1256 | + * folder or file in the path. |
|
1257 | + * |
|
1258 | + * @param string $path The absolute or relative path |
|
1259 | + * @param int $depth The folder depth to reduce the path to |
|
1260 | + * @return string |
|
1261 | + */ |
|
1262 | 1262 | public static function relativizePathByDepth(string $path, int $depth=2) : string |
1263 | 1263 | { |
1264 | 1264 | $path = self::normalizePath($path); |
@@ -1296,23 +1296,23 @@ discard block |
||
1296 | 1296 | return trim(implode('/', $tokens), '/'); |
1297 | 1297 | } |
1298 | 1298 | |
1299 | - /** |
|
1300 | - * Makes the specified path relative to another path, |
|
1301 | - * by removing one from the other if found. Also |
|
1302 | - * normalizes the path to use forward slashes. |
|
1303 | - * |
|
1304 | - * Example: |
|
1305 | - * |
|
1306 | - * <pre> |
|
1307 | - * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
1308 | - * </pre> |
|
1309 | - * |
|
1310 | - * Result: <code>to/file.txt</code> |
|
1311 | - * |
|
1312 | - * @param string $path |
|
1313 | - * @param string $relativeTo |
|
1314 | - * @return string |
|
1315 | - */ |
|
1299 | + /** |
|
1300 | + * Makes the specified path relative to another path, |
|
1301 | + * by removing one from the other if found. Also |
|
1302 | + * normalizes the path to use forward slashes. |
|
1303 | + * |
|
1304 | + * Example: |
|
1305 | + * |
|
1306 | + * <pre> |
|
1307 | + * relativizePath('c:\some\folder\to\file.txt', 'c:\some\folder'); |
|
1308 | + * </pre> |
|
1309 | + * |
|
1310 | + * Result: <code>to/file.txt</code> |
|
1311 | + * |
|
1312 | + * @param string $path |
|
1313 | + * @param string $relativeTo |
|
1314 | + * @return string |
|
1315 | + */ |
|
1316 | 1316 | public static function relativizePath(string $path, string $relativeTo) : string |
1317 | 1317 | { |
1318 | 1318 | $path = self::normalizePath($path); |
@@ -1324,17 +1324,17 @@ discard block |
||
1324 | 1324 | return $relative; |
1325 | 1325 | } |
1326 | 1326 | |
1327 | - /** |
|
1328 | - * Checks that the target file exists, and throws an exception |
|
1329 | - * if it does not. |
|
1330 | - * |
|
1331 | - * @param string $path |
|
1332 | - * @param int|NULL $errorCode Optional custom error code |
|
1333 | - * @throws FileHelper_Exception |
|
1334 | - * @return string The real path to the file |
|
1335 | - * |
|
1336 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1337 | - */ |
|
1327 | + /** |
|
1328 | + * Checks that the target file exists, and throws an exception |
|
1329 | + * if it does not. |
|
1330 | + * |
|
1331 | + * @param string $path |
|
1332 | + * @param int|NULL $errorCode Optional custom error code |
|
1333 | + * @throws FileHelper_Exception |
|
1334 | + * @return string The real path to the file |
|
1335 | + * |
|
1336 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1337 | + */ |
|
1338 | 1338 | public static function requireFileExists(string $path, ?int $errorCode=null) : string |
1339 | 1339 | { |
1340 | 1340 | $result = realpath($path); |
@@ -1372,18 +1372,18 @@ discard block |
||
1372 | 1372 | ); |
1373 | 1373 | } |
1374 | 1374 | |
1375 | - /** |
|
1376 | - * Reads a specific line number from the target file and returns its |
|
1377 | - * contents, if the file has such a line. Does so with little memory |
|
1378 | - * usage, as the file is not read entirely into memory. |
|
1379 | - * |
|
1380 | - * @param string $path |
|
1381 | - * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
1382 | - * @return string|NULL Will return null if the requested line does not exist. |
|
1383 | - * @throws FileHelper_Exception |
|
1384 | - * |
|
1385 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1386 | - */ |
|
1375 | + /** |
|
1376 | + * Reads a specific line number from the target file and returns its |
|
1377 | + * contents, if the file has such a line. Does so with little memory |
|
1378 | + * usage, as the file is not read entirely into memory. |
|
1379 | + * |
|
1380 | + * @param string $path |
|
1381 | + * @param int $lineNumber Note: 1-based; the first line is number 1. |
|
1382 | + * @return string|NULL Will return null if the requested line does not exist. |
|
1383 | + * @throws FileHelper_Exception |
|
1384 | + * |
|
1385 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1386 | + */ |
|
1387 | 1387 | public static function getLineFromFile(string $path, int $lineNumber) : ?string |
1388 | 1388 | { |
1389 | 1389 | self::requireFileExists($path); |
@@ -1399,19 +1399,19 @@ discard block |
||
1399 | 1399 | $file->seek($targetLine); |
1400 | 1400 | |
1401 | 1401 | if($file->key() !== $targetLine) { |
1402 | - return null; |
|
1402 | + return null; |
|
1403 | 1403 | } |
1404 | 1404 | |
1405 | 1405 | return $file->current(); |
1406 | 1406 | } |
1407 | 1407 | |
1408 | - /** |
|
1409 | - * Retrieves the total amount of lines in the file, without |
|
1410 | - * reading the whole file into memory. |
|
1411 | - * |
|
1412 | - * @param string $path |
|
1413 | - * @return int |
|
1414 | - */ |
|
1408 | + /** |
|
1409 | + * Retrieves the total amount of lines in the file, without |
|
1410 | + * reading the whole file into memory. |
|
1411 | + * |
|
1412 | + * @param string $path |
|
1413 | + * @return int |
|
1414 | + */ |
|
1415 | 1415 | public static function countFileLines(string $path) : int |
1416 | 1416 | { |
1417 | 1417 | self::requireFileExists($path); |
@@ -1441,26 +1441,26 @@ discard block |
||
1441 | 1441 | return $number+1; |
1442 | 1442 | } |
1443 | 1443 | |
1444 | - /** |
|
1445 | - * Parses the target file to detect any PHP classes contained |
|
1446 | - * within, and retrieve information on them. Does not use the |
|
1447 | - * PHP reflection API. |
|
1448 | - * |
|
1449 | - * @param string $filePath |
|
1450 | - * @return FileHelper_PHPClassInfo |
|
1451 | - */ |
|
1444 | + /** |
|
1445 | + * Parses the target file to detect any PHP classes contained |
|
1446 | + * within, and retrieve information on them. Does not use the |
|
1447 | + * PHP reflection API. |
|
1448 | + * |
|
1449 | + * @param string $filePath |
|
1450 | + * @return FileHelper_PHPClassInfo |
|
1451 | + */ |
|
1452 | 1452 | public static function findPHPClasses(string $filePath) : FileHelper_PHPClassInfo |
1453 | 1453 | { |
1454 | 1454 | return new FileHelper_PHPClassInfo($filePath); |
1455 | 1455 | } |
1456 | 1456 | |
1457 | - /** |
|
1458 | - * Detects the end of line style used in the target file, if any. |
|
1459 | - * Can be used with large files, because it only reads part of it. |
|
1460 | - * |
|
1461 | - * @param string $filePath The path to the file. |
|
1462 | - * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
1463 | - */ |
|
1457 | + /** |
|
1458 | + * Detects the end of line style used in the target file, if any. |
|
1459 | + * Can be used with large files, because it only reads part of it. |
|
1460 | + * |
|
1461 | + * @param string $filePath The path to the file. |
|
1462 | + * @return NULL|ConvertHelper_EOL The end of line character information, or NULL if none is found. |
|
1463 | + */ |
|
1464 | 1464 | public static function detectEOLCharacter(string $filePath) : ?ConvertHelper_EOL |
1465 | 1465 | { |
1466 | 1466 | // 20 lines is enough to get a good picture of the newline style in the file. |
@@ -1473,18 +1473,18 @@ discard block |
||
1473 | 1473 | return ConvertHelper::detectEOLCharacter($string); |
1474 | 1474 | } |
1475 | 1475 | |
1476 | - /** |
|
1477 | - * Reads the specified amount of lines from the target file. |
|
1478 | - * Unicode BOM compatible: any byte order marker is stripped |
|
1479 | - * from the resulting lines. |
|
1480 | - * |
|
1481 | - * @param string $filePath |
|
1482 | - * @param int $amount Set to 0 to read all lines. |
|
1483 | - * @return array |
|
1484 | - * |
|
1485 | - * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
1486 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1487 | - */ |
|
1476 | + /** |
|
1477 | + * Reads the specified amount of lines from the target file. |
|
1478 | + * Unicode BOM compatible: any byte order marker is stripped |
|
1479 | + * from the resulting lines. |
|
1480 | + * |
|
1481 | + * @param string $filePath |
|
1482 | + * @param int $amount Set to 0 to read all lines. |
|
1483 | + * @return array |
|
1484 | + * |
|
1485 | + * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
|
1486 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1487 | + */ |
|
1488 | 1488 | public static function readLines(string $filePath, int $amount=0) : array |
1489 | 1489 | { |
1490 | 1490 | self::requireFileExists($filePath); |
@@ -1537,16 +1537,16 @@ discard block |
||
1537 | 1537 | return $result; |
1538 | 1538 | } |
1539 | 1539 | |
1540 | - /** |
|
1541 | - * Reads all content from a file. |
|
1542 | - * |
|
1543 | - * @param string $filePath |
|
1544 | - * @throws FileHelper_Exception |
|
1545 | - * @return string |
|
1546 | - * |
|
1547 | - * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1548 | - * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
1549 | - */ |
|
1540 | + /** |
|
1541 | + * Reads all content from a file. |
|
1542 | + * |
|
1543 | + * @param string $filePath |
|
1544 | + * @throws FileHelper_Exception |
|
1545 | + * @return string |
|
1546 | + * |
|
1547 | + * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
|
1548 | + * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
|
1549 | + */ |
|
1550 | 1550 | public static function readContents(string $filePath) : string |
1551 | 1551 | { |
1552 | 1552 | self::requireFileExists($filePath); |
@@ -1567,18 +1567,18 @@ discard block |
||
1567 | 1567 | ); |
1568 | 1568 | } |
1569 | 1569 | |
1570 | - /** |
|
1571 | - * Ensures that the target path exists on disk, and is a folder. |
|
1572 | - * |
|
1573 | - * @param string $path |
|
1574 | - * @return string The real path, with normalized slashes. |
|
1575 | - * @throws FileHelper_Exception |
|
1576 | - * |
|
1577 | - * @see FileHelper::normalizePath() |
|
1578 | - * |
|
1579 | - * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
1580 | - * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
1581 | - */ |
|
1570 | + /** |
|
1571 | + * Ensures that the target path exists on disk, and is a folder. |
|
1572 | + * |
|
1573 | + * @param string $path |
|
1574 | + * @return string The real path, with normalized slashes. |
|
1575 | + * @throws FileHelper_Exception |
|
1576 | + * |
|
1577 | + * @see FileHelper::normalizePath() |
|
1578 | + * |
|
1579 | + * @see FileHelper::ERROR_FOLDER_DOES_NOT_EXIST |
|
1580 | + * @see FileHelper::ERROR_PATH_IS_NOT_A_FOLDER |
|
1581 | + */ |
|
1582 | 1582 | public static function requireFolderExists(string $path) : string |
1583 | 1583 | { |
1584 | 1584 | $actual = realpath($path); |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | |
85 | 85 | $contents = file_get_contents($file); |
86 | 86 | |
87 | - if($contents === false) |
|
87 | + if ($contents === false) |
|
88 | 88 | { |
89 | 89 | throw new FileHelper_Exception( |
90 | 90 | 'Cannot load serialized content from file.', |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | $result = @unserialize($contents); |
100 | 100 | |
101 | - if($result !== false) { |
|
101 | + if ($result !== false) { |
|
102 | 102 | return $result; |
103 | 103 | } |
104 | 104 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | |
115 | 115 | public static function deleteTree($rootFolder) |
116 | 116 | { |
117 | - if(!file_exists($rootFolder)) { |
|
117 | + if (!file_exists($rootFolder)) { |
|
118 | 118 | return true; |
119 | 119 | } |
120 | 120 | |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | public static function createFolder($path) |
157 | 157 | { |
158 | - if(is_dir($path) || mkdir($path, 0777, true)) { |
|
158 | + if (is_dir($path) || mkdir($path, 0777, true)) { |
|
159 | 159 | return; |
160 | 160 | } |
161 | 161 | |
@@ -190,11 +190,11 @@ discard block |
||
190 | 190 | |
191 | 191 | if ($item->isDir()) |
192 | 192 | { |
193 | - FileHelper::copyTree($itemPath, $target . '/' . $baseName); |
|
193 | + FileHelper::copyTree($itemPath, $target.'/'.$baseName); |
|
194 | 194 | } |
195 | - else if($item->isFile()) |
|
195 | + else if ($item->isFile()) |
|
196 | 196 | { |
197 | - self::copyFile($itemPath, $target . '/' . $baseName); |
|
197 | + self::copyFile($itemPath, $target.'/'.$baseName); |
|
198 | 198 | } |
199 | 199 | } |
200 | 200 | } |
@@ -222,11 +222,11 @@ discard block |
||
222 | 222 | |
223 | 223 | $targetFolder = dirname($targetPath); |
224 | 224 | |
225 | - if(!file_exists($targetFolder)) |
|
225 | + if (!file_exists($targetFolder)) |
|
226 | 226 | { |
227 | 227 | self::createFolder($targetFolder); |
228 | 228 | } |
229 | - else if(!is_writable($targetFolder)) |
|
229 | + else if (!is_writable($targetFolder)) |
|
230 | 230 | { |
231 | 231 | throw new FileHelper_Exception( |
232 | 232 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | ); |
239 | 239 | } |
240 | 240 | |
241 | - if(copy($sourcePath, $targetPath)) { |
|
241 | + if (copy($sourcePath, $targetPath)) { |
|
242 | 242 | return; |
243 | 243 | } |
244 | 244 | |
@@ -265,11 +265,11 @@ discard block |
||
265 | 265 | */ |
266 | 266 | public static function deleteFile(string $filePath) : void |
267 | 267 | { |
268 | - if(!file_exists($filePath)) { |
|
268 | + if (!file_exists($filePath)) { |
|
269 | 269 | return; |
270 | 270 | } |
271 | 271 | |
272 | - if(unlink($filePath)) { |
|
272 | + if (unlink($filePath)) { |
|
273 | 273 | return; |
274 | 274 | } |
275 | 275 | |
@@ -293,10 +293,10 @@ discard block |
||
293 | 293 | * @return Csv |
294 | 294 | * @see CSVHelper::createParser() |
295 | 295 | */ |
296 | - public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : Csv |
|
296 | + public static function createCSVParser(string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : Csv |
|
297 | 297 | { |
298 | - if($delimiter==='') { $delimiter = ';'; } |
|
299 | - if($enclosure==='') { $enclosure = '"'; } |
|
298 | + if ($delimiter === '') { $delimiter = ';'; } |
|
299 | + if ($enclosure === '') { $enclosure = '"'; } |
|
300 | 300 | |
301 | 301 | $parser = CSVHelper::createParser($delimiter); |
302 | 302 | $parser->enclosure = $enclosure; |
@@ -320,11 +320,11 @@ discard block |
||
320 | 320 | * @see parseCSVFile() |
321 | 321 | * @see FileHelper::ERROR_PARSING_CSV |
322 | 322 | */ |
323 | - public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
323 | + public static function parseCSVString(string $csv, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
324 | 324 | { |
325 | 325 | $parser = self::createCSVParser($delimiter, $enclosure, '\\', $heading); |
326 | 326 | |
327 | - if($parser->parse($csv)) |
|
327 | + if ($parser->parse($csv)) |
|
328 | 328 | { |
329 | 329 | return $parser->data; |
330 | 330 | } |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
353 | 353 | * @see FileHelper::ERROR_CANNOT_READ_FILE_CONTENTS |
354 | 354 | */ |
355 | - public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading=false) : array |
|
355 | + public static function parseCSVFile(string $filePath, string $delimiter = ';', string $enclosure = '"', string $escape = '\\', bool $heading = false) : array |
|
356 | 356 | { |
357 | 357 | $content = self::readContents($filePath); |
358 | 358 | |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | public static function detectMimeType(string $fileName) : ?string |
370 | 370 | { |
371 | 371 | $ext = self::getExtension($fileName); |
372 | - if(empty($ext)) { |
|
372 | + if (empty($ext)) { |
|
373 | 373 | return null; |
374 | 374 | } |
375 | 375 | |
@@ -390,11 +390,11 @@ discard block |
||
390 | 390 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
391 | 391 | * @see FileHelper::ERROR_UNKNOWN_FILE_MIME_TYPE |
392 | 392 | */ |
393 | - public static function sendFile(string $filePath, $fileName = null, bool $asAttachment=true) |
|
393 | + public static function sendFile(string $filePath, $fileName = null, bool $asAttachment = true) |
|
394 | 394 | { |
395 | 395 | self::requireFileExists($filePath); |
396 | 396 | |
397 | - if(empty($fileName)) { |
|
397 | + if (empty($fileName)) { |
|
398 | 398 | $fileName = basename($filePath); |
399 | 399 | } |
400 | 400 | |
@@ -412,10 +412,10 @@ discard block |
||
412 | 412 | |
413 | 413 | header("Cache-Control: public", true); |
414 | 414 | header("Content-Description: File Transfer", true); |
415 | - header("Content-Type: " . $mime, true); |
|
415 | + header("Content-Type: ".$mime, true); |
|
416 | 416 | |
417 | 417 | $disposition = 'inline'; |
418 | - if($asAttachment) { |
|
418 | + if ($asAttachment) { |
|
419 | 419 | $disposition = 'attachment'; |
420 | 420 | } |
421 | 421 | |
@@ -443,7 +443,7 @@ discard block |
||
443 | 443 | requireCURL(); |
444 | 444 | |
445 | 445 | $ch = curl_init(); |
446 | - if(!is_resource($ch)) |
|
446 | + if (!is_resource($ch)) |
|
447 | 447 | { |
448 | 448 | throw new FileHelper_Exception( |
449 | 449 | 'Could not initialize a new cURL instance.', |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | |
465 | 465 | $output = curl_exec($ch); |
466 | 466 | |
467 | - if($output === false) { |
|
467 | + if ($output === false) { |
|
468 | 468 | throw new FileHelper_Exception( |
469 | 469 | 'Unable to open URL', |
470 | 470 | sprintf( |
@@ -478,7 +478,7 @@ discard block |
||
478 | 478 | |
479 | 479 | curl_close($ch); |
480 | 480 | |
481 | - if(is_string($output)) |
|
481 | + if (is_string($output)) |
|
482 | 482 | { |
483 | 483 | return $output; |
484 | 484 | } |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | */ |
501 | 501 | public static function isPHPFile($pathOrDirIterator) |
502 | 502 | { |
503 | - if(self::getExtension($pathOrDirIterator) == 'php') { |
|
503 | + if (self::getExtension($pathOrDirIterator) == 'php') { |
|
504 | 504 | return true; |
505 | 505 | } |
506 | 506 | |
@@ -517,14 +517,14 @@ discard block |
||
517 | 517 | */ |
518 | 518 | public static function getExtension($pathOrDirIterator, bool $lowercase = true) : string |
519 | 519 | { |
520 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
520 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
521 | 521 | $filename = $pathOrDirIterator->getFilename(); |
522 | 522 | } else { |
523 | 523 | $filename = basename($pathOrDirIterator); |
524 | 524 | } |
525 | 525 | |
526 | 526 | $ext = pathinfo($filename, PATHINFO_EXTENSION); |
527 | - if($lowercase) { |
|
527 | + if ($lowercase) { |
|
528 | 528 | $ext = mb_strtolower($ext); |
529 | 529 | } |
530 | 530 | |
@@ -546,13 +546,13 @@ discard block |
||
546 | 546 | public static function getFilename($pathOrDirIterator, $extension = true) |
547 | 547 | { |
548 | 548 | $path = $pathOrDirIterator; |
549 | - if($pathOrDirIterator instanceof \DirectoryIterator) { |
|
549 | + if ($pathOrDirIterator instanceof \DirectoryIterator) { |
|
550 | 550 | $path = $pathOrDirIterator->getFilename(); |
551 | 551 | } |
552 | 552 | |
553 | 553 | $path = self::normalizePath($path); |
554 | 554 | |
555 | - if(!$extension) { |
|
555 | + if (!$extension) { |
|
556 | 556 | return pathinfo($path, PATHINFO_FILENAME); |
557 | 557 | } |
558 | 558 | |
@@ -570,12 +570,12 @@ discard block |
||
570 | 570 | * @see FileHelper::ERROR_CANNOT_FIND_JSON_FILE |
571 | 571 | * @see FileHelper::ERROR_CANNOT_DECODE_JSON_FILE |
572 | 572 | */ |
573 | - public static function parseJSONFile(string $file, $targetEncoding=null, $sourceEncoding=null) |
|
573 | + public static function parseJSONFile(string $file, $targetEncoding = null, $sourceEncoding = null) |
|
574 | 574 | { |
575 | 575 | self::requireFileExists($file, self::ERROR_CANNOT_FIND_JSON_FILE); |
576 | 576 | |
577 | 577 | $content = file_get_contents($file); |
578 | - if(!$content) { |
|
578 | + if (!$content) { |
|
579 | 579 | throw new FileHelper_Exception( |
580 | 580 | 'Cannot get file contents', |
581 | 581 | sprintf( |
@@ -586,12 +586,12 @@ discard block |
||
586 | 586 | ); |
587 | 587 | } |
588 | 588 | |
589 | - if(isset($targetEncoding)) { |
|
589 | + if (isset($targetEncoding)) { |
|
590 | 590 | $content = mb_convert_encoding($content, $targetEncoding, $sourceEncoding); |
591 | 591 | } |
592 | 592 | |
593 | 593 | $json = json_decode($content, true); |
594 | - if($json === false || $json === NULL) { |
|
594 | + if ($json === false || $json === NULL) { |
|
595 | 595 | throw new FileHelper_Exception( |
596 | 596 | 'Cannot decode json data', |
597 | 597 | sprintf( |
@@ -631,13 +631,13 @@ discard block |
||
631 | 631 | |
632 | 632 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
633 | 633 | |
634 | - while(strstr($name, ' ')) { |
|
634 | + while (strstr($name, ' ')) { |
|
635 | 635 | $name = str_replace(' ', ' ', $name); |
636 | 636 | } |
637 | 637 | |
638 | 638 | $name = str_replace(array_keys($replaces), array_values($replaces), $name); |
639 | 639 | |
640 | - while(strstr($name, '..')) { |
|
640 | + while (strstr($name, '..')) { |
|
641 | 641 | $name = str_replace('..', '.', $name); |
642 | 642 | } |
643 | 643 | |
@@ -669,7 +669,7 @@ discard block |
||
669 | 669 | * @return array An indexed array with files. |
670 | 670 | * @see FileHelper::createFileFinder() |
671 | 671 | */ |
672 | - public static function findHTMLFiles(string $targetFolder, array $options=array()) : array |
|
672 | + public static function findHTMLFiles(string $targetFolder, array $options = array()) : array |
|
673 | 673 | { |
674 | 674 | return self::findFiles($targetFolder, array('html'), $options); |
675 | 675 | } |
@@ -686,7 +686,7 @@ discard block |
||
686 | 686 | * @return array An indexed array of PHP files. |
687 | 687 | * @see FileHelper::createFileFinder() |
688 | 688 | */ |
689 | - public static function findPHPFiles(string $targetFolder, array $options=array()) : array |
|
689 | + public static function findPHPFiles(string $targetFolder, array $options = array()) : array |
|
690 | 690 | { |
691 | 691 | return self::findFiles($targetFolder, array('php'), $options); |
692 | 692 | } |
@@ -706,22 +706,22 @@ discard block |
||
706 | 706 | * @return array |
707 | 707 | * @see FileHelper::createFileFinder() |
708 | 708 | */ |
709 | - public static function findFiles(string $targetFolder, array $extensions=array(), array $options=array(), array $files=array()) : array |
|
709 | + public static function findFiles(string $targetFolder, array $extensions = array(), array $options = array(), array $files = array()) : array |
|
710 | 710 | { |
711 | 711 | $finder = self::createFileFinder($targetFolder); |
712 | 712 | |
713 | 713 | $finder->setPathmodeStrip(); |
714 | 714 | |
715 | - if(isset($options['relative-path']) && $options['relative-path'] === true) |
|
715 | + if (isset($options['relative-path']) && $options['relative-path'] === true) |
|
716 | 716 | { |
717 | 717 | $finder->setPathmodeRelative(); |
718 | 718 | } |
719 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
719 | + else if (isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
720 | 720 | { |
721 | 721 | $finder->setPathmodeAbsolute(); |
722 | 722 | } |
723 | 723 | |
724 | - if(isset($options['strip-extension'])) |
|
724 | + if (isset($options['strip-extension'])) |
|
725 | 725 | { |
726 | 726 | $finder->stripExtensions(); |
727 | 727 | } |
@@ -739,12 +739,12 @@ discard block |
||
739 | 739 | * @param bool $keepPath Whether to keep the path component, if any. Default PHP pathinfo behavior is not to. |
740 | 740 | * @return string |
741 | 741 | */ |
742 | - public static function removeExtension(string $filename, bool $keepPath=false) : string |
|
742 | + public static function removeExtension(string $filename, bool $keepPath = false) : string |
|
743 | 743 | { |
744 | 744 | // normalize paths to allow windows style slashes even on nix servers |
745 | 745 | $filename = self::normalizePath($filename); |
746 | 746 | |
747 | - if(!$keepPath) |
|
747 | + if (!$keepPath) |
|
748 | 748 | { |
749 | 749 | return pathinfo($filename, PATHINFO_FILENAME); |
750 | 750 | } |
@@ -777,7 +777,7 @@ discard block |
||
777 | 777 | public static function detectUTFBom(string $filename) : ?string |
778 | 778 | { |
779 | 779 | $fp = fopen($filename, 'r'); |
780 | - if($fp === false) |
|
780 | + if ($fp === false) |
|
781 | 781 | { |
782 | 782 | throw new FileHelper_Exception( |
783 | 783 | 'Cannot open file for reading', |
@@ -792,10 +792,10 @@ discard block |
||
792 | 792 | |
793 | 793 | $boms = self::getUTFBOMs(); |
794 | 794 | |
795 | - foreach($boms as $bom => $value) |
|
795 | + foreach ($boms as $bom => $value) |
|
796 | 796 | { |
797 | 797 | $length = mb_strlen($value); |
798 | - if(mb_substr($text, 0, $length) == $value) { |
|
798 | + if (mb_substr($text, 0, $length) == $value) { |
|
799 | 799 | return $bom; |
800 | 800 | } |
801 | 801 | } |
@@ -814,13 +814,13 @@ discard block |
||
814 | 814 | */ |
815 | 815 | public static function getUTFBOMs() |
816 | 816 | { |
817 | - if(!isset(self::$utfBoms)) { |
|
817 | + if (!isset(self::$utfBoms)) { |
|
818 | 818 | self::$utfBoms = array( |
819 | - 'UTF32-BE' => chr(0x00) . chr(0x00) . chr(0xFE) . chr(0xFF), |
|
820 | - 'UTF32-LE' => chr(0xFF) . chr(0xFE) . chr(0x00) . chr(0x00), |
|
821 | - 'UTF16-BE' => chr(0xFE) . chr(0xFF), |
|
822 | - 'UTF16-LE' => chr(0xFF) . chr(0xFE), |
|
823 | - 'UTF8' => chr(0xEF) . chr(0xBB) . chr(0xBF) |
|
819 | + 'UTF32-BE' => chr(0x00).chr(0x00).chr(0xFE).chr(0xFF), |
|
820 | + 'UTF32-LE' => chr(0xFF).chr(0xFE).chr(0x00).chr(0x00), |
|
821 | + 'UTF16-BE' => chr(0xFE).chr(0xFF), |
|
822 | + 'UTF16-LE' => chr(0xFF).chr(0xFE), |
|
823 | + 'UTF8' => chr(0xEF).chr(0xBB).chr(0xBF) |
|
824 | 824 | ); |
825 | 825 | } |
826 | 826 | |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | $encodings = self::getKnownUnicodeEncodings(); |
842 | 842 | |
843 | 843 | $keep = array(); |
844 | - foreach($encodings as $string) |
|
844 | + foreach ($encodings as $string) |
|
845 | 845 | { |
846 | 846 | $withHyphen = str_replace('UTF', 'UTF-', $string); |
847 | 847 | |
@@ -888,16 +888,16 @@ discard block |
||
888 | 888 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
889 | 889 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
890 | 890 | */ |
891 | - public static function saveAsJSON($data, string $file, bool $pretty=false) |
|
891 | + public static function saveAsJSON($data, string $file, bool $pretty = false) |
|
892 | 892 | { |
893 | 893 | $options = null; |
894 | - if($pretty) { |
|
894 | + if ($pretty) { |
|
895 | 895 | $options = JSON_PRETTY_PRINT; |
896 | 896 | } |
897 | 897 | |
898 | 898 | $json = json_encode($data, $options); |
899 | 899 | |
900 | - if($json===false) |
|
900 | + if ($json === false) |
|
901 | 901 | { |
902 | 902 | $errorCode = json_last_error(); |
903 | 903 | |
@@ -923,14 +923,14 @@ discard block |
||
923 | 923 | * @see FileHelper::ERROR_SAVE_FILE_NOT_WRITABLE |
924 | 924 | * @see FileHelper::ERROR_SAVE_FILE_WRITE_FAILED |
925 | 925 | */ |
926 | - public static function saveFile(string $filePath, string $content='') : void |
|
926 | + public static function saveFile(string $filePath, string $content = '') : void |
|
927 | 927 | { |
928 | 928 | $filePath = self::normalizePath($filePath); |
929 | 929 | |
930 | 930 | // target file already exists |
931 | - if(file_exists($filePath)) |
|
931 | + if (file_exists($filePath)) |
|
932 | 932 | { |
933 | - if(!is_writable($filePath)) |
|
933 | + if (!is_writable($filePath)) |
|
934 | 934 | { |
935 | 935 | throw new FileHelper_Exception( |
936 | 936 | sprintf('Cannot save file: target file [%s] exists, but is not writable.', basename($filePath)), |
@@ -950,7 +950,7 @@ discard block |
||
950 | 950 | // create the folder as needed |
951 | 951 | self::createFolder($targetFolder); |
952 | 952 | |
953 | - if(!is_writable($targetFolder)) |
|
953 | + if (!is_writable($targetFolder)) |
|
954 | 954 | { |
955 | 955 | throw new FileHelper_Exception( |
956 | 956 | sprintf('Cannot save file: target folder [%s] is not writable.', basename($targetFolder)), |
@@ -963,7 +963,7 @@ discard block |
||
963 | 963 | } |
964 | 964 | } |
965 | 965 | |
966 | - if(is_dir($filePath)) |
|
966 | + if (is_dir($filePath)) |
|
967 | 967 | { |
968 | 968 | throw new FileHelper_Exception( |
969 | 969 | sprintf('Cannot save file: the target [%s] is a directory.', basename($filePath)), |
@@ -975,7 +975,7 @@ discard block |
||
975 | 975 | ); |
976 | 976 | } |
977 | 977 | |
978 | - if(file_put_contents($filePath, $content) !== false) { |
|
978 | + if (file_put_contents($filePath, $content) !== false) { |
|
979 | 979 | return; |
980 | 980 | } |
981 | 981 | |
@@ -1013,7 +1013,7 @@ discard block |
||
1013 | 1013 | { |
1014 | 1014 | static $checked = array(); |
1015 | 1015 | |
1016 | - if(isset($checked[$command])) { |
|
1016 | + if (isset($checked[$command])) { |
|
1017 | 1017 | return $checked[$command]; |
1018 | 1018 | } |
1019 | 1019 | |
@@ -1026,7 +1026,7 @@ discard block |
||
1026 | 1026 | |
1027 | 1027 | $os = strtolower(PHP_OS_FAMILY); |
1028 | 1028 | |
1029 | - if(!isset($osCommands[$os])) |
|
1029 | + if (!isset($osCommands[$os])) |
|
1030 | 1030 | { |
1031 | 1031 | throw new FileHelper_Exception( |
1032 | 1032 | 'Unsupported OS for CLI commands', |
@@ -1052,7 +1052,7 @@ discard block |
||
1052 | 1052 | $pipes |
1053 | 1053 | ); |
1054 | 1054 | |
1055 | - if($process === false) { |
|
1055 | + if ($process === false) { |
|
1056 | 1056 | $checked[$command] = false; |
1057 | 1057 | return false; |
1058 | 1058 | } |
@@ -1083,7 +1083,7 @@ discard block |
||
1083 | 1083 | */ |
1084 | 1084 | public static function checkPHPFileSyntax($path) |
1085 | 1085 | { |
1086 | - if(!self::canMakePHPCalls()) { |
|
1086 | + if (!self::canMakePHPCalls()) { |
|
1087 | 1087 | return true; |
1088 | 1088 | } |
1089 | 1089 | |
@@ -1094,7 +1094,7 @@ discard block |
||
1094 | 1094 | // when the validation is successful, the first entry |
1095 | 1095 | // in the array contains the success message. When it |
1096 | 1096 | // is invalid, the first entry is always empty. |
1097 | - if(!empty($output[0])) { |
|
1097 | + if (!empty($output[0])) { |
|
1098 | 1098 | return true; |
1099 | 1099 | } |
1100 | 1100 | |
@@ -1115,7 +1115,7 @@ discard block |
||
1115 | 1115 | public static function getModifiedDate($path) |
1116 | 1116 | { |
1117 | 1117 | $time = filemtime($path); |
1118 | - if($time !== false) { |
|
1118 | + if ($time !== false) { |
|
1119 | 1119 | $date = new \DateTime(); |
1120 | 1120 | $date->setTimestamp($time); |
1121 | 1121 | return $date; |
@@ -1144,7 +1144,7 @@ discard block |
||
1144 | 1144 | */ |
1145 | 1145 | public static function getSubfolders($targetFolder, $options = array()) |
1146 | 1146 | { |
1147 | - if(!is_dir($targetFolder)) |
|
1147 | + if (!is_dir($targetFolder)) |
|
1148 | 1148 | { |
1149 | 1149 | throw new FileHelper_Exception( |
1150 | 1150 | 'Target folder does not exist', |
@@ -1168,29 +1168,29 @@ discard block |
||
1168 | 1168 | |
1169 | 1169 | $d = new \DirectoryIterator($targetFolder); |
1170 | 1170 | |
1171 | - foreach($d as $item) |
|
1171 | + foreach ($d as $item) |
|
1172 | 1172 | { |
1173 | - if($item->isDir() && !$item->isDot()) |
|
1173 | + if ($item->isDir() && !$item->isDot()) |
|
1174 | 1174 | { |
1175 | 1175 | $name = $item->getFilename(); |
1176 | 1176 | |
1177 | - if(!$options['absolute-path']) { |
|
1177 | + if (!$options['absolute-path']) { |
|
1178 | 1178 | $result[] = $name; |
1179 | 1179 | } else { |
1180 | 1180 | $result[] = $targetFolder.'/'.$name; |
1181 | 1181 | } |
1182 | 1182 | |
1183 | - if(!$options['recursive']) |
|
1183 | + if (!$options['recursive']) |
|
1184 | 1184 | { |
1185 | 1185 | continue; |
1186 | 1186 | } |
1187 | 1187 | |
1188 | 1188 | $subs = self::getSubfolders($targetFolder.'/'.$name, $options); |
1189 | - foreach($subs as $sub) |
|
1189 | + foreach ($subs as $sub) |
|
1190 | 1190 | { |
1191 | 1191 | $relative = $name.'/'.$sub; |
1192 | 1192 | |
1193 | - if(!$options['absolute-path']) { |
|
1193 | + if (!$options['absolute-path']) { |
|
1194 | 1194 | $result[] = $relative; |
1195 | 1195 | } else { |
1196 | 1196 | $result[] = $targetFolder.'/'.$relative; |
@@ -1240,7 +1240,7 @@ discard block |
||
1240 | 1240 | $unit = preg_replace('/[^bkmgtpezy]/i', '', $size); // Remove the non-unit characters from the size. |
1241 | 1241 | $size = floatval(preg_replace('/[^0-9\.]/', '', $size)); // Remove the non-numeric characters from the size. |
1242 | 1242 | |
1243 | - if($unit) |
|
1243 | + if ($unit) |
|
1244 | 1244 | { |
1245 | 1245 | // Find the position of the unit in the ordered string which is the power of magnitude to multiply a kilobyte by. |
1246 | 1246 | return round($size * pow(1024, stripos('bkmgtpezy', $unit[0]))); |
@@ -1259,7 +1259,7 @@ discard block |
||
1259 | 1259 | * @param int $depth The folder depth to reduce the path to |
1260 | 1260 | * @return string |
1261 | 1261 | */ |
1262 | - public static function relativizePathByDepth(string $path, int $depth=2) : string |
|
1262 | + public static function relativizePathByDepth(string $path, int $depth = 2) : string |
|
1263 | 1263 | { |
1264 | 1264 | $path = self::normalizePath($path); |
1265 | 1265 | |
@@ -1267,17 +1267,17 @@ discard block |
||
1267 | 1267 | $tokens = array_filter($tokens); // remove empty entries (trailing slash for example) |
1268 | 1268 | $tokens = array_values($tokens); // re-index keys |
1269 | 1269 | |
1270 | - if(empty($tokens)) { |
|
1270 | + if (empty($tokens)) { |
|
1271 | 1271 | return ''; |
1272 | 1272 | } |
1273 | 1273 | |
1274 | 1274 | // remove the drive if present |
1275 | - if(strstr($tokens[0], ':')) { |
|
1275 | + if (strstr($tokens[0], ':')) { |
|
1276 | 1276 | array_shift($tokens); |
1277 | 1277 | } |
1278 | 1278 | |
1279 | 1279 | // path was only the drive |
1280 | - if(count($tokens) == 0) { |
|
1280 | + if (count($tokens) == 0) { |
|
1281 | 1281 | return ''; |
1282 | 1282 | } |
1283 | 1283 | |
@@ -1286,8 +1286,8 @@ discard block |
||
1286 | 1286 | |
1287 | 1287 | // reduce the path to the specified depth |
1288 | 1288 | $length = count($tokens); |
1289 | - if($length > $depth) { |
|
1290 | - $tokens = array_slice($tokens, $length-$depth); |
|
1289 | + if ($length > $depth) { |
|
1290 | + $tokens = array_slice($tokens, $length - $depth); |
|
1291 | 1291 | } |
1292 | 1292 | |
1293 | 1293 | // append the last element again |
@@ -1335,14 +1335,14 @@ discard block |
||
1335 | 1335 | * |
1336 | 1336 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1337 | 1337 | */ |
1338 | - public static function requireFileExists(string $path, ?int $errorCode=null) : string |
|
1338 | + public static function requireFileExists(string $path, ?int $errorCode = null) : string |
|
1339 | 1339 | { |
1340 | 1340 | $result = realpath($path); |
1341 | - if($result !== false) { |
|
1341 | + if ($result !== false) { |
|
1342 | 1342 | return $result; |
1343 | 1343 | } |
1344 | 1344 | |
1345 | - if($errorCode === null) { |
|
1345 | + if ($errorCode === null) { |
|
1346 | 1346 | $errorCode = self::ERROR_FILE_DOES_NOT_EXIST; |
1347 | 1347 | } |
1348 | 1348 | |
@@ -1353,15 +1353,15 @@ discard block |
||
1353 | 1353 | ); |
1354 | 1354 | } |
1355 | 1355 | |
1356 | - public static function requireFileReadable(string $path, ?int $errorCode=null) : string |
|
1356 | + public static function requireFileReadable(string $path, ?int $errorCode = null) : string |
|
1357 | 1357 | { |
1358 | 1358 | $path = self::requireFileExists($path, $errorCode); |
1359 | 1359 | |
1360 | - if(is_readable($path)) { |
|
1360 | + if (is_readable($path)) { |
|
1361 | 1361 | return $path; |
1362 | 1362 | } |
1363 | 1363 | |
1364 | - if($errorCode === null) { |
|
1364 | + if ($errorCode === null) { |
|
1365 | 1365 | $errorCode = self::ERROR_FILE_NOT_READABLE; |
1366 | 1366 | } |
1367 | 1367 | |
@@ -1390,15 +1390,15 @@ discard block |
||
1390 | 1390 | |
1391 | 1391 | $file = new \SplFileObject($path); |
1392 | 1392 | |
1393 | - if($file->eof()) { |
|
1393 | + if ($file->eof()) { |
|
1394 | 1394 | return ''; |
1395 | 1395 | } |
1396 | 1396 | |
1397 | - $targetLine = $lineNumber-1; |
|
1397 | + $targetLine = $lineNumber - 1; |
|
1398 | 1398 | |
1399 | 1399 | $file->seek($targetLine); |
1400 | 1400 | |
1401 | - if($file->key() !== $targetLine) { |
|
1401 | + if ($file->key() !== $targetLine) { |
|
1402 | 1402 | return null; |
1403 | 1403 | } |
1404 | 1404 | |
@@ -1424,7 +1424,7 @@ discard block |
||
1424 | 1424 | $number = $spl->key(); |
1425 | 1425 | |
1426 | 1426 | // if seeking to the end the cursor is still at 0, there are no lines. |
1427 | - if($number === 0) |
|
1427 | + if ($number === 0) |
|
1428 | 1428 | { |
1429 | 1429 | // since it's a very small file, to get reliable results, |
1430 | 1430 | // we read its contents and use that to determine what |
@@ -1432,13 +1432,13 @@ discard block |
||
1432 | 1432 | // that this is not pactical to solve with the SplFileObject. |
1433 | 1433 | $content = file_get_contents($path); |
1434 | 1434 | |
1435 | - if(empty($content)) { |
|
1435 | + if (empty($content)) { |
|
1436 | 1436 | return 0; |
1437 | 1437 | } |
1438 | 1438 | } |
1439 | 1439 | |
1440 | 1440 | // return the line number we were able to reach + 1 (key is zero-based) |
1441 | - return $number+1; |
|
1441 | + return $number + 1; |
|
1442 | 1442 | } |
1443 | 1443 | |
1444 | 1444 | /** |
@@ -1485,13 +1485,13 @@ discard block |
||
1485 | 1485 | * @see FileHelper::ERROR_CANNOT_OPEN_FILE_TO_READ_LINES |
1486 | 1486 | * @see FileHelper::ERROR_FILE_DOES_NOT_EXIST |
1487 | 1487 | */ |
1488 | - public static function readLines(string $filePath, int $amount=0) : array |
|
1488 | + public static function readLines(string $filePath, int $amount = 0) : array |
|
1489 | 1489 | { |
1490 | 1490 | self::requireFileExists($filePath); |
1491 | 1491 | |
1492 | 1492 | $fn = fopen($filePath, "r"); |
1493 | 1493 | |
1494 | - if($fn === false) |
|
1494 | + if ($fn === false) |
|
1495 | 1495 | { |
1496 | 1496 | throw new FileHelper_Exception( |
1497 | 1497 | 'Could not open file for reading.', |
@@ -1507,19 +1507,19 @@ discard block |
||
1507 | 1507 | $counter = 0; |
1508 | 1508 | $first = true; |
1509 | 1509 | |
1510 | - while(!feof($fn)) |
|
1510 | + while (!feof($fn)) |
|
1511 | 1511 | { |
1512 | 1512 | $counter++; |
1513 | 1513 | |
1514 | 1514 | $line = fgets($fn); |
1515 | 1515 | |
1516 | 1516 | // can happen with zero length files |
1517 | - if($line === false) { |
|
1517 | + if ($line === false) { |
|
1518 | 1518 | continue; |
1519 | 1519 | } |
1520 | 1520 | |
1521 | 1521 | // the first line may contain a unicode BOM marker. |
1522 | - if($first) |
|
1522 | + if ($first) |
|
1523 | 1523 | { |
1524 | 1524 | $line = ConvertHelper::stripUTFBom($line); |
1525 | 1525 | $first = false; |
@@ -1527,7 +1527,7 @@ discard block |
||
1527 | 1527 | |
1528 | 1528 | $result[] = $line; |
1529 | 1529 | |
1530 | - if($amount > 0 && $counter == $amount) { |
|
1530 | + if ($amount > 0 && $counter == $amount) { |
|
1531 | 1531 | break; |
1532 | 1532 | } |
1533 | 1533 | } |
@@ -1553,7 +1553,7 @@ discard block |
||
1553 | 1553 | |
1554 | 1554 | $result = file_get_contents($filePath); |
1555 | 1555 | |
1556 | - if($result !== false) { |
|
1556 | + if ($result !== false) { |
|
1557 | 1557 | return $result; |
1558 | 1558 | } |
1559 | 1559 | |
@@ -1583,7 +1583,7 @@ discard block |
||
1583 | 1583 | { |
1584 | 1584 | $actual = realpath($path); |
1585 | 1585 | |
1586 | - if($actual === false) |
|
1586 | + if ($actual === false) |
|
1587 | 1587 | { |
1588 | 1588 | throw new FileHelper_Exception( |
1589 | 1589 | 'Folder does not exist', |
@@ -1595,7 +1595,7 @@ discard block |
||
1595 | 1595 | ); |
1596 | 1596 | } |
1597 | 1597 | |
1598 | - if(is_dir($path)) |
|
1598 | + if (is_dir($path)) |
|
1599 | 1599 | { |
1600 | 1600 | return self::normalizePath($actual); |
1601 | 1601 | } |
@@ -191,8 +191,7 @@ discard block |
||
191 | 191 | if ($item->isDir()) |
192 | 192 | { |
193 | 193 | FileHelper::copyTree($itemPath, $target . '/' . $baseName); |
194 | - } |
|
195 | - else if($item->isFile()) |
|
194 | + } else if($item->isFile()) |
|
196 | 195 | { |
197 | 196 | self::copyFile($itemPath, $target . '/' . $baseName); |
198 | 197 | } |
@@ -225,8 +224,7 @@ discard block |
||
225 | 224 | if(!file_exists($targetFolder)) |
226 | 225 | { |
227 | 226 | self::createFolder($targetFolder); |
228 | - } |
|
229 | - else if(!is_writable($targetFolder)) |
|
227 | + } else if(!is_writable($targetFolder)) |
|
230 | 228 | { |
231 | 229 | throw new FileHelper_Exception( |
232 | 230 | sprintf('Target folder [%s] is not writable.', basename($targetFolder)), |
@@ -715,8 +713,7 @@ discard block |
||
715 | 713 | if(isset($options['relative-path']) && $options['relative-path'] === true) |
716 | 714 | { |
717 | 715 | $finder->setPathmodeRelative(); |
718 | - } |
|
719 | - else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
716 | + } else if(isset($options['absolute-path']) && $options['absolute-path'] === true) |
|
720 | 717 | { |
721 | 718 | $finder->setPathmodeAbsolute(); |
722 | 719 | } |
@@ -18,9 +18,9 @@ discard block |
||
18 | 18 | * @param bool $forceNew |
19 | 19 | * @return NumberInfo |
20 | 20 | */ |
21 | -function parseNumber($value, bool $forceNew=false) |
|
21 | +function parseNumber($value, bool $forceNew = false) |
|
22 | 22 | { |
23 | - if($value instanceof NumberInfo && $forceNew !== true) { |
|
23 | + if ($value instanceof NumberInfo && $forceNew !== true) { |
|
24 | 24 | return $value; |
25 | 25 | } |
26 | 26 | |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | $args = func_get_args(); |
102 | 102 | |
103 | 103 | // is the localization package installed? |
104 | - if(function_exists('\AppLocalize\t')) |
|
104 | + if (function_exists('\AppLocalize\t')) |
|
105 | 105 | { |
106 | 106 | return call_user_func_array('\AppLocalize\t', $args); |
107 | 107 | } |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | */ |
120 | 120 | function requireCURL() : void |
121 | 121 | { |
122 | - if(function_exists('curl_init')) { |
|
122 | + if (function_exists('curl_init')) { |
|
123 | 123 | return; |
124 | 124 | } |
125 | 125 | |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @param bool $initial The initial boolean value to use. |
137 | 137 | * @return Value_Bool |
138 | 138 | */ |
139 | -function valBool(bool $initial=false) : Value_Bool |
|
139 | +function valBool(bool $initial = false) : Value_Bool |
|
140 | 140 | { |
141 | 141 | return new Value_Bool($initial); |
142 | 142 | } |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | * @param bool $initial |
150 | 150 | * @return Value_Bool_True |
151 | 151 | */ |
152 | -function valBoolTrue(bool $initial=false) : Value_Bool_True |
|
152 | +function valBoolTrue(bool $initial = false) : Value_Bool_True |
|
153 | 153 | { |
154 | 154 | return new Value_Bool_True($initial); |
155 | 155 | } |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | * @param bool $initial |
163 | 163 | * @return Value_Bool_False |
164 | 164 | */ |
165 | -function valBoolFalse(bool $initial=true) : Value_Bool_False |
|
165 | +function valBoolFalse(bool $initial = true) : Value_Bool_False |
|
166 | 166 | { |
167 | 167 | return new Value_Bool_False($initial); |
168 | 168 | } |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | */ |
185 | 185 | function init() |
186 | 186 | { |
187 | - if(!class_exists('\AppLocalize\Localization')) { |
|
187 | + if (!class_exists('\AppLocalize\Localization')) { |
|
188 | 188 | return; |
189 | 189 | } |
190 | 190 |
@@ -15,7 +15,7 @@ |
||
15 | 15 | $autoload = $root.'/vendor/autoload.php'; |
16 | 16 | |
17 | 17 | // we need the autoloader to be present |
18 | - if($autoload === false) |
|
18 | + if ($autoload === false) |
|
19 | 19 | { |
20 | 20 | die('<b>ERROR:</b> Autoloader not present. Run composer update first.'); |
21 | 21 | } |