Skip to content

Commit f184d83

Browse files
committed
fix: add types to View $filters and $plugins
1 parent f7e6cff commit f184d83

File tree

4 files changed

+37
-45
lines changed

4 files changed

+37
-45
lines changed

app/Config/View.php

+12-2
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@
55
use CodeIgniter\Config\View as BaseView;
66
use CodeIgniter\View\ViewDecoratorInterface;
77

8+
/**
9+
* @phpstan-type ParserCallable (callable(mixed): mixed)
10+
* @phpstan-type ParserCallableString (callable(mixed): mixed)&string
11+
*/
812
class View extends BaseView
913
{
1014
/**
@@ -30,7 +34,10 @@ class View extends BaseView
3034
* { title|esc(js) }
3135
* { created_on|date(Y-m-d)|esc(attr) }
3236
*
33-
* @var array
37+
* @psalm-suppress UndefinedDocblockClass
38+
*
39+
* @var array<string, string>
40+
* @phpstan-var array<string, ParserCallableString>
3441
*/
3542
public $filters = [];
3643

@@ -39,7 +46,10 @@ class View extends BaseView
3946
* by the core Parser by creating aliases that will be replaced with
4047
* any callable. Can be single or tag pair.
4148
*
42-
* @var array
49+
* @psalm-suppress UndefinedDocblockClass
50+
*
51+
* @var array<string, array<string>|callable|string>
52+
* @phpstan-var array<string, array<ParserCallableString>|ParserCallableString|ParserCallable>
4353
*/
4454
public $plugins = [];
4555

phpstan-baseline.php

-35
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
<?php declare(strict_types = 1);
22

33
$ignoreErrors = [];
4-
$ignoreErrors[] = [
5-
'message' => '#^PHPDoc type array of property Config\\\\View\\:\\:\\$filters is not covariant with PHPDoc type array\\<string, callable\\-string\\> of overridden property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters\\.$#',
6-
'count' => 1,
7-
'path' => __DIR__ . '/app/Config/View.php',
8-
];
9-
$ignoreErrors[] = [
10-
'message' => '#^PHPDoc type array of property Config\\\\View\\:\\:\\$plugins is not covariant with PHPDoc type array\\<string, callable\\-string\\> of overridden property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins\\.$#',
11-
'count' => 1,
12-
'path' => __DIR__ . '/app/Config/View.php',
13-
];
144
$ignoreErrors[] = [
155
'message' => '#^Method CodeIgniter\\\\BaseModel\\:\\:chunk\\(\\) has parameter \\$userFunc with no signature specified for Closure\\.$#',
166
'count' => 1,
@@ -256,26 +246,6 @@
256246
'count' => 1,
257247
'path' => __DIR__ . '/system/ComposerScripts.php',
258248
];
259-
$ignoreErrors[] = [
260-
'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$coreFilters type has no signature specified for callable\\.$#',
261-
'count' => 1,
262-
'path' => __DIR__ . '/system/Config/View.php',
263-
];
264-
$ignoreErrors[] = [
265-
'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$corePlugins type has no signature specified for callable\\.$#',
266-
'count' => 1,
267-
'path' => __DIR__ . '/system/Config/View.php',
268-
];
269-
$ignoreErrors[] = [
270-
'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$filters type has no signature specified for callable\\.$#',
271-
'count' => 1,
272-
'path' => __DIR__ . '/system/Config/View.php',
273-
];
274-
$ignoreErrors[] = [
275-
'message' => '#^Property CodeIgniter\\\\Config\\\\View\\:\\:\\$plugins type has no signature specified for callable\\.$#',
276-
'count' => 1,
277-
'path' => __DIR__ . '/system/Config/View.php',
278-
];
279249
$ignoreErrors[] = [
280250
'message' => '#^Method CodeIgniter\\\\Database\\\\BaseBuilder\\:\\:_whereIn\\(\\) has parameter \\$values with no signature specified for Closure\\.$#',
281251
'count' => 1,
@@ -1706,11 +1676,6 @@
17061676
'count' => 1,
17071677
'path' => __DIR__ . '/system/View/Parser.php',
17081678
];
1709-
$ignoreErrors[] = [
1710-
'message' => '#^Property Config\\\\View\\:\\:\\$plugins \\(array\\) on left side of \\?\\? is not nullable\\.$#',
1711-
'count' => 1,
1712-
'path' => __DIR__ . '/system/View/Parser.php',
1713-
];
17141679
$ignoreErrors[] = [
17151680
'message' => '#^Property CodeIgniter\\\\View\\\\Table\\:\\:\\$function type has no signature specified for callable\\.$#',
17161681
'count' => 1,

system/Config/View.php

+17-6
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
/**
1717
* View configuration
18+
*
19+
* @phpstan-type ParserCallable (callable(mixed): mixed)
20+
* @phpstan-type ParserCallableString (callable(mixed): mixed)&string
1821
*/
1922
class View extends BaseConfig
2023
{
@@ -34,8 +37,10 @@ class View extends BaseConfig
3437
* To prevent potential abuse, all filters MUST be defined here
3538
* in order for them to be available for use within the Parser.
3639
*
40+
* @psalm-suppress UndefinedDocblockClass
41+
*
3742
* @var array<string, string>
38-
* @phpstan-var array<string, callable-string>
43+
* @phpstan-var array<string, ParserCallableString>
3944
*/
4045
public $filters = [];
4146

@@ -44,16 +49,20 @@ class View extends BaseConfig
4449
* by the core Parser by creating aliases that will be replaced with
4550
* any callable. Can be single or tag pair.
4651
*
47-
* @var array<string, string>
48-
* @phpstan-var array<string, callable-string>
52+
* @psalm-suppress UndefinedDocblockClass
53+
*
54+
* @var array<string, array<string>|callable|string>
55+
* @phpstan-var array<string, array<ParserCallableString>|ParserCallableString|ParserCallable>
4956
*/
5057
public $plugins = [];
5158

5259
/**
5360
* Built-in View filters.
5461
*
62+
* @psalm-suppress UndefinedDocblockClass
63+
*
5564
* @var array<string, string>
56-
* @phpstan-var array<string, callable-string>
65+
* @phpstan-var array<string, ParserCallableString>
5766
*/
5867
protected $coreFilters = [
5968
'abs' => '\abs',
@@ -82,8 +91,10 @@ class View extends BaseConfig
8291
/**
8392
* Built-in View plugins.
8493
*
85-
* @var array<string, string>
86-
* @phpstan-var array<string, callable-string>
94+
* @psalm-suppress UndefinedDocblockClass
95+
*
96+
* @var array<string, array<string>|callable|string>
97+
* @phpstan-var array<string, array<ParserCallableString>|ParserCallableString|ParserCallable>
8798
*/
8899
protected $corePlugins = [
89100
'csp_script_nonce' => '\CodeIgniter\View\Plugins::cspScriptNonce',

system/View/Parser.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919

2020
/**
2121
* Class for parsing pseudo-vars
22+
*
23+
* @phpstan-type ParserCallable (callable(mixed): mixed)
24+
* @phpstan-type ParserCallableString (callable(mixed): mixed)&string
2225
*/
2326
class Parser extends View
2427
{
@@ -58,7 +61,10 @@ class Parser extends View
5861
/**
5962
* Stores any plugins registered at run-time.
6063
*
61-
* @var array
64+
* @psalm-suppress UndefinedClass
65+
*
66+
* @var array<string, array<string>|callable|string>
67+
* @phpstan-var array<string, array<ParserCallableString>|ParserCallableString|ParserCallable>
6268
*/
6369
protected $plugins = [];
6470

@@ -78,7 +84,7 @@ class Parser extends View
7884
public function __construct(ViewConfig $config, ?string $viewPath = null, $loader = null, ?bool $debug = null, ?LoggerInterface $logger = null)
7985
{
8086
// Ensure user plugins override core plugins.
81-
$this->plugins = $config->plugins ?? [];
87+
$this->plugins = $config->plugins;
8288

8389
parent::__construct($config, $viewPath, $loader, $debug, $logger);
8490
}

0 commit comments

Comments
 (0)