Skip to content

Commit 3e671ab

Browse files
authored
Merge branch 'master' into master
2 parents c10d2e6 + 532ae5b commit 3e671ab

File tree

10 files changed

+155
-21
lines changed

10 files changed

+155
-21
lines changed

.gitattributes

+6
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,11 @@
55
/.gitattributes export-ignore
66
/.github export-ignore
77
/.gitignore export-ignore
8+
/.editorconfig export-ignore
89
/phpunit.xml.dist export-ignore
910
/tests export-ignore
11+
/.php_cs.common.php export-ignore
12+
/.php_cs.dist export-ignore
13+
/.php_cs.tests.php export-ignore
14+
/psalm.xml export-ignore
15+
/psalm-baseline.xml export-ignore

CHANGELOG.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,10 @@ All notable changes to this project will be documented in this file.
99
- Add support for Attribute accessors with no backing field or type hinting [#1315 / pindab0ter](https://github.com/barryvdh/laravel-ide-helper/pull/1338).
1010

1111
### Fixed
12+
- Fix return type of methods provided by `SoftDeletes` [#1345 / KentarouTakeda](https://github.com/barryvdh/laravel-ide-helper/pull/1345)
1213
- Handle PHP 8.1 deprecation warnings when passing `null` to `new \ReflectionClass` [#1351 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1351)
13-
14+
- Fix issue where \Eloquent is not included when using write_mixin [#1352 / Jefemy](https://github.com/barryvdh/laravel-ide-helper/pull/1352)
15+
- Fix model factory method arguments for Laravel >= 9 [#1361 / wimski](https://github.com/barryvdh/laravel-ide-helper/pull/1361)
1416

1517
2022-03-06, 2.12.3
1618
------------------

src/Console/ModelsCommand.php

+17-8
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,7 @@ protected function getTypeOverride($type)
463463
*/
464464
public function getPropertiesFromTable($model)
465465
{
466+
$database = $model->getConnection()->getDatabaseName();
466467
$table = $model->getConnection()->getTablePrefix() . $model->getTable();
467468
$schema = $model->getConnection()->getDoctrineSchemaManager();
468469
$databasePlatform = $schema->getDatabasePlatform();
@@ -482,11 +483,6 @@ public function getPropertiesFromTable($model)
482483
$databasePlatform->registerDoctrineTypeMapping($yourTypeName, $doctrineTypeName);
483484
}
484485

485-
$database = null;
486-
if (strpos($table, '.')) {
487-
[$database, $table] = explode('.', $table);
488-
}
489-
490486
$columns = $schema->listTableColumns($table, $database);
491487

492488
if (!$columns) {
@@ -926,10 +922,19 @@ protected function createPhpDocs($class)
926922
$phpdoc->appendTag($tag);
927923
}
928924

929-
if ($this->write && !$phpdoc->getTagsByName('mixin')) {
925+
if ($this->write) {
930926
$eloquentClassNameInModel = $this->getClassNameInDestinationFile($reflection, 'Eloquent');
927+
928+
// remove the already existing tag to prevent duplicates
929+
foreach ($phpdoc->getTagsByName('mixin') as $tag) {
930+
if($tag->getContent() === $eloquentClassNameInModel) {
931+
$phpdoc->deleteTag($tag);
932+
}
933+
}
934+
931935
$phpdoc->appendTag(Tag::createInstance('@mixin ' . $eloquentClassNameInModel, $phpdoc));
932936
}
937+
933938
if ($this->phpstorm_noinspections) {
934939
/**
935940
* Facades, Eloquent API
@@ -1220,7 +1225,7 @@ protected function getSoftDeleteMethods($model)
12201225
$traits = class_uses_recursive($model);
12211226
if (in_array('Illuminate\\Database\\Eloquent\\SoftDeletes', $traits)) {
12221227
$modelName = $this->getClassNameInDestinationFile($model, get_class($model));
1223-
$builder = $this->getClassNameInDestinationFile($model, \Illuminate\Database\Query\Builder::class);
1228+
$builder = $this->getClassNameInDestinationFile($model, \Illuminate\Database\Eloquent\Builder::class);
12241229
$this->setMethod('withTrashed', $builder . '|' . $modelName, []);
12251230
$this->setMethod('withoutTrashed', $builder . '|' . $modelName, []);
12261231
$this->setMethod('onlyTrashed', $builder . '|' . $modelName, []);
@@ -1258,7 +1263,11 @@ protected function getFactoryMethods($model)
12581263
return;
12591264
}
12601265

1261-
$this->setMethod('factory', $factory, ['...$parameters']);
1266+
if (version_compare($this->laravel->version(), '9', '>=')) {
1267+
$this->setMethod('factory', $factory, ['$count = null, $state = []']);
1268+
} else {
1269+
$this->setMethod('factory', $factory, ['...$parameters']);
1270+
}
12621271
}
12631272

12641273
/**

tests/Console/ModelsCommand/Factories/Test.php

+25-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,33 @@
1313

1414
class Test extends AbstractModelsCommand
1515
{
16-
public function test(): void
16+
public function test_8(): void
1717
{
18-
if (!version_compare(Application::VERSION, '8.2', '>=')) {
18+
if (!version_compare(Application::VERSION, '8.2', '>=') || !version_compare(Application::VERSION, '9', '<')) {
1919
$this->markTestSkipped(
20-
'This test only works in Laravel >= 8.2'
20+
'This test only works in Laravel >= 8.2 and < 9'
21+
);
22+
}
23+
24+
Factory::guessFactoryNamesUsing(static::getFactoryNameResolver());
25+
26+
$command = $this->app->make(ModelsCommand::class);
27+
28+
$tester = $this->runCommand($command, [
29+
'--write' => true,
30+
]);
31+
32+
$this->assertSame(0, $tester->getStatusCode());
33+
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
34+
$this->assertStringNotContainsString('not found', $tester->getDisplay());
35+
$this->assertMatchesMockedSnapshot();
36+
}
37+
38+
public function test_9(): void
39+
{
40+
if (!version_compare(Application::VERSION, '9', '>=')) {
41+
$this->markTestSkipped(
42+
'This test only works in Laravel >= 9'
2143
);
2244
}
2345

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
6+
7+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory;
8+
use Illuminate\Database\Eloquent\Factories\HasFactory;
9+
use Illuminate\Database\Eloquent\Model;
10+
11+
/**
12+
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithCustomNamespace
13+
*
14+
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\CustomSpace\ModelWithCustomNamespaceFactory factory($count = null, $state = [])
15+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newModelQuery()
16+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace newQuery()
17+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithCustomNamespace query()
18+
* @mixin \Eloquent
19+
*/
20+
class ModelWithCustomNamespace extends Model
21+
{
22+
use HasFactory;
23+
24+
/**
25+
* Create a new factory instance for the model.
26+
*
27+
* @return \Illuminate\Database\Eloquent\Factories\Factory
28+
*/
29+
protected static function newFactory()
30+
{
31+
return ModelWithCustomNamespaceFactory::new();
32+
}
33+
}
34+
<?php
35+
36+
declare(strict_types=1);
37+
38+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
39+
40+
use Illuminate\Database\Eloquent\Factories\HasFactory;
41+
use Illuminate\Database\Eloquent\Model;
42+
43+
/**
44+
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithFactory
45+
*
46+
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithFactoryFactory factory($count = null, $state = [])
47+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newModelQuery()
48+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory newQuery()
49+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithFactory query()
50+
* @mixin \Eloquent
51+
*/
52+
class ModelWithFactory extends Model
53+
{
54+
use HasFactory;
55+
}
56+
<?php
57+
58+
declare(strict_types=1);
59+
60+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
61+
62+
/**
63+
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithNestedFactory
64+
*
65+
* @method static \Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Factories\ModelWithNestedFactoryFactory factory($count = null, $state = [])
66+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newModelQuery()
67+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory newQuery()
68+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithNestedFactory query()
69+
* @mixin \Eloquent
70+
*/
71+
class ModelWithNestedFactory extends ModelWithFactory
72+
{
73+
}
74+
<?php
75+
76+
declare(strict_types=1);
77+
78+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models;
79+
80+
use Illuminate\Database\Eloquent\Factories\HasFactory;
81+
use Illuminate\Database\Eloquent\Model;
82+
83+
/**
84+
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\Factories\Models\ModelWithoutFactory
85+
*
86+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newModelQuery()
87+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory newQuery()
88+
* @method static \Illuminate\Database\Eloquent\Builder|ModelWithoutFactory query()
89+
* @mixin \Eloquent
90+
*/
91+
class ModelWithoutFactory extends Model
92+
{
93+
use HasFactory;
94+
}

tests/Console/ModelsCommand/GeneratePhpdocWithForcedFqn/__snapshots__/Test__test__1.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newModelQuery()
9090
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post newQuery()
9191
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post null(string $unusedParam)
92-
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onlyTrashed()
92+
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post onlyTrashed()
9393
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post query()
9494
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNotNullable($value)
9595
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereBigIntegerNullable($value)
@@ -164,8 +164,8 @@
164164
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereUuidNullable($value)
165165
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereYearNotNullable($value)
166166
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post whereYearNullable($value)
167-
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withTrashed()
168-
* @method static \Illuminate\Database\Query\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withoutTrashed()
167+
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withTrashed()
168+
* @method static \Illuminate\Database\Eloquent\Builder|\Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\GeneratePhpdocWithForcedFqn\Models\Post withoutTrashed()
169169
* @mixin \Eloquent
170170
*/
171171
class Post extends Model

tests/Console/ModelsCommand/GeneratePhpdocWithFqn/__snapshots__/Test__test__1.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@
9595
* @method static EloquentBuilder|Post newModelQuery()
9696
* @method static EloquentBuilder|Post newQuery()
9797
* @method static EloquentBuilder|Post null(string $unusedParam)
98-
* @method static QueryBuilder|Post onlyTrashed()
98+
* @method static EloquentBuilder|Post onlyTrashed()
9999
* @method static EloquentBuilder|Post query()
100100
* @method static EloquentBuilder|Post whereBigIntegerNotNullable($value)
101101
* @method static EloquentBuilder|Post whereBigIntegerNullable($value)
@@ -170,8 +170,8 @@
170170
* @method static EloquentBuilder|Post whereUuidNullable($value)
171171
* @method static EloquentBuilder|Post whereYearNotNullable($value)
172172
* @method static EloquentBuilder|Post whereYearNullable($value)
173-
* @method static QueryBuilder|Post withTrashed()
174-
* @method static QueryBuilder|Post withoutTrashed()
173+
* @method static EloquentBuilder|Post withTrashed()
174+
* @method static EloquentBuilder|Post withoutTrashed()
175175
* @mixin Eloquent
176176
*/
177177
class Post extends Model

tests/Console/ModelsCommand/GeneratePhpdocWithMixin/Models/Post.php

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
/**
1010
* @property $someProp
1111
* @method someMethod(string $method)
12+
* @mixin IdeHelperPost
1213
*/
1314
class Post extends Model
1415
{

tests/Console/ModelsCommand/SoftDeletes/__snapshots__/Test__test__1.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
* @property integer $id
1414
* @method static \Illuminate\Database\Eloquent\Builder|Simple newModelQuery()
1515
* @method static \Illuminate\Database\Eloquent\Builder|Simple newQuery()
16-
* @method static \Illuminate\Database\Query\Builder|Simple onlyTrashed()
16+
* @method static \Illuminate\Database\Eloquent\Builder|Simple onlyTrashed()
1717
* @method static \Illuminate\Database\Eloquent\Builder|Simple query()
1818
* @method static \Illuminate\Database\Eloquent\Builder|Simple whereId($value)
19-
* @method static \Illuminate\Database\Query\Builder|Simple withTrashed()
20-
* @method static \Illuminate\Database\Query\Builder|Simple withoutTrashed()
19+
* @method static \Illuminate\Database\Eloquent\Builder|Simple withTrashed()
20+
* @method static \Illuminate\Database\Eloquent\Builder|Simple withoutTrashed()
2121
* @mixin \Eloquent
2222
*/
2323
class Simple extends Model

0 commit comments

Comments
 (0)