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

Incorrect behavior of MixedTypeRector #8633

Closed
maks-rafalko opened this issue May 13, 2024 · 4 comments · Fixed by rectorphp/rector-src#5874
Closed

Incorrect behavior of MixedTypeRector #8633

maks-rafalko opened this issue May 13, 2024 · 4 comments · Fixed by rectorphp/rector-src#5874
Labels

Comments

@maks-rafalko
Copy link

Bug Report

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

Minimal PHP Code Causing Issue

See https://getrector.com/demo/393aa099-ae74-4edc-a562-f65d5d2f1491

<?php

interface FileFilter {}

class ConcreteFileFilter implements FileFilter {}

/**
 * @param ConcreteFileFilter|FileFilter $fileFilter
 */
function usesFileFilter(FileFilter $fileFilter) {}

Change

@@ -4,7 +4,4 @@
 
 class ConcreteFileFilter implements FileFilter {}
 
-/**
- * @param ConcreteFileFilter|FileFilter $fileFilter
- */
 function usesFileFilter(FileFilter $fileFilter) {}

Responsible rules

  • MixedTypeRector

Expected Behavior

No change is expected (Rector didn't remove phpdoc on 1.0.3, started removing on 1.0.4 and later)

@samsonasik
Copy link
Member

The @param usage is invalid, as it use child and parent in union, which one invalidate another, choose one instead if you one to keep the doc, eg:

@param ConcreteFileFilter $fileFilter

https://getrector.com/demo/019ddfd5-98e9-455a-80e6-044a4fa686a9

@maks-rafalko
Copy link
Author

Let me ask a couple of questions:

  1. why it's invalid? what rule this union type breaks? From static analysis point of view, everything is good: https://phpstan.org/r/09f93713-b38e-4255-90f3-cdb825f45307
  2. is it MixedTypeRector's job to decide to remove or not remove this param? It's a bit confusing cause this rule's description says "Change mixed docs type to mixed typed"

@samsonasik
Copy link
Member

  1. The @param is still invalid, even phpstan decide it is fine, that dead code, that will still be removed if you enable deadCode set list.
  2. the MixedTypeRector indeed should not remove the doc if it not change the mixed type, I will add check for that.

@samsonasik samsonasik reopened this May 14, 2024
maks-rafalko added a commit to infection/infection that referenced this issue May 14, 2024
* Upgrade Rector and fix new issues

* Revert removed PHPDocs and skip `MixedTypeRector` as it seems there is a bug

See rectorphp/rector#8633

* Update lock file
@staabm
Copy link
Contributor

staabm commented May 14, 2024

fyi, phpstan normalized the phpdoc away:
https://phpstan.org/r/177beddc-6dd6-47e8-afe2-0f852e05661d

so we could argue that the phpdoc is misleading and leads to wrong assumptions by the dev.
(still you are right its not the MixedTypeRector rules job, to delete it)
see also PHPStan type normalization docs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants