Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like Path often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use Path, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 30 | final class Path |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * The number of buffer entries that triggers a cleanup operation. |
||
| 34 | */ |
||
| 35 | const CLEANUP_THRESHOLD = 1250; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * The buffer size after the cleanup operation. |
||
| 39 | */ |
||
| 40 | const CLEANUP_SIZE = 1000; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Buffers input/output of {@link canonicalize()}. |
||
| 44 | * |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | private static $buffer = array(); |
||
| 48 | |||
| 49 | /** |
||
| 50 | * The size of the buffer. |
||
| 51 | * |
||
| 52 | * @var int |
||
| 53 | */ |
||
| 54 | private static $bufferSize = 0; |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Canonicalizes the given path. |
||
| 58 | * |
||
| 59 | * During normalization, all slashes are replaced by forward slashes ("/"). |
||
| 60 | * Furthermore, all "." and ".." segments are removed as far as possible. |
||
| 61 | * ".." segments at the beginning of relative paths are not removed. |
||
| 62 | * |
||
| 63 | * ```php |
||
| 64 | * echo Path::canonicalize("\webmozart\puli\..\css\style.css"); |
||
| 65 | * // => /webmozart/css/style.css |
||
| 66 | * |
||
| 67 | * echo Path::canonicalize("../css/./style.css"); |
||
| 68 | * // => ../css/style.css |
||
| 69 | * ``` |
||
| 70 | * |
||
| 71 | * This method is able to deal with both UNIX and Windows paths. |
||
| 72 | * |
||
| 73 | * @param string $path A path string. |
||
| 74 | * |
||
| 75 | * @return string The canonical path. |
||
| 76 | * |
||
| 77 | * @since 1.0 Added method. |
||
| 78 | * @since 2.0 Method now fails if $path is not a string. |
||
| 79 | * @since 2.1 Added support for `~`. |
||
| 80 | */ |
||
| 81 | 511 | public static function canonicalize($path) |
|
| 141 | |||
| 142 | /** |
||
| 143 | * Normalizes the given path. |
||
| 144 | * |
||
| 145 | * During normalization, all slashes are replaced by forward slashes ("/"). |
||
| 146 | * Contrary to {@link canonicalize()}, this method does not remove invalid |
||
| 147 | * or dot path segments. Consequently, it is much more efficient and should |
||
| 148 | * be used whenever the given path is known to be a valid, absolute system |
||
| 149 | * path. |
||
| 150 | * |
||
| 151 | * This method is able to deal with both UNIX and Windows paths. |
||
| 152 | * |
||
| 153 | * @param string $path A path string. |
||
| 154 | * |
||
| 155 | * @return string The normalized path. |
||
| 156 | * |
||
| 157 | * @since 2.2 Added method. |
||
| 158 | */ |
||
| 159 | 2 | public static function normalize($path) |
|
| 165 | |||
| 166 | /** |
||
| 167 | * Returns the directory part of the path. |
||
| 168 | * |
||
| 169 | * This method is similar to PHP's dirname(), but handles various cases |
||
| 170 | * where dirname() returns a weird result: |
||
| 171 | * |
||
| 172 | * - dirname() does not accept backslashes on UNIX |
||
| 173 | * - dirname("C:/webmozart") returns "C:", not "C:/" |
||
| 174 | * - dirname("C:/") returns ".", not "C:/" |
||
| 175 | * - dirname("C:") returns ".", not "C:/" |
||
| 176 | * - dirname("webmozart") returns ".", not "" |
||
| 177 | * - dirname() does not canonicalize the result |
||
| 178 | * |
||
| 179 | * This method fixes these shortcomings and behaves like dirname() |
||
| 180 | * otherwise. |
||
| 181 | * |
||
| 182 | * The result is a canonical path. |
||
| 183 | * |
||
| 184 | * @param string $path A path string. |
||
| 185 | * |
||
| 186 | * @return string The canonical directory part. Returns the root directory |
||
| 187 | * if the root directory is passed. Returns an empty string |
||
| 188 | * if a relative path is passed that contains no slashes. |
||
| 189 | * Returns an empty string if an empty string is passed. |
||
| 190 | * |
||
| 191 | * @since 1.0 Added method. |
||
| 192 | * @since 2.0 Method now fails if $path is not a string. |
||
| 193 | */ |
||
| 194 | 41 | public static function getDirectory($path) |
|
| 226 | |||
| 227 | /** |
||
| 228 | * Returns canonical path of the user's home directory. |
||
| 229 | * |
||
| 230 | * Supported operating systems: |
||
| 231 | * |
||
| 232 | * - UNIX |
||
| 233 | * - Windows8 and upper |
||
| 234 | * |
||
| 235 | * If your operation system or environment isn't supported, an exception is thrown. |
||
| 236 | * |
||
| 237 | * The result is a canonical path. |
||
| 238 | * |
||
| 239 | * @return string The canonical home directory |
||
| 240 | * |
||
| 241 | * @throws RuntimeException If your operation system or environment isn't supported |
||
| 242 | * |
||
| 243 | * @since 2.1 Added method. |
||
| 244 | */ |
||
| 245 | 13 | public static function getHomeDirectory() |
|
| 259 | |||
| 260 | /** |
||
| 261 | * Returns the root directory of a path. |
||
| 262 | * |
||
| 263 | * The result is a canonical path. |
||
| 264 | * |
||
| 265 | * @param string $path A path string. |
||
| 266 | * |
||
| 267 | * @return string The canonical root directory. Returns an empty string if |
||
| 268 | * the given path is relative or empty. |
||
| 269 | * |
||
| 270 | * @since 1.0 Added method. |
||
| 271 | * @since 2.0 Method now fails if $path is not a string. |
||
| 272 | */ |
||
| 273 | 18 | public static function getRoot($path) |
|
| 311 | |||
| 312 | /** |
||
| 313 | * Returns the file name from a file path. |
||
| 314 | * |
||
| 315 | * @param string $path The path string. |
||
| 316 | * |
||
| 317 | * @return string The file name. |
||
| 318 | * |
||
| 319 | * @since 1.1 Added method. |
||
| 320 | * @since 2.0 Method now fails if $path is not a string. |
||
| 321 | */ |
||
| 322 | 8 | public static function getFilename($path) |
|
| 332 | |||
| 333 | /** |
||
| 334 | * Returns the file name without the extension from a file path. |
||
| 335 | * |
||
| 336 | * @param string $path The path string. |
||
| 337 | * @param string|null $extension If specified, only that extension is cut |
||
| 338 | * off (may contain leading dot). |
||
| 339 | * |
||
| 340 | * @return string The file name without extension. |
||
| 341 | * |
||
| 342 | * @since 1.1 Added method. |
||
| 343 | * @since 2.0 Method now fails if $path or $extension have invalid types. |
||
| 344 | */ |
||
| 345 | 20 | public static function getFilenameWithoutExtension($path, $extension = null) |
|
| 361 | |||
| 362 | /** |
||
| 363 | * Returns the extension from a file path. |
||
| 364 | * |
||
| 365 | * @param string $path The path string. |
||
| 366 | * @param bool $forceLowerCase Forces the extension to be lower-case |
||
| 367 | * (requires mbstring extension for correct |
||
| 368 | * multi-byte character handling in extension). |
||
| 369 | * |
||
| 370 | * @return string The extension of the file path (without leading dot). |
||
| 371 | * |
||
| 372 | * @since 1.1 Added method. |
||
| 373 | * @since 2.0 Method now fails if $path is not a string. |
||
| 374 | */ |
||
| 375 | 51 | public static function getExtension($path, $forceLowerCase = false) |
|
| 391 | |||
| 392 | /** |
||
| 393 | * Returns whether the path has an extension. |
||
| 394 | * |
||
| 395 | * @param string $path The path string. |
||
| 396 | * @param string|array|null $extensions If null or not provided, checks if |
||
| 397 | * an extension exists, otherwise |
||
| 398 | * checks for the specified extension |
||
| 399 | * or array of extensions (with or |
||
| 400 | * without leading dot). |
||
| 401 | * @param bool $ignoreCase Whether to ignore case-sensitivity |
||
| 402 | * (requires mbstring extension for |
||
| 403 | * correct multi-byte character |
||
| 404 | * handling in the extension). |
||
| 405 | * |
||
| 406 | * @return bool Returns `true` if the path has an (or the specified) |
||
| 407 | * extension and `false` otherwise. |
||
| 408 | * |
||
| 409 | * @since 1.1 Added method. |
||
| 410 | * @since 2.0 Method now fails if $path or $extensions have invalid types. |
||
| 411 | */ |
||
| 412 | 30 | public static function hasExtension($path, $extensions = null, $ignoreCase = false) |
|
| 440 | |||
| 441 | /** |
||
| 442 | * Changes the extension of a path string. |
||
| 443 | * |
||
| 444 | * @param string $path The path string with filename.ext to change. |
||
| 445 | * @param string $extension New extension (with or without leading dot). |
||
| 446 | * |
||
| 447 | * @return string The path string with new file extension. |
||
| 448 | * |
||
| 449 | * @since 1.1 Added method. |
||
| 450 | * @since 2.0 Method now fails if $path or $extension is not a string. |
||
| 451 | */ |
||
| 452 | 14 | public static function changeExtension($path, $extension) |
|
| 475 | |||
| 476 | /** |
||
| 477 | * Returns whether a path is absolute. |
||
| 478 | * |
||
| 479 | * @param string $path A path string. |
||
| 480 | * |
||
| 481 | * @return bool Returns true if the path is absolute, false if it is |
||
| 482 | * relative or empty. |
||
| 483 | * |
||
| 484 | * @since 1.0 Added method. |
||
| 485 | * @since 2.0 Method now fails if $path is not a string. |
||
| 486 | */ |
||
| 487 | 111 | public static function isAbsolute($path) |
|
| 520 | |||
| 521 | /** |
||
| 522 | * Returns whether a path is relative. |
||
| 523 | * |
||
| 524 | * @param string $path A path string. |
||
| 525 | * |
||
| 526 | * @return bool Returns true if the path is relative or empty, false if |
||
| 527 | * it is absolute. |
||
| 528 | * |
||
| 529 | * @since 1.0 Added method. |
||
| 530 | * @since 2.0 Method now fails if $path is not a string. |
||
| 531 | */ |
||
| 532 | 16 | public static function isRelative($path) |
|
| 536 | |||
| 537 | /** |
||
| 538 | * Turns a relative path into an absolute path. |
||
| 539 | * |
||
| 540 | * Usually, the relative path is appended to the given base path. Dot |
||
| 541 | * segments ("." and "..") are removed/collapsed and all slashes turned |
||
| 542 | * into forward slashes. |
||
| 543 | * |
||
| 544 | * ```php |
||
| 545 | * echo Path::makeAbsolute("../style.css", "/webmozart/puli/css"); |
||
| 546 | * // => /webmozart/puli/style.css |
||
| 547 | * ``` |
||
| 548 | * |
||
| 549 | * If an absolute path is passed, that path is returned unless its root |
||
| 550 | * directory is different than the one of the base path. In that case, an |
||
| 551 | * exception is thrown. |
||
| 552 | * |
||
| 553 | * ```php |
||
| 554 | * Path::makeAbsolute("/style.css", "/webmozart/puli/css"); |
||
| 555 | * // => /style.css |
||
| 556 | * |
||
| 557 | * Path::makeAbsolute("C:/style.css", "C:/webmozart/puli/css"); |
||
| 558 | * // => C:/style.css |
||
| 559 | * |
||
| 560 | * Path::makeAbsolute("C:/style.css", "/webmozart/puli/css"); |
||
| 561 | * // InvalidArgumentException |
||
| 562 | * ``` |
||
| 563 | * |
||
| 564 | * If the base path is not an absolute path, an exception is thrown. |
||
| 565 | * |
||
| 566 | * The result is a canonical path. |
||
| 567 | * |
||
| 568 | * @param string $path A path to make absolute. |
||
| 569 | * @param string $basePath An absolute base path. |
||
| 570 | * |
||
| 571 | * @return string An absolute path in canonical form. |
||
| 572 | * |
||
| 573 | * @throws InvalidArgumentException If the base path is not absolute or if |
||
| 574 | * the given path is an absolute path with |
||
| 575 | * a different root than the base path. |
||
| 576 | * |
||
| 577 | * @since 1.0 Added method. |
||
| 578 | * @since 2.0 Method now fails if $path or $basePath is not a string. |
||
| 579 | * @since 2.2.2 Method does not fail anymore of $path and $basePath are |
||
| 580 | * absolute, but on different partitions. |
||
| 581 | */ |
||
| 582 | 82 | public static function makeAbsolute($path, $basePath) |
|
| 583 | { |
||
| 584 | 82 | Assert::stringNotEmpty($basePath, 'The base path must be a non-empty string. Got: %s'); |
|
| 585 | |||
| 586 | 79 | if (!static::isAbsolute($basePath)) { |
|
| 587 | 1 | throw new InvalidArgumentException(sprintf( |
|
| 588 | 1 | 'The base path "%s" is not an absolute path.', |
|
| 589 | $basePath |
||
| 590 | )); |
||
| 591 | } |
||
| 592 | |||
| 593 | 78 | if (static::isAbsolute($path)) { |
|
| 594 | 22 | return static::canonicalize($path); |
|
| 595 | } |
||
| 596 | |||
| 597 | 55 | View Code Duplication | if (false !== ($pos = strpos($basePath, '://'))) { |
| 598 | 12 | $scheme = substr($basePath, 0, $pos + 3); |
|
| 599 | 12 | $basePath = substr($basePath, $pos + 3); |
|
| 600 | } else { |
||
| 601 | 43 | $scheme = ''; |
|
| 602 | } |
||
| 603 | |||
| 604 | 55 | return $scheme.self::canonicalize(rtrim($basePath, '/\\').'/'.$path); |
|
| 605 | } |
||
| 606 | |||
| 607 | /** |
||
| 608 | * Turns a path into a relative path. |
||
| 609 | * |
||
| 610 | * The relative path is created relative to the given base path: |
||
| 611 | * |
||
| 612 | * ```php |
||
| 613 | * echo Path::makeRelative("/webmozart/style.css", "/webmozart/puli"); |
||
| 614 | * // => ../style.css |
||
| 615 | * ``` |
||
| 616 | * |
||
| 617 | * If a relative path is passed and the base path is absolute, the relative |
||
| 618 | * path is returned unchanged: |
||
| 619 | * |
||
| 620 | * ```php |
||
| 621 | * Path::makeRelative("style.css", "/webmozart/puli/css"); |
||
| 622 | * // => style.css |
||
| 623 | * ``` |
||
| 624 | * |
||
| 625 | * If both paths are relative, the relative path is created with the |
||
| 626 | * assumption that both paths are relative to the same directory: |
||
| 627 | * |
||
| 628 | * ```php |
||
| 629 | * Path::makeRelative("style.css", "webmozart/puli/css"); |
||
| 630 | * // => ../../../style.css |
||
| 631 | * ``` |
||
| 632 | * |
||
| 633 | * If both paths are absolute, their root directory must be the same, |
||
| 634 | * otherwise an exception is thrown: |
||
| 635 | * |
||
| 636 | * ```php |
||
| 637 | * Path::makeRelative("C:/webmozart/style.css", "/webmozart/puli"); |
||
| 638 | * // InvalidArgumentException |
||
| 639 | * ``` |
||
| 640 | * |
||
| 641 | * If the passed path is absolute, but the base path is not, an exception |
||
| 642 | * is thrown as well: |
||
| 643 | * |
||
| 644 | * ```php |
||
| 645 | * Path::makeRelative("/webmozart/style.css", "webmozart/puli"); |
||
| 646 | * // InvalidArgumentException |
||
| 647 | * ``` |
||
| 648 | * |
||
| 649 | * If the base path is not an absolute path, an exception is thrown. |
||
| 650 | * |
||
| 651 | * The result is a canonical path. |
||
| 652 | * |
||
| 653 | * @param string $path A path to make relative. |
||
| 654 | * @param string $basePath A base path. |
||
| 655 | * |
||
| 656 | * @return string A relative path in canonical form. |
||
| 657 | * |
||
| 658 | * @throws InvalidArgumentException If the base path is not absolute or if |
||
| 659 | * the given path has a different root |
||
| 660 | * than the base path. |
||
| 661 | * |
||
| 662 | * @since 1.0 Added method. |
||
| 663 | * @since 2.0 Method now fails if $path or $basePath is not a string. |
||
| 664 | */ |
||
| 665 | 97 | public static function makeRelative($path, $basePath) |
|
| 666 | { |
||
| 667 | 97 | Assert::string($basePath, 'The base path must be a string. Got: %s'); |
|
| 668 | |||
| 669 | 95 | $path = static::canonicalize($path); |
|
| 670 | 94 | $basePath = static::canonicalize($basePath); |
|
| 671 | |||
| 672 | 94 | list($root, $relativePath) = self::split($path); |
|
| 673 | 94 | list($baseRoot, $relativeBasePath) = self::split($basePath); |
|
| 674 | |||
| 675 | // If the base path is given as absolute path and the path is already |
||
| 676 | // relative, consider it to be relative to the given absolute path |
||
| 677 | // already |
||
| 678 | 94 | if ('' === $root && '' !== $baseRoot) { |
|
| 679 | // If base path is already in its root |
||
| 680 | 32 | if ('' === $relativeBasePath) { |
|
| 681 | 30 | $relativePath = ltrim($relativePath, './\\'); |
|
| 682 | } |
||
| 683 | |||
| 684 | 32 | return $relativePath; |
|
| 685 | } |
||
| 686 | |||
| 687 | // If the passed path is absolute, but the base path is not, we |
||
| 688 | // cannot generate a relative path |
||
| 689 | 62 | if ('' !== $root && '' === $baseRoot) { |
|
| 690 | 2 | throw new InvalidArgumentException(sprintf( |
|
| 691 | 2 | 'The absolute path "%s" cannot be made relative to the '. |
|
| 692 | 'relative path "%s". You should provide an absolute base '. |
||
| 693 | 2 | 'path instead.', |
|
| 694 | $path, |
||
| 695 | $basePath |
||
| 696 | )); |
||
| 697 | } |
||
| 698 | |||
| 699 | // Fail if the roots of the two paths are different |
||
| 700 | 60 | if ($baseRoot && $root !== $baseRoot) { |
|
| 701 | 18 | throw new InvalidArgumentException(sprintf( |
|
| 702 | 18 | 'The path "%s" cannot be made relative to "%s", because they '. |
|
| 703 | 18 | 'have different roots ("%s" and "%s").', |
|
| 704 | $path, |
||
| 705 | $basePath, |
||
| 706 | $root, |
||
| 707 | $baseRoot |
||
| 708 | )); |
||
| 709 | } |
||
| 710 | |||
| 711 | 42 | if ('' === $relativeBasePath) { |
|
| 712 | 5 | return $relativePath; |
|
| 713 | } |
||
| 714 | |||
| 715 | // Build a "../../" prefix with as many "../" parts as necessary |
||
| 716 | 37 | $parts = explode('/', $relativePath); |
|
| 717 | 37 | $baseParts = explode('/', $relativeBasePath); |
|
| 718 | 37 | $dotDotPrefix = ''; |
|
| 719 | |||
| 720 | // Once we found a non-matching part in the prefix, we need to add |
||
| 721 | // "../" parts for all remaining parts |
||
| 722 | 37 | $match = true; |
|
| 723 | |||
| 724 | 37 | foreach ($baseParts as $i => $basePart) { |
|
| 725 | 37 | if ($match && isset($parts[$i]) && $basePart === $parts[$i]) { |
|
| 726 | 21 | unset($parts[$i]); |
|
| 727 | |||
| 728 | 21 | continue; |
|
| 729 | } |
||
| 730 | |||
| 731 | 26 | $match = false; |
|
| 732 | 26 | $dotDotPrefix .= '../'; |
|
| 733 | } |
||
| 734 | |||
| 735 | 37 | return rtrim($dotDotPrefix.implode('/', $parts), '/'); |
|
| 736 | } |
||
| 737 | |||
| 738 | /** |
||
| 739 | * Returns whether the given path is on the local filesystem. |
||
| 740 | * |
||
| 741 | * @param string $path A path string. |
||
| 742 | * |
||
| 743 | * @return bool Returns true if the path is local, false for a URL. |
||
| 744 | * |
||
| 745 | * @since 1.0 Added method. |
||
| 746 | * @since 2.0 Method now fails if $path is not a string. |
||
| 747 | */ |
||
| 748 | 6 | public static function isLocal($path) |
|
| 754 | |||
| 755 | /** |
||
| 756 | * Returns the longest common base path of a set of paths. |
||
| 757 | * |
||
| 758 | * Dot segments ("." and "..") are removed/collapsed and all slashes turned |
||
| 759 | * into forward slashes. |
||
| 760 | * |
||
| 761 | * ```php |
||
| 762 | * $basePath = Path::getLongestCommonBasePath(array( |
||
| 763 | * '/webmozart/css/style.css', |
||
| 764 | * '/webmozart/css/..' |
||
| 765 | * )); |
||
| 766 | * // => /webmozart |
||
| 767 | * ``` |
||
| 768 | * |
||
| 769 | * The root is returned if no common base path can be found: |
||
| 770 | * |
||
| 771 | * ```php |
||
| 772 | * $basePath = Path::getLongestCommonBasePath(array( |
||
| 773 | * '/webmozart/css/style.css', |
||
| 774 | * '/puli/css/..' |
||
| 775 | * )); |
||
| 776 | * // => / |
||
| 777 | * ``` |
||
| 778 | * |
||
| 779 | * If the paths are located on different Windows partitions, `null` is |
||
| 780 | * returned. |
||
| 781 | * |
||
| 782 | * ```php |
||
| 783 | * $basePath = Path::getLongestCommonBasePath(array( |
||
| 784 | * 'C:/webmozart/css/style.css', |
||
| 785 | * 'D:/webmozart/css/..' |
||
| 786 | * )); |
||
| 787 | * // => null |
||
| 788 | * ``` |
||
| 789 | * |
||
| 790 | * @param array $paths A list of paths. |
||
| 791 | * |
||
| 792 | * @return string|null The longest common base path in canonical form or |
||
| 793 | * `null` if the paths are on different Windows |
||
| 794 | * partitions. |
||
| 795 | * |
||
| 796 | * @since 1.0 Added method. |
||
| 797 | * @since 2.0 Method now fails if $paths are not strings. |
||
| 798 | */ |
||
| 799 | 81 | public static function getLongestCommonBasePath(array $paths) |
|
| 837 | |||
| 838 | /** |
||
| 839 | * Joins two or more path strings. |
||
| 840 | * |
||
| 841 | * The result is a canonical path. |
||
| 842 | * |
||
| 843 | * @param string[]|string $paths Path parts as parameters or array. |
||
| 844 | * |
||
| 845 | * @return string The joint path. |
||
| 846 | * |
||
| 847 | * @since 2.0 Added method. |
||
| 848 | */ |
||
| 849 | 61 | public static function join($paths) |
|
| 890 | |||
| 891 | /** |
||
| 892 | * Returns whether a path is a base path of another path. |
||
| 893 | * |
||
| 894 | * Dot segments ("." and "..") are removed/collapsed and all slashes turned |
||
| 895 | * into forward slashes. |
||
| 896 | * |
||
| 897 | * ```php |
||
| 898 | * Path::isBasePath('/webmozart', '/webmozart/css'); |
||
| 899 | * // => true |
||
| 900 | * |
||
| 901 | * Path::isBasePath('/webmozart', '/webmozart'); |
||
| 902 | * // => true |
||
| 903 | * |
||
| 904 | * Path::isBasePath('/webmozart', '/webmozart/..'); |
||
| 905 | * // => false |
||
| 906 | * |
||
| 907 | * Path::isBasePath('/webmozart', '/puli'); |
||
| 908 | * // => false |
||
| 909 | * ``` |
||
| 910 | * |
||
| 911 | * @param string $basePath The base path to test. |
||
| 912 | * @param string $ofPath The other path. |
||
| 913 | * |
||
| 914 | * @return bool Whether the base path is a base path of the other path. |
||
| 915 | * |
||
| 916 | * @since 1.0 Added method. |
||
| 917 | * @since 2.0 Method now fails if $basePath or $ofPath is not a string. |
||
| 918 | */ |
||
| 919 | 61 | public static function isBasePath($basePath, $ofPath) |
|
| 933 | |||
| 934 | /** |
||
| 935 | * Splits a part into its root directory and the remainder. |
||
| 936 | * |
||
| 937 | * If the path has no root directory, an empty root directory will be |
||
| 938 | * returned. |
||
| 939 | * |
||
| 940 | * If the root directory is a Windows style partition, the resulting root |
||
| 941 | * will always contain a trailing slash. |
||
| 942 | * |
||
| 943 | * list ($root, $path) = Path::split("C:/webmozart") |
||
| 944 | * // => array("C:/", "webmozart") |
||
| 945 | * |
||
| 946 | * list ($root, $path) = Path::split("C:") |
||
| 947 | * // => array("C:/", "") |
||
| 948 | * |
||
| 949 | * @param string $path The canonical path to split. |
||
| 950 | * |
||
| 951 | * @return string[] An array with the root directory and the remaining |
||
| 952 | * relative path. |
||
| 953 | */ |
||
| 954 | 408 | private static function split($path) |
|
| 988 | |||
| 989 | /** |
||
| 990 | * Converts string to lower-case (multi-byte safe if mbstring is installed). |
||
| 991 | * |
||
| 992 | * @param string $str The string |
||
| 993 | * |
||
| 994 | * @return string Lower case string |
||
| 995 | */ |
||
| 996 | 6 | private static function toLower($str) |
|
| 1004 | |||
| 1005 | private function __construct() |
||
| 1008 | } |
||
| 1009 |
This check marks calls to methods that do not seem to exist on an object.
This is most likely the result of a method being renamed without all references to it being renamed likewise.