Skip to content

Commit 59da4eb

Browse files
committed
added PHP 7.1 scalar and return type hints
1 parent 845aaff commit 59da4eb

File tree

14 files changed

+75
-190
lines changed

14 files changed

+75
-190
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/Bridges/CacheLatte/CacheMacro.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,7 @@ public function nodeClosed(Latte\MacroNode $node)
7979
/********************* run-time helpers ****************d*g**/
8080

8181

82-
/**
83-
* @return void
84-
*/
85-
public static function initRuntime(Latte\Runtime\Template $template)
82+
public static function initRuntime(Latte\Runtime\Template $template): void
8683
{
8784
if (!empty($template->global->cacheStack)) {
8885
$file = (new \ReflectionClass($template))->getFileName();
@@ -95,13 +92,9 @@ public static function initRuntime(Latte\Runtime\Template $template)
9592

9693
/**
9794
* Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
98-
* @param Nette\Caching\IStorage
99-
* @param string
100-
* @param Nette\Caching\OutputHelper[]
101-
* @param array
10295
* @return Nette\Caching\OutputHelper|\stdClass
10396
*/
104-
public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &$parents, array $args = NULL)
97+
public static function createCache(Nette\Caching\IStorage $cacheStorage, string $key, ?array &$parents, array $args = NULL)
10598
{
10699
if ($args) {
107100
if (array_key_exists('if', $args) && !$args['if']) {
@@ -124,9 +117,8 @@ public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &
124117
/**
125118
* Ends the output cache.
126119
* @param Nette\Caching\OutputHelper[]
127-
* @return void
128120
*/
129-
public static function endCache(&$parents, array $args = NULL)
121+
public static function endCache(array &$parents, array $args = NULL): void
130122
{
131123
$helper = array_pop($parents);
132124
if ($helper instanceof Nette\Caching\OutputHelper) {

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 [];
@@ -192,7 +185,7 @@ public function save($key, $data, array $dependencies = NULL)
192185
}
193186

194187

195-
private function completeDependencies($dp)
188+
private function completeDependencies(?array $dp): array
196189
{
197190
// convert expire into relative amount of seconds
198191
if (isset($dp[self::EXPIRATION])) {
@@ -235,9 +228,8 @@ private function completeDependencies($dp)
235228
/**
236229
* Removes item from the cache.
237230
* @param mixed
238-
* @return void
239231
*/
240-
public function remove($key)
232+
public function remove($key): void
241233
{
242234
$this->save($key, NULL);
243235
}
@@ -249,9 +241,8 @@ public function remove($key)
249241
* - Cache::PRIORITY => (int) priority
250242
* - Cache::TAGS => (array) tags
251243
* - Cache::ALL => TRUE
252-
* @return void
253244
*/
254-
public function clean(array $conditions = NULL)
245+
public function clean(array $conditions = NULL): void
255246
{
256247
$conditions = (array) $conditions;
257248
if (isset($conditions[self::TAGS])) {
@@ -281,9 +272,8 @@ public function call($function)
281272
/**
282273
* Caches results of function/method calls.
283274
* @param mixed
284-
* @return \Closure
285275
*/
286-
public function wrap($function, array $dependencies = NULL)
276+
public function wrap($function, array $dependencies = NULL): \Closure
287277
{
288278
return function () use ($function, $dependencies) {
289279
$key = [$function, func_get_args()];
@@ -302,24 +292,22 @@ public function wrap($function, array $dependencies = NULL)
302292
/**
303293
* Starts the output cache.
304294
* @param mixed
305-
* @return OutputHelper|NULL
306295
*/
307-
public function start($key)
296+
public function start($key): ?OutputHelper
308297
{
309298
$data = $this->load($key);
310299
if ($data === NULL) {
311300
return new OutputHelper($this, $key);
312301
}
313302
echo $data;
303+
return NULL;
314304
}
315305

316306

317307
/**
318308
* Generates internal cache key.
319-
* @param mixed
320-
* @return string
321309
*/
322-
protected function generateKey($key)
310+
protected function generateKey($key): string
323311
{
324312
return $this->namespace . md5(is_scalar($key) ? (string) $key : serialize($key));
325313
}
@@ -330,10 +318,8 @@ protected function generateKey($key)
330318

331319
/**
332320
* Checks CALLBACKS dependencies.
333-
* @param array
334-
* @return bool
335321
*/
336-
public static function checkCallbacks($callbacks)
322+
public static function checkCallbacks(array $callbacks): bool
337323
{
338324
foreach ($callbacks as $callback) {
339325
if (!array_shift($callback)(...$callback)) {
@@ -346,23 +332,17 @@ public static function checkCallbacks($callbacks)
346332

347333
/**
348334
* Checks CONSTS dependency.
349-
* @param string
350-
* @param mixed
351-
* @return bool
352335
*/
353-
private static function checkConst($const, $value)
336+
private static function checkConst(string $const, $value): bool
354337
{
355338
return defined($const) && constant($const) === $value;
356339
}
357340

358341

359342
/**
360343
* Checks FILES dependency.
361-
* @param string
362-
* @param int|NULL
363-
* @return bool
364344
*/
365-
private static function checkFile($file, $time)
345+
private static function checkFile(string $file, ?int $time): bool
366346
{
367347
return @filemtime($file) == $time; // @ - stat may fail
368348
}

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)