-
-
Notifications
You must be signed in to change notification settings - Fork 78
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
Detect when a class extends a class that has been flagged as @internal #248
Conversation
d2f2df1
to
6f28dd7
Compare
This is amazing. I want to come back and review it more. Because we could move a lot of this logic into a shared service that can help handle #249. Like |
I'm not sure how a service like that could be named 🤔 Do you mean something like: final class Foo {
public function isClassFromAnotherExtension(\PhpParser\Node\Stmt\Class_ $node);
public function IsClassFromADependencyExtension();
} ? |
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.
Some thoughts on naming and maybe ditching the private methods added to the Rule.
In reference to #247 (I tagged the wrong issue before), we could move these two methods into static methods in a namespace helper utility class. One that checks if a namespace is in Drupal and another if it's in a shared namespace.
I will try to re-work this PR this week to include the requested changes (hoping I won't have to wait this weekend) |
ah! Seems the fresh (3h ago) and new nikic/php-parser version 4.13.2 breaks the CI thanks to this:
I think we could ignore this error because I'm gonna add this error to the ignored error in the phpstan configuration. What do you think @mglaman? |
@brambaud could we just add the "ignore next line" inline error? On mobile, but PHPStan has some inline comment to ignore an error on the next line |
@mglaman If you prefer the inline ignore tag fine by me! |
@brambaud Since it's one failure, I like a single ignore. If we had 30+ and it'd be a huge refactor, then I'd ignore it in the config. Either approach requires coming back to audit errors being ignored. This single ignore helps as a "reminder" if it shows again in new code |
I'll give this a review later this evening, I have a feeling it's ready to go :) |
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.
Looks great, @brambaud ! I'll pause to merge to see your thoughts on s/ClassHelper
/NamespaceCheck
.
I like NamespaceCheck::isInDrupalNamespace
(or just isDrupalNamespace
). I think it reads well
Agreed about the naming and changes have been done! Thanks! |
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.
This is amazing, thanks!
See #183
In this PR, a shared namespace for Drupal starts with
Drupal\project_name
.It means:
Drupal\Core
can extends an internal class fromDrupal\Core
Drupal\my_module
can extends an internal class fromDrupal\my_module
Drupal\my_module
cannot extends an internal class fromDrupal\Core
or\Drupal\another_module
Drupal\Component
cannot extends an internal class fromDrupal\Core
or\Drupal\another_module
Drupal\Core
cannot extends an internal class fromDrupal\Component
or\Drupal\another_module
For the part detecting calls to internal methods, I think it can be handled in another PR 🤔