Add extends declaration for Macroable classes to fix missing inherited methods (#1674)

This commit is contained in:
KentarouTakeda
2025-02-22 16:59:08 +01:00
committed by GitHub
parent 3d4e37798e
commit 09623f216c
2 changed files with 34 additions and 1 deletions
+1 -1
View File
@@ -29,7 +29,7 @@ $s3 = $s1 . $s2;
<?php foreach ($namespaces_by_extends_ns as $namespace => $aliases) : ?>
namespace <?= $namespace === '__root' ? '' : trim($namespace, '\\') ?> {
<?php foreach ($aliases as $alias) : ?>
<?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
<?php echo trim($alias->getDocComment($s1)) . "\n{$s1}" . $alias->getClassType() ?> <?= $alias->getExtendsClass() ?><?php if($alias->shouldExtendParentClass()): ?> extends <?= $alias->getParentClass() ?><?php endif; ?> {
<?php foreach ($alias->getMethods() as $method) : ?>
<?= trim($method->getDocComment($s2)) . "\n{$s2}" ?>public static function <?= $method->getName() ?>(<?= $method->getParamsWithDefault() ?>)
{<?php if ($method->getDeclaringClass() !== $method->getRoot()) : ?>
+33
View File
@@ -36,6 +36,7 @@ class Alias
protected $classType = 'class';
protected $short;
protected $namespace = '__root';
protected $parentClass;
protected $root = null;
protected $classes = [];
protected $methods = [];
@@ -87,6 +88,7 @@ class Alias
$this->detectNamespace();
$this->detectClassType();
$this->detectExtendsNamespace();
$this->detectParentClass();
if (!empty($this->namespace)) {
try {
@@ -171,6 +173,25 @@ class Alias
return $this->extendsNamespace;
}
/**
* Get the parent class of the class which this alias extends
*
* @return null|string
*/
public function getParentClass()
{
return $this->parentClass;
}
/**
* Check if this class should extend the parent class
*/
public function shouldExtendParentClass()
{
return $this->parentClass
&& $this->getExtendsNamespace() !== '\\Illuminate\\Support\\Facades';
}
/**
* Get the Alias by which this class is called
*
@@ -268,6 +289,18 @@ class Alias
}
}
/**
* Detect the parent class
*/
protected function detectParentClass()
{
$reflection = new ReflectionClass($this->root);
$parentClass = $reflection->getParentClass();
$this->parentClass = $parentClass ? '\\' . $parentClass->getName() : null;
}
/**
* Detect the class type
*/