From dfe9374a71abd7dc767c87e2358f339d8f18c688 Mon Sep 17 00:00:00 2001 From: Valentin Udaltsov Date: Sat, 9 Mar 2024 03:10:02 +0300 Subject: [PATCH] Added FileResourceTest, fixed memoization in FileResource::changeDetector() --- FileResource.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/FileResource.php b/FileResource.php index 5b37876..b1fe9ab 100644 --- a/FileResource.php +++ b/FileResource.php @@ -35,13 +35,16 @@ public function __construct(string $file, string|false $extension = false) $this->file = $file; } + /** + * @throws FileNotReadable + */ public function contents(): string { if ($this->contents !== null) { return $this->contents; } - $contents = file_get_contents($this->file); + $contents = @file_get_contents($this->file); if ($contents === false) { throw new FileNotReadable($this->file); @@ -50,9 +53,12 @@ public function contents(): string return $this->contents = $contents; } + /** + * @throws FileNotReadable + */ public function changeDetector(): ChangeDetector { - return $this->changeDetector ??= ChangeDetector::fromFileContents($this->file, $this->contents); + return $this->changeDetector ??= ChangeDetector::fromFileContents($this->file, $this->contents()); } public function isInternal(): bool