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

chico-rei / correios-php / 27362348693

11 Jun 2026 04:37PM UTC coverage: 4.627% (-0.1%) from 4.758%
27362348693

push

github

mathmarques
Remove dependency

0 of 35 new or added lines in 2 files covered. (0.0%)

57 of 1232 relevant lines covered (4.63%)

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
 * Signatures are intentionally untyped to stay compatible with
13
 * psr/simple-cache ^1.0 on PHP 7.4.
14
 */
15
class ArrayCache implements CacheInterface
16
{
17
    /**
18
     * @var array<string, array{value: mixed, expiresAt: int|null}>
19
     */
20
    private array $store = [];
21

22
    public function get($key, $default = null)
23
    {
NEW
24
        if (!$this->has($key)) {
×
NEW
25
            return $default;
×
26
        }
27

NEW
28
        return $this->store[$key]['value'];
×
29
    }
30

31
    public function set($key, $value, $ttl = null)
32
    {
NEW
33
        $this->store[$key] = [
×
NEW
34
            'value' => $value,
×
NEW
35
            'expiresAt' => $this->expirationFromTtl($ttl),
×
NEW
36
        ];
×
37

NEW
38
        return true;
×
39
    }
40

41
    public function delete($key)
42
    {
NEW
43
        unset($this->store[$key]);
×
44

NEW
45
        return true;
×
46
    }
47

48
    public function clear()
49
    {
NEW
50
        $this->store = [];
×
51

NEW
52
        return true;
×
53
    }
54

55
    public function getMultiple($keys, $default = null)
56
    {
NEW
57
        $values = [];
×
58

NEW
59
        foreach ($keys as $key) {
×
NEW
60
            $values[$key] = $this->get($key, $default);
×
61
        }
62

NEW
63
        return $values;
×
64
    }
65

66
    public function setMultiple($values, $ttl = null)
67
    {
NEW
68
        foreach ($values as $key => $value) {
×
NEW
69
            $this->set($key, $value, $ttl);
×
70
        }
71

NEW
72
        return true;
×
73
    }
74

75
    public function deleteMultiple($keys)
76
    {
NEW
77
        foreach ($keys as $key) {
×
NEW
78
            $this->delete($key);
×
79
        }
80

NEW
81
        return true;
×
82
    }
83

84
    public function has($key)
85
    {
NEW
86
        if (!array_key_exists($key, $this->store)) {
×
NEW
87
            return false;
×
88
        }
89

NEW
90
        $expiresAt = $this->store[$key]['expiresAt'];
×
91

NEW
92
        if ($expiresAt !== null && $expiresAt <= time()) {
×
NEW
93
            unset($this->store[$key]);
×
94

NEW
95
            return false;
×
96
        }
97

NEW
98
        return true;
×
99
    }
100

101
    /**
102
     * @param int|DateInterval|null $ttl
103
     */
104
    private function expirationFromTtl($ttl): ?int
105
    {
NEW
106
        if ($ttl === null) {
×
NEW
107
            return null;
×
108
        }
109

NEW
110
        if ($ttl instanceof DateInterval) {
×
NEW
111
            return (new DateTimeImmutable())->add($ttl)->getTimestamp();
×
112
        }
113

NEW
114
        return time() + (int) $ttl;
×
115
    }
116
}
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