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()
- The getMenu()
method is not defined in CMSApplicationInterface
Factory::getApplication()->get()
- The get()
method is not defined in CMSApplicationInterface
Factory::getApplication()->triggerEvent()
- The triggerEvent()
method is not defined in CMSApplicationInterface
Factory::getApplication()->bootComponent()->getMVCFactory()
- The getMVCFactory()
method is not defined in ComponentInterface
- 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
We should still probably reintroduce the interfaces we revoked here joomla-framework/application@49d2f19 for the
get
method and extend our interface from thisThis one gets weird. We probably want to define a EventInterface . But we also probably want to make some of the applications own exceptions run through the
AbstractApplication
's dispatch event rather than thetriggerEvent
methodWe should check the component interface also implements the https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/MVC/Factory/MVCFactoryServiceInterface.php
MVCFactoryServiceInterface
interface where requiredWe should add this in - but we'll need to add add an exception it can throw for applications that don't have menus (cli and webservices). I guess we need the same exception/method for
getRouter
too