[Php74][Php80] Handle TypedPropertyRector + StringableForToStringRector#1473
[Php74][Php80] Handle TypedPropertyRector + StringableForToStringRector#1473TomasVotruba merged 16 commits intomainfrom
Conversation
|
/cc @mkopinsky |
|
Fixed 🎉 The solution is only apply typed property to make nullable: - private $nickname;
+ private ?string $nickname = null;But not apply |
|
@mkopinsky it seems in PHP 8.0, when class has method Fatal error: Uncaught TypeError: Fixture::__toString(): Return value must be of type string, null returned in /in/dhmYZ:7
Stack trace:
#0 /in/dhmYZ(11): Fixture->__toString()ref https://3v4l.org/dhmYZ |
|
It seems the solution is find return statement in the classmethod with -return $this->nickname;
+return (string) $this->nickname; |
|
That makes perfect sense. In the application I took this from, |
|
@mkopinsky implemented 🎉 |
|
All checks have passed 🎉 @TomasVotruba it is ready for review. |
|
Thank you, looks good 👍 |
| $hasReturn = $this->betterNodeFinder->hasInstancesOfInFunctionLikeScoped($toStringClassMethod, Return_::class); | ||
|
|
||
| if (! $hasReturn) { | ||
| $lastKey = array_key_last((array) $toStringClassMethod->stmts); |
There was a problem hiding this comment.
it seems cause downgrade error:
- $lastKey = array_key_last((array) $toStringClassMethod->stmts);
+ end((array) $toStringClassMethod->stmts);
+ $lastKey = key((array) $toStringClassMethod->stmts);DowngradeArrayKeyFirstLastRector seems needs update for casting condition.
There was a problem hiding this comment.
I created PR #1475 for it. It next need a tweak in DowngradeArrayKeyFirstLastRector to adapt this condition.
Given the following code:
It produce error:
This PR fix it. Fixes rectorphp/rector#6862