Alias will grab macros from \Illuminate\Database\Eloquent\Builder too (#1118)

* `Alias` will grab macros from `\Illuminate\Database\Eloquent\Builder` too.

* `@return` will contains `|static` for Eloquent Builder macros which return Eloquent Builder instance.

* `Macro` tests.

* `Alias::detectMethods()` tests.

* Mock classes rename.
This commit is contained in:
Aleksei Lebedev
2020-12-21 11:15:47 +01:00
committed by GitHub
parent 9ba2f5c557
commit 36c4406b3a
4 changed files with 194 additions and 3 deletions
+7 -2
View File
@@ -4,6 +4,7 @@ namespace Barryvdh\LaravelIdeHelper;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Tag;
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
use Illuminate\Support\Collection;
class Macro extends Method
@@ -49,8 +50,12 @@ class Macro extends Method
// Add macro return type
if ($method->hasReturnType()) {
$type = $method->getReturnType()->getName();
$type .= $method->getReturnType()->allowsNull() ? '|null' : '';
$builder = EloquentBuilder::class;
$return = $method->getReturnType();
$type = $return->getName();
$type .= $this->root === "\\{$builder}" && $return->getName() === $builder ? '|static' : '';
$type .= $return->allowsNull() ? '|null' : '';
$this->phpdoc->appendTag(Tag::createInstance("@return {$type}"));
}