-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Importing and aliases vs. fully qualified namespaces #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I totally second the importing approach 👍
I would rather forbid aliases usage or allow them only for exceptional cases. Proper class name must contain all data necessary to understand the purpose of class. There are a lot of names with directory-per-word approach and would be better to rename classes than introduce aliases each time you want to use them, for instance: You may notice that there are a lot of code in Magento2 using short names already. But in code which was not changed for a long time there are still a lot of fully-qualified class names. Would be nice to replace fully-qualified class names with imports all over the code and enforce short name usage with static test (for example, check that What tool would you suggest for such transformation? The closest ready-to-use utility I found so far is PHP Refactoring Browser, but "optimize use statements" feature here does not work as expected: type-hinted class names in constructor/other methods, PHPDoc blocks are not updated. So, except the IDE abilities which I didn't analyze, I would build such script using one of:
|
Thanks @orlangur for the comment. I just picked that Exception class for no reason, and yes I should have made a better alias, but for me even importing without alias is still better than fully qualified name. Maybe aliases could be used only if we have two classes with the same name. To tell you the truth, I am not sure which tool would be the best to do this automatically. I know some IDEs can do that, but I am not sure how reliable are they. I guess it would be hard to find a reliable tool. |
Internal ticket: MAGETWO-32347 |
Thank you for your submission. We recently made some changes to the way we process GitHub submissions to more quickly identify and respond to core code issues. Feature Requests and Improvements should now be submitted to the new Magento 2 Feature Requests and Improvements forum (see details here). We are closing this GitHub ticket and have moved your request to the new forum. |
[Performance] Performance Profile Generator
…nloadableCart… #872 - Merge Pull Request magento/graphql-ce#872 from Rus0/graphql-ce:ISSUE-824 - Merged commits: 1. e20be33
use PHPstorm |
I think that Magento2 should import namespaces and use aliases instead of using fully qualified namespaces all over the place.
Here is an example.
What I suggest is that instead of:
We could have:
Here are the benefits from this:
Let me know what you think.
The text was updated successfully, but these errors were encountered: