Skip to content

Incorrect behavior of TypedPropertyFromColumnTypeRector on nullable property default value #7830

@gaelreyrol

Description

@gaelreyrol

Bug Report

Hi!

The TypedPropertyFromColumnTypeRector rule is not taking into account the default value of the Column nullable property.

When the NullabilityColumnPropertyTypeResolver class resolves the value from the annotation, if the value is not configured (because it matches the default value), the resolver does not look at the annotation default value itself. Which result in a nullable property where it should not.

Subject Details
Rector version last dev-main
Installed as composer dependency

Minimal PHP Code Causing Issue

See https://getrector.com/demo/cf1b2f7a-8064-488a-b580-bf111aa26dd5

<?php

use Doctrine\ORM\Mapping as ORM;

/**
 * @ORM\Entity
 */
final class DemoFile
{
    /**
     * @var string $id
     *
     * @ORM\Column(name="id", type="bigint")
     * @ORM\Id
     * @ORM\GeneratedValue(strategy="AUTO")
     */
    private $id;
}

Responsible rules

  • TypedPropertyFromColumnTypeRector

Actual Behavior

@@ -14,5 +14,5 @@
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      */
-    private $id;
+    private ?string $id = null;
 }

Expected Behavior

@@ -14,5 +14,5 @@
      * @ORM\Id
      * @ORM\GeneratedValue(strategy="AUTO")
      */
-    private $id;
+    private string $id = null;
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions