mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-17 17:47:13 +00:00
Add extends declaration for Macroable classes to fix missing inherited methods (#1674)
This commit is contained in:
@@ -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()) : ?>
|
||||
|
||||
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user