-
-
Notifications
You must be signed in to change notification settings - Fork 46
Create a IsA expression #396
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
base: main
Are you sure you want to change the base?
Conversation
src/Expression/ForClasses/IsA.php
Outdated
\is_a($theClass->getFQCN(), $allowedFqcn, true) | ||
|| \is_subclass_of($theClass->getFQCN(), $allowedFqcn) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we really need to check both? Both do the same, except that is_a()
also returns true
for the class itself (like is_a(A::class, A::class)
), AFAIK, so is_subclass_of()
should never be called.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately, is_a
doesnt check for interface implementation, and is_subclass_of
doesnt check for same class. :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
unfortunately,
is_a
doesn't check for interface implementation
I think it does: https://3v4l.org/91Yt8
AFAIK, is_a
does the same as instanceof
(and it is even more powerful, since it can check string class names and not only instances, if the third parameter is true
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HAH! u r correct, I will fix this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed and force pushed
7b00915
to
5143cff
Compare
This will allow for testing if a class extends or implements another code unit, anywhere in the inheritance tree.
5143cff
to
cafad1a
Compare
Hello, this PR is useful. When can it merge? |
When we used to support older php versions we wanted to avoid relying on checks triggering the autoload and parse the code statically. Not sure it still makes sense, so potentially this is a good addition. At this point I am wondering if we should just update |
That is why I opened this other PR but never got it merged. That PR just adds an IF statement so we don't try to define PHPARKITECT_COMPOSER_INSTALL more than once, which triggers PHP errors. |
For me, the PR is adding value. Maybe we can consider both ways to understand what is the correct one. |
As of now, there is a known limitation when we parse files building ClassDescription objects as we do not walk the inheritance tree, so the analisys stops at the class we currently parsing. This means that, given a ClassDescription object, the If I have a rule saying "class X should not extend class Y" is that the expected behaviour? I doubt that 🤔 One possibile approach would be having two rules like
this also would work for |
I think we need to ensure that autoloading works with all our installation methods (Composer, PHAR, Docker); otherwise, it's a good idea. (I'm even open to deprecating some of the installation methods.) |
|
This will allow for testing if a class extends or
implements another code unit, anywhere in the inheritance tree.