-
Improvement
-
Resolution: Done
-
Low
Since 20th March 2020, this has been agreed:
Unless otherwise specified, this Coding Style document will defer to PSR-12, and PSR-1 in that order.
Where a de-facto Moodle standard* is encountered but is undocumented, an appropriate MDLSITE issue should be raised to have the standard either documented within this Coding style guide, or rejected and the PSR recommendations adopted instead.
* "de-facto Moodle standard" is any coding style which is commonly and typically used in Moodle
Background
Moodle's coding style pre-dates the standard and widely recognised PSR specifications. There have been several requests for us to start recognising these in the future.
Proposal
I would like to propose that our coding style guidelines be updated to explicitly defer to the PSR standards relating to coding style where no explicit rule already exists.
Those standards are:
- PSR-12: https://www.php-fig.org/psr/psr-12/
PSR-2:https://www.php-fig.org/psr/psr-2/Replaced by PSR-12- PSR-1: https://www.php-fig.org/psr/psr-1/
Existing coding style rules must continue to be observed, but for new styles we have not yet ruled on, we should defer to those PSRs in that order (newest to oldest).
It is suggested that the following wording replace the existing section 1.1, "Scope" of the coding style:
This document describes style guidelines for developers working on or with Moodle code. It talks purely about the mechanics of code layout and the choices we have made for Moodle. The intent of this specification is to reduce cognitive friction when scanning code from different authors. It does so by enumerating a shared set of rules and expectations about how to format PHP code.
Unless otherwise specified, this Coding Style document will defer to PSR-12, and PSR-1 in that order.
Where a de-facto Moodle standard is encountered but is undocumented, an appropriate MDLSITE issue should be raised to have the standard either documented within this Coding style guide, or rejected and the PSR recommendations adopted instead.
A "de-facto Moodle standard" is any coding style which is commonly and typically used in Moodle
Voting
This proposal has three voting options.
Vote "Accept"
The wording of this proposal should be accepted in its current form.
Vote "Reject"
This proposal should be rejected in its current form but should be amended to consider additional points. It may be resubmitted in the future once these points are addressed.
Vote "Dismiss"
This proposal should be rejected, and the issue closed. It will not be re-opened for discussion in the near future, unless there is a change in situation.
- has a non-specific relationship to
-
MDLSITE-6087 Require formal namespaces for any new PHP files
-
- Closed
-
- has to be done after
-
MDLSITE-5967 Stop requiring MOODLE_INTERNAL for files without side-effects
-
- Closed
-
- has to be done before
-
MDLSITE-5667 Coding style ruling about function/method return types and nullables
-
- Closed
-