Skip to content

Commit e6fcf78

Browse files
committed
coding style
1 parent dea9ae7 commit e6fcf78

File tree

12 files changed

+35
-73
lines changed

12 files changed

+35
-73
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ public function nodeOpened(Latte\MacroNode $node)
6363
->write(
6464
'<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) /* line %var */ try { ?>',
6565
Nette\Utils\Random::generate(),
66-
$node->startLine
66+
$node->startLine,
6767
);
6868
}
6969

@@ -81,7 +81,7 @@ public function nodeClosed(Latte\MacroNode $node)
8181
} catch (\Throwable $ʟ_e) {
8282
Nette\Bridges\CacheLatte\CacheMacro::rollback($this->global->cacheStack); throw $ʟ_e;
8383
} ?>',
84-
$node->startLine
84+
$node->startLine,
8585
);
8686
}
8787

@@ -108,7 +108,7 @@ public static function createCache(
108108
Nette\Caching\Storage $cacheStorage,
109109
string $key,
110110
?array &$parents,
111-
?array $args = null
111+
?array $args = null,
112112
) {
113113
if ($args) {
114114
if (array_key_exists('if', $args) && !$args['if']) {

src/Caching/Cache.php

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,10 +138,8 @@ public function bulkLoad(array $keys, ?callable $generator = null): array
138138
$result[$key] = $this->load(
139139
$key,
140140
$generator
141-
? function (&$dependencies) use ($key, $generator) {
142-
return $generator(...[$key, &$dependencies]);
143-
}
144-
: null
141+
? fn(&$dependencies) => $generator(...[$key, &$dependencies])
142+
: null,
145143
);
146144
}
147145

@@ -155,9 +153,7 @@ public function bulkLoad(array $keys, ?callable $generator = null): array
155153
if (isset($cacheData[$storageKey])) {
156154
$result[$key] = $cacheData[$storageKey];
157155
} elseif ($generator) {
158-
$result[$key] = $this->load($key, function (&$dependencies) use ($key, $generator) {
159-
return $generator(...[$key, &$dependencies]);
160-
});
156+
$result[$key] = $this->load($key, fn(&$dependencies) => $generator(...[$key, &$dependencies]));
161157
} else {
162158
$result[$key] = null;
163159
}
@@ -298,9 +294,7 @@ public function call(callable $function)
298294
$key[0][0] = get_class($function[0]);
299295
}
300296

301-
return $this->load($key, function () use ($function, $key) {
302-
return $function(...array_slice($key, 1));
303-
});
297+
return $this->load($key, fn() => $function(...array_slice($key, 1)));
304298
}
305299

306300

