Skip to content

Commit 7b191b9

Browse files
authored
Merge pull request #4 from tyrsson:simplify-adapterinterface-factory
Latest Revisions
2 parents 4e3bd74 + 91860ed commit 7b191b9

29 files changed

Lines changed: 149 additions & 610 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@
7171
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
7272
"test-integration": "phpunit --colors=always --testsuite \"integration test\"",
7373
"sa": "vendor/bin/phpstan analyse --memory-limit=256M",
74-
"sa-generate-baseline": "vendor/bin/phpstan analyse --memory-limit=256M --generate-baseline",
74+
"sa-gen-baseline": "vendor/bin/phpstan analyse --memory-limit=256M --generate-baseline",
7575
"sa-verbose": "vendor/bin/phpstan analyse --memory-limit=256M -vv",
7676
"upload-coverage": "coveralls -v"
7777
}

composer.lock

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

phpstan-baseline.neon

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,19 @@
11
parameters:
2-
ignoreErrors:
2+
ignoreErrors:
3+
-
4+
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<int\|string, string\>\> given\.$#'
5+
identifier: argument.type
6+
count: 1
7+
path: src/Metadata/Source.php
8+
9+
-
10+
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, array\<string, string\>\|string\> given\.$#'
11+
identifier: argument.type
12+
count: 1
13+
path: src/Metadata/Source.php
14+
15+
-
16+
message: '#^Parameter \#2 \$array of function implode expects array\<string\>, array\<int, list\<string\>\> given\.$#'
17+
identifier: argument.type
18+
count: 1
19+
path: src/Metadata/Source.php

src/AdapterPlatform.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,6 @@ class AdapterPlatform extends AbstractPlatform
2727
*/
2828
protected string $quoteIdentifierTo = '""';
2929

