Add DocBlocks for classes too

This commit is contained in:
Jonas De Smet
2018-02-01 15:53:32 +01:00
parent 28f0ac3781
commit e29e035135
2 changed files with 26 additions and 1 deletions
+1
View File
@@ -15,6 +15,7 @@
namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> { namespace <?= $namespace == '__root' ? '' : trim($namespace, '\\') ?> {
<?php foreach($aliases as $alias): ?> <?php foreach($aliases as $alias): ?>
<?= trim($alias->getDocComment(' ')) ?>
<?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> { <?= $alias->getClassType() ?> <?= $alias->getExtendsClass() ?> {
<?php foreach($alias->getMethods() as $method): ?> <?php foreach($alias->getMethods() as $method): ?>
+25 -1
View File
@@ -10,6 +10,11 @@
namespace Barryvdh\LaravelIdeHelper; namespace Barryvdh\LaravelIdeHelper;
use Barryvdh\Reflection\DocBlock;
use Barryvdh\Reflection\DocBlock\Context;
use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer;
use ReflectionClass;
class Alias class Alias
{ {
protected $alias; protected $alias;
@@ -27,6 +32,7 @@ class Alias
protected $valid = false; protected $valid = false;
protected $magicMethods = array(); protected $magicMethods = array();
protected $interfaces = array(); protected $interfaces = array();
protected $phpdoc = null;
/** /**
* @param string $alias * @param string $alias
@@ -56,7 +62,13 @@ class Alias
$this->detectNamespace(); $this->detectNamespace();
$this->detectClassType(); $this->detectClassType();
$this->detectExtendsNamespace(); $this->detectExtendsNamespace();
if(!empty($this->namespace)) {
//Create a DocBlock and serializer instance
$this->phpdoc = new DocBlock(new ReflectionClass($alias), new Context($this->namespace));
}
if ($facade === '\Illuminate\Database\Eloquent\Model') { if ($facade === '\Illuminate\Database\Eloquent\Model') {
$this->usedMethods = array('decrement', 'increment'); $this->usedMethods = array('decrement', 'increment');
} }
@@ -333,6 +345,18 @@ class Alias
} }
} }
/**
* Get the docblock for this alias
*
* @param string $prefix
* @return mixed
*/
public function getDocComment($prefix = "\t\t")
{
$serializer = new DocBlockSerializer(1, $prefix);
return ($this->phpdoc) ? $serializer->getDocComment($this->phpdoc) : '';
}
/** /**
* Output an error. * Output an error.
* *