@@ -4,6 +4,87 @@ All type inference capabilities of this extension are summarised below:
4
4
5
5
## Dynamic Function Return Type Extensions
6
6
7
+ ### FactoriesFunctionReturnTypeExtension
8
+
9
+ This extension provides precise return types for the ` config() ` and ` model() ` functions.
10
+
11
+ ** Before:**
12
+ ``` php
13
+ \PHPStan\dumpType(config('bar')); // BaseConfig|null
14
+ \PHPStan\dumpType(config('App')); // BaseConfig|null
15
+ \PHPStan\dumpType(model(BarModel::class)); // Model|null
16
+
17
+ ```
18
+
19
+ ** After:**
20
+ ``` php
21
+ \PHPStan\dumpType(config('bar')); // null
22
+ \PHPStan\dumpType(config('App')); // Config\App
23
+ \PHPStan\dumpType(model(BarModel::class)); // CodeIgniter\PHPStan\Tests\Fixtures\Type\BarModel
24
+
25
+ ```
26
+
27
+ > [ !NOTE]
28
+ > ** Configuration:**
29
+ >
30
+ > This extension adds the default namespace for ` config() ` and ` model() ` functions as ` Config\ `
31
+ > and ` App\Models\ ` , respectively, when searching for possible classes. If your application uses
32
+ > other namespaces, you can configure this extension in your ` phpstan.neon ` to recognize those namespaces:
33
+ >
34
+ > ``` yml
35
+ > parameters:
36
+ > codeigniter:
37
+ > additionalConfigNamespaces:
38
+ > - Acme\Blog\Config\
39
+ > - Foo\Bar\Config\
40
+ > additionalModelNamespaces:
41
+ > - Acme\Blog\Models\
42
+ >
43
+ > ```
44
+
45
+ # ## FakeFunctionReturnTypeExtension
46
+
47
+ This extension provides precise return type for the `fake()` function.
48
+
49
+ **Before:**
50
+ ` ` ` php
51
+ \P HPStan\d umpType(fake('baz')); // array|object
52
+ \P HPStan\d umpType(fake(BarModel::class)); // array|object
53
+ \P HPStan\d umpType(fake(UserModel::class)); // array|object
54
+ \P HPStan\d umpType(fake(UserIdentityModel::class)); // array|object
55
+ \P HPStan\d umpType(fake(LoginModel::class)); // array|object
56
+ \P HPStan\d umpType(fake(TokenLoginModel::class)); // array|object
57
+ \P HPStan\d umpType(fake(GroupModel::class)); // array|object
58
+
59
+ ` ` `
60
+
61
+ **After:**
62
+ ` ` ` php
63
+ \P HPStan\d umpType(fake('baz')); // never
64
+ \P HPStan\d umpType(fake(BarModel::class)); // stdClass
65
+ \P HPStan\d umpType(fake(UserModel::class)); // CodeIgniter\S hield\E ntities\U ser
66
+ \P HPStan\d umpType(fake(UserIdentityModel::class)); // CodeIgniter\S hield\E ntities\UserIdent ity
67
+ \P HPStan\d umpType(fake(LoginModel::class)); // CodeIgniter\S hield\E ntities\L ogin
68
+ \P HPStan\d umpType(fake(TokenLoginModel::class)); // CodeIgniter\S hield\E ntities\L ogin
69
+ \P HPStan\d umpType(fake(GroupModel::class)); // array{user_id: int, group: string, created_at: string}
70
+
71
+ ` ` `
72
+
73
+ > [!NOTE]
74
+ > **Configuration:**
75
+ >
76
+ > When the model passed to `fake()` has the property `$returnType` set to `array`, this extension will give
77
+ > a precise array shape based on the allowed fields of the model. Most of the time, the formatted fields are
78
+ > strings. If not a string, you can indicate the format return type for the particular field.
79
+ >
80
+ > ```yml
81
+ > parameters:
82
+ > codeigniter:
83
+ > notStringFormattedFields: # key-value pair of field => format
84
+ > success: bool
85
+ > user_id: int
86
+ > ```
87
+
7
88
# ## ServicesFunctionReturnTypeExtension
8
89
9
90
This extension provides precise return types for the `service()` and `single_service()` functions.
@@ -19,6 +100,26 @@ This extension provides precise return types for the `service()` and `single_ser
19
100
\P HPStan\d umpType(service('cache')); // CodeIgniter\C ache\C acheInterface
20
101
` ` `
21
102
103
+ > [!NOTE]
104
+ > **Configuration:**
105
+ >
106
+ > You can instruct PHPStan to consider your own services factory classes.
107
+ > **Please note that it should be a valid class extending `CodeIgniter\Config\BaseService`!**
108
+ >
109
+ > ```yml
110
+ > parameters:
111
+ > codeigniter:
112
+ > additionalServices:
113
+ > - Acme\Blog\Config\ServiceFactory
114
+ > ```
115
+
116
+ # # Dynamic Method Return Type Extension
117
+
118
+ # ## ModelFindReturnTypeExtension
119
+
120
+ This extension provides precise return types for `CodeIgniter\Model`'s `find()`, `findAll()`, and `first()` methods.
121
+ This also allows dynamic return type transformation of `CodeIgniter\Model` when `asArray()` or `asObject()` is called.
122
+
22
123
# # Dynamic Static Method Return Type Extensions
23
124
24
125
# ## ReflectionHelperGetPrivateMethodInvokerReturnTypeExtension
@@ -61,6 +162,7 @@ public function testSomePrivateMethod(): void
61
162
` ` `
62
163
63
164
> [!NOTE]
165
+ > **Configuration:**
64
166
>
65
167
> If you are using `ReflectionHelper` outside of testing, you can still enjoy the precise return types by adding a
66
168
> service for the class using this trait. In your `phpstan.neon` (or `phpstan.neon.dist`), add the following to
@@ -115,3 +217,16 @@ class MyService extends \Config\Services
115
217
}
116
218
117
219
` ` `
220
+
221
+ > [!NOTE]
222
+ > **Configuration:**
223
+ >
224
+ > You can instruct PHPStan to consider your own services factory classes.
225
+ > **Please note that it should be a valid class extending `CodeIgniter\Config\BaseService`!**
226
+ >
227
+ > ```yml
228
+ > parameters:
229
+ > codeigniter:
230
+ > additionalServices:
231
+ > - Acme\Blog\Config\ServiceFactory
232
+ > ```
0 commit comments