Skip to content

fix AssertIsTypeMethodCallRector crash on enum case argument#674

Merged
TomasVotruba merged 1 commit into
mainfrom
claude/fix-rector-phpunit-issue-mpdWb
May 21, 2026
Merged

fix AssertIsTypeMethodCallRector crash on enum case argument#674
TomasVotruba merged 1 commit into
mainfrom
claude/fix-rector-phpunit-issue-mpdWb

Conversation

@TomasVotruba
Copy link
Copy Markdown
Member

Summary

  • Fixes a fatal crash in AssertIsTypeMethodCallRector when isType() is called with an enum case argument inside a TestCase subclass
  • Adds a is_string() guard before using the resolved arg value as an array key in isset()
  • Adds a skip fixture to cover the non-string arg scenario

Root cause

ValueResolver::getValue() returns the enum case object itself for enum arguments. Using it as an array key in isset(self::IS_TYPE_VALUE_TO_METHOD[$argValue]) caused:

System error: "Cannot access offset of type App\Enums\SomeEnum in isset or empty"

Fix

Added an is_string($argValue) guard immediately after resolving the argument value. Non-string values can never match any key in IS_TYPE_VALUE_TO_METHOD, so returning null early is both correct and safe.

Fixes rectorphp/rector#9765


Generated by Claude Code

…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
@TomasVotruba TomasVotruba merged commit 29d203f into main May 21, 2026
7 checks passed
@TomasVotruba TomasVotruba deleted the claude/fix-rector-phpunit-issue-mpdWb branch May 21, 2026 09:10
@TomasVotruba
Copy link
Copy Markdown
Member Author

Looks good 👌

@Levivb
Copy link
Copy Markdown
Contributor

Levivb commented May 21, 2026

not really though ;)

although the actual crash is fixed, the underlying issue is that isType is processed regardless of the classtype the method is called on.

- (new stdClass)->isType('array');
+ (new stdClass)->isArray();

@TomasVotruba
Copy link
Copy Markdown
Member Author

2 bugs in one :)

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.

AssertIsTypeMethodCallRector crashes on 'isType' method call on any other object

3 participants