Skip to content

Incorrect behavior of PropertyTypeFromStrictSetterGetterRector combined with ClassPropertyAssignToConstructorPromotionRector #9583

Description

@raneomik

Bug Report

Hello, I have got this issue when migrating some old code :

"System error: \"Rector\\TypeDeclaration\\NodeAnalyzer\\ClassMethodAndPropertyAnalyzer::isLocalPropertyVariableAssign(): Argument #1 ($onlyClassMethodStmt) must be of type PhpParser\\Node\\Stmt, null given, called in /var/www/vendor/rector/rector/rules/TypeDeclaration/NodeAnalyzer/ClassMethodAndPropertyAnalyzer.php on line 48

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/122b127a-762c-4551-8cac-f0d41e8886a4

<?php

class ObjectProvider
{
    private $objects;
    private $prop;

    public function __construct(iterable $objects, $prop)
    {
        $this->prop = $prop;
        foreach ($objects as $object) {
            $this->clients[$client::class] = $client;
        }
    }    

    public function getObjects(): array
    {
        return $this->objects;
    }
}

Responsible rules

  • ClassPropertyAssignToConstructorPromotionRector
  • PropertyTypeFromStrictSetterGetterRector

Expected Behavior

removing the getObjects method suggests me this without error :

 class ObjectProvider
 {
     private $objects;
-    private $prop;
 
-    public function __construct(iterable $objects, $prop)
+    public function __construct(iterable $objects, private $prop)
     {
-        $this->prop = $prop;
         foreach ($objects as $object) {
             $this->clients[$client::class] = $client;
         }
     }    
 }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions