Feature request from ldusan84, posted on GitHub Dec 25, 2014
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:
throw new \Magento\Framework\Model\Exception(
__('Invalid login or password.'),
self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD
);
We could have:
use \Magento\Framework\Model\Exception as MagentoException
/* ... */
throw new MagentoException(
__('Invalid login or password.'),
self::EXCEPTION_INVALID_EMAIL_OR_PASSWORD
);
Here are the benefits from this:
-
With importing namespaces keyword at the first few lines of a class you actually get a nice documentation of your class dependencies. Everything that class uses is in those first few lines. It makes dependencies explicit.
-
If something changes in the future, you would only need to change it in one place, in import declaration and the alias remains. With fully qualified namespaces you would need to find them everywhere in class and change.
-
Less confusion if you have similar namespaces, you can give them different aliases.
- All major frameworks use importing/aliases over fully qualified namespaces.
Let me know what you think.