Skip to content

Commit 1481749

Browse files
committed
added PHP 8 typehints
1 parent dbf7b1d commit 1481749

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
@@ -100,14 +100,13 @@ public static function initRuntime(Latte\Runtime\Template $template): void
100100

101101
/**
102102
* Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
103-
* @return Nette\Caching\OutputHelper|\stdClass
104103
*/
105104
public static function createCache(
106105
Nette\Caching\Storage $cacheStorage,
107106
string $key,
108107
?array &$parents,
109108
array $args = null,
110-
) {
109+
): Nette\Caching\OutputHelper|\stdClass {
111110
if ($args) {
112111
if (array_key_exists('if', $args) && !$args['if']) {
113112
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);
@@ -153,12 +150,10 @@ public function bulkLoad(array $keys, callable $generator = null): array
153150
* - Cache::ITEMS => (array|string) cache items
154151
* - Cache::CONSTS => (array|string) cache items
155152
*
156-
* @param mixed $key
157-
* @param mixed $data
158153
* @return mixed value itself
159154
* @throws Nette\InvalidArgumentException
160155
*/
161-
public function save($key, $data, array $dependencies = null)
156+
public function save(mixed $key, mixed $data, array $dependencies = null): mixed
162157
{
163158
$key = $this->generateKey($key);
164159

@@ -174,6 +169,7 @@ public function save($key, $data, array $dependencies = null)
174169

175170
if ($data === null) {
176171
$this->storage->remove($key);
172+
return null;
177173
} else {
178174
$dependencies = $this->completeDependencies($dependencies);
179175
if (isset($dependencies[self::EXPIRATION]) && $dependencies[self::EXPIRATION] <= 0) {
@@ -233,9 +229,8 @@ private function completeDependencies(?array $dp): array
233229

234230
/**
235231
* Removes item from the cache.
236-
* @param mixed $key
237232
*/
238-
public function remove($key): void
233+
public function remove(mixed $key): void
239234
{
240235
$this->save($key, null);
241236
}
@@ -260,9 +255,8 @@ public function clean(array $conditions = null): void
260255

261256
/**
262257
* Caches results of function/method calls.
263-
* @return mixed
264258
*/
265-
public function call(callable $function)
259+
public function call(callable $function): mixed
266260
{
267261
$key = func_get_args();
268262
if (is_array($function) && is_object($function[0])) {
@@ -292,9 +286,8 @@ public function wrap(callable $function, array $dependencies = null): \Closure
292286

293287
/**
294288
* Starts the output cache.
295-
* @param mixed $key
296289
*/
297-
public function capture($key): ?OutputHelper
290+
public function capture(mixed $key): ?OutputHelper
298291
{
299292
$data = $this->load($key);
300293
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)
@@ -317,9 +317,8 @@ protected function readMetaAndLock(string $file, int $lock): ?array
317317

318318
/**
319319
* Reads cache data from disk and closes cache file handle.
320-
* @return mixed
321320
*/
322-
protected function readData(array $meta)
321+
protected function readData(array $meta): mixed
323322
{
324323
$data = stream_get_contents($meta[self::HANDLE]);
325324
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)