From fa81f7306e122875a0ddd3ea23f1145bdcfea5c0 Mon Sep 17 00:00:00 2001 From: Lukas Gaechter Date: Wed, 18 Sep 2024 23:15:41 +0200 Subject: [PATCH] fix: Only include parent methods that are not already present --- lib/Reflection/ClassReflection.php | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/Reflection/ClassReflection.php b/lib/Reflection/ClassReflection.php index 7df9aa5..a84ae77 100644 --- a/lib/Reflection/ClassReflection.php +++ b/lib/Reflection/ClassReflection.php @@ -22,7 +22,14 @@ public function __construct($reflection) public function addParentInformation($parentClass) { - $this->parentMethods = array_merge($this->parentMethods, $parentClass->getMethods()); + $methods = array_map(function ($method) { + return $method->getName(); + }, $this->parentMethods); + $parent_methods = array_filter($parentClass->getMethods(), function ($parent_method) use ($methods) { + return !in_array($parent_method->getName(), $methods); + }); + + $this->parentMethods = array_merge($this->parentMethods, $parent_methods); $this->parentProperties = $parentClass->getProperties(); } @@ -40,7 +47,15 @@ public function getMethods() $methods = $this->reflection->getMethods(); if ($this->reflection->getParent() && !empty($this->parentMethods)) { - $methods = array_merge($methods, $this->parentMethods); + // Filter out parent methods that are already defined in the child class. + $method_names = array_map(function ($method) { + return $method->getName(); + }, $methods); + $parent_methods = array_filter($this->parentMethods, function ($parent_method) use ($method_names) { + return !in_array($parent_method->getName(), $method_names); + }); + + $methods = array_merge($methods, $parent_methods); } $methods = array_filter($methods, function ($item) {