Skip to content

[CodeQuality] Make property nullable when null default present in TypedPropertyFromColumnTypeRector - #523

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-typed-property-null-default-non-nullable
Sep 8, 2026
Merged

TomasVotruba merged 1 commit into
mainfrom
fix-typed-property-null-default-non-nullable

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Sep 8, 2026

Copy link
Copy Markdown
Member

A property with a = null default must be nullable. When TypedPropertyFromColumnTypeRector typed such a property from a nullable=false column, it produced a non-nullable type with a = null default - a fatal error.

The default is the source of truth here: if a property defaults to null, the resolved type is made nullable regardless of the column mapping. The default value is left untouched.

 /**
  * @ORM\Column(type="datetime", nullable=false)
  */
-private $historyDate = null;
+private ?\DateTimeInterface $historyDate = null;

Fixes rectorphp/rector#9896

@TomasVotruba
TomasVotruba force-pushed the fix-typed-property-null-default-non-nullable branch from 3fdcad9 to b724ec5 Compare September 8, 2026 17:13
…edPropertyFromColumnTypeRector

A property with a `= null` default must be nullable, regardless of the
`nullable=false` column mapping. Add null to the resolved type instead of
touching the default.

Fixes rectorphp/rector#9896
@TomasVotruba
TomasVotruba force-pushed the fix-typed-property-null-default-non-nullable branch from b724ec5 to b8c86ec Compare September 8, 2026 19:15
@TomasVotruba TomasVotruba changed the title [CodeQuality] Remove null default in TypedPropertyFromColumnTypeRector when type is non-nullable [CodeQuality] Make property nullable when null default present in TypedPropertyFromColumnTypeRector Sep 8, 2026
@TomasVotruba
TomasVotruba merged commit bacd0fd into main Sep 8, 2026
7 checks passed
@TomasVotruba
TomasVotruba deleted the fix-typed-property-null-default-non-nullable branch September 8, 2026 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

TypedPropertyFromColumnTypeRector should remove initialize value when adding class as type

1 participant