-
-
Notifications
You must be signed in to change notification settings - Fork 47
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
Conversation
7b00915
to
5143cff
Compare
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.) |
@micheleorselli I made some necessary updates to this PR, it all seems to be green, please feel free to squash&merge or ask for changes. |
src/Expression/ForClasses/IsA.php
Outdated
} | ||
|
||
return false; | ||
} |
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.
If I got it right here we need the class to implement at least one of the fqcn specified. I'm ok with that but I was wondering if we can make it explicit in some way. For instance we could either:
- make IsA accepting one parameter instead of an array (but it is less expressive since you cannot say "a class is A or B")
- change the name to something like
IsOneOf
or something similar
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.
I changed the name to IsOneOf
|
||
namespace Arkitect\Tests\Unit\Expressions\ForClasses\DummyClasses; | ||
|
||
class Banana implements FruitInterface |
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.
if possibile I would avoid creating test classes here. You could either:
- create fixtures directory like we did in the E2E section of the tests
- rely on vfsstream and create the classes only in memory. This also means you'll have to create and register a custom autoloader. (that would be my preferred choice but if it is too much work no 1. is fine
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.
I moved the dummy classes declaration to inside the class test itself, this avoids creating the dummy classes files, keeps the whole test self-contained and avoids the complexity of using a vfs.
Let me know if this is ok.
775f8b2
to
ebe773f
Compare
@micheleorselli I rebased and squashed the previous fixup commits and created 2 more, one for each comment. let me know if anything else is needed from my side. |
ebe773f
to
e95cd8a
Compare
/** | ||
* @param class-string ...$allowedFqcnList | ||
*/ | ||
public function __construct(string ...$allowedFqcnList) |
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.
Can we avoid variadic parameter?
We removed it from other expression to add the exclude parameter if needed
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.
Sure.
I dropped the commit that renamed the expression, and applied the previous suggestion where we only accept one fqcn to test, instead of the variadic.
let me know if anything else is needed from my side.
e95cd8a
to
782aa59
Compare
|
@AlessandroMinoccheri @micheleorselli |
What do you think @micheleorselli? For me we can merge it. |
yup, all good for me. Thank you @hgraca 🎉 |
This will allow for testing if a class extends or
implements another code unit, anywhere in the inheritance tree.