• 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

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

3
namespace h4kuna\CriticalCache\Caching\ValidityAware;
4

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

9
final readonly class TimeRangeItem
10
{
11
        public function __construct(
1✔
12
                public ?DateTimeImmutable $from,
13
                public ?DateTimeImmutable $to,
14
                public ?string $value,
15
                private ClockInterface $clock,
16
        ) {
17
                if ($this->from !== null && $this->to !== null && $this->from > $this->to) {
1✔
NEW
18
                        throw new LogicException('From date must be less than to date.');
×
19
                }
20
        }
1✔
21

22
        public function value(): ?string
23
        {
24
                return $this->isValid() ? $this->value : null;
1✔
25
        }
26

27
        public function isExpired(): bool
28
        {
29
                if ($this->value === null) {
1✔
30
                        return true;
1✔
31
                } elseif ($this->to === null) {
1✔
32
                        return false;
1✔
33
                }
34

35
                return $this->to < $this->clock->now();
1✔
36
        }
37

38
        public function isValid(): bool
39
        {
40
                if ($this->value === null) {
1✔
41
                        return false;
1✔
42
                } elseif ($this->from === null && $this->to === null) {
1✔
NEW
43
                        return true;
×
44
                }
45

46
                $now = $this->clock->now();
1✔
47
                if ($this->from !== null && $this->to !== null) {
1✔
48
                        return $this->from <= $now && $now <= $this->to;
1✔
49
                } elseif ($this->from === null) {
1✔
50
                        return $now <= $this->to;
1✔
51
                }
52

53
                return $this->from <= $now;
1✔
54
        }
55
}
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