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.
Currently PSR-0 is wide accepted standard for PHP. When renaming a class it is possible to detect if structure of the folder that contains a class is following PSR-0 and adjust the folder name. CASE 1 (namespaces): # file: Zend/Log/Writer/File.php namespace Zend\Log\Writer; class File {} NetBeans detected that folder structure of the class matches PSR-0. When: a) renaming class name file name should be adjusted, b) renaming namespace should move the file to new (or existing) folder with adjusted name. CASE 2 ("_" separator): # file: Zend/Log/Writer/File.php class Zend_Log_Writer_File {} NetBeans detected that folder structure of the class matches PSR-0. When: a) renaming class name folder name and/or file name should be adjusted. FS STRUCTURE: Original state: - Zend/ -- Cache/ -- Db/ -- Log/ --- Writer/ ---- File.php After changing "Zend" part of the name to "Foo", new state of the structure: - Foo/ -- Log/ --- Writer/ ---- File.php - Zend/ -- Cache/ -- Db/ -- Log/ --- Writer/ (empty now) What do you think?
Info: Fully Qualified Name (FQN) = Namespace + Class name. See: http://www.php.net/manual/en/language.namespaces.rules.php ---- I think it's a great idea. But actually i'm just a tiny bit more interested in the other way around, though both would be great. So you suggest: Renaming the FQN renames the file or change the directory. I'm more interested in: Renaming the file or changing the directory updates the FQN. Additionally: Both operation would alter the same things in the end (namely: FQN and file structure). But then after that has been done it should update all the FQN's used in other files. Example: /MyVender/Class1.php: namespace \MyVendor\Class1; /MyVender/Class2.php: namespace \MyVendor\Class2; use \MyVendor\Class1; Now changing Class1 FQN (or the file/dir) should update the use statement in Class2.php Note: Sometimes FQN are used directly in the source code rather the with the use keyword. ---- Another thing is that PSR-4 just came out .. i'm just not too sure if that is related and how it would effect the proposal.
It looks like PSR-4 will complicate the possibilities for automatic refactoring as there will be code setting up the vendor prefixes and which directories they relate to. It seems that within PSR-0 it would be possible for refactoring to work in both directions, i.e. changing the namespace would rename the directories, and renaming the directories could change the namespace.
I believe it's as easy as processing composer.json in the Composer enabled project. Then all the information about autoloading, prefixes will be gathered and could be used for refactoring.
I find this idea really awesome ! I won't add comment about what was said, especially about changing file/folder name changing FQN, and stuff, because it's exactly what I actually need in my apps. I would also add a feature : I'm using "New PHP Class" in the right-click menu in the "Projects" tab, to create my files. I propose to add one feature : "New Namespace" Example : If we have this typical Symfony2-like arborescence : app/ -config/ -Resources/ logs/ src/ -MySociety/ --FirstBundle/ ---Command/ ---Resources/ --SecondBundle/ ---Controller ---Resources/ -SecondSociety/ --ThirdBundle ---Twig/ What I want : -> Add a new Controller to MySociety\FirstBundle I clicked on "FirstBundle" and selected "New Namespace". Netbeans will look for PSR-0 notes in composer.json root file : finds "src/". Now he knows that "src/" is the root for PSR-0 namespaces. Then, he finds "MySociety" and "FirstBundle" folders. According to the two found folders, he'll autocomplete the base namespace name with this : "\MySociety\FirstBundle\{cursorPosition}". Then I type "Controller\MyController" The FQN is the following : \MySociety\FirstBundle\Controller\MyController Netbeans would then look for all folders and the final class name : MySociety/ => EXISTS MySociety/FirstBundle/ => EXISTS MySociety/FirstBundle/Controller => DOES NOT EXIST => Netbeans creates it ! MySociety/FirstBundle/Controller/MyController.php (final name) => Does not exist, create it ! And we would just have to create a specific template for "New Namespace" right-click menu function, which could look like this : <?php namespace ${namespace}; /** * Class ${name} * Project ${project.name} * * @author ${user} * @version 1.0 ${date?date?string("dd/MM/yyyy")} */ class ${name} { } ?> The "namespace" var would be "\MySociety\FirstBundle\Controller" The "name" var would be "MyController" It's just some more ideas... ;)
Just a comment, if you need to priorities enhancements.. PSR-0 is now deprecated... http://www.php-fig.org/psr/psr-0/
C'mon devs, 4 years later and the IDE still doesn't support PSR?
Yes PSR-0 is deprecated. For this we should use PSR-4. This is what NetBeans should change and enhance. Please create a ticket at the JIRA board: https://issues.apache.org/jira/projects/NETBEANS/issues Cheers Chris