Skip to content

Add resolveExprPropertyFetch to support Enum::CASE->value expressions#176

Merged
lisachenko merged 1 commit into
masterfrom
devin/1777304195-resolve-expr-property-fetch
Apr 27, 2026
Merged

Add resolveExprPropertyFetch to support Enum::CASE->value expressions#176
lisachenko merged 1 commit into
masterfrom
devin/1777304195-resolve-expr-property-fetch

Conversation

@devin-ai-integration
Copy link
Copy Markdown
Contributor

Summary

Adds support for resolving property fetch expressions on objects in NodeExpressionResolver, enabling expressions like BackedEnum::CASE->value to be resolved correctly as parameter default values.

Changes

  1. resolveExprPropertyFetch method in NodeExpressionResolver — resolves property access on objects (e.g. SomeEnum::CASE->value). Resets isConstant/constantName since PHP does not treat Enum::CASE->value as a constant.

  2. fetchReflectionClass fix — uses native reflection for loaded enum classes so that getConstant() returns actual enum case instances (the parser-reflection ReflectionClass::getConstant() returns false for enum cases).

  3. Test stub ClassWithBackedEnumDefaultValue in FileWithClasses81.php — uses BackedPhp81EnumHTTPMethods::GET->value as a parameter default.

  4. Unit test in NodeExpressionResolverTest — verifies the resolver evaluates BackedPhp81EnumHTTPMethods::GET->value to 'get'.

  5. Integration test in ReflectionParameterTest — verifies getDefaultValue() returns 'get' for the parameter with a backed enum property default.

Review & Testing Checklist for Human

  • Verify the fetchReflectionClass change to use native reflection for enums doesn't affect other enum constant resolution paths (e.g. SomeEnum::CASE without property fetch)
  • Run the full test suite (vendor/bin/phpunit) — all 12,738 tests pass with 0 failures
  • Run PHPStan (vendor/bin/phpstan analyse src --no-progress) — 0 errors

Notes

The fetchReflectionClass change is necessary because the parser-reflection's ReflectionClass::getConstant() returns false for enum cases, while native PHP's \ReflectionClass::getConstant() correctly returns the enum instance. Using native reflection for loaded enums allows the property fetch chain to work correctly.

Link to Devin session: https://app.devin.ai/sessions/33bcb37b7b784272ad76aa48fe6683c4
Requested by: @lisachenko

- Add resolveExprPropertyFetch method in NodeExpressionResolver to resolve
  property fetch on objects (e.g. BackedEnum::CASE->value)
- Use native reflection for loaded enum classes in fetchReflectionClass so
  enum case constants resolve to actual enum instances
- Reset isConstant/constantName in property fetch since PHP does not consider
  Enum::CASE->value a constant expression
- Add ClassWithBackedEnumDefaultValue test stub
- Add unit test for resolver and integration test for parameter defaults

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@lisachenko
Copy link
Copy Markdown
Member

resolves #155

@devin-ai-integration
Copy link
Copy Markdown
Contributor Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

@lisachenko lisachenko added this to the 4.0.0 milestone Apr 27, 2026
@lisachenko lisachenko merged commit 348ce66 into master Apr 27, 2026
7 checks passed
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.

1 participant