Skip to content

Commit

Permalink
fix: Typecast issues (#369)
Browse files Browse the repository at this point in the history
  • Loading branch information
ankitpokhrel authored Nov 18, 2021
1 parent c48bc87 commit da1bb94
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/Cache/FileStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,13 @@ protected function lock(string $path, int $type = LOCK_SH, callable $cb = null)
public function sharedGet(string $path): string
{
return $this->lock($path, LOCK_SH, function ($handle) use ($path) {
return fread($handle, filesize($path) ?: 1);
$contents = fread($handle, filesize($path) ?: 1);

if (false === $contents) {
return '';
}

return $contents;
});
}

Expand Down Expand Up @@ -198,7 +204,7 @@ public function set(string $key, $value)
}

return $this->lock($cacheFile, LOCK_EX, function ($handle) use ($cacheKey, $cacheFile, $value) {
$contents = fread($handle, filesize($cacheFile) ?: 1) ?? [];
$contents = fread($handle, filesize($cacheFile) ?: 1) ?? '';
$contents = json_decode($contents, true) ?? [];

if ( ! empty($contents[$cacheKey]) && \is_array($value)) {
Expand Down

0 comments on commit da1bb94

Please sign in to comment.