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

MichaelJ2324 / PHP-REST-Client / 15164546007

21 May 2025 02:13PM UTC coverage: 98.369%. Remained the same
15164546007

push

github

web-flow
Merge pull request #20 from MichaelJ2324/3.x

v3.0.7

0 of 2 new or added lines in 1 file covered. (0.0%)

1146 of 1165 relevant lines covered (98.37%)

1.56 hits per line

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

100.0
/src/Cache/MemoryCache.php
1
<?php
2

3
namespace MRussell\REST\Cache;
4

5
use Psr\SimpleCache\CacheInterface;
6

7
class MemoryCache implements CacheInterface
8
{
9
    private array $cache = [];
10

11
    private static self $instance;
12

13
    /**
14
     * Get the In Memory Cache Object
15
     */
16
    public static function getInstance(): MemoryCache
1✔
17
    {
18
        if (!isset(static::$instance)) {
1✔
19
            // @codeCoverageIgnoreStart
20
            static::$instance = new static();
21
            // @codeCoverageIgnoreEnd
22
        }
23

24
        return static::$instance;
1✔
25
    }
26

27
    /**
28
     * @inheritDoc
29
     */
30
    public function get($key, $default = null): mixed
1✔
31
    {
32
        return $this->cache[$key] ?? $default;
1✔
33
    }
34

35
    /**
36
     * @param $key
37
     * @param $value
38
     * @param $ttl - Ignored since its in memory
39
     * @return bool|void
40
     */
41
    public function set($key, $value, $ttl = null): bool
1✔
42
    {
43
        $this->cache[$key] = $value;
1✔
44
        return true;
1✔
45
    }
46

47
    /**
48
     * @inheritDoc
49
     */
50
    public function delete($key): bool
2✔
51
    {
52
        $return = false;
2✔
53
        if ($this->has($key)) {
2✔
54
            unset($this->cache[$key]);
2✔
55
            $return = true;
2✔
56
        }
57

58
        return $return;
2✔
59
    }
60

61
    /**
62
     * @inheritDoc
63
     */
64
    public function clear(): bool
1✔
65
    {
66
        $this->cache = [];
1✔
67
        return true;
1✔
68
    }
69

70
    /**
71
     * @inheritDoc
72
     */
73
    public function getMultiple($keys, $default = null): iterable
1✔
74
    {
75
        $items = $default ?? [];
1✔
76
        foreach ($keys as $key) {
1✔
77
            if ($this->has($key)) {
1✔
78
                $items[$key] = $this->cache[$key];
1✔
79
            }
80
        }
81

82
        if (empty($items)) {
1✔
83
            $items = $default;
1✔
84
        }
85

86
        return $items ?? [];
1✔
87
    }
88

89
    /**
90
     * @inheritDoc
91
     */
92
    public function setMultiple($values, $ttl = null): bool
1✔
93
    {
94
        foreach ($values as $key => $value) {
1✔
95
            $this->set($key, $value, $ttl);
1✔
96
        }
97

98
        return true;
1✔
99
    }
100

101
    /**
102
     * @inheritDoc
103
     */
104
    public function deleteMultiple($keys): bool
1✔
105
    {
106
        $return = true;
1✔
107
        foreach ($keys as $key) {
1✔
108
            if (!$this->delete($key)) {
1✔
109
                $return = false;
1✔
110
            }
111
        }
112

113
        return $return;
1✔
114
    }
115

116
    /**
117
     * @inheritDoc
118
     */
119
    public function has($key): bool
1✔
120
    {
121
        return isset($this->cache[$key]);
1✔
122
    }
123
}
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