• 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

95.24
/src/PSR16/Expire.php
1
<?php declare(strict_types=1);
2

3
namespace h4kuna\CriticalCache\PSR16;
4

5
use DateInterval;
6
use DateTimeImmutable;
7
use DateTimeInterface;
8
use Psr\Clock\ClockInterface;
9

10

11
final class Expire
12
{
13
        /**
14
         * @return ($ttl is null ? null : int)
15
         */
16
        public static function at(int|null|DateInterval|DateTimeInterface $ttl, ?ClockInterface $clock = null): ?int
1✔
17
        {
18
                return self::toDate($ttl, $clock)?->getTimestamp();
1✔
19
        }
20

21
        /**
22
         * @return ($ttl is null ? null : DateTimeInterface)
23
         */
24
        public static function toDate(
1✔
25
                int|null|DateInterval|DateTimeInterface $ttl,
26
                ?ClockInterface $clock = null,
27
        ): ?DateTimeInterface {
28
                if ($ttl === null) {
1✔
29
                        return null;
1✔
30
                } elseif (is_int($ttl)) {
1✔
31
                        return self::createDateTimeImmutable($clock)->modify("$ttl seconds");
1✔
32
                } elseif ($ttl instanceof DateTimeInterface) {
1✔
33
                        return $ttl;
1✔
34
                }
35

36
                return self::createDateTimeImmutable($clock)->add($ttl);
1✔
37
        }
38

39
        private static function createDateTimeImmutable(?ClockInterface $clock = null): DateTimeImmutable
1✔
40
        {
41
                return $clock === null ? new DateTimeImmutable() : $clock->now();
1✔
42
        }
43

44
        /**
45
         * @return ($ttl is null ? null : int)
46
         */
47
        public static function after(int|null|DateInterval|DateTimeInterface $ttl, ?ClockInterface $clock = null): ?int
1✔
48
        {
49
                if ($ttl === null || is_int($ttl)) {
1✔
50
                        return $ttl;
1✔
51
                }
52

53
                $now = self::createDateTimeImmutable($clock);
1✔
54
                if ($ttl instanceof DateTimeInterface) {
1✔
55
                        $timestamp = $ttl->getTimestamp();
1✔
56
                } else {
57
                        $timestamp = $now->add($ttl)->getTimestamp();
1✔
58
                }
59

60
                return $timestamp - $now->getTimestamp();
1✔
61
        }
62

63
        public function midnight(?ClockInterface $clock = null): int
64
        {
NEW
65
                return self::after(new DateTimeImmutable('tomorrow'), $clock);
×
66
        }
67

68
}
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