Skip to content

Crash and Incorrect behavior of AddParamBasedOnParentClassMethodRector #8149

@klimslim

Description

@klimslim

Bug Report

Rector crashes with PHPStan exception

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/e913f712-f893-4504-a26d-1e73c3892e0d

<?php

class Foo{
    public function baz($default = []) {
        return implode('', $default);
    }
    
    public function boo($default = '') {
        return $default;
    }
}

class Bar extends Foo {
    public function baz() {
        echo parent::baz();
    }
    
    public function boo() {
        echo parent::boo();
    }
}

Responsible rules

  • AddParamBasedOnParentClassMethodRector

Expected Behavior

It should not crash and should produce the following diff:

@@ -11,11 +11,11 @@
 }
 
 class Bar extends Foo {
-    public function baz() {
+    public function baz($default = []) {
         echo parent::baz();
     }
     
-    public function boo() {
+    public function boo($default = '') {
         echo parent::boo();
     }
 }

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions