Skip to content

Fix generics signature of config() and model() #7660

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 10 additions & 14 deletions system/Common.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
*/

use CodeIgniter\Cache\CacheInterface;
use CodeIgniter\Config\BaseConfig;
use CodeIgniter\Config\Factories;
use CodeIgniter\Cookie\Cookie;
use CodeIgniter\Cookie\CookieStore;
Expand All @@ -27,7 +26,6 @@
use CodeIgniter\HTTP\Response;
use CodeIgniter\HTTP\ResponseInterface;
use CodeIgniter\HTTP\URI;
use CodeIgniter\Model;
use CodeIgniter\Session\Session;
use CodeIgniter\Test\TestLogger;
use Config\App;
Expand Down Expand Up @@ -202,16 +200,15 @@ function command(string $command)

if (! function_exists('config')) {
/**
* More simple way of getting config instances from Factories
* Simpler way of getting config instances from Factories
*
* @template ConfigTemplate of BaseConfig
* @template T of object
*
* @param class-string<ConfigTemplate>|string $name
* @param class-string<T>|non-empty-string $name
*
* @return ConfigTemplate|null
* @phpstan-return ($name is class-string<ConfigTemplate> ? ConfigTemplate : object|null)
* @phpstan-return ($name is class-string<T> ? T : null)
*/
function config(string $name, bool $getShared = true)
function config(string $name, bool $getShared = true): ?object
{
return Factories::config($name, ['getShared' => $getShared]);
}
Expand Down Expand Up @@ -811,16 +808,15 @@ function log_message(string $level, string $message, array $context = [])

if (! function_exists('model')) {
/**
* More simple way of getting model instances from Factories
* Simpler way of getting model instances from Factories
*
* @template ModelTemplate of Model
* @template T of object
*
* @param class-string<ModelTemplate>|string $name
* @param class-string<T>|non-empty-string $name
*
* @return ModelTemplate|null
* @phpstan-return ($name is class-string<ModelTemplate> ? ModelTemplate : object|null)
* @phpstan-return ($name is class-string<T> ? T : null)
*/
function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn = null)
function model(string $name, bool $getShared = true, ?ConnectionInterface &$conn = null): ?object
{
return Factories::models($name, ['getShared' => $getShared], $conn);
}
Expand Down
2 changes: 1 addition & 1 deletion system/Debug/Toolbar.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ public function prepare(?RequestInterface $request = null, ?ResponseInterface $r
return;
}

$toolbar = Services::toolbar(config(self::class));
$toolbar = Services::toolbar(config(ToolbarConfig::class));
$stats = $app->getPerformanceStats();
$data = $toolbar->run(
$stats['startTime'],
Expand Down