Skip to content

Commit

Permalink
refactor: add Factories::models() to suppress PHPStan error
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Nov 19, 2021
1 parent c3e43e9 commit d382c70
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 0 additions & 1 deletion system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,6 @@ function log_message(string $level, string $message, array $context = [])
* @param class-string<T> $name
*
* @return T
* @phpstan-return Model
*/
function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn = null)
{
Expand Down
16 changes: 14 additions & 2 deletions system/Config/Factories.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace CodeIgniter\Config;

use CodeIgniter\Database\ConnectionInterface;
use CodeIgniter\Model;
use Config\Services;

Expand All @@ -23,7 +24,6 @@
* instantiation checks.
*
* @method static BaseConfig config(...$arguments)
* @method static Model models(...$arguments)
*/
class Factories
{
Expand Down Expand Up @@ -67,6 +67,18 @@ class Factories
*/
protected static $instances = [];

/**
* @template T of Model
*
* @param class-string<T> $name
*
* @return T
*/
public static function models(string $name, array $options = [], ?ConnectionInterface &$conn = null)
{
return self::__callStatic('models', [$name, $options, $conn]);
}

/**
* Loads instances based on the method component name. Either
* creates a new instance or returns an existing shared instance.
Expand Down Expand Up @@ -263,7 +275,7 @@ public static function setOptions(string $component, array $values): array
/**
* Resets the static arrays, optionally just for one component
*
* @param string $component Lowercase, plural component name
* @param string|null $component Lowercase, plural component name
*/
public static function reset(?string $component = null)
{
Expand Down

0 comments on commit d382c70

Please sign in to comment.