fix AssertIsTypeMethodCallRector crash on enum case argument#674
Merged
Conversation
…ing isset on enum case When `isType()` is called with an enum case argument, `ValueResolver::getValue()` returns an enum object. Using it as an array key in `isset()` caused a fatal error: "Cannot access offset of type SomeEnum in isset or empty". Add `is_string()` guard before the array lookup so non-string args are safely skipped. Fixes rectorphp/rector#9765
Member
Author
|
Looks good 👌 |
Contributor
|
not really though ;) although the actual crash is fixed, the underlying issue is that - (new stdClass)->isType('array');
+ (new stdClass)->isArray(); |
Member
Author
|
2 bugs in one :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
AssertIsTypeMethodCallRectorwhenisType()is called with an enum case argument inside aTestCasesubclassis_string()guard before using the resolved arg value as an array key inisset()Root cause
ValueResolver::getValue()returns the enum case object itself for enum arguments. Using it as an array key inisset(self::IS_TYPE_VALUE_TO_METHOD[$argValue])caused:Fix
Added an
is_string($argValue)guard immediately after resolving the argument value. Non-string values can never match any key inIS_TYPE_VALUE_TO_METHOD, so returningnullearly is both correct and safe.Fixes rectorphp/rector#9765
Generated by Claude Code