src/Caching/Storages/MemcachedStorage.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ public function __construct(
4949
string $host = 'localhost',
5050
int $port = 11211,
5151
string $prefix = '',
52-
?Journal $journal = null
52+
?Journal $journal = null,
5353
) {
5454
if (!static::isAvailable()) {
5555
throw new Nette\NotSupportedException("PHP extension 'memcached' is not loaded.");
@@ -110,9 +110,7 @@ public function read(string $key)
110110

111111
public function bulkRead(array $keys): array
112112
{
113-
$prefixedKeys = array_map(function ($key) {
114-
return urlencode($this->prefix . $key);
115-
}, $keys);
113+
$prefixedKeys = array_map(fn($key) => urlencode($this->prefix . $key), $keys);
116114
$keys = array_combine($prefixedKeys, $keys);
117115
$metas = $this->memcached->getMulti($prefixedKeys);
118116
$result = [];

tests/Bridges.Latte2/CacheMacro.cache.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,23 @@ $params['id'] = 456;
2626

2727
Assert::matchFile(
2828
__DIR__ . '/expected/CacheMacro.cache.php',
29-
$latte->compile(__DIR__ . '/templates/cache.latte')
29+
$latte->compile(__DIR__ . '/templates/cache.latte'),
3030
);
3131
Assert::matchFile(
3232
__DIR__ . '/expected/CacheMacro.cache.html',
3333
$latte->renderToString(
3434
__DIR__ . '/templates/cache.latte',
35-
$params
36-
)
35+
$params,
36+
),
3737
);
3838
Assert::matchFile(
3939
__DIR__ . '/expected/CacheMacro.cache.html',
4040
$latte->renderToString(
4141
__DIR__ . '/templates/cache.latte',
42-
$params
43-
)
42+
$params,
43+
),
4444
);
4545
Assert::matchFile(
4646
__DIR__ . '/expected/CacheMacro.cache.inc.php',
47-
file_get_contents($latte->getCacheFile(__DIR__ . strtr('/templates/include.cache.latte', '/', DIRECTORY_SEPARATOR)))
47+
file_get_contents($latte->getCacheFile(__DIR__ . strtr('/templates/include.cache.latte', '/', DIRECTORY_SEPARATOR))),
4848
);

tests/Bridges.Latte2/CacheMacro.createCache.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,7 @@ test('', function () {
3030
test('', function () {
3131
$parents = [];
3232
$dp = [Cache::Tags => ['rum', 'cola']];
33-
$dpFallback = function () use ($dp) {
34-
return $dp;
35-
};
33+
$dpFallback = fn() => $dp;
3634
$outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents);
3735
CacheMacro::endCache($parents, ['dependencies' => $dpFallback]);
3836
Assert::same($dp + [Cache::Expire => '+ 7 days'], $outputHelper->dependencies);
@@ -44,9 +42,7 @@ test('', function () {
4442
Cache::Tags => ['rum', 'cola'],
4543
Cache::Expire => '+ 1 days',
4644
];
47-
$dpFallback = function () use ($dp) {
48-
return $dp;
49-
};
45+
$dpFallback = fn() => $dp;
5046
$outputHelper = CacheMacro::createCache(new DevNullStorage, 'test', $parents);
5147
CacheMacro::endCache($parents, ['dependencies' => $dpFallback]);
5248
Assert::same($dp, $outputHelper->dependencies);

tests/Bridges.Latte3/CacheNode.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ test('', function () {
2626
test('', function () {
2727
$parents = [];
2828
$dp = [Cache::Tags => ['rum', 'cola']];
29-
$dpFallback = function () use ($dp) {
30-
return $dp;
31-
};
29+
$dpFallback = fn() => $dp;
3230
$outputHelper = CacheNode::createCache(new DevNullStorage, 'test', $parents, ['dependencies' => $dpFallback]);
3331
CacheNode::endCache($parents);
3432
Assert::same($dp + [Cache::Expire => '+ 7 days'], $outputHelper->dependencies);
@@ -40,9 +38,7 @@ test('', function () {
4038
Cache::Tags => ['rum', 'cola'],
4139
Cache::Expire => '+ 1 days',
4240
];
43-
$dpFallback = function () use ($dp) {
44-
return $dp;
45-
};
41+
$dpFallback = fn() => $dp;
4642
$outputHelper = CacheNode::createCache(new DevNullStorage, 'test', $parents, ['dependencies' => $dpFallback]);
4743
CacheNode::endCache($parents);
4844
Assert::same($dp, $outputHelper->dependencies);

tests/Bridges.Latte3/{cache}.phpt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@ $params['id'] = 456;
2525

2626
Assert::matchFile(
2727
__DIR__ . '/expected/cache.php',
28-
$latte->compile(__DIR__ . '/templates/cache.latte')
28+
$latte->compile(__DIR__ . '/templates/cache.latte'),
2929
);
3030
Assert::matchFile(
3131
__DIR__ . '/expected/cache.html',
3232
$latte->renderToString(
3333
__DIR__ . '/templates/cache.latte',
34-
$params
35-
)
34+
$params,
35+
),
3636
);
3737
Assert::matchFile(
3838
__DIR__ . '/expected/cache.html',
3939
$latte->renderToString(
4040
__DIR__ . '/templates/cache.latte',
41-
$params
42-
)
41+
$params,
42+
),
4343
);
4444
Assert::matchFile(
4545
__DIR__ . '/expected/cache.inc.php',
46-
file_get_contents($latte->getCacheFile(__DIR__ . strtr('/templates/include.cache.latte', '/', DIRECTORY_SEPARATOR)))
46+
file_get_contents($latte->getCacheFile(__DIR__ . strtr('/templates/include.cache.latte', '/', DIRECTORY_SEPARATOR))),
4747
);

tests/Caching/Cache.bulkLoad.phpt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ test('storage without bulk load support', function () {
1919
$cache = new Cache($storage, 'ns');
2020
Assert::same([1 => null, 2 => null], $cache->bulkLoad([1, 2]), 'data');
2121

22-
Assert::same([1 => 1, 2 => 2], $cache->bulkLoad([1, 2], function ($key) {
23-
return $key;
24-
}));
22+
Assert::same([1 => 1, 2 => 2], $cache->bulkLoad([1, 2], fn($key) => $key));
2523

2624
$data = $cache->bulkLoad([1, 2]);
2725
Assert::same(1, $data[1]['data']);
@@ -33,9 +31,7 @@ test('storage with bulk load support', function () {
3331
$cache = new Cache($storage, 'ns');
3432
Assert::same([1 => null, 2 => null], $cache->bulkLoad([1, 2]));
3533

36-
Assert::same([1 => 1, 2 => 2], $cache->bulkLoad([1, 2], function ($key) {
37-
return $key;
38-
}));
34+
Assert::same([1 => 1, 2 => 2], $cache->bulkLoad([1, 2], fn($key) => $key));
3935

4036
$data = $cache->bulkLoad([1, 2]);
4137
Assert::same(1, $data[1]['data']);

tests/Caching/Cache.load.phpt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,10 @@ require __DIR__ . '/Cache.php';
1919
$storage = new TestStorage;
2020
$cache = new Cache($storage, 'ns');
2121

22-
$value = $cache->load('key', function () {
23-
return 'value';
24-
});
22+
$value = $cache->load('key', fn() => 'value');
2523
Assert::same('value', $value);
2624

27-
$data = $cache->load('key', function () {
28-
return "won't load this value"; // will read from storage
29-
});
25+
$data = $cache->load('key', fn() => "won't load this value");
3026
Assert::same('value', $data['data']);
3127

3228

@@ -41,9 +37,7 @@ $value = $cache->load('key', function (&$deps) use ($dependencies) {
4137
});
4238
Assert::same('value', $value);
4339

44-
$data = $cache->load('key', function () {
45-
return "won't load this value"; // will read from storage
46-
});
40+
$data = $cache->load('key', fn() => "won't load this value");
4741
Assert::same('value', $data['data']);
4842
Assert::same($dependencies, $data['dependencies']);
4943

tests/Caching/Cache.save.phpt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ Assert::same($dependencies, $res['dependencies']);
3131
$storage = new testStorage;
3232
$cache = new Cache($storage, 'ns');
3333

34-
$cache->save('key', function () {
35-
return 'value';
36-
});
34+
$cache->save('key', fn() => 'value');
3735

3836
$res = $cache->load('key');
3937
Assert::same('value', $res['data']);
@@ -45,9 +43,7 @@ $storage = new testStorage;
4543
$cache = new Cache($storage, 'ns');
4644
$dependencies = [Cache::Tags => ['tag']];
4745

48-
$cache->save('key', function () {
49-
return 'value';
50-
}, $dependencies);
46+
$cache->save('key', fn() => 'value', $dependencies);
5147

5248
$res = $cache->load('key');
5349
Assert::same('value', $res['data']);
@@ -59,9 +55,7 @@ $storage = new testStorage;
5955
$cache = new Cache($storage, 'ns');
6056
$dependencies = [Cache::Expire => new DateTime];
6157

62-
$res = $cache->save('key', function () {
63-
return 'value';
64-
}, $dependencies);
58+
$res = $cache->save('key', fn() => 'value', $dependencies);
6559
Assert::same('value', $res);
6660

6761
$res = $cache->load('key');

0 commit comments

Comments
 (0)