mirror of
https://github.com/rectorphp/rector.git
synced 2024-06-03 18:00:50 +00:00
4e3847e1bc
3c07468691
[DX] Localize few PackageBuilder classes (#2884)
29 lines
958 B
PHP
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);
|
|
}
|
|
}
|