-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[4.0] Interfaces Incomplete #24587
Description
There are a lot of cases where interfaces come across as very incomplete. With a static analysis tool, there would be loads of errors related to calling methods that do not exist on the documented return type. When interfaces are in use, it is a best practice to only rely on methods that actually exist as part of the interface as anything else typically points to a dependency on a class implementing that interface.
Examples of current uses in core include:
Factory::getApplication()->getMenu()- ThegetMenu()method is not defined inCMSApplicationInterfaceFactory::getApplication()->get()- Theget()method is not defined inCMSApplicationInterfaceFactory::getApplication()->triggerEvent()- ThetriggerEvent()method is not defined inCMSApplicationInterfaceFactory::getApplication()->bootComponent()->getMVCFactory()- ThegetMVCFactory()method is not defined inComponentInterface- CategoryServiceInterface containing a method related to counting tagged items
Valid fixes include changing doc blocks to accurate return types (i.e. classes instead of interfaces), ensuring methods are defined on interfaces as appropriate, adding inline docblocks indicating the return type for that use case, or adding method_exists() checks throughout the codebase because "unsafe" use of the interfaces are in use ("unsafe" in this context meaning calling methods not declared on a documented return type, generally an interface).
EDITED: STRIKETHROUGH'S BY @wilsonge AS WE MERGE FIXES