Repository navigation
Load the ParameterBag stub until symfony/http-foundation 8.2 - #519
Open
ChrisAbner wants to merge 1 commit into
Open
ChrisAbner wants to merge 1 commit into
ChrisAbner wants to merge 1 commit into
Conversation
ParameterBag::keys() and all() return the parameters' own keys, so a numeric parameter name comes back as an int on every released version, while Symfony 7.4+ documents keys() as list<string> and all() as array<string, mixed>. The stub was only loaded below 7.4, so a correct is_string() guard over those keys was reported as always true. Symfony 8.2 casts the keys to strings and documents all() as array<mixed> (symfony/symfony#66127), so the stub is now loaded below 8.2, and it covers all() as well. The InputBag and Request stubs keep their 7.4 gate.
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.
Closes #510
ParameterBag::keys()andall()return the parameters with their own keys, and PHP turns numeric array keys into integers, so?0=xgives the key0as aninton every releasedsymfony/http-foundationversion. Symfony 7.4+ documentskeys()aslist<string>,all()asarray<string, mixed>and the iterator as<string, mixed>, andStubFilesExtensionLoaderstopped loadingParameterBag.stubfrom 7.4 on. So a correctis_string($key)guard over those keys is reported as always true, and removing it lets anintreach astringparameter. This PR loadsParameterBag.stubbelow 8.2.0.0, and the stub now coversall()too (array<mixed>).Why 8.2: symfony/symfony#66127, merged into 8.2, makes
keys()and the iterator cast the keys tostringand documentsall()asarray<mixed>, so from 8.2 on the upstream types match what the code returns and should win, as #481 intends. 8.2 is not released yet (the latest is 8.1.10). Raising the existing< 7.4.0.0block would also bring back theInputBagandRequeststubs, soParameterBag.stubgets its own condition and the other two keep theirs. The issue suggests< 8.3.0.0, but 8.2 is where the runtime behaviour changes. Theall()entry uses the same type as 8.2 upstream.Verification. An external project (
phpstan/phpstan2.3.4, this extension through a path repository, level 8), with the issue's snippet, the same guard overarray_keys($bag->all()), the key type offoreach ($request->query as $key => $value), and the actual keys ofRequest::create('/search?0=x&78=y&q=z')->query->keys():symfony/http-foundationkeys()before → after$bag->all()before → afteris_string($key)reported (keys(),all()) before → after0,78areintlist<int|string>→ samearray→array<mixed>intlist<string>→list<int|string>array<string, mixed>→array<mixed>intlist<string>→list<int|string>array<string, mixed>→array<mixed>intlist<string>→list<int|string>array<string, mixed>→array<mixed>'0','78'arestringlist<string>→ samearray<mixed>→ sameOn 7.4–8.1 the
foreachkey goes fromstringtoint|string; on 8.2 it staysstring.InputBag::get(),$request->request->get('a', 'x')and$bag->all('foo')give the same types before and after on every version.tests/Type/Symfony/data/parameter_bag.phpasserts the types ofkeys(),all(),all('foo')and theforeachkey. With the suite'ssymfony/http-foundation6.4 the stub was already loaded, so only theall()assertions fail without this change; they pass with it, on the highest dependencies (6.4.49) and with--prefer-lowest(5.4.54, PHPStan 2.3.0).phpunit(448 tests),parallel-lint, PHPStan level 8 and phpcs (build-cs) pass.Not covered: the suite never installs
symfony/http-foundation7.4 or later (dev constraint^5.4 || ^6.1), so no test reaches the new version condition itself; once #483 widens that constraint,parameter_bag.phpcovers it as is.InputBag::all()without arguments still hasstringkeys on every Symfony version, becauseInputBagDynamicReturnTypeExtensionbuilds that type itself; that is older than the 7.4 gate and changing it would affect all versions, so I left it out.