diff --git a/app/Config/View.php b/app/Config/View.php index 78cd547e3b8f..fa2d05ca84ce 100644 --- a/app/Config/View.php +++ b/app/Config/View.php @@ -5,6 +5,12 @@ use CodeIgniter\Config\View as BaseView; use CodeIgniter\View\ViewDecoratorInterface; +/** + * @phpstan-type ParserCallable (callable(mixed): mixed) + * @psalm-type ParserCallable = (callable(mixed): mixed) + * @phpstan-type ParserCallableString (callable(mixed): mixed)&string + * @psalm-type ParserCallableString = (callable(mixed): mixed)&string + */ class View extends BaseView { /** @@ -30,7 +36,8 @@ class View extends BaseView * { title|esc(js) } * { created_on|date(Y-m-d)|esc(attr) } * - * @var array + * @var array + * @phpstan-var array */ public $filters = []; @@ -39,7 +46,8 @@ class View extends BaseView * by the core Parser by creating aliases that will be replaced with * any callable. Can be single or tag pair. * - * @var array + * @var array|callable|string> + * @phpstan-var array|ParserCallableString|ParserCallable> */ public $plugins = []; diff --git a/phpstan-baseline.php b/phpstan-baseline.php index ec5d6987990e..e3267ecafdca 100644 --- a/phpstan-baseline.php +++ b/phpstan-baseline.php @@ -1,16 +1,6 @@ '#^PHPDoc type array of property Config\\\\View\\:\\:\\$filters is not covariant with PHPDoc type array\\ of overridden property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/app/Config/View.php', -]; -$ignoreErrors[] = [ - 'message' => '#^PHPDoc type array of property Config\\\\View\\:\\:\\$plugins is not covariant with PHPDoc type array\\ of overridden property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/app/Config/View.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#', 'count' => 1, @@ -256,26 +246,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/ComposerScripts.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$coreFilters type has no signature specified for callable\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/View.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$corePlugins type has no signature specified for callable\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/View.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters type has no signature specified for callable\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/View.php', -]; -$ignoreErrors[] = [ - 'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins type has no signature specified for callable\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/Config/View.php', -]; $ignoreErrors[] = [ 'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#', 'count' => 1, @@ -1706,11 +1676,6 @@ 'count' => 1, 'path' => __DIR__ . '/system/View/Parser.php', ]; -$ignoreErrors[] = [ - 'message' => '#^Property Config\\\\View\\:\\:\\$plugins \\(array\\) on left side of \\?\\? is not nullable\\.$#', - 'count' => 1, - 'path' => __DIR__ . '/system/View/Parser.php', -]; $ignoreErrors[] = [ 'message' => '#^Property CodeIgniter\\\\View\\\\Table\\:\\:\\$function type has no signature specified for callable\\.$#', 'count' => 1, diff --git a/system/Config/View.php b/system/Config/View.php index de4ed62b936a..cb4868b60bb3 100644 --- a/system/Config/View.php +++ b/system/Config/View.php @@ -15,6 +15,11 @@ /** * View configuration + * + * @phpstan-type ParserCallable (callable(mixed): mixed) + * @psalm-type ParserCallable = (callable(mixed): mixed) + * @phpstan-type ParserCallableString (callable(mixed): mixed)&string + * @psalm-type ParserCallableString = (callable(mixed): mixed)&string */ class View extends BaseConfig { @@ -35,7 +40,7 @@ class View extends BaseConfig * in order for them to be available for use within the Parser. * * @var array - * @phpstan-var array + * @phpstan-var array */ public $filters = []; @@ -44,8 +49,8 @@ class View extends BaseConfig * by the core Parser by creating aliases that will be replaced with * any callable. Can be single or tag pair. * - * @var array - * @phpstan-var array + * @var array|callable|string> + * @phpstan-var array|ParserCallableString|ParserCallable> */ public $plugins = []; @@ -53,7 +58,7 @@ class View extends BaseConfig * Built-in View filters. * * @var array - * @phpstan-var array + * @phpstan-var array */ protected $coreFilters = [ 'abs' => '\abs', @@ -82,8 +87,8 @@ class View extends BaseConfig /** * Built-in View plugins. * - * @var array - * @phpstan-var array + * @var array|callable|string> + * @phpstan-var array|ParserCallableString|ParserCallable> */ protected $corePlugins = [ 'csp_script_nonce' => '\CodeIgniter\View\Plugins::cspScriptNonce', diff --git a/system/View/Parser.php b/system/View/Parser.php index b9abf91edb5f..7483b768e3bf 100644 --- a/system/View/Parser.php +++ b/system/View/Parser.php @@ -19,6 +19,11 @@ /** * Class for parsing pseudo-vars + * + * @phpstan-type ParserCallable (callable(mixed): mixed) + * @psalm-type ParserCallable = (callable(mixed): mixed) + * @phpstan-type ParserCallableString (callable(mixed): mixed)&string + * @psalm-type ParserCallableString = (callable(mixed): mixed)&string */ class Parser extends View { @@ -58,7 +63,8 @@ class Parser extends View /** * Stores any plugins registered at run-time. * - * @var array + * @var array|callable|string> + * @phpstan-var array|ParserCallableString|ParserCallable> */ protected $plugins = []; @@ -78,7 +84,7 @@ class Parser extends View public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null) { // Ensure user plugins override core plugins. - $this->plugins = $config->plugins ?? []; + $this->plugins = $config->plugins; parent::__construct($config, $viewPath, $loader, $debug, $logger); }