mirror of
https://github.com/barryvdh/laravel-ide-helper.git
synced 2026-08-20 11:03:09 +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);
|
$phpdoc = new \phpDocumentor\Reflection\DocBlock($method);
|
||||||
|
|
||||||
$shortDescription = $phpdoc->getShortDescription();
|
$description = $phpdoc->getShortDescription();
|
||||||
$output .= "\t/**\n\t * ".$shortDescription."\n";
|
|
||||||
|
|
||||||
$longDescription = $phpdoc->getLongDescription()->getContents();
|
$longDescription = $phpdoc->getLongDescription()->getContents();
|
||||||
if($longDescription){
|
if($longDescription){
|
||||||
$longDescription = str_replace("\n", "\n\t * ", $longDescription);
|
$description .= "\n".$longDescription;
|
||||||
$output .= "\t * ".$longDescription."\n";
|
|
||||||
}
|
}
|
||||||
|
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";
|
$output .= "\t *\n\t * @static\n";
|
||||||
|
|
||||||
$paramTags = $phpdoc->getTagsByName('param');
|
$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;
|
$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."(";
|
$output .= "\t */\n\t public ".($static ? 'static' : '')." function ".$method->name."(";
|
||||||
|
|
||||||
$params = array();
|
$params = array();
|
||||||
@@ -326,4 +351,27 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n";
|
|||||||
return $output;
|
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