Skip to content

Commit 2ff9672

Browse files
riesjartmfn
andauthored
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]>
1 parent 00ee13e commit 2ff9672

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ All notable changes to this project will be documented in this file.
88
### Added
99
- Fix phpdoc generate for custom cast with parameter [\#986 / artelkr](https://github.com/barryvdh/laravel-ide-helper/pull/986)
1010
- Created a possibility to add custom relation type [\#987 / efinder2](https://github.com/barryvdh/laravel-ide-helper/pull/987)
11+
- Added `@see` with macro/mixin definition location to PhpDoc [\#1054 / riesjart](https://github.com/barryvdh/laravel-ide-helper/pull/1054)
1112

1213
### Changed
1314
- Implement DeferrableProvider [\#914 / kon-shou](https://github.com/barryvdh/laravel-ide-helper/pull/914)

src/Macro.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Barryvdh\Reflection\DocBlock;
66
use Barryvdh\Reflection\DocBlock\Tag;
7+
use Illuminate\Support\Collection;
78

89
class Macro extends Method
910
{
@@ -33,6 +34,8 @@ protected function initPhpDoc($method)
3334
{
3435
$this->phpdoc = new DocBlock('/** */');
3536

37+
$this->addLocationToPhpDoc();
38+
3639
// Add macro parameters
3740
foreach ($method->getParameters() as $parameter) {
3841
$type = $parameter->hasType() ? $parameter->getType()->getName() : 'mixed';
@@ -53,6 +56,24 @@ protected function initPhpDoc($method)
5356
}
5457
}
5558

59+
protected function addLocationToPhpDoc()
60+
{
61+
$enclosingClass = $this->method->getClosureScopeClass();
62+
63+
/** @var \ReflectionMethod $enclosingMethod */
64+
$enclosingMethod = Collection::make($enclosingClass->getMethods())
65+
->first(function (\ReflectionMethod $method) {
66+
return $method->getStartLine() <= $this->method->getStartLine()
67+
&& $method->getEndLine() >= $this->method->getEndLine();
68+
});
69+
70+
if ($enclosingMethod) {
71+
$this->phpdoc->appendTag(Tag::createInstance(
72+
'@see \\' . $enclosingClass->getName() . '::' . $enclosingMethod->getName() . '()'
73+
));
74+
}
75+
}
76+
5677
/**
5778
* @param \ReflectionFunctionAbstract $method
5879
* @param \ReflectionClass $class

0 commit comments

Comments
 (0)