* @throws IOException When target file or directory already exists
* @throws IOException When origin cannot be renamed
*/
@ -301,6 +320,8 @@ class Filesystem {
/**
* Creates a symbolic link or copy a directory.
*
* @return void
*
* @throws IOException When symlink fails
*/
public static function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false) {
@ -336,6 +357,8 @@ class Filesystem {
*
* @param string|string[] $targetFiles The target file(s)
*
* @return void
*
* @throws FileNotFoundException When original file is missing or not a file
* @throws IOException When link fails, including if link already exists
*/
@ -367,7 +390,7 @@ class Filesystem {
/**
* @param string $linkType Name of the link type, typically 'symbolic' or 'hard'
*/
private static function linkException(string $origin, string $target, string $linkType) {
private static function linkException(string $origin, string $target, string $linkType): never {
if (self::$lastError) {
if ('\\' === \DIRECTORY_SEPARATOR && str_contains(self::$lastError, 'error code(1314)')) {
throw new IOException(sprintf('Unable to create "%s" link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
throw new \RuntimeException("Cannot find the home directory path: Your environment or operating system isn't supported.");
throw new RuntimeException("Cannot find the home directory path: Your environment or operating system isn't supported.");
}
/**
@ -417,17 +420,17 @@ class Path {
*
* @param string $basePath an absolute base path
*
* @throws \InvalidArgumentException if the base path is not absolute or if
* @throws InvalidArgumentException if the base path is not absolute or if
* the given path is an absolute path with
* a different root than the base path
*/
public static function makeAbsolute(string $path, string $basePath): string {
if ('' === $basePath) {
throw new \InvalidArgumentException(sprintf('The base path must be a non-empty string. Got: "%s".', $basePath));
throw new InvalidArgumentException(sprintf('The base path must be a non-empty string. Got: "%s".', $basePath));
}
if (!self::isAbsolute($basePath)) {
throw new \InvalidArgumentException(sprintf('The base path "%s" is not an absolute path.', $basePath));
throw new InvalidArgumentException(sprintf('The base path "%s" is not an absolute path.', $basePath));
}
if (self::isAbsolute($path)) {
@ -516,12 +519,12 @@ class Path {
// If the passed path is absolute, but the base path is not, we
// cannot generate a relative path
if ('' !== $root && '' === $baseRoot) {
throw new \InvalidArgumentException(sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath));
throw new InvalidArgumentException(sprintf('The absolute path "%s" cannot be made relative to the relative path "%s". You should provide an absolute base path instead.', $path, $basePath));
}
// Fail if the roots of the two paths are different
if ($baseRoot && $root !== $baseRoot) {
throw new \InvalidArgumentException(sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot));
throw new InvalidArgumentException(sprintf('The path "%s" cannot be made relative to "%s", because they have different roots ("%s" and "%s").', $path, $basePath, $root, $baseRoot));