Separation of concerns
This commit is contained in:
@@ -2,44 +2,31 @@
|
||||
|
||||
namespace IO\Input;
|
||||
|
||||
use IO\Exception\FileNotFoundException;
|
||||
use IO\Exception\FileNotReadableException;
|
||||
use IO\Exception\MissingFileArgumentException;
|
||||
use SplFileInfo;
|
||||
use IO\Filesystem\File;
|
||||
|
||||
class ShowInfoArguments
|
||||
{
|
||||
use ArgvAccess;
|
||||
|
||||
private SplFileInfo $file;
|
||||
private File $file;
|
||||
|
||||
public static function createFromGlobals(): self
|
||||
{
|
||||
$arguments = self::getArguments();
|
||||
$arguments = self::getScriptArgs();
|
||||
return new self(array_shift($arguments));
|
||||
}
|
||||
|
||||
public function __construct(?string $file)
|
||||
public function __construct(?string $filepath)
|
||||
{
|
||||
$this->guardUnusableFile($file);
|
||||
$this->file = new SplFileInfo($file);
|
||||
if (is_null($filepath)) {
|
||||
throw new MissingFileArgumentException();
|
||||
}
|
||||
$this->file = File::fromString($filepath);
|
||||
}
|
||||
|
||||
public function getFile(): SplFileInfo
|
||||
public function getFile(): File
|
||||
{
|
||||
return $this->file;
|
||||
}
|
||||
|
||||
private function guardUnusableFile(string $file): void
|
||||
{
|
||||
if (is_null($file)) {
|
||||
throw new MissingFileArgumentException();
|
||||
}
|
||||
if (!file_exists($file)) {
|
||||
throw new FileNotFoundException($file);
|
||||
}
|
||||
if (!is_readable($file)) {
|
||||
throw new FileNotReadableException($file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user