Skip to content
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

Tracking method used? #1

Open
ondrejmirtes opened this issue Aug 11, 2019 · 2 comments
Open

Tracking method used? #1

ondrejmirtes opened this issue Aug 11, 2019 · 2 comments

Comments

@ondrejmirtes
Copy link

Hi,
I've been intrigued by finding this library because I'm facing a similar challenge in PHPStan. I'd like to know what method do you use to track file dependencies?

I've only been able to find this directory in your source code: https://github.com/BackEndTea/Dependency-Finder/tree/master/src/PHPParser/Visitor So I think that you only use Name AST node ocurrences as dependencies.

But this problem is far more complex. Consider for example this scenario:

You have a class A that has property private $bProperty with injected class B. You call method doB on $this->bProperty that returns C. Now you call some method on the C object.

Now you're in a situation that class A depends on changes in class C but AFAIK your tool is not able to track this.

PHPStan solves this thanks to type inference - it knows about types of all expressions so it's able to reason about method calls, read phpDocs etc. The logic itself to find out about dependencies is in this class: https://github.com/phpstan/phpstan/blob/master/src/Dependency/DependencyResolver.php

Let me know if you want to work together on this problem :)

@BackEndTea
Copy link
Owner

You are correct in assuming this package only uses the Name nodes to find out the dependencies. And while it is far from perfect it does give a pretty accurate depiction of the dependencies.

You have a class A that has property private $bProperty with injected class B. You call method doB on $this->bProperty that returns C. Now you call some method on the C object.

I mostly wrote this package to support another package: watch-phpunit. Where i want to find out all dependencies, and it doesn't matter if they are direct dependencies or child dependencies. So in your example, class A depends on class B. And class B once again depends on class C, and this package should be able to detect that, as long as the dependency is somewhere in the code (not in the comments) explicitly.

However, moving forward i do think that it would be better if it could infer that class A has a direct dependency on class C. So i'd like working together on that issue.

@ondrejmirtes
Copy link
Author

So feel free to check out these classes:

This command dumps JSON with dependencies to disk. It has this format:

The array key represents file "X" - if file "X" is modified, then all these files in the key's array value need to be analysed.

Although using PHPStan's type inference internally is not its primary usecase, some projects like Rector have been successfully using it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants