Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.8] Enh: FactoryMakeCommand updated to generate more IDE friendly code #28188

Merged
merged 1 commit into from
Apr 12, 2019

Conversation

klimov-paul
Copy link
Contributor

Update 'make:factory' command to generate code, which is more consistent regardless to other generators:

  • import model via use statement instead of usage fully qualified class name inline.
  • added PHPDoc hint for $factory variable, facilitating better IDE type-hinting and static analysis

With this patch command php artisan make:factory -m Foo FooFactory generates following code:

<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */

use Faker\Generator as Faker;
use App\Foo;

$factory->define(Foo::class, function (Faker $faker) {
    return [
        //
    ];
});

@driesvints driesvints changed the title Enh: FactoryMakeCommand updated to generate more IDE friendly code [5.8] Enh: FactoryMakeCommand updated to generate more IDE friendly code Apr 11, 2019
@@ -1,6 +1,9 @@
<?php

/* @var $factory \Illuminate\Database\Eloquent\Factory */
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove this DocBlock. #24647.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this correct? I think DockBlocks have to start with /** and this is just /*

http://docs.phpdoc.org/guides/docblocks.html

Copy link
Contributor Author

@klimov-paul klimov-paul Apr 16, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Such var description should be recognized correctly by any modern IDE. It is recognized by PHPStorm at least.
In the same time having this as PHPDoc block (e.g. `/**``) may cause problem with PHP code style fixers as they consider this to be a PHPDoc, which is not bound to function or class definition, and thus is incorrect.

@klimov-paul
Copy link
Contributor Author

This has requested and denied many times.

If some changeset constantly reappear in PRs, perhaps it means there is a point behind it, and it should be reconsidered from different angle.

Without the doc comment IDE consider factory code as the one containing an error and does not provide type-hinting in case you with to add a state definition:
no-comment

With the doc comment IDE consider code to be corrent and provide the type-hint for the factory methods:
has-comments

Please remove this DocBlock

Sorry, would not do this. You are free to edit the PR manually or close it altogether, I see not point to spent any more efforts in this.

@taylorotwell taylorotwell merged commit 1300902 into laravel:5.8 Apr 12, 2019
@taylorotwell
Copy link
Member

I'll just give in on this, heh. I think it kinda harms the "tranquility" of the file having some IDE centric docblock in there but I'm just tired of fighting that battle and maybe I'm wrong anyways. 🤷‍♂️

@ahmadmayahi
Copy link
Contributor

Too late to comment on this, but I disagree with such additions.
This is a trick rather than an improvement.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants