Skip to content

Commit 7016083

Browse files
authored
Merge pull request #5358 from kenjis/fix-model-phpstan-error
refactor: add Factories::models() to suppress PHPStan error
2 parents 67d00b3 + 9096197 commit 7016083

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

system/Common.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,6 @@ function log_message(string $level, string $message, array $context = [])
773773
* @param class-string<T> $name
774774
*
775775
* @return T
776-
* @phpstan-return Model
777776
*/
778777
function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn = null)
779778
{

system/Config/Factories.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace CodeIgniter\Config;
1313

14+
use CodeIgniter\Database\ConnectionInterface;
1415
use CodeIgniter\Model;
1516
use Config\Services;
1617

@@ -23,7 +24,6 @@
2324
* instantiation checks.
2425
*
2526
* @method static BaseConfig config(...$arguments)
26-
* @method static Model models(...$arguments)
2727
*/
2828
class Factories
2929
{
@@ -67,6 +67,22 @@ class Factories
6767
*/
6868
protected static $instances = [];
6969

70+
/**
71+
* This method is only to prevent PHPStan error.
72+
* If we have a solution, we can remove this method.
73+
* See https://github.com/codeigniter4/CodeIgniter4/pull/5358
74+
*
75+
* @template T of Model
76+
*
77+
* @param class-string<T> $name
78+
*
79+
* @return T
80+
*/
81+
public static function models(string $name, array $options = [], ?ConnectionInterface &$conn = null)
82+
{
83+
return self::__callStatic('models', [$name, $options, $conn]);
84+
}
85+
7086
/**
7187
* Loads instances based on the method component name. Either
7288
* creates a new instance or returns an existing shared instance.
@@ -263,7 +279,7 @@ public static function setOptions(string $component, array $values): array
263279
/**
264280
* Resets the static arrays, optionally just for one component
265281
*
266-
* @param string $component Lowercase, plural component name
282+
* @param string|null $component Lowercase, plural component name
267283
*/
268284
public static function reset(?string $component = null)
269285
{

0 commit comments

Comments
 (0)