Skip to content
This repository has been archived by the owner on Sep 20, 2021. It is now read-only.

Madness with exceptions #95

Closed
unkind opened this issue Nov 8, 2018 · 5 comments
Closed

Madness with exceptions #95

unkind opened this issue Nov 8, 2018 · 5 comments
Assignees
Labels

Comments

@unkind
Copy link

unkind commented Nov 8, 2018

image

image

Maybe it's just a PhpStorm's bug, but I really didn't find the root Exception class.

use Hoa\Exception as HoaException;

— what is that? Aliasing sub-namespace or aliasing class Exception in the namespace Hoa?

If first, how does it work:

class Exception extends HoaException

?

If second, I see no class Exception in the namespace Hoa (only Hoa\Exception\Exception).

It looks like black magic. What's the purpose?

And aliasing is still supported by most popular IDE (PhpStorm) quite bad, e.g. find usages ignores aliased classes. I know that it's not an argument ("they should fix it"), but it also leads to confusions when reading code. Is it possible to resolve all aliases?

And I still don't get purpose of Consistency::flexEntity.

@vonglasow vonglasow self-assigned this Nov 8, 2018
@Hywan
Copy link
Member

Hywan commented Nov 12, 2018

Hello :-),

The purpose of flex entities is to keep BC when a class is moved into a namespace of the same name. This happens sometimes, and flex entities are here to solve this issue.

When using PHPStorm, you might take a look at https://github.com/hoaproject/Devtools#expandflexentities. Running hoa devtools:expandflexentities will generate a file that will fix all the issues for PHPStorm.

@Hywan Hywan self-assigned this Nov 12, 2018
@Hywan Hywan closed this as completed Nov 12, 2018
@Hywan
Copy link
Member

Hywan commented Nov 12, 2018

I close the issue because I answered it, but feel free to re-open if you still have a question.

@unkind
Copy link
Author

unkind commented Nov 12, 2018

moved into a namespace of the same name

I don't get it. Do you mean \Acme\A -> \Acme\B? class_alias has the same effect, doesn't it?

@Hywan
Copy link
Member

Hywan commented Nov 12, 2018

Let's consider A\B\C is initiallly located is A/B/C.php, but then the namespace A\B\C is created, then following our standards, the file must be moved in A/B/C/C.php, and with the name A\B\C\C. So A\B\C is an alias to A\B\C\C, to keep BC.

@unkind
Copy link
Author

unkind commented Nov 13, 2018

@Hywan OK, but it still solves with class_alias, doesn't require additional code (Consistency::flexEntity()) and IDE is able to resolve real exception class without plugins and doesn't produce bloody errors.

If I understand it right, it's better to refactor it.

@unkind unkind mentioned this issue Dec 3, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Development

No branches or pull requests

3 participants