Skip to content

[CodeQuality] Skip InlineConstructorDefaultToPropertyRector on property defined in parent, when parent::__construct() is called - #8297

Merged
TomasVotruba merged 3 commits into
mainfrom
skip-inline-constructor-parent-construct
Aug 5, 2026
Merged

[CodeQuality] Skip InlineConstructorDefaultToPropertyRector on property defined in parent, when parent::__construct() is called#8297
TomasVotruba merged 3 commits into
mainfrom
skip-inline-constructor-parent-construct

Conversation

@TomasVotruba

Copy link
Copy Markdown
Member

When parent::__construct() is called first, the parent constructor may write to a property that the child also declares. Moving the child's constructor assign to a property default flips the order — the default now applies before the parent constructor runs, so the parent's write wins instead of being overwritten.

Real-world case (Mautic Client extends FOS\OAuthServerBundle\Model\Client):

// parent
class Client implements ClientInterface
{
    protected array $allowedGrantTypes = [];

    public function __construct()
    {
        $this->allowedGrantTypes[] = OAuth2::GRANT_TYPE_AUTH_CODE;
    }
}
 class Client extends BaseClient
 {
-    protected array $allowedGrantTypes;
+    protected array $allowedGrantTypes = [OAuth2::GRANT_TYPE_AUTH_CODE, OAuth2::GRANT_TYPE_REFRESH_TOKEN];

     public function __construct()
     {
         parent::__construct();
-
-        $this->allowedGrantTypes = [
-            OAuth2::GRANT_TYPE_AUTH_CODE,
-            OAuth2::GRANT_TYPE_REFRESH_TOKEN,
-        ];
     }
 }

Before the change the value ends up [auth_code, refresh_token]; after it, the parent appends on top of the default and it becomes [auth_code, refresh_token, auth_code].

Fix

Skip the property when both hold:

  1. parent::__construct() is called above the assign
  2. the property is also defined in a parent class (checked via ReflectionProvider)

Properties owned only by the child still get inlined as before, even with a parent::__construct() call present.

…ty also defined in parent, when parent::__construct() is called
@TomasVotruba
TomasVotruba force-pushed the skip-inline-constructor-parent-construct branch from 17d862f to 96a8806 Compare August 5, 2026 21:53
@TomasVotruba
TomasVotruba merged commit a87065d into main Aug 5, 2026
64 checks passed
@TomasVotruba
TomasVotruba deleted the skip-inline-constructor-parent-construct branch August 5, 2026 22:19
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.

2 participants