Add array shape typing to definitions in MenuLinkManager

Created on 11 May 2025, 3 days ago

Problem/Motivation

We can improve the typing of the return values of methods of MenuLinkManagerInterface so PHPStan on higher levels doesn't complain so much. This is primarily useful for consumers of MenuLinkManager, as core is currently at a lower level with a large baseline.

Note that the menu definitions returned by MenuLinkInterface and descendants (MenuLinkBase, MenuLinkDefault, etc), and MenuTreeStorage/MenuTreeStorageInterface are distinctly different, so they do not share the same type.

MenuLink definitions can have arbitrary keys, and MenuTreeStorage also has level (P*) columns.

I think MenuLinkItemInterface etc will need to use a generic, anyway.

Steps to reproduce

Make calls to MenuLinkManagerInterface methods in a private project with a high PHPSTan level.

Run \PHPStan\dumpType() on the result of the methods.

See the results do not have any keys or typing.

Proposed resolution

Introduce two PHPStan types, which have array shapes of menu link definitions.

One is a fully hydrated definition, the other is a partial, which includes the same typing, except all keys are optional.

Remaining tasks

Improve docs.

User interface changes

Nil.

Introduced terminology

Nil.

API changes

PHPDocs

Data model changes

Nil.

Release notes snippet

Nil.

📌 Task
Status

Active

Version

11.0 🔥

Component

menu system

Created by

🇦🇺Australia dpi Perth, Australia

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