Skip to content

Commit

Permalink
Fix styles
Browse files Browse the repository at this point in the history
  • Loading branch information
Hectorhammett committed Aug 13, 2024
1 parent 2e5872c commit d16fc10
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
36 changes: 29 additions & 7 deletions src/Cache/FileSystemCacheItemPool.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,27 @@

class FileSystemCacheItemPool implements CacheItemPoolInterface
{
/**
* @var string
*/
private string $cachePath = 'cache/';

/**
* @var array<CacheItemInterface>
*/
private array $buffer = [];

/**
* Creates a FileSystemCacheItemPool cache that stores values in local storage
*
* @var FileSystemCacheItemPoolOptions $options
*
* @var null|FileSystemCacheItemPoolOptions $options
*/
public function __construct(FileSystemCacheItemPoolOptions $options = new FileSystemCacheItemPoolOptions())
public function __construct(null|FileSystemCacheItemPoolOptions $options = null)

Check failure on line 42 in src/Cache/FileSystemCacheItemPool.php

View workflow job for this annotation

GitHub Actions / PHPStan Static Analysis

PHPDoc tag @var above a method has no effect.
{
if (!$options) {
$options = new FileSystemCacheItemPoolOptions();
}

$this->cachePath = $options->cachePath;

if (is_dir($this->cachePath)) {
Expand Down Expand Up @@ -61,11 +72,22 @@ public function getItem(string $key): CacheItemInterface
}

$serializedItem = file_get_contents($itemPath);

if ($serializedItem === false) {
return new TypedItem($key);
}

return unserialize($serializedItem);
}

/**
* {@inheritdoc}
*
* @return iterable<CacheItemInterface> An iterable object containing all the
* A traversable collection of Cache Items keyed by the cache keys of
* each item. A Cache item will be returned for each key, even if that
* key is not found. However, if no keys are specified then an empty
* traversable MUST be returned instead.
*/
public function getItems(array $keys = []): iterable
{
Expand All @@ -84,7 +106,7 @@ public function getItems(array $keys = []): iterable
public function save(CacheItemInterface $item): bool
{
if (!$this->validKey($item->getKey())) {
throw new InvalidArgumentException("The key " . $item->getKey() . " is not valid. The key should follow the pattern |^[a-zA-Z0-9_\.! ]+$|");
throw new InvalidArgumentException('The key ' . $item->getKey() . " is not valid. The key should follow the pattern |^[a-zA-Z0-9_\.! ]+$|");
}

$itemPath = $this->cacheFilePath($item->getKey());
Expand All @@ -104,7 +126,7 @@ public function save(CacheItemInterface $item): bool
*/
public function hasItem(string $key): bool
{
return $this->getItem($key)->isHit();
return $this->getItem($key)->isHit();
}

/**
Expand All @@ -126,7 +148,7 @@ public function clear(): bool
continue;
}

if (!unlink($this->cachePath . "/" . $fileName)) {
if (!unlink($this->cachePath . '/' . $fileName)) {
return false;
}
}
Expand Down Expand Up @@ -201,6 +223,6 @@ private function cacheFilePath(string $key): string

private function validKey(string $key): bool
{
return preg_match('|^[a-zA-Z0-9_\.! ]+$|', $key);
return (bool)preg_match('|^[a-zA-Z0-9_\.! ]+$|', $key);
}
}
2 changes: 1 addition & 1 deletion src/Cache/FileSystemCacheItemPoolOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@
class FileSystemCacheItemPoolOptions
{
public string $cachePath = 'cache/';
}
}

0 comments on commit d16fc10

Please sign in to comment.