Skip to content

Commit 0a1375b

Browse files
committed
coding style
1 parent 271d4be commit 0a1375b

File tree

6 files changed

+26
-22
lines changed

6 files changed

+26
-22
lines changed

src/Bridges/CacheLatte/CacheMacro.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,12 @@ public static function initRuntime(Latte\Runtime\Template $template): void
9494
* Starts the output cache. Returns Nette\Caching\OutputHelper object if buffering was started.
9595
* @return Nette\Caching\OutputHelper|\stdClass
9696
*/
97-
public static function createCache(Nette\Caching\IStorage $cacheStorage, string $key, ?array &$parents, array $args = null)
98-
{
97+
public static function createCache(
98+
Nette\Caching\IStorage $cacheStorage,
99+
string $key,
100+
?array &$parents,
101+
array $args = null
102+
) {
99103
if ($args) {
100104
if (array_key_exists('if', $args) && !$args['if']) {
101105
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/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/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/Storages/FileStorage.deadlock.phpt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ try {
2121
$cache->load('key', function () {
2222
throw new Exception;
2323
});
24-
} catch (Exception $e) {
24+
} catch (\Throwable $e) {
2525
}
2626

2727
Assert::noError(function () use ($cache) {

0 commit comments

Comments
 (0)