diff --git a/config/ide-helper.php b/config/ide-helper.php index 80366da..2a24d78 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -193,4 +193,16 @@ return array( 'integer' => 'int', 'boolean' => 'bool', ), + + /* + |-------------------------------------------------------------------------- + | Include DocBlocks from classes + |-------------------------------------------------------------------------- + | + | Include DocBlocks from classes to allow additional code inspection for + | magic methods and properties. + | + */ + 'include_class_docblocks' => false, + ); diff --git a/src/Alias.php b/src/Alias.php index 7042c12..009a740 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -10,11 +10,12 @@ namespace Barryvdh\LaravelIdeHelper; +use ReflectionClass; use Barryvdh\Reflection\DocBlock; use Barryvdh\Reflection\DocBlock\Context; -use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; use Barryvdh\Reflection\DocBlock\Tag\MethodTag; -use ReflectionClass; +use Illuminate\Config\Repository as ConfigRepository; +use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; class Alias { @@ -35,17 +36,22 @@ class Alias protected $interfaces = array(); protected $phpdoc = null; + /** @var ConfigRepository */ + protected $config; + /** - * @param string $alias - * @param string $facade - * @param array $magicMethods - * @param array $interfaces + * @param ConfigRepository $config + * @param string $alias + * @param string $facade + * @param array $magicMethods + * @param array $interfaces */ - public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array()) + public function __construct($config, $alias, $facade, $magicMethods = array(), $interfaces = array()) { $this->alias = $alias; $this->magicMethods = $magicMethods; $this->interfaces = $interfaces; + $this->config = $config; // Make the class absolute $facade = '\\' . ltrim($facade, '\\'); @@ -403,10 +409,20 @@ class Alias $serializer = new DocBlockSerializer(1, $prefix); if ($this->phpdoc) { + if ($this->config->get('ide-helper.include_class_docblocks')) { + // if a class doesn't expose any DocBlock tags + // we can perform reflection on the class and + // add in the original class DocBlock + if (count($this->phpdoc->getTags()) === 0) { + $class = new ReflectionClass($this->root); + $this->phpdoc = new DocBlock($class->getDocComment()); + } + } + $this->removeDuplicateMethodsFromPhpDoc(); return $serializer->getDocComment($this->phpdoc); } - + return ''; } diff --git a/src/Generator.php b/src/Generator.php index e3d5cf1..e1afc53 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -203,7 +203,7 @@ class Generator } $magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array(); - $alias = new Alias($name, $facade, $magicMethods, $this->interfaces); + $alias = new Alias($this->config, $name, $facade, $magicMethods, $this->interfaces); if ($alias->isValid()) { //Add extra methods, from other classes (magic static calls) if (array_key_exists($name, $this->extra)) {