rector/vendor/symplify/smart-file-system/src/FileSystemGuard.php
2022-09-01 09:30:44 +00:00

29 lines
958 B
PHP

<?php
declare (strict_types=1);
namespace RectorPrefix202209\Symplify\SmartFileSystem;
use RectorPrefix202209\Symplify\SmartFileSystem\Exception\DirectoryNotFoundException;
use RectorPrefix202209\Symplify\SmartFileSystem\Exception\FileNotFoundException;
final class FileSystemGuard
{
public function ensureFileExists(string $file, string $location) : void
{
if (\file_exists($file)) {
return;
}
throw new FileNotFoundException(\sprintf('File "%s" not found in "%s".', $file, $location));
}
public function ensureDirectoryExists(string $directory, string $extraMessage) : void
{
if (\is_dir($directory) && \file_exists($directory)) {
return;
}
$message = \sprintf('Directory "%s" was not found.', $directory);
if ($extraMessage !== '') {
$message .= ' ' . $extraMessage;
}
throw new DirectoryNotFoundException($message);
}
}