Gather assert types conditional on installed PHPStan version #301
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Types may depend on the PHPStan version used--especially when a dynamic return type extension relies on types inferred by PHPStan.
Example from
SlashitFunctionsDynamicFunctionReturnTypeExtension, where the type depends on PHPStan’s handling ofrtrim():phpstan-wordpress/src/SlashitFunctionsDynamicFunctionReturnTypeExtension.php
Line 62 in 1cdb6d5
Among other cases, this can cause tests to fail in the lowest-deps build. To avoid bumping the required PHPStan version, this PR introduces the
InstalledPhpStanVersionclass and uses it inDynamicReturnTypeExtensionTestto avoid gathering types for versions that produce different results than the latest.The types returned in the lowest supported version should still be checked to rule out incorrect cases. This has been done for
data/slashit-functions.php. We could also add, e.g.,data/slashit-functions-bc.phpwith assertions that pass with the lowest PHPStan version. This has not been done yet.