-
-
Notifications
You must be signed in to change notification settings - Fork 410
Add rector to migrate __sleep() to __serialize() #7212
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
base: main
Are you sure you want to change the base?
Conversation
foreach ($node->stmts as $stmt) { | ||
if ($stmt instanceof Node\Stmt\Return_ && $stmt->expr instanceof Array_) { | ||
$newItems = []; | ||
foreach ($stmt->expr->items as $item) { | ||
if ($item !== null && $item->value instanceof Node\Scalar\String_) { | ||
$propName = $item->value->value; | ||
$newItems[] = new ArrayItem( | ||
new PropertyFetch(new Node\Expr\Variable('this'), $propName), | ||
$item->value | ||
); | ||
} | ||
} | ||
$stmt->expr->items = $newItems; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use betterNodeFinder->findReturnsScoped($node)
to locate returns, and apply change/validate for its values, see example
Lines 90 to 100 in fb5d1cf
$returns = $this->betterNodeFinder->findReturnsScoped($node); | |
if (! $this->returnAnalyzer->hasOnlyReturnWithExpr($node, $returns)) { | |
return null; | |
} | |
foreach ($returns as $return) { | |
// we need exact string "value" return | |
if (! $return->expr instanceof String_ && ! $return->expr instanceof InterpolatedString) { | |
return null; | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check now
9b6aa04
to
9ec79ce
Compare
foreach ($return->expr->items as $item) { | ||
if ($item !== null && $item->value instanceof Node\Scalar\String_) { | ||
$propName = $item->value->value; | ||
$newItems[] = new ArrayItem( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add $hasChanged = false
init variable before loop, set $hasChanged = true
after changed, verify $hasChanged before apply return, return null if no change
); | ||
} | ||
} | ||
$return->expr->items = $newItems; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
init $newItems inside inner loop, verify not empty before assign
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
check ! $hasChanged
, return null
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please check now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you give link of example the error/deprecation notice on https://3v4l.org/ for this case?
Also probably handle __wakeup
as well.
Thank you.
Not implemented in PHP core yet. I think it will be added soon. I’ll add __wakeup soon. |
https://wiki.php.net/rfc/deprecations_php_8_5#deprecate_the_sleep_and_wakeup_magic_methods