Skip to content

[TypeDeclaration] Add TypedPropertyFromContainerGetSetUpRector#8120

Merged
TomasVotruba merged 1 commit into
mainfrom
tv-typed-property-from-container-get-setup
Jun 30, 2026
Merged

[TypeDeclaration] Add TypedPropertyFromContainerGetSetUpRector#8120
TomasVotruba merged 1 commit into
mainfrom
tv-typed-property-from-container-get-setup

Conversation

@TomasVotruba

@TomasVotruba TomasVotruba commented Jun 30, 2026

Copy link
Copy Markdown
Member

Adds a new rule that promotes a private test-case property to a strict typed property based on its @var object type, when the property is assigned via a container fetch in setUp().

Only applies when all hold:

  • class is a PHPUnit test case
  • property is private, non-static, untyped, single
  • has a @var tag whose type is an existing object type
  • assigned in setUp() via a container ->get() fetch (static::getContainer()->get(), $this->container->get(), $this->get())

The @var tag is removed after promotion.

 final class BulkNotificationTest extends MauticMysqlTestCase
 {
-    /**
-     * @var BulkNotification
-     */
-    private $bulkNotification;
+    private BulkNotification $bulkNotification;

     protected function setUp(): void
     {
         parent::setUp();
         $this->bulkNotification = static::getContainer()->get('mautic.integrations.sync.notification.bulk_notification');
     }
 }

Registered in TypeDeclarationLevel just above TypedPropertyFromAssignsRector so it applies sooner.

@TomasVotruba TomasVotruba merged commit fad4926 into main Jun 30, 2026
65 checks passed
@TomasVotruba TomasVotruba deleted the tv-typed-property-from-container-get-setup branch June 30, 2026 09:46
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.

1 participant