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

[PHP] Implement full PSR/PER code style and use by default #4685

Open
terax6669 opened this issue Sep 25, 2022 · 12 comments
Open

[PHP] Implement full PSR/PER code style and use by default #4685

terax6669 opened this issue Sep 25, 2022 · 12 comments
Assignees
Labels
kind:feature A feature request PHP [ci] enable extra PHP tests (php/php.editor)

Comments

@terax6669
Copy link

terax6669 commented Sep 25, 2022

Description

Some things that I noticed, but I'm sure there are more:

  • Formatting rules for PHP should adhere to PSR by default
  • Formatting rules in the Blank Lines category seem to be impossible to adhere to PSR. Example with traits - according to PSR traits should be the first thin inside a class. We have Before Use Trait but not After. Therefore I must set Before Function to 1 to separate traits and functions. Now even if I set After Class Header to 0 I will get a blank line when I have a method inside a class but no trait (which would be the most common scenario).
    Impemented in Add "After Use Trait" to the formatting options #4685 #6467.
<?php

class Foo
{
    use Bar;

    public function foobar()
    {
    }
}

// vs

class Foo
{
// this blank line shouldn't be here!
    public function foobar()
    {
    }
}

Use case/motivation

PSR is the de facto standard for PHP.

There are a few things in PSR that are not available in NetBeans. It would be great to fix those and also set it as default formatting for PHP files in the next version!

Related issues

Are you willing to submit a pull request?

No

Code of Conduct

Yes

@terax6669 terax6669 added kind:feature A feature request needs:triage Requires attention from one of the committers labels Sep 25, 2022
@erickcomp
Copy link

+1.
With each passing day, it gets harder to find non-PSR-12 code. Netbeans is wonderful, but you cannot use it out of the box if you work in a team where people use multiple IDE's and PSR-12 is a must.

@mbien mbien added the PHP [ci] enable extra PHP tests (php/php.editor) label Sep 28, 2022
@erickcomp
Copy link

Hi guys! Is there any plan on implementing this? I dare to say that one cannot code modern PHP app with Netbeans without having PSR-12 support nowadays.

@terax6669
Copy link
Author

@erickcomp I think if we treat this ticket as an epic task and break it down into smaller chunks, the devs would be able to implement it step by step. I already listed some related issues.

If you notice any incompatibilities please make a separate issue on it and I'll add it to the issue description.

@KacerCZ
Copy link
Contributor

KacerCZ commented Jan 15, 2023

Issue #4611 is related to blank lines in class.

@KacerCZ KacerCZ removed the needs:triage Requires attention from one of the committers label Jan 15, 2023
@KacerCZ
Copy link
Contributor

KacerCZ commented Jan 30, 2023

Just to reference up-to-date recommendation, PSR-12 was replaced by PER coding style.
https://www.php-fig.org/per/coding-style/

@czukowski
Copy link
Contributor

czukowski commented Jul 19, 2023

Just adding my 2 cents to the discussion, implementing and maintaining native full compliance to PSR or its successors seems like quite a big task and that's not even the single coding standard in use. Various reasons, including those outside of our control, may lead to other standards being implemented by different projects.

Perhaps this task could be delegated to PHPCS. It is very fast and there is already a basic integration of it. NB could ship (or be able to download) rule sets for popular standards to use with projects that don't come with their own sets. It should be even possible to display CS errors inline, much like the PHP parser's. Going this way might prove a simpler alternative, while giving a freedom to choose specific standards to the users at the same time.

@zkwbbr
Copy link

zkwbbr commented Sep 7, 2023

+1 To adding After Use Trait

@junichi11 junichi11 self-assigned this Sep 9, 2023
junichi11 added a commit to junichi11/netbeans that referenced this issue Sep 15, 2023
- apache#4685
- Add "After Use Trait" option
- Add unit tests
junichi11 added a commit that referenced this issue Sep 20, 2023
Add "After Use Trait" to the formatting options #4685
@terax6669 terax6669 changed the title [PHP] Implement full PSR and use by default [PHP] Implement full PSR/PER code style and use by default Nov 17, 2023
@erickcomp
Copy link

It seems we have (most of) the options to adhere to the per coding-style. Noob question: Is it hard to make these configs the default when you install the IDE?

@terax6669
Copy link
Author

I'd say the settings are very obtuse, but some trial and error will allow you to set it up properly.

@erickcomp
Copy link

I see. But can we get very close to PER coding style, right? If so, could we get this settings out of the box on NB? I mean, when we install it for the first time, we got formatting options as close as possible to the PER coding style.

@terax6669
Copy link
Author

If you do, could you post a list of all the changes you have to make from the default config? Would make it easier to implement that.

As for whether that would be the default... I think it should, but I'm not making decisions. IDK how that works, maybe Junichi can weigh in.

@erickcomp
Copy link

I'm planning to take some time to create this config in the next few weeks. I'll let you guys know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:feature A feature request PHP [ci] enable extra PHP tests (php/php.editor)
Projects
None yet
Development

No branches or pull requests

7 participants