Improved Type Renaming

Hi all! Today we would like to show you brand new renaming feature for next NetBeans release.

Most of you definitely use common standard that every class is in its own file and the file name is the same as the class name. It means that if you have class Foo it will surely be in a file named Foo.php. But when you rename that class you surely want to rename its file as well. And NetBeans, finally, allows you to do that automatically :-) Just check one checkbox during refactoring process and that's all.

So here are some screenshots:

Right click on the class name and invoke Refactor -> Rename....

Improved Type Renaming

Type new name and check Rename Also File With the Declaration. checkbox.

Improved Type Renaming

Confirm refactoring and look at new file name :-)

Improved Type Renaming

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 Refactoring). Thanks a lot!

Comments:

Good feature. Will the checkbox automatically be checked the next time a refactoring occurs?

Posted by guest on March 20, 2013 at 03:58 PM CET #

No, it has to be rechecked.

Posted by Ondrej Brejla on March 20, 2013 at 04:01 PM CET #

Will it use lower case filename if the previous is it?
autoloader with strtolower($class) in it...

Posted by Robert Sandgren on March 20, 2013 at 08:05 PM CET #

No, the name of the file is exactly the same as for class. But it's a good enhancement. You can write it to our bugzilla [1]. Thanks!

[1] http://netbeans.org/bugzilla/enter_bug.cgi?product=php

Posted by Ondrej Brejla on March 21, 2013 at 07:32 AM CET #

I do back the request Robert made.

Names of classes and namespaces are not case-sensitive in PHP.
Thus you should not rely on the class name being given in the "right" casing.

If this is your convention, better be aware that you are introducing a new principle into the language that has never been a part of the language definition and never will be.
In PHP there is by definition no difference in writing "new foo()" instead of "new Foo()" and no development environment will warn or force you to prefer the one over the other.

What would be even better though is a feature for refactoring namespaces.
My colleagues have asked me several times now for that now because it would be so useful.

However: this includes that you would need to assume a certain behavior of the auto-loader.
So to implement this feature properly you would have to add some project-wide settings that describe what your auto-loader does. Usually that would be (at least) a "root-directory" and a "style of file- and folder names" (case-sensitive or not).
But since you can have multiple auto-loaders within the same project you may want to bind those settings to a namespace.

Posted by guest on March 23, 2013 at 01:16 PM CET #

> be aware that you are introducing a new principle into the language

Definitely not. Classes with the same name as files (including casing) is a widely used style.

But I'll try to make some improvements. To let NB remember the last used option (rename file too or not) and add a checkbox to rename file with lowercases.

Posted by Ondrej Brejla on March 27, 2013 at 10:19 AM CET #

I just pushed that changes, so that lowercase option will be in the dev build soon.

Posted by Ondrej Brejla on March 27, 2013 at 11:45 AM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
About

This blogs is written by NetBeans developers who contribute to the PHP support mainly.

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today