phpstan: Variable $event might not be defined.

Created on 13 January 2025, 2 months ago

This phpstan warning is triggered twice in on of our tests. It's basically a false positive. We have a required radios form element, which must return one of three choices and nothing else. Then there's a switch statement that assigns $event does differently for each choice choice. The phpstan warning is because phpstan thinks the $event variable will not be set if the choice is anything other than the three choices, which is true but that can never happen. And there is no reasonable default value for $event.

A workaround is to use a match() statement instead of a switch. It's a little less clear IMO, but it should eliminate the warning, which will make the tests easier to maintain.

πŸ“Œ Task
Status

Active

Version

4.0

Component

Rules Core

Created by

πŸ‡ΊπŸ‡ΈUnited States tr Cascadia

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Merge Requests

Comments & Activities

Production build 0.71.5 2024