hoaproject / Compiler

The Hoa\Compiler library.
https://hoa-project.net/
453 stars 47 forks source link

Madness with exceptions #95

Closed unkind closed 5 years ago

unkind commented 5 years ago

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.

Hywan commented 5 years ago

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 commented 5 years ago

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

unkind commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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.