Skip to content

Commit 25c1429

Browse files
committed
Merge upstream/0.2.x into result-count-issue
Resolves conflicts from PRs #44 and #45 (namespace restructuring, config key changes, import cleanup). Removes unused result factories.
2 parents 0b654b6 + cfcf2e3 commit 25c1429

42 files changed

Lines changed: 531 additions & 373 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

composer.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
"scripts": {
6363
"check": [
6464
"@cs-check",
65-
"@static-analysis",
65+
"@sa",
6666
"@test",
6767
"@test-integration"
6868
],
@@ -71,8 +71,9 @@
7171
"test": "phpunit --colors=always --testsuite \"unit test\"",
7272
"test-coverage": "phpunit --colors=always --coverage-clover clover.xml",
7373
"test-integration": "phpunit --colors=always --testsuite \"integration test\"",
74-
"static-analysis": "vendor/bin/phpstan analyse --memory-limit=256M",
75-
"sa-generate-baseline": "vendor/bin/phpstan analyse --memory-limit=256M --generate-baseline",
74+
"sa": "vendor/bin/phpstan analyse --memory-limit=256M",
75+
"sa-gen-baseline": "vendor/bin/phpstan analyse --memory-limit=256M --generate-baseline",
76+
"sa-verbose": "vendor/bin/phpstan analyse --memory-limit=256M -vv",
7677
"upload-coverage": "coveralls -v"
7778
}
7879
}

phpstan-baseline.neon

Lines changed: 86 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,24 @@ parameters:
3030
count: 1
3131
path: src/Connection.php
3232

33+
-
34+
message: '#^PHPDoc tag @var for variable \$connectionInstance contains unknown class PhpDb\\Mysql\\Driver\\ConnectionInterface\.$#'
35+
identifier: class.notFound
36+
count: 1
37+
path: src/Container/DriverInterfaceFactory.php
38+
39+
-
40+
message: '#^PHPDoc tag @var for variable \$resultInstance contains unknown class PhpDb\\Mysql\\Driver\\ResultInterface\.$#'
41+
identifier: class.notFound
42+
count: 1
43+
path: src/Container/DriverInterfaceFactory.php
44+
45+
-
46+
message: '#^PHPDoc tag @var for variable \$statementInstance contains unknown class PhpDb\\Mysql\\Driver\\StatementInterface\.$#'
47+
identifier: class.notFound
48+
count: 1
49+
path: src/Container/DriverInterfaceFactory.php
50+
3351
-
3452
message: '#^Instanceof between PhpDb\\Mysql\\Connection and PhpDb\\Adapter\\Driver\\DriverAwareInterface will always evaluate to true\.$#'
3553
identifier: instanceof.alwaysTrue
@@ -174,8 +192,75 @@ parameters:
174192
count: 1
175193
path: src/Statement.php
176194

195+
-
196+
message: '#^Call to an undefined method PhpDb\\Mysql\\Driver\:\:quoteValue\(\)\.$#'
197+
identifier: method.notFound
198+
count: 2
199+
path: test/integration/AdapterPlatformTest.php
200+
201+
-
202+
message: '#^Parameter \#1 \$connection of class PhpDb\\Mysql\\Driver constructor expects PhpDb\\Mysql\\Connection, PDO given\.$#'
203+
identifier: argument.type
204+
count: 1
205+
path: test/integration/AdapterPlatformTest.php
206+
207+
-
208+
message: '#^Parameter \#1 \$connection of class PhpDb\\Mysql\\Driver constructor expects PhpDb\\Mysql\\Connection, mysqli given\.$#'
209+
identifier: argument.type
210+
count: 1
211+
path: test/integration/AdapterPlatformTest.php
212+
213+
-
214+
message: '#^Parameter \#2 \$statementPrototype of class PhpDb\\Mysql\\Driver constructor expects PhpDb\\Mysql\\Statement, PhpDb\\Adapter\\Driver\\Pdo\\Statement given\.$#'
215+
identifier: argument.type
216+
count: 1
217+
path: test/integration/AdapterPlatformTest.php
218+
219+
-
220+
message: '#^Property PhpDbIntegrationTest\\Mysql\\Platform\\AdapterPlatformTest\:\:\$adapters \(array\<string, mysqli\|PDO\>\) does not accept array\<string, mysqli\|PDO\|PhpDb\\Mysql\\Connection\>\.$#'
221+
identifier: assign.propertyType
222+
count: 1
223+
path: test/integration/AdapterPlatformTest.php
224+
225+
-
226+
message: '#^Property PhpDbIntegrationTest\\Mysql\\Platform\\AdapterPlatformTest\:\:\$adapters \(array\<string, mysqli\|PDO\>\) does not accept array\<string, mysqli\|PDO\|PhpDb\\Mysql\\Pdo\\Connection\>\.$#'
227+
identifier: assign.propertyType
228+
count: 1
229+
path: test/integration/AdapterPlatformTest.php
230+
231+
-
232+
message: '#^Parameter \#1 \$container of callable PhpDb\\Mysql\\Container\\DriverInterfaceFactory expects Laminas\\ServiceManager\\ServiceManager, Psr\\Container\\ContainerInterface given\.$#'
233+
identifier: argument.type
234+
count: 2
235+
path: test/integration/Container/DriverInterfaceFactoryTest.php
236+
237+
-
238+
message: '#^Parameter \#1 \$container of callable PhpDb\\Mysql\\Container\\PdoDriverInterfaceFactory expects Laminas\\ServiceManager\\ServiceManager, Psr\\Container\\ContainerInterface given\.$#'
239+
identifier: argument.type
240+
count: 1
241+
path: test/integration/Container/PdoDriverInterfaceFactoryTest.php
242+
177243
-
178244
message: '#^Call to static method PHPUnit\\Framework\\Assert\:\:assertIsInt\(\) with int will always evaluate to true\.$#'
179245
identifier: staticMethod.alreadyNarrowedType
180246
count: 1
181-
path: test/integration/Driver/Pdo/ConnectionTest.php
247+
path: test/integration/Pdo/ConnectionTest.php
248+
249+
-
250+
message: '#^Unreachable statement \- code above always terminates\.$#'
251+
identifier: deadCode.unreachable
252+
count: 1
253+
path: test/integration/Pdo/QueryTest.php
254+
255+
-
256+
message: '#^Unreachable statement \- code above always terminates\.$#'
257+
identifier: deadCode.unreachable
258+
count: 1
259+
path: test/integration/Pdo/TableGatewayTest.php
260+
261+
-
262+
message: '#^Unreachable statement \- code above always terminates\.$#'
263+
identifier: deadCode.unreachable
264+
count: 1
265+
path: test/integration/TableGatewayTest.php
266+

src/Container/ConnectionInterfaceFactory.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,14 @@ public function __invoke(
1818
string $requestedName,
1919
?array $options = null
2020
): ConnectionInterface&Connection {
21-
if (! is_array($options['connection']) || $options['connection'] === []) {
21+
$conn = $options['connection'] ?? [];
22+
if (! is_array($conn) || $conn === []) {
2223
throw new InvalidConnectionParametersException(
2324
'Connection configuration must be an array of parameters passed via $options["connection"]',
24-
$options['connection']
25+
$conn
2526
);
2627
}
2728

28-
return new Connection($options['connection']);
29+
return new Connection($conn);
2930
}
3031
}

src/Container/DriverInterfaceFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public function __invoke(
2727
throw ContainerException::forService(
2828
Driver::class,
2929
self::class,
30-
'$options["connection"] must containe an array of connection configuration.'
30+
'$options["connection"] must contain an array of connection configuration.'
3131
);
3232
}
3333

src/Container/MysqliResultFactory.php

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

src/Container/PdoConnectionInterfaceFactory.php

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,27 @@
55
namespace PhpDb\Mysql\Container;
66

77
use PhpDb\Adapter\Driver\PdoConnectionInterface;
8+
use PhpDb\Adapter\Exception\InvalidConnectionParametersException;
89
use PhpDb\Mysql\Pdo\Connection;
910
use Psr\Container\ContainerInterface;
1011

12+
use function is_array;
13+
1114
final class PdoConnectionInterfaceFactory
1215
{
13-
public function __invoke(ContainerInterface $container): PdoConnectionInterface&Connection
14-
{
15-
/** @var array $config */
16-
$config = $container->get('config');
17-
18-
/** @var array $dbConfig */
19-
$dbConfig = $config['db'] ?? [];
20-
21-
/** @var array $connectionConfig */
22-
$connectionConfig = $dbConfig['connection'] ?? [];
16+
public function __invoke(
17+
ContainerInterface $container,
18+
string $requestedName,
19+
?array $options = null
20+
): PdoConnectionInterface&Connection {
21+
$conn = $options['connection'] ?? [];
22+
if (! is_array($conn) || $conn === []) {
23+
throw new InvalidConnectionParametersException(
24+
'Connection configuration must be an array of parameters passed via $options["connection"]',
25+
$conn
26+
);
27+
}
2328

24-
return new Connection($connectionConfig);
29+
return new Connection($conn);
2530
}
2631
}

src/Container/PdoDriverInterfaceFactory.php

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,51 @@
44

55
namespace PhpDb\Mysql\Container;
66

7+
use Laminas\ServiceManager\ServiceManager;
78
use PhpDb\Adapter\Driver\Pdo\Result;
89
use PhpDb\Adapter\Driver\Pdo\Statement;
910
use PhpDb\Adapter\Driver\PdoConnectionInterface;
1011
use PhpDb\Adapter\Driver\PdoDriverInterface;
1112
use PhpDb\Adapter\Driver\ResultInterface;
1213
use PhpDb\Adapter\Driver\StatementInterface;
14+
use PhpDb\Exception\ContainerException;
1315
use PhpDb\Mysql\Pdo\Connection;
1416
use PhpDb\Mysql\Pdo\Driver;
1517
use Psr\Container\ContainerInterface;
1618

1719
final class PdoDriverInterfaceFactory
1820
{
19-
public function __invoke(ContainerInterface $container): PdoDriverInterface&Driver
20-
{
21+
public function __invoke(
22+
ContainerInterface&ServiceManager $container,
23+
string $requestedName,
24+
?array $options = null
25+
): PdoDriverInterface&Driver {
26+
if (! isset($options['connection'])) {
27+
throw ContainerException::forService(
28+
Driver::class,
29+
self::class,
30+
'$options["connection"] must contain an array of connection configuration.'
31+
);
32+
}
2133
/** @var PdoConnectionInterface&Connection $connectionInstance */
22-
$connectionInstance = $container->get(Connection::class);
34+
$connectionInstance = $container->build(Connection::class, $options);
2335

2436
/** @var StatementInterface&Statement $statementInstance */
25-
$statementInstance = $container->get(Statement::class);
37+
$statementInstance = $container->build(
38+
Statement::class,
39+
$options['options'] ?? []
40+
);
2641

2742
/** @var ResultInterface&Result $resultInstance */
28-
$resultInstance = $container->get(Result::class);
43+
$resultInstance = $container->has(ResultInterface::class)
44+
? $container->get(ResultInterface::class)
45+
: new Result();
46+
2947
return new Driver(
3048
$connectionInstance,
3149
$statementInstance,
32-
$resultInstance
50+
$resultInstance,
51+
$options['pdo_features'] ?? []
3352
);
3453
}
3554
}

src/Container/PdoResultFactory.php

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

src/Container/PdoStatementFactory.php

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,11 @@
1010

1111
final class PdoStatementFactory
1212
{
13-
public function __invoke(ContainerInterface $container): StatementInterface&Statement
14-
{
15-
/** @var array $config */
16-
$config = $container->get('config');
17-
18-
/** @var array $dbConfig */
19-
$dbConfig = $config['db'] ?? [];
20-
21-
/** @var array $options */
22-
$options = $dbConfig['options'] ?? [];
23-
13+
public function __invoke(
14+
ContainerInterface $container,
15+
string $requestedName,
16+
?array $options = null
17+
): StatementInterface&Statement {
2418
return new Statement(options: $options);
2519
}
2620
}

0 commit comments

Comments
 (0)