moodlehq / moodle-cs

Moodle Coding Style
https://github.com/moodlehq/moodle-cs
GNU General Public License v3.0
18 stars 15 forks source link

Rules about implements and opening brace do not accept PSR-12 #153

Open andrewnicols opened 5 months ago

andrewnicols commented 5 months ago

Moodle's coding style does not actively state anything regarding the location of the opening brace when there are multiple implemnts but we previously conventioned the following:

class after_user_passed_mfa implements
    \Psr\EventDispatcher\StoppableEventInterface {

However, PSR-12 states:

The extends and implements keywords MUST be declared on the same line as the class name.

The opening brace for the class MUST go on its own line; the closing brace for the class MUST go on the next line after the body.

Opening braces MUST be on their own line and MUST NOT be preceded or followed by a blank line.

Lists of implements and, in the case of interfaces, extends MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one interface per line.

That is, the following is accepted:

class after_user_passed_mfa implements
    \Psr\EventDispatcher\StoppableEventInterface
{

This is slightly conflated by the fact that PSR-12 requires that the opening brace for a class (and method) be on its own line, but in this case I do think that should require it be on its own line for multi-line implements as it is much easier to read when:

For example, in the following example where a single interface is implemented and the class use a trait, it's quite hard to spot easily where the class starts.

class after_user_passed_mfa implements
    \Psr\EventDispatcher\StoppableEventInterface {
    use \core\hook\stoppable_trait;
}

At the moment, using the PSR-12 style will give the message:

Opening brace should be on the same line as the declaration for class before_course_deleted