Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8613271

Browse files
committed
Document Model/Entity type inference
1 parent c237109 commit 8613271

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

docs/type-inference.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,14 @@ class from the passed name or class string.
4444
> - Acme\Blog\Models\
4545
> ```
4646
47+
### FakeFunctionReturnTypeExtension
48+
49+
**Class:** `CodeIgniter\PHPStan\Type\FakeFunctionReturnTypeExtension`
50+
51+
This extension provides the precise return type for the `fake()` function, typing it as a single fabricated
52+
record of the given model's return type (an entity, a shaped array, or a `stdClass`). The model may be passed
53+
as a class string, a model name, or a model instance.
54+
4755
## Dynamic Method Return Type Extensions
4856
4957
### ReflectionHelperMethodInvokerStaticReturnTypeExtension
@@ -83,6 +91,29 @@ This extension provides precise return types for the following methods of `CodeI
8391
- `request()`
8492
- `getGlobalArray()`
8593
94+
### ModelFindReturnTypeExtension
95+
96+
**Class:** `CodeIgniter\PHPStan\Type\ModelFindReturnTypeExtension`
97+
98+
This extension provides precise return types for the `find()`, `findAll()`, `first()`, and `findColumn()`
99+
methods of `CodeIgniter\Model` subclasses.
100+
101+
A fetched row is typed from the model's `$returnType`:
102+
- an entity instance (whose properties are typed by the entity extension below),
103+
- a shaped array built from the table's columns and the model's `$casts`, or
104+
- a `stdClass` with those same fields.
105+
106+
The row type also honors an `asArray()`/`asObject()` override and a `select()` field list earlier in the call
107+
chain. A `select()` supports `column`, `table.column`, `as` aliases, and `table.*`, resolving qualified
108+
references (including joined tables) against the introspected schema. A non-constant or unparseable `select()`
109+
falls back to a generic array.
110+
111+
Each method then wraps that row type:
112+
- `find()`: a single row or `null` for a scalar id, a list of rows for an array of ids or no argument.
113+
- `findAll()`: a list of rows.
114+
- `first()`: a single row or `null`.
115+
- `findColumn()`: a list of the selected column's values, or `null`.
116+
86117
## Dynamic Static Method Return Type Extensions
87118
88119
### ReflectionHelperMethodInvokerStaticReturnTypeExtension
@@ -148,3 +179,14 @@ handler names.
148179
> codeigniter:
149180
> addBackupHandlerAsReturnType: true
150181
> ```
182+
183+
## Properties Class Reflection Extensions
184+
185+
### EntityPropertiesClassReflectionExtension
186+
187+
**Class:** `CodeIgniter\PHPStan\Reflection\EntityPropertiesClassReflectionExtension`
188+
189+
This extension types the virtual properties of `CodeIgniter\Entity\Entity` subclasses. For each property it
190+
layers the entity's `$dates` and `$casts` (resolving custom `$castHandlers` by reflecting their `get()` method)
191+
over the type of the backing database column. That column is found through the table of the model whose
192+
`$returnType` is the entity. Properties that are neither a date, a cast, nor a known column resolve to `mixed`.

0 commit comments

Comments
 (0)