Skip to content

AddParamTypeFromPropertyTypeRector doesn't respect inheritance #8098

@AAllport

Description

@AAllport

Bug Report

Subject Details
Rector version v0.17.0
laravel/framework v10.16.1
laravel/socialite v5.8.0
socialiteproviders/manager v4.3.0

AddParamTypeFromPropertyTypeRector does not respect inheritance.

When using SetList::TYPE_DECLARATION in a project that has classes extending those from 3rd parties,
Rector will attempt to add a type declaration to functions that extend from their parent, triggering a fatal error due to the signature mismatching.

Minimal PHP Code Causing Issue

image

Difficult to create a demo since this issue relies on a class being read-only.
However, the above screenshot was from the following (abbreviated) code

<?php

namespace App\Providers;

class XeroSocialiteProvider extends \SocialiteProviders\Manager\OAuth2\AbstractProvider
{
    protected function getUserByToken($token)
    {
        //
    }
}

Expected Behaviour

Rector should not add the string type to the param, as it breaks the change.
Or even better, Rector should inspect the inheritance chain to fix it if it has broken (eg, due to an upgrade).

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