Skip to content

Commit c805941

Browse files
committed
CS
1 parent 902919a commit c805941

14 files changed

+102
-107
lines changed

src/Db/Result.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -393,12 +393,7 @@ public function hasAffectedRows(): bool
393393
*/
394394
public function getColumnType(string $column): string
395395
{
396-
$type = $this->getColumnsDataTypes()[$column] ?? null;
397-
if ($type === null) {
398-
throw Exceptions\ResultException::noColumn($column);
399-
}
400-
401-
return $type;
396+
return $this->getColumnsDataTypes()[$column] ?? throw Exceptions\ResultException::noColumn($column);
402397
}
403398

404399

tests/Integration/AsyncTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function testMoreExecutesWithoutCompletePrevious(): void
9292
{
9393
Tester\Assert::exception(function (): void {
9494
$this->connection->asyncExecute('SELECT 1')->asyncExecute('SELECT 2');
95-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_QUERY_SENT_FAILED);
95+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_QUERY_SENT_FAILED);
9696
}
9797

9898

@@ -101,7 +101,7 @@ public function testCompleteExecuteWithQuery(): void
101101
Tester\Assert::exception(function (): void {
102102
$this->connection->asyncQuery('SELECT 1');
103103
$this->connection->completeAsyncExecute();
104-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_NO_EXECUTE_IS_SENT);
104+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_NO_EXECUTE_IS_SENT);
105105
}
106106

107107

@@ -112,7 +112,7 @@ public function testGetQueryResultAfterExecute(): void
112112
Tester\Assert::exception(function () use ($asyncQuery): void {
113113
$this->connection->asyncExecute('SELECT 2');
114114
$asyncQuery->getNextResult();
115-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_QUERY_SENT_FAILED);
115+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_QUERY_SENT_FAILED);
116116
}
117117

118118

@@ -124,7 +124,7 @@ public function testCancelAsyncQuery(): void
124124

125125
Tester\Assert::exception(static function () use ($asyncQuery): void {
126126
$asyncQuery->getNextResult();
127-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_NO_QUERY_IS_SENT);
127+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_NO_QUERY_IS_SENT);
128128
}
129129

130130

@@ -146,7 +146,7 @@ public function testMoreAsyncQueriesWithoutCompletePrevious(): void
146146

147147
Tester\Assert::exception(function (): void {
148148
$this->connection->asyncQuery('SELECT 2');
149-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_QUERY_SENT_FAILED);
149+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_QUERY_SENT_FAILED);
150150
}
151151

152152

@@ -162,13 +162,13 @@ public function testMoreAsyncQueriesInOne(): void
162162

163163
Tester\Assert::exception(static function () use ($asyncQuery1): void {
164164
$asyncQuery1->getNextResult();
165-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::NO_OTHER_ASYNC_RESULT);
165+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::NO_OTHER_ASYNC_RESULT);
166166

167167
$asyncQuery2 = $this->connection->asyncQuery('SELECT 3');
168168

169169
Tester\Assert::exception(static function () use ($asyncQuery1): void {
170170
$asyncQuery1->getNextResult();
171-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_ANOTHER_QUERY_IS_RUNNING);
171+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_ANOTHER_QUERY_IS_RUNNING);
172172

173173
$result3 = $asyncQuery2->getNextResult();
174174
Tester\Assert::same(3, $result3->fetchSingle());
@@ -177,7 +177,7 @@ public function testMoreAsyncQueriesInOne(): void
177177

178178
Tester\Assert::exception(static function () use ($asyncQuery1): void {
179179
$asyncQuery1->getNextResult();
180-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::ASYNC_ANOTHER_QUERY_IS_RUNNING);
180+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::ASYNC_ANOTHER_QUERY_IS_RUNNING);
181181
}
182182

183183

@@ -196,12 +196,12 @@ public function testError(): void
196196
$asyncQuery = $this->connection->asyncQuery('SELECT bad_column');
197197
Tester\Assert::exception(static function () use ($asyncQuery): void {
198198
$asyncQuery->getNextResult();
199-
}, Db\Exceptions\QueryException::class, null, Db\Exceptions\QueryException::ASYNC_QUERY_FAILED);
199+
}, Db\Exceptions\QueryException::class, code: Db\Exceptions\QueryException::ASYNC_QUERY_FAILED);
200200

