Skip to content

Method ordering #88

@dpi

Description

@dpi

SlevomatCodingStandard.Classes.ClassStructure has been enhanced. We can now add more detailed method ordering rules now that some issues/PR solved:

Proposal 1

Summary of proposed rules:

  • top:
    • test setUp()
    • controller create()
    • plugin createInstance()
    • entity baseFieldDefinitions()
    • invoke method
    • form getFormId(), form getEditableConfigNames()
  • middle
    • form
      • form (content entity form)
      • build
      • validate
      • submit
  • bottom:
    • form actions(), form save()
    • test tearDown()
    • service getSubscribedEvents()
    • __toString()
  • test providers will not be bumper against their method. Theres no rule for this. I think it should be okay that these static methods are moved below the public method block.
  • method order doesnt have context of the class, eg whether its an entity or form or service. So we're just hoping things fall into line.
  • ordering
    • mixed bag of methods, setter/getters, custom methods, etc
    • static methods
    • protected methods
    • private methods

Proposal 2 / Alternate

As visible in a demo PR (not linked), theres quite a large LOC change for proposal 1.

Taking from proposal, but changing some things:

Defer or reconsider static/protected/private ordering.

And actions() / save().

Most others would keep their position simply due to discipline.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions