Skip to content

Commit

Permalink
Add inherited methods in ReflectionClass
Browse files Browse the repository at this point in the history
  • Loading branch information
koriym committed Sep 7, 2023
1 parent bf9775d commit 890ce9e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/ReflectionClass.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@

use Ray\ServiceLocator\ServiceLocator;

/** @extends \ReflectionClass<object> */
use function get_class_methods;

/**
* @template T of object
* @template-extends \ReflectionClass<T>
*/
class ReflectionClass extends \ReflectionClass implements Reader
{
/**
Expand Down Expand Up @@ -36,4 +41,36 @@ public function getAnnotation(string $annotationName)

return null;
}

/**
* @param int|null $filter
*
* @return list<ReflectionMethod>
*
* @psalm-external-mutation-free
*/
public function getMethods($filter = null): array
{
$methods = [];
$methodNames = get_class_methods($this->name);
foreach ($methodNames as $methodName) {
$methods[] = new ReflectionMethod($this->name, $methodName);
}

return $methods;
}

/**
* @psalm-suppress MethodSignatureMismatch
* @psalm-external-mutation-free
*/
public function getConstructor(): ?ReflectionMethod

Check warning on line 67 in src/ReflectionClass.php

View check run for this annotation

Codecov / codecov/patch

src/ReflectionClass.php#L67

Added line #L67 was not covered by tests
{
$parent = parent::getConstructor();
if ($parent === null) {
return null;

Check warning on line 71 in src/ReflectionClass.php

View check run for this annotation

Codecov / codecov/patch

src/ReflectionClass.php#L69-L71

Added lines #L69 - L71 were not covered by tests
}

return new ReflectionMethod($parent->class, $parent->name);

Check warning on line 74 in src/ReflectionClass.php

View check run for this annotation

Codecov / codecov/patch

src/ReflectionClass.php#L74

Added line #L74 was not covered by tests
}
}
2 changes: 2 additions & 0 deletions src/ReflectionMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ public function setObject(WeavedInterface $object): void
}

/**
* @return ReflectionClass<object>
*
* @psalm-external-mutation-free
* @psalm-suppress MethodSignatureMismatch
*/
Expand Down

0 comments on commit 890ce9e

Please sign in to comment.