Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
110 changes: 2 additions & 108 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@
<InvalidArgument>
<code><![CDATA[$this->connectionParameters]]></code>
</InvalidArgument>
<MixedArgument>
<code><![CDATA[$this->resource->getAttribute(\PDO::ATTR_DRIVER_NAME)]]></code>
</MixedArgument>
<MixedArgument/>
<MixedArgumentTypeCoercion>
<code><![CDATA[$key]]></code>
</MixedArgumentTypeCoercion>
Expand Down Expand Up @@ -80,9 +78,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Metadata/Source/SqliteMetadata.php">
<ClassMustBeFinal>
<code><![CDATA[SqliteMetadata]]></code>
</ClassMustBeFinal>
<MixedArgument>
<code><![CDATA[$fk['match']]]></code>
<code><![CDATA[$fk['on_delete']]]></code>
Expand Down Expand Up @@ -364,17 +359,9 @@
</file>
<file src="test/unit/AdapterTest.php">
<InvalidPropertyAssignmentValue>
<code><![CDATA[$this->getMockBuilder(Driver::class)
->setConstructorArgs([
$this->mockConnection,
$this->mockStatement,
])
->getMock()]]></code>
<code><![CDATA[$this->getMockBuilder(Statement::class)->getMock()]]></code>
</InvalidPropertyAssignmentValue>
<MixedArgument>
<code><![CDATA[Driver::class]]></code>
<code><![CDATA[Driver::class]]></code>
<code><![CDATA[Statement::class]]></code>
</MixedArgument>
<MixedAssignment>
Expand Down Expand Up @@ -432,56 +419,13 @@
<code><![CDATA[Adapter]]></code>
<code><![CDATA[Adapter]]></code>
<code><![CDATA[Adapter]]></code>
<code><![CDATA[Driver]]></code>
<code><![CDATA[Driver]]></code>
<code><![CDATA[Statement]]></code>
</UndefinedClass>
<UnusedPsalmSuppress>
<code><![CDATA[UndefinedMagicPropertyFetch]]></code>
<code><![CDATA[UndefinedMagicPropertyFetch]]></code>
</UnusedPsalmSuppress>
</file>
<file src="test/unit/ConfigProviderTest.php">
<MixedPropertyTypeCoercion>
<code><![CDATA[[
'aliases' => [
PlatformInterface::class => Platform\Sqlite::class,
ProfilerInterface::class => Profiler::class,
],
'factories' => [
AdapterInterface::class => AdapterServiceFactory::class,
DriverInterface::class => Driver\Pdo\DriverFactory::class,
Platform\Sqlite::class => InvokableFactory::class,
Profiler::class => InvokableFactory::class,
],
]]]></code>
</MixedPropertyTypeCoercion>
<UndefinedClass>
<code><![CDATA[AdapterServiceFactory]]></code>
<code><![CDATA[Driver\Pdo\DriverFactory]]></code>
</UndefinedClass>
</file>
<file src="test/unit/Driver/Pdo/PdoTest.php">
<MixedAssignment>
<code><![CDATA[$result]]></code>
<code><![CDATA[$this->pdo]]></code>
</MixedAssignment>
<MixedMethodCall>
<code><![CDATA[setConnectionParameters]]></code>
</MixedMethodCall>
<UndefinedClass>
<code><![CDATA[$this->pdo]]></code>
<code><![CDATA[$this->pdo]]></code>
<code><![CDATA[$this->pdo]]></code>
<code><![CDATA[$this->pdo]]></code>
<code><![CDATA[$this->pdo]]></code>
<code><![CDATA[$this->pdo]]></code>
<code><![CDATA[Driver]]></code>
<code><![CDATA[Driver]]></code>
<code><![CDATA[Driver]]></code>
<code><![CDATA[Driver]]></code>
</UndefinedClass>
</file>
<file src="test/unit/Driver/Pdo/ResultTest.php">
<InvalidArrayOffset>
<code><![CDATA[$data[$position++]]]></code>
Expand All @@ -490,17 +434,6 @@
<code><![CDATA[function () use ($data, &$position) {]]></code>
</MissingClosureReturnType>
</file>
<file src="test/unit/Driver/Pdo/StatementIntegrationTest.php">
<InvalidArgument>
<code><![CDATA[$driver]]></code>
</InvalidArgument>
<MixedArgument>
<code><![CDATA[Driver::class]]></code>
</MixedArgument>
<UndefinedClass>
<code><![CDATA[Driver]]></code>
</UndefinedClass>
</file>
<file src="test/unit/Driver/Pdo/StatementTest.php">
<MixedArgument>
<code><![CDATA[new Driver(new Connection())]]></code>
Expand All @@ -509,47 +442,8 @@
<code><![CDATA[Driver]]></code>
</UndefinedClass>
</file>
<file src="test/unit/ModuleTest.php">
<MixedPropertyTypeCoercion>
<code><![CDATA[[
'aliases' => [
PlatformInterface::class => Platform\Sqlite::class,
ProfilerInterface::class => Profiler::class,
],
'factories' => [
AdapterInterface::class => AdapterServiceFactory::class,
DriverInterface::class => Driver\Pdo\DriverFactory::class,
Platform\Sqlite::class => InvokableFactory::class,
Profiler::class => InvokableFactory::class,
],
]]]></code>
</MixedPropertyTypeCoercion>
<UndefinedClass>
<code><![CDATA[AdapterServiceFactory]]></code>
<code><![CDATA[Driver\Pdo\DriverFactory]]></code>
</UndefinedClass>
</file>
<file src="test/unit/Platform/SqliteTest.php">
<InvalidArgument>
<code><![CDATA[function ($errno, $errstr) use (&$raisedNotice) {
$this->assertEquals(E_USER_NOTICE, $errno);
$this->assertEquals(
$errstr,
'Attempting to quote a value in PhpDb\Adapter\Sqlite\Platform\Sqlite without extension/driver support can '
. 'introduce security vulnerabilities in a production environment'
);
$raisedNotice = true;
}]]></code>
<code><![CDATA[function ($errno, $errstr) use (&$raisedNotice) {
$this->assertEquals(E_USER_NOTICE, $errno);
$this->assertEquals(
$errstr,
'Attempting to quote a value in PhpDb\Adapter\Sqlite\Platform\Sqlite without extension/driver support can '
. 'introduce security vulnerabilities in a production environment'
);
$raisedNotice = true;
}]]></code>
</InvalidArgument>
<InvalidArgument/>
<MixedAssignment>
<code><![CDATA[$driver]]></code>
</MixedAssignment>
Expand Down
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,8 +5,8 @@
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;

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,8 +10,8 @@
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;
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/Driver/Pdo/Pdo.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use PhpDb\Adapter\Driver\ResultInterface;
use PhpDb\Adapter\Sqlite\Driver\DatabasePlatformNameTrait;

final class Pdo extends AbstractPdo implements DriverFeatureProviderInterface
class Pdo extends AbstractPdo implements DriverFeatureProviderInterface
{
use DatabasePlatformNameTrait;
use DriverFeatureProviderTrait;
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
9 changes: 4 additions & 5 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 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
Loading