Skip to content

Commit

Permalink
fix: Only include parent methods that are not already present
Browse files Browse the repository at this point in the history
  • Loading branch information
gchtr committed Sep 19, 2024
1 parent e47b91e commit 6d3ab73
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions lib/Reflection/ClassReflection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand All @@ -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) {
Expand Down

0 comments on commit 6d3ab73

Please sign in to comment.