201201
$this->connection->asyncExecute('SELECT bad_column');
202202
Tester\Assert::exception(function (): void {
203203
$this->connection->completeAsyncExecute();
204-
}, Db\Exceptions\QueryException::class, null, Db\Exceptions\QueryException::ASYNC_QUERY_FAILED);
204+
}, Db\Exceptions\QueryException::class, code: Db\Exceptions\QueryException::ASYNC_QUERY_FAILED);
205205
}
206206

207207

tests/Integration/BasicTest.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function testConnectionNoConfig(): void
8484

8585
Tester\Assert::exception(function (): void {
8686
$this->connection->connect();
87-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::NO_CONFIG);
87+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::NO_CONFIG);
8888
}
8989

9090

@@ -94,7 +94,7 @@ public function testFailedConnection(): void
9494

9595
Tester\Assert::exception(function (): void {
9696
$this->connection->ping();
97-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::CONNECTION_FAILED);
97+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::CONNECTION_FAILED);
9898
}
9999

100100

@@ -104,7 +104,7 @@ public function testChangeConnectionSettingsAfterConnected(): void
104104

105105
Tester\Assert::exception(function (): void {
106106
$this->connection->setConnectionConfig('');
107-
}, Db\Exceptions\ConnectionException::class, null, Db\Exceptions\ConnectionException::CANT_CHANGE_CONNECTION_CONFIG_WHEN_CONNECTED);
107+
}, Db\Exceptions\ConnectionException::class, code: Db\Exceptions\ConnectionException::CANT_CHANGE_CONNECTION_CONFIG_WHEN_CONNECTED);
108108

109109
$this->connection->close();
110110

@@ -187,7 +187,7 @@ public function testFailedQuery(): void
187187
Tester\Assert::true($e->getQuery() instanceof Db\Query);
188188
throw $e;
189189
}
190-
}, Db\Exceptions\QueryException::class, null, Db\Exceptions\QueryException::QUERY_FAILED);
190+
}, Db\Exceptions\QueryException::class, code: Db\Exceptions\QueryException::QUERY_FAILED);
191191
}
192192

193193

@@ -196,7 +196,7 @@ public function testPassParamToQuery(): void
196196
Tester\Assert::exception(function (): void {
197197
$query = Db\Sql\Query::create('SELECT 1');
198198
$this->connection->query($query, 1);
199-
}, Db\Exceptions\QueryException::class, null, Db\Exceptions\QueryException::CANT_PASS_PARAMS);
199+
}, Db\Exceptions\QueryException::class, code: Db\Exceptions\QueryException::CANT_PASS_PARAMS);
200200
}
201201

202202

@@ -243,7 +243,7 @@ public function testFailedExecute(): void
243243
{
244244
Tester\Assert::exception(function (): void {
245245
$this->connection->execute('SELECT bad_column');
246-
}, Db\Exceptions\QueryException::class, null, Db\Exceptions\QueryException::QUERY_FAILED);
246+
}, Db\Exceptions\QueryException::class, code: Db\Exceptions\QueryException::QUERY_FAILED);
247247
}
248248

249249

tests/Integration/CollectingResultsTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function testResultCollector(): void
5252
// Try also parse some non-existing column
5353
Tester\Assert::exception(static function () use ($resultSelect): void {
5454
$resultSelect->parseColumnValue('non_existing_column', 'someValue');
55-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::NO_COLUMN);
55+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::NO_COLUMN);
5656

5757
$querySelect = $resultSelect->getQuery();
5858

tests/Integration/DataTypeCacheTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public function testNoOidInCache(): void
108108

109109
Tester\Assert::exception(static function () use ($result2): void {
110110
Tester\Assert::same('hstore', $result2->getColumnType('data'));
111-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::NO_OID_IN_DATA_TYPE_CACHE);
111+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::NO_OID_IN_DATA_TYPE_CACHE);
112112

