• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

h4kuna / critical-cache / 12136248911

03 Dec 2024 09:00AM UTC coverage: 93.796% (+0.3%) from 93.511%
12136248911

push

github

h4kuna
fix(github actions)

257 of 274 relevant lines covered (93.8%)

0.94 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

92.31
/src/Services/UseOneTimeService.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\CriticalCache\Services;
4

5
use DateInterval;
6
use h4kuna\CriticalCache\Contracts\UseOneTimeServiceContract;
7
use h4kuna\CriticalCache\Exceptions\BrokenCacheException;
8
use Psr\SimpleCache\CacheInterface;
9

10
final class UseOneTimeService implements UseOneTimeServiceContract
11
{
12
        public function __construct(
1✔
13
                private readonly CacheInterface $cache,
14
        ) {
15
        }
1✔
16

17
        public function save(string $key, string $value, null|int|DateInterval $ttl = 900): string
1✔
18
        {
19
                $this->cache->set($key, $value, $ttl);
1✔
20

21
                return $value;
1✔
22
        }
23

24
        public function get(string $key): ?string
1✔
25
        {
26
                $stored = $this->cache->get($key);
1✔
27
                if ($stored === null) {
1✔
28
                        return null;
1✔
29
                }
30

31
                $this->cache->delete($key);
1✔
32

33
                if (is_string($stored) === false) {
1✔
34
                        throw new BrokenCacheException('Stored value is not string.');
×
35
                }
36

37
                return $stored;
1✔
38
        }
39
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc