apache / netbeans

Apache NetBeans
https://netbeans.apache.org/
Apache License 2.0
2.69k stars 853 forks source link

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

Open terax6669 opened 2 years ago

terax6669 commented 2 years ago

Description

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

class Foo { use Bar;

public function foobar()
{
}

}

// vs

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


* `Templates/Scripting/PHPClass.php` class opening bracket should be on a new line
* Same thing for the `cls` code template and the constructor method inside (it's hidden by the fact that default settings in NetBeans reformat code templates on completion)
* Related: #4609
* Related: #4641

### 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

* #4609
* #4611
* #4641
* #5186
* #6715
* #6716
* #6717
* #7524

### Are you willing to submit a pull request?

No

### Code of Conduct

Yes
erickcomp commented 2 years ago

+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.

erickcomp commented 2 years ago

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 commented 2 years ago

@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 commented 1 year ago

Issue #4611 is related to blank lines in class.

KacerCZ commented 1 year ago

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

czukowski commented 1 year ago

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 commented 1 year ago

+1 To adding After Use Trait

erickcomp commented 1 year ago

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 commented 1 year ago

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

erickcomp commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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