mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Merge pull request #720 from JeppeKnockaert/remove-duplicate-functions-from-phpdoc
Prevent duplicate function declarations in docblocks
This commit is contained in:
+1
-1
@@ -14,7 +14,7 @@
|
|||||||
"illuminate/support": "^5.5,<5.8",
|
"illuminate/support": "^5.5,<5.8",
|
||||||
"illuminate/console": "^5.5,<5.8",
|
"illuminate/console": "^5.5,<5.8",
|
||||||
"illuminate/filesystem": "^5.5,<5.8",
|
"illuminate/filesystem": "^5.5,<5.8",
|
||||||
"barryvdh/reflection-docblock": "^2.0.4",
|
"barryvdh/reflection-docblock": "^2.0.5",
|
||||||
"composer/composer": "^1.6"
|
"composer/composer": "^1.6"
|
||||||
},
|
},
|
||||||
"require-dev": {
|
"require-dev": {
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Barryvdh\LaravelIdeHelper;
|
|||||||
use Barryvdh\Reflection\DocBlock;
|
use Barryvdh\Reflection\DocBlock;
|
||||||
use Barryvdh\Reflection\DocBlock\Context;
|
use Barryvdh\Reflection\DocBlock\Context;
|
||||||
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
|
||||||
|
use Barryvdh\Reflection\DocBlock\Tag\MethodTag;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
|
|
||||||
class Alias
|
class Alias
|
||||||
@@ -395,12 +396,33 @@ class Alias
|
|||||||
$serializer = new DocBlockSerializer(1, $prefix);
|
$serializer = new DocBlockSerializer(1, $prefix);
|
||||||
|
|
||||||
if ($this->phpdoc) {
|
if ($this->phpdoc) {
|
||||||
|
$this->removeDuplicateMethodsFromPhpDoc();
|
||||||
return $serializer->getDocComment($this->phpdoc);
|
return $serializer->getDocComment($this->phpdoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Removes method tags from the doc comment that already appear as functions inside the class.
|
||||||
|
* This prevents duplicate function errors in the IDE.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
protected function removeDuplicateMethodsFromPhpDoc()
|
||||||
|
{
|
||||||
|
$methods = count($this->methods) > 0 ? $this->methods : $this->getMethods();
|
||||||
|
$methodNames = array_map(function (Method $method) {
|
||||||
|
return $method->getName();
|
||||||
|
}, $methods);
|
||||||
|
|
||||||
|
foreach ($this->phpdoc->getTags() as $tag) {
|
||||||
|
if ($tag instanceof MethodTag && in_array($tag->getMethodName(), $methodNames)) {
|
||||||
|
$this->phpdoc->deleteTag($tag);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Output an error.
|
* Output an error.
|
||||||
*
|
*
|
||||||
|
|||||||
Reference in New Issue
Block a user