Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
andrewnicols opened this issue Apr 14, 2024 · 0 comments
Open

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

andrewnicols opened this issue Apr 14, 2024 · 0 comments

Comments

@andrewnicols
Copy link
Contributor

andrewnicols commented Apr 14, 2024

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:

  • you have multiple interfaces implemented
  • you use traits
  • you have an undocumented method (allowed) in the beginning of the class

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant