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
222 changes: 0 additions & 222 deletions analyzer-baseline.toml
Original file line number Diff line number Diff line change
@@ -1,233 +1,11 @@
variant = "loose"

[[issues]]
file = "src/ConfigProvider.php"
code = "imprecise-type"
message = "Type `array` in return type of `__invoke` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/ConfigProvider.php"
code = "imprecise-type"
message = "Type `array` in return type of `getDependencies` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "imprecise-type"
message = "Type `array` in parameter `$options` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "imprecise-type"
message = "Type `array` in property `$config` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "imprecise-type"
message = "Type `array` in return type of `getConfig` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "invalid-return-statement"
message = 'Invalid return type for function `PhpDb\Container\AbstractAdapterInterfaceFactory::getConfig`: expected `array<array-key, mixed>`, but found `array<array-key, mixed>|null`.'
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "mixed-argument"
message = 'Invalid argument type for argument #2 of `Laminas\ServiceManager\ServiceManager::build`: expected `array<array-key, mixed>|null`, but found `mixed`.'
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "mixed-assignment"
message = "Assigning `mixed` type to a variable may lead to unexpected behavior."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "mixed-property-type-coercion"
message = "A value with a less specific type `nonnull` is being assigned to property `$config` (array<array-key, mixed>|null)."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "nullable-return-statement"
message = 'Function `PhpDb\Container\AbstractAdapterInterfaceFactory::getConfig` is declared to return `array<array-key, mixed>` but possibly returns a nullable value (inferred as `array<array-key, mixed>|null`).'
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "possibly-null-argument"
message = 'Argument #3 of method `PhpDb\Adapter\Adapter::__construct` is possibly `null`, but parameter type `PhpDb\ResultSet\ResultSetInterface<mixed>` does not accept it.'
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "possibly-null-array-access"
message = "Cannot perform array access on possibly `null` value."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "possibly-undefined-string-array-index"
message = "Possibly undefined array key `string` accessed on `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$driver`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$platform`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$profiler`."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "unhandled-thrown-type"
message = 'Potentially unhandled exception `Psr\Container\ContainerExceptionInterface` in `PhpDb\Container\AbstractAdapterInterfaceFactory::getConfig`.'
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "unhandled-thrown-type"
message = 'Potentially unhandled exception `Psr\Container\NotFoundExceptionInterface` in `PhpDb\Container\AbstractAdapterInterfaceFactory::getConfig`.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceDelegator.php"
code = "imprecise-type"
message = "Type `array` in parameter `$options` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceDelegator.php"
code = "imprecise-type"
message = "Type `array` in parameter `$state` is imprecise, equivalent to `array<array-key, mixed>`."
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceDelegator.php"
code = "mixed-argument"
message = 'Invalid argument type for argument #1 of `PhpDb\Container\AdapterInterfaceDelegator::__construct`: expected `string`, but found `nonnull`.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceDelegator.php"
code = "mixed-assignment"
message = "Assigning `mixed` type to a variable may lead to unexpected behavior."
count = 2

[[issues]]
file = "src/Container/AdapterInterfaceDelegator.php"
code = "unused-parameter"
message = "Parameter `$options` is never used."
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "mixed-argument"
message = 'Invalid argument type for argument #2 of `Laminas\ServiceManager\ServiceManager::build`: expected `array<array-key, mixed>|null`, but found `nonnull`.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "mixed-assignment"
message = "Assigning `nonnull` type to a variable may lead to unexpected behavior."
count = 2

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "possibly-null-argument"
message = 'Argument #1 of method `Laminas\ServiceManager\ServiceManager::build` is possibly `null`, but parameter type `class-string<PhpDb\Adapter\Driver\DriverInterface<object|resource, object|resource, object|resource>>|class-string<PhpDb\Adapter\Driver\PdoDriverInterface>|string` does not accept it.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "possibly-null-argument"
message = 'Argument #3 of method `PhpDb\Adapter\Adapter::__construct` is possibly `null`, but parameter type `PhpDb\ResultSet\ResultSetInterface<mixed>` does not accept it.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$adapterPlatform`."
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$profilerInterface`."
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "unhandled-thrown-type"
message = 'Potentially unhandled exception `Laminas\ServiceManager\Exception\ServiceNotCreatedException` in `PhpDb\Container\AdapterInterfaceFactory::__invoke`.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "unhandled-thrown-type"
message = 'Potentially unhandled exception `PhpDb\Exception\ContainerException` in `PhpDb\Container\AdapterInterfaceFactory::__invoke`.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "unhandled-thrown-type"
message = 'Potentially unhandled exception `Psr\Container\ContainerExceptionInterface` in `PhpDb\Container\AdapterInterfaceFactory::__invoke`.'
count = 1

[[issues]]
file = "src/Container/AdapterInterfaceFactory.php"
code = "unhandled-thrown-type"
message = 'Potentially unhandled exception `Psr\Container\NotFoundExceptionInterface` in `PhpDb\Container\AdapterInterfaceFactory::__invoke`.'
count = 1

[[issues]]
file = "src/ResultSet/AbstractResultSet.php"
code = "incompatible-return-type"
message = 'Return type `int|null` of `PhpDb\ResultSet\AbstractResultSet::count()` is incompatible with parent return type `int` of `Countable::count()`'
count = 1

[[issues]]
file = "src/ResultSet/AbstractResultSet.php"
code = "mixed-assignment"
message = "Assigning `mixed` type to a variable may lead to unexpected behavior."
count = 2

[[issues]]
file = "src/ResultSet/HydratingResultSet.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$row`."
count = 1

[[issues]]
file = "src/ResultSet/ObjectResultSet.php"
code = "redundant-docblock-type"
message = "Redundant docblock type for variable `$row`."
count = 1

[[issues]]
file = "src/ResultSet/RowPrototypeResultSet.php"
code = "redundant-condition"
message = "Redundant ternary operator: condition is always truthy."
count = 1

[[issues]]
file = "src/RowGateway/AbstractRowGateway.php"
code = "imprecise-type"
Expand Down
12 changes: 0 additions & 12 deletions lint-baseline.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,6 @@ code = "cyclomatic-complexity"
message = "Class has high complexity."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "no-empty"
message = "Use of the `empty` construct."
count = 1

[[issues]]
file = "src/Container/AbstractAdapterInterfaceFactory.php"
code = "no-isset"
message = "Use of the `isset` construct."
count = 1

[[issues]]
file = "src/ResultSet/AbstractResultSet.php"
code = "cyclomatic-complexity"
Expand Down
14 changes: 14 additions & 0 deletions src/ConfigProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
{
public const string NAMED_ADAPTER_KEY = 'adapters';

/**
* @return array{
* abstract_factories: list<class-string>,
* aliases: array<class-string, class-string>,
* factories: array<class-string, class-string>,
* }
*/
public function getDependencies(): array
{
return [
Expand All @@ -24,6 +31,13 @@ public function getDependencies(): array
];
}

/**
* @return array{dependencies: array{
* abstract_factories: list<class-string>,
* aliases: array<class-string, class-string>,
* factories: array<class-string, class-string>,
* }}
*/
public function __invoke(): array
{
return [
Expand Down
34 changes: 21 additions & 13 deletions src/Container/AbstractAdapterInterfaceFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,15 @@
use PhpDb\Adapter\Adapter;
use PhpDb\Adapter\AdapterInterface;
use PhpDb\Adapter\Driver\DriverInterface;
use PhpDb\Adapter\Driver\PdoDriverInterface;
use PhpDb\Adapter\Platform\PlatformInterface;
use PhpDb\Adapter\Profiler\ProfilerInterface;
use PhpDb\ConfigProvider;
use PhpDb\Exception\ContainerException;
use PhpDb\ResultSet\ResultSet;
use PhpDb\ResultSet\ResultSetInterface;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\ContainerInterface;
use Psr\Container\NotFoundExceptionInterface;

use function is_array;

Expand All @@ -30,12 +31,16 @@
*/
final class AbstractAdapterInterfaceFactory implements AbstractFactoryInterface
{
/** @var array<array-key, mixed>|null */
protected ?array $config = null;

/**
* Can we create an adapter by the requested name?
*
* @param string $requestedName
*
* @throws ContainerExceptionInterface If retrieving the config service fails.
* @throws NotFoundExceptionInterface If the config service cannot be resolved.
*/
#[Override]
public function canCreate(ContainerInterface $container, $requestedName): bool
Expand All @@ -43,18 +48,19 @@
$config = $this->getConfig($container);

if ([] === $config) {
return false;

Check warning on line 51 in src/Container/AbstractAdapterInterfaceFactory.php

View workflow job for this annotation

GitHub Actions / qa / Mutation testing

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ $config = $this->getConfig($container); if ([] === $config) { - return false; + } return is_array($config[$requestedName] ?? null) && [] !== $config[$requestedName];
}

return (
isset($config[$requestedName])
&& is_array($config[$requestedName])
&& ! empty($config[$requestedName])
);
return is_array($config[$requestedName] ?? null) && [] !== $config[$requestedName];
}

/**
* Get db configuration, if any
*
* @return array<array-key, mixed>
*
* @throws ContainerExceptionInterface If retrieving the config service fails.
* @throws NotFoundExceptionInterface If the config service cannot be resolved.
*/
protected function getConfig(ContainerInterface $container): array
{
Expand All @@ -64,9 +70,10 @@

if (! $container->has('config')) {
$this->config = [];
return $this->config;

Check warning on line 73 in src/Container/AbstractAdapterInterfaceFactory.php

View workflow job for this annotation

GitHub Actions / qa / Mutation testing

Escaped Mutant for Mutator "ReturnRemoval": @@ @@ if (! $container->has('config')) { $this->config = []; - return $this->config; + } /** @var array{'PhpDb\Adapter\AdapterInterface'?: array{adapters?: array<array-key, mixed>, ...}, ...} $config */
}

/** @var array{'PhpDb\Adapter\AdapterInterface'?: array{adapters?: array<array-key, mixed>, ...}, ...} $config */
$config = $container->get('config');
$this->config = $config[AdapterInterface::class][ConfigProvider::NAMED_ADAPTER_KEY] ?? [];
return $this->config;
Expand All @@ -79,15 +86,20 @@
* ServiceManager.
*
* @param string $requestedName
* @param array<array-key, mixed>|null $options
*
* @throws ContainerException If the named adapter has no driver configured.
* @throws ContainerExceptionInterface If a dependency cannot be built.
*/
#[Override]
public function __invoke(
ContainerInterface $container,
$requestedName,
?array $options = null,
): AdapterInterface&Adapter {
/** @var class-string<DriverInterface>|class-string<PdoDriverInterface>|null $driverClass */
$driverClass = $this->config[$requestedName]['driver'] ?? null;
/** @var array{driver?: class-string<DriverInterface>|null, ...} $adapterConfig */
$adapterConfig = $this->config[$requestedName] ?? [];
$driverClass = $adapterConfig['driver'] ?? null;

if (null === $driverClass) {
throw ContainerException::forMissingDriver($requestedName, self::class);
Expand All @@ -96,18 +108,14 @@
throw ContainerException::forNonBuildingContainer($requestedName, self::class, ServiceManager::class);
}

/** @var DriverInterface|PdoDriverInterface $driver */
$driver = $container->build($driverClass, $this->config[$requestedName]);
$driver = $container->build($driverClass, $adapterConfig);

/** @var PlatformInterface $platform */
$platform = $container->build(PlatformInterface::class, ['driver' => $driver]);

Check warning on line 113 in src/Container/AbstractAdapterInterfaceFactory.php

View workflow job for this annotation

GitHub Actions / qa / Mutation testing

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ $driver = $container->build($driverClass, $adapterConfig); - $platform = $container->build(PlatformInterface::class, ['driver' => $driver]); + $platform = $container->build(PlatformInterface::class, []); $resultSet = $container->has(ResultSetInterface::class) ? $container->build(ResultSetInterface::class)

/** @var ResultSetInterface|null $resultSet */
$resultSet = $container->has(ResultSetInterface::class)
? $container->build(ResultSetInterface::class)
: new ResultSet();

/** @var ProfilerInterface|null $profiler */
$profiler = $container->has(ProfilerInterface::class)
? $container->build(ProfilerInterface::class)
: null;
Expand Down
Loading
Loading