-
Notifications
You must be signed in to change notification settings - Fork 133
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
Added package name collector #1205
Added package name collector #1205
Conversation
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 would rather see extending the FileReferenceVisitor
to add a property to ClassLikeReference
and you then checking against that property, rather than trying to re-parse the file again in the collector.
*/ | ||
private function getCommentDoc(ClassLikeReference $reference): string | ||
{ | ||
$node = $this->nikicPhpParser->getNodeForClassLikeReference($reference); |
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 very expensive - it forces every class-like to be loaded and parsed at least twice during the program runtime.
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.
And also forces the second parsing to be again stored in memory.
|
||
public function satisfy(array $config, TokenReferenceInterface $reference): bool | ||
{ | ||
if (!$reference instanceof ClassLikeReference) { |
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.
Limiting this only to class-likes seems half done looking at the docs for that annotation: https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/package.html#description
public function __construct( | ||
private readonly NikicPhpParser $nikicPhpParser | ||
) { | ||
$this->lexer = new Lexer(); |
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 don't like the concept of mixing Ast Parsing (done in AST module
) and collectors (done in Layer
module). They are separate concerns and should be done in their respective places.
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 agree. The collector should not be aware of the parser. I think this should be an extractor instead, which can then emit a reference. I am not sure, if it should be a class reference or maybe something else/new.
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.
At the moment the TokenReferenceInterface only handles the Token and its filepath - could we add a more generic array of meta information, which we can then search later in collectors?
For example, if there was a new TokenReferenceMetaInterface, with an array of those in each TokenReferenceInterface, we could store a new PackageAnnotationMeta object in that array when we find the @package
annotation, and then search for it in collectors.
This would prevent the TokenReferenceInterface gradually having more fields as more meta data is attached to it (if more collectors come along in the future).
The extractor you suggest could then add a TokenReferenceMeta to the TokenReference.
Sorry - I don't think I've explained this very well - I'll see if I can start to build it so you can see what I mean.
); | ||
} | ||
|
||
private function getPackageDocBlock(array $packageNames): Doc |
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 the test be done on some fixture
class file instead of this synthetic doc-block? Those test then can serve as a documentation reference as well to show case how it should be used as well.
ca76e7a
to
20772c6
Compare
bfe5c46
to
80800bc
Compare
I've made a number of changes:
Some other notes: I can't make use of file-level The recent work on pulling the docblock parsing into a separate method in |
Just re-read https://docs.phpdoc.org/3.0/guide/references/phpdoc/tags/package.html#description and thinking I should remove package name handling from global functions. They're only mentioned if the annotation is at the file-level docblock (which we can't handle). |
Please update the git origin for development to https://github.com/qossmic/deptrac-src and reopen the PR. |
Closes #1190