Skip to content

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

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

Merged
merged 1 commit into from
Apr 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Illuminate/Database/Console/Factories/FactoryMakeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,22 @@ protected function getStub()
*/
protected function buildClass($name)
{
$model = $this->option('model')
$namespaceModel = $this->option('model')
? $this->qualifyClass($this->option('model'))
: 'Model';
: trim($this->rootNamespace(), '\\').'\\Model';

$model = class_basename($namespaceModel);

return str_replace(
'DummyModel', $model, parent::buildClass($name)
[
'NamespacedDummyModel',
'DummyModel',
],
[
$namespaceModel,
$model,
],
parent::buildClass($name)
);
}

Expand Down
3 changes: 3 additions & 0 deletions src/Illuminate/Database/Console/Factories/stubs/factory.stub
Original file line number Diff line number Diff line change
@@ -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.


use Faker\Generator as Faker;
use NamespacedDummyModel;

$factory->define(DummyModel::class, function (Faker $faker) {
return [
Expand Down