Skip to content

Commit b06f7b4

Browse files
committed
used PHP 7.1 features
1 parent 6b87c62 commit b06f7b4

File tree

7 files changed

+20
-17
lines changed

7 files changed

+20
-17
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,13 @@ public static function endCache(&$parents, array $args = NULL)
131131
$helper = array_pop($parents);
132132
if ($helper instanceof Nette\Caching\OutputHelper) {
133133
if (isset($args['dependencies'])) {
134-
$args += call_user_func($args['dependencies']);
134+
$args += $args['dependencies']();
135135
}
136136
if (isset($args['expire'])) {
137137
$args['expiration'] = $args['expire']; // back compatibility
138138
}
139-
$helper->dependencies[Cache::TAGS] = isset($args['tags']) ? $args['tags'] : NULL;
140-
$helper->dependencies[Cache::EXPIRATION] = isset($args['expiration']) ? $args['expiration'] : '+ 7 days';
139+
$helper->dependencies[Cache::TAGS] = $args['tags'] ?? NULL;
140+
$helper->dependencies[Cache::EXPIRATION] = $args['expiration'] ?? '+ 7 days';
141141
$helper->end();
142142
}
143143
}

src/Caching/Cache.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function load($key, $fallback = NULL)
9292
$data = $this->storage->read($this->generateKey($key));
9393
if ($data === NULL && $fallback) {
9494
return $this->save($key, function (&$dependencies) use ($fallback) {
95-
return call_user_func_array($fallback, [&$dependencies]);
95+
return $fallback(...[&$dependencies]);
9696
});
9797
}
9898
return $data;
@@ -122,7 +122,7 @@ public function bulkLoad(array $keys, $fallback = NULL)
122122
foreach ($result as $key => $value) {
123123
if ($value === NULL) {
124124
$result[$key] = $this->save($key, function (&$dependencies) use ($key, $fallback) {
125-
return call_user_func_array($fallback, [$key, &$dependencies]);
125+
return $fallback(...[$key, &$dependencies]);
126126
});
127127
}
128128
}
@@ -138,7 +138,7 @@ public function bulkLoad(array $keys, $fallback = NULL)
138138
$result[$key] = $cacheData[$storageKey];
139139
} elseif ($fallback) {
140140
$result[$key] = $this->save($key, function (&$dependencies) use ($key, $fallback) {
141-
return call_user_func_array($fallback, [$key, &$dependencies]);
141+
return $fallback(...[$key, &$dependencies]);
142142
});
143143
} else {
144144
$result[$key] = NULL;
@@ -171,7 +171,7 @@ public function save($key, $data, array $dependencies = NULL)
171171
if ($data instanceof \Closure) {
172172
$this->storage->lock($key);
173173
try {
174-
$data = call_user_func_array($data, [&$dependencies]);
174+
$data = $data(...[&$dependencies]);
175175
} catch (\Throwable $e) {
176176
$this->storage->remove($key);
177177
throw $e;
@@ -336,7 +336,7 @@ protected function generateKey($key)
336336
public static function checkCallbacks($callbacks)
337337
{
338338
foreach ($callbacks as $callback) {
339-
if (!call_user_func_array(array_shift($callback), $callback)) {
339+
if (!array_shift($callback)(...$callback)) {
340340
return FALSE;
341341
}
342342
}

src/Caching/Storages/FileStorage.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ class FileStorage implements Nette\Caching\IStorage
3232
*/
3333

3434
/** @internal cache file structure */
35-
const META_HEADER_LEN = 28, // 22b signature + 6b meta-struct size + serialized meta-struct + data
35+
private const
36+
META_HEADER_LEN = 28, // 22b signature + 6b meta-struct size + serialized meta-struct + data
3637
// meta structure: array of
3738
META_TIME = 'time', // timestamp
3839
META_SERIALIZED = 'serialized', // is content serialized?
@@ -42,7 +43,8 @@ class FileStorage implements Nette\Caching\IStorage
4243
META_CALLBACKS = 'callbacks'; // array of callbacks (function, args)
4344

4445
/** additional cache structure */
45-
const FILE = 'file',
46+
private const
47+
FILE = 'file',
4648
HANDLE = 'handle';
4749

4850

src/Caching/Storages/MemoryStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class MemoryStorage implements Nette\Caching\IStorage
3030
*/
3131
public function read($key)
3232
{
33-
return isset($this->data[$key]) ? $this->data[$key] : NULL;
33+
return $this->data[$key] ?? NULL;
3434
}
3535

3636

src/Caching/Storages/NewMemcachedStorage.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ class NewMemcachedStorage implements Nette\Caching\IStorage, Nette\Caching\IBulk
2121
use Nette\SmartObject;
2222

2323
/** @internal cache structure */
24-
const META_CALLBACKS = 'callbacks',
24+
private const
25+
META_CALLBACKS = 'callbacks',
2526
META_DATA = 'data',
2627
META_DELTA = 'delta';
2728

tests/Caching/Cache.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestStorage implements IStorage
1111

1212
public function read($key)
1313
{
14-
return isset($this->data[$key]) ? $this->data[$key] : NULL;
14+
return $this->data[$key] ?? NULL;
1515
}
1616

1717
public function write($key, $data, array $dependencies)

tests/Storages/FileStorage.wrap.phpt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ class Test
3333
$cache = new Cache(new FileStorage(TEMP_DIR));
3434

3535
$called = FALSE;
36-
Assert::same(55, call_user_func($cache->wrap('mockFunction'), 5, 50));
36+
Assert::same(55, $cache->wrap('mockFunction')(5, 50));
3737
Assert::true($called);
3838

3939
$called = FALSE;
40-
Assert::same(55, call_user_func($cache->wrap('mockFunction'), 5, 50));
40+
Assert::same(55, $cache->wrap('mockFunction')(5, 50));
4141
Assert::false($called);
4242

4343

4444
$called = FALSE;
4545
$callback = [new Test, 'mockMethod'];
46-
Assert::same(55, call_user_func($cache->wrap($callback), 5, 50));
46+
Assert::same(55, $cache->wrap($callback)(5, 50));
4747
Assert::true($called);
4848

4949
$called = FALSE;
50-
Assert::same(55, call_user_func($cache->wrap($callback), 5, 50));
50+
Assert::same(55, $cache->wrap($callback)(5, 50));
5151
Assert::false($called);

0 commit comments

Comments
 (0)