Skip to content

Commit d3610bb

Browse files
committed
coding style
1 parent db9c203 commit d3610bb

File tree

10 files changed

+42
-40
lines changed

10 files changed

+42
-40
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ public function nodeOpened(Latte\MacroNode $node)
5959
$this->used = true;
6060
$node->empty = false;
6161
$node->openingCode = Latte\PhpWriter::using($node)
62-
->write('<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>',
62+
->write(
63+
'<?php if (Nette\Bridges\CacheLatte\CacheMacro::createCache($this->global->cacheStorage, %var, $this->global->cacheStack, %node.array?)) { ?>',
6364
Nette\Utils\Random::generate()
6465
);
6566
}
@@ -94,8 +95,12 @@ public static function initRuntime(Latte\Runtime\Template $template): void
9495
* Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
9596
* @return Nette\Caching\OutputHelper|\stdClass
9697
*/
97-
public static function createCache(Nette\Caching\IStorage $cacheStorage, string $key, ?array &$parents, array $args = null)
98-
{
98+
public static function createCache(
99+
Nette\Caching\IStorage $cacheStorage,
100+
string $key,
101+
?array &$parents,
102+
array $args = null
103+
) {
99104
if ($args) {
100105
if (array_key_exists('if', $args) && !$args['if']) {
101106
return $parents[] = new \stdClass;

src/Caching/Cache.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ final public function getNamespace(): string
7474
*/
7575
public function derive(string $namespace)
7676
{
77-
$derived = new static($this->storage, $this->namespace . $namespace);
78-
return $derived;
77+
return new static($this->storage, $this->namespace . $namespace);
7978
}
8079

8180

@@ -206,7 +205,7 @@ private function completeDependencies(?array $dp): array
206205
// convert FILES into CALLBACKS
207206
if (isset($dp[self::FILES])) {
208207
foreach (array_unique((array) $dp[self::FILES]) as $item) {
209-
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkFile'], $item, @filemtime($item) ?: null]; // @ - stat may fail
208+
$dp[self::CALLBACKS][] = [[self::class, 'checkFile'], $item, @filemtime($item) ?: null]; // @ - stat may fail
210209
}
211210
unset($dp[self::FILES]);
212211
}
@@ -219,7 +218,7 @@ private function completeDependencies(?array $dp): array
219218
// convert CONSTS into CALLBACKS
220219
if (isset($dp[self::CONSTS])) {
221220
foreach (array_unique((array) $dp[self::CONSTS]) as $item) {
222-
$dp[self::CALLBACKS][] = [[__CLASS__, 'checkConst'], $item, constant($item)];
221+
$dp[self::CALLBACKS][] = [[self::class, 'checkConst'], $item, constant($item)];
223222
}
224223
unset($dp[self::CONSTS]);
225224
}

src/Caching/IBulkReader.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
interface IBulkReader
1717
{
18-
1918
/**
2019
* Reads from cache in bulk.
2120
* @return array key => value pairs, missing items are omitted

src/Caching/IStorage.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
interface IStorage
1717
{
18-
1918
/**
2019
* Read from cache.
2120
* @return mixed

src/Caching/Storages/FileStorage.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,9 @@ public function __construct(string $dir, IJournal $journal = null)
8181
public function read(string $key)
8282
{
8383
$meta = $this->readMetaAndLock($this->getCacheFile($key), LOCK_SH);
84-
if ($meta && $this->verify($meta)) {
85-
return $this->readData($meta); // calls fclose()
86-
87-
} else {
88-
return null;
89-
}
84+
return $meta && $this->verify($meta)
85+
? $this->readData($meta) // calls fclose()
86+
: null;
9087
}
9188

9289

@@ -327,11 +324,7 @@ protected function readData(array $meta)
327324
flock($meta[self::HANDLE], LOCK_UN);
328325
fclose($meta[self::HANDLE]);
329326

330-
if (empty($meta[self::META_SERIALIZED])) {
331-
return $data;
332-
} else {
333-
return unserialize($data);
334-
}
327+
return empty($meta[self::META_SERIALIZED]) ? $data : unserialize($data);
335328
}
336329

337330

src/Caching/Storages/IJournal.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
interface IJournal
1717
{
18-
1918
/**
2019
* Writes entry information into the journal.
2120
*/

src/Caching/Storages/MemcachedStorage.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@ public static function isAvailable(): bool
4545
}
4646

4747

48-
public function __construct(string $host = 'localhost', int $port = 11211, string $prefix = '', IJournal $journal = null)
49-
{
48+
public function __construct(
49+
string $host = 'localhost',
50+
int $port = 11211,
51+
string $prefix = '',
52+
IJournal $journal = null
53+
) {
5054
if (!static::isAvailable()) {
5155
throw new Nette\NotSupportedException("PHP extension 'memcached' is not loaded.");
5256
}

src/Caching/Storages/SQLiteStorage.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ public function lock(string $key): void
9292

9393
public function write(string $key, $data, array $dependencies): void
9494
{
95-
$expire = isset($dependencies[Cache::EXPIRATION]) ? $dependencies[Cache::EXPIRATION] + time() : null;
96-
$slide = isset($dependencies[Cache::SLIDING]) ? $dependencies[Cache::EXPIRATION] : null;
95+
$expire = isset($dependencies[Cache::EXPIRATION])
96+
? $dependencies[Cache::EXPIRATION] + time()
97+
: null;
98+
$slide = isset($dependencies[Cache::SLIDING])
99+
? $dependencies[Cache::EXPIRATION]
100+
: null;
97101

98102
$this->pdo->exec('BEGIN TRANSACTION');
99103
$this->pdo->prepare('REPLACE INTO cache (key, data, expire, slide) VALUES (?, ?, ?, ?)')

tests/Caching/Cache.load.phpt

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ $cache = new Cache($storage, 'ns');
2222
$value = $cache->load('key', function () {
2323
return 'value';
2424
});
25-
Assert::equal('value', $value);
25+
Assert::same('value', $value);
2626

2727
$data = $cache->load('key', function () {
2828
return "won't load this value"; // will read from storage
2929
});
30-
Assert::equal('value', $data['data']);
30+
Assert::same('value', $data['data']);
3131

3232

3333
// load twice with closure fallback, pass dependencies
@@ -39,13 +39,13 @@ $value = $cache->load('key', function (&$deps) use ($dependencies) {
3939
$deps = $dependencies;
4040
return 'value';
4141
});
42-
Assert::equal('value', $value);
42+
Assert::same('value', $value);
4343

4444
$data = $cache->load('key', function () {
4545
return "won't load this value"; // will read from storage
4646
});
47-
Assert::equal('value', $data['data']);
48-
Assert::equal($dependencies, $data['dependencies']);
47+
Assert::same('value', $data['data']);
48+
Assert::same($dependencies, $data['dependencies']);
4949

5050

5151
// load twice with fallback, pass dependencies
@@ -58,7 +58,7 @@ function fallback(&$deps)
5858

5959

6060
$value = $cache->load('key2', 'fallback');
61-
Assert::equal('value', $value);
61+
Assert::same('value', $value);
6262
$data = $cache->load('key2');
63-
Assert::equal('value', $data['data']);
64-
Assert::equal($dependencies, $data['dependencies']);
63+
Assert::same('value', $data['data']);
64+
Assert::same($dependencies, $data['dependencies']);

tests/Caching/Cache.save.phpt

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@ $dependencies = [Cache::TAGS => ['tag']];
2323
$cache->save('key', 'value', $dependencies);
2424

2525
$res = $cache->load('key');
26-
Assert::equal('value', $res['data']);
27-
Assert::equal($dependencies, $res['dependencies']);
26+
Assert::same('value', $res['data']);
27+
Assert::same($dependencies, $res['dependencies']);
2828

2929

3030
// save callback return value
@@ -36,8 +36,8 @@ $cache->save('key', function () {
3636
});
3737

3838
$res = $cache->load('key');
39-
Assert::equal('value', $res['data']);
40-
Assert::equal([], $res['dependencies']);
39+
Assert::same('value', $res['data']);
40+
Assert::same([], $res['dependencies']);
4141

4242

4343
// save callback return value with dependencies
@@ -50,8 +50,8 @@ $cache->save('key', function () {
5050
}, $dependencies);
5151

5252
$res = $cache->load('key');
53-
Assert::equal('value', $res['data']);
54-
Assert::equal($dependencies, $res['dependencies']);
53+
Assert::same('value', $res['data']);
54+
Assert::same($dependencies, $res['dependencies']);
5555

5656

5757
// do not save already expired data
@@ -62,7 +62,7 @@ $dependencies = [Cache::EXPIRATION => new DateTime];
6262
$res = $cache->save('key', function () {
6363
return 'value';
6464
}, $dependencies);
65-
Assert::equal('value', $res);
65+
Assert::same('value', $res);
6666

6767
$res = $cache->load('key');
6868
Assert::null($res);

0 commit comments

Comments
 (0)