From e9bc9347cc4683fcdcda00f8185943586ec643e7 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 6 Aug 2014 19:27:22 +0200 Subject: [PATCH] Cleanup --- composer.json | 4 ++-- src/Alias.php | 32 +++++++++++++++++++++----------- src/Console/GeneratorCommand.php | 16 +++++----------- src/Generator.php | 24 +++++++++++++++++++++--- src/IdeHelperServiceProvider.php | 4 +--- src/Method.php | 32 ++++++++++++++++++++++++-------- 6 files changed, 74 insertions(+), 38 deletions(-) diff --git a/composer.json b/composer.json index f598a4a..9a8abcc 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "barryvdh/laravel-ide-helper", "description": "Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.", - "keywords": ["laravel", "autocomplete", "phpstorm", "netbeans", "sublime", "codeintel", "phpdoc"], + "keywords": ["laravel", "autocomplete", "ide", "helper", "phpstorm", "netbeans", "sublime", "codeintel", "phpdoc"], "license": "MIT", "authors": [ { @@ -30,7 +30,7 @@ }, "extra": { "branch-alias": { - "dev-master": "1.10-dev" + "dev-master": "1.11-dev" } } } diff --git a/src/Alias.php b/src/Alias.php index 051fff2..c77be4a 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -3,7 +3,7 @@ * Laravel IDE Helper Generator * * @author Barry vd. Heuvel - * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) + * @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link https://github.com/barryvdh/laravel-ide-helper */ @@ -26,6 +26,12 @@ class Alias protected $magicMethods = array(); protected $interfaces = array(); + /** + * @param string $alias + * @param string $facade + * @param array $magicMethods + * @param array $interfaces + */ public function __construct($alias, $facade, $magicMethods = array(), $interfaces = array()) { $this->alias = $alias; @@ -67,7 +73,6 @@ class Alias echo "Class not exists: $class\r\n"; } } - } /** @@ -129,7 +134,6 @@ class Alias $this->addMagicMethods(); $this->detectMethods(); return $this->methods; - } /** @@ -191,11 +195,9 @@ class Alias $this->error( "PDOException: " . $e->getMessage() . "\nPlease configure your database connection correctly, or use the sqlite memory driver (-M). Skipping $facade." ); - } catch (\Exception $e) { $this->error("Exception: " . $e->getMessage() . "\nSkipping $facade."); } - } /** @@ -212,8 +214,11 @@ class Alias return false; } - protected function addMagicMethods(){ - + /** + * Add magic methods, as defined in the configuration files + */ + protected function addMagicMethods() + { foreach($this->magicMethods as $magic => $real){ list($className, $name) = explode('::', $real); if(!class_exists($className) && !interface_exists($className)){ @@ -230,6 +235,7 @@ class Alias } } } + /** * Get the methods for one or multiple classes. * @@ -257,10 +263,14 @@ class Alias } } - // Helper class to log errors - protected function error($msg) + /** + * Output an error. + * + * @param string $string + * @return void + */ + protected function error($string) { - echo $msg . "\r\n"; + echo $string . "\r\n"; } - } diff --git a/src/Console/GeneratorCommand.php b/src/Console/GeneratorCommand.php index 1e05a63..7c40046 100644 --- a/src/Console/GeneratorCommand.php +++ b/src/Console/GeneratorCommand.php @@ -3,7 +3,7 @@ * Laravel IDE Helper Generator * * @author Barry vd. Heuvel - * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) + * @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link https://github.com/barryvdh/laravel-ide-helper */ @@ -16,11 +16,7 @@ use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; -use Illuminate\Foundation\AliasLoader; -use phpDocumentor\Reflection\DocBlock; -use phpDocumentor\Reflection\DocBlock\Context; -use phpDocumentor\Reflection\DocBlock\Tag; -use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer; + /** * A command to generate autocomplete information for your IDE @@ -103,11 +99,9 @@ class GeneratorCommand extends Command $helpers = ''; } - $generator = new Generator($this->config, $this->view, $helpers); - $output = $generator->generate(); - - - $written = $this->files->put($filename, $output); + $generator = new Generator($this->config, $this->view, $this->getOutput(), $helpers); + $content = $generator->generate(); + $written = $this->files->put($filename, $content); if ($written !== false) { $this->info("A new helper file was written to $filename"); diff --git a/src/Generator.php b/src/Generator.php index 684ff84..b68f81f 100644 --- a/src/Generator.php +++ b/src/Generator.php @@ -3,7 +3,7 @@ * Laravel IDE Helper Generator * * @author Barry vd. Heuvel - * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) + * @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link https://github.com/barryvdh/laravel-ide-helper */ @@ -12,6 +12,7 @@ namespace Barryvdh\LaravelIdeHelper; use Illuminate\Foundation\AliasLoader; use Illuminate\Config\Repository as ConfigRepository; +use Symfony\Component\Console\Output\OutputInterface; class Generator { @@ -21,6 +22,9 @@ class Generator /** @var \Illuminate\View\Factory */ protected $view; + /** @var \Symfony\Component\Console\Output\OutputInterface */ + protected $output; + protected $extra = array(); protected $magic = array(); protected $interfaces = array(); @@ -29,10 +33,12 @@ class Generator /** * @param \Illuminate\Config\Repository $config * @param \Illuminate\View\Factory $view + * @param \Symfony\Component\Console\Output\OutputInterface $output * @param string $helpers */ public function __construct(ConfigRepository $config, /* Illuminate\View\Factory */ $view, + OutputInterface $output = null, $helpers = '' ) { $this->config = $config; @@ -58,7 +64,6 @@ class Generator ->with('namespaces', $this->getNamespaces()) ->with('helpers', $this->helpers) ->render(); - } protected function detectDrivers() @@ -123,7 +128,6 @@ class Generator foreach (AliasLoader::getInstance()->getAliases() as $name => $facade) { $magicMethods = array_key_exists($name, $this->magic) ? $this->magic[$name] : array(); $alias = new Alias($name, $facade, $magicMethods, $this->interfaces); - if ($alias->isValid()) { //Add extra methods, from other classes (magic static calls) @@ -173,4 +177,18 @@ class Generator } } + /** + * Write a string as error output. + * + * @param string $string + * @return void + */ + protected function error($string) + { + if($this->output){ + $this->output->writeln("$string"); + }else{ + echo $string . "\r\n"; + } + } } diff --git a/src/IdeHelperServiceProvider.php b/src/IdeHelperServiceProvider.php index 53edefb..f9cd2db 100644 --- a/src/IdeHelperServiceProvider.php +++ b/src/IdeHelperServiceProvider.php @@ -3,7 +3,7 @@ * Laravel IDE Helper Generator * * @author Barry vd. Heuvel - * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) + * @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link https://github.com/barryvdh/laravel-ide-helper */ @@ -42,14 +42,12 @@ class IdeHelperServiceProvider extends ServiceProvider */ public function register() { - $this->app['command.ide-helper.generate'] = $this->app->share( function ($app) { return new GeneratorCommand($app['config'], $app['files'], $app['view']); } ); - $this->app['command.ide-helper.models'] = $this->app->share( function () { return new ModelsCommand(); diff --git a/src/Method.php b/src/Method.php index f751b5b..1ff0186 100644 --- a/src/Method.php +++ b/src/Method.php @@ -3,7 +3,7 @@ * Laravel IDE Helper Generator * * @author Barry vd. Heuvel - * @copyright 2013 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) + * @copyright 2014 Barry vd. Heuvel / Fruitcake Studio (http://www.fruitcakestudio.nl) * @license http://www.opensource.org/licenses/mit-license.php MIT * @link https://github.com/barryvdh/laravel-ide-helper */ @@ -17,16 +17,24 @@ use phpDocumentor\Reflection\DocBlock\Serializer as DocBlockSerializer; class Method { + /** @var \phpDocumentor\Reflection\DocBlock */ + protected $phpdoc; protected $output = ''; protected $name; protected $namespace; - protected $phpdoc; protected $params = array(); protected $params_with_default = array(); protected $interfaces = array(); - public function __construct($method, $alias, $class, $methodName = null, $interfaces = array()) + /** + * @param \ReflectionMethod $method + * @param string $alias + * @param string $class + * @param string|null $methodName + * @param array $interfaces + */ + public function __construct(\ReflectionMethod $method, $alias, $class, $methodName = null, $interfaces = array()) { $this->interfaces = $interfaces; $this->name = $methodName ?: $method->name; @@ -39,7 +47,7 @@ class Method try { $this->normalizeDescription($method); } catch (\Exception $e) { - $this->info("Cannot normalize method $alias::{$this->name}.."); + $this->error("Cannot normalize method $alias::{$this->name}.."); } //Get the parameters, including formatted default values @@ -57,8 +65,6 @@ class Method $declaringClass = $method->getDeclaringClass(); $this->declaringClassName = '\\' . ltrim($declaringClass->name, '\\'); $this->root = '\\' . ltrim($class->getName(), '\\'); - - } /** @@ -121,7 +127,7 @@ class Method */ public function getParams($implode = true) { - return implode(', ', $this->params); + return $implode ? implode(', ', $this->params) : $this->params; } /** @@ -132,7 +138,7 @@ class Method */ public function getParamsWithDefault($implode = true) { - return implode(', ', $this->params_with_default); + return $implode ? implode(', ', $this->params_with_default) : $this->params_with_default; } /** @@ -250,4 +256,14 @@ class Method } } + /** + * Output an error. + * + * @param string $string + * @return void + */ + protected function error($string) + { + echo $string . "\r\n"; + } }