#3860 - Use PSR-12 standard

Identifier #3860
Issue type Feature request or suggestion
Title Use PSR-12 standard
Status Completed
Tags

Type: Standards compliance (custom)

Handling member Chris Graham
Addon core
Description Our code is formatted according to PSR-2. Now there's a new PSR-12 standard.

There are a lot of very prescriptive parts that are common sense that I don't want to implement into the Code Quality Checker, and really are just there to hit programmers over the head with when they write awfully ugly code.

But of what is there and we don't currently support, the following is relevant to enforce our code to...

1) No "?>" at end of PHP file
2) No lines longer than 80 characters
3) No multiple statements per line
4) No upper case keywords
5) No long-form casting or type declarations, e.g. do (int) not (integer)
6) Do not skip parentheses when constructing a new object, even if not needed
7) No blank lines after an opening brace or before a closing brace
8) Visibility must be declared on class constants (PHP 7.1+)
9) If a case statement has no break, it must be documented '// no break'

I am happy to implement some of these independently into the CQC without formally declaring PSR-12.

If it's all done, we can then updating the coding standards document to reflect our PSR-12 support.

PHP CodeSniffer can scan for PSR-12 issues https://github.com/squizlabs/PHP_CodeSniffer/ -- we should perhaps add this to our release process as an extra manual check. If we are finding many issues, they should also be coded into the CQC.
Steps to reproduce

Related to

#2747 - PHP refresh (ongoing)

#3681 - Run the PHP codebase through PHP_CodeSniffer beautifier

Funded? No
The system will post a comment when this issue is modified (e.g., status changes). To be notified of this, click "Enable comment notifications".

Rating

Unrated