Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@
use Laminas\ServiceManager\Factory\InvokableFactory;
use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Driver\PdoConnectionInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\PdoConnectionInterface;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Adapter\Profiler\Profiler;
use PhpDb\Adapter\Profiler\ProfilerInterface;
Expand All @@ -34,10 +34,10 @@ public function __invoke(): array
public function getDependencies(): array
{
return [
'aliases' => [
'aliases' => [
MetadataInterface::class => Metadata\Source\SqliteMetadata::class,
],
'factories' => [
'factories' => [
Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class,
],
'delegators' => [
Expand Down
1 change: 0 additions & 1 deletion src/Container/AdapterFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,4 +81,3 @@ public function __invoke(ContainerInterface $container): AdapterInterface
);
}
}

2 changes: 1 addition & 1 deletion src/Container/MetadataInterfaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
namespace PhpDb\Adapter\Sqlite\Container;

use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata;
use PhpDb\Adapter\SchemaAwareInterface;
use PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata;
use PhpDb\Metadata\MetadataInterface;
use Psr\Container\ContainerInterface;

final class MetadataInterfaceFactory
{
public function __invoke(ContainerInterface $container): MetadataInterface&SqliteMetadata

Check failure on line 15 in src/Container/MetadataInterfaceFactory.php

View workflow job for this annotation

GitHub Actions / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidReturnType

src/Container/MetadataInterfaceFactory.php:15:62: InvalidReturnType: PhpDb\Adapter\Sqlite\Container\MetadataInterfaceFactory::__invoke is not expected to return, but it does, either implicitly or explicitly (see https://psalm.dev/011)
{
/** @var AdapterInterface&SchemaAwareInterface $adapter */
$adapter = $container->get(AdapterInterface::class);

return new SqliteMetadata(

Check failure on line 20 in src/Container/MetadataInterfaceFactory.php

View workflow job for this annotation

GitHub Actions / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidReturnStatement

src/Container/MetadataInterfaceFactory.php:20:16: InvalidReturnStatement: The inferred type 'PhpDb\Adapter\Sqlite\Metadata\Source\SqliteMetadata' does not match the declared return type 'never' for PhpDb\Adapter\Sqlite\Container\MetadataInterfaceFactory::__invoke (see https://psalm.dev/128)
$adapter
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Container/PdoDriverFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Feature\SqliteRowCounter;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Connection;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Feature\SqliteRowCounter;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo as PdoDriver;
use PhpDb\Container\AdapterManager;
use Psr\Container\ContainerInterface;

final class PdoDriverFactory
{
public function __invoke(ContainerInterface $container): PdoDriverInterface&PdoDriver

Check failure on line 21 in src/Container/PdoDriverFactory.php

View workflow job for this annotation

GitHub Actions / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidReturnType

src/Container/PdoDriverFactory.php:21:62: InvalidReturnType: PhpDb\Adapter\Sqlite\Container\PdoDriverFactory::__invoke is not expected to return, but it does, either implicitly or explicitly (see https://psalm.dev/011)
{
/** @var AdapterManager $adapterManager */
$adapterManager = $container->get(AdapterManager::class);
Expand All @@ -32,7 +32,7 @@
/** @var ResultInterface&Result $resultInstance */
$resultInstance = $adapterManager->get(Result::class);

return new PdoDriver(

Check failure on line 35 in src/Container/PdoDriverFactory.php

View workflow job for this annotation

GitHub Actions / QA Checks (Psalm [8.1, locked], ubuntu-latest, laminas/laminas-continuous-integration-action@v1, ...

InvalidReturnStatement

src/Container/PdoDriverFactory.php:35:16: InvalidReturnStatement: The inferred type 'PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo' does not match the declared return type 'never' for PhpDb\Adapter\Sqlite\Container\PdoDriverFactory::__invoke (see https://psalm.dev/128)
$connectionInstance,
$statementInstance,
$resultInstance,
Expand Down
1 change: 0 additions & 1 deletion src/Container/PdoStatementFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\ParameterContainer;
use Psr\Container\ContainerInterface;

final class PdoStatementFactory
Expand Down
2 changes: 1 addition & 1 deletion src/Container/PlatformInterfaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use PDO;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Sqlite\Platform\Sqlite;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Adapter\Sqlite\Platform\Sqlite;
use PhpDb\Container\AdapterManager;
use Psr\Container\ContainerInterface;

Expand Down
10 changes: 7 additions & 3 deletions src/Driver/Pdo/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
namespace PhpDb\Adapter\Sqlite\Driver\Pdo;

use Override;
use PDO;
use PDOException;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Driver\Pdo\AbstractPdoConnection;
use PhpDb\Adapter\Exception;
use Webmozart\Assert\Assert;

use function array_diff_key;
use function assert;
use function is_int;
use function is_string;
use function str_starts_with;
Expand Down Expand Up @@ -94,9 +96,11 @@ public function connect(): ConnectionInterface
$this->dsn = $dsn;

try {
$this->resource = new \PDO(dsn: $dsn, options: $options);
$this->resource->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
$this->driverName = strtolower($this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME));
$this->resource = new PDO(dsn: $dsn, options: $options);
$this->resource->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$driverName = $this->resource->getAttribute(PDO::ATTR_DRIVER_NAME);
assert(is_string($driverName));
$this->driverName = strtolower($driverName);
} catch (PDOException $e) {
$code = $e->getCode();
if (! is_int($code)) {
Expand Down
2 changes: 1 addition & 1 deletion src/Metadata/Source/SqliteMetadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ protected function loadConstraintData(string $table, string $schema): void
$id = $name = null;
foreach ($foreignKeys as $fk) {
if ($id !== $fk['id']) {
$id = $fk['id'];
$id = $fk['id'];
// todo: decide on whether to continue to use _laminas_
$name = '_laminas_' . $table . '_FOREIGN_KEY_' . ($id + 1);
$constraints[$name] = [
Expand Down
3 changes: 3 additions & 0 deletions src/Module.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

namespace PhpDb\Adapter\Sqlite;

/**
* @psalm-api
*/
final class Module
{
public function getConfig(): array
Expand Down
13 changes: 6 additions & 7 deletions src/Platform/Sqlite.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,19 @@
namespace PhpDb\Adapter\Sqlite\Platform;

use Override;
use PDO;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Exception;
use PhpDb\Adapter\Platform\AbstractPlatform;
use PhpDb\Sql\Platform\PlatformDecoratorInterface;
use PhpDb\Adapter\Sqlite\Driver\Pdo;
use PhpDb\Adapter\Sqlite\Sql\Platform\Sqlite as SqlPlatformDecorator;
use PhpDb\Sql\Platform\PlatformDecoratorInterface;

class Sqlite extends AbstractPlatform
{
public final const PLATFORM_NAME = 'SQLite';
/** @var string[] */
protected $quoteIdentifier = ['"', '"'];

/** @var \PDO */
/** @var PDO */
protected $resource;

/**
Expand All @@ -27,7 +26,7 @@ class Sqlite extends AbstractPlatform
protected $quoteIdentifierTo = '\'';

public function __construct(
protected readonly PdoDriverInterface|\PDO $driver
protected readonly PdoDriverInterface|PDO $driver
) {
}

Expand All @@ -43,7 +42,7 @@ public function quoteValue(string $value): string
$resource = $resource->getConnection()->getResource();
}

if ($resource instanceof \PDO) {
if ($resource instanceof PDO) {
return $resource->quote($value);
}

Expand All @@ -62,7 +61,7 @@ public function quoteTrustedValue(int|float|string|bool $value): ?string
$resource = $resource->getConnection()->getResource();
}

if ($resource instanceof \PDO) {
if ($resource instanceof PDO) {
return $resource->quote($value);
}

Expand Down
4 changes: 3 additions & 1 deletion src/Sql/Platform/Ddl/AlterTableDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Sql\Ddl\AlterTable;
use PhpDb\Sql\Ddl\Column\ColumnInterface;
use PhpDb\Sql\Platform\PlatformDecoratorInterface;

use function count;
Expand Down Expand Up @@ -147,7 +148,7 @@ protected function processChangeColumns(?PlatformInterface $adapterPlatform = nu
{
$sqls = [];

/** @var \PhpDb\Sql\Ddl\Column\ColumnInterface $column */
/** @var ColumnInterface $column */
foreach ($this->changeColumns as $name => $column) {
$sql = $this->processExpression($column, $adapterPlatform);
$insertStart = $this->getSqlInsertOffsets($sql);
Expand Down Expand Up @@ -217,6 +218,7 @@ private function normalizeColumnOption(string $name): string

/**
* phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod
*
* @psalm-suppress UnusedReturnValue
*/
private function compareColumnOptions(string $columnA, string $columnB): int
Expand Down
5 changes: 2 additions & 3 deletions src/Sql/Platform/Ddl/CreateTableDecorator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@

final class CreateTableDecorator extends CreateTable implements PlatformDecoratorInterface
{
/**
* @psalm-suppress PossiblyUnusedProperty
*/
/** @psalm-suppress PossiblyUnusedProperty */
protected CreateTable $subject;

/** @var int[] */
Expand Down Expand Up @@ -158,6 +156,7 @@ private function normalizeColumnOption(string $name): string

/**
* phpcs:ignore SlevomatCodingStandard.Classes.UnusedPrivateElements.UnusedMethod
*
* @psalm-suppress UnusedReturnValue
*/
private function compareColumnOptions(string $columnA, string $columnB): int
Expand Down
4 changes: 2 additions & 2 deletions test/integration/Container/TestAsset/SetupTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace PhpDbIntegrationTest\Adapter\Sqlite\Container\TestAsset;

use Override;
use Laminas\ServiceManager\ServiceManager;
use Laminas\Stdlib\ArrayUtils;
use Override;
use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Sqlite\ConfigProvider;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo;
use PhpDb\Container\AdapterManager;
use PhpDb\Container\ConfigProvider as LaminasDbConfigProvider;
use Psr\Container\ContainerInterface;
use PHPUnit\Framework\Attributes\RequiresPhpExtension;
use Psr\Container\ContainerInterface;

/**
* This trait provides a setup method for integration tests that require
Expand Down
13 changes: 1 addition & 12 deletions test/integration/Driver/Pdo/ConnectionIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,17 +36,6 @@ public function testGetCurrentSchema(): void
self::assertIsString($connection->getCurrentSchema());
}

// public function testSetResource(): void
// {
// $resource = $this->getAdapter()->getDriver()->getConnection()->getResource();
// $connection = new Connection([]);
// self::assertSame($connection, $connection->setResource($resource));

// $connection->disconnect();
// unset($connection);
// unset($resource);
// }

public function testGetResource(): void
{
$connection = $this->getAdapter()->getDriver()->getConnection();
Expand Down Expand Up @@ -129,7 +118,7 @@ public function testGetLastGeneratedValue(): never
public function testConnectReturnsConnectionWhenResourceSet(): void
{
/** @var PDO $resource */
$resource = $this->getAdapter()->getDriver()->getConnection()->getResource();
$resource = $this->getAdapter()->getDriver()->getConnection()->getResource();
/** @var PdoConnectionInterface&Connection $connection */
$connection = $this->getAdapter()->getDriver()->getConnection();
self::assertInstanceOf(PdoConnectionInterface::class, $connection);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/Driver/Pdo/StatementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@

use PDO;
use PDOStatement;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDbIntegrationTest\Adapter\Sqlite\Container\TestAsset\SetupTrait;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
Expand All @@ -29,7 +29,7 @@ final class StatementTest extends TestCase
public function testGetResource(): void
{
/** @var PDO $pdo */
$pdo = $this->getAdapter()->getDriver()->getConnection()->getResource();
$pdo = $this->getAdapter()->getDriver()->getConnection()->getResource();
/** @var StatementInterface&Statement $statement */
$statement = $this->getAdapter()->getDriver()->createStatement();
/** @var PDOStatement $stmt */
Expand Down
10 changes: 6 additions & 4 deletions test/unit/AdapterServiceFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,22 @@

namespace PhpDbTest\Adapter\Sqlite;

use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\ServiceManager;
use Override;
use PhpDb\Adapter\Profiler\Profiler;
use PhpDb\Adapter\Profiler\ProfilerInterface;
use PhpDb\Adapter\Sqlite\Adapter;
use PhpDb\Adapter\Sqlite\AdapterServiceFactory;
use PhpDb\Adapter\Sqlite\ConfigProvider;
use Laminas\ServiceManager\ServiceLocatorInterface;
use Laminas\ServiceManager\ServiceManager;
use Override;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\TestCase;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;

use function array_key_exists;
use function extension_loaded;
use function is_array;

#[CoversMethod(AdapterServiceFactory::class, '__invoke')]
final class AdapterServiceFactoryTest extends TestCase
Expand All @@ -24,7 +26,7 @@ final class AdapterServiceFactoryTest extends TestCase

protected function createServiceManager(array $dbConfig): ServiceLocatorInterface
{
$config = (new ConfigProvider())->getDependencies();
$config = (new ConfigProvider())->getDependencies();
if (array_key_exists('services', $config) && is_array($config['services'])) {
$config['services']['config'] = $dbConfig;
}
Expand Down
6 changes: 3 additions & 3 deletions test/unit/AdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
namespace PhpDbTest\Adapter\Sqlite;

use InvalidArgumentException;
use Override;
use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\ParameterContainer;
use PhpDb\Adapter\Profiler;
use PhpDb\ResultSet\ResultSet;
use PhpDb\ResultSet\ResultSetInterface;
use PhpDb\Adapter\Sqlite\Adapter;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Pdo;
use PhpDb\Adapter\Sqlite\Driver\Pdo\Statement;
use PhpDb\Adapter\Sqlite\Platform\Sqlite as SqlitePlatform;
use PhpDb\ResultSet\ResultSet;
use PhpDb\ResultSet\ResultSetInterface;
use PhpDbTest\Adapter\Sqlite\TestAsset\TemporaryResultSet;
use Override;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\Group;
use PHPUnit\Framework\Attributes\TestDox;
Expand Down
16 changes: 8 additions & 8 deletions test/unit/ConfigProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@

namespace PhpDbTest\Adapter\Sqlite;

use Laminas\ServiceManager\Factory\InvokableFactory;
use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Driver\ConnectionInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Driver\PdoConnectionInterface;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Adapter\Driver\StatementInterface;
use PhpDb\Adapter\Driver\Pdo\Result;
use PhpDb\Adapter\Driver\Pdo\Statement;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Adapter\Profiler\Profiler;
use PhpDb\Adapter\Profiler\ProfilerInterface;
Expand All @@ -24,7 +25,6 @@
use PhpDb\Container\AdapterManager;
use PhpDb\Metadata\MetadataInterface;
use PhpDb\ResultSet;
use Laminas\ServiceManager\Factory\InvokableFactory;
use PHPUnit\Framework\Attributes\CoversMethod;
use PHPUnit\Framework\Attributes\Depends;
use PHPUnit\Framework\TestCase;
Expand All @@ -34,12 +34,12 @@
#[CoversMethod(ConfigProvider::class, 'getAdapterManagerConfig')]
final class ConfigProviderTest extends TestCase
{
/** @var array<string, array<array-key, string>> */
/** @var array<string, array<string, string|array<int,string>>> */
private array $config = [
'aliases' => [
'aliases' => [
MetadataInterface::class => Metadata\Source\SqliteMetadata::class,
],
'factories' => [
'factories' => [
Metadata\Source\SqliteMetadata::class => Container\MetadataInterfaceFactory::class,
],
'delegators' => [
Expand Down Expand Up @@ -76,7 +76,7 @@ final class ConfigProviderTest extends TestCase
Statement::class => Container\PdoStatementFactory::class,
Platform\Sqlite::class => Container\PlatformInterfaceFactory::class,
//Profiler::class => InvokableFactory::class,
ResultSet\ResultSet::class => InvokableFactory::class,
ResultSet\ResultSet::class => InvokableFactory::class,
],
];

Expand Down
Loading
Loading