Skip to content

Commit 0de58d2

Browse files
committed
added PHP 7.0 scalar and return type hints
1 parent fd2713f commit 0de58d2

File tree

13 files changed

+70
-177
lines changed

13 files changed

+70
-177
lines changed

src/Bridges/CacheDI/CacheExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public function afterCompile(Nette\PhpGenerator\ClassType $class)
5454
}
5555

5656

57-
private function checkTempDir($dir)
57+
private function checkTempDir($dir): bool
5858
{
5959
@mkdir($dir); // @ - directory may exists
6060

src/Caching/Cache.php

Lines changed: 15 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -51,30 +51,27 @@ public function __construct(IStorage $storage, $namespace = NULL)
5151

5252
/**
5353
* Returns cache storage.
54-
* @return IStorage
5554
*/
56-
public function getStorage()
55+
public function getStorage(): IStorage
5756
{
5857
return $this->storage;
5958
}
6059

6160

6261
/**
6362
* Returns cache namespace.
64-
* @return string
6563
*/
66-
public function getNamespace()
64+
public function getNamespace(): string
6765
{
6866
return (string) substr($this->namespace, 0, -1);
6967
}
7068

7169

7270
/**
7371
* Returns new nested cache object.
74-
* @param string
7572
* @return static
7673
*/
77-
public function derive($namespace)
74+
public function derive(string $namespace)
7875
{
7976
$derived = new static($this->storage, $this->namespace . $namespace);
8077
return $derived;
@@ -84,10 +81,9 @@ public function derive($namespace)
8481
/**
8582
* Reads the specified item from the cache or generate it.
8683
* @param mixed
87-
* @param callable
8884
* @return mixed
8985
*/
90-
public function load($key, $fallback = NULL)
86+
public function load($key, callable $fallback = NULL)
9187
{
9288
$data = $this->storage->read($this->generateKey($key));
9389
if ($data === NULL && $fallback) {
@@ -101,11 +97,8 @@ public function load($key, $fallback = NULL)
10197

10298
/**
10399
* Reads multiple items from the cache.
104-
* @param array
105-
* @param callable
106-
* @return array
107100
*/
108-
public function bulkLoad(array $keys, $fallback = NULL)
101+
public function bulkLoad(array $keys, callable $fallback = NULL): array
109102
{
110103
if (count($keys) === 0) {
111104
return [];
@@ -187,7 +180,7 @@ public function save($key, $data, array $dependencies = NULL)
187180
}
188181

189182

190-
private function completeDependencies($dp)
183+
private function completeDependencies(?array $dp): array
191184
{
192185
// convert expire into relative amount of seconds
193186
if (isset($dp[self::EXPIRATION])) {
@@ -230,9 +223,8 @@ private function completeDependencies($dp)
230223
/**
231224
* Removes item from the cache.
232225
* @param mixed
233-
* @return void
234226
*/
235-
public function remove($key)
227+
public function remove($key): void
236228
{
237229
$this->save($key, NULL);
238230
}
@@ -244,9 +236,8 @@ public function remove($key)
244236
* - Cache::PRIORITY => (int) priority
245237
* - Cache::TAGS => (array) tags
246238
* - Cache::ALL => TRUE
247-
* @return void
248239
*/
249-
public function clean(array $conditions = NULL)
240+
public function clean(array $conditions = NULL): void
250241
{
251242
$conditions = (array) $conditions;
252243
if (isset($conditions[self::TAGS])) {
@@ -276,9 +267,8 @@ public function call($function)
276267
/**
277268
* Caches results of function/method calls.
278269
* @param mixed
279-
* @return \Closure
280270
*/
281-
public function wrap($function, array $dependencies = NULL)
271+
public function wrap($function, array $dependencies = NULL): \Closure
282272
{
283273
return function () use ($function, $dependencies) {
284274
$key = [$function, func_get_args()];
@@ -297,24 +287,22 @@ public function wrap($function, array $dependencies = NULL)
297287
/**
298288
* Starts the output cache.
299289
* @param mixed
300-
* @return OutputHelper|NULL
301290
*/
302-
public function start($key)
291+
public function start($key): ?OutputHelper
303292
{
304293
$data = $this->load($key);
305294
if ($data === NULL) {
306295
return new OutputHelper($this, $key);
307296
}
308297
echo $data;
298+
return NULL;
309299
}
310300

311301

312302
/**
313303
* Generates internal cache key.
314-
* @param mixed
315-
* @return string
316304
*/
317-
protected function generateKey($key)
305+
protected function generateKey($key): string
318306
{
319307
return $this->namespace . md5(is_scalar($key) ? (string) $key : serialize($key));
320308
}
@@ -325,10 +313,8 @@ protected function generateKey($key)
325313

326314
/**
327315
* Checks CALLBACKS dependencies.
328-
* @param array
329-
* @return bool
330316
*/
331-
public static function checkCallbacks($callbacks)
317+
public static function checkCallbacks(array $callbacks): bool
332318
{
333319
foreach ($callbacks as $callback) {
334320
if (!array_shift($callback)(...$callback)) {
@@ -341,23 +327,17 @@ public static function checkCallbacks($callbacks)
341327

342328
/**
343329
* Checks CONSTS dependency.
344-
* @param string
345-
* @param mixed
346-
* @return bool
347330
*/
348-
private static function checkConst($const, $value)
331+
private static function checkConst(string $const, $value): bool
349332
{
350333
return defined($const) && constant($const) === $value;
351334
}
352335

353336

354337
/**
355338
* Checks FILES dependency.
356-
* @param string
357-
* @param int|NULL
358-
* @return bool
359339
*/
360-
private static function checkFile($file, $time)
340+
private static function checkFile(string $file, ?int $time): bool
361341
{
362342
return @filemtime($file) == $time; // @ - stat may fail
363343
}

src/Caching/IBulkReader.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,8 @@ interface IBulkReader
1818

1919
/**
2020
* Reads from cache in bulk.
21-
* @param string
2221
* @return array key => value pairs, missing items are omitted
2322
*/
24-
function bulkRead(array $keys);
23+
function bulkRead(array $keys): array;
2524

2625
}

src/Caching/IStorage.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -18,38 +18,28 @@ interface IStorage
1818

1919
/**
2020
* Read from cache.
21-
* @param string
2221
* @return mixed
2322
*/
24-
function read($key);
23+
function read(string $key);
2524

2625
/**
2726
* Prevents item reading and writing. Lock is released by write() or remove().
28-
* @param string
29-
* @return void
3027
*/
31-
function lock($key);
28+
function lock(string $key): void;
3229

3330
/**
3431
* Writes item into the cache.
35-
* @param string
36-
* @param mixed
37-
* @return void
3832
*/
39-
function write($key, $data, array $dependencies);
33+
function write(string $key, $data, array $dependencies): void;
4034

4135
/**
4236
* Removes item from the cache.
43-
* @param string
44-
* @return void
4537
*/
46-
function remove($key);
38+
function remove(string $key): void;
4739

4840
/**
4941
* Removes items from the cache by conditions.
50-
* @param array conditions
51-
* @return void
5242
*/
53-
function clean(array $conditions);
43+
function clean(array $conditions): void;
5444

5545
}

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: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,51 +21,41 @@ class DevNullStorage implements Nette\Caching\IStorage
2121

2222
/**
2323
* Read from cache.
24-
* @param string
2524
* @return mixed
2625
*/
27-
public function read($key)
26+
public function read(string $key)
2827
{
2928
}
3029

3130

3231
/**
3332
* Prevents item reading and writing. Lock is released by write() or remove().
34-
* @param string
35-
* @return void
3633
*/
37-
public function lock($key)
34+
public function lock(string $key): void
3835
{
3936
}
4037

4138

4239
/**
4340
* Writes item into the cache.
44-
* @param string
45-
* @param mixed
46-
* @return void
4741
*/
48-
public function write($key, $data, array $dependencies)
42+
public function write(string $key, $data, array $dependencies): void
4943
{
5044
}
5145

5246

5347
/**
5448
* Removes item from the cache.
55-
* @param string
56-
* @return void
5749
*/
58-
public function remove($key)
50+
public function remove(string $key): void
5951
{
6052
}
6153

6254

6355
/**
6456
* Removes items from the cache by conditions & garbage collector.
65-
* @param array conditions
66-
* @return void
6757
*/
68-
public function clean(array $conditions)
58+
public function clean(array $conditions): void
6959
{
7060
}
7161

0 commit comments

Comments
 (0)