From f29e6037c04633c3dd0d182e0f3b6dfb91b5f606 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 6 Aug 2014 12:29:26 +0200 Subject: [PATCH] Work on interfaces --- src/Alias.php | 6 ++++-- src/Console/GeneratorCommand.php | 8 ++------ src/Generator.php | 20 +++++++++++--------- src/Method.php | 17 ++++++++++++----- src/config/config.php | 3 +++ 5 files changed, 32 insertions(+), 22 deletions(-) diff --git a/src/Alias.php b/src/Alias.php index e5d989c..f5aa274 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -23,10 +23,12 @@ class Alias protected $methods = array(); protected $used_methods = array(); protected $valid = false; + protected $interfaces = array(); - public function __construct($alias, $facade) + public function __construct($alias, $facade, $interfaces = array()) { $this->alias = $alias; + $this->interfaces = $interfaces; // Make the class absolute $facade = '\\' . ltrim($facade, '\\'); @@ -223,7 +225,7 @@ class Alias // Only add the methods to the output when the root is not the same as the facade. // And don't add the __*() methods if ($this->facade !== $this->root && substr($method->name, 0, 2) !== '__') { - $this->methods[] = new Method($method, $this->alias, $reflection); + $this->methods[] = new Method($method, $this->alias, $reflection, $this->interfaces); } $this->used_methods[] = $method->name; } diff --git a/src/Console/GeneratorCommand.php b/src/Console/GeneratorCommand.php index 50812e8..1e05a63 100644 --- a/src/Console/GeneratorCommand.php +++ b/src/Console/GeneratorCommand.php @@ -53,10 +53,7 @@ class GeneratorCommand extends Command /** @var \Illuminate\View\Factory */ protected $view; - protected $extra; protected $onlyExtend; - protected $helpers; - protected $magic; /** @@ -94,8 +91,7 @@ class GeneratorCommand extends Command $this->useMemoryDriver(); } - $extra = $this->config->get('laravel-ide-helper::extra'); - $magic = $this->config->get('laravel-ide-helper::magic'); + $helpers = ''; if ($this->option('helpers') || ($this->config->get('laravel-ide-helper::include_helpers'))) { foreach ($this->config->get('laravel-ide-helper::helper_files', array()) as $helper) { @@ -107,7 +103,7 @@ class GeneratorCommand extends Command $helpers = ''; } - $generator = new Generator($this->view, $extra, $magic, $helpers); + $generator = new Generator($this->config, $this->view, $helpers); $output = $generator->generate(); diff --git a/src/Generator.php b/src/Generator.php index 74aced3..04d967e 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -15,6 +15,8 @@ use Illuminate\Config\Repository as ConfigRepository; class Generator { + /** @var \Illuminate\Config\Repository */ + protected $config; /** @var \Illuminate\View\Factory */ protected $view; @@ -24,21 +26,21 @@ class Generator protected $helpers; /** + * @param \Illuminate\Config\Repository $config * @param \Illuminate\View\Factory $view - * @param array $extra - * @param array $magic * @param string $helpers */ - public function __construct( /* Illuminate\View\Factory */ - $view, - $extra = array(), - $magic = array(), + public function __construct(ConfigRepository $config, + /* Illuminate\View\Factory */ $view, $helpers = '' ) { + $this->config = $config; $this->view = $view; - $this->extra = $extra; - $this->magic = $magic; + $this->extra = $this->config->get('laravel-ide-helper::extra'); + $this->magic = $this->config->get('laravel-ide-helper::magic'); + $this->interfaces = $this->config->get('laravel-ide-helper::interfaces'); $this->helpers = $helpers; + } /** @@ -66,7 +68,7 @@ class Generator // Get all aliases foreach (AliasLoader::getInstance()->getAliases() as $name => $facade) { - $alias = new Alias($name, $facade); + $alias = new Alias($name, $facade, $this->interfaces); if ($alias->isValid()) { diff --git a/src/Method.php b/src/Method.php index 2e7989b..e93e7b0 100644 --- a/src/Method.php +++ b/src/Method.php @@ -24,11 +24,12 @@ class Method protected $phpdoc; protected $params = array(); protected $params_with_default = array(); + protected $interfaces = array(); - public function __construct($method, $alias, $class, $methodName = null) + public function __construct($method, $alias, $class, $interfaces = array()) { - - $this->name = $methodName ?: $method->name; + $this->interfaces = $interfaces; + $this->name = $method->name; $this->namespace = $method->getDeclaringClass()->getNamespaceName(); //Create a DocBlock and serializer instance @@ -38,7 +39,7 @@ class Method try { $this->normalizeDescription($method); } catch (\Exception $e) { - $this->info("Cannot normalize method $alias::$methodName.."); + $this->info("Cannot normalize method $alias::{$this->name}.."); } //Get the parameters, including formatted default values @@ -173,12 +174,18 @@ class Method //Get the return type and adjust them for beter autocomplete $returnTags = $this->phpdoc->getTagsByName('return'); if ($returnTags) { - /** @var $tag */ + /** @var Tag $tag */ $tag = reset($returnTags); $returnValue = $tag->getType(); + + foreach($this->interfaces as $interface => $real){ + $returnValue = str_replace($interface, $real, $returnValue); + } + $tag->setContent($returnValue); } else { $returnValue = null; } + return $returnValue; } diff --git a/src/config/config.php b/src/config/config.php index 89b3dad..6925516 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -70,6 +70,9 @@ return array( 'alert' => 'Monolog\Logger::addAlert', 'emergency' => 'Monolog\Logger::addEmergency', ) + ), + 'interfaces' => array( + '\Illuminate\Auth\UserInterface' => '\User', ) );