AnnotationToAttributeRector doesn't handle optional properties properly

Created on 12 January 2025, 3 months ago

Drupal version

11.0.6

Drupal Rector version

0.20.3

Problem / Motivation

In my annotation class, I had this:

  /**
   * The directions for the plugin's links.
   *
   * Array keys are machine names, array values are labels.
   *
   * @var array
   */
  public $directions = [];

The rector rule produces this in the attribute class:

    public readonly array $directions,

This should have the same default value as in the annotation, so it's an optional attribute property.

🐛 Bug report
Status

Active

Component

Code

Created by

🇬🇧United Kingdom joachim

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024