@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | protected CacheInterface $storage, |
26 | 26 | protected ?EventDispatcherInterface $dispatcher = null, |
27 | 27 | protected ?string $prefix = null, |
28 | - ) {} |
|
28 | + ){} |
|
29 | 29 | |
30 | 30 | public function get(string $key, mixed $default = null): mixed |
31 | 31 | { |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | |
36 | 36 | $value = $this->storage->get($key); |
37 | 37 | |
38 | - if ($value === null) { |
|
38 | + if ($value === null){ |
|
39 | 39 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
40 | 40 | |
41 | 41 | return $default; |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | return $value; |
47 | 47 | } |
48 | 48 | |
49 | - public function set(string $key, mixed $value, \DateInterval|int|null $ttl = null): bool |
|
49 | + public function set(string $key, mixed $value, \DateInterval | int | null $ttl = null): bool |
|
50 | 50 | { |
51 | 51 | $key = $this->resolveKey($key); |
52 | 52 | |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | { |
90 | 90 | $array = []; |
91 | 91 | // Resolve keys and dispatch events |
92 | - foreach ($keys as $key) { |
|
92 | + foreach ($keys as $key){ |
|
93 | 93 | $key = $this->resolveKey($key); |
94 | 94 | $this->dispatcher?->dispatch(new CacheRetrieving($key)); |
95 | 95 | // Fill resulting array with default values |
@@ -99,16 +99,16 @@ discard block |
||
99 | 99 | // If no dispatcher is set, we can skip the loop with events |
100 | 100 | // to save some CPU cycles |
101 | 101 | $keys = \array_keys($array); |
102 | - if ($this->dispatcher === null) { |
|
102 | + if ($this->dispatcher === null){ |
|
103 | 103 | return $this->storage->getMultiple($keys, $default); |
104 | 104 | } |
105 | 105 | |
106 | 106 | $result = $this->storage->getMultiple($keys); |
107 | 107 | |
108 | - foreach ($result as $key => $value) { |
|
109 | - if ($value === null) { |
|
108 | + foreach ($result as $key => $value){ |
|
109 | + if ($value === null){ |
|
110 | 110 | $this->dispatcher->dispatch(new CacheMissed($key)); |
111 | - } else { |
|
111 | + }else{ |
|
112 | 112 | // Replace default value with actual value in the resulting array |
113 | 113 | $array[$key] = $value; |
114 | 114 | $this->dispatcher->dispatch(new CacheHit($key, $value)); |
@@ -118,12 +118,12 @@ discard block |
||
118 | 118 | return $array; |
119 | 119 | } |
120 | 120 | |
121 | - public function setMultiple(iterable $values, \DateInterval|int|null $ttl = null): bool |
|
121 | + public function setMultiple(iterable $values, \DateInterval | int | null $ttl = null): bool |
|
122 | 122 | { |
123 | 123 | $dispatcher = $this->dispatcher; |
124 | 124 | $array = []; |
125 | 125 | // Resolve keys and dispatch events |
126 | - foreach ($values as $key => $value) { |
|
126 | + foreach ($values as $key => $value){ |
|
127 | 127 | $key = $this->resolveKey($key); |
128 | 128 | $dispatcher?->dispatch(new KeyWriting($key, $value)); |
129 | 129 | $array[$key] = $value; |
@@ -148,7 +148,7 @@ discard block |
||
148 | 148 | |
149 | 149 | $array = []; |
150 | 150 | // Resolve keys and dispatch events |
151 | - foreach ($keys as $key) { |
|
151 | + foreach ($keys as $key){ |
|
152 | 152 | $key = $this->resolveKey($key); |
153 | 153 | $dispatcher?->dispatch(new KeyDeleting($key)); |
154 | 154 | $array[] = $key; |
@@ -179,6 +179,6 @@ discard block |
||
179 | 179 | |
180 | 180 | private function resolveKey(string $key): string |
181 | 181 | { |
182 | - return $this->prefix . $key; |
|
182 | + return $this->prefix.$key; |
|
183 | 183 | } |
184 | 184 | } |
@@ -25,7 +25,8 @@ discard block |
||
25 | 25 | protected CacheInterface $storage, |
26 | 26 | protected ?EventDispatcherInterface $dispatcher = null, |
27 | 27 | protected ?string $prefix = null, |
28 | - ) {} |
|
28 | + ) { |
|
29 | +} |
|
29 | 30 | |
30 | 31 | public function get(string $key, mixed $default = null): mixed |
31 | 32 | { |
@@ -35,7 +36,8 @@ discard block |
||
35 | 36 | |
36 | 37 | $value = $this->storage->get($key); |
37 | 38 | |
38 | - if ($value === null) { |
|
39 | + if ($value === null) |
|
40 | + { |
|
39 | 41 | $this->dispatcher?->dispatch(new CacheMissed($key)); |
40 | 42 | |
41 | 43 | return $default; |
@@ -89,7 +91,8 @@ discard block |
||
89 | 91 | { |
90 | 92 | $array = []; |
91 | 93 | // Resolve keys and dispatch events |
92 | - foreach ($keys as $key) { |
|
94 | + foreach ($keys as $key) |
|
95 | + { |
|
93 | 96 | $key = $this->resolveKey($key); |
94 | 97 | $this->dispatcher?->dispatch(new CacheRetrieving($key)); |
95 | 98 | // Fill resulting array with default values |
@@ -99,16 +102,21 @@ discard block |
||
99 | 102 | // If no dispatcher is set, we can skip the loop with events |
100 | 103 | // to save some CPU cycles |
101 | 104 | $keys = \array_keys($array); |
102 | - if ($this->dispatcher === null) { |
|
105 | + if ($this->dispatcher === null) |
|
106 | + { |
|
103 | 107 | return $this->storage->getMultiple($keys, $default); |
104 | 108 | } |
105 | 109 | |
106 | 110 | $result = $this->storage->getMultiple($keys); |
107 | 111 | |
108 | - foreach ($result as $key => $value) { |
|
109 | - if ($value === null) { |
|
112 | + foreach ($result as $key => $value) |
|
113 | + { |
|
114 | + if ($value === null) |
|
115 | + { |
|
110 | 116 | $this->dispatcher->dispatch(new CacheMissed($key)); |
111 | - } else { |
|
117 | + } |
|
118 | + else |
|
119 | + { |
|
112 | 120 | // Replace default value with actual value in the resulting array |
113 | 121 | $array[$key] = $value; |
114 | 122 | $this->dispatcher->dispatch(new CacheHit($key, $value)); |
@@ -123,7 +131,8 @@ discard block |
||
123 | 131 | $dispatcher = $this->dispatcher; |
124 | 132 | $array = []; |
125 | 133 | // Resolve keys and dispatch events |
126 | - foreach ($values as $key => $value) { |
|
134 | + foreach ($values as $key => $value) |
|
135 | + { |
|
127 | 136 | $key = $this->resolveKey($key); |
128 | 137 | $dispatcher?->dispatch(new KeyWriting($key, $value)); |
129 | 138 | $array[$key] = $value; |
@@ -148,7 +157,8 @@ discard block |
||
148 | 157 | |
149 | 158 | $array = []; |
150 | 159 | // Resolve keys and dispatch events |
151 | - foreach ($keys as $key) { |
|
160 | + foreach ($keys as $key) |
|
161 | + { |
|
152 | 162 | $key = $this->resolveKey($key); |
153 | 163 | $dispatcher?->dispatch(new KeyDeleting($key)); |
154 | 164 | $array[] = $key; |