Skip to content

Commit 30d955d

Browse files
committed
added PHP 7.1 return type hints
1 parent 6edb742 commit 30d955d

File tree

9 files changed

+30
-55
lines changed

9 files changed

+30
-55
lines changed

src/Caching/Cache.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,8 @@ private function completeDependencies($dp)
223223
/**
224224
* Removes item from the cache.
225225
* @param mixed
226-
* @return void
227226
*/
228-
public function remove($key)
227+
public function remove($key): void
229228
{
230229
$this->save($key, NULL);
231230
}
@@ -237,9 +236,8 @@ public function remove($key)
237236
* - Cache::PRIORITY => (int) priority
238237
* - Cache::TAGS => (array) tags
239238
* - Cache::ALL => TRUE
240-
* @return void
241239
*/
242-
public function clean(array $conditions = NULL)
240+
public function clean(array $conditions = NULL): void
243241
{
244242
$conditions = (array) $conditions;
245243
if (isset($conditions[self::TAGS])) {
@@ -289,15 +287,15 @@ public function wrap($function, array $dependencies = NULL): \Closure
289287
/**
290288
* Starts the output cache.
291289
* @param mixed
292-
* @return OutputHelper|NULL
293290
*/
294-
public function start($key)
291+
public function start($key): ?OutputHelper
295292
{
296293
$data = $this->load($key);
297294
if ($data === NULL) {
298295
return new OutputHelper($this, $key);
299296
}
300297
echo $data;
298+
return NULL;
301299
}
302300

303301

src/Caching/OutputHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,8 @@ public function __construct(Cache $cache, $key)
3939

4040
/**
4141
* Stops and saves the cache.
42-
* @return void
4342
*/
44-
public function end(array $dependencies = NULL)
43+
public function end(array $dependencies = NULL): void
4544
{
4645
if ($this->cache === NULL) {
4746
throw new Nette\InvalidStateException('Output cache has already been saved.');

src/Caching/Storages/DevNullStorage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,36 +30,32 @@ public function read(string $key)
3030

3131
/**
3232
* Prevents item reading and writing. Lock is released by write() or remove().
33-
* @return void
3433
*/
35-
public function lock(string $key)
34+
public function lock(string $key): void
3635
{
3736
}
3837

3938

4039
/**
4140
* Writes item into the cache.
42-
* @return void
4341
*/
44-
public function write(string $key, $data, array $dependencies)
42+
public function write(string $key, $data, array $dependencies): void
4543
{
4644
}
4745

4846

4947
/**
5048
* Removes item from the cache.
51-
* @return void
5249
*/
53-
public function remove(string $key)
50+
public function remove(string $key): void
5451
{
5552
}
5653

5754

5855
/**
5956
* Removes items from the cache by conditions & garbage collector.
60-
* @return void
6157
*/
62-
public function clean(array $conditions)
58+
public function clean(array $conditions): void
6359
{
6460
}
6561

src/Caching/Storages/FileStorage.php

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,8 @@ private function verify(array $meta): bool
137137

138138
/**
139139
* Prevents item reading and writing. Lock is released by write() or remove().
140-
* @return void
141140
*/
142-
public function lock(string $key)
141+
public function lock(string $key): void
143142
{
144143
$cacheFile = $this->getCacheFile($key);
145144
if ($this->useDirs && !is_dir($dir = dirname($cacheFile))) {
@@ -155,9 +154,8 @@ public function lock(string $key)
155154

156155
/**
157156
* Writes item into the cache.
158-
* @return void
159157
*/
160-
public function write(string $key, $data, array $dp)
158+
public function write(string $key, $data, array $dp): void
161159
{
162160
$meta = [
163161
self::META_TIME => microtime(),
@@ -238,9 +236,8 @@ public function write(string $key, $data, array $dp)
238236

239237
/**
240238
* Removes item from the cache.
241-
* @return void
242239
*/
243-
public function remove(string $key)
240+
public function remove(string $key): void
244241
{
245242
unset($this->locks[$key]);
246243
$this->delete($this->getCacheFile($key));
@@ -249,9 +246,8 @@ public function remove(string $key)
249246

250247
/**
251248
* Removes items from the cache by conditions & garbage collector.
252-
* @return void
253249
*/
254-
public function clean(array $conditions)
250+
public function clean(array $conditions): void
255251
{
256252
$all = !empty($conditions[Cache::ALL]);
257253
$collector = empty($conditions);
@@ -305,9 +301,8 @@ public function clean(array $conditions)
305301
* Reads cache data from disk.
306302
* @param string file path
307303
* @param int lock mode
308-
* @return array|NULL
309304
*/
310-
protected function readMetaAndLock(string $file, int $lock)
305+
protected function readMetaAndLock(string $file, int $lock): ?array
311306
{
312307
$handle = @fopen($file, 'r+b'); // @ - file may not exist
313308
if (!$handle) {
@@ -366,9 +361,8 @@ protected function getCacheFile(string $key): string
366361
/**
367362
* Deletes and closes file.
368363
* @param resource $handle
369-
* @return void
370364
*/
371-
private static function delete(string $file, $handle = NULL)
365+
private static function delete(string $file, $handle = NULL): void
372366
{
373367
if (@unlink($file)) { // @ - file may not already exist
374368
if ($handle) {

src/Caching/Storages/IJournal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ function write(string $key, array $dependencies);
2727
* Cleans entries from journal.
2828
* @return array|NULL of removed items or NULL when performing a full cleanup
2929
*/
30-
function clean(array $conditions);
30+
function clean(array $conditions): ?array;
3131

3232
}

src/Caching/Storages/MemoryStorage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,38 +35,34 @@ public function read(string $key)
3535

3636
/**
3737
* Prevents item reading and writing. Lock is released by write() or remove().
38-
* @return void
3938
*/
40-
public function lock(string $key)
39+
public function lock(string $key): void
4140
{
4241
}
4342

4443

4544
/**
4645
* Writes item into the cache.
47-
* @return void
4846
*/
49-
public function write(string $key, $data, array $dependencies)
47+
public function write(string $key, $data, array $dependencies): void
5048
{
5149
$this->data[$key] = $data;
5250
}
5351

5452

5553
/**
5654
* Removes item from the cache.
57-
* @return void
5855
*/
59-
public function remove(string $key)
56+
public function remove(string $key): void
6057
{
6158
unset($this->data[$key]);
6259
}
6360

6461

6562
/**
6663
* Removes items from the cache by conditions & garbage collector.
67-
* @return void
6864
*/
69-
public function clean(array $conditions)
65+
public function clean(array $conditions): void
7066
{
7167
if (!empty($conditions[Nette\Caching\Cache::ALL])) {
7268
$this->data = [];

src/Caching/Storages/NewMemcachedStorage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -141,18 +141,16 @@ public function bulkRead(array $keys): array
141141

142142
/**
143143
* Prevents item reading and writing. Lock is released by write() or remove().
144-
* @return void
145144
*/
146-
public function lock(string $key)
145+
public function lock(string $key): void
147146
{
148147
}
149148

150149

151150
/**
152151
* Writes item into the cache.
153-
* @return void
154152
*/
155-
public function write(string $key, $data, array $dp)
153+
public function write(string $key, $data, array $dp): void
156154
{
157155
if (isset($dp[Cache::ITEMS])) {
158156
throw new Nette\NotSupportedException('Dependent items are not supported by MemcachedStorage.');
@@ -188,19 +186,17 @@ public function write(string $key, $data, array $dp)
188186

189187
/**
190188
* Removes item from the cache.
191-
* @return void
192189
*/
193-
public function remove(string $key)
190+
public function remove(string $key): void
194191
{
195192
$this->memcached->delete(urlencode($this->prefix . $key), 0);
196193
}
197194

198195

199196
/**
200197
* Removes items from the cache by conditions & garbage collector.
201-
* @return void
202198
*/
203-
public function clean(array $conditions)
199+
public function clean(array $conditions): void
204200
{
205201
if (!empty($conditions[Cache::ALL])) {
206202
$this->memcached->flush();

src/Caching/Storages/SQLiteJournal.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private function open()
6767
/**
6868
* Writes entry information into the journal.
6969
*/
70-
public function write(string $key, array $dependencies)
70+
public function write(string $key, array $dependencies): void
7171
{
7272
if (!$this->pdo) {
7373
$this->open();
@@ -98,7 +98,7 @@ public function write(string $key, array $dependencies)
9898
* Cleans entries from journal.
9999
* @return array|NULL removed items or NULL when performing a full cleanup
100100
*/
101-
public function clean(array $conditions)
101+
public function clean(array $conditions): ?array
102102
{
103103
if (!$this->pdo) {
104104
$this->open();

src/Caching/Storages/SQLiteStorage.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -95,18 +95,16 @@ public function bulkRead(array $keys): array
9595

9696
/**
9797
* Prevents item reading and writing. Lock is released by write() or remove().
98-
* @return void
9998
*/
100-
public function lock(string $key)
99+
public function lock(string $key): void
101100
{
102101
}
103102

104103

105104
/**
106105
* Writes item into the cache.
107-
* @return void
108106
*/
109-
public function write(string $key, $data, array $dependencies)
107+
public function write(string $key, $data, array $dependencies): void
110108
{
111109
$expire = isset($dependencies[Cache::EXPIRATION]) ? $dependencies[Cache::EXPIRATION] + time() : NULL;
112110
$slide = isset($dependencies[Cache::SLIDING]) ? $dependencies[Cache::EXPIRATION] : NULL;
@@ -129,9 +127,8 @@ public function write(string $key, $data, array $dependencies)
129127

130128
/**
131129
* Removes item from the cache.
132-
* @return void
133130
*/
134-
public function remove(string $key)
131+
public function remove(string $key): void
135132
{
136133
$this->pdo->prepare('DELETE FROM cache WHERE key=?')
137134
->execute([$key]);
@@ -140,9 +137,8 @@ public function remove(string $key)
140137

141138
/**
142139
* Removes items from the cache by conditions & garbage collector.
143-
* @return void
144140
*/
145-
public function clean(array $conditions)
141+
public function clean(array $conditions): void
146142
{
147143
if (!empty($conditions[Cache::ALL])) {
148144
$this->pdo->prepare('DELETE FROM cache')->execute();

0 commit comments

Comments
 (0)