Skip to content

[4.0] Interfaces Incomplete #24587

@mbabker

Description

@mbabker

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions