per-coding-style icon indicating copy to clipboard operation
per-coding-style copied to clipboard

Only add PHP opening tag when the following rule of thumb are met

Open ravage84 opened this issue 1 year ago • 1 comments

While I like the consistency of having opening tags everywhere (as in #74), I can see it being "too much", especially for one liners.

What do you think of the following rule of thumb proposal?

Add PHP opening tags when all requirements are met:

  • Tne mandatory class namespace is defined or no class or interface respectively is defined
  • All necessary classes & functions are imported
  • All necessary variables & constants are defined
  • All necessary structures are visible or hinted at with a comment
  • All statements and/or structures are related to each other
  • Or the PHP opening tag is essential to the code example

Do not add PHP opening tags when:

  • Only one or many unrelated statements are shown
  • Only one or many unrelated functions are shown
  • Only one or many unrelated methods are shown
  • Only one or many unrelated classes or interfaces respectively are shown
  • Only one or many unrelated other structures, such as an if-clause or match expression, are shown

ravage84 avatar Jun 05 '23 12:06 ravage84