Skip to content

Commit

Permalink
Merge pull request #5358 from kenjis/fix-model-phpstan-error
Browse files Browse the repository at this point in the history
refactor: add Factories::models() to suppress PHPStan error
  • Loading branch information
kenjis committed Jan 8, 2022
2 parents 67d00b3 + 9096197 commit 7016083
Show file tree
Hide file tree
Showing 2 changed files with 18 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 @@ -773,7 +773,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
20 changes: 18 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,22 @@ class Factories
*/
protected static $instances = [];

/**
* This method is only to prevent PHPStan error.
* If we have a solution, we can remove this method.
* See https://github.com/codeigniter4/CodeIgniter4/pull/5358
*
* @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 +279,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 7016083

Please sign in to comment.