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

h4kuna / critical-cache / 21202020816

21 Jan 2026 08:10AM UTC coverage: 95.0% (-0.2%) from 95.214%
21202020816

push

github

h4kuna
feat(ValidityAwareCache): remove ValidService

73 of 78 new or added lines in 7 files covered. (93.59%)

380 of 400 relevant lines covered (95.0%)

0.95 hits per line

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

94.74
/src/Caching/ValidityAware/TimeRangeEncoder.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\CriticalCache\Caching\ValidityAware;
4

5
use DateTimeImmutable;
6
use DateTimeInterface;
7
use h4kuna\CriticalCache\Exceptions\LogicException;
8
use Psr\Clock\ClockInterface;
9

10
/**
11
 * f = from
12
 * t = to
13
 * v = value
14
 *
15
 * @phpstan-type TypeSave array{f: string, t: string, v: string}
16
 */
17
final readonly class TimeRangeEncoder
18
{
19
        public function __construct(
1✔
20
                private ClockInterface $clock,
21
        ) {
22
        }
1✔
23

24
        /**
25
         * @param TypeSave|null $data
26
         */
27
        public function decode(?array $data): TimeRangeItem
1✔
28
        {
29
                if ($data === null) {
1✔
30
                        return new TimeRangeItem(from: null, to: null, value: null, clock: $this->clock);
1✔
31
                }
32

33
                return new TimeRangeItem(self::toDate($data['f']), self::toDate($data['t']), $data['v'], $this->clock);
1✔
34
        }
35

36
        /**
37
         * @return TypeSave
38
         */
39
        public function encode(
1✔
40
                ?DateTimeInterface $from,
41
                DateTimeInterface $to,
42
                string $value,
43
        ): array {
44
                return [
45
                        't' => self::toString($to),
1✔
46
                        'v' => $value,
1✔
47
                        'f' => $from === null ? '' : self::toString($from),
1✔
48
                ];
49
        }
50

51
        private static function toString(DateTimeInterface $dateTime): string
1✔
52
        {
53
                return $dateTime->format(DateTimeInterface::RFC3339_EXTENDED);
1✔
54
        }
55

56
        private static function toDate(string $dateTime): ?DateTimeImmutable
1✔
57
        {
58
                if ($dateTime === '') {
1✔
59
                        return null;
1✔
60
                }
61
                $date = DateTimeImmutable::createFromFormat(DateTimeInterface::RFC3339_EXTENDED, $dateTime);
1✔
62

63
                if ($date === false) {
1✔
NEW
64
                        throw new LogicException('Broken date format in cache.');
×
65
                }
66

67
                return $date;
1✔
68
        }
69
}
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