Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Argument type declaration unnecessarily removed #6611

Closed
devbanana opened this issue Aug 3, 2021 · 1 comment · Fixed by rectorphp/rector-src#591
Closed

Argument type declaration unnecessarily removed #6611

devbanana opened this issue Aug 3, 2021 · 1 comment · Fixed by rectorphp/rector-src#591
Labels

Comments

@devbanana
Copy link

Bug Report

Subject Details
Rector version 0.11.42

I'm having an odd bug which I have been able to reproduce. If I enable Option::AUTO_IMPORT_NAMES, then enable the sets DowngradeTypedPropertyRector and DowngradeMixedTypeDeclarationRector, function arguments with the same type declaration as a property will be stripped of their typed declaration, and an @param will be added with type mixed.

See code example for more clarity.

Minimal PHP Code Causing Issue

In test.php:

<?php
namespace First;
class SomeClass {}

namespace Second;
use First\SomeClass;

class AnotherClass
{
    private SomeClass $foo;

    public function bar(SomeClass $baz)
    {
    }
}

In rector.php:

<?php

declare(strict_types=1);

use Rector\Core\Configuration\Option;
use Rector\DowngradePhp74\Rector\Property\DowngradeTypedPropertyRector;
use Rector\DowngradePhp80\Rector\FunctionLike\DowngradeMixedTypeDeclarationRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
    $parameters = $containerConfigurator->parameters();
    $parameters->set(Option::AUTO_IMPORT_NAMES, true);

    $services = $containerConfigurator->services();
    $services->set(DowngradeTypedPropertyRector::class);
    $services->set(DowngradeMixedTypeDeclarationRector::class);
};

Running command:

vendor/bin/rector process test.php

Gives output:

<?php
namespace First;
class SomeClass {}

namespace Second;
use First\SomeClass;

class AnotherClass
{
    /**
     * @var SomeClass
     */
    private $foo;

    /**
     * @param mixed $baz
     */
    public function bar($baz)
    {
    }
}

Expected Behaviour

It should strip the property of its type declaration, but not the function argument.

So the output should be:

<?php
namespace First;
class SomeClass {}

namespace Second;
use First\SomeClass;

class AnotherClass
{
    /**
     * @var SomeClass
     */
    private $foo;

    public function bar(SomeClass $baz)
    {
    }
}
@devbanana devbanana added the bug label Aug 3, 2021
@devbanana devbanana changed the title Property type declaration unnecessarily removed Argument type declaration unnecessarily removed Aug 3, 2021
@samsonasik
Copy link
Member

Could you create failing fixture PR for it? For multiple rules issue, you can create under https://github.com/rectorphp/rector-src/tree/main/tests/Issues

Thank you.

samsonasik added a commit to rectorphp/rector-src that referenced this issue Aug 4, 2021
TomasVotruba pushed a commit to rectorphp/rector-src that referenced this issue Aug 4, 2021
…deMixedTypeDeclarationRector Name parameter (#591)

* Demonstrate issue with DowngradeMixedTypeDeclarationRector

* Closes #590 Fixes rectorphp/rector#6611

* final touch: better check as already FullyQualified no need convert

* final touch: clean up

Co-authored-by: Brandon Olivares <programmer2188@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants