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

Don't treat class name literals as dependencies #47

Closed
brightbyte opened this issue May 13, 2019 · 4 comments
Closed

Don't treat class name literals as dependencies #47

brightbyte opened this issue May 13, 2019 · 4 comments

Comments

@brightbyte
Copy link

Class name literals, like FooBar::class, should not be treated as a dependency on the class FooBar. Such literals are really just syntactic sugar for string literals like "FooBar", they don't require the class to be loaded, or even to exist at all.

Technically, class name literals are a dependency on the class name, as they have to be updated when the class is renamed. If this kind of dependency should still be tracked, the mechanism for marking the dependency type suggested in #43 could be used to mark such dependencies as "name".

@mihaeu
Copy link
Owner

mihaeu commented May 13, 2019 via email

@brightbyte
Copy link
Author

Yea, I know what you mean. It would probably not be good to just ignore those, always. But I want to be able to pick and choose. So having a dependency-type "name" or "constant" would be helpful, since then I could filter them out when I don't care about them.

I didn't even think about actual constants, by the way - but you are right, Foo::BAR and Foo::class are not so different. Except the latter doesn't require the class to exist or be loaded.

My use case is that some code may use class literals to implement a kind of soft dependency, registering classes by name and using reflection to instantiate them, only relying on some known interface when using the instances. This patterns is quite common in the code I work with, and I'd like to be able to ignore this kind of dependency, since it'S a lot less problematic than other kinds (even though I'd prefer it to go away as well).

@brightbyte
Copy link
Author

I just learned about "connascence" metrics [1] that differentiate between different types and dependencies. This goes into the same direction I was thinking in here: distinguishing different kinds of dependencies allows for more meaningful analysis of the dependency graph. For instance, dependencies on behavior (use) are transitive, while dependencies on names (mention) are not (or at least not always).

[1] https://en.wikipedia.org/wiki/Connascence

@mihaeu
Copy link
Owner

mihaeu commented May 2, 2021

Thought some more about this, but if someone adds a non-existing XYZ::class somewhere I would still want this to show up, especially when writing architecture tests. If there are exceptions those can still be filtered using regex provided by the dephpend option.

@mihaeu mihaeu closed this as completed May 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants