From 890ce9e2cff918456804d496b993b819990f752d Mon Sep 17 00:00:00 2001 From: Akihito Koriyama Date: Fri, 8 Sep 2023 04:58:40 +0900 Subject: [PATCH] Add inherited methods in ReflectionClass --- src/ReflectionClass.php | 39 ++++++++++++++++++++++++++++++++++++++- src/ReflectionMethod.php | 2 ++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/src/ReflectionClass.php b/src/ReflectionClass.php index 14b60dd5..0a7d8638 100644 --- a/src/ReflectionClass.php +++ b/src/ReflectionClass.php @@ -6,7 +6,12 @@ use Ray\ServiceLocator\ServiceLocator; -/** @extends \ReflectionClass */ +use function get_class_methods; + +/** + * @template T of object + * @template-extends \ReflectionClass + */ class ReflectionClass extends \ReflectionClass implements Reader { /** @@ -36,4 +41,36 @@ public function getAnnotation(string $annotationName) return null; } + + /** + * @param int|null $filter + * + * @return list + * + * @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 + { + $parent = parent::getConstructor(); + if ($parent === null) { + return null; + } + + return new ReflectionMethod($parent->class, $parent->name); + } } diff --git a/src/ReflectionMethod.php b/src/ReflectionMethod.php index daaa96e4..38e078c4 100644 --- a/src/ReflectionMethod.php +++ b/src/ReflectionMethod.php @@ -24,6 +24,8 @@ public function setObject(WeavedInterface $object): void } /** + * @return ReflectionClass + * * @psalm-external-mutation-free * @psalm-suppress MethodSignatureMismatch */