From a9ea231679ceffb659e0ad8dfb00c3f3594c382d Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 28 Aug 2017 07:35:56 -0400 Subject: [PATCH 01/19] Support higher order tap() (#554) --- resources/views/meta.php | 1 + 1 file changed, 1 insertion(+) diff --git a/resources/views/meta.php b/resources/views/meta.php index f97a7ac..41ce574 100644 --- a/resources/views/meta.php +++ b/resources/views/meta.php @@ -46,5 +46,6 @@ namespace PHPSTORM_META { override(\head(0), elementType(0)); override(\last(0), elementType(0)); override(\with(0), type(0)); + override(\tap(0), type(0)); } From 55c9bfc33b0e8fc35a8f7939f1d4afe5debf1eb3 Mon Sep 17 00:00:00 2001 From: Chris Morrell Date: Mon, 28 Aug 2017 07:37:22 -0400 Subject: [PATCH 02/19] Allow for configurable meta filename (#553) --- config/ide-helper.php | 2 ++ src/Console/MetaCommand.php | 5 +++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/config/ide-helper.php b/config/ide-helper.php index f481d4c..48a06db 100644 --- a/config/ide-helper.php +++ b/config/ide-helper.php @@ -13,6 +13,8 @@ return array( 'filename' => '_ide_helper', 'format' => 'php', + + 'meta_filename' => '.phpstorm.meta.php', /* |-------------------------------------------------------------------------- diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php index e2bd73f..9c623a6 100644 --- a/src/Console/MetaCommand.php +++ b/src/Console/MetaCommand.php @@ -28,7 +28,6 @@ class MetaCommand extends Command * @var string */ protected $name = 'ide-helper:meta'; - protected $filename = '.phpstorm.meta.php'; /** * The console command description. @@ -138,8 +137,10 @@ class MetaCommand extends Command */ protected function getOptions() { + $filename = $this->config->get('ide-helper.meta_filename'); + return array( - array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $this->filename), + array('filename', 'F', InputOption::VALUE_OPTIONAL, 'The path to the meta file', $filename), ); } } From cb6f52f4d6bbc18a31aac9de58acfd4d8e9f05e2 Mon Sep 17 00:00:00 2001 From: Zakaria Acharki Date: Mon, 28 Aug 2017 12:38:22 +0100 Subject: [PATCH 03/19] Minor typo fix (#548) --- readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/readme.md b/readme.md index 0ec60ae..c049c15 100644 --- a/readme.md +++ b/readme.md @@ -166,7 +166,7 @@ After publishing vendor, simply change the `include_fluent` line your `config/id ```php 'include_fluent' => true, ``` -And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE now. +And then run `php artisan ide-helper:generate` , you will now see all of the Fluent methods are recognized by your IDE. ## PhpStorm Meta for Container instances From ce72ff46631401c2ca8466a730b492e048d01497 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Mon, 28 Aug 2017 13:39:24 +0200 Subject: [PATCH 04/19] Remove exit for static code analysers --- resources/views/helper.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/resources/views/helper.php b/resources/views/helper.php index 89e69ad..dcfdaf2 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -4,12 +4,11 @@ * A helper file for Laravel 5, to provide autocomplete information to your IDE * Generated for Laravel on . * + * This file should not be included in your code, only analyzed by your IDE! + * * @author Barry vd. Heuvel * @see https://github.com/barryvdh/laravel-ide-helper */ -namespace { - exit("This file should not be included, only analyzed by your IDE"); -} $aliases): ?> From fedcb57295befa98016b8ce6322f3dec65ee5441 Mon Sep 17 00:00:00 2001 From: Charles Peterson Date: Mon, 28 Aug 2017 08:12:54 -0500 Subject: [PATCH 05/19] Add an eloquent command (#544) * Add an eloquent command for adding the `@mixin \Eloquent` to the Illuminate\Database\Eloquent\Model * spacing updates... * multi-line function call syntax * Write helper mixin to Eloquent/Model after helper created * Cleanup into helper - similar to Generator * syntax cleanup --- src/Console/EloquentCommand.php | 61 +++++++++++++++++++++++++ src/Console/GeneratorCommand.php | 3 +- src/Eloquent.php | 78 ++++++++++++++++++++++++++++++++ src/IdeHelperServiceProvider.php | 19 ++++++-- 4 files changed, 157 insertions(+), 4 deletions(-) create mode 100644 src/Console/EloquentCommand.php create mode 100644 src/Eloquent.php diff --git a/src/Console/EloquentCommand.php b/src/Console/EloquentCommand.php new file mode 100644 index 0000000..0dd8533 --- /dev/null +++ b/src/Console/EloquentCommand.php @@ -0,0 +1,61 @@ + + * @copyright 2017 Charles A. Peterson / Fruitcake Studio (http://www.fruitcakestudio.nl) + * @license http://www.opensource.org/licenses/mit-license.php MIT + * @link https://github.com/barryvdh/laravel-ide-helper + */ + +namespace Barryvdh\LaravelIdeHelper\Console; + +use Barryvdh\LaravelIdeHelper\Eloquent; +use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; + +/** + * A command to add \Eloquent mixin to Eloquent\Model + * + * @author Charles A. Peterson + */ +class EloquentCommand extends Command +{ + /** + * The console command name. + * + * @var string + */ + protected $name = 'ide-helper:eloquent'; + + /** + * @var Filesystem $files + */ + protected $files; + + /** + * The console command description. + * + * @var string + */ + protected $description = 'Add \Eloquent helper to \Eloquent\Model'; + + /** + * @param Filesystem $files + */ + public function __construct(Filesystem $files) + { + parent::__construct(); + $this->files = $files; + } + + /** + * Execute the console command. + * + * @return void + */ + public function handle() + { + Eloquent::writeEloquentModelHelper($this, $this->files); + } +} diff --git a/src/Console/GeneratorCommand.php b/src/Console/GeneratorCommand.php index be753e0..02cce24 100644 --- a/src/Console/GeneratorCommand.php +++ b/src/Console/GeneratorCommand.php @@ -10,8 +10,8 @@ namespace Barryvdh\LaravelIdeHelper\Console; +use Barryvdh\LaravelIdeHelper\Eloquent; use Barryvdh\LaravelIdeHelper\Generator; -use Illuminate\Config\Repository as ConfigRepository; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Input\InputOption; @@ -115,6 +115,7 @@ class GeneratorCommand extends Command if ($written !== false) { $this->info("A new helper file was written to $filename"); + Eloquent::writeEloquentModelHelper($this, $this->files); } else { $this->error("The helper file could not be created at $filename"); } diff --git a/src/Eloquent.php b/src/Eloquent.php new file mode 100644 index 0000000..c27b1c1 --- /dev/null +++ b/src/Eloquent.php @@ -0,0 +1,78 @@ + + */ +namespace Barryvdh\LaravelIdeHelper; + +use Illuminate\Console\Command; +use Illuminate\Filesystem\Filesystem; +use Barryvdh\Reflection\DocBlock; +use Barryvdh\Reflection\DocBlock\Context; +use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; +use Barryvdh\Reflection\DocBlock\Tag; + +class Eloquent +{ + /** + * Write mixin helper to the Eloquent\Model + * This is needed since laravel/framework v5.4.29 + * + * @param Command $command + * @param Filesystem $files + * + * @return void + */ + public static function writeEloquentModelHelper(Command $command, Filesystem $files) + { + $class = 'Illuminate\Database\Eloquent\Model'; + + $reflection = new \ReflectionClass($class); + $namespace = $reflection->getNamespaceName(); + $originalDoc = $reflection->getDocComment(); + if (!$originalDoc) { + $command->info('Unexpected no document on ' . $class); + } + $phpdoc = new DocBlock($reflection, new Context($namespace)); + + $mixins = $phpdoc->getTagsByName('mixin'); + foreach ($mixins as $m) { + if ($m->getContent() === '\Eloquent') { + $command->info('Tag Exists: @mixin \Eloquent in ' . $class); + + return; + } + } + + // add the Eloquent mixin + $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc)); + + $serializer = new DocBlockSerializer(); + $serializer->getDocComment($phpdoc); + $docComment = $serializer->getDocComment($phpdoc); + + $filename = $reflection->getFileName(); + if ($filename) { + $contents = $files->get($filename); + if ($contents) { + $count = 0; + $contents = str_replace($originalDoc, $docComment, $contents, $count); + if ($count > 0) { + if ($files->put($filename, $contents)) { + $command->info('Wrote @mixin \Eloquent to ' . $filename); + } else { + $command->error('File write failed to ' . $filename); + } + } else { + $command->error('Content did not change ' . $contents); + } + } else { + $command->error('No file contents found ' . $filename); + } + } else { + $command->error('Filename not found ' . $class); + } + } +} diff --git a/src/IdeHelperServiceProvider.php b/src/IdeHelperServiceProvider.php index 0b4c6d5..1305fb8 100644 --- a/src/IdeHelperServiceProvider.php +++ b/src/IdeHelperServiceProvider.php @@ -10,10 +10,11 @@ namespace Barryvdh\LaravelIdeHelper; -use Illuminate\Support\ServiceProvider; +use Barryvdh\LaravelIdeHelper\Console\EloquentCommand; +use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand; use Barryvdh\LaravelIdeHelper\Console\MetaCommand; use Barryvdh\LaravelIdeHelper\Console\ModelsCommand; -use Barryvdh\LaravelIdeHelper\Console\GeneratorCommand; +use Illuminate\Support\ServiceProvider; use Illuminate\View\Engines\EngineResolver; use Illuminate\View\Engines\PhpEngine; use Illuminate\View\Factory; @@ -80,7 +81,19 @@ class IdeHelperServiceProvider extends ServiceProvider } ); - $this->commands('command.ide-helper.generate', 'command.ide-helper.models', 'command.ide-helper.meta'); + $this->app->singleton( + 'command.ide-helper.eloquent', + function ($app) use ($localViewFactory) { + return new EloquentCommand($app['files']); + } + ); + + $this->commands( + 'command.ide-helper.generate', + 'command.ide-helper.models', + 'command.ide-helper.meta', + 'command.ide-helper.eloquent' + ); } /** From 01320a48e3ad0e89b064e4a2380c2735a92ab022 Mon Sep 17 00:00:00 2001 From: Subodh Dahal Date: Mon, 28 Aug 2017 19:01:15 +0545 Subject: [PATCH 06/19] Bugfix: Undefined property: Barryvdh\LaravelIdeHelper\Console\MetaCommand::$config (#562) --- src/Console/MetaCommand.php | 7 ++++++- src/IdeHelperServiceProvider.php | 8 ++++---- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/Console/MetaCommand.php b/src/Console/MetaCommand.php index 9c623a6..13c9ed0 100644 --- a/src/Console/MetaCommand.php +++ b/src/Console/MetaCommand.php @@ -42,6 +42,9 @@ class MetaCommand extends Command /** @var \Illuminate\Contracts\View\Factory */ protected $view; + /** @var \Illuminate\Contracts\Config */ + protected $config; + protected $methods = [ 'new \Illuminate\Contracts\Container\Container', '\Illuminate\Contracts\Container\Container::make(0)', @@ -56,11 +59,13 @@ class MetaCommand extends Command * * @param \Illuminate\Contracts\Filesystem\Filesystem $files * @param \Illuminate\Contracts\View\Factory $view + * @param \Illuminate\Contracts\Config $config */ - public function __construct($files, $view) + public function __construct($files, $view, $config) { $this->files = $files; $this->view = $view; + $this->config = $config; parent::__construct(); } diff --git a/src/IdeHelperServiceProvider.php b/src/IdeHelperServiceProvider.php index 1305fb8..91a64cd 100644 --- a/src/IdeHelperServiceProvider.php +++ b/src/IdeHelperServiceProvider.php @@ -39,7 +39,7 @@ class IdeHelperServiceProvider extends ServiceProvider { $viewPath = __DIR__.'/../resources/views'; $this->loadViewsFrom($viewPath, 'ide-helper'); - + $configPath = __DIR__ . '/../config/ide-helper.php'; if (function_exists('config_path')) { $publishPath = config_path('ide-helper.php'); @@ -59,7 +59,7 @@ class IdeHelperServiceProvider extends ServiceProvider $configPath = __DIR__ . '/../config/ide-helper.php'; $this->mergeConfigFrom($configPath, 'ide-helper'); $localViewFactory = $this->createLocalViewFactory(); - + $this->app->singleton( 'command.ide-helper.generate', function ($app) use ($localViewFactory) { @@ -73,11 +73,11 @@ class IdeHelperServiceProvider extends ServiceProvider return new ModelsCommand($app['files']); } ); - + $this->app->singleton( 'command.ide-helper.meta', function ($app) use ($localViewFactory) { - return new MetaCommand($app['files'], $localViewFactory); + return new MetaCommand($app['files'], $localViewFactory, $app['config']); } ); From ea6d6d0105239d4cbdf5179319b1a03cae891378 Mon Sep 17 00:00:00 2001 From: Carl Evison Date: Sat, 2 Sep 2017 16:44:59 +0100 Subject: [PATCH 07/19] update to the latest code intel (#567) --- readme.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index c049c15..25dcb11 100644 --- a/readme.md +++ b/readme.md @@ -22,7 +22,7 @@ If you don't want to generate it, you can add a pre-generated file to the root f * Generated version for Lumen: https://gist.github.com/barryvdh/be17164b0ad51f832f20 * Generated Phpstorm Meta file: https://gist.github.com/barryvdh/bb6ffc5d11e0a75dba67 -Note: You do need CodeIntel for Sublime Text: https://github.com/SublimeCodeIntel/SublimeCodeIntel +Note: You do need CodeComplice for Sublime Text: https://github.com/spectacles/CodeComplice ### Install @@ -151,9 +151,9 @@ php artisan ide-helper:models --ignore="Post,User" Note: With namespaces, wrap your model name in double-quotes (`"`): `php artisan ide-helper:models "API\User"`, or escape the slashes (`Api\\User`) -For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add +For properly recognition of `Model` methods (i.e. `paginate`, `findOrFail`) you should extend `\Eloquent` or add ```php -/** @mixin \Eloquent */ +/** @mixin \Eloquent */ ``` for your model class. From 721a7cd3f7a1eb22f3cbc621a673df2ff4f72315 Mon Sep 17 00:00:00 2001 From: Greg Roach Date: Sat, 2 Sep 2017 21:25:00 +0100 Subject: [PATCH 08/19] The 'artisan optimize' command is deprecated --- readme.md | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/readme.md b/readme.md index 25dcb11..fbdc6db 100644 --- a/readme.md +++ b/readme.md @@ -66,7 +66,7 @@ You can now re-generate the docs yourself (for future updates) php artisan ide-helper:generate ``` -Note: `bootstrap/compiled.php` has to be cleared first, so run `php artisan clear-compiled` before generating (and `php artisan optimize` after). +Note: `bootstrap/compiled.php` has to be cleared first, so run `php artisan clear-compiled` before generating. You can configure your composer.json to do this after each commit: @@ -75,8 +75,7 @@ You can configure your composer.json to do this after each commit: "post-update-cmd": [ "Illuminate\\Foundation\\ComposerScripts::postUpdate", "php artisan ide-helper:generate", - "php artisan ide-helper:meta", - "php artisan optimize" + "php artisan ide-helper:meta" ] }, ``` From 28f0ac3781c451793ff1c50c8980be1a377936c0 Mon Sep 17 00:00:00 2001 From: "M. Vugteveen" Date: Wed, 13 Sep 2017 14:18:03 +0200 Subject: [PATCH 09/19] also show time in generated files (#574) --- resources/views/helper.php | 2 +- resources/views/meta.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/helper.php b/resources/views/helper.php index dcfdaf2..a41a8d9 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -2,7 +2,7 @@ /** * A helper file for Laravel 5, to provide autocomplete information to your IDE - * Generated for Laravel on . + * Generated for Laravel on . * * This file should not be included in your code, only analyzed by your IDE! * diff --git a/resources/views/meta.php b/resources/views/meta.php index 41ce574..38ef3a6 100644 --- a/resources/views/meta.php +++ b/resources/views/meta.php @@ -4,7 +4,7 @@ namespace PHPSTORM_META { /** * PhpStorm Meta file, to provide autocomplete information for PhpStorm - * Generated on . + * Generated on . * * @author Barry vd. Heuvel * @see https://github.com/barryvdh/laravel-ide-helper From e29e0351355684ad51d1358b3be6cace4213d11f Mon Sep 17 00:00:00 2001 From: Jonas De Smet Date: Thu, 1 Feb 2018 15:53:32 +0100 Subject: [PATCH 10/19] Add DocBlocks for classes too --- resources/views/helper.php | 1 + src/Alias.php | 26 +++++++++++++++++++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/resources/views/helper.php b/resources/views/helper.php index a41a8d9..8bfbfb6 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -15,6 +15,7 @@ namespace { + getDocComment(' ')) ?> getClassType() ?> getExtendsClass() ?> { getMethods() as $method): ?> diff --git a/src/Alias.php b/src/Alias.php index 4902f80..12d23cc 100644 --- a/src/Alias.php +++ b/src/Alias.php @@ -10,6 +10,11 @@ namespace Barryvdh\LaravelIdeHelper; +use Barryvdh\Reflection\DocBlock; +use Barryvdh\Reflection\DocBlock\Context; +use Barryvdh\Reflection\DocBlock\Serializer as DocBlockSerializer; +use ReflectionClass; + class Alias { protected $alias; @@ -27,6 +32,7 @@ class Alias protected $valid = false; protected $magicMethods = array(); protected $interfaces = array(); + protected $phpdoc = null; /** * @param string $alias @@ -56,7 +62,13 @@ class Alias $this->detectNamespace(); $this->detectClassType(); $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') { $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. * From 387efb9b42b90f4380d773362972b619f6ba9b58 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Wed, 7 Feb 2018 09:31:35 +0100 Subject: [PATCH 11/19] Allow L5.6 --- composer.json | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 1af907b..49b35c1 100644 --- a/composer.json +++ b/composer.json @@ -11,15 +11,15 @@ ], "require": { "php": ">=5.4.0", - "illuminate/support": "^5.0,<5.6", - "illuminate/console": "^5.0,<5.6", - "illuminate/filesystem": "^5.0,<5.6", + "illuminate/support": "^5.0,<5.7", + "illuminate/console": "^5.0,<5.7", + "illuminate/filesystem": "^5.0,<5.7", "barryvdh/reflection-docblock": "^2.0.4", "symfony/class-loader": "^2.3|^3.0" }, "require-dev": { - "illuminate/config": "^5.0,<5.6", - "illuminate/view": "^5.0,<5.6", + "illuminate/config": "^5.0,<5.7", + "illuminate/view": "^5.0,<5.7", "phpunit/phpunit" : "4.*", "scrutinizer/ocular": "~1.1", "squizlabs/php_codesniffer": "~2.3", From ea113e8c0bd915aad961dc9999fdce7f58e486bf Mon Sep 17 00:00:00 2001 From: Patrick <943484+iPaat@users.noreply.github.com> Date: Wed, 7 Feb 2018 13:17:03 +0100 Subject: [PATCH 12/19] Fixes a bug where a missing DocBlock caused errors --- src/Eloquent.php | 44 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/src/Eloquent.php b/src/Eloquent.php index c27b1c1..9e5e2bc 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -32,27 +32,57 @@ class Eloquent $reflection = new \ReflectionClass($class); $namespace = $reflection->getNamespaceName(); $originalDoc = $reflection->getDocComment(); + if (!$originalDoc) { $command->info('Unexpected no document on ' . $class); } $phpdoc = new DocBlock($reflection, new Context($namespace)); $mixins = $phpdoc->getTagsByName('mixin'); - foreach ($mixins as $m) { - if ($m->getContent() === '\Eloquent') { - $command->info('Tag Exists: @mixin \Eloquent in ' . $class); + $expectedMixins = [ + '\Eloquent' => false, + '\Illuminate\Database\Eloquent\Builder' => false, + '\Illuminate\Database\Query\Builder' => false, + ]; - return; + foreach ($mixins as $m) { + $mixin = $m->getContent(); + + if(isset($expectedMixins[$mixin])) { + $command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class); + + $expectedMixins[$mixin] = true; } } - // add the Eloquent mixin - $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc)); + $changed = false; + foreach($expectedMixins as $expectedMixin => $present) { + if($present === false) { + $phpdoc->appendTag(Tag::createInstance('@mixin ' . $expectedMixin, $phpdoc)); + + $changed = true; + } + } + + // If nothing's changed, stop here. + if(!$changed) { + return; + } $serializer = new DocBlockSerializer(); $serializer->getDocComment($phpdoc); $docComment = $serializer->getDocComment($phpdoc); + /* + The new DocBlock is appended to the beginning of the class declaration. + Since there is no DocBlock, the declaration is used as a guide. + */ + if (!$originalDoc) { + $originalDoc = 'abstract class Model implements'; + + $docComment .= "\nabstract class Model implements"; + } + $filename = $reflection->getFileName(); if ($filename) { $contents = $files->get($filename); @@ -61,7 +91,7 @@ class Eloquent $contents = str_replace($originalDoc, $docComment, $contents, $count); if ($count > 0) { if ($files->put($filename, $contents)) { - $command->info('Wrote @mixin \Eloquent to ' . $filename); + $command->info('Wrote expected docblock to ' . $filename); } else { $command->error('File write failed to ' . $filename); } From 1fc4284af6dec64e978e61c3117036d008836c23 Mon Sep 17 00:00:00 2001 From: Patrick <943484+iPaat@users.noreply.github.com> Date: Wed, 7 Feb 2018 13:24:36 +0100 Subject: [PATCH 13/19] Fixes for Travis. --- src/Eloquent.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Eloquent.php b/src/Eloquent.php index 9e5e2bc..d84435d 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -48,7 +48,7 @@ class Eloquent foreach ($mixins as $m) { $mixin = $m->getContent(); - if(isset($expectedMixins[$mixin])) { + if (isset($expectedMixins[$mixin])) { $command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class); $expectedMixins[$mixin] = true; @@ -56,8 +56,8 @@ class Eloquent } $changed = false; - foreach($expectedMixins as $expectedMixin => $present) { - if($present === false) { + foreach ($expectedMixins as $expectedMixin => $present) { + if ($present === false) { $phpdoc->appendTag(Tag::createInstance('@mixin ' . $expectedMixin, $phpdoc)); $changed = true; @@ -65,7 +65,7 @@ class Eloquent } // If nothing's changed, stop here. - if(!$changed) { + if (!$changed) { return; } From 2d56afce8e6dc9b495f092fa3029f8d75f8f05d6 Mon Sep 17 00:00:00 2001 From: "Barry vd. Heuvel" Date: Thu, 8 Feb 2018 17:00:48 +0100 Subject: [PATCH 14/19] Revert "Fixes a bug where a missing DocBlock caused errors" --- src/Eloquent.php | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/Eloquent.php b/src/Eloquent.php index d84435d..c27b1c1 100644 --- a/src/Eloquent.php +++ b/src/Eloquent.php @@ -32,57 +32,27 @@ class Eloquent $reflection = new \ReflectionClass($class); $namespace = $reflection->getNamespaceName(); $originalDoc = $reflection->getDocComment(); - if (!$originalDoc) { $command->info('Unexpected no document on ' . $class); } $phpdoc = new DocBlock($reflection, new Context($namespace)); $mixins = $phpdoc->getTagsByName('mixin'); - $expectedMixins = [ - '\Eloquent' => false, - '\Illuminate\Database\Eloquent\Builder' => false, - '\Illuminate\Database\Query\Builder' => false, - ]; - foreach ($mixins as $m) { - $mixin = $m->getContent(); + if ($m->getContent() === '\Eloquent') { + $command->info('Tag Exists: @mixin \Eloquent in ' . $class); - if (isset($expectedMixins[$mixin])) { - $command->info('Tag Exists: @mixin ' . $mixin . ' in ' . $class); - - $expectedMixins[$mixin] = true; + return; } } - $changed = false; - foreach ($expectedMixins as $expectedMixin => $present) { - if ($present === false) { - $phpdoc->appendTag(Tag::createInstance('@mixin ' . $expectedMixin, $phpdoc)); - - $changed = true; - } - } - - // If nothing's changed, stop here. - if (!$changed) { - return; - } + // add the Eloquent mixin + $phpdoc->appendTag(Tag::createInstance("@mixin \\Eloquent", $phpdoc)); $serializer = new DocBlockSerializer(); $serializer->getDocComment($phpdoc); $docComment = $serializer->getDocComment($phpdoc); - /* - The new DocBlock is appended to the beginning of the class declaration. - Since there is no DocBlock, the declaration is used as a guide. - */ - if (!$originalDoc) { - $originalDoc = 'abstract class Model implements'; - - $docComment .= "\nabstract class Model implements"; - } - $filename = $reflection->getFileName(); if ($filename) { $contents = $files->get($filename); @@ -91,7 +61,7 @@ class Eloquent $contents = str_replace($originalDoc, $docComment, $contents, $count); if ($count > 0) { if ($files->put($filename, $contents)) { - $command->info('Wrote expected docblock to ' . $filename); + $command->info('Wrote @mixin \Eloquent to ' . $filename); } else { $command->error('File write failed to ' . $filename); } From bda5120e9a942ee0de7867d0516d0378ea5bdcd7 Mon Sep 17 00:00:00 2001 From: Jeppe Knockaert Date: Wed, 14 Feb 2018 12:06:34 +0100 Subject: [PATCH 15/19] Add morphedByMany relationship --- src/Console/ModelsCommand.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 7359a84..4b7aa5b 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -460,7 +460,8 @@ class ModelsCommand extends Command 'morphOne', 'morphTo', 'morphMany', - 'morphToMany' + 'morphToMany', + 'morphedByMany' ) as $relation) { $search = '$this->' . $relation . '('; if ($pos = stripos($code, $search)) { @@ -470,7 +471,7 @@ class ModelsCommand extends Command if ($relationObj instanceof Relation) { $relatedModel = '\\' . get_class($relationObj->getRelated()); - $relations = ['hasManyThrough', 'belongsToMany', 'hasMany', 'morphMany', 'morphToMany']; + $relations = ['hasManyThrough', 'belongsToMany', 'hasMany', 'morphMany', 'morphToMany', 'morphedByMany']; if (in_array($relation, $relations)) { //Collection or array of models (because Collection is Arrayable) $this->setProperty( From 17982029f06cb229829332599148dc792b4fb7b7 Mon Sep 17 00:00:00 2001 From: Jeppe Knockaert Date: Wed, 14 Feb 2018 12:15:38 +0100 Subject: [PATCH 16/19] Move long one-line array to multiple lines --- src/Console/ModelsCommand.php | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 4b7aa5b..91f9886 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -471,7 +471,14 @@ class ModelsCommand extends Command if ($relationObj instanceof Relation) { $relatedModel = '\\' . get_class($relationObj->getRelated()); - $relations = ['hasManyThrough', 'belongsToMany', 'hasMany', 'morphMany', 'morphToMany', 'morphedByMany']; + $relations = [ + 'hasManyThrough', + 'belongsToMany', + 'hasMany', + 'morphMany', + 'morphToMany', + 'morphedByMany', + ]; if (in_array($relation, $relations)) { //Collection or array of models (because Collection is Arrayable) $this->setProperty( From c7b7ebf1b578c57a437bb586a3059674e99c6e85 Mon Sep 17 00:00:00 2001 From: Jackey Cheung Date: Wed, 21 Mar 2018 11:36:02 +0800 Subject: [PATCH 17/19] suppress PHPStorm formatter --- src/Console/ModelsCommand.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 7359a84..7a79083 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -145,6 +145,7 @@ class ModelsCommand extends Command $output = " Date: Thu, 3 May 2018 16:02:16 -0400 Subject: [PATCH 18/19] Remove dependecy to Symfony\Component\ClassLoader\ClassMapGenerator and replace it with Composer\Autoload\ClassMapGenerator. --- composer.json | 2 +- src/Console/ModelsCommand.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 49b35c1..cfaedee 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "illuminate/console": "^5.0,<5.7", "illuminate/filesystem": "^5.0,<5.7", "barryvdh/reflection-docblock": "^2.0.4", - "symfony/class-loader": "^2.3|^3.0" + "composer/composer": "^1.6", }, "require-dev": { "illuminate/config": "^5.0,<5.7", diff --git a/src/Console/ModelsCommand.php b/src/Console/ModelsCommand.php index 7359a84..71c08d3 100644 --- a/src/Console/ModelsCommand.php +++ b/src/Console/ModelsCommand.php @@ -10,6 +10,7 @@ namespace Barryvdh\LaravelIdeHelper\Console; +use Composer\Autoload\ClassMapGenerator; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Relations\Relation; use Illuminate\Support\Str; @@ -17,7 +18,6 @@ use Illuminate\Filesystem\Filesystem; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\ClassLoader\ClassMapGenerator; use Barryvdh\Reflection\DocBlock; use Barryvdh\Reflection\DocBlock\Context; use Barryvdh\Reflection\DocBlock\Tag; From 4691bc5fbdcebc6a1ae0fe865292ccf654be6b00 Mon Sep 17 00:00:00 2001 From: Timur Zurbaev Date: Sat, 5 May 2018 10:09:30 +0800 Subject: [PATCH 19/19] Remove `mixed` typehint from `Fluent::default` method --- resources/views/helper.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/helper.php b/resources/views/helper.php index 8bfbfb6..e517a60 100644 --- a/resources/views/helper.php +++ b/resources/views/helper.php @@ -72,7 +72,7 @@ namespace Illuminate\Support { * @method Fluent charset(string $charset) Add the character set modifier * @method Fluent collation(string $collation) Add the collation modifier * @method Fluent comment(string $comment) Add comment - * @method Fluent default(mixed $value) Add the default modifier + * @method Fluent default($value) Add the default modifier * @method Fluent first() Select first row * @method Fluent index(string $name = null) Add the in dex clause * @method Fluent on(string $table) `on` of a foreign key