Several New Hints

Posted by Ondrej Brejla on Oracle Blogs See other posts from Oracle Blogs or by Ondrej Brejla
Published on Wed, 11 Apr 2012 04:24:52 -0500 Indexed on 2012/04/11 11:36 UTC
Read the original article Hit count: 293

Filed under:

Hi all! Today we would like to introduce you some of our new experimental hints for NetBeans 7.2. They are called: Unused Use Statement and Immutable Variables.

Unused Use Statement

This hint is quite simple. It highlights (underlines) your use statements, which are not used.

Unused Use Statement

Typical use case is after some refactoring, when you forgot to remove some obsolete use statements. This hint warns you on them and allows you to remove them easily. Just click on the hint bulb in the gutter and select Remove Unused Use Statement.

Unused Use Statement

And of course, it works in multiple use statements combined too.

Unused Use Statement

Immutable Variables

The next one is the hint which checks too many assignments into a variable. And why? That's simple. Mostly you should use just one assignment into one variable. But sometimes you are lazy and you do something like:

Immutable Variables

But it's quite wrong, because what you really do is:

Immutable Variables

And that's exactly the case, when our new hint warns you, that Too many assignments (2) into variable $foo occured. Nothing more.

Immutable Variables

Yes, we know that there are some cases, where could be more assignments and no warning should occur, e.g.:

Immutable Variables

Because maybe one likes longer increment syntax more than the short one. So we tried to handle these cases to don't bother you if it's not a need.

Note: We are almost sure that this hint doesn't cover all your use cases, because there are a lot of them. So if you find something strange, write it into our bugzilla so we can handle it better for you. Thanks for your patience!

And the last thing is, that you can set the number of allowed assignments in Tools -> Options -> Editor -> Hints -> PHP: Immutable Variables.

Immutable Variables

Note: This hint works just for a common variables, not for fields. We have an enhancement request for that and it should be implemented in next version of NetBeans (probably 7.3).

And that's all for today and as usual, please test it and if you find something strange, don't hesitate to file a new issue (product php, component Editor). Thanks.

© Oracle Blogs or respective owner

Related posts about /Features