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

PSR12 4.4 Methods and Functions close braces same line #618

Closed
1 task done
junior-paytech opened this issue Sep 18, 2024 · 5 comments
Closed
1 task done

PSR12 4.4 Methods and Functions close braces same line #618

junior-paytech opened this issue Sep 18, 2024 · 5 comments

Comments

@junior-paytech
Copy link

Is your feature request related to a problem?

It is related to PHP8 and PSR12 standard

Describe the solution you'd like

As described in PSR12 item 4.4

If a function or method contains no statements or comments (such as an empty no-op implementation or when using constructor property promotion), then the body SHOULD be abbreviated as {} and placed on the same line as the previous symbol, separated by a space. For example:

class Point
{
    public function __construct(private int $x, private int $y) {}
    
    // ...
}
class Point
{
    public function __construct(
      public readonly int $x,
      public readonly int $y,
    ) {}
}

Additional context (optional)

Exists some discussion and "suggestions" in this topic - squizlabs/PHP_CodeSniffer#3291

@jrfnl
Copy link
Member

jrfnl commented Sep 18, 2024

Don't know where you're getting your information from, but this is not part of PSR12.

This is the literal text of PSR12 section 4.4:

4.4 Methods and Functions

Visibility MUST be declared on all methods.

Method names MUST NOT be prefixed with a single underscore to indicate protected or private visibility. That is, an underscore prefix explicitly has no meaning.

Method and function names MUST NOT be declared with space after the method name. The opening brace MUST go on its own line, and the closing brace MUST go on the next line following the body. There MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis.

A method declaration looks like the following. Note the placement of parentheses, commas, spaces, and braces:
... code sample...

https://www.php-fig.org/psr/psr-12/#44-methods-and-functions

@junior-paytech
Copy link
Author

junior-paytech commented Sep 18, 2024

I took it from - https://www.php-fig.org/per/coding-style/#44-methods-and-functions that can be accessed in the page https://www.php-fig.org/psr/psr-12/ and click on the link "PER Coding Style" on the right top menu (Additional info)

@jrfnl
Copy link
Member

jrfnl commented Sep 18, 2024

@junior-paytech PSR-PER is not the same as PSR12 and for those things for which PSR12 has its own rules, PSR-12 sniffs cannot be updated to follow PSR-PER as in that case, the PSR 12 sniff would no longer enforce PSR12.

@junior-paytech
Copy link
Author

I understand your point, but I believe that the PER is more "actual" and aligned with the current php development.

Anyway, thank you your support.

@jrfnl
Copy link
Member

jrfnl commented Sep 18, 2024

I understand your point, but I believe that the PER is more "actual" and aligned with the current php development.

The intention is to add rulesets for each PSR-PER version via a new external standard. See #29 about this.

Also see #566, which I think is largely what you intended to ask.

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

No branches or pull requests

2 participants