Skip to content

[TypeDeclarationDocblocks] Strip never[] on docblock @ return on DocblockReturnArrayFromDirectArrayInstanceRector#7290

Merged
samsonasik merged 2 commits intomainfrom
strip-never
Sep 15, 2025
Merged

[TypeDeclarationDocblocks] Strip never[] on docblock @ return on DocblockReturnArrayFromDirectArrayInstanceRector#7290
samsonasik merged 2 commits intomainfrom
strip-never

Conversation

@samsonasik
Copy link
Member

@samsonasik samsonasik commented Sep 15, 2025

Given the following code:

    public function get(): array
    {
        return [
            'a' => false,
            'b' => 'b',
            'c' => true,
            'd' => $this->getNullable(),
            'class' => StripEmptyCombine::class,
            'opt' => [],
            'init' => false,
            'attrs' => [
                'x' => 'x',
                'class' => 'pick',
                'apply' => 'true',
                'head' => $this->trans('foo'),
            ],
        ];
    }

It currently got:

+    /**
+     * @return array<string, string|bool|never[]|array<string, string>|null>
+     */
     public function get(): array

that cause phpstan error:

  - '#Method get\(\) should return array<string, array\|bool\|string> but returns array<string, array<string, string>\|bool\|string>#'

see error at https://phpstan.org/r/15722015-5567-4305-aeac-8dda263328ef

@samsonasik
Copy link
Member Author

Use mixed[] seems the way, see https://phpstan.org/r/9bf0fc59-bc8a-4f22-a05f-c50560f36081

@samsonasik
Copy link
Member Author

All checks have passed 🎉 @TomasVotruba I am merging it ;)

@samsonasik samsonasik merged commit 7546e9a into main Sep 15, 2025
49 checks passed
@samsonasik samsonasik deleted the strip-never branch September 15, 2025 14:50
@github-actions
Copy link
Contributor

This pull request has been automatically locked because it has been closed for 150 days. Please open a new PR if you want to continue the work.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant