You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
/** * @phpstan-template T of GotoTarget * * @phpstan-type CandidateNotesData array{candidate: string, note: string} * @phpstan-type PersonalmanagerData array{token: string} * * @phpstan-type GotoRouteDataTypes array{ * 'personalmanager': PersonalmanagerData, * 'my-pending-reviews': null, * 'candidate-notes': CandidateNotesData, * 'dashboard': null, * } * ↑ * Would also be nice if you could use Enums as the key for arrays. */finalclassGotoRoute
{
/** * @phpstan-var T */publicGotoTarget$target;
/** * @phpstan-var GotoRouteDataTypes[value-of<T>] */public ?array$data = null;
}
enum GotoTarget: string
{
casePERSONALMANAGER = 'personalmanager';
caseMY_PENDING_REVIEWS = 'my-pending-reviews';
caseCANDIDATE_NOTES = 'candidate-notes';
caseDASHBOARD = 'dashboard';
}
PhpStan complains for this line: public ?array $data = null; with
phpstan: PHPDoc tag @var for property GotoRoute::$data with type array{personalmanager: array{token: string}, my-pending-reviews: null, candidate-notes: array{candidate: string, note: string}, dashboard: null}[value-of<T>] is not subtype of native type array|null.
and
phpstan: Property GotoRoute::$data type has no value type specified in iterable type array.
What I want to achieve is the following:
T ($target) is GotoTarget::DASHBOARD -> $data is null
T ($target) is GotoTarget::PERSONALMANAGER -> $data is array{token: string}
Bug report
Example:
PhpStan complains for this line:
public ?array $data = null;
withphpstan: PHPDoc tag @var for property GotoRoute::$data with type array{personalmanager: array{token: string}, my-pending-reviews: null, candidate-notes: array{candidate: string, note: string}, dashboard: null}[value-of<T>] is not subtype of native type array|null.
and
phpstan: Property GotoRoute::$data type has no value type specified in iterable type array.
What I want to achieve is the following:
$target
) isGotoTarget::DASHBOARD
->$data
isnull
$target
) isGotoTarget::PERSONALMANAGER
->$data
isarray{token: string}
It works with this:
But I don't like it, because the more you add, the uglier it gets.
Code snippet that reproduces the problem
https://phpstan.org/r/7fa9183e-5190-4c79-a545-40e40be1033c
Expected output
$target
) isGotoTarget::DASHBOARD
->$data
isnull
$target
) isGotoTarget::PERSONALMANAGER
->$data
isarray{token: string}
The text was updated successfully, but these errors were encountered: