Skip to content

Commit c6be19c

Browse files
committed
Type Factories::cells() from its class-string argument
1 parent b05e201 commit c6be19c

3 files changed

Lines changed: 8 additions & 3 deletions

File tree

‎docs/type-inference.md‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,8 @@ handler names.
215215
**Class:** `CodeIgniter\PHPStan\Type\FactoriesStaticMethodReturnTypeExtension`
216216
217217
This extension provides precise return types for the static factory entry points `Factories::config()`,
218-
`Factories::models()`, and `Factories::get()`, the static counterparts of the `config()` and `model()`
219-
functions. A class-string argument resolves to that class for any component, while a string alias resolves
218+
`Factories::models()`, `Factories::cells()`, and `Factories::get()`, the static counterparts of the
219+
`config()` and `model()` functions. A class-string argument resolves to that class for any component, while a string alias resolves
220220
through the `config`/`model` namespaces (including the `additionalConfigNamespaces` and
221221
`additionalModelNamespaces` settings of the `FactoriesFunctionReturnTypeExtension`).
222222

‎src/Type/FactoriesStaticMethodReturnTypeExtension.php‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function getClass(): string
3838

3939
public function isStaticMethodSupported(MethodReflection $methodReflection): bool
4040
{
41-
return in_array($methodReflection->getName(), ['get', 'config', 'models'], true);
41+
return in_array($methodReflection->getName(), ['get', 'cells', 'config', 'models'], true);
4242
}
4343

4444
public function getTypeFromStaticMethodCall(MethodReflection $methodReflection, StaticCall $methodCall, Scope $scope): ?Type

‎tests/data/type-inference/factories-static-return-types.php‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use CodeIgniter\Config\Factories;
1717
use CodeIgniter\PHPStan\Tests\Fixtures\BarModel;
18+
use CodeIgniter\View\Cells\Cell;
1819
use Config\App;
1920

2021
use function PHPStan\Testing\assertType;
@@ -39,10 +40,14 @@
3940
// A non-class-string alias under an unmapped component is left as the framework's declared type.
4041
assertType('object|null', Factories::get('filters', 'toolbar'));
4142

43+
assertType('CodeIgniter\View\Cells\Cell', Factories::cells(Cell::class));
44+
assertType('object|null', Factories::cells('toolbar'));
45+
4246
// A non-constant alias is unresolvable, so the declared type is left in place rather than narrowed to null.
4347
function staticFactoriesDynamic(string $name): void
4448
{
4549
assertType('CodeIgniter\Config\BaseConfig|null', Factories::config($name));
4650
assertType('CodeIgniter\Model|null', Factories::models($name));
4751
assertType('object|null', Factories::get('config', $name));
52+
assertType('object|null', Factories::cells($name));
4853
}

0 commit comments

Comments
 (0)