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.
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.
And of course, it works in multiple use statements combined too.
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:
But it's quite wrong, because what you really do is:
And that's exactly the case, when our new hint warns you, that Too many assignments (2) into variable $foo occured. Nothing more.
Yes, we know that there are some cases, where could be more assignments and no warning should occur, e.g.:
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.
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).