30-
/** @var string[] */
31-
private array $knownPgsqlResources = [
32-
'pgsql link',
33-
'pgsql link persistent',
34-
];
35-
3630
public function __construct(
3731
private readonly DriverInterface|PdoDriverInterface|PDO $driver,
3832
) {
@@ -89,6 +83,7 @@ public function quoteTrustedValue($value): string
8983
*/
9084
protected function quoteViaDriver($value): ?string
9185
{
86+
/** @var PgSqlConnection|string $resource */
9287
$resource = $this->driver instanceof DriverInterface
9388
? $this->driver->getConnection()->getResource()
9489
: $this->driver;

src/ConfigProvider.php

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,30 +4,29 @@
44

55
namespace PhpDb\Adapter\Pgsql;
66

7-
use Laminas\ServiceManager\Factory\InvokableFactory;
87
use PhpDb\Adapter\Adapter;
98
use PhpDb\Adapter\AdapterInterface;
109
use PhpDb\Adapter\Driver\ConnectionInterface;
1110
use PhpDb\Adapter\Driver\DriverInterface;
11+
use PhpDb\Adapter\Driver\Pdo\Statement as PdoStatement;
1212
use PhpDb\Adapter\Driver\PdoConnectionInterface;
1313
use PhpDb\Adapter\Driver\PdoDriverInterface;
14-
use PhpDb\Adapter\Driver\Pdo\Statement as PdoStatement;
15-
use PhpDb\Adapter\Platform\PlatformInterface;
1614
use PhpDb\Adapter\Pgsql\Pdo\Connection as PdoConnection;
1715
use PhpDb\Adapter\Pgsql\Pdo\Driver as PdoDriver;
18-
use PhpDb\Adapter\Profiler\Profiler;
19-
use PhpDb\Adapter\Profiler\ProfilerInterface;
20-
use PhpDb\Container\AdapterAbstractServiceFactory;
16+
use PhpDb\Adapter\Platform\PlatformInterface;
17+
use PhpDb\ConfigProvider as PhpDbConfigProvider;
2118
use PhpDb\Metadata\MetadataInterface;
22-
use PhpDb\ResultSet\ResultSetInterface;
2319

20+
/**
21+
* @internal
22+
*/
2423
final readonly class ConfigProvider
2524
{
2625
public function __invoke(): array
2726
{
2827
return [
2928
'dependencies' => $this->getDependencies(),
30-
AdapterInterface::class => $this->getConfig(),
29+
//AdapterInterface::class => $this->getConfig(),
3130
];
3231
}
3332

@@ -44,7 +43,7 @@ public function getConfig(): array
4443
'database' => 'your_database',
4544
],
4645
// Named Adapter configurations
47-
'adapters' => [
46+
PhpDbConfigProvider::NAMED_ADAPTER_KEY => [
4847
AdapterInterface::class => [
4948
'driver' => Driver::class,
5049
'connection' => [
@@ -62,11 +61,7 @@ public function getConfig(): array
6261
public function getDependencies(): array
6362
{
6463
return [
65-
'abstract_factories' => [
66-
Container\AdapterAbstractServiceFactory::class,
67-
],
6864
'aliases' => [
69-
AdapterInterface::class => Adapter::class,
7065
DriverInterface::class => Driver::class,
7166
'pgsql' => Driver::class,
7267
'PgSQL' => Driver::class,
@@ -88,15 +83,14 @@ public function getDependencies(): array
8883
PlatformInterface::class => AdapterPlatform::class,
8984
],
9085
'factories' => [
91-
Adapter::class => Container\AdapterInterfaceFactory::class,
92-
AdapterPlatform::class => Container\PlatformInterfaceFactory::class,
93-
Connection::class => Container\ConnectionInterfaceFactory::class,
94-
Metadata\Source::class => Container\MetadataInterfaceFactory::class,
95-
Statement::class => Container\StatementInterfaceFactory::class,
96-
Driver::class => Container\DriverInterfaceFactory::class,
97-
PdoConnection::class => Container\PdoConnectionInterfaceFactory::class,
98-
PdoDriver::class => Container\PdoDriverInterfaceFactory::class,
99-
PdoStatement::class => Container\PdoStatemenFactory::class,
86+
AdapterPlatform::class => Container\PlatformInterfaceFactory::class,
87+
Connection::class => Container\ConnectionInterfaceFactory::class,
88+
Driver::class => Container\DriverInterfaceFactory::class,
89+
Metadata\Source::class => Container\MetadataInterfaceFactory::class,
90+
PdoConnection::class => Container\PdoConnectionInterfaceFactory::class,
91+
PdoDriver::class => Container\PdoDriverInterfaceFactory::class,
92+
PdoStatement::class => Container\PdoStatementFactory::class,
93+
Statement::class => Container\StatementInterfaceFactory::class,
10094
// Provide the following if you wish to override the Profiler implementation
10195
//ProfilerInterface::class => YourCustomProfilerFactory::class,
10296
// Provide the following if you wish to override the ResultSet implementation

src/Connection.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
class Connection extends AbstractConnection implements DriverAwareInterface
3535
{
36-
protected Driver $driver;
36+
protected DriverInterface|Driver $driver;
3737

3838
/** @var ?PgSqlConnection */
3939
protected $resource;
@@ -58,6 +58,7 @@ public function setResource(
5858
return $this;
5959
}
6060

61+
/** @phpstan-ignore method.childReturnType */
6162
#[Override]
6263
public function getResource(): ?PgSqlConnection
6364
{
@@ -66,7 +67,7 @@ public function getResource(): ?PgSqlConnection
6667

6768
#[Override]
6869
public function setDriver(
69-
DriverInterface $driver
70+
DriverInterface|Driver $driver
7071
): ConnectionInterface&DriverAwareInterface {
7172
$this->driver = $driver;
7273

@@ -120,8 +121,8 @@ public function connect(): static
120121
set_error_handler(function ($number, $string) {
121122
throw new Exception\RuntimeException(
122123
self::class . '::connect: Unable to connect to database',
123-
$number ?? 0,
124-
new Exception\ErrorException($string, $number ?? 0)
124+
$number,
125+
new Exception\ErrorException($string, $number)
125126
);
126127
});
127128
try {
@@ -253,6 +254,7 @@ public function execute($sql): ResultInterface
253254
throw new Exception\InvalidQueryException(pg_last_error($this->resource));
254255
}
255256

257+
/** @phpstan-ignore argument.type */
256258
return $this->driver->createResult($resultResource);
257259
}
258260

src/Container/AdapterAbstractServiceFactory.php

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

0 commit comments

Comments
 (0)