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

h4kuna / critical-cache / 21130772768

19 Jan 2026 08:40AM UTC coverage: 95.214% (-0.09%) from 95.3%
21130772768

push

github

h4kuna
feat(update): new version
- UseOneTimeService support validFrom
- use LogicException
- remove old dependency Nette/Caching

29 of 33 new or added lines in 6 files covered. (87.88%)

1 existing line in 1 file now uncovered.

378 of 397 relevant lines covered (95.21%)

0.95 hits per line

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

90.91
/src/Utils/DateRangeStore.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\CriticalCache\Utils;
4

5
use DateTimeImmutable;
6
use DateTimeInterface;
7
use h4kuna\CriticalCache\Exceptions\LogicException;
8

9
/**
10
 * @phpstan-type TypeRange array{from: ?DateTimeImmutable, to: ?DateTimeImmutable, v: ?string}
11
 * @phpstan-type TypeSave array{from?: string, to?: string, v?: string}
12
 */
13
final class DateRangeStore
14
{
15
        /**
16
         * @param TypeSave $data
17
         * @return TypeRange
18
         */
19
        public static function decode(array $data): array
1✔
20
        {
21
                $data['from'] = array_key_exists('from', $data) ? self::toDate($data['from']) : null;
1✔
22
                $data['to'] = array_key_exists('to', $data) ? self::toDate($data['to']) : null;
1✔
23

24
                if (array_key_exists('v', $data) === false) {
1✔
25
                        $data['v'] = null;
1✔
26
                }
27

28
                return $data;
1✔
29
        }
30

31
        /**
32
         * @return TypeSave
33
         */
34
        public static function encode(
1✔
35
                ?DateTimeInterface $from,
36
                DateTimeInterface $to,
37
                string $value,
38
        ): array {
39
                $out = [
1✔
40
                        'to' => self::toString($to),
1✔
41
                ];
42

43
                if ($from !== null) {
1✔
44
                        $out['from'] = self::toString($from);
1✔
45
                }
46

47
                $out['v'] = $value;
1✔
48

49
                return $out;
1✔
50
        }
51

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

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

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

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