I’ve been looking at this page in the MODX 3 docs, and noticed that in a number of cases, it doesn’t reflect the style of the MODX 3 core code.
I don’t know if this is because some code hasn’t been converted, the page is outdated, or the coding standards are somewhat loose.
The guidelines on that page are also a little vague.
For example, " Beginning brackets do NOT linebreak. They start one space after the end parenthesis, as according to traditional Unix policy."
It’s not clear what constitutes a “beginning bracket.” From the text and examples, it seems that this would include curly braces (and, imo, it’s incorrect to call them brackets, though some people do use that term for them, as does Wikipedia).
In the MODX 2 core code, curly braces for classes and functions/methods are generally on the same line (as they are in my code).
In MODX 3 braces for classes are generally on a new line, but those for functions/methods are not. The PSR-2 examples show curly braces for some functions on a new line, but I couldn’t find any “rule” for this, and those for functions with the arguments on separate lines, put them after the final
Another issue, not mentioned in the docs is the many instances of
else if rather than
elseif in the core code. PSR-2 (should PSR-2 be mentioned on the page? It’s not) says it should be
elseif which could be fixed with search-and-replace.
The examples on the page also show no spaces between arguments/parameters. This practice is inconsistent in both MODX 2 and MODX 3, though no spaces seems to be more prevalent. FWIW, I prefer spaces. For one thing, it allows lines to break there on smaller screens when example code is inline in a paragraph rather then in
<pre> tags. I also think it makes the code easier to read.
Here’s another rule: " * Always name PHP class files in name.class.php format."
This is no longer followed in MODX 3.
It’s not a coding style issue, but while I’m at it, it’s MODX 3 (not MODX3), right? Or is it required to be MODX Revolution 3 in all cases?
In my code, I generally put curly braces on the same line for both classes and functions/methods (which is how they are generally in MODX 2), and I put spaces between arguments.
My biggest concern here is what style should be used in example code in, say, a new edition of MODX: The Official Guide and my MODX extras? Can I continue to put all curly braces on the same line and spaces between arguments?