Use docblock builder

This commit is contained in:
Barry vd. Heuvel
2024-02-18 19:58:06 +01:00
parent 127c9dca94
commit c223665e99
7 changed files with 207 additions and 133 deletions
+11 -42
View File
@@ -11,18 +11,19 @@
namespace Barryvdh\LaravelIdeHelper;
use Barryvdh\LaravelIdeHelper\DocBlock\DocBlockBuilder;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use Barryvdh\Reflection\DocBlock\Tag;
use Barryvdh\Reflection\DocBlock\Tag\ParamTag;
use Barryvdh\Reflection\DocBlock\Tag\ReturnTag;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use phpDocumentor\Reflection\DocBlock\Serializer;
class Method
{
/** @var DocBlock */
/** @var DocBlockBuilder */
protected $phpdoc;
/** @var \ReflectionMethod */
@@ -65,9 +66,9 @@ class Method
//Normalize the description and inherit the docs from parents/interfaces
try {
$this->normalizeParams($this->phpdoc);
$this->normalizeReturn($this->phpdoc);
$this->normalizeDescription($this->phpdoc);
// $this->normalizeParams($this->phpdoc);
// $this->normalizeReturn($this->phpdoc);
// $this->normalizeDescription($this->phpdoc);
} catch (\Exception $e) {
}
@@ -75,7 +76,7 @@ class Method
$this->getParameters($method);
//Make the method static
$this->phpdoc->appendTag(Tag::createInstance('@static', $this->phpdoc));
$this->phpdoc->appendTagline('@static');
}
/**
@@ -83,7 +84,8 @@ class Method
*/
protected function initPhpDoc($method)
{
$this->phpdoc = new DocBlock($method, new Context($this->namespace, $this->classAliases));
$context = new \phpDocumentor\Reflection\Types\Context($this->namespace, $this->classAliases);
$this->phpdoc = DocBlockBuilder::createFromReflector($method, $context);
}
/**
@@ -145,8 +147,8 @@ class Method
*/
public function getDocComment($prefix = "\t\t")
{
$serializer = new DocBlockSerializer(1, $prefix);
return $serializer->getDocComment($this->phpdoc);
$serializer = new Serializer(1, $prefix);
return $serializer->getDocComment($this->phpdoc->getDocBlock());
}
/**
@@ -191,39 +193,6 @@ class Method
return $implode ? implode(', ', $this->params_with_default) : $this->params_with_default;
}
/**
* Get the description and get the inherited docs.
*
* @param DocBlock $phpdoc
*/
protected function normalizeDescription(DocBlock $phpdoc)
{
//Get the short + long description from the DocBlock
$description = $phpdoc->getText();
//Loop through parents/interfaces, to fill in {@inheritdoc}
if (strpos($description, '{@inheritdoc}') !== false) {
$inheritdoc = $this->getInheritDoc($this->method);
$inheritDescription = $inheritdoc->getText();
$description = str_replace('{@inheritdoc}', $inheritDescription, $description);
$phpdoc->setText($description);
$this->normalizeParams($inheritdoc);
$this->normalizeReturn($inheritdoc);
//Add the tags that are inherited
$inheritTags = $inheritdoc->getTags();
if ($inheritTags) {
/** @var Tag $tag */
foreach ($inheritTags as $tag) {
$tag->setDocBlock();
$phpdoc->appendTag($tag);
}
}
}
}
/**
* Normalize the parameters
*