From 37d146cd6d6a97ec29fd02a3d35c803274f17589 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 9 May 2013 22:09:29 +0200 Subject: [PATCH] Make non-static instead of skipping So the parent functions are still accessible, without errors. --- .../LaravelIdeHelper/GeneratorCommand.php | 32 +++++++++++-------- src/config/config.php | 8 ++--- 2 files changed, 22 insertions(+), 18 deletions(-) diff --git a/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php b/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php index 19a1923..5f2009e 100644 --- a/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php +++ b/src/Barryvdh/LaravelIdeHelper/GeneratorCommand.php @@ -40,7 +40,7 @@ class GeneratorCommand extends Command { } $extra = \Config::get('laravel-ide-helper::extra'); - $skip = \Config::get('laravel-ide-helper::skip'); + $nonstatic = \Config::get('laravel-ide-helper::nonstatic'); $onlyExtend = \Config::get('laravel-ide-helper::only_extend'); if( $this->option('helpers') || (\Config::get('laravel-ide-helper::include_helpers') && ! $this->option('nohelpers'))){ @@ -51,7 +51,7 @@ class GeneratorCommand extends Command { $sublime = $this->option('sublime') || \Config::get('laravel-ide-helper::sublime'); - $content = $this->generateDocs($extra, $skip, $onlyExtend, $helpers, $sublime); + $content = $this->generateDocs($extra, $nonstatic, $onlyExtend, $helpers, $sublime); $written = \File::put($filename, $content); @@ -98,7 +98,7 @@ class GeneratorCommand extends Command { ); } - protected function generateDocs($extra = array(), $skip = array(), $onlyExtend = array(), $helpers = array(), $sublime = false){ + protected function generateDocs($extra = array(), $nonstatic = array(), $onlyExtend = array(), $helpers = array(), $sublime = false){ $aliasLoader = AliasLoader::getInstance(); @@ -162,20 +162,23 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n"; if(!in_array($alias, $onlyExtend)) { - if(array_key_exists($alias, $skip)){ - $skipMethods = $skip[$alias]; + $usedMethods = array(); + if(array_key_exists($alias, $nonstatic) ){ + $nonstaticMethods = $nonstatic[$alias]; }else{ - $skipMethods = array(); + $nonstaticMethods = array(); } + $methods = $d->getMethods(); if($methods) { foreach ($methods as $method) { - if(!in_array($method->name, $skipMethods)){ - $output .= $this->parseMethod($method, $alias, $root, $sublime); - $skipMethods[] = $method->name; + if(!in_array($method->name, $usedMethods)){ + $static = !in_array($method->name, $nonstaticMethods); + $output .= $this->parseMethod($method, $alias, $root, $sublime, $static); + $usedMethods[] = $method->name; } } } @@ -195,9 +198,10 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n"; $output .= "\t/**\n\t * @var \\$extraClass \$$rootParam\n\t */\n\t static private \$$rootParam;\n\n"; foreach ($methods as $method) { - if(!in_array($method->name, $skipMethods)){ - $output .= $this->parseMethod($method, $alias, $extraClass, $sublime, $rootParam); - $skipMethods[] = $method->name; + if(!in_array($method->name, $usedMethods)){ + $static = !in_array($method->name, $nonstaticMethods); + $output .= $this->parseMethod($method, $alias, $extraClass, $sublime, $static, $rootParam); + $usedMethods[] = $method->name; } } @@ -225,7 +229,7 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n"; return $output; } - protected function parseMethod($method, $alias, $root, $sublime, $rootParam = 'root'){ + protected function parseMethod($method, $alias, $root, $sublime, $static = true, $rootParam = 'root'){ if($method->name === '__clone'){ return ''; } @@ -262,7 +266,7 @@ namespace {\n\tdie('Only to be used as an helper for your IDE');\n}\n\n"; }else{ $output .= "\t * @return ".$returnValue."\n"; } - $output .= "\t */\n\t public static function ".$method->name."("; + $output .= "\t */\n\t public ".($static ? 'static' : '')." function ".$method->name."("; $reflection = $method->getReflectionObject(); diff --git a/src/config/config.php b/src/config/config.php index 1709a5b..3ec5d79 100644 --- a/src/config/config.php +++ b/src/config/config.php @@ -62,15 +62,15 @@ return array( /* |-------------------------------------------------------------------------- - | Skipped methods + | Non-static methods |-------------------------------------------------------------------------- | - | These functions aren't actually facade calls, so don't include them as helper + | These functions aren't actually facade calls, so don't make them static | */ - 'skip' => array( - 'Eloquent' => array('freshTimestamp'), + 'nonstatic' => array( + 'Eloquent' => array('freshTimestamp', 'newCollection', 'toArray', 'toJson', 'toSql'), ), /*