Skip to content

Commit 1044f46

Browse files
isaackearlmfn
andauthored
allow model_locations to have glob patterns (#1059)
* allow model_locations to have glob patterns This if statement check for a valid directory was happening to early. It was checking the string that contained the wildcards to see if it is a valid directory and always failing. Need to check after the foreach starts. fixes #1058 . * test(#1059) Allow glob directories * Fix tests to chdir() into where to expect the glob to work * Update CHANGELOG.md Co-authored-by: Markus Podar <[email protected]>
1 parent fd4d280 commit 1044f46

File tree

5 files changed

+227
-5
lines changed

5 files changed

+227
-5
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ All notable changes to this project will be documented in this file.
1515

1616
### Fixed
1717
- Compatibility with Lumen [\#1043 / mfn](https://github.com/barryvdh/laravel-ide-helper/pull/1043)
18+
- Allow model_locations to have glob patterns [\#1059 / saackearl](https://github.com/barryvdh/laravel-ide-helper/pull/1059)
1819

1920
2020-09-07, 2.8.1
2021
-----------------

src/Console/ModelsCommand.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -305,13 +305,14 @@ protected function loadModels()
305305
$dir = base_path($dir);
306306
}
307307

308-
if (!is_dir($dir)) {
309-
$this->error("Cannot locate directory '{'$dir}'");
310-
continue;
311-
}
312-
313308
$dirs = glob($dir, GLOB_ONLYDIR);
314309
foreach ($dirs as $dir) {
310+
311+
if (!is_dir($dir)) {
312+
$this->error("Cannot locate directory '{'$dir}'");
313+
continue;
314+
}
315+
315316
if (file_exists($dir)) {
316317
$classMap = ClassMapGenerator::createMap($dir);
317318

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AllowGlobDirectory\Services\Post\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
class Post extends Model
10+
{
11+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AllowGlobDirectory;
6+
7+
use Barryvdh\LaravelIdeHelper\Console\ModelsCommand;
8+
use Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AbstractModelsCommand;
9+
10+
final class Test extends AbstractModelsCommand
11+
{
12+
/** @var string */
13+
private $cwd;
14+
15+
protected function setUp(): void
16+
{
17+
parent::setUp();
18+
19+
$this->cwd = getcwd();
20+
}
21+
22+
protected function tearDown(): void
23+
{
24+
chdir($this->cwd);
25+
26+
parent::tearDown();
27+
}
28+
29+
public function test(): void
30+
{
31+
$command = $this->app->make(ModelsCommand::class);
32+
33+
chdir(__DIR__);
34+
35+
$tester = $this->runCommand($command, [
36+
'--dir' => ['Services/*/Models'],
37+
'--write' => true,
38+
]);
39+
40+
$this->assertSame(0, $tester->getStatusCode());
41+
$this->assertStringContainsString('Written new phpDocBlock to', $tester->getDisplay());
42+
$this->assertMatchesMockedSnapshot();
43+
}
44+
}
Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AllowGlobDirectory\Services\Post\Models;
6+
7+
use Illuminate\Database\Eloquent\Model;
8+
9+
/**
10+
* Barryvdh\LaravelIdeHelper\Tests\Console\ModelsCommand\AllowGlobDirectory\Services\Post\Models\Post
11+
*
12+
* @property integer $id
13+
* @property string|null $char_nullable
14+
* @property string $char_not_nullable
15+
* @property string|null $string_nullable
16+
* @property string $string_not_nullable
17+
* @property string|null $text_nullable
18+
* @property string $text_not_nullable
19+
* @property string|null $medium_text_nullable
20+
* @property string $medium_text_not_nullable
21+
* @property string|null $long_text_nullable
22+
* @property string $long_text_not_nullable
23+
* @property integer|null $integer_nullable
24+
* @property integer $integer_not_nullable
25+
* @property integer|null $tiny_integer_nullable
26+
* @property integer $tiny_integer_not_nullable
27+
* @property integer|null $small_integer_nullable
28+
* @property integer $small_integer_not_nullable
29+
* @property integer|null $medium_integer_nullable
30+
* @property integer $medium_integer_not_nullable
31+
* @property integer|null $big_integer_nullable
32+
* @property integer $big_integer_not_nullable
33+
* @property integer|null $unsigned_integer_nullable
34+
* @property integer $unsigned_integer_not_nullable
35+
* @property integer|null $unsigned_tiny_integer_nullable
36+
* @property integer $unsigned_tiny_integer_not_nullable
37+
* @property integer|null $unsigned_small_integer_nullable
38+
* @property integer $unsigned_small_integer_not_nullable
39+
* @property integer|null $unsigned_medium_integer_nullable
40+
* @property integer $unsigned_medium_integer_not_nullable
41+
* @property integer|null $unsigned_big_integer_nullable
42+
* @property integer $unsigned_big_integer_not_nullable
43+
* @property float|null $float_nullable
44+
* @property float $float_not_nullable
45+
* @property float|null $double_nullable
46+
* @property float $double_not_nullable
47+
* @property string|null $decimal_nullable
48+
* @property string $decimal_not_nullable
49+
* @property string|null $unsigned_decimal_nullable
50+
* @property string $unsigned_decimal_not_nullable
51+
* @property integer|null $boolean_nullable
52+
* @property integer $boolean_not_nullable
53+
* @property string|null $enum_nullable
54+
* @property string $enum_not_nullable
55+
* @property string|null $json_nullable
56+
* @property string $json_not_nullable
57+
* @property string|null $jsonb_nullable
58+
* @property string $jsonb_not_nullable
59+
* @property string|null $date_nullable
60+
* @property string $date_not_nullable
61+
* @property string|null $datetime_nullable
62+
* @property string $datetime_not_nullable
63+
* @property string|null $datetimetz_nullable
64+
* @property string $datetimetz_not_nullable
65+
* @property string|null $time_nullable
66+
* @property string $time_not_nullable
67+
* @property string|null $timetz_nullable
68+
* @property string $timetz_not_nullable
69+
* @property string|null $timestamp_nullable
70+
* @property string $timestamp_not_nullable
71+
* @property string|null $timestamptz_nullable
72+
* @property string $timestamptz_not_nullable
73+
* @property integer|null $year_nullable
74+
* @property integer $year_not_nullable
75+
* @property mixed|null $binary_nullable
76+
* @property mixed $binary_not_nullable
77+
* @property string|null $uuid_nullable
78+
* @property string $uuid_not_nullable
79+
* @property string|null $ipaddress_nullable
80+
* @property string $ipaddress_not_nullable
81+
* @property string|null $macaddress_nullable
82+
* @property string $macaddress_not_nullable
83+
* @property \Illuminate\Support\Carbon|null $created_at
84+
* @property \Illuminate\Support\Carbon|null $updated_at
85+
* @method static \Illuminate\Database\Eloquent\Builder|Post newModelQuery()
86+
* @method static \Illuminate\Database\Eloquent\Builder|Post newQuery()
87+
* @method static \Illuminate\Database\Eloquent\Builder|Post query()
88+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNotNullable($value)
89+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBigIntegerNullable($value)
90+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNotNullable($value)
91+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBinaryNullable($value)
92+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNotNullable($value)
93+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereBooleanNullable($value)
94+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNotNullable($value)
95+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCharNullable($value)
96+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereCreatedAt($value)
97+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNotNullable($value)
98+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDateNullable($value)
99+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNotNullable($value)
100+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimeNullable($value)
101+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNotNullable($value)
102+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDatetimetzNullable($value)
103+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNotNullable($value)
104+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDecimalNullable($value)
105+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNotNullable($value)
106+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereDoubleNullable($value)
107+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNotNullable($value)
108+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereEnumNullable($value)
109+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNotNullable($value)
110+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereFloatNullable($value)
111+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereId($value)
112+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNotNullable($value)
113+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIntegerNullable($value)
114+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNotNullable($value)
115+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereIpaddressNullable($value)
116+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNotNullable($value)
117+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonNullable($value)
118+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNotNullable($value)
119+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereJsonbNullable($value)
120+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNotNullable($value)
121+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereLongTextNullable($value)
122+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNotNullable($value)
123+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMacaddressNullable($value)
124+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNotNullable($value)
125+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumIntegerNullable($value)
126+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNotNullable($value)
127+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereMediumTextNullable($value)
128+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNotNullable($value)
129+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereSmallIntegerNullable($value)
130+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNotNullable($value)
131+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereStringNullable($value)
132+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNotNullable($value)
133+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTextNullable($value)
134+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNotNullable($value)
135+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimeNullable($value)
136+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNotNullable($value)
137+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestampNullable($value)
138+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNotNullable($value)
139+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimestamptzNullable($value)
140+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNotNullable($value)
141+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTimetzNullable($value)
142+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNotNullable($value)
143+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereTinyIntegerNullable($value)
144+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNotNullable($value)
145+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedBigIntegerNullable($value)
146+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNotNullable($value)
147+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedDecimalNullable($value)
148+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNotNullable($value)
149+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedIntegerNullable($value)
150+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNotNullable($value)
151+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedMediumIntegerNullable($value)
152+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNotNullable($value)
153+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedSmallIntegerNullable($value)
154+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNotNullable($value)
155+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUnsignedTinyIntegerNullable($value)
156+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUpdatedAt($value)
157+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNotNullable($value)
158+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereUuidNullable($value)
159+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNotNullable($value)
160+
* @method static \Illuminate\Database\Eloquent\Builder|Post whereYearNullable($value)
161+
* @mixin \Eloquent
162+
*/
163+
class Post extends Model
164+
{
165+
}

0 commit comments

Comments
 (0)