Repository navigation
Reject optional parameters in non-@api code - #6878
Open
ondrejmirtes wants to merge 2 commits into
Open
ondrejmirtes wants to merge 2 commits into
ondrejmirtes wants to merge 2 commits into
Conversation
…functions Existing violations are recorded in build/baseline-optional-parameters.neon. Amp-Thread-ID: https://ampcode.com/threads/T-01a18404-a5f9-74cf-bb1b-815927dc7033
Parameters that became optional in the last 135 days are now required, and every caller passes the former default explicitly. The native mirrors in turbo-ext follow: regenerated arginfo, required ZPP arguments, and native calls into PHP that pass the full argument lists. Kept optional: parameters after an older optional parameter, the TemplateTypeTrait::isValidVariance() $strict required by the interface, CachedParser's $cachedSourceBytesMax (constructed by Larastan), OpenSslCipherMethodsProvider's $supportedCipherMethods (DI autowiring), and the trailing ExpressionResult constructor parameters that the generated ExpressionResultFactory does not pass. Amp-Thread-ID: https://ampcode.com/threads/T-01a18404-a5f9-74cf-bb1b-815927dc7033
ondrejmirtes
force-pushed
the
no-optional-parameters
branch
from
October 28, 2026 22:05
6a188ee to
7e47baa
Compare
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.
Adds a build rule (
build/PHPStan/Build/NoOptionalParameterRule.php) that reports optional parameters in methods and functions that aren't@api. Constructors count as non-@apieven in@apiclasses unless the constructor has its own@apitag. Closures and arrow functions aren't checked. Parameters that are optional in an ancestor are skipped. Existing violations are recorded inbuild/baseline-optional-parameters.neon.The second commit makes the 272 optional parameters added in the last 135 days (since
e300c7eae) required, and every caller now passes the former default explicitly. The turbo-ext native mirrors follow: regenerated arginfo, required ZPP arguments, and native calls into PHP that pass full argument lists. The baseline goes from 467 to 195 entries.These stay optional on purpose:
TemplateTypeTrait::isValidVariance()$strict, because the interface requires itCachedParser::__construct()$cachedSourceBytesMax, because Larastan constructs the classOpenSslCipherMethodsProvider::__construct()$supportedCipherMethods, because DI autowiring needs itExpressionResult::__construct()parameters, which the generatedExpressionResultFactorydoesn't passVerified locally:
make testspasses with and without the turbo extension.smoke.php, the differential tests,walk-trace.php,signature-parityandside-by-side.phpall pass.bin/phpstan analyse -c build/phpstan.neonis clean, and its raw output is identical with and without turbo.