Skip to content

[DeadCode] Skip RemoveDefaultValueFromAssignedPropertyRector on early return in constructor-called method - #8261

Merged
TomasVotruba merged 1 commit into
mainfrom
fix-default-value-early-return-in-called-method
Aug 2, 2026
Merged

[DeadCode] Skip RemoveDefaultValueFromAssignedPropertyRector on early return in constructor-called method#8261
TomasVotruba merged 1 commit into
mainfrom
fix-default-value-early-return-in-called-method

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

RemoveDefaultValueFromAssignedPropertyRector already bails out when the constructor itself contains a return, since the assign can be skipped. But the property may also be assigned in a method called from the constructor - and that method can early return too.

Reported on this real-world case (Mautic Fetcher), where [] was wrongly removed from $unknownLeadIds / $unknownContactIds:

 class Fetcher
 {
-    private array $unknownLeadIds = [];
+    private array $unknownLeadIds;

     public function __construct(...)
     {
         $this->fetchLeads();
     }

     private function fetchLeads(): void
     {
         if (!$campaignMembers = $this->organizer->getLeadIds()) {
             return; // <-- assign never happens, property stays uninitialized
         }

         // ...
         $this->unknownLeadIds = array_values(array_diff($campaignMembers, $this->knownLeadIds));
     }
 }

After the change the whole class is skipped, as fetchLeads() may return before the assign.

@TomasVotruba
TomasVotruba enabled auto-merge (squash) August 2, 2026 10:42
@TomasVotruba
TomasVotruba merged commit 98e63f8 into main Aug 2, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the fix-default-value-early-return-in-called-method branch August 2, 2026 10:43
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