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

Trait methods are not detected #27

Merged
merged 2 commits into from
Sep 11, 2020
Merged

Conversation

enumag
Copy link
Contributor

@enumag enumag commented Sep 10, 2020

How about a test for traits this time? Turns out a method defined in a trait can't be disallowed neither by using the trait name nor the class name. In my opinion both should work.

This method might be helpful for implementation:
https://github.com/nette/utils/blob/960bc900bd8a97d89feb8cbd1ae332e34a8adac3/src/Utils/Reflection.php#L146

@enumag enumag force-pushed the feature/trait-methods branch from ea0d145 to a73664b Compare September 10, 2020 06:35
@spaze
Copy link
Owner

spaze commented Sep 10, 2020

Thanks. When using class names, the methods in traits are detected when the class is known (loaded in bootstrap.php, see 24592e0) but using the trait name, they're not. Should be able to get it working sooner or later.

@spaze spaze force-pushed the feature/trait-methods branch from 24592e0 to 12678ae Compare September 11, 2020 00:10
@spaze spaze merged commit d7348f0 into spaze:master Sep 11, 2020
@spaze
Copy link
Owner

spaze commented Sep 11, 2020

I've learned so far that once in PHPStan land, there's always a PHPStan's way, a PHPStan's class and/or a method that does what you need. All you need to do is to find it 🤣

When a trait method is forbidden using the trait name, then also the name of the class using the trait will be shown in the error message:

Calling Traits\TestTrait::z() (as Traits\TestClass::z()) is forbidden, method TestTrait::z() is dangerous'

Thanks again.

@enumag enumag deleted the feature/trait-methods branch September 11, 2020 06:48
@enumag
Copy link
Contributor Author

enumag commented Sep 11, 2020

Nice! Thank you!

@spaze
Copy link
Owner

spaze commented Sep 11, 2020

No problem! I'll release a new version with these and other changes next week probably. Unless you'll be back with another challenge 😂

@enumag
Copy link
Contributor Author

enumag commented Sep 11, 2020

No promises! 😂

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

Successfully merging this pull request may close these issues.

2 participants