diff --git a/composer.json b/composer.json index ebcd00980d..ccf22b1f1a 100644 --- a/composer.json +++ b/composer.json @@ -54,7 +54,7 @@ "doctrine/coding-standard": "^9.0.2 || ^14.0", "phpbench/phpbench": "^0.16.10 || ^1.0", "phpstan/extension-installer": "~1.1.0 || ^1.4", - "phpstan/phpstan": "~1.4.10 || 2.1.22", + "phpstan/phpstan": "~1.4.10 || 2.1.23", "phpstan/phpstan-deprecation-rules": "^1 || ^2", "phpunit/phpunit": "^7.5 || ^8.5 || ^9.6", "psr/log": "^1 || ^2 || ^3", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 0b966b47b7..897178a71c 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1056,6 +1056,12 @@ parameters: count: 1 path: src/Internal/HydrationCompleteHandler.php + - + message: '#^Offset int\|null might not exist on array\\.$#' + identifier: offsetAccess.notFound + count: 1 + path: src/Internal/StronglyConnectedComponents.php + - message: '#^Property Doctrine\\ORM\\Internal\\StronglyConnectedComponents\:\:\$representingNodes \(array\\) does not accept array\\.$#' identifier: assign.propertyType @@ -3594,7 +3600,7 @@ parameters: - message: '#^Property Doctrine\\ORM\\Query\\Filter\\SQLFilter\:\:\$parameters \(array\\) does not accept non\-empty\-array\\.$#' identifier: assign.propertyType - count: 1 + count: 2 path: src/Query/Filter/SQLFilter.php - @@ -4173,12 +4179,6 @@ parameters: count: 1 path: src/Tools/Console/Command/ConvertMappingCommand.php - - - message: '#^Parameter \#2 \$destPath of method Doctrine\\ORM\\Tools\\Console\\Command\\ConvertMappingCommand\:\:getExporter\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: src/Tools/Console/Command/ConvertMappingCommand.php - - message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$#' identifier: property.notFound @@ -4203,12 +4203,6 @@ parameters: count: 1 path: src/Tools/Console/Command/GenerateEntitiesCommand.php - - - message: '#^Parameter \#2 \$outputDirectory of method Doctrine\\ORM\\Tools\\EntityGenerator\:\:generate\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: src/Tools/Console/Command/GenerateEntitiesCommand.php - - message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$name\.$#' identifier: property.notFound @@ -4227,12 +4221,6 @@ parameters: count: 1 path: src/Tools/Console/Command/GenerateProxiesCommand.php - - - message: '#^Parameter \#2 \$proxyDir of method Doctrine\\ORM\\Proxy\\ProxyFactory\:\:generateProxyClasses\(\) expects string\|null, string\|false given\.$#' - identifier: argument.type - count: 1 - path: src/Tools/Console/Command/GenerateProxiesCommand.php - - message: '#^Access to an undefined property Doctrine\\Persistence\\Mapping\\ClassMetadata\:\:\$customRepositoryClassName\.$#' identifier: property.notFound @@ -4251,12 +4239,6 @@ parameters: count: 1 path: src/Tools/Console/Command/GenerateRepositoriesCommand.php - - - message: '#^Parameter \#2 \$outputDirectory of method Doctrine\\ORM\\Tools\\EntityRepositoryGenerator\:\:writeEntityRepositoryClass\(\) expects string, string\|false given\.$#' - identifier: argument.type - count: 1 - path: src/Tools/Console/Command/GenerateRepositoriesCommand.php - - message: '#^Method Doctrine\\ORM\\Tools\\Console\\Command\\MappingDescribeCommand\:\:formatMappings\(\) has parameter \$propertyMappings with no value type specified in iterable type array\.$#' identifier: missingType.iterableValue diff --git a/src/Persisters/Entity/BasicEntityPersister.php b/src/Persisters/Entity/BasicEntityPersister.php index ad29122300..75b89e2c39 100644 --- a/src/Persisters/Entity/BasicEntityPersister.php +++ b/src/Persisters/Entity/BasicEntityPersister.php @@ -1753,6 +1753,11 @@ public function getSelectConditionStatementSQL($field, $value, $assoc = null, $c $value = [$value]; } + if ($value === []) { + $selectedColumns[] = '1=0'; + continue; + } + $nullKeys = array_keys($value, null, true); $nonNullValues = array_diff_key($value, array_flip($nullKeys)); diff --git a/tests/Tests/ORM/Functional/Ticket/GH12254Test.php b/tests/Tests/ORM/Functional/Ticket/GH12254Test.php new file mode 100644 index 0000000000..6be7fefc4d --- /dev/null +++ b/tests/Tests/ORM/Functional/Ticket/GH12254Test.php @@ -0,0 +1,62 @@ +setUpEntitySchema([ + GH12254EntityA::class, + ]); + + $this->_em->persist(new GH12254EntityA()); + $this->_em->flush(); + $this->_em->clear(); + } + + public function testFindByEmptyArrayShouldReturnEmptyArray(): void + { + // pretend we are starting afresh + $this->_em = $this->getEntityManager(); + $result = $this->_em->getRepository(GH12254EntityA::class)->findBy(['id' => []]); + $this->assertEmpty($result); + } + + public function testFindByInNullableField(): void + { + $this->_em = $this->getEntityManager(); + $result = $this->_em->getRepository(GH12254EntityA::class)->findBy(['name' => []]); + $this->assertEmpty($result); + } +} + +/** + * @Entity() + */ +class GH12254EntityA +{ + /** + * @Column(type="integer") + * @Id() + * @GeneratedValue(strategy="AUTO") + * @var int + */ + public $id; + + /** + * @Column(type="string", nullable=true) + * @var string|null + */ + public $name = null; +} diff --git a/tests/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php b/tests/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php index 60ed7391f3..d9e8fe96fe 100644 --- a/tests/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php +++ b/tests/Tests/ORM/Persisters/BasicEntityPersisterTypeValueSqlTest.php @@ -129,7 +129,10 @@ public function testSelectConditionStatementNeqNull(): void self::assertEquals('test IS NOT NULL', $statement); } - /** @group DDC-3056 */ + /** + * @group DDC-3056 + * @group GH12254 + */ public function testSelectConditionStatementWithMultipleValuesContainingNull(): void { self::assertEquals( @@ -151,6 +154,11 @@ public function testSelectConditionStatementWithMultipleValuesContainingNull(): '(t0.id IN (?, ?) OR t0.id IS NULL)', $this->persister->getSelectConditionStatementSQL('id', [123, null, 234]) ); + + self::assertEquals( + '1=0', + $this->persister->getSelectConditionStatementSQL('id', []) + ); } public function testCountCondition(): void