Skip to content

Bug: Docs: \App\Config\Filters::globals type does not pass PHPStan when using the multiple-URI 'except' pattern #9651

@FarmGeek4Life

Description

@FarmGeek4Life

PHP Version

8.3

CodeIgniter4 Version

4.6.0

CodeIgniter4 Installation Method

Composer (using codeigniter4/appstarter)

Which operating systems have you tested for this bug?

Linux

Which server did you use?

apache

Database

No response

What happened?

PHPStan reports an issue when using the ['except' => ['foo/', 'bar/']] pattern shown in the documentation for global filters

In my case, I have multiple URIs I need to exclude from the debug toolbar for validity, with the below shortened example:

public array $globals = [
    'before' => [],
    'after' => [
        'toolbar' => ['except' => ['api/*', '*/export/*']],
    ],
];

Running PHPStan on my site results in the following message:
#^Property Config\\Filters\:\:\$globals \(array\<string, array\<int\<0, max\>\|string, array\<string, string\>\|string\>\>\) does not accept default value of type array\{before\: array\{\}, after\: array\{toolbar\: array\{except\: array\{''\api/\*'', ''\*/export/\*''\}\}\}\}\.$#

Changing the PHPDoc type hint from
@var array<string, array<string, array<string, string>>>|array<string, list<string>>
to
@var array<string, array<string, array<string, string|list<string>>>>|array<string, list<string>>
appears to resolve the issue, though I don't know if that is fully valid or properly supported by other static analyzers

Steps to Reproduce

Modify Config\Filters::globals to have an 'except' rule with multiple URIs, then run PHPStan

Expected Output

No issue reported by PHPStan about the default value of Config\Filters::globals

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugVerified issues on the current code behavior or pull requests that will fix them

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions