Skip to content

Commit 4128656

Browse files
committed
used PHP 7.0 features
1 parent 51e2928 commit 4128656

File tree

5 files changed

+14
-14
lines changed

5 files changed

+14
-14
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -115,14 +115,14 @@ public static function createCache(Nette\Caching\IStorage $cacheStorage, $key, &
115115
$cache = new Cache($cacheStorage, 'Nette.Templating.Cache');
116116
if ($helper = $cache->start($key)) {
117117
if (isset($args['dependencies'])) {
118-
$args += call_user_func($args['dependencies']);
118+
$args += $args['dependencies']();
119119
}
120120
if (isset($args['expire'])) {
121121
$args['expiration'] = $args['expire']; // back compatibility
122122
}
123123
$helper->dependencies = [
124-
$cache::TAGS => isset($args['tags']) ? $args['tags'] : NULL,
125-
$cache::EXPIRATION => isset($args['expiration']) ? $args['expiration'] : '+ 7 days',
124+
$cache::TAGS => $args['tags'] ?? NULL,
125+
$cache::EXPIRATION => $args['expiration'] ?? '+ 7 days',
126126
];
127127
$parents[] = $helper;
128128
}

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;
@@ -331,7 +331,7 @@ protected function generateKey($key)
331331
public static function checkCallbacks($callbacks)
332332
{
333333
foreach ($callbacks as $callback) {
334-
if (!call_user_func_array(array_shift($callback), $callback)) {
334+
if (!array_shift($callback)(...$callback)) {
335335
return FALSE;
336336
}
337337
}

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

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)