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

chico-rei / correios-php / 27582377165

15 Jun 2026 11:08PM UTC coverage: 4.589% (-0.04%) from 4.627%
27582377165

push

github

mathmarques
set min version to php 8.2

57 of 1242 relevant lines covered (4.59%)

0.05 hits per line

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

0.0
/src/Cache/ArrayCache.php
1
<?php
2

3
namespace ChicoRei\Packages\Correios\Cache;
4

5
use DateInterval;
6
use DateTimeImmutable;
7
use Psr\SimpleCache\CacheInterface;
8

9
/**
10
 * Minimal in-memory PSR-16 cache used as the default cache driver.
11
 */
12
class ArrayCache implements CacheInterface
13
{
14
    /**
15
     * @var array<string, array{value: mixed, expiresAt: int|null}>
16
     */
17
    private array $store = [];
18

19
    public function get(string $key, mixed $default = null): mixed
20
    {
21
        if (!$this->has($key)) {
×
22
            return $default;
×
23
        }
24

25
        return $this->store[$key]['value'];
×
26
    }
27

28
    public function set(string $key, mixed $value, null|int|DateInterval $ttl = null): bool
29
    {
30
        $this->store[$key] = [
×
31
            'value' => $value,
×
32
            'expiresAt' => $this->expirationFromTtl($ttl),
×
33
        ];
×
34

35
        return true;
×
36
    }
37

38
    public function delete(string $key): bool
39
    {
40
        unset($this->store[$key]);
×
41

42
        return true;
×
43
    }
44

45
    public function clear(): bool
46
    {
47
        $this->store = [];
×
48

49
        return true;
×
50
    }
51

52
    public function getMultiple(iterable $keys, mixed $default = null): iterable
53
    {
54
        $values = [];
×
55

56
        foreach ($keys as $key) {
×
57
            $values[$key] = $this->get($key, $default);
×
58
        }
59

60
        return $values;
×
61
    }
62

63
    public function setMultiple(iterable $values, null|int|DateInterval $ttl = null): bool
64
    {
65
        foreach ($values as $key => $value) {
×
66
            $this->set($key, $value, $ttl);
×
67
        }
68

69
        return true;
×
70
    }
71

72
    public function deleteMultiple(iterable $keys): bool
73
    {
74
        foreach ($keys as $key) {
×
75
            $this->delete($key);
×
76
        }
77

78
        return true;
×
79
    }
80

81
    public function has(string $key): bool
82
    {
83
        if (!array_key_exists($key, $this->store)) {
×
84
            return false;
×
85
        }
86

87
        $expiresAt = $this->store[$key]['expiresAt'];
×
88

89
        if ($expiresAt !== null && $expiresAt <= time()) {
×
90
            unset($this->store[$key]);
×
91

92
            return false;
×
93
        }
94

95
        return true;
×
96
    }
97

98
    private function expirationFromTtl(null|int|DateInterval $ttl): ?int
99
    {
100
        if ($ttl === null) {
×
101
            return null;
×
102
        }
103

104
        if ($ttl instanceof DateInterval) {
×
105
            return (new DateTimeImmutable())->add($ttl)->getTimestamp();
×
106
        }
107

108
        return time() + $ttl;
×
109
    }
110
}
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