Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Down_To_PHP71] Handle Downgrade Param Widening + Downgrade Reflection Get on DowngradeLevelSetList::DOWN_TO_PHP_71#3001

Merged
TomasVotruba merged 27 commits into
mainfrom
fix-7546
Oct 20, 2022
Merged

[Down_To_PHP71] Handle Downgrade Param Widening + Downgrade Reflection Get on DowngradeLevelSetList::DOWN_TO_PHP_71#3001
TomasVotruba merged 27 commits into
mainfrom
fix-7546

Conversation

@samsonasik

Copy link
Copy Markdown
Member

@samsonasik

Copy link
Copy Markdown
Member Author

Fixed 🎉 /cc @leoloso

@samsonasik samsonasik marked this pull request as draft October 18, 2022 08:17
@samsonasik

Copy link
Copy Markdown
Member Author

It seems cause error in other downgrade tests:


There were 5 failures:

1) Rector\Tests\DowngradePhp80\Rector\Expression\DowngradeMatchToSwitchRector\DowngradeMatchToSwitchRectorTest::test with data set #6 ('/home/runner/work/rector-src/...hp.inc')
Failed asserting that string matches format description.
--- Expected
+++ Actual
@@ @@
     public function run($value)
     {
         static function (mixed $default) : mixed {
-            switch (true) {
-                case is_string($default):
-                    return sprintf('"%s"', $default);
-                default:
-                    return $default;
-            }
+            return match (true) {
+                    is_string($default) => sprintf('"%s"', $default),
+                    default => $default,
+                };
         };
     }

@leoloso

leoloso commented Oct 18, 2022

Copy link
Copy Markdown
Contributor

That was soooooooooo quick!!!!!!! Thanks @samsonasik 💪

@samsonasik

Copy link
Copy Markdown
Member Author

I tried manually check the DowngradeReflectionGetAttributesRector, it seems due to $reflectionClass no longer typed, and it got mixed type already.

It seems needs to use original node instead of latest changed type for this use case.

@samsonasik

Copy link
Copy Markdown
Member Author

It seems can be resolved by lookup variable from Param when exists on NodeTypeResolver->getType() 50f3a58

@samsonasik samsonasik marked this pull request as ready for review October 18, 2022 11:18
@samsonasik

Copy link
Copy Markdown
Member Author

Using find first previous to get first from param seems need another tweaking, as the following code will not be processed correctly:

use ReflectionClass;

class DowngradeParamReflectionGetAttribute
{
    public function run(ReflectionClass $reflectionClass)
    {
        echo $reflectionClass->getFileName();

        if ($reflectionClass->getAttributes()) {
            return true;
        }
        return false;
    }
}

as first previous is:

echo $reflectionClass->getFileName();

which will be mixed type already after downgrade parameter type widening.

@samsonasik samsonasik marked this pull request as draft October 18, 2022 11:30
@samsonasik samsonasik marked this pull request as ready for review October 18, 2022 11:46
@samsonasik

Copy link
Copy Markdown
Member Author

I added check not param and stil mixed type 0dd5c08

@samsonasik

Copy link
Copy Markdown
Member Author

All checks have passed 🎉 @TomasVotruba it is ready for review.

@samsonasik

Copy link
Copy Markdown
Member Author

It seems it will make unreliable when it reassign or unset after pull from Param, marking back to draft.

@samsonasik samsonasik marked this pull request as draft October 18, 2022 14:00
@samsonasik

Copy link
Copy Markdown
Member Author

@samsonasik

Copy link
Copy Markdown
Member Author

The issue seems when PhpdocInfo->hasChanged() is true, it is not immediatelly applied the information to the Node as comment, as if the node is printed, the comment still not shown, so it is late to get information of the PHPStan type.

@samsonasik

Copy link
Copy Markdown
Member Author

@samsonasik samsonasik force-pushed the fix-7546 branch 2 times, most recently from 28ede78 to ca4e720 Compare October 19, 2022 08:11
@samsonasik

Copy link
Copy Markdown
Member Author

Let's try early refresh doc Node before refresh scope c81df9c

@samsonasik samsonasik marked this pull request as ready for review October 19, 2022 08:26
@samsonasik

Copy link
Copy Markdown
Member Author

Finally 🎉 🎉 🎉, All checks have passed 🎉 @TomasVotruba I think it is ready now 🎉 🎉 🎉

@samsonasik samsonasik force-pushed the fix-7546 branch 2 times, most recently from 97cabca to 79722fe Compare October 19, 2022 10:52
@samsonasik

Copy link
Copy Markdown
Member Author

Rebased.

@TomasVotruba

Copy link
Copy Markdown
Member

Thank you 👍

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Incorrect behavior of DowngradeParameterTypeWideningRector + DowngradeReflectionGetAttributesRector

4 participants