Skip to content

Commit 647a17e

Browse files
committed
added PHP 8 typehints
1 parent 64934aa commit 647a17e

File tree

10 files changed

+19
-28
lines changed

10 files changed

+19
-28
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,13 @@ public static function initRuntime(Latte\Runtime\Template $template): void
101101

102102
/**
103103
* Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
104-
* @return Nette\Caching\OutputHelper|\stdClass
105104
*/
106105
public static function createCache(
107106
Nette\Caching\Storage $cacheStorage,
108107
string $key,
109108
?array &$parents,
110109
?array $args = null,
111-
) {
110+
): Nette\Caching\OutputHelper|\stdClass {
112111
if ($args) {
113112
if (array_key_exists('if', $args) && !$args['if']) {
114113
return $parents[] = new \stdClass;

src/Caching/Cache.php

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -68,20 +68,17 @@ final public function getNamespace(): string
6868

6969
/**
7070
* Returns new nested cache object.
71-
* @return static
7271
*/
73-
public function derive(string $namespace)
72+
public function derive(string $namespace): static
7473
{
7574
return new static($this->storage, $this->namespace . $namespace);
7675
}
7776

7877

7978
/**
8079
* Reads the specified item from the cache or generate it.
81-
* @param mixed $key
82-
* @return mixed
8380
*/
84-
public function load($key, ?callable $generator = null)
81+
public function load(mixed $key, ?callable $generator = null): mixed
8582
{
8683
$storageKey = $this->generateKey($key);
8784
$data = $this->storage->read($storageKey);
@@ -158,12 +155,10 @@ public function bulkLoad(array $keys, ?callable $generator = null): array
158155
* - Cache::ITEMS => (array|string) cache items
159156
* - Cache::CONSTS => (array|string) cache items
160157
*
161-
* @param mixed $key
162-
* @param mixed $data
163158
* @return mixed value itself
164159
* @throws Nette\InvalidArgumentException
165160
*/
166-
public function save($key, $data, ?array $dependencies = null)
161+
public function save(mixed $key, mixed $data, ?array $dependencies = null): mixed
167162
{
168163
$key = $this->generateKey($key);
169164

@@ -179,6 +174,7 @@ public function save($key, $data, ?array $dependencies = null)
179174

180175
if ($data === null) {
181176
$this->storage->remove($key);
177+
return null;
182178
} else {
183179
$dependencies = $this->completeDependencies($dependencies);
184180
if (isset($dependencies[self::EXPIRATION]) && $dependencies[self::EXPIRATION] <= 0) {
@@ -242,9 +238,8 @@ private function completeDependencies(?array $dp): array
242238

243239
/**
244240
* Removes item from the cache.
245-
* @param mixed $key
246241
*/
247-
public function remove($key): void
242+
public function remove(mixed $key): void
248243
{
249244
$this->save($key, null);
250245
}
@@ -270,9 +265,8 @@ public function clean(?array $conditions = null): void
270265

271266
/**
272267
* Caches results of function/method calls.
273-
* @return mixed
274268
*/
275-
public function call(callable $function)
269+
public function call(callable $function): mixed
276270
{
277271
$key = func_get_args();
278272
if (is_array($function) && is_object($function[0])) {
@@ -304,9 +298,8 @@ public function wrap(callable $function, ?array $dependencies = null): \Closure
304298

305299
/**
306300
* Starts the output cache.
307-
* @param mixed $key
308301
*/
309-
public function capture($key): ?OutputHelper
302+
public function capture(mixed $key): ?OutputHelper
310303
{
311304
$data = $this->load($key);
312305
if ($data === null) {

src/Caching/OutputHelper.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class OutputHelper
2626
private mixed $key;
2727

2828

29-
public function __construct(Cache $cache, $key)
29+
public function __construct(Cache $cache, mixed $key)
3030
{
3131
$this->cache = $cache;
3232
$this->key = $key;

src/Caching/Storage.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@ interface Storage
1717
{
1818
/**
1919
* Read from cache.
20-
* @return mixed
2120
*/
22-
function read(string $key);
21+
function read(string $key): mixed;
2322

2423
/**
2524
* Prevents item reading and writing. Lock is released by write() or remove().

src/Caching/Storages/DevNullStorage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ class DevNullStorage implements Nette\Caching\Storage
1919
{
2020
use Nette\SmartObject;
2121

22-
public function read(string $key)
22+
public function read(string $key): mixed
2323
{
24+
return null;
2425
}
2526

2627

src/Caching/Storages/FileStorage.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ public function __construct(string $dir, ?Journal $journal = null)
7575
}
7676

7777

78-
public function read(string $key)
78+
public function read(string $key): mixed
7979
{
8080
$meta = $this->readMetaAndLock($this->getCacheFile($key), LOCK_SH);
8181
return $meta && $this->verify($meta)
@@ -324,9 +324,8 @@ protected function readMetaAndLock(string $file, int $lock): ?array
324324

325325
/**
326326
* Reads cache data from disk and closes cache file handle.
327-
* @return mixed
328327
*/
329-
protected function readData(array $meta)
328+
protected function readData(array $meta): mixed
330329
{
331330
$data = stream_get_contents($meta[self::HANDLE]);
332331
flock($meta[self::HANDLE], LOCK_UN);

src/Caching/Storages/MemcachedStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ public function getConnection(): \Memcached
7676
}
7777

7878

79-
public function read(string $key)
79+
public function read(string $key): mixed
8080
{
8181
$key = urlencode($this->prefix . $key);
8282
$meta = $this->memcached->get($key);

src/Caching/Storages/MemoryStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class MemoryStorage implements Nette\Caching\Storage
2222
private array $data = [];
2323

2424

25-
public function read(string $key)
25+
public function read(string $key): mixed
2626
{
2727
return $this->data[$key] ?? null;
2828
}

src/Caching/Storages/SQLiteStorage.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public function __construct(string $path)
5151
}
5252

5353

54-
public function read(string $key)
54+
public function read(string $key): mixed
5555
{
5656
$stmt = $this->pdo->prepare('SELECT data, slide FROM cache WHERE key=? AND (expire IS NULL OR expire >= ?)');
5757
$stmt->execute([$key, time()]);
5858
if (!$row = $stmt->fetch(\PDO::FETCH_ASSOC)) {
59-
return;
59+
return null;
6060
}
6161

6262
if ($row['slide'] !== null) {

tests/Caching/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class TestStorage implements IStorage
1010
private array $data = [];
1111

1212

13-
public function read(string $key)
13+
public function read(string $key): mixed
1414
{
1515
return $this->data[$key] ?? null;
1616
}

0 commit comments

Comments
 (0)