deptrac icon indicating copy to clipboard operation
deptrac copied to clipboard

Added package name collector

Open ariddlestone opened this issue 2 years ago • 2 comments

Closes qossmic/deptrac#1190

ariddlestone avatar May 29 '23 20:05 ariddlestone

I've made a number of changes:

  • Added ReferenceBuilder::$metaData so that we can store arbitrary details there and inject them into the references created
  • Created a PackageName class, which is added to ReferenceBuilder::$metaData in FileReferenceVisitor - I can't use an extractor as the $referenceBuilder is a FileReferenceBuilder by the time the extractors are called for class-like nodes
  • Modified PackageNameCollector to look for PackageNames in TokenReferenceInterface::getMetaData() to determine package names
  • Modified parser tests to use a fixture, and added collector test

Some other notes:

I can't make use of file-level @package annotations, as nikic/php-parser doesn't support them. For now I'm therefore only handling class-like and function docblocks.

The recent work on pulling the docblock parsing into a separate method in FileReferenceVisitor::processClassLikeDocs() was nice. I wonder if it might be worth later looking at separating the various data-gathering processes there into their own registered classes, like extractors are currently.

ariddlestone avatar Jul 12 '23 16:07 ariddlestone

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

ariddlestone avatar Jul 12 '23 16:07 ariddlestone

Please update the git origin for development to https://github.com/qossmic/deptrac-src and reopen the PR. Thank you very much!

gennadigennadigennadi avatar Mar 14 '24 11:03 gennadigennadigennadi