mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-18 01:57:13 +00:00
Get {@inheritdoc} from parent/interface
Better fix for #17 Should find the actual description and add the parameters to the helper class.
This commit is contained in:
@@ -249,14 +249,30 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n";
|
||||
|
||||
$phpdoc = new \phpDocumentor\Reflection\DocBlock($method);
|
||||
|
||||
$shortDescription = $phpdoc->getShortDescription();
|
||||
$output .= "\t/**\n\t * ".$shortDescription."\n";
|
||||
|
||||
$description = $phpdoc->getShortDescription();
|
||||
$longDescription = $phpdoc->getLongDescription()->getContents();
|
||||
if($longDescription){
|
||||
$longDescription = str_replace("\n", "\n\t * ", $longDescription);
|
||||
$output .= "\t * ".$longDescription."\n";
|
||||
$description .= "\n".$longDescription;
|
||||
}
|
||||
if(strpos($description, '{@inheritdoc}') !== false){
|
||||
$inheritdoc = $this->getInheritDoc($method);
|
||||
$inheritDescription = $inheritdoc->getShortDescription();
|
||||
|
||||
$inheritLongDescription = $inheritdoc->getLongDescription()->getContents();
|
||||
if($inheritLongDescription){
|
||||
$inheritDescription .= "\n".$inheritLongDescription;
|
||||
}
|
||||
$description = str_replace('{@inheritdoc}', $inheritDescription, $description);
|
||||
$inheritTags = $inheritdoc->getTags();
|
||||
if($inheritTags){
|
||||
foreach($inheritTags as $tag){
|
||||
$tag->setDocBlock();
|
||||
$phpdoc->appendTag($tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
$description = str_replace("\n", "\n\t * ", $description);
|
||||
$output .= "\t/**\n\t * ".$description."\n";
|
||||
$output .= "\t *\n\t * @static\n";
|
||||
|
||||
$paramTags = $phpdoc->getTagsByName('param');
|
||||
@@ -285,6 +301,15 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n";
|
||||
$returnValue = null;
|
||||
}
|
||||
|
||||
$allTags = $phpdoc->getTags();
|
||||
if($allTags){
|
||||
foreach($allTags as $tag){
|
||||
if(!in_array($tag->getName(), array('return', 'param'))){
|
||||
$output .= "\t * @".$tag->getName() ." ". $tag->getContent()."\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$output .= "\t */\n\t public ".($static ? 'static' : '')." function ".$method->name."(";
|
||||
|
||||
$params = array();
|
||||
@@ -326,4 +351,27 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n";
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \ReflectionMethod $reflectionMethod
|
||||
* @return string
|
||||
*/
|
||||
protected function getInheritDoc($reflectionMethod){
|
||||
$parentClass = $reflectionMethod->getDeclaringClass()->getParentClass();
|
||||
|
||||
if($parentClass){
|
||||
$method = $parentClass->getMethod($reflectionMethod->getName());
|
||||
}else{
|
||||
$method = $reflectionMethod->getPrototype();
|
||||
}
|
||||
if($method){
|
||||
$phpdoc = new \phpDocumentor\Reflection\DocBlock($method);
|
||||
if(strpos($phpdoc->getShortDescription(), '{@inheritdoc}') !== false || strpos($phpdoc->getLongDescription(), '{@inheritdoc}') !== false ){
|
||||
//Not at the end yet, try another parent/interface..
|
||||
return $this->getInheritDoc($method);
|
||||
}else{
|
||||
return $phpdoc;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user