Skip to content

Commit f077bee

Browse files
authored
Merge pull request #9 from tyrsson/provide-defaults
Provides default instances to driver constructors where possible.
2 parents 890b6bd + c183415 commit f077bee

6 files changed

Lines changed: 107 additions & 91 deletions

File tree

composer.lock

Lines changed: 59 additions & 43 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

phpstan-baseline.neon

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ parameters:
1212
count: 1
1313
path: src/Metadata/Source.php
1414

15-
-
16-
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<string, string\>\|string\> given\.$#'
17-
identifier: argument.type
18-
count: 1
19-
path: src/Metadata/Source.php
20-
2115
-
2216
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, list\<string\>\> given\.$#'
2317
identifier: argument.type

src/DatabasePlatformNameTrait.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/Driver.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Override;
88
use PgSql\Result as PgSqlResult;
99
use PhpDb\Adapter\Driver\ConnectionInterface;
10+
use PhpDb\Adapter\Driver\DriverAwareInterface;
1011
use PhpDb\Adapter\Driver\DriverInterface;
1112
use PhpDb\Adapter\Driver\ResultInterface;
1213
use PhpDb\Adapter\Driver\StatementInterface;
@@ -24,8 +25,6 @@
2425
*/
2526
class Driver implements DriverInterface, ProfilerAwareInterface
2627
{
27-
use DatabasePlatformNameTrait;
28-
2928
protected ?ProfilerInterface $profiler = null;
3029

3130
/** @var array */
@@ -34,9 +33,9 @@ class Driver implements DriverInterface, ProfilerAwareInterface
3433
];
3534

3635
public function __construct(
37-
protected readonly ConnectionInterface&Connection $connection,
38-
protected readonly StatementInterface&Statement $statementPrototype,
39-
protected readonly ResultInterface&Result $resultPrototype,
36+
protected readonly DriverAwareInterface&ConnectionInterface&Connection $connection,
37+
protected readonly DriverAwareInterface&StatementInterface&Statement $statementPrototype = new Statement(),
38+
protected readonly ResultInterface&Result $resultPrototype = new Result(),
4039
array $options = []
4140
) {
4241
$this->checkEnvironment();
@@ -55,9 +54,15 @@ public function setProfiler(
5554
): DriverInterface&ProfilerAwareInterface {
5655
$this->profiler = $profiler;
5756

58-
$this->connection->setProfiler($profiler);
57+
// @phpstan-ignore instanceof.alwaysTrue
58+
if ($this->connection instanceof ProfilerAwareInterface) {
59+
$this->connection->setProfiler($profiler);
60+
}
5961

60-
$this->statementPrototype->setProfiler($profiler);
62+
// @phpstan-ignore instanceof.alwaysTrue
63+
if ($this->statementPrototype instanceof ProfilerAwareInterface) {
64+
$this->statementPrototype->setProfiler($profiler);
65+
}
6166

6267
return $this;
6368
}

0 commit comments

Comments
 (0)