Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
5.88% |
1 / 17 |
|
11.11% |
1 / 9 |
CRAP | |
0.00% |
0 / 1 |
| LaravelCacheItem | |
5.88% |
1 / 17 |
|
11.11% |
1 / 9 |
132.05 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| getKey | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| get | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isHit | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| set | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| expiresAt | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| expiresAfter | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
12 | |||
| tag | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getMetadata | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Apie\LaravelApie\Wrappers\Cache; |
| 4 | |
| 5 | use Apie\Core\ValueObjects\Utils; |
| 6 | use Symfony\Contracts\Cache\ItemInterface; |
| 7 | |
| 8 | class LaravelCacheItem implements ItemInterface |
| 9 | { |
| 10 | private ?int $expiration = null; |
| 11 | |
| 12 | /** |
| 13 | * @var array<array-key, mixed> $metadata |
| 14 | */ |
| 15 | private array $metadata = []; |
| 16 | |
| 17 | public function __construct( |
| 18 | private readonly string $key, |
| 19 | ) { |
| 20 | } |
| 21 | |
| 22 | public function getKey(): string |
| 23 | { |
| 24 | return $this->key; |
| 25 | } |
| 26 | |
| 27 | public function get(): mixed |
| 28 | { |
| 29 | return null; |
| 30 | } |
| 31 | |
| 32 | public function isHit(): bool |
| 33 | { |
| 34 | return false; |
| 35 | } |
| 36 | |
| 37 | public function set(mixed $value): static |
| 38 | { |
| 39 | return $this; |
| 40 | } |
| 41 | |
| 42 | public function expiresAt(?\DateTimeInterface $expiration): static |
| 43 | { |
| 44 | $this->expiration = $expiration?->getTimestamp(); |
| 45 | |
| 46 | return $this; |
| 47 | } |
| 48 | |
| 49 | public function expiresAfter(int|\DateInterval|null $time): static |
| 50 | { |
| 51 | if ($time instanceof \DateInterval) { |
| 52 | $now = new \DateTimeImmutable(); |
| 53 | $this->expiration = $now->add($time)->getTimestamp(); |
| 54 | } elseif ($time !== null) { |
| 55 | $this->expiration = time() + $time; |
| 56 | } else { |
| 57 | $this->expiration = null; |
| 58 | } |
| 59 | |
| 60 | return $this; |
| 61 | } |
| 62 | |
| 63 | public function tag($tags): static |
| 64 | { |
| 65 | $this->metadata['tags'] = is_string($tags) ? [$tags] : Utils::toArray($tags); |
| 66 | |
| 67 | return $this; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * @return array<array-key, mixed> |
| 72 | */ |
| 73 | public function getMetadata(): array |
| 74 | { |
| 75 | return $this->metadata + ['expiration' => $this->expiration]; |
| 76 | } |
| 77 | } |