Skip to content

Commit

Permalink
Support for ReflectionClassConstant as Reflector in ImportResolver
Browse files Browse the repository at this point in the history
  • Loading branch information
BenMorel committed May 3, 2024
1 parent 8728865 commit 11ed9da
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## UNRELEASED (0.5.3)

**New features**

- Support for `ReflectionClassConstant` as Reflector in `ImportResolver`

## [0.5.2](https://github.com/brick/reflection/releases/tag/0.5.2) - 2024-05-02

**Compatibility improvements**
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Test {
}
```

You can create a resolver by passing any reflection object belonging to the PHP file as a context: a `ReflectionClass`, a `ReflectionProperty`, a `ReflectionMethod` or a `ReflectionParameter`:
You can create a resolver by passing any reflection object belonging to the PHP file as a context: a `ReflectionClass`, a `ReflectionClassConstant`, a `ReflectionProperty`, a `ReflectionMethod` or a `ReflectionParameter`:

```php
use Brick\Reflection\ImportResolver;
Expand Down
5 changes: 5 additions & 0 deletions src/ImportResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Doctrine\Common\Annotations\TokenParser;
use InvalidArgumentException;
use ReflectionClass;
use ReflectionClassConstant;
use ReflectionMethod;
use ReflectionParameter;
use ReflectionProperty;
Expand Down Expand Up @@ -70,6 +71,10 @@ private function getDeclaringClass(Reflector $reflector) : ?ReflectionClass
return $reflector;
}

if ($reflector instanceof ReflectionClassConstant) {
return $reflector->getDeclaringClass();
}

if ($reflector instanceof ReflectionProperty) {
return $reflector->getDeclaringClass();
}
Expand Down

0 comments on commit 11ed9da

Please sign in to comment.