[2.x] fix: widen Extend\SearchDriver class-string types to SearcherInterface#4668
Merged
Conversation
…terface The docblock annotations on addSearcher/addFilter/replaceFilter/setFulltext/ addMutator were typed `class-string<AbstractSearcher>`, but the surrounding comments already say "must implement SearcherInterface" (and "or extend AbstractSearcher if using the default driver"). Custom non-DB drivers — the whole reason SearcherInterface exists separately from AbstractSearcher — were tripping phpstan with a false positive on every addSearcher/addFilter call in their extend.php. Widen the annotations to `class-string<SearcherInterface>`, which is what the runtime actually checks against, and which the docblocks have always described. No behavioural change. Drops the now-unused AbstractSearcher import.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
The docblock annotations on
Extend\SearchDriver::addSearcher()/addFilter()/replaceFilter()/setFulltext()/addMutator()were typedclass-string<AbstractSearcher>, but the prose right next to them already said:The type annotation was strictly narrower than the prose. Custom non-DB search drivers — the whole reason
SearcherInterfaceexists separately fromAbstractSearcher— would trip phpstan with a false positive on every singleaddSearcher()/addFilter()call in theirextend.php.This PR widens the annotations to
class-string<SearcherInterface>, which is what the runtime actually checks against (line 50/66/etc. just assign the string into an array) and what the docblocks have always described.AbstractSearcherextends/implementsSearcherInterface, so this is a strictly looser type — no breakage for the default driver, and custom-driver extensions get a phpstan-clean run.Also drops the now-unused
use Flarum\Search\Database\AbstractSearcher;import.Changes
framework/core/src/Extend/SearchDriver.php: 5 docblock annotations widened, 1 import removed, 1 import added.Test plan
AbstractSearchersubclasses still type-check (covariance — narrower is fine).SearcherInterfaceimplementers now type-check (this is the bug being fixed).