• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In
Build has been canceled!

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

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

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

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

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

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

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

63
                return $timestamp - $now->getTimestamp();
1✔
64
        }
65

66
        /**
67
         * next day 00:00:00
68
         */
69
        public static function midnight(?ClockInterface $clock = null): int
1✔
70
        {
71
                $now = $clock?->now()->modify('tomorrow') ?? new DateTimeImmutable('tomorrow');
1✔
72
                return self::after($now, $clock);
1✔
73
        }
74

75
        /**
76
         * this day 23:59:59
77
         */
78
        public static function lasSecondOfDay(?ClockInterface $clock = null): int
79
        {
NEW
80
                return self::midnight($clock) - 1;
×
81
        }
82

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