Skip to content

Conversation

@tomasfejfar
Copy link
Contributor

As per phpstan/phpstan#6812 (comment)

Am I on the right track?

@tomasfejfar tomasfejfar force-pushed the tf-locateIdentifiersByType branch 2 times, most recently from 22b2511 to 449ba41 Compare March 17, 2022 16:02
@ondrejmirtes
Copy link
Member

Yes, looks great :)

@tomasfejfar
Copy link
Contributor Author

I'll try to implement the functions as well for it to have the same functionality as the source locator.

@tomasfejfar
Copy link
Contributor Author

Making the tests pass is a pain! "Works on my machine"™ 🙈

@tomasfejfar tomasfejfar force-pushed the tf-locateIdentifiersByType branch 3 times, most recently from ff08115 to 8cd6edc Compare March 17, 2022 21:36
@tomasfejfar tomasfejfar force-pushed the tf-locateIdentifiersByType branch from 8cd6edc to ba04fac Compare March 17, 2022 23:02
@tomasfejfar
Copy link
Contributor Author

That's probably the best I can do :)

@ondrejmirtes
Copy link
Member

Thank you, it's nice. Do you plan to also send PRs for all the other source locators? 😊

@ondrejmirtes ondrejmirtes merged commit 7688036 into phpstan:1.5.x Mar 18, 2022
@tomasfejfar
Copy link
Contributor Author

Maybe :)

@ondrejmirtes
Copy link
Member

I'll add these methods to ReflectionProvider once all the sensible source locators support that:

	/**
	 * @return array<string, ClassReflection>
	 */
	public function getAllClasses(): array;

	/**
	 * @return array<string, FunctionReflection>
	 */
	public function getAllFunctions(): array;

	/**
	 * @return array<string, GlobalConstantReflection>
	 */
	public function getAllConstants(): array;

I don't want to do it sooner because it'd lead to incomplete and confusing results.

Please note that it doesn't make sense for some source locators like AutoloadSourceLocator to support this, it's fine for some to still return [].

Also I'm torn if the classes and functions should be indexed by lowercase name or not, probably yeah, so that classes like AggregateSourceLocator and ChainReflectionProvider can de-duplicate the returned results.

@tomasfejfar
Copy link
Contributor Author

BTW: My implementation stems from \PHPStan\Reflection\BetterReflection\SourceLocator\OptimizedDirectorySourceLocator::locateIdentifier which does not support constants. Therefore it does not support constants as well and in that case the original behavior (empty array) remains.

@tomasfejfar
Copy link
Contributor Author

And I understand how all source locators need to implement this. Otherwise it's ultra confusing :)

@tomasfejfar
Copy link
Contributor Author

I actually had it previously indexed by lowercase names, but the interface specified array<int, Reflection> so I changed that. I hadn't had time to dig deeper on where and how it's actually used and if I can change it.

@ondrejmirtes
Copy link
Member

Yes, directory source locator doesn't look for constants, that's fine, people should follow this: https://phpstan.org/user-guide/discovering-symbols#global-constants

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