Invalid nullable property check for simple_array mapping type

Open
#670 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php

Research direction

Read Doctrine DBAL's src/Types/SimpleArrayType.php around line 41, then locate the Doctrine ORM property type-mapping check in this repository. Confirm how nullable simple_array fields are represented before deciding the expected validation behavior. Done means the reported mismatch is handled correctly and a regression test covers a nullable database field with a non-nullable list property.

Written by the indexing model from the issue text.

Description

Doctrine DBAL always converts the database value to a PHP array, even when the field contains null. SimpleArrayType mapper converts the null value from DB to an empty PHP array.
However, when I put a not-nullable type hint for the simple_array mapping from the nullable DB field:

/**
 * @var list<string>
 * @ORM\Column(type="simple_array", nullable=true)
 */
private $simpleArrayFromNullableField;

PHPStan check produces an error:
Property PHPStan\Rules\Doctrine\ORM\MyEntity::$simpleArrayFromNullableField type mapping mismatch: database can contain list<string>|null but property expects list<string>.

Dominant language
PHP
Stars
678
Forks
122
Avg merge
5d 18h
Merged PRs (30d)
3

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from phpstan/phpstan-doctrine

All issues in phpstan/phpstan-doctrine

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.