Add @see location for macros & mixins to PhpDoc (#1054)

* Add @see location for macros & mixins to PhpDoc

* Fix CS

* Add entry to changelog

* Improve changelog entry

* Adjust CS

* Update CHANGELOG.md

Co-authored-by: Markus Podar <[email protected]>
This commit is contained in:
Richard van Baarsen
2020-09-11 16:35:41 +02:00
committed by GitHub
co-authored by Markus Podar
parent 00ee13e0cf
commit 2ff9672a49
2 changed files with 22 additions and 0 deletions
+1
View File
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
### Added
- Fix phpdoc generate for custom cast with parameter [\#986 / artelkr](https://github.com/barryvdh/laravel-ide-helper/pull/986)
- Created a possibility to add custom relation type [\#987 / efinder2](https://github.com/barryvdh/laravel-ide-helper/pull/987)
- Added `@see` with macro/mixin definition location to PhpDoc [\#1054 / riesjart](https://github.com/barryvdh/laravel-ide-helper/pull/1054)
### Changed
- Implement DeferrableProvider [\#914 / kon-shou](https://github.com/barryvdh/laravel-ide-helper/pull/914)
+21
View File
@@ -4,6 +4,7 @@ namespace Barryvdh\LaravelIdeHelper;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Tag;
use Illuminate\Support\Collection;
class Macro extends Method
{
@@ -33,6 +34,8 @@ class Macro extends Method
{
$this->phpdoc = new DocBlock('/** */');
$this->addLocationToPhpDoc();
// Add macro parameters
foreach ($method->getParameters() as $parameter) {
$type = $parameter->hasType() ? $parameter->getType()->getName() : 'mixed';
@@ -53,6 +56,24 @@ class Macro extends Method
}
}
protected function addLocationToPhpDoc()
{
$enclosingClass = $this->method->getClosureScopeClass();
/** @var \ReflectionMethod $enclosingMethod */
$enclosingMethod = Collection::make($enclosingClass->getMethods())
->first(function (\ReflectionMethod $method) {
return $method->getStartLine() <= $this->method->getStartLine()
&& $method->getEndLine() >= $this->method->getEndLine();
});
if ($enclosingMethod) {
$this->phpdoc->appendTag(Tag::createInstance(
'@see \\' . $enclosingClass->getName() . '::' . $enclosingMethod->getName() . '()'
));
}
}
/**
* @param \ReflectionFunctionAbstract $method
* @param \ReflectionClass $class