per-coding-style
per-coding-style copied to clipboard
Only add PHP opening tag when the following rule of thumb are met
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