Skip to content

Commit

Permalink
Fix build for DBAL 4
Browse files Browse the repository at this point in the history
  • Loading branch information
derrabus committed Dec 30, 2022
1 parent 57f2569 commit 0a6de30
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 11 deletions.
4 changes: 3 additions & 1 deletion lib/Doctrine/ORM/AbstractQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -1030,9 +1030,11 @@ private function getTimestampKey(): TimestampCacheKey|null
protected function getHydrationCacheId(): array
{
$parameters = [];
$types = [];

foreach ($this->getParameters() as $parameter) {
$parameters[$parameter->getName()] = $this->processParameterValue($parameter->getValue());
$types[$parameter->getType()] = $parameter->getType();
}

$sql = $this->getSQL();
Expand All @@ -1044,7 +1046,7 @@ protected function getHydrationCacheId(): array
ksort($hints);
assert($queryCacheProfile !== null);

return $queryCacheProfile->generateCacheKeys($sql, $parameters, $hints);
return $queryCacheProfile->generateCacheKeys($sql, $parameters, $types, $hints);
}

/**
Expand Down
11 changes: 6 additions & 5 deletions lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ protected function fetchVersionAndNotUpsertableValues(ClassMetadata $versionedCl
* @param mixed[] $id
*
* @return list<ParameterType|int|string>
* @psalm-return list<ParameterType::*|int|string>
* @psalm-return list<ParameterType::*|ArrayParameterType::*|string>
*/
private function extractIdentifierTypes(array $id, ClassMetadata $versionedClass): array
{
Expand Down Expand Up @@ -1812,7 +1812,7 @@ public function expandParameters(array $criteria): array
* - class to which the field belongs to
*
* @return mixed[][]
* @psalm-return array{0: array, 1: list<ParameterType::*|int|string>}
* @psalm-return array{0: array, 1: list<ParameterType::*|ArrayParameterType::*|string>}
*/
private function expandToManyParameters(array $criteria): array
{
Expand All @@ -1834,8 +1834,8 @@ private function expandToManyParameters(array $criteria): array
/**
* Infers field types to be used by parameter type casting.
*
* @return list<ParameterType|int|string>
* @psalm-return list<ParameterType::*|int|string>
* @return list<ParameterType|ArrayParameterType|int|string>
* @psalm-return list<ParameterType::*|ArrayParameterType::*|string>
*
* @throws QueryException
*/
Expand Down Expand Up @@ -1879,7 +1879,8 @@ private function getTypes(string $field, mixed $value, ClassMetadata $class): ar
return $types;
}

private function getArrayBindingType(ParameterType|int|string $type): int
/** @psalm-return ArrayParameterType::* */
private function getArrayBindingType(ParameterType|int|string $type): ArrayParameterType|int
{
if (! $type instanceof ParameterType) {
$type = Type::getType((string) $type)->getBindingType();
Expand Down
5 changes: 3 additions & 2 deletions lib/Doctrine/ORM/Persisters/Entity/EntityPersister.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\ORM\Persisters\Entity;

use Doctrine\Common\Collections\Criteria;
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\ParameterType;
use Doctrine\ORM\Mapping\ClassMetadata;
Expand Down Expand Up @@ -69,14 +70,14 @@ public function getCountSQL(array|Criteria $criteria = []): string;
*
* @param string[] $criteria
*
* @psalm-return array{list<mixed>, list<ParameterType::*|int|string>}
* @psalm-return array{list<mixed>, list<ParameterType::*|ArrayParameterType::*|string>}
*/
public function expandParameters(array $criteria): array;

/**
* Expands Criteria Parameters by walking the expressions and grabbing all parameters and types from it.
*
* @psalm-return array{list<mixed>, list<ParameterType::*|int|string>}
* @psalm-return array{list<mixed>, list<ParameterType::*|ArrayParameterType::*|string>}
*/
public function expandCriteriaParameters(Criteria $criteria): array;

Expand Down
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Query/ParameterTypeInferer.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class ParameterTypeInferer
* - Type (\Doctrine\DBAL\Types\Type::*)
* - Connection (\Doctrine\DBAL\Connection::PARAM_*)
*/
public static function inferType(mixed $value): ParameterType|int|string
public static function inferType(mixed $value): ParameterType|ArrayParameterType|int|string
{
if (is_int($value)) {
return Types::INTEGER;
Expand Down
4 changes: 4 additions & 0 deletions phpstan-dbal4.neon
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ parameters:
message: '~^Variable \$e on left side of \?\? always exists and is not nullable\.$~'
path: lib/Doctrine/ORM/UnitOfWork.php

-
message: '~^Method Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister\:\:getArrayBindingType\(\) never returns int so it can be removed from the return type\.$~'
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php

-
message: '~^Parameter #1 \$command of method Symfony\\Component\\Console\\Application::add\(\) expects Symfony\\Component\\Console\\Command\\Command, Doctrine\\DBAL\\Tools\\Console\\Command\\ReservedWordsCommand given\.$~'
path: lib/Doctrine/ORM/Tools/Console/ConsoleRunner.php
Expand Down
3 changes: 3 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ parameters:
-
message: '~^Method Doctrine\\ORM\\Query\\AST\\Functions\\TrimFunction::getTrimMode\(\) never returns .* so it can be removed from the return type\.$~'
path: lib/Doctrine/ORM/Query/AST/Functions/TrimFunction.php
-
message: '~^Method Doctrine\\ORM\\Persisters\\Entity\\BasicEntityPersister\:\:getArrayBindingType\(\) never returns .* so it can be removed from the return type\.$~'
path: lib/Doctrine/ORM/Persisters/Entity/BasicEntityPersister.php
4 changes: 2 additions & 2 deletions tests/Doctrine/Tests/ORM/Query/ParameterTypeInfererTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@

class ParameterTypeInfererTest extends OrmTestCase
{
/** @psalm-return Generator<string, array{mixed, (ParameterType|int|string)}> */
/** @psalm-return Generator<string, array{mixed, (ParameterType::*|ArrayParameterType::*|string)}> */
public function providerParameterTypeInferer(): Generator
{
yield 'integer' => [1, Types::INTEGER];
Expand All @@ -39,7 +39,7 @@ public function providerParameterTypeInferer(): Generator
}

/** @dataProvider providerParameterTypeInferer */
public function testParameterTypeInferer(mixed $value, ParameterType|int|string $expected): void
public function testParameterTypeInferer(mixed $value, ParameterType|ArrayParameterType|int|string $expected): void
{
self::assertEquals($expected, ParameterTypeInferer::inferType($value));
}
Expand Down

0 comments on commit 0a6de30

Please sign in to comment.