Repository navigation
Cast SymfonyOutput::isDecorated() to bool - #7048
Open
Gabrieljr42 wants to merge 4 commits into
Open
Gabrieljr42 wants to merge 4 commits into
Gabrieljr42 wants to merge 4 commits into
Conversation
Symfony 5.4 leaves isDecorated() untyped, so the value can be the int 0 or 1 from preg_match. The wrapper return type is bool.
Contributor
|
Thank you for the PR. I did not merge yet because I am thinking about whether there is a more general fix we can/should take.. |
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 phpstan/phpstan#15696
Symfony 5.4 declares
Output::isDecorated()with no native return type.StreamOutput::hasColorSupport()returns the int frompreg_match.SymfonyOutput::isDecorated()lives in a file withstrict_typesand aboolreturn, so that int throwsTypeError.Inside the phpstan phar, Turbo's
trustTypesUnderdrops argument and return checks for the whole archive, includingvendor/. The int then reaches a user formatter that still requiresbool. A cast in this wrapper is user code, and that pass does not remove it.isVerbose,isVeryVerbose, andisDebugalready return bool from Symfony. This change does not touch them, and it does not touchturbo-ext/.Tests
tests/PHPStan/Command/Symfony/SymfonyOutputTest.phpfeeds the wrapper1,0,true, andfalsethrough aNullOutputsubclass whoseisDecorated(): mixedreturns the raw value. The double does not callparent::__construct(), becauseNullOutputdefines no constructor of its own.Before the cast, PHPUnit 11.5.57 on PHP 8.3.33 reported
TypeErrorfor1and for0(Return value must be of type bool, int returnedatSymfonyOutput.php:59). The two bool cases passed (2 assertions).After the cast, the same class was OK: 4 tests, 4 assertions.
parallel-lintreported no syntax error on the two files.The phar repro from the issue was not run here. The turbo extension is not loaded, and PHPUnit does not enter
trustOwnTypesIfSuitable.make tests,make phpstan, andmake cswere not run.