![]() Server : Apache System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64 User : corals ( 1002) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system Directory : /home/corals/cartforge.co/vendor/phpmd/phpmd/src/main/php/PHPMD/Utility/ |
<?php namespace PHPMD\Utility; use RuntimeException; class Paths { /** * Transform the given absolute path to the relative path based on the given base path. * * @param string $basePath * @param string $filePath * @return string */ public static function getRelativePath($basePath, $filePath) { // normalize slashes and ensure base path ends with slash $basePath = rtrim(str_replace('\\', '/', $basePath), '/') . '/'; $filePath = str_replace('\\', '/', $filePath); // subtract base dir from filepath if there's a match if (stripos($filePath, $basePath) === 0) { $filePath = substr($filePath, strlen($basePath)); } return $filePath; } /** * Concat pathB to pathA with a single path separators between them * * @param string $pathA * @param string $pathB * @return string */ public static function concat($pathA, $pathB) { return rtrim(str_replace('\\', '/', $pathA), '/') . '/' . ltrim(str_replace('\\', '/', $pathB), '/'); } /** * Get the realpath of the given path or exception on failure * @param string $path * @return string * @throws RuntimeException */ public static function getRealPath($path) { $absolutePath = realpath($path); if ($absolutePath === false) { throw new RuntimeException('Unable to determine the realpath for: ' . $path); } return $absolutePath; } }