Skip to content

Commit 192096a

Browse files
authored
Separate chain calls (#15)
1 parent dced3ce commit 192096a

4 files changed

Lines changed: 28 additions & 10 deletions

File tree

src/DbCache.php

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ public function set($key, $value, $ttl = null): bool
106106
}
107107

108108
try {
109-
$this->db->createCommand()
109+
$this->db
110+
->createCommand()
110111
->upsert($this->table, $this->buildDataRow($key, $ttl, $value, true))
111112
->noCache()
112113
->execute()
@@ -169,7 +170,8 @@ public function setMultiple($values, $ttl = null): bool
169170
$this->deleteData($keys);
170171

171172
if (!empty($rows) && !$this->isExpiredTtl($ttl)) {
172-
$this->db->createCommand()
173+
$this->db
174+
->createCommand()
173175
->batchInsert($this->table, ['id', 'expire', 'data'], $rows)
174176
->noCache()
175177
->execute()
@@ -238,7 +240,11 @@ private function deleteData($id): void
238240

239241
try {
240242
$condition = $id === true ? '' : ['id' => $id];
241-
$this->db->createCommand()->delete($this->table, $condition)->noCache()->execute();
243+
$this->db
244+
->createCommand()
245+
->delete($this->table, $condition)
246+
->noCache()
247+
->execute();
242248
} catch (Throwable $e) {
243249
throw new CacheException('Unable to delete cache data.', 0, $e);
244250
}
@@ -274,7 +280,8 @@ private function buildDataRow(string $id, ?int $ttl, $value, bool $associative):
274280
private function gc(): void
275281
{
276282
if (random_int(0, 1000000) < $this->gcProbability) {
277-
$this->db->createCommand()
283+
$this->db
284+
->createCommand()
278285
->delete($this->table, ['AND', ['>', 'expire', 0], ['<', 'expire', time()]])
279286
->execute()
280287
;
@@ -295,7 +302,9 @@ private function normalizeTtl($ttl): ?int
295302
}
296303

297304
if ($ttl instanceof DateInterval) {
298-
return (new DateTime('@0'))->add($ttl)->getTimestamp();
305+
return (new DateTime('@0'))
306+
->add($ttl)
307+
->getTimestamp();
299308
}
300309

301310
return (int) $ttl;

src/Migration/M202101140204CreateCache.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@ public function up(MigrationBuilder $b): void
3232
$builder = new MigrationBuilder($this->cache->getDb(), $this->migrationInformer);
3333

3434
$builder->createTable($this->cache->getTable(), [
35-
'id' => $builder->string(128)->notNull(),
35+
'id' => $builder
36+
->string(128)
37+
->notNull(),
3638
'expire' => $builder->integer(),
3739
'data' => $builder->binary(),
3840
'PRIMARY KEY ([[id]])',

tests/DbCacheTest.php

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -481,15 +481,20 @@ public function testDeleteMultipleThrowExceptionForFailExecuteCommand(): void
481481

482482
private function createDbCacheWithFailConnection(): DbCache
483483
{
484-
$command = $this->getMockBuilder(Command::class)
484+
$command = $this
485+
->getMockBuilder(Command::class)
485486
->onlyMethods(['execute'])
486487
->disableOriginalConstructor()
487488
->getMockForAbstractClass()
488489
;
489-
$command->method('execute')->willThrowException(new Exception('Some error.'));
490+
$command
491+
->method('execute')
492+
->willThrowException(new Exception('Some error.'));
490493

491494
$db = $this->createMock(ConnectionInterface::class);
492-
$db->method('createCommand')->willReturn($command);
495+
$db
496+
->method('createCommand')
497+
->willReturn($command);
493498

494499
return new DbCache($db);
495500
}

tests/MigrationTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ public function testUpAndDown(): void
2222

2323
private function tableExists(string $tableName): bool
2424
{
25-
return $this->db->getSchema()->getTableSchema($tableName) !== null;
25+
return $this->db
26+
->getSchema()
27+
->getTableSchema($tableName) !== null;
2628
}
2729
}

0 commit comments

Comments
 (0)