This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.
Hi, I am not sure if this belongs to "PHP" or general "Editor" product, so please correct me if I am wrong. In PHP we have the PHP Framework Interop Group (http://www.php-fig.org/) which tries to standardize PHP coding and I think this is great to help developer to write clean looking code. PSR-2 says something about line length: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#23-lines There is a "soft limit" on line length of 120 characters. It would be great if we could make this limit configurable in Netbeans in Tools -> Options -> Editor -> Formatting. And if we write code in a line and it becomes longer that the "soft limit", Netbeans tries to break it into smaller chunks automatically. For example: $object->getInstance()->getBlaa()->doAnything()->doSomething()->foobar()->getObject()->setTitle('This is new title'); Becomes to: $object->getInstance() ->getBlaa() ->doAnything() ->doSomething() ->foobar() ->getObject() ->setTitle('This is new title'); Another example: class A { public function bee(SomeClassHint $object, $parameter1, $parameter2, $anotherParameter, $default = 'do_not_know') { $x = 0; return $x; } } Becomes to: class A { public function bee( SomeClassHint $object, $parameter1, $parameter2, $anotherParameter, $default = 'do_not_know' ) { $x = 0; return $x; } } This is defined in https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#44-method-arguments This would be a really nice feature ;-)
Isn't Editor->Formatting->Wrapping what you are talking about? You have to invoke formatting action of course, but it can work for you too :)
Created attachment 127631 [details] Screenshot of formatting Oh you are right. I did not know what "Wrapping" was for... stupid mee :-) But as you see in my screenshot the wrappers for "Method Parameters" and "Method Call Arguments" are not working like defined in PSR-2. And it would be nice if this standards would be use as base of the formatting. The formatter for "Chained Method Calls" seems not to work (as expected). Additionally the lines of code in the "Preview" is very short, no long parameter lists are use, etc so that you do not see any changes, when you change the settings from "Never" to "If long" or "Always.
I made some improvements for 7.3, so you can test it there.
Okay, thanks. I will test it.
Using NetBeans IDE 7.4 (Build 201310111528), the option in Formatting > Language PHP, Category Wrapping, setting "Chained Method Calls" on "If long" does not work. For instance : $object->getInstance()->getBlaa()->doAnything()->doSomething()->foobar()->getObject()->setTitle('This is new title'); is not wrapped in any way. Even if it's way other the limit of 120 char.
As of netbeans 8.0, it still seems impossible to have only one argument per line when the line is too long. https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md#46-method-and-function-calls >Argument lists 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 argument per line. Same for chained method call.
Yes, the options for the Method Call Arguments in the Wrapping category aren't enough to match the PSR-2 standard. "If Long" will add a line break at the specified character limit, but that just puts the method call on two lines. "Always" adds a line break after every argument, which is good for long function calls (matches the standard) but for short function calls it also adds all the line breaks, which is not good. Either "If Long" needs to add a line break after every argument, or there needs to be another option, in order to match the standard.
Something that would be close would be a combination of "Always" and "If long" ("Always if long" ?). I can't get to have a level of indentation when using Always: public function bee( SomeClassHint $object, $parameter1, $parameter2, $anotherParameter,$default = 'do_not_know' ) { //body } should be: public function bee( SomeClassHint $object, $parameter1, $parameter2, $anotherParameter,$default = 'do_not_know' ){ //body } Note the indentation of "SomeClassHint" AND the left parenthesis if on the same line as the }. > When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them.