Skip to content

Commit 3c0db3d

Browse files
authored
Added IDE helper annotations for models (#138)
* Added IDE helper annotations for models * Deleted and ignored `_ide_helper_models.php`
1 parent 439d213 commit 3c0db3d

13 files changed

+381
-2
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ yarn-error.log
2121
/storage/debugbar
2222
.phpstorm.meta.php
2323
_ide_helper.php
24+
_ide_helper_models.php

app/Models/User.php

+3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Illuminate\Foundation\Auth\User as Authenticatable;
88
use Illuminate\Notifications\Notifiable;
99

10+
/**
11+
* @mixin IdeHelperUser
12+
*/
1013
class User extends Authenticatable
1114
{
1215
use HasFactory, Notifiable;

app/User.php

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
use Illuminate\Foundation\Auth\User as Authenticatable;
77
use \Storage;
88

9+
/**
10+
* @mixin IdeHelperUser
11+
*/
912
class User extends \Wave\User
1013
{
1114

config/ide-helper.php

+345
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,345 @@
1+
<?php
2+
declare(strict_types=1);
3+
4+
return [
5+
6+
/*
7+
|--------------------------------------------------------------------------
8+
| Filename & Format
9+
|--------------------------------------------------------------------------
10+
|
11+
| The default filename
12+
|
13+
*/
14+
15+
'filename' => '_ide_helper.php',
16+
17+
/*
18+
|--------------------------------------------------------------------------
19+
| Models filename
20+
|--------------------------------------------------------------------------
21+
|
22+
| The default filename for the models helper file
23+
|
24+
*/
25+
26+
'models_filename' => '_ide_helper_models.php',
27+
28+
/*
29+
|--------------------------------------------------------------------------
30+
| Where to write the PhpStorm specific meta file
31+
|--------------------------------------------------------------------------
32+
|
33+
| PhpStorm also supports the directory `.phpstorm.meta.php/` with arbitrary
34+
| files in it, should you need additional files for your project; e.g.
35+
| `.phpstorm.meta.php/laravel_ide_Helper.php'.
36+
|
37+
*/
38+
'meta_filename' => '.phpstorm.meta.php',
39+
40+
/*
41+
|--------------------------------------------------------------------------
42+
| Fluent helpers
43+
|--------------------------------------------------------------------------
44+
|
45+
| Set to true to generate commonly used Fluent methods
46+
|
47+
*/
48+
49+
'include_fluent' => true,
50+
51+
/*
52+
|--------------------------------------------------------------------------
53+
| Factory Builders
54+
|--------------------------------------------------------------------------
55+
|
56+
| Set to true to generate factory generators for better factory()
57+
| method auto-completion.
58+
|
59+
| Deprecated for Laravel 8 or latest.
60+
|
61+
*/
62+
63+
'include_factory_builders' => false,
64+
65+
/*
66+
|--------------------------------------------------------------------------
67+
| Write Model Magic methods
68+
|--------------------------------------------------------------------------
69+
|
70+
| Set to false to disable write magic methods of model
71+
|
72+
*/
73+
74+
'write_model_magic_where' => true,
75+
76+
/*
77+
|--------------------------------------------------------------------------
78+
| Write Model External Eloquent Builder methods
79+
|--------------------------------------------------------------------------
80+
|
81+
| Set to false to disable write external eloquent builder methods
82+
|
83+
*/
84+
85+
'write_model_external_builder_methods' => true,
86+
87+
/*
88+
|--------------------------------------------------------------------------
89+
| Write Model relation count properties
90+
|--------------------------------------------------------------------------
91+
|
92+
| Set to false to disable writing of relation count properties to model DocBlocks.
93+
|
94+
*/
95+
96+
'write_model_relation_count_properties' => true,
97+
98+
/*
99+
|--------------------------------------------------------------------------
100+
| Write Eloquent Model Mixins
101+
|--------------------------------------------------------------------------
102+
|
103+
| This will add the necessary DocBlock mixins to the model class
104+
| contained in the Laravel Framework. This helps the IDE with
105+
| auto-completion.
106+
|
107+
| Please be aware that this setting changes a file within the /vendor directory.
108+
|
109+
*/
110+
111+
'write_eloquent_model_mixins' => false,
112+
113+
/*
114+
|--------------------------------------------------------------------------
115+
| Helper files to include
116+
|--------------------------------------------------------------------------
117+
|
118+
| Include helper files. By default not included, but can be toggled with the
119+
| -- helpers (-H) option. Extra helper files can be included.
120+
|
121+
*/
122+
123+
'include_helpers' => false,
124+
125+
'helper_files' => [
126+
base_path() . '/vendor/laravel/framework/src/Illuminate/Support/helpers.php',
127+
],
128+
129+
/*
130+
|--------------------------------------------------------------------------
131+
| Model locations to include
132+
|--------------------------------------------------------------------------
133+
|
134+
| Define in which directories the ide-helper:models command should look
135+
| for models.
136+
|
137+
| glob patterns are supported to easier reach models in sub-directories,
138+
| e.g. `app/Services/* /Models` (without the space)
139+
|
140+
*/
141+
142+
'model_locations' => [
143+
'app/Models',
144+
'wave/src'
145+
],
146+
147+
/*
148+
|--------------------------------------------------------------------------
149+
| Models to ignore
150+
|--------------------------------------------------------------------------
151+
|
152+
| Define which models should be ignored.
153+
|
154+
*/
155+
156+
'ignored_models' => [
157+
158+
],
159+
160+
/*
161+
|--------------------------------------------------------------------------
162+
| Models hooks
163+
|--------------------------------------------------------------------------
164+
|
165+
| Define which hook classes you want to run for models to add custom information
166+
|
167+
| Hooks should implement Barryvdh\LaravelIdeHelper\Contracts\ModelHookInterface.
168+
|
169+
*/
170+
171+
'model_hooks' => [
172+
// App\Support\IdeHelper\MyModelHook::class
173+
],
174+
175+
/*
176+
|--------------------------------------------------------------------------
177+
| Extra classes
178+
|--------------------------------------------------------------------------
179+
|
180+
| These implementations are not really extended, but called with magic functions
181+
|
182+
*/
183+
184+
'extra' => [
185+
'Eloquent' => ['Illuminate\Database\Eloquent\Builder', 'Illuminate\Database\Query\Builder'],
186+
'Session' => ['Illuminate\Session\Store'],
187+
],
188+
189+
'magic' => [],
190+
191+
/*
192+
|--------------------------------------------------------------------------
193+
| Interface implementations
194+
|--------------------------------------------------------------------------
195+
|
196+
| These interfaces will be replaced with the implementing class. Some interfaces
197+
| are detected by the helpers, others can be listed below.
198+
|
199+
*/
200+
201+
'interfaces' => [
202+
203+
],
204+
205+
/*
206+
|--------------------------------------------------------------------------
207+
| Support for custom DB types
208+
|--------------------------------------------------------------------------
209+
|
210+
| This setting allow you to map any custom database type (that you may have
211+
| created using CREATE TYPE statement or imported using database plugin
212+
| / extension to a Doctrine type.
213+
|
214+
| Each key in this array is a name of the Doctrine2 DBAL Platform. Currently valid names are:
215+
| 'postgresql', 'db2', 'drizzle', 'mysql', 'oracle', 'sqlanywhere', 'sqlite', 'mssql'
216+
|
217+
| This name is returned by getName() method of the specific Doctrine/DBAL/Platforms/AbstractPlatform descendant
218+
|
219+
| The value of the array is an array of type mappings. Key is the name of the custom type,
220+
| (for example, "jsonb" from Postgres 9.4) and the value is the name of the corresponding Doctrine2 type (in
221+
| our case it is 'json_array'. Doctrine types are listed here:
222+
| https://www.doctrine-project.org/projects/doctrine-dbal/en/latest/reference/types.html#types
223+
|
224+
| So to support jsonb in your models when working with Postgres, just add the following entry to the array below:
225+
|
226+
| "postgresql" => array(
227+
| "jsonb" => "json_array",
228+
| ),
229+
|
230+
*/
231+
'custom_db_types' => [
232+
233+
],
234+
235+
/*
236+
|--------------------------------------------------------------------------
237+
| Support for camel cased models
238+
|--------------------------------------------------------------------------
239+
|
240+
| There are some Laravel packages (such as Eloquence) that allow for accessing
241+
| Eloquent model properties via camel case, instead of snake case.
242+
|
243+
| Enabling this option will support these packages by saving all model
244+
| properties as camel case, instead of snake case.
245+
|
246+
| For example, normally you would see this:
247+
|
248+
| * @property \Illuminate\Support\Carbon $created_at
249+
| * @property \Illuminate\Support\Carbon $updated_at
250+
|
251+
| With this enabled, the properties will be this:
252+
|
253+
| * @property \Illuminate\Support\Carbon $createdAt
254+
| * @property \Illuminate\Support\Carbon $updatedAt
255+
|
256+
| Note, it is currently an all-or-nothing option.
257+
|
258+
*/
259+
'model_camel_case_properties' => false,
260+
261+
/*
262+
|--------------------------------------------------------------------------
263+
| Property Casts
264+
|--------------------------------------------------------------------------
265+
|
266+
| Cast the given "real type" to the given "type".
267+
|
268+
*/
269+
'type_overrides' => [
270+
'integer' => 'int',
271+
'boolean' => 'bool',
272+
],
273+
274+
/*
275+
|--------------------------------------------------------------------------
276+
| Include DocBlocks from classes
277+
|--------------------------------------------------------------------------
278+
|
279+
| Include DocBlocks from classes to allow additional code inspection for
280+
| magic methods and properties.
281+
|
282+
*/
283+
'include_class_docblocks' => false,
284+
285+
/*
286+
|--------------------------------------------------------------------------
287+
| Force FQN usage
288+
|--------------------------------------------------------------------------
289+
|
290+
| Use the fully qualified (class) name in docBlock,
291+
| event if class exists in a given file
292+
| or there is an import (use className) of a given class
293+
|
294+
*/
295+
'force_fqn' => false,
296+
297+
/*
298+
|--------------------------------------------------------------------------
299+
| Use generics syntax
300+
|--------------------------------------------------------------------------
301+
|
302+
| Use generics syntax within DocBlocks,
303+
| e.g. `Collection<User>` instead of `Collection|User[]`.
304+
|
305+
*/
306+
'use_generics_annotations' => true,
307+
308+
/*
309+
|--------------------------------------------------------------------------
310+
| Additional relation types
311+
|--------------------------------------------------------------------------
312+
|
313+
| Sometimes it's needed to create custom relation types. The key of the array
314+
| is the Relationship Method name. The value of the array is the canonical class
315+
| name of the Relationship, e.g. `'relationName' => RelationShipClass::class`.
316+
|
317+
*/
318+
'additional_relation_types' => [],
319+
320+
/*
321+
|--------------------------------------------------------------------------
322+
| Additional relation return types
323+
|--------------------------------------------------------------------------
324+
|
325+
| When using custom relation types its possible for the class name to not contain
326+
| the proper return type of the relation. The key of the array is the relationship
327+
| method name. The value of the array is the return type of the relation.
328+
| e.g. `'relationName' => 'many'`.
329+
|
330+
*/
331+
'additional_relation_return_types' => [],
332+
333+
/*
334+
|--------------------------------------------------------------------------
335+
| Run artisan commands after migrations to generate model helpers
336+
|--------------------------------------------------------------------------
337+
|
338+
| The specified commands should run after migrations are finished running.
339+
|
340+
*/
341+
'post_migrate' => [
342+
// 'ide-helper:models --nowrite',
343+
],
344+
345+
];

wave/src/Announcement.php

+3
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55
use Illuminate\Database\Eloquent\Model;
66

7+
/**
8+
* @mixin IdeHelperAnnouncement
9+
*/
710
class Announcement extends Model
811
{
912
public function users(){

wave/src/ApiKey.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@
55
use Illuminate\Database\Eloquent\Model;
66

77

8+
/**
9+
* @mixin IdeHelperApiKey
10+
*/
811
class ApiKey extends Model
912
{
1013
protected $table = 'api_keys';
11-
14+
1215
/**
1316
* The attributes that are mass assignable.
1417
*

0 commit comments

Comments
 (0)