Important memory improvement

This commit is contained in:
2021-03-23 23:10:23 +01:00
parent 8f88b626f0
commit cc2696668c
4 changed files with 65 additions and 33 deletions

View File

@@ -11,12 +11,7 @@ class ShowInfoArguments
{
use ArgvAccess;
private ?string $file;
public function __construct(?string $file)
{
$this->file = $file;
}
private SplFileInfo $file;
public static function createFromGlobals(): self
{
@@ -24,18 +19,27 @@ class ShowInfoArguments
return new self(array_shift($arguments));
}
public function __construct(?string $file)
{
$this->guardUnusableFile($file);
$this->file = new SplFileInfo($file);
}
public function getFile(): SplFileInfo
{
if (is_null($this->file)) {
return $this->file;
}
private function guardUnusableFile(string $file): void
{
if (is_null($file)) {
throw new MissingFileArgumentException();
}
if (!file_exists($this->file)) {
throw new FileNotFoundException($this->file);
if (!file_exists($file)) {
throw new FileNotFoundException($file);
}
if (!is_readable($this->file)) {
throw new FileNotReadableException($this->file);
if (!is_readable($file)) {
throw new FileNotReadableException($file);
}
return new SplFileInfo($this->file);
}
}