Skip to content

Commit

Permalink
Added FileResourceTest, fixed memoization in FileResource::changeDete…
Browse files Browse the repository at this point in the history
…ctor()
  • Loading branch information
vudaltsov committed Mar 9, 2024
1 parent 44528da commit dfe9374
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions FileResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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
Expand Down

0 comments on commit dfe9374

Please sign in to comment.