Skip to content

Commit 7209dd7

Browse files
committed
added PHP 8 typehints
1 parent 82b622f commit 7209dd7

File tree

9 files changed

+20
-27
lines changed

9 files changed

+20
-27
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,14 +101,14 @@ 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|null
111+
{
112112
if ($args) {
113113
if (array_key_exists('if', $args) && !$args['if']) {
114114
return $parents[] = new \stdClass;
@@ -122,7 +122,7 @@ public static function createCache(
122122
}
123123

124124
$cache = new Cache($cacheStorage, 'Nette.Templating.Cache');
125-
if ($helper = $cache->start($key)) {
125+
if ($helper = $cache->capture($key)) {
126126
$parents[] = $helper;
127127
}
128128

src/Caching/Cache.php

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

8282
/**
8383
* Returns new nested cache object.
84-
* @return static
8584
*/
86-
public function derive(string $namespace)
85+
public function derive(string $namespace): static
8786
{
8887
return new static($this->storage, $this->namespace . $namespace);
8988
}
9089

9190

9291
/**
9392
* Reads the specified item from the cache or generate it.
94-
* @param mixed $key
95-
* @return mixed
9693
*/
97-
public function load($key, ?callable $generator = null)
94+
public function load(mixed $key, ?callable $generator = null): mixed
9895
{
9996
$storageKey = $this->generateKey($key);
10097
$data = $this->storage->read($storageKey);
@@ -170,12 +167,10 @@ public function bulkLoad(array $keys, ?callable $generator = null): array
170167
* - Cache::Files => (array|string) file names
171168
* - Cache::Items => (array|string) cache items
172169
* - Cache::Constants => (array|string) cache items
173-
* @param mixed $key
174-
* @param mixed $data
175170
* @return mixed value itself
176171
* @throws Nette\InvalidArgumentException
177172
*/
178-
public function save($key, $data, ?array $dependencies = null)
173+
public function save(mixed $key, mixed $data, ?array $dependencies = null): mixed
179174
{
180175
$key = $this->generateKey($key);
181176

@@ -191,6 +186,7 @@ public function save($key, $data, ?array $dependencies = null)
191186

192187
if ($data === null) {
193188
$this->storage->remove($key);
189+
return null;
194190
} else {
195191
$dependencies = $this->completeDependencies($dependencies);
196192
if (isset($dependencies[self::Expire]) && $dependencies[self::Expire] <= 0) {
@@ -254,9 +250,8 @@ private function completeDependencies(?array $dp): array
254250

255251
/**
256252
* Removes item from the cache.
257-
* @param mixed $key
258253
*/
259-
public function remove($key): void
254+
public function remove(mixed $key): void
260255
{
261256
$this->save($key, null);
262257
}
@@ -282,9 +277,8 @@ public function clean(?array $conditions = null): void
282277

283278
/**
284279
* Caches results of function/method calls.
285-
* @return mixed
286280
*/
287-
public function call(callable $function)
281+
public function call(callable $function): mixed
288282
{
289283
$key = func_get_args();
290284
if (is_array($function) && is_object($function[0])) {
@@ -316,9 +310,8 @@ public function wrap(callable $function, ?array $dependencies = null): \Closure
316310

317311
/**
318312
* Starts the output cache.
319-
* @param mixed $key
320313
*/
321-
public function capture($key): ?OutputHelper
314+
public function capture(mixed $key): ?OutputHelper
322315
{
323316
$data = $this->load($key);
324317
if ($data === null) {

src/Caching/OutputHelper.php

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

2626

27-
public function __construct(Cache $cache, $key)
27+
public function __construct(Cache $cache, mixed $key)
2828
{
2929
$this->cache = $cache;
3030
$this->key = $key;

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
@@ -72,7 +72,7 @@ public function __construct(string $dir, ?Journal $journal = null)
7272
}
7373

7474

75-
public function read(string $key)
75+
public function read(string $key): mixed
7676
{
7777
$meta = $this->readMetaAndLock($this->getCacheFile($key), LOCK_SH);
7878
return $meta && $this->verify($meta)
@@ -321,9 +321,8 @@ protected function readMetaAndLock(string $file, int $lock): ?array
321321

322322
/**
323323
* Reads cache data from disk and closes cache file handle.
324-
* @return mixed
325324
*/
326-
protected function readData(array $meta)
325+
protected function readData(array $meta): mixed
327326
{
328327
$data = stream_get_contents($meta[self::Handle]);
329328
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
@@ -74,7 +74,7 @@ public function getConnection(): \Memcached
7474
}
7575

7676

77-
public function read(string $key)
77+
public function read(string $key): mixed
7878
{
7979
$key = urlencode($this->prefix . $key);
8080
$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)