113113
$result2->free();
114114
}

tests/Integration/FetchMutatorTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ public function testFetchAssocColumnMutatorMutatedObjectAsKey(): void
212212

213213
Tester\Assert::exception(static function () use ($result): void {
214214
$result->fetchAssoc('test_date=id');
215-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_MUTATOR_BAR_RETURN_TYPE);
215+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_MUTATOR_BAR_RETURN_TYPE);
216216

217217
$result->free();
218218
}
@@ -415,7 +415,7 @@ public function testFetchPairsKeyMutatorMutatedObject(): void
415415

416416
Tester\Assert::exception(static function () use ($result): void {
417417
$result->fetchPairs();
418-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_MUTATOR_BAR_RETURN_TYPE);
418+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_MUTATOR_BAR_RETURN_TYPE);
419419

420420
$result->free();
421421
}

tests/Integration/FetchTest.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -273,23 +273,23 @@ public function testFetchAssocBadDescriptor(): void
273273

274274
Tester\Assert::exception(static function () use ($result): void {
275275
$result->fetchAssoc('');
276-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
276+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
277277

278278
Tester\Assert::exception(static function () use ($result): void {
279279
$result->fetchAssoc('=types');
280-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
280+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
281281

282282
Tester\Assert::exception(static function () use ($result): void {
283283
$result->fetchAssoc('|types');
284-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
284+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
285285

286286
Tester\Assert::exception(static function () use ($result): void {
287287
$result->fetchAssoc('types=');
288-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
288+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
289289

290290
Tester\Assert::exception(static function () use ($result): void {
291291
$result->fetchAssoc('types|');
292-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
292+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_BAD_DESCRIPTOR);
293293

294294
$result->free();
295295
}
@@ -310,7 +310,7 @@ public function testFetchAssocNoColumn(): void
310310

311311
Tester\Assert::exception(static function () use ($result): void {
312312
$result->fetchAssoc('id=types');
313-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_NO_COLUMN);
313+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_NO_COLUMN);
314314

315315
$result->free();
316316
}
@@ -353,7 +353,7 @@ public function testFetchAssocObjectAsKey(): void
353353

354354
Tester\Assert::exception(static function () use ($result): void {
355355
$result->fetchAssoc('test_date=id');
356-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_ASSOC_ONLY_SCALAR_AS_KEY);
356+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_ASSOC_ONLY_SCALAR_AS_KEY);
357357

358358
$result->free();
359359
}
@@ -399,7 +399,7 @@ public function testFetchPairsOnlyOneColumn(): void
399399

400400
Tester\Assert::exception(static function () use ($result): void {
401401
$result->fetchPairs('name');
402-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_PAIRS_BAD_COLUMNS);
402+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_PAIRS_BAD_COLUMNS);
403403

404404
$result->free();
405405
}
@@ -445,7 +445,7 @@ public function testFetchPairsObjectAsKey(): void
445445

446446
Tester\Assert::exception(static function () use ($result): void {
447447
$result->fetchPairs('test_date', 'id');
448-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::FETCH_PAIRS_ONLY_SCALAR_AS_KEY);
448+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::FETCH_PAIRS_ONLY_SCALAR_AS_KEY);
449449

450450
$result->free();
451451
}
@@ -467,12 +467,12 @@ public function testFetchPairsBadKeyOrValue(): void
467467
// Bad key
468468
Tester\Assert::exception(static function () use ($result): void {
469469
$result->fetchPairs('type', 'name');
470-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::NO_COLUMN);
470+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::NO_COLUMN);
471471

472472
// Bad value
473473
Tester\Assert::exception(static function () use ($result): void {
474474
$result->fetchPairs('id', 'type');
475-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::NO_COLUMN);
475+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::NO_COLUMN);
476476

477477
$result->free();
478478
}
@@ -504,19 +504,19 @@ public function testFetchBadOffset(): void
504504

505505
Tester\Assert::exception(static function () use ($row): void {
506506
$row[1];
507-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NOT_STRING_KEY);
507+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NOT_STRING_KEY);
508508

509509
Tester\Assert::exception(static function () use ($row): void {
510510
$row[1] = 'value';
511-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NOT_STRING_KEY);
511+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NOT_STRING_KEY);
512512

513513
Tester\Assert::exception(static function () use ($row): void {
514514
isset($row[1]);
515-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NOT_STRING_KEY);
515+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NOT_STRING_KEY);
516516

517517
Tester\Assert::exception(static function () use ($row): void {
518518
unset($row[1]);
519-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NOT_STRING_KEY);
519+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NOT_STRING_KEY);
520520

521521
$result->free();
522522
}
@@ -539,7 +539,7 @@ public function testFetchNoColumn(): void
539539

540540
Tester\Assert::exception(static function () use ($row): void {
541541
$row->cnt;
542-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NO_COLUMN);
542+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NO_COLUMN);
543543

544544
$result->free();
545545
}
@@ -666,7 +666,7 @@ public function testResultNoColumnForType(): void
666666

667667
Tester\Assert::exception(static function () use ($result): void {
668668
$result->getColumnType('count');
669-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::NO_COLUMN);
669+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::NO_COLUMN);
670670

671671
$result->free();
672672
}
@@ -680,7 +680,7 @@ public function testResultColumnIsAlreadyInUse(): void
680680
$row = $result->fetch();
681681
\assert($row !== null);
682682
$row->column;
683-
}, Db\Exceptions\ResultException::class, null, Db\Exceptions\ResultException::COLUMN_NAME_IS_ALREADY_IN_USE);
683+
}, Db\Exceptions\ResultException::class, code: Db\Exceptions\ResultException::COLUMN_NAME_IS_ALREADY_IN_USE);
684684

685685
$result->free();
686686
}
@@ -770,11 +770,11 @@ public function testRowValues(): void
770770

771771
Tester\Assert::exception(static function () use ($row): void {
772772
$row->type;
773-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NO_COLUMN);
773+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NO_COLUMN);
774774

775775
Tester\Assert::exception(static function () use ($row): void {
776776
$row['another_type'];
777-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NO_COLUMN);
777+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NO_COLUMN);
778778

779779
$row->type = 'test';
780780

@@ -794,15 +794,15 @@ public function testRowValues(): void
794794

795795
Tester\Assert::exception(static function () use ($row): void {
796796
$row->type;
797-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NO_COLUMN);
797+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NO_COLUMN);
798798

799799
unset($row['another_type']);
800800

801801
Tester\Assert::false(isset($row['another_type']));
802802

803803
Tester\Assert::exception(static function () use ($row): void {
804804
$row['another_type'];
805-
}, Db\Exceptions\RowException::class, null, Db\Exceptions\RowException::NO_COLUMN);
805+
}, Db\Exceptions\RowException::class, code: Db\Exceptions\RowException::NO_COLUMN);
806806

807807
unset($row->name);
808808

tests/Integration/FluentQueryExecuteFetchTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function testFreeWithoutResult(): void
243243
{
244244
Tester\Assert::exception(function (): void {
245245
$this->connection->createQuery()->select([1])->free();
246-
}, Fluent\Exceptions\QueryException::class, null, Fluent\Exceptions\QueryException::YOU_MUST_EXECUTE_QUERY_BEFORE_THAT);
246+
}, Fluent\Exceptions\QueryException::class, code: Fluent\Exceptions\QueryException::YOU_MUST_EXECUTE_QUERY_BEFORE_THAT);
247247
}
248248

249249

@@ -255,7 +255,7 @@ public function testUpdateExecuted(): void
255255

256256
Tester\Assert::exception(static function () use ($query): void {
257257
$query->from('table');
258-
}, Fluent\Exceptions\QueryException::class, null, Fluent\Exceptions\QueryException::CANT_UPDATE_QUERY_AFTER_EXECUTE);
258+
}, Fluent\Exceptions\QueryException::class, code: Fluent\Exceptions\QueryException::CANT_UPDATE_QUERY_AFTER_EXECUTE);
259259
}
260260

261261

0 commit comments

Comments
 (0)