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.
Summary: | PSR-0 folder structure renaming when renaming classes | ||
---|---|---|---|
Product: | php | Reporter: | turneliusz |
Component: | Refactoring | Assignee: | Ondrej Brejla <obrejla> |
Status: | NEW --- | ||
Severity: | normal | ||
Priority: | P3 | ||
Version: | Dev | ||
Hardware: | PC | ||
OS: | All | ||
Issue Type: | ENHANCEMENT | Exception Reporter: |
Description
turneliusz
2013-01-06 16:54:17 UTC
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 |