Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix build for DBAL 4 #10354

Merged
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
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->getName()] = $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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is actually an interesting find. We've called this method the wrong way the whole time. 🫣

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Backported as #10355.

}

/**
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
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