From 647b8ff0d11cbc5ed3228af0e6fbd3cb5fa79438 Mon Sep 17 00:00:00 2001 From: Thach Nguyen Date: Mon, 29 Jan 2018 16:26:01 +0700 Subject: [PATCH] Reuse library "phpdocumentor/reflection-docblock" instead of "barryvdh/reflection-docblock" --- composer.json | 2 +- src/Console/ModelsCommand.php | 11 +++++------ src/Method.php | 30 +++++++++++++++++------------- 3 files changed, 23 insertions(+), 20 deletions(-) diff --git a/composer.json b/composer.json index 3699053..17d5c95 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "illuminate/filesystem": "4.x", "illuminate/database": "4.x", "illuminate/view": "4.x", - "barryvdh/reflection-docblock": "^2.0.4", + "phpdocumentor/reflection-docblock": "^2.0.4", "symfony/class-loader": "~2.3", "kdyby/parse-use-statements": "~0.2" }, diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 5a08b61..a9f1e40 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -15,10 +15,9 @@ use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\ClassLoader\ClassMapGenerator; -use Barryvdh\Reflection\DocBlock; -use Barryvdh\Reflection\DocBlock\Context; -use Barryvdh\Reflection\DocBlock\Tag; -use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Context; +use phpDocumentor\Reflection\DocBlock\Tag; /** * A command to generate autocomplete information for your IDE @@ -399,7 +398,7 @@ class ModelsCommand extends Command $properties = array(); $methods = array(); foreach ($phpdoc->getTags() as $tag) { - /* @var Tag|\Barryvdh\Reflection\DocBlock\Tag\PropertyTag|\Barryvdh\Reflection\DocBlock\Tag\MethodTag $tag */ + /* @var Tag|Tag\PropertyTag|Tag\MethodTag $tag */ $name = $tag->getName(); if ($name == 'property' || $name == 'property-read' || $name == 'property-write') { $properties[] = $tag->getVariableName(); @@ -433,7 +432,7 @@ class ModelsCommand extends Command $phpdoc->appendTag($tag); } - $serializer = new DocBlockSerializer(); + $serializer = new DocBlock\Serializer(); $serializer->getDocComment($phpdoc); $docComment = $serializer->getDocComment($phpdoc); diff --git a/src/Method.php b/src/Method.php index d6af1a3..6a88196 100644 --- a/src/Method.php +++ b/src/Method.php @@ -10,17 +10,15 @@ namespace Barryvdh\LaravelIdeHelper; -use Barryvdh\Reflection\DocBlock; -use Barryvdh\Reflection\DocBlock\Context; -use Barryvdh\Reflection\DocBlock\Tag; -use Barryvdh\Reflection\DocBlock\Tag\ReturnTag; -use Barryvdh\Reflection\DocBlock\Tag\ParamTag; -use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; +use phpDocumentor\Reflection\DocBlock; +use phpDocumentor\Reflection\DocBlock\Context; +use phpDocumentor\Reflection\DocBlock\Tag; +use phpDocumentor\Reflection\DocBlock\Tag\ReturnTag; use Kdyby\ParseUseStatements\UseStatements; class Method { - /** @var \Barryvdh\Reflection\DocBlock */ + /** @var \phpDocumentor\Reflection\DocBlock */ protected $phpdoc; /** @var \ReflectionMethod */ @@ -98,7 +96,7 @@ class Method */ public function getDocComment($prefix = "\t\t", $trim = false) { - $serializer = new DocBlockSerializer(1, $prefix); + $serializer = new DocBlock\Serializer(1, $prefix); $str = $serializer->getDocComment($this->phpdoc); if ($trim) { $str = preg_replace(array('/\s+$/m', '#^(\s*/\*\*[\r\n])(?:\s*\*[\r\n])+#u', '#(?:[\r\n]\s*\*)+([\r\n]\s*\*/)$#u'), array('', '$1', '$1'), $str); @@ -192,20 +190,25 @@ class Method */ protected function normalizeReturnTags(DocBlock $phpdoc) { - $this->return = null; + static $typeProp; + if (!isset($typeProp)) { + $typeProp = new \ReflectionProperty('phpDocumentor\Reflection\DocBlock\Tag\ReturnTag', 'type'); + $typeProp->setAccessible(true); + } + $this->return = null; //Get the return type and adjust them for better autocomplete foreach ($phpdoc->getTags() as $tag) { if ($tag instanceof ReturnTag) { // Convert the keywords - $typeValue = static::convertKeywords($tag->getType(false)); - $tag->setType($typeValue); + $typeValue = static::convertKeywords($typeProp->getValue($tag)); + $typeProp->setValue($tag, $typeValue); // Get the expanded type $typeValue = $tag->getType(); // Replace the interfaces - if (get_class($tag) === ReturnTag::class) { + if (preg_match('/\bReturnTag$/', get_class($tag))) { foreach ($this->interfaces as $interface => $real) { $typeValue = preg_replace('/(^|\|)' . preg_quote($interface, '/') . '\b/', $real, $typeValue); } @@ -213,7 +216,8 @@ class Method } // Re-set the type - $tag->setType($typeValue); + $typeProp->setValue($tag, $typeValue); + $tag->setDescription($tag->getDescription()); } } }