From 9f7d523811a56cb5d10afbea555beac306a63203 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Tue, 9 Sep 2025 00:53:02 -0500 Subject: [PATCH 01/13] VERY ROUGH first draft. (just makes it work) No psalm work No code cleanup No additional test Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- src/ConfigProvider.php | 12 ++++++ src/Container/ConnectionFactoryFactory.php | 47 ++++++++++++++++++++++ src/Container/DriverFactoryFactory.php | 30 ++++++++++++++ src/Container/MysqliConnectionFactory.php | 16 ++++++-- src/Container/MysqliDriverFactory.php | 23 +++++++++++ src/Container/PlatformFactoryFactory.php | 15 +++++++ src/Container/PlatformInterfaceFactory.php | 5 +++ 7 files changed, 145 insertions(+), 3 deletions(-) create mode 100644 src/Container/ConnectionFactoryFactory.php create mode 100644 src/Container/DriverFactoryFactory.php create mode 100644 src/Container/PlatformFactoryFactory.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 9eb4524..e366e5c 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -14,6 +14,7 @@ use PhpDb\Adapter\Mysql\Metadata\Source\MysqlMetadata; use PhpDb\Adapter\Platform\PlatformInterface; use PhpDb\Adapter\Profiler; +use PhpDb\Container\AdapterAbstractServiceFactory; use PhpDb\Container\AdapterManager; use PhpDb\Container\MetadataFactory; use PhpDb\Metadata\MetadataInterface; @@ -32,6 +33,9 @@ public function __invoke(): array public function getDependencies(): array { return [ + 'abstract_factories' => [ + AdapterAbstractServiceFactory::class, + ], 'aliases' => [ MetadataInterface::class => MysqlMetadata::class, ], @@ -65,6 +69,9 @@ public function getAdapterManagerConfig(): array PdoDriverInterface::class => Driver\Pdo\Pdo::class, Profiler\ProfilerInterface::class => Profiler\Profiler::class, ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, + 'ConnectionFactoryFactory' => Container\ConnectionFactoryFactory::class, + 'DriverFactoryFactory' => Container\DriverFactoryFactory::class, + 'PlatformFactoryFactory' => Container\PlatformFactoryFactory::class, ], 'factories' => [ AdapterInterface::class => Container\AdapterFactory::class, @@ -80,6 +87,11 @@ public function getAdapterManagerConfig(): array Profiler\Profiler::class => InvokableFactory::class, ResultSet\ResultSet::class => InvokableFactory::class, ], + 'invokables' => [ + Container\ConnectionFactoryFactory::class => Container\ConnectionFactoryFactory::class, + Container\DriverFactoryFactory::class => Container\DriverFactoryFactory::class, + Container\PlatformFactoryFactory::class => Container\PlatformFactoryFactory::class, + ], ]; } } diff --git a/src/Container/ConnectionFactoryFactory.php b/src/Container/ConnectionFactoryFactory.php new file mode 100644 index 0000000..6690b37 --- /dev/null +++ b/src/Container/ConnectionFactoryFactory.php @@ -0,0 +1,47 @@ +get('config')['db']['adapters'] ?? []; + if (! isset($adapterConfig[$requestedName]['driver'])) { + throw new \RuntimeException(sprintf( + 'Named adapter "%s" is not configured with a driver', + $requestedName + )); + } + $adapterServices = $container->get('config')[AdapterManager::class]; + $configuredDriver = $adapterConfig[$requestedName]['driver']; + if (array_key_exists($configuredDriver, $adapterServices['aliases'])) { + $aliasTo = $adapterServices['aliases'][$configuredDriver]; + } else { + $aliasTo = $configuredDriver; + } + return match ($aliasTo) { + Mysqli::class => new MysqliConnectionFactory(), + Pdo::class => new PdoConnectionFactory(), + default => throw new RuntimeException(sprintf( + 'No connection factory found for driver "%s"', + $configuredDriver + )), + }; + } +} diff --git a/src/Container/DriverFactoryFactory.php b/src/Container/DriverFactoryFactory.php new file mode 100644 index 0000000..f7cb60b --- /dev/null +++ b/src/Container/DriverFactoryFactory.php @@ -0,0 +1,30 @@ +get('config')['db']['adapters'] ?? []; + if (! isset($adapterConfig[$requestedName]['driver'])) { + throw new \RuntimeException(sprintf( + 'Named adapter "%s" is not configured with a driver', + $requestedName + )); + } + $adapterServices = $container->get('config')[AdapterManager::class]; + + $configuredDriver = $adapterConfig[$requestedName]['driver']; + $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; + $driverFactory = $adapterServices['factories'][$aliasTo]; + return new $driverFactory(); + } +} diff --git a/src/Container/MysqliConnectionFactory.php b/src/Container/MysqliConnectionFactory.php index 8c084ce..81397b8 100644 --- a/src/Container/MysqliConnectionFactory.php +++ b/src/Container/MysqliConnectionFactory.php @@ -4,14 +4,18 @@ namespace PhpDb\Adapter\Mysql\Container; +use Laminas\ServiceManager\Factory\FactoryInterface; use PhpDb\Adapter\Driver\ConnectionInterface; use PhpDb\Adapter\Mysql\Driver\Mysqli\Connection; use Psr\Container\ContainerInterface; -final class MysqliConnectionFactory +final class MysqliConnectionFactory implements FactoryInterface { - public function __invoke(ContainerInterface $container): ConnectionInterface&Connection - { + public function __invoke( + ContainerInterface $container, + string $requestedName, + ?array $options = null + ): ConnectionInterface&Connection { /** @var array $config */ $config = $container->get('config'); @@ -23,4 +27,10 @@ public function __invoke(ContainerInterface $container): ConnectionInterface&Con return new Connection($connectionConfig); } + + public static function createFromConfig(ContainerInterface $container, string $requestedName): ConnectionInterface&Connection + { + $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; + return new Connection($adapterConfig['connection'] ?? []); + } } diff --git a/src/Container/MysqliDriverFactory.php b/src/Container/MysqliDriverFactory.php index 310bd3a..4268950 100644 --- a/src/Container/MysqliDriverFactory.php +++ b/src/Container/MysqliDriverFactory.php @@ -41,4 +41,27 @@ public function __invoke(ContainerInterface $container): Driver\DriverInterface& $options ); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName, + ): Driver\DriverInterface&Mysqli\Mysqli { + + /** @var AdapterManager $adapterManager */ + $adapterManager = $container->get(AdapterManager::class); + $connectionFactory = ($adapterManager->get('ConnectionFactoryFactory'))($container, $requestedName); + /** @var array $config */ + $config = $container->get('config'); + /** @var array $dbConfig */ + $dbConfig = $config['db'] ?? []; + /** @var array $adapterConfig */ + $adapterConfig = $dbConfig['adapters'][$requestedName] ?? []; + + return new Mysqli\Mysqli( + $connectionFactory::createFromConfig($container, $requestedName), + $adapterManager->get(Mysqli\Statement::class), + $adapterManager->get(Mysqli\Result::class), + $adapterConfig['options'] ?? [] + ); + } } diff --git a/src/Container/PlatformFactoryFactory.php b/src/Container/PlatformFactoryFactory.php new file mode 100644 index 0000000..933353f --- /dev/null +++ b/src/Container/PlatformFactoryFactory.php @@ -0,0 +1,15 @@ + Date: Sun, 14 Sep 2025 20:37:08 -0500 Subject: [PATCH 02/13] Slight refactor to align code with php-db/phpdb Removes non class-name service identifiers Implements changes needed for AbstractAdapterServiceFactory to initialize a Pdo instance. Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- src/ConfigProvider.php | 45 ++++++++++--------- ... => ConnectionInterfaceFactoryFactory.php} | 9 ++-- ....php => DriverInterfaceFactoryFactory.php} | 9 ++-- src/Container/MysqliConnectionFactory.php | 6 ++- src/Container/MysqliDriverFactory.php | 3 +- src/Container/PdoConnectionFactory.php | 8 ++++ src/Container/PdoDriverFactory.php | 34 ++++++++++++++ src/Container/PlatformFactoryFactory.php | 15 ------- .../PlatformInterfaceFactoryFactory.php | 16 +++++++ 9 files changed, 99 insertions(+), 46 deletions(-) rename src/Container/{ConnectionFactoryFactory.php => ConnectionInterfaceFactoryFactory.php} (85%) rename src/Container/{DriverFactoryFactory.php => DriverInterfaceFactoryFactory.php} (73%) delete mode 100644 src/Container/PlatformFactoryFactory.php create mode 100644 src/Container/PlatformInterfaceFactoryFactory.php diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index e366e5c..9ba805f 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -16,6 +16,9 @@ use PhpDb\Adapter\Profiler; use PhpDb\Container\AdapterAbstractServiceFactory; use PhpDb\Container\AdapterManager; +use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface; +use PhpDb\Container\DriverInterfaceFactoryFactoryInterface; +use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; use PhpDb\Container\MetadataFactory; use PhpDb\Metadata\MetadataInterface; use PhpDb\ResultSet; @@ -54,24 +57,24 @@ public function getAdapterManagerConfig(): array { return [ 'aliases' => [ - 'MySqli' => Driver\Mysqli\Mysqli::class, - 'MySQLi' => Driver\Mysqli\Mysqli::class, - 'Mysqli' => Driver\Mysqli\Mysqli::class, - 'mysqli' => Driver\Mysqli\Mysqli::class, - 'PDO_MySQL' => Driver\Pdo\Pdo::class, - 'Pdo_MySQL' => Driver\Pdo\Pdo::class, - 'Pdo_Mysql' => Driver\Pdo\Pdo::class, - 'pdo_mysql' => Driver\Pdo\Pdo::class, - 'pdomysql' => Driver\Pdo\Pdo::class, - 'pdodriver' => Driver\Pdo\Pdo::class, - 'pdo' => Driver\Pdo\Pdo::class, - DriverInterface::class => Driver\Mysqli\Mysqli::class, - PdoDriverInterface::class => Driver\Pdo\Pdo::class, - Profiler\ProfilerInterface::class => Profiler\Profiler::class, - ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, - 'ConnectionFactoryFactory' => Container\ConnectionFactoryFactory::class, - 'DriverFactoryFactory' => Container\DriverFactoryFactory::class, - 'PlatformFactoryFactory' => Container\PlatformFactoryFactory::class, + 'MySqli' => Driver\Mysqli\Mysqli::class, + 'MySQLi' => Driver\Mysqli\Mysqli::class, + 'Mysqli' => Driver\Mysqli\Mysqli::class, + 'mysqli' => Driver\Mysqli\Mysqli::class, + 'PDO_MySQL' => Driver\Pdo\Pdo::class, + 'Pdo_MySQL' => Driver\Pdo\Pdo::class, + 'Pdo_Mysql' => Driver\Pdo\Pdo::class, + 'pdo_mysql' => Driver\Pdo\Pdo::class, + 'pdomysql' => Driver\Pdo\Pdo::class, + 'pdodriver' => Driver\Pdo\Pdo::class, + 'pdo' => Driver\Pdo\Pdo::class, + DriverInterface::class => Driver\Mysqli\Mysqli::class, + PdoDriverInterface::class => Driver\Pdo\Pdo::class, + Profiler\ProfilerInterface::class => Profiler\Profiler::class, + ResultSet\ResultSetInterface::class => ResultSet\ResultSet::class, + ConnectionInterfaceFactoryFactoryInterface::class => Container\ConnectionInterfaceFactoryFactory::class, + DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class, + PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class, ], 'factories' => [ AdapterInterface::class => Container\AdapterFactory::class, @@ -88,9 +91,9 @@ public function getAdapterManagerConfig(): array ResultSet\ResultSet::class => InvokableFactory::class, ], 'invokables' => [ - Container\ConnectionFactoryFactory::class => Container\ConnectionFactoryFactory::class, - Container\DriverFactoryFactory::class => Container\DriverFactoryFactory::class, - Container\PlatformFactoryFactory::class => Container\PlatformFactoryFactory::class, + Container\ConnectionInterfaceFactoryFactory::class => Container\ConnectionInterfaceFactoryFactory::class, + Container\DriverInterfaceFactoryFactory::class => Container\DriverInterfaceFactoryFactory::class, + Container\PlatformInterfaceFactoryFactory::class => Container\PlatformInterfaceFactoryFactory::class, ], ]; } diff --git a/src/Container/ConnectionFactoryFactory.php b/src/Container/ConnectionInterfaceFactoryFactory.php similarity index 85% rename from src/Container/ConnectionFactoryFactory.php rename to src/Container/ConnectionInterfaceFactoryFactory.php index 6690b37..4268303 100644 --- a/src/Container/ConnectionFactoryFactory.php +++ b/src/Container/ConnectionInterfaceFactoryFactory.php @@ -4,22 +4,23 @@ namespace PhpDb\Adapter\Mysql\Container; -use PhpDb\Container\AdapterManager; use PhpDb\Adapter\Mysql\Container\MysqliConnectionFactory; use PhpDb\Adapter\Mysql\Container\PdoConnectionFactory; use PhpDb\Adapter\Mysql\Driver\Mysqli\Mysqli; use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; +use PhpDb\Container\AdapterManager; +use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface as FactoryFactoryInterface; use Psr\Container\ContainerInterface; use RuntimeException; use function array_key_exists; use function sprintf; -final class ConnectionFactoryFactory +final class ConnectionInterfaceFactoryFactory implements FactoryFactoryInterface { public function __invoke( - ContainerInterface $container, - string $requestedName + ?ContainerInterface $container = null, + ?string $requestedName = null ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { diff --git a/src/Container/DriverFactoryFactory.php b/src/Container/DriverInterfaceFactoryFactory.php similarity index 73% rename from src/Container/DriverFactoryFactory.php rename to src/Container/DriverInterfaceFactoryFactory.php index f7cb60b..162c74f 100644 --- a/src/Container/DriverFactoryFactory.php +++ b/src/Container/DriverInterfaceFactoryFactory.php @@ -5,14 +5,17 @@ namespace PhpDb\Adapter\Mysql\Container; use PhpDb\Container\AdapterManager; +use PhpDb\Container\DriverInterfaceFactoryFactoryInterface as FactoryFactoryInterface; use Psr\Container\ContainerInterface; use function sprintf; -final class DriverFactoryFactory +final class DriverInterfaceFactoryFactory implements FactoryFactoryInterface { - public function __invoke(ContainerInterface $container, string $requestedName): callable - { + public function __invoke( + ?ContainerInterface $container = null, + ?string $requestedName = null + ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { throw new \RuntimeException(sprintf( diff --git a/src/Container/MysqliConnectionFactory.php b/src/Container/MysqliConnectionFactory.php index 81397b8..01117eb 100644 --- a/src/Container/MysqliConnectionFactory.php +++ b/src/Container/MysqliConnectionFactory.php @@ -28,8 +28,10 @@ public function __invoke( return new Connection($connectionConfig); } - public static function createFromConfig(ContainerInterface $container, string $requestedName): ConnectionInterface&Connection - { + public static function createFromConfig( + ContainerInterface $container, + string $requestedName + ): ConnectionInterface&Connection { $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; return new Connection($adapterConfig['connection'] ?? []); } diff --git a/src/Container/MysqliDriverFactory.php b/src/Container/MysqliDriverFactory.php index 4268950..fade802 100644 --- a/src/Container/MysqliDriverFactory.php +++ b/src/Container/MysqliDriverFactory.php @@ -5,6 +5,7 @@ namespace PhpDb\Adapter\Mysql\Container; use PhpDb\Adapter\Driver; +use PhpDb\Adapter\Mysql\Container\ConnectionInterfaceFactoryFactory as ConnectionFactoryFactory; use PhpDb\Adapter\Mysql\Driver\Mysqli; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; @@ -49,7 +50,7 @@ public static function createFromConfig( /** @var AdapterManager $adapterManager */ $adapterManager = $container->get(AdapterManager::class); - $connectionFactory = ($adapterManager->get('ConnectionFactoryFactory'))($container, $requestedName); + $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class))($container, $requestedName); /** @var array $config */ $config = $container->get('config'); /** @var array $dbConfig */ diff --git a/src/Container/PdoConnectionFactory.php b/src/Container/PdoConnectionFactory.php index 5b07458..1370281 100644 --- a/src/Container/PdoConnectionFactory.php +++ b/src/Container/PdoConnectionFactory.php @@ -23,4 +23,12 @@ public function __invoke(ContainerInterface $container): ConnectionInterface&Con return new Connection($connectionConfig); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName + ): ConnectionInterface&Connection { + $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; + return new Connection($adapterConfig['connection'] ?? []); + } } diff --git a/src/Container/PdoDriverFactory.php b/src/Container/PdoDriverFactory.php index 2d5420b..d7b1d91 100644 --- a/src/Container/PdoDriverFactory.php +++ b/src/Container/PdoDriverFactory.php @@ -37,4 +37,38 @@ public function __invoke(ContainerInterface $container): PdoDriverInterface&PdoD $resultInstance ); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName, + ): PdoDriverInterface&PdoDriver { + + /** @var AdapterManager $adapterManager */ + $adapterManager = $container->get(AdapterManager::class); + $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class ))($container, $requestedName); + /** @var array $config */ + $config = $container->get('config'); + /** @var array $dbConfig */ + $dbConfig = $config['db'] ?? []; + /** @var array $adapterConfig */ + $adapterConfig = $dbConfig['adapters'][$requestedName] ?? []; + /** @var array $options */ + $options = $adapterConfig['options'] ?? []; + + /** @var ConnectionInterface&Connection $connectionInstance */ + $connectionInstance = $connectionFactory::createFromConfig($container, $requestedName); + + /** @var StatementInterface&Statement $statementInstance */ + $statementInstance = $adapterManager->get(Statement::class); + + /** @var ResultInterface&Result $resultInstance */ + $resultInstance = $adapterManager->get(Result::class); + + return new PdoDriver( + $connectionInstance, + $statementInstance, + $resultInstance, + $options + ); + } } diff --git a/src/Container/PlatformFactoryFactory.php b/src/Container/PlatformFactoryFactory.php deleted file mode 100644 index 933353f..0000000 --- a/src/Container/PlatformFactoryFactory.php +++ /dev/null @@ -1,15 +0,0 @@ - Date: Mon, 15 Sep 2025 21:51:54 -0500 Subject: [PATCH 03/13] PhpCS and Psalm corrections Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- src/ConfigProvider.php | 21 ++++---- src/Container/AdapterFactory.php | 3 -- src/Container/AdapterManagerDelegator.php | 2 +- .../ConnectionInterfaceFactoryFactory.php | 2 +- .../DriverInterfaceFactoryFactory.php | 7 +-- src/Container/MysqliConnectionFactory.php | 8 --- src/Container/MysqliDriverFactory.php | 24 --------- src/Container/PdoConnectionFactory.php | 8 --- src/Container/PdoDriverFactory.php | 34 ------------- src/Container/PlatformInterfaceFactory.php | 5 -- src/Driver/Mysqli/Connection.php | 13 ++--- src/Driver/Mysqli/Mysqli.php | 25 ++-------- src/Driver/Mysqli/Result.php | 9 ++-- src/Driver/Mysqli/Statement.php | 7 +-- src/Driver/Pdo/Pdo.php | 4 +- src/Metadata/Source/MysqlMetadata.php | 50 +------------------ src/Platform/Mysql.php | 2 +- .../Mysql/Ddl/AlterTableDecorator.php | 2 +- .../Mysql/Ddl/CreateTableDecorator.php | 2 +- src/Sql/Platform/Mysql/Mysql.php | 2 +- src/Sql/Platform/Mysql/SelectDecorator.php | 7 ++- .../Driver/Pdo/AbstractAdapterTestCase.php | 1 - 22 files changed, 48 insertions(+), 190 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 9ba805f..d0a9c1d 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -18,8 +18,8 @@ use PhpDb\Container\AdapterManager; use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface; use PhpDb\Container\DriverInterfaceFactoryFactoryInterface; -use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; use PhpDb\Container\MetadataFactory; +use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; use PhpDb\Metadata\MetadataInterface; use PhpDb\ResultSet; @@ -39,13 +39,13 @@ public function getDependencies(): array 'abstract_factories' => [ AdapterAbstractServiceFactory::class, ], - 'aliases' => [ + 'aliases' => [ MetadataInterface::class => MysqlMetadata::class, ], - 'factories' => [ + 'factories' => [ MysqlMetadata::class => MetadataFactory::class, ], - 'delegators' => [ + 'delegators' => [ AdapterManager::class => [ Container\AdapterManagerDelegator::class, ], @@ -56,7 +56,7 @@ public function getDependencies(): array public function getAdapterManagerConfig(): array { return [ - 'aliases' => [ + 'aliases' => [ 'MySqli' => Driver\Mysqli\Mysqli::class, 'MySQLi' => Driver\Mysqli\Mysqli::class, 'Mysqli' => Driver\Mysqli\Mysqli::class, @@ -76,7 +76,7 @@ public function getAdapterManagerConfig(): array DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class, PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class, ], - 'factories' => [ + 'factories' => [ AdapterInterface::class => Container\AdapterFactory::class, Driver\Mysqli\Mysqli::class => Container\MysqliDriverFactory::class, Driver\Mysqli\Connection::class => Container\MysqliConnectionFactory::class, @@ -91,9 +91,12 @@ public function getAdapterManagerConfig(): array ResultSet\ResultSet::class => InvokableFactory::class, ], 'invokables' => [ - Container\ConnectionInterfaceFactoryFactory::class => Container\ConnectionInterfaceFactoryFactory::class, - Container\DriverInterfaceFactoryFactory::class => Container\DriverInterfaceFactoryFactory::class, - Container\PlatformInterfaceFactoryFactory::class => Container\PlatformInterfaceFactoryFactory::class, + Container\ConnectionInterfaceFactoryFactory::class + => Container\ConnectionInterfaceFactoryFactory::class, + Container\DriverInterfaceFactoryFactory::class + => Container\DriverInterfaceFactoryFactory::class, + Container\PlatformInterfaceFactoryFactory::class + => Container\PlatformInterfaceFactoryFactory::class, ], ]; } diff --git a/src/Container/AdapterFactory.php b/src/Container/AdapterFactory.php index b6b9b16..9ea2136 100644 --- a/src/Container/AdapterFactory.php +++ b/src/Container/AdapterFactory.php @@ -55,7 +55,6 @@ public function __invoke(ContainerInterface $container): AdapterInterface )); } - /** @var PlatformInterface $platformInstance */ $platformInstance = $adapterManager->get(PlatformInterface::class); if (! $adapterManager->has(ResultSetInterface::class)) { @@ -65,10 +64,8 @@ public function __invoke(ContainerInterface $container): AdapterInterface )); } - /** @var ResultSetInterface $resultSetInstance */ $resultSetInstance = $adapterManager->get(ResultSetInterface::class); - /** @var ProfilerInterface|null $profilerInstanceOrNull */ $profilerInstanceOrNull = $adapterManager->has(ProfilerInterface::class) ? $adapterManager->get(ProfilerInterface::class) : null; diff --git a/src/Container/AdapterManagerDelegator.php b/src/Container/AdapterManagerDelegator.php index 7ee69a7..c93cf39 100644 --- a/src/Container/AdapterManagerDelegator.php +++ b/src/Container/AdapterManagerDelegator.php @@ -5,7 +5,7 @@ namespace PhpDb\Adapter\Mysql\Container; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; -use PhpDB\Adapter\Mysql\ConfigProvider; +use PhpDb\Adapter\Mysql\ConfigProvider; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; diff --git a/src/Container/ConnectionInterfaceFactoryFactory.php b/src/Container/ConnectionInterfaceFactoryFactory.php index 4268303..d5f0cdf 100644 --- a/src/Container/ConnectionInterfaceFactoryFactory.php +++ b/src/Container/ConnectionInterfaceFactoryFactory.php @@ -24,7 +24,7 @@ public function __invoke( ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Named adapter "%s" is not configured with a driver', $requestedName )); diff --git a/src/Container/DriverInterfaceFactoryFactory.php b/src/Container/DriverInterfaceFactoryFactory.php index 162c74f..11190a1 100644 --- a/src/Container/DriverInterfaceFactoryFactory.php +++ b/src/Container/DriverInterfaceFactoryFactory.php @@ -7,6 +7,7 @@ use PhpDb\Container\AdapterManager; use PhpDb\Container\DriverInterfaceFactoryFactoryInterface as FactoryFactoryInterface; use Psr\Container\ContainerInterface; +use RuntimeException; use function sprintf; @@ -18,7 +19,7 @@ public function __invoke( ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Named adapter "%s" is not configured with a driver', $requestedName )); @@ -26,8 +27,8 @@ public function __invoke( $adapterServices = $container->get('config')[AdapterManager::class]; $configuredDriver = $adapterConfig[$requestedName]['driver']; - $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; - $driverFactory = $adapterServices['factories'][$aliasTo]; + $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; + $driverFactory = $adapterServices['factories'][$aliasTo]; return new $driverFactory(); } } diff --git a/src/Container/MysqliConnectionFactory.php b/src/Container/MysqliConnectionFactory.php index 01117eb..ef7b959 100644 --- a/src/Container/MysqliConnectionFactory.php +++ b/src/Container/MysqliConnectionFactory.php @@ -27,12 +27,4 @@ public function __invoke( return new Connection($connectionConfig); } - - public static function createFromConfig( - ContainerInterface $container, - string $requestedName - ): ConnectionInterface&Connection { - $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; - return new Connection($adapterConfig['connection'] ?? []); - } } diff --git a/src/Container/MysqliDriverFactory.php b/src/Container/MysqliDriverFactory.php index fade802..310bd3a 100644 --- a/src/Container/MysqliDriverFactory.php +++ b/src/Container/MysqliDriverFactory.php @@ -5,7 +5,6 @@ namespace PhpDb\Adapter\Mysql\Container; use PhpDb\Adapter\Driver; -use PhpDb\Adapter\Mysql\Container\ConnectionInterfaceFactoryFactory as ConnectionFactoryFactory; use PhpDb\Adapter\Mysql\Driver\Mysqli; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; @@ -42,27 +41,4 @@ public function __invoke(ContainerInterface $container): Driver\DriverInterface& $options ); } - - public static function createFromConfig( - ContainerInterface $container, - string $requestedName, - ): Driver\DriverInterface&Mysqli\Mysqli { - - /** @var AdapterManager $adapterManager */ - $adapterManager = $container->get(AdapterManager::class); - $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class))($container, $requestedName); - /** @var array $config */ - $config = $container->get('config'); - /** @var array $dbConfig */ - $dbConfig = $config['db'] ?? []; - /** @var array $adapterConfig */ - $adapterConfig = $dbConfig['adapters'][$requestedName] ?? []; - - return new Mysqli\Mysqli( - $connectionFactory::createFromConfig($container, $requestedName), - $adapterManager->get(Mysqli\Statement::class), - $adapterManager->get(Mysqli\Result::class), - $adapterConfig['options'] ?? [] - ); - } } diff --git a/src/Container/PdoConnectionFactory.php b/src/Container/PdoConnectionFactory.php index 1370281..5b07458 100644 --- a/src/Container/PdoConnectionFactory.php +++ b/src/Container/PdoConnectionFactory.php @@ -23,12 +23,4 @@ public function __invoke(ContainerInterface $container): ConnectionInterface&Con return new Connection($connectionConfig); } - - public static function createFromConfig( - ContainerInterface $container, - string $requestedName - ): ConnectionInterface&Connection { - $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; - return new Connection($adapterConfig['connection'] ?? []); - } } diff --git a/src/Container/PdoDriverFactory.php b/src/Container/PdoDriverFactory.php index d7b1d91..2d5420b 100644 --- a/src/Container/PdoDriverFactory.php +++ b/src/Container/PdoDriverFactory.php @@ -37,38 +37,4 @@ public function __invoke(ContainerInterface $container): PdoDriverInterface&PdoD $resultInstance ); } - - public static function createFromConfig( - ContainerInterface $container, - string $requestedName, - ): PdoDriverInterface&PdoDriver { - - /** @var AdapterManager $adapterManager */ - $adapterManager = $container->get(AdapterManager::class); - $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class ))($container, $requestedName); - /** @var array $config */ - $config = $container->get('config'); - /** @var array $dbConfig */ - $dbConfig = $config['db'] ?? []; - /** @var array $adapterConfig */ - $adapterConfig = $dbConfig['adapters'][$requestedName] ?? []; - /** @var array $options */ - $options = $adapterConfig['options'] ?? []; - - /** @var ConnectionInterface&Connection $connectionInstance */ - $connectionInstance = $connectionFactory::createFromConfig($container, $requestedName); - - /** @var StatementInterface&Statement $statementInstance */ - $statementInstance = $adapterManager->get(Statement::class); - - /** @var ResultInterface&Result $resultInstance */ - $resultInstance = $adapterManager->get(Result::class); - - return new PdoDriver( - $connectionInstance, - $statementInstance, - $resultInstance, - $options - ); - } } diff --git a/src/Container/PlatformInterfaceFactory.php b/src/Container/PlatformInterfaceFactory.php index 7edbefd..fdac197 100644 --- a/src/Container/PlatformInterfaceFactory.php +++ b/src/Container/PlatformInterfaceFactory.php @@ -33,9 +33,4 @@ public function __invoke(ContainerInterface $container): PlatformInterface&Mysql return new Mysql($driverInstance); } - - public static function fromDriver(DriverInterface $driverInstance): PlatformInterface&Mysql - { - return new Mysql($driverInstance); - } } diff --git a/src/Driver/Mysqli/Connection.php b/src/Driver/Mysqli/Connection.php index c33b2e2..f1df5df 100644 --- a/src/Driver/Mysqli/Connection.php +++ b/src/Driver/Mysqli/Connection.php @@ -1,4 +1,4 @@ -isConnected()) { $this->connect(); @@ -90,7 +94,6 @@ public function connect(): ConnectionInterface return $this; } - /** @var array $p */ $p = $this->connectionParameters; // given a list of key names, test for existence in $p @@ -105,12 +108,10 @@ public function connect(): ConnectionInterface return null; }; - /** @var string|null $hostname */ $hostname = $findParameterValue(['hostname', 'host']); $username = $findParameterValue(['username', 'user']); $password = $findParameterValue(['password', 'passwd', 'pw']); $database = $findParameterValue(['database', 'dbname', 'db', 'schema']); - /** @var int|null $port */ $port = isset($p['port']) ? (int) $p['port'] : null; /** @var string|null $socket */ $socket = $p['socket'] ?? null; diff --git a/src/Driver/Mysqli/Mysqli.php b/src/Driver/Mysqli/Mysqli.php index 12cc05a..a0f319a 100644 --- a/src/Driver/Mysqli/Mysqli.php +++ b/src/Driver/Mysqli/Mysqli.php @@ -1,4 +1,4 @@ -checkEnvironment(); - $options = array_intersect_key(array_merge($this->options, $options), $this->options); if ($this->connection instanceof DriverAwareInterface) { $this->connection->setDriver($this); @@ -61,24 +60,6 @@ public function setProfiler(ProfilerInterface $profiler): ProfilerAwareInterface return $this; } - public function getProfiler(): ?ProfilerInterface - { - return $this->profiler; - } - - /** - * Get statement prototype - */ - public function getStatementPrototype(): StatementInterface&Statement - { - return $this->statementPrototype; - } - - public function getResultPrototype(): ResultInterface&Result - { - return $this->resultPrototype; - } - public function checkEnvironment(): bool { if (! extension_loaded('mysqli')) { @@ -156,8 +137,10 @@ public function formatParameterName(string $name, ?string $type = null): string /** * Get last generated value + * + * @return bool|int|null|string */ - public function getLastGeneratedValue(): int|string|null|false + public function getLastGeneratedValue(): bool|int|string|null|string|null|false { return $this->getConnection()->getLastGeneratedValue(); } diff --git a/src/Driver/Mysqli/Result.php b/src/Driver/Mysqli/Result.php index 3efedec..88efd7d 100644 --- a/src/Driver/Mysqli/Result.php +++ b/src/Driver/Mysqli/Result.php @@ -1,4 +1,4 @@ -|numeric-string */ #[Override] - public function getAffectedRows(): int + public function getAffectedRows(): int|string { if ($this->resource instanceof mysqli || $this->resource instanceof mysqli_stmt) { return $this->resource->affected_rows; @@ -179,7 +183,6 @@ protected function loadDataFromMysqliStatement(): bool $this->statementBindValues['keys'][] = $col->name; } $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null); - $refs = []; foreach ($this->statementBindValues['values'] as $i => &$f) { $refs[$i] = &$f; } diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index a04c50c..11b79f7 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -1,4 +1,4 @@ -profiler; - } - public function initialize(\mysqli $mysqli): static { $this->mysqli = $mysqli; diff --git a/src/Driver/Pdo/Pdo.php b/src/Driver/Pdo/Pdo.php index fa89fe7..5bf8f54 100644 --- a/src/Driver/Pdo/Pdo.php +++ b/src/Driver/Pdo/Pdo.php @@ -1,4 +1,4 @@ -resultPrototype; - /** @var null $rowCount */ $rowCount = null; - /** @var string|int|bool|null $lastGeneratedValue */ $lastGeneratedValue = $this->getLastGeneratedValue(); $result->initialize($resource, $lastGeneratedValue, $rowCount); diff --git a/src/Metadata/Source/MysqlMetadata.php b/src/Metadata/Source/MysqlMetadata.php index f19bf36..d88f0ef 100644 --- a/src/Metadata/Source/MysqlMetadata.php +++ b/src/Metadata/Source/MysqlMetadata.php @@ -1,4 +1,4 @@ -data['constraint_names'][$schema])) { - return; - } - - $this->prepareDataHierarchy('constraint_names', $schema); - - $p = $this->adapter->getPlatform(); - - $isColumns = [ - ['TC', 'TABLE_NAME'], - ['TC', 'CONSTRAINT_NAME'], - ['TC', 'CONSTRAINT_TYPE'], - ]; - - array_walk($isColumns, function (&$c) use ($p) { - $c = $p->quoteIdentifierChain($c); - }); - - $sql = 'SELECT ' . implode(', ', $isColumns) - . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' - . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS']) . 'TC' - . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) - . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) - . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) - . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) - . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) - . ' IN (\'BASE TABLE\', \'VIEW\')'; - - if ($schema !== self::DEFAULT_SCHEMA) { - $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) - . ' = ' . $p->quoteTrustedValue($schema); - } else { - $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) - . ' != \'INFORMATION_SCHEMA\''; - } - - $results = $this->adapter->query($sql, AdapterInterface::QUERY_MODE_EXECUTE); - - $data = []; - foreach ($results->toArray() as $row) { - $data[] = array_change_key_case($row, CASE_LOWER); - } - - $this->data['constraint_names'][$schema] = $data; - } - protected function loadConstraintDataKeys(string $schema): void { if (isset($this->data['constraint_keys'][$schema])) { diff --git a/src/Platform/Mysql.php b/src/Platform/Mysql.php index c87a870..b497f96 100644 --- a/src/Platform/Mysql.php +++ b/src/Platform/Mysql.php @@ -1,4 +1,4 @@ -subject = $subject; } + /** + * @return void + */ protected function localizeVariables() { parent::localizeVariables(); diff --git a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php b/test/integration/Driver/Pdo/AbstractAdapterTestCase.php index 71a2ba6..ee4d537 100644 --- a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php +++ b/test/integration/Driver/Pdo/AbstractAdapterTestCase.php @@ -25,7 +25,6 @@ abstract class AbstractAdapterTestCase extends TestCase public function testConnection(): void { - /** @var ConnectionInterface $connection */ $connection = $this->getAdapter()->getDriver()->getConnection(); $this->assertInstanceOf(ConnectionInterface::class, $connection); } From 8074b5badb43f6b2586fbd6e525f2d4b2e72233b Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 22:16:03 -0500 Subject: [PATCH 04/13] Revert "PhpCS and Psalm corrections" This reverts commit 59854cbed4879b2cede565b8c45f346fe5987fb8. Signed-off-by: Joey Smith --- src/ConfigProvider.php | 21 ++++---- src/Container/AdapterFactory.php | 3 ++ src/Container/AdapterManagerDelegator.php | 2 +- .../ConnectionInterfaceFactoryFactory.php | 2 +- .../DriverInterfaceFactoryFactory.php | 7 ++- src/Container/MysqliConnectionFactory.php | 8 +++ src/Container/MysqliDriverFactory.php | 24 +++++++++ src/Container/PdoConnectionFactory.php | 8 +++ src/Container/PdoDriverFactory.php | 34 +++++++++++++ src/Container/PlatformInterfaceFactory.php | 5 ++ src/Driver/Mysqli/Connection.php | 13 +++-- src/Driver/Mysqli/Mysqli.php | 25 ++++++++-- src/Driver/Mysqli/Result.php | 9 ++-- src/Driver/Mysqli/Statement.php | 7 ++- src/Driver/Pdo/Pdo.php | 4 +- src/Metadata/Source/MysqlMetadata.php | 50 ++++++++++++++++++- src/Platform/Mysql.php | 2 +- .../Mysql/Ddl/AlterTableDecorator.php | 2 +- .../Mysql/Ddl/CreateTableDecorator.php | 2 +- src/Sql/Platform/Mysql/Mysql.php | 2 +- src/Sql/Platform/Mysql/SelectDecorator.php | 7 +-- .../Driver/Pdo/AbstractAdapterTestCase.php | 1 + 22 files changed, 190 insertions(+), 48 deletions(-) diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index d0a9c1d..9ba805f 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -18,8 +18,8 @@ use PhpDb\Container\AdapterManager; use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface; use PhpDb\Container\DriverInterfaceFactoryFactoryInterface; -use PhpDb\Container\MetadataFactory; use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; +use PhpDb\Container\MetadataFactory; use PhpDb\Metadata\MetadataInterface; use PhpDb\ResultSet; @@ -39,13 +39,13 @@ public function getDependencies(): array 'abstract_factories' => [ AdapterAbstractServiceFactory::class, ], - 'aliases' => [ + 'aliases' => [ MetadataInterface::class => MysqlMetadata::class, ], - 'factories' => [ + 'factories' => [ MysqlMetadata::class => MetadataFactory::class, ], - 'delegators' => [ + 'delegators' => [ AdapterManager::class => [ Container\AdapterManagerDelegator::class, ], @@ -56,7 +56,7 @@ public function getDependencies(): array public function getAdapterManagerConfig(): array { return [ - 'aliases' => [ + 'aliases' => [ 'MySqli' => Driver\Mysqli\Mysqli::class, 'MySQLi' => Driver\Mysqli\Mysqli::class, 'Mysqli' => Driver\Mysqli\Mysqli::class, @@ -76,7 +76,7 @@ public function getAdapterManagerConfig(): array DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class, PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class, ], - 'factories' => [ + 'factories' => [ AdapterInterface::class => Container\AdapterFactory::class, Driver\Mysqli\Mysqli::class => Container\MysqliDriverFactory::class, Driver\Mysqli\Connection::class => Container\MysqliConnectionFactory::class, @@ -91,12 +91,9 @@ public function getAdapterManagerConfig(): array ResultSet\ResultSet::class => InvokableFactory::class, ], 'invokables' => [ - Container\ConnectionInterfaceFactoryFactory::class - => Container\ConnectionInterfaceFactoryFactory::class, - Container\DriverInterfaceFactoryFactory::class - => Container\DriverInterfaceFactoryFactory::class, - Container\PlatformInterfaceFactoryFactory::class - => Container\PlatformInterfaceFactoryFactory::class, + Container\ConnectionInterfaceFactoryFactory::class => Container\ConnectionInterfaceFactoryFactory::class, + Container\DriverInterfaceFactoryFactory::class => Container\DriverInterfaceFactoryFactory::class, + Container\PlatformInterfaceFactoryFactory::class => Container\PlatformInterfaceFactoryFactory::class, ], ]; } diff --git a/src/Container/AdapterFactory.php b/src/Container/AdapterFactory.php index 9ea2136..b6b9b16 100644 --- a/src/Container/AdapterFactory.php +++ b/src/Container/AdapterFactory.php @@ -55,6 +55,7 @@ public function __invoke(ContainerInterface $container): AdapterInterface )); } + /** @var PlatformInterface $platformInstance */ $platformInstance = $adapterManager->get(PlatformInterface::class); if (! $adapterManager->has(ResultSetInterface::class)) { @@ -64,8 +65,10 @@ public function __invoke(ContainerInterface $container): AdapterInterface )); } + /** @var ResultSetInterface $resultSetInstance */ $resultSetInstance = $adapterManager->get(ResultSetInterface::class); + /** @var ProfilerInterface|null $profilerInstanceOrNull */ $profilerInstanceOrNull = $adapterManager->has(ProfilerInterface::class) ? $adapterManager->get(ProfilerInterface::class) : null; diff --git a/src/Container/AdapterManagerDelegator.php b/src/Container/AdapterManagerDelegator.php index c93cf39..7ee69a7 100644 --- a/src/Container/AdapterManagerDelegator.php +++ b/src/Container/AdapterManagerDelegator.php @@ -5,7 +5,7 @@ namespace PhpDb\Adapter\Mysql\Container; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; -use PhpDb\Adapter\Mysql\ConfigProvider; +use PhpDB\Adapter\Mysql\ConfigProvider; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; diff --git a/src/Container/ConnectionInterfaceFactoryFactory.php b/src/Container/ConnectionInterfaceFactoryFactory.php index d5f0cdf..4268303 100644 --- a/src/Container/ConnectionInterfaceFactoryFactory.php +++ b/src/Container/ConnectionInterfaceFactoryFactory.php @@ -24,7 +24,7 @@ public function __invoke( ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new RuntimeException(sprintf( + throw new \RuntimeException(sprintf( 'Named adapter "%s" is not configured with a driver', $requestedName )); diff --git a/src/Container/DriverInterfaceFactoryFactory.php b/src/Container/DriverInterfaceFactoryFactory.php index 11190a1..162c74f 100644 --- a/src/Container/DriverInterfaceFactoryFactory.php +++ b/src/Container/DriverInterfaceFactoryFactory.php @@ -7,7 +7,6 @@ use PhpDb\Container\AdapterManager; use PhpDb\Container\DriverInterfaceFactoryFactoryInterface as FactoryFactoryInterface; use Psr\Container\ContainerInterface; -use RuntimeException; use function sprintf; @@ -19,7 +18,7 @@ public function __invoke( ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new RuntimeException(sprintf( + throw new \RuntimeException(sprintf( 'Named adapter "%s" is not configured with a driver', $requestedName )); @@ -27,8 +26,8 @@ public function __invoke( $adapterServices = $container->get('config')[AdapterManager::class]; $configuredDriver = $adapterConfig[$requestedName]['driver']; - $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; - $driverFactory = $adapterServices['factories'][$aliasTo]; + $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; + $driverFactory = $adapterServices['factories'][$aliasTo]; return new $driverFactory(); } } diff --git a/src/Container/MysqliConnectionFactory.php b/src/Container/MysqliConnectionFactory.php index ef7b959..01117eb 100644 --- a/src/Container/MysqliConnectionFactory.php +++ b/src/Container/MysqliConnectionFactory.php @@ -27,4 +27,12 @@ public function __invoke( return new Connection($connectionConfig); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName + ): ConnectionInterface&Connection { + $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; + return new Connection($adapterConfig['connection'] ?? []); + } } diff --git a/src/Container/MysqliDriverFactory.php b/src/Container/MysqliDriverFactory.php index 310bd3a..fade802 100644 --- a/src/Container/MysqliDriverFactory.php +++ b/src/Container/MysqliDriverFactory.php @@ -5,6 +5,7 @@ namespace PhpDb\Adapter\Mysql\Container; use PhpDb\Adapter\Driver; +use PhpDb\Adapter\Mysql\Container\ConnectionInterfaceFactoryFactory as ConnectionFactoryFactory; use PhpDb\Adapter\Mysql\Driver\Mysqli; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; @@ -41,4 +42,27 @@ public function __invoke(ContainerInterface $container): Driver\DriverInterface& $options ); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName, + ): Driver\DriverInterface&Mysqli\Mysqli { + + /** @var AdapterManager $adapterManager */ + $adapterManager = $container->get(AdapterManager::class); + $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class))($container, $requestedName); + /** @var array $config */ + $config = $container->get('config'); + /** @var array $dbConfig */ + $dbConfig = $config['db'] ?? []; + /** @var array $adapterConfig */ + $adapterConfig = $dbConfig['adapters'][$requestedName] ?? []; + + return new Mysqli\Mysqli( + $connectionFactory::createFromConfig($container, $requestedName), + $adapterManager->get(Mysqli\Statement::class), + $adapterManager->get(Mysqli\Result::class), + $adapterConfig['options'] ?? [] + ); + } } diff --git a/src/Container/PdoConnectionFactory.php b/src/Container/PdoConnectionFactory.php index 5b07458..1370281 100644 --- a/src/Container/PdoConnectionFactory.php +++ b/src/Container/PdoConnectionFactory.php @@ -23,4 +23,12 @@ public function __invoke(ContainerInterface $container): ConnectionInterface&Con return new Connection($connectionConfig); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName + ): ConnectionInterface&Connection { + $adapterConfig = $container->get('config')['db']['adapters'][$requestedName] ?? []; + return new Connection($adapterConfig['connection'] ?? []); + } } diff --git a/src/Container/PdoDriverFactory.php b/src/Container/PdoDriverFactory.php index 2d5420b..d7b1d91 100644 --- a/src/Container/PdoDriverFactory.php +++ b/src/Container/PdoDriverFactory.php @@ -37,4 +37,38 @@ public function __invoke(ContainerInterface $container): PdoDriverInterface&PdoD $resultInstance ); } + + public static function createFromConfig( + ContainerInterface $container, + string $requestedName, + ): PdoDriverInterface&PdoDriver { + + /** @var AdapterManager $adapterManager */ + $adapterManager = $container->get(AdapterManager::class); + $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class ))($container, $requestedName); + /** @var array $config */ + $config = $container->get('config'); + /** @var array $dbConfig */ + $dbConfig = $config['db'] ?? []; + /** @var array $adapterConfig */ + $adapterConfig = $dbConfig['adapters'][$requestedName] ?? []; + /** @var array $options */ + $options = $adapterConfig['options'] ?? []; + + /** @var ConnectionInterface&Connection $connectionInstance */ + $connectionInstance = $connectionFactory::createFromConfig($container, $requestedName); + + /** @var StatementInterface&Statement $statementInstance */ + $statementInstance = $adapterManager->get(Statement::class); + + /** @var ResultInterface&Result $resultInstance */ + $resultInstance = $adapterManager->get(Result::class); + + return new PdoDriver( + $connectionInstance, + $statementInstance, + $resultInstance, + $options + ); + } } diff --git a/src/Container/PlatformInterfaceFactory.php b/src/Container/PlatformInterfaceFactory.php index fdac197..7edbefd 100644 --- a/src/Container/PlatformInterfaceFactory.php +++ b/src/Container/PlatformInterfaceFactory.php @@ -33,4 +33,9 @@ public function __invoke(ContainerInterface $container): PlatformInterface&Mysql return new Mysql($driverInstance); } + + public static function fromDriver(DriverInterface $driverInstance): PlatformInterface&Mysql + { + return new Mysql($driverInstance); + } } diff --git a/src/Driver/Mysqli/Connection.php b/src/Driver/Mysqli/Connection.php index f1df5df..c33b2e2 100644 --- a/src/Driver/Mysqli/Connection.php +++ b/src/Driver/Mysqli/Connection.php @@ -1,4 +1,4 @@ -final isConnected()) { $this->connect(); @@ -94,6 +90,7 @@ public function connect(): ConnectionInterface return $this; } + /** @var array $p */ $p = $this->connectionParameters; // given a list of key names, test for existence in $p @@ -108,10 +105,12 @@ public function connect(): ConnectionInterface return null; }; + /** @var string|null $hostname */ $hostname = $findParameterValue(['hostname', 'host']); $username = $findParameterValue(['username', 'user']); $password = $findParameterValue(['password', 'passwd', 'pw']); $database = $findParameterValue(['database', 'dbname', 'db', 'schema']); + /** @var int|null $port */ $port = isset($p['port']) ? (int) $p['port'] : null; /** @var string|null $socket */ $socket = $p['socket'] ?? null; diff --git a/src/Driver/Mysqli/Mysqli.php b/src/Driver/Mysqli/Mysqli.php index a0f319a..12cc05a 100644 --- a/src/Driver/Mysqli/Mysqli.php +++ b/src/Driver/Mysqli/Mysqli.php @@ -1,4 +1,4 @@ -final checkEnvironment(); + $options = array_intersect_key(array_merge($this->options, $options), $this->options); if ($this->connection instanceof DriverAwareInterface) { $this->connection->setDriver($this); @@ -60,6 +61,24 @@ public function setProfiler(ProfilerInterface $profiler): ProfilerAwareInterface return $this; } + public function getProfiler(): ?ProfilerInterface + { + return $this->profiler; + } + + /** + * Get statement prototype + */ + public function getStatementPrototype(): StatementInterface&Statement + { + return $this->statementPrototype; + } + + public function getResultPrototype(): ResultInterface&Result + { + return $this->resultPrototype; + } + public function checkEnvironment(): bool { if (! extension_loaded('mysqli')) { @@ -137,10 +156,8 @@ public function formatParameterName(string $name, ?string $type = null): string /** * Get last generated value - * - * @return bool|int|null|string */ - public function getLastGeneratedValue(): bool|int|string|null|string|null|false + public function getLastGeneratedValue(): int|string|null|false { return $this->getConnection()->getLastGeneratedValue(); } diff --git a/src/Driver/Mysqli/Result.php b/src/Driver/Mysqli/Result.php index 88efd7d..3efedec 100644 --- a/src/Driver/Mysqli/Result.php +++ b/src/Driver/Mysqli/Result.php @@ -1,4 +1,4 @@ -final |numeric-string */ #[Override] - public function getAffectedRows(): int|string + public function getAffectedRows(): int { if ($this->resource instanceof mysqli || $this->resource instanceof mysqli_stmt) { return $this->resource->affected_rows; @@ -183,6 +179,7 @@ protected function loadDataFromMysqliStatement(): bool $this->statementBindValues['keys'][] = $col->name; } $this->statementBindValues['values'] = array_fill(0, count($this->statementBindValues['keys']), null); + $refs = []; foreach ($this->statementBindValues['values'] as $i => &$f) { $refs[$i] = &$f; } diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index 11b79f7..a04c50c 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -1,4 +1,4 @@ -final profiler; + } + public function initialize(\mysqli $mysqli): static { $this->mysqli = $mysqli; diff --git a/src/Driver/Pdo/Pdo.php b/src/Driver/Pdo/Pdo.php index 5bf8f54..fa89fe7 100644 --- a/src/Driver/Pdo/Pdo.php +++ b/src/Driver/Pdo/Pdo.php @@ -1,4 +1,4 @@ -final resultPrototype; + /** @var null $rowCount */ $rowCount = null; + /** @var string|int|bool|null $lastGeneratedValue */ $lastGeneratedValue = $this->getLastGeneratedValue(); $result->initialize($resource, $lastGeneratedValue, $rowCount); diff --git a/src/Metadata/Source/MysqlMetadata.php b/src/Metadata/Source/MysqlMetadata.php index d88f0ef..f19bf36 100644 --- a/src/Metadata/Source/MysqlMetadata.php +++ b/src/Metadata/Source/MysqlMetadata.php @@ -1,4 +1,4 @@ -final data['constraint_names'][$schema])) { + return; + } + + $this->prepareDataHierarchy('constraint_names', $schema); + + $p = $this->adapter->getPlatform(); + + $isColumns = [ + ['TC', 'TABLE_NAME'], + ['TC', 'CONSTRAINT_NAME'], + ['TC', 'CONSTRAINT_TYPE'], + ]; + + array_walk($isColumns, function (&$c) use ($p) { + $c = $p->quoteIdentifierChain($c); + }); + + $sql = 'SELECT ' . implode(', ', $isColumns) + . ' FROM ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLES']) . 'T' + . ' INNER JOIN ' . $p->quoteIdentifierChain(['INFORMATION_SCHEMA', 'TABLE_CONSTRAINTS']) . 'TC' + . ' ON ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_SCHEMA']) + . ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_NAME']) + . ' = ' . $p->quoteIdentifierChain(['TC', 'TABLE_NAME']) + . ' WHERE ' . $p->quoteIdentifierChain(['T', 'TABLE_TYPE']) + . ' IN (\'BASE TABLE\', \'VIEW\')'; + + if ($schema !== self::DEFAULT_SCHEMA) { + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' = ' . $p->quoteTrustedValue($schema); + } else { + $sql .= ' AND ' . $p->quoteIdentifierChain(['T', 'TABLE_SCHEMA']) + . ' != \'INFORMATION_SCHEMA\''; + } + + $results = $this->adapter->query($sql, AdapterInterface::QUERY_MODE_EXECUTE); + + $data = []; + foreach ($results->toArray() as $row) { + $data[] = array_change_key_case($row, CASE_LOWER); + } + + $this->data['constraint_names'][$schema] = $data; + } + protected function loadConstraintDataKeys(string $schema): void { if (isset($this->data['constraint_keys'][$schema])) { diff --git a/src/Platform/Mysql.php b/src/Platform/Mysql.php index b497f96..c87a870 100644 --- a/src/Platform/Mysql.php +++ b/src/Platform/Mysql.php @@ -1,4 +1,4 @@ -final subject = $subject; } - /** - * @return void - */ protected function localizeVariables() { parent::localizeVariables(); diff --git a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php b/test/integration/Driver/Pdo/AbstractAdapterTestCase.php index ee4d537..71a2ba6 100644 --- a/test/integration/Driver/Pdo/AbstractAdapterTestCase.php +++ b/test/integration/Driver/Pdo/AbstractAdapterTestCase.php @@ -25,6 +25,7 @@ abstract class AbstractAdapterTestCase extends TestCase public function testConnection(): void { + /** @var ConnectionInterface $connection */ $connection = $this->getAdapter()->getDriver()->getConnection(); $this->assertInstanceOf(ConnectionInterface::class, $connection); } From 8aa5e08bce940604075b3aeeb9567c215d16a9a7 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 22:34:23 -0500 Subject: [PATCH 05/13] phpcs and psalm Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- psalm-baseline.xml | 204 ++++++++++++++---- src/ConfigProvider.php | 21 +- src/Container/AdapterManagerDelegator.php | 2 +- .../ConnectionInterfaceFactoryFactory.php | 2 +- .../DriverInterfaceFactoryFactory.php | 7 +- src/Container/MysqliDriverFactory.php | 6 +- src/Container/PdoDriverFactory.php | 5 +- src/Driver/Mysqli/Connection.php | 2 +- src/Driver/Mysqli/Mysqli.php | 2 +- src/Driver/Mysqli/Result.php | 2 +- src/Driver/Mysqli/Statement.php | 2 +- src/Driver/Pdo/Connection.php | 2 +- src/Driver/Pdo/Pdo.php | 2 +- src/Metadata/Source/MysqlMetadata.php | 2 +- src/Platform/Mysql.php | 2 +- .../Mysql/Ddl/AlterTableDecorator.php | 2 +- .../Mysql/Ddl/CreateTableDecorator.php | 2 +- src/Sql/Platform/Mysql/Mysql.php | 2 +- src/Sql/Platform/Mysql/SelectDecorator.php | 2 +- 19 files changed, 195 insertions(+), 76 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 59f46a9..8e1ee82 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,5 +1,34 @@ + + + + + + + + + + + + + + Container\ConnectionInterfaceFactoryFactory::class, + Container\DriverInterfaceFactoryFactory::class + => Container\DriverInterfaceFactoryFactory::class, + Container\PlatformInterfaceFactoryFactory::class + => Container\PlatformInterfaceFactoryFactory::class, + ]]]> + + + + + + + + @@ -7,25 +36,122 @@ - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + get(ConnectionInterfaceFactoryFactory::class) + )($container, $requestedName)]]> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + get(ConnectionInterfaceFactoryFactory::class) + )($container, $requestedName)]]> + + + + + + + + + + + + + + + + + + - - - @@ -116,25 +242,30 @@ - - - - - getConnection()->getLastGeneratedValue()]]> - - - - resultPrototype]]> + + + + + + + + + + getConnection()->getLastGeneratedValue()]]> + + + connection;]]> + @@ -143,6 +274,9 @@ + + + @@ -151,9 +285,6 @@ - - - resource->affected_rows]]> resource->num_rows]]> @@ -225,9 +356,6 @@ - - - @@ -288,9 +416,6 @@ - - - @@ -303,9 +428,6 @@ - - - @@ -480,14 +602,8 @@ - - - - - - @@ -546,9 +662,6 @@ - - - @@ -585,15 +698,7 @@ - - - - - - - - processInfo['paramPrefix']]]> processInfo['paramPrefix']]]> @@ -628,6 +733,12 @@ + + + + + + @@ -718,6 +829,9 @@ + + mysqliParams)]]> + diff --git a/src/ConfigProvider.php b/src/ConfigProvider.php index 9ba805f..d0a9c1d 100644 --- a/src/ConfigProvider.php +++ b/src/ConfigProvider.php @@ -18,8 +18,8 @@ use PhpDb\Container\AdapterManager; use PhpDb\Container\ConnectionInterfaceFactoryFactoryInterface; use PhpDb\Container\DriverInterfaceFactoryFactoryInterface; -use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; use PhpDb\Container\MetadataFactory; +use PhpDb\Container\PlatformInterfaceFactoryFactoryInterface; use PhpDb\Metadata\MetadataInterface; use PhpDb\ResultSet; @@ -39,13 +39,13 @@ public function getDependencies(): array 'abstract_factories' => [ AdapterAbstractServiceFactory::class, ], - 'aliases' => [ + 'aliases' => [ MetadataInterface::class => MysqlMetadata::class, ], - 'factories' => [ + 'factories' => [ MysqlMetadata::class => MetadataFactory::class, ], - 'delegators' => [ + 'delegators' => [ AdapterManager::class => [ Container\AdapterManagerDelegator::class, ], @@ -56,7 +56,7 @@ public function getDependencies(): array public function getAdapterManagerConfig(): array { return [ - 'aliases' => [ + 'aliases' => [ 'MySqli' => Driver\Mysqli\Mysqli::class, 'MySQLi' => Driver\Mysqli\Mysqli::class, 'Mysqli' => Driver\Mysqli\Mysqli::class, @@ -76,7 +76,7 @@ public function getAdapterManagerConfig(): array DriverInterfaceFactoryFactoryInterface::class => Container\DriverInterfaceFactoryFactory::class, PlatformInterfaceFactoryFactoryInterface::class => Container\PlatformInterfaceFactoryFactory::class, ], - 'factories' => [ + 'factories' => [ AdapterInterface::class => Container\AdapterFactory::class, Driver\Mysqli\Mysqli::class => Container\MysqliDriverFactory::class, Driver\Mysqli\Connection::class => Container\MysqliConnectionFactory::class, @@ -91,9 +91,12 @@ public function getAdapterManagerConfig(): array ResultSet\ResultSet::class => InvokableFactory::class, ], 'invokables' => [ - Container\ConnectionInterfaceFactoryFactory::class => Container\ConnectionInterfaceFactoryFactory::class, - Container\DriverInterfaceFactoryFactory::class => Container\DriverInterfaceFactoryFactory::class, - Container\PlatformInterfaceFactoryFactory::class => Container\PlatformInterfaceFactoryFactory::class, + Container\ConnectionInterfaceFactoryFactory::class + => Container\ConnectionInterfaceFactoryFactory::class, + Container\DriverInterfaceFactoryFactory::class + => Container\DriverInterfaceFactoryFactory::class, + Container\PlatformInterfaceFactoryFactory::class + => Container\PlatformInterfaceFactoryFactory::class, ], ]; } diff --git a/src/Container/AdapterManagerDelegator.php b/src/Container/AdapterManagerDelegator.php index 7ee69a7..c93cf39 100644 --- a/src/Container/AdapterManagerDelegator.php +++ b/src/Container/AdapterManagerDelegator.php @@ -5,7 +5,7 @@ namespace PhpDb\Adapter\Mysql\Container; use Laminas\ServiceManager\Factory\DelegatorFactoryInterface; -use PhpDB\Adapter\Mysql\ConfigProvider; +use PhpDb\Adapter\Mysql\ConfigProvider; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; diff --git a/src/Container/ConnectionInterfaceFactoryFactory.php b/src/Container/ConnectionInterfaceFactoryFactory.php index 4268303..d5f0cdf 100644 --- a/src/Container/ConnectionInterfaceFactoryFactory.php +++ b/src/Container/ConnectionInterfaceFactoryFactory.php @@ -24,7 +24,7 @@ public function __invoke( ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Named adapter "%s" is not configured with a driver', $requestedName )); diff --git a/src/Container/DriverInterfaceFactoryFactory.php b/src/Container/DriverInterfaceFactoryFactory.php index 162c74f..11190a1 100644 --- a/src/Container/DriverInterfaceFactoryFactory.php +++ b/src/Container/DriverInterfaceFactoryFactory.php @@ -7,6 +7,7 @@ use PhpDb\Container\AdapterManager; use PhpDb\Container\DriverInterfaceFactoryFactoryInterface as FactoryFactoryInterface; use Psr\Container\ContainerInterface; +use RuntimeException; use function sprintf; @@ -18,7 +19,7 @@ public function __invoke( ): callable { $adapterConfig = $container->get('config')['db']['adapters'] ?? []; if (! isset($adapterConfig[$requestedName]['driver'])) { - throw new \RuntimeException(sprintf( + throw new RuntimeException(sprintf( 'Named adapter "%s" is not configured with a driver', $requestedName )); @@ -26,8 +27,8 @@ public function __invoke( $adapterServices = $container->get('config')[AdapterManager::class]; $configuredDriver = $adapterConfig[$requestedName]['driver']; - $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; - $driverFactory = $adapterServices['factories'][$aliasTo]; + $aliasTo ??= $adapterServices['aliases'][$configuredDriver] ?? $configuredDriver; + $driverFactory = $adapterServices['factories'][$aliasTo]; return new $driverFactory(); } } diff --git a/src/Container/MysqliDriverFactory.php b/src/Container/MysqliDriverFactory.php index fade802..4b87376 100644 --- a/src/Container/MysqliDriverFactory.php +++ b/src/Container/MysqliDriverFactory.php @@ -5,7 +5,6 @@ namespace PhpDb\Adapter\Mysql\Container; use PhpDb\Adapter\Driver; -use PhpDb\Adapter\Mysql\Container\ConnectionInterfaceFactoryFactory as ConnectionFactoryFactory; use PhpDb\Adapter\Mysql\Driver\Mysqli; use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; @@ -47,10 +46,11 @@ public static function createFromConfig( ContainerInterface $container, string $requestedName, ): Driver\DriverInterface&Mysqli\Mysqli { - /** @var AdapterManager $adapterManager */ $adapterManager = $container->get(AdapterManager::class); - $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class))($container, $requestedName); + $connectionFactory = ( + $adapterManager->get(ConnectionInterfaceFactoryFactory::class) + )($container, $requestedName); /** @var array $config */ $config = $container->get('config'); /** @var array $dbConfig */ diff --git a/src/Container/PdoDriverFactory.php b/src/Container/PdoDriverFactory.php index d7b1d91..5e82d45 100644 --- a/src/Container/PdoDriverFactory.php +++ b/src/Container/PdoDriverFactory.php @@ -42,10 +42,11 @@ public static function createFromConfig( ContainerInterface $container, string $requestedName, ): PdoDriverInterface&PdoDriver { - /** @var AdapterManager $adapterManager */ $adapterManager = $container->get(AdapterManager::class); - $connectionFactory = ($adapterManager->get(ConnectionInterfaceFactoryFactory::class ))($container, $requestedName); + $connectionFactory = ( + $adapterManager->get(ConnectionInterfaceFactoryFactory::class) + )($container, $requestedName); /** @var array $config */ $config = $container->get('config'); /** @var array $dbConfig */ diff --git a/src/Driver/Mysqli/Connection.php b/src/Driver/Mysqli/Connection.php index c33b2e2..f580d7e 100644 --- a/src/Driver/Mysqli/Connection.php +++ b/src/Driver/Mysqli/Connection.php @@ -23,7 +23,7 @@ use const MYSQLI_CLIENT_SSL; use const MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; -class Connection extends AbstractConnection implements DriverAwareInterface +final class Connection extends AbstractConnection implements DriverAwareInterface { protected Mysqli $driver; diff --git a/src/Driver/Mysqli/Mysqli.php b/src/Driver/Mysqli/Mysqli.php index 12cc05a..e9ee6d9 100644 --- a/src/Driver/Mysqli/Mysqli.php +++ b/src/Driver/Mysqli/Mysqli.php @@ -20,7 +20,7 @@ use function extension_loaded; use function is_string; -class Mysqli implements DriverInterface, ProfilerAwareInterface +final class Mysqli implements DriverInterface, ProfilerAwareInterface { use DatabasePlatformNameTrait; diff --git a/src/Driver/Mysqli/Result.php b/src/Driver/Mysqli/Result.php index 3efedec..ce8732d 100644 --- a/src/Driver/Mysqli/Result.php +++ b/src/Driver/Mysqli/Result.php @@ -18,7 +18,7 @@ use function call_user_func_array; use function count; -class Result implements Iterator, ResultInterface +final class Result implements Iterator, ResultInterface { protected mysqli|mysqli_result|mysqli_stmt $resource; diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index a04c50c..730a068 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -20,7 +20,7 @@ use function call_user_func_array; use function is_array; -class Statement implements StatementInterface, DriverAwareInterface, ProfilerAwareInterface +final class Statement implements StatementInterface, DriverAwareInterface, ProfilerAwareInterface { protected \mysqli $mysqli; diff --git a/src/Driver/Pdo/Connection.php b/src/Driver/Pdo/Connection.php index 27033e7..152f4fc 100644 --- a/src/Driver/Pdo/Connection.php +++ b/src/Driver/Pdo/Connection.php @@ -18,7 +18,7 @@ use function is_string; use function strtolower; -class Connection extends AbstractPdoConnection +final class Connection extends AbstractPdoConnection { /** * {@inheritDoc} diff --git a/src/Driver/Pdo/Pdo.php b/src/Driver/Pdo/Pdo.php index fa89fe7..bb2e0a6 100644 --- a/src/Driver/Pdo/Pdo.php +++ b/src/Driver/Pdo/Pdo.php @@ -11,7 +11,7 @@ use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\Mysql\DatabasePlatformNameTrait; -class Pdo extends AbstractPdo +final class Pdo extends AbstractPdo { use DatabasePlatformNameTrait; diff --git a/src/Metadata/Source/MysqlMetadata.php b/src/Metadata/Source/MysqlMetadata.php index f19bf36..05e1bf8 100644 --- a/src/Metadata/Source/MysqlMetadata.php +++ b/src/Metadata/Source/MysqlMetadata.php @@ -20,7 +20,7 @@ use const CASE_LOWER; use const PREG_PATTERN_ORDER; -class MysqlMetadata extends AbstractSource +final class MysqlMetadata extends AbstractSource { /** * @throws Exception diff --git a/src/Platform/Mysql.php b/src/Platform/Mysql.php index c87a870..8c4ebfd 100644 --- a/src/Platform/Mysql.php +++ b/src/Platform/Mysql.php @@ -15,7 +15,7 @@ use function implode; use function str_replace; -class Mysql extends AbstractPlatform +final class Mysql extends AbstractPlatform { public final const PLATFORM_NAME = 'MySQL'; diff --git a/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php b/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php index 02babda..94e9d1a 100644 --- a/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php +++ b/src/Sql/Platform/Mysql/Ddl/AlterTableDecorator.php @@ -18,7 +18,7 @@ use function substr_replace; use function uksort; -class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterface +final class AlterTableDecorator extends AlterTable implements PlatformDecoratorInterface { /** @var AlterTable */ protected $subject; diff --git a/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php b/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php index 07985cf..2e7ae46 100644 --- a/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php +++ b/src/Sql/Platform/Mysql/Ddl/CreateTableDecorator.php @@ -18,7 +18,7 @@ use function substr_replace; use function uksort; -class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface +final class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface { /** @var CreateTable */ protected $subject; diff --git a/src/Sql/Platform/Mysql/Mysql.php b/src/Sql/Platform/Mysql/Mysql.php index 169699b..da8d789 100644 --- a/src/Sql/Platform/Mysql/Mysql.php +++ b/src/Sql/Platform/Mysql/Mysql.php @@ -9,7 +9,7 @@ use PhpDb\Sql\Platform\AbstractPlatform; use PhpDb\Sql\Select; -class Mysql extends AbstractPlatform +final class Mysql extends AbstractPlatform { public function __construct() { diff --git a/src/Sql/Platform/Mysql/SelectDecorator.php b/src/Sql/Platform/Mysql/SelectDecorator.php index fb5395d..785df37 100644 --- a/src/Sql/Platform/Mysql/SelectDecorator.php +++ b/src/Sql/Platform/Mysql/SelectDecorator.php @@ -10,7 +10,7 @@ use PhpDb\Sql\Platform\PlatformDecoratorInterface; use PhpDb\Sql\Select; -class SelectDecorator extends Select implements PlatformDecoratorInterface +final class SelectDecorator extends Select implements PlatformDecoratorInterface { /** @var Select */ protected $subject; From 74a97a44a6bb9e3b097c9e699eaf9b501cf1a307 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:11:17 -0500 Subject: [PATCH 06/13] Fix existing unit/integration test Bump deps Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- composer.lock | 40 +++++++++---------- src/Driver/Mysqli/Connection.php | 2 +- src/Driver/Pdo/Connection.php | 2 +- src/Driver/Pdo/Pdo.php | 2 +- .../Container/MysqliConnectionFactoryTest.php | 2 +- .../Container/TestAsset/SetupTrait.php | 2 +- 6 files changed, 25 insertions(+), 25 deletions(-) diff --git a/composer.lock b/composer.lock index 930fce5..8e9f62b 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "0a28997311306ff77626a0d7c49dc330", + "content-hash": "e5e1ef9a4473d1845705bbe6dfa7c935", "packages": [ { "name": "brick/varexporter", @@ -259,16 +259,16 @@ }, { "name": "php-db/phpdb", - "version": "0.1.0", + "version": "0.1.1", "source": { "type": "git", "url": "https://github.com/php-db/phpdb.git", - "reference": "db3f84bd1952885ded3ed2b6731e82b7e9943bf9" + "reference": "f671eabd951cd5da927ea814c8d0f83bb16247e0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/php-db/phpdb/zipball/db3f84bd1952885ded3ed2b6731e82b7e9943bf9", - "reference": "db3f84bd1952885ded3ed2b6731e82b7e9943bf9", + "url": "https://api.github.com/repos/php-db/phpdb/zipball/f671eabd951cd5da927ea814c8d0f83bb16247e0", + "reference": "f671eabd951cd5da927ea814c8d0f83bb16247e0", "shasum": "" }, "require": { @@ -321,7 +321,7 @@ "issues": "https://github.com/php-db/phpdb/issues", "source": "https://github.com/php-db/phpdb" }, - "time": "2025-08-06T05:15:11+00:00" + "time": "2025-09-15T22:14:40+00:00" }, { "name": "psr/container", @@ -2875,16 +2875,16 @@ }, { "name": "phpunit/phpunit", - "version": "11.5.36", + "version": "11.5.39", "source": { "type": "git", "url": "https://github.com/sebastianbergmann/phpunit.git", - "reference": "264a87c7ef68b1ab9af7172357740dc266df5957" + "reference": "ad5597f79d8489d2870073ac0bc0dd0ad1fa9931" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/264a87c7ef68b1ab9af7172357740dc266df5957", - "reference": "264a87c7ef68b1ab9af7172357740dc266df5957", + "url": "https://api.github.com/repos/sebastianbergmann/phpunit/zipball/ad5597f79d8489d2870073ac0bc0dd0ad1fa9931", + "reference": "ad5597f79d8489d2870073ac0bc0dd0ad1fa9931", "shasum": "" }, "require": { @@ -2956,7 +2956,7 @@ "support": { "issues": "https://github.com/sebastianbergmann/phpunit/issues", "security": "https://github.com/sebastianbergmann/phpunit/security/policy", - "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.36" + "source": "https://github.com/sebastianbergmann/phpunit/tree/11.5.39" }, "funding": [ { @@ -2980,7 +2980,7 @@ "type": "tidelift" } ], - "time": "2025-09-03T06:24:17+00:00" + "time": "2025-09-14T06:20:41+00:00" }, { "name": "psalm/plugin-phpunit", @@ -4246,16 +4246,16 @@ }, { "name": "slevomat/coding-standard", - "version": "8.22.0", + "version": "8.22.1", "source": { "type": "git", "url": "https://github.com/slevomat/coding-standard.git", - "reference": "a4cef983bad2e70125612d22b2f6e2bd1333d5c2" + "reference": "1dd80bf3b93692bedb21a6623c496887fad05fec" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/a4cef983bad2e70125612d22b2f6e2bd1333d5c2", - "reference": "a4cef983bad2e70125612d22b2f6e2bd1333d5c2", + "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/1dd80bf3b93692bedb21a6623c496887fad05fec", + "reference": "1dd80bf3b93692bedb21a6623c496887fad05fec", "shasum": "" }, "require": { @@ -4267,11 +4267,11 @@ "require-dev": { "phing/phing": "3.0.1|3.1.0", "php-parallel-lint/php-parallel-lint": "1.4.0", - "phpstan/phpstan": "2.1.22", + "phpstan/phpstan": "2.1.24", "phpstan/phpstan-deprecation-rules": "2.0.3", "phpstan/phpstan-phpunit": "2.0.7", "phpstan/phpstan-strict-rules": "2.0.6", - "phpunit/phpunit": "9.6.8|10.5.48|11.4.4|11.5.36|12.3.8" + "phpunit/phpunit": "9.6.8|10.5.48|11.4.4|11.5.36|12.3.10" }, "type": "phpcodesniffer-standard", "extra": { @@ -4295,7 +4295,7 @@ ], "support": { "issues": "https://github.com/slevomat/coding-standard/issues", - "source": "https://github.com/slevomat/coding-standard/tree/8.22.0" + "source": "https://github.com/slevomat/coding-standard/tree/8.22.1" }, "funding": [ { @@ -4307,7 +4307,7 @@ "type": "tidelift" } ], - "time": "2025-09-06T09:14:48+00:00" + "time": "2025-09-13T08:53:30+00:00" }, { "name": "spatie/array-to-xml", diff --git a/src/Driver/Mysqli/Connection.php b/src/Driver/Mysqli/Connection.php index f580d7e..c33b2e2 100644 --- a/src/Driver/Mysqli/Connection.php +++ b/src/Driver/Mysqli/Connection.php @@ -23,7 +23,7 @@ use const MYSQLI_CLIENT_SSL; use const MYSQLI_CLIENT_SSL_DONT_VERIFY_SERVER_CERT; -final class Connection extends AbstractConnection implements DriverAwareInterface +class Connection extends AbstractConnection implements DriverAwareInterface { protected Mysqli $driver; diff --git a/src/Driver/Pdo/Connection.php b/src/Driver/Pdo/Connection.php index 152f4fc..27033e7 100644 --- a/src/Driver/Pdo/Connection.php +++ b/src/Driver/Pdo/Connection.php @@ -18,7 +18,7 @@ use function is_string; use function strtolower; -final class Connection extends AbstractPdoConnection +class Connection extends AbstractPdoConnection { /** * {@inheritDoc} diff --git a/src/Driver/Pdo/Pdo.php b/src/Driver/Pdo/Pdo.php index bb2e0a6..fa89fe7 100644 --- a/src/Driver/Pdo/Pdo.php +++ b/src/Driver/Pdo/Pdo.php @@ -11,7 +11,7 @@ use PhpDb\Adapter\Driver\ResultInterface; use PhpDb\Adapter\Mysql\DatabasePlatformNameTrait; -final class Pdo extends AbstractPdo +class Pdo extends AbstractPdo { use DatabasePlatformNameTrait; diff --git a/test/integration/Container/MysqliConnectionFactoryTest.php b/test/integration/Container/MysqliConnectionFactoryTest.php index f345089..ba5ad21 100644 --- a/test/integration/Container/MysqliConnectionFactoryTest.php +++ b/test/integration/Container/MysqliConnectionFactoryTest.php @@ -28,7 +28,7 @@ public function testInvokeReturnsMysqliConnection(): void ]); $factory = new MysqliConnectionFactory(); - $connection = $factory($this->container); + $connection = $factory($this->container, Connection::class); self::assertInstanceOf(ConnectionInterface::class, $connection); self::assertInstanceOf(Connection::class, $connection); diff --git a/test/integration/Container/TestAsset/SetupTrait.php b/test/integration/Container/TestAsset/SetupTrait.php index 3b728b3..4c05c6c 100644 --- a/test/integration/Container/TestAsset/SetupTrait.php +++ b/test/integration/Container/TestAsset/SetupTrait.php @@ -12,7 +12,7 @@ use PhpDb\Adapter\Mysql\ConfigProvider; use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; use PhpDb\Container\AdapterManager; -use PhpDb\Container\ConfigProvider as LaminasDbConfigProvider; +use PhpDb\ConfigProvider as LaminasDbConfigProvider; use Psr\Container\ContainerInterface; use function getenv; From 5124b8635f7239591afc70e1de6354eabe655234 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:16:37 -0500 Subject: [PATCH 07/13] Try to exclude psalm from the 8.1 action run Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- .laminas-ci.json | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.laminas-ci.json b/.laminas-ci.json index 4e488ab..8751408 100644 --- a/.laminas-ci.json +++ b/.laminas-ci.json @@ -7,6 +7,10 @@ "name": "PHPUnit", "php": "8.1" }, + { + "name": "Psalm", + "php": "8.1" + }, { "name": "PHPUnit", "php": "8.4", From 222dde5d64f6076d6bc2ef9f751d1673d2f98ded Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:26:50 -0500 Subject: [PATCH 08/13] Signed-off-by: Joey Smith --- test/integration/Container/TestAsset/SetupTrait.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/integration/Container/TestAsset/SetupTrait.php b/test/integration/Container/TestAsset/SetupTrait.php index 4c05c6c..57fd919 100644 --- a/test/integration/Container/TestAsset/SetupTrait.php +++ b/test/integration/Container/TestAsset/SetupTrait.php @@ -11,8 +11,8 @@ use PhpDb\Adapter\Driver\DriverInterface; use PhpDb\Adapter\Mysql\ConfigProvider; use PhpDb\Adapter\Mysql\Driver\Pdo\Pdo; -use PhpDb\Container\AdapterManager; use PhpDb\ConfigProvider as LaminasDbConfigProvider; +use PhpDb\Container\AdapterManager; use Psr\Container\ContainerInterface; use function getenv; From fe3e76ce461e37536aa496aeadf8b5511cba3874 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:34:34 -0500 Subject: [PATCH 09/13] Signed-off-by: Joey Smith --- .laminas-ci.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/.laminas-ci.json b/.laminas-ci.json index 8751408..4e488ab 100644 --- a/.laminas-ci.json +++ b/.laminas-ci.json @@ -7,10 +7,6 @@ "name": "PHPUnit", "php": "8.1" }, - { - "name": "Psalm", - "php": "8.1" - }, { "name": "PHPUnit", "php": "8.4", From 0f7551fc140e235941b5a81994765b71cba22249 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:42:36 -0500 Subject: [PATCH 10/13] Make phpcs and psalm play nice Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- psalm-baseline.xml | 185 +++++++++++++++++------------------------ src/Platform/Mysql.php | 2 +- 2 files changed, 79 insertions(+), 108 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index 8e1ee82..f9047bf 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -1,34 +1,5 @@ - - - - - - - - - - - - - - Container\ConnectionInterfaceFactoryFactory::class, - Container\DriverInterfaceFactoryFactory::class - => Container\DriverInterfaceFactoryFactory::class, - Container\PlatformInterfaceFactoryFactory::class - => Container\PlatformInterfaceFactoryFactory::class, - ]]]> - - - - - - - - @@ -37,22 +8,67 @@ - - - - - + + + + + + + + + + get('config')[AdapterManager::class]]]> + + + + + + + + + + + + - + + + + + - - - - - + + + + + + get('config')[AdapterManager::class]]]> + + + + + + + + + + + + + + + + - + + + + + + + + @@ -69,31 +85,16 @@ - - - - - - - - - - - - get(ConnectionInterfaceFactoryFactory::class) - )($container, $requestedName)]]> - - - - + + + @@ -115,26 +116,12 @@ - - - - - - - - - - - get(ConnectionInterfaceFactoryFactory::class) - )($container, $requestedName)]]> - - - - + + + @@ -146,12 +133,10 @@ - - - - - + + + @@ -246,26 +231,18 @@ + + getConnection()->getLastGeneratedValue()]]> + + + + resultPrototype]]> - - - - - - - - - - getConnection()->getLastGeneratedValue()]]> - - - connection;]]> - @@ -274,9 +251,6 @@ - - - @@ -416,6 +390,9 @@ + + + @@ -602,6 +579,9 @@ + + + @@ -733,12 +713,6 @@ - - - - - - @@ -829,9 +803,6 @@ - - mysqliParams)]]> - diff --git a/src/Platform/Mysql.php b/src/Platform/Mysql.php index 8c4ebfd..c87a870 100644 --- a/src/Platform/Mysql.php +++ b/src/Platform/Mysql.php @@ -15,7 +15,7 @@ use function implode; use function str_replace; -final class Mysql extends AbstractPlatform +class Mysql extends AbstractPlatform { public final const PLATFORM_NAME = 'MySQL'; From 999c249f5e0afb58e8cd98871bf2be8e783d417b Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:47:10 -0500 Subject: [PATCH 11/13] Adjust psalm config Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- psalm-baseline.xml | 9 --------- psalm.xml.dist | 6 ++++++ 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/psalm-baseline.xml b/psalm-baseline.xml index f9047bf..5380170 100644 --- a/psalm-baseline.xml +++ b/psalm-baseline.xml @@ -134,9 +134,6 @@ - - - @@ -390,9 +387,6 @@ - - - @@ -579,9 +573,6 @@ - - - diff --git a/psalm.xml.dist b/psalm.xml.dist index a063019..d0a7d11 100644 --- a/psalm.xml.dist +++ b/psalm.xml.dist @@ -35,6 +35,12 @@ + + + + + + From c20ff4c78900a84a34cf4b080e96d6a46f47e781 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Mon, 15 Sep 2025 23:49:31 -0500 Subject: [PATCH 12/13] Bump min php-db/phpdb version to 0.1.1 Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 55effa2..b888451 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,7 @@ }, "require": { "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", - "php-db/phpdb": "^0.1.0" + "php-db/phpdb": "^0.1.1" }, "require-dev": { "ext-mysqli": "*", From a66fa66b8baf5c690935271752cfc70642451099 Mon Sep 17 00:00:00 2001 From: Joey Smith Date: Tue, 16 Sep 2025 16:14:29 -0500 Subject: [PATCH 13/13] Drop php 8.1.0 support in composer.json. Signed-off-by: Joey Smith Signed-off-by: Joey Smith --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index b888451..1f58b5a 100644 --- a/composer.json +++ b/composer.json @@ -32,7 +32,7 @@ } }, "require": { - "php": "~8.1.0 || ~8.2.0 || ~8.3.0 || ~8.4.0", + "php": "~8.2.0 || ~8.3.0 || ~8.4.0", "php-db/phpdb": "^0.1.1" }, "require-dev": {