Skip to content

Wire ReflectionEnum into existing infrastructure#192

Merged
lisachenko merged 2 commits intomasterfrom
copilot/wire-reflectionenum-into-infrastructure
Apr 28, 2026
Merged

Wire ReflectionEnum into existing infrastructure#192
lisachenko merged 2 commits intomasterfrom
copilot/wire-reflectionenum-into-infrastructure

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 28, 2026

ReflectionClassConstant had no integration with the ReflectionEnum stack: enum case constants couldn't be looked up by name via the engine, getDeclaringClass() returned a plain ReflectionClass instead of ReflectionEnum, and there was no way to obtain a properly-typed ReflectionEnumUnitCase/ReflectionEnumBackedCase from a constant.

Changes

  • ReflectionEngine::parseClassConstant() — now searches EnumCase nodes in addition to ClassConst nodes, so new ReflectionClassConstant('MyEnum', 'CaseName') no longer throws InvalidArgumentException.

  • ReflectionClassConstant::getDeclaringClass() — returns ReflectionEnum when isEnumCase() is true, matching native PHP where \ReflectionClassConstant::getDeclaringClass() returns \ReflectionEnum for enum case constants.

  • ReflectionClassConstant::toEnumCase() — new method converting an enum-case constant to ReflectionEnumUnitCase or ReflectionEnumBackedCase (delegates to ReflectionEnum::getCase()); throws ReflectionException if called on a non-enum-case constant.

$parsedEnum     = $fileNamespace->getEnums()[BackedPhp81EnumHTTPMethods::class];
$parsedConstant = $parsedEnum->getReflectionConstant('GET'); // ReflectionClassConstant

$parsedConstant->getDeclaringClass(); // ReflectionEnum (was ReflectionClass)
$parsedConstant->toEnumCase();        // ReflectionEnumBackedCase, getBackingValue() => 'get'

- Fix ReflectionEngine::parseClassConstant() to handle EnumCase nodes
- Fix ReflectionClassConstant::getDeclaringClass() to return ReflectionEnum for enum cases
- Add ReflectionClassConstant::toEnumCase() for converting to ReflectionEnumUnitCase/ReflectionEnumBackedCase
- Add tests for all new functionality

Agent-Logs-Url: https://github.com/goaop/parser-reflection/sessions/95741007-a246-4a8c-821f-7a733a378e44

Co-authored-by: lisachenko <640114+lisachenko@users.noreply.github.com>
Copilot AI changed the title [WIP] Wire ReflectionEnum into existing infrastructure Wire ReflectionEnum into existing infrastructure Apr 28, 2026
Copilot AI requested a review from lisachenko April 28, 2026 14:19
@lisachenko lisachenko marked this pull request as ready for review April 28, 2026 14:20
@lisachenko lisachenko added this to the 4.0.0 milestone Apr 28, 2026
@lisachenko lisachenko merged commit 301e176 into master Apr 28, 2026
7 checks passed
@lisachenko lisachenko deleted the copilot/wire-reflectionenum-into-infrastructure branch April 28, 2026 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Development

Successfully merging this pull request may close these issues.

Wire ReflectionEnum into existing infrastructure

2 participants