Skip to content

min() and max() do not return false on php8 #2161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2023

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Jan 3, 2023

refs phpstan/phpstan#7239 (comment)

bottom line: in php8 min() and max() do no longer return false
https://www.php.net/manual/en/function.max.php

@@ -133,7 +133,13 @@ public function dataFileAsserts(): iterable

yield from $this->gatherAssertTypes(__DIR__ . '/../Reflection/data/staticReturnType.php');

yield from $this->gatherAssertTypes(__DIR__ . '/data/minmax-arrays.php');
Copy link
Contributor Author

@staabm staabm Jan 3, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

turned the existing assertions into a php<8 case (minmax-arrays.php)

copied the existing assertion files and adjusted them for php8+ (minmax-php8.php) - meaning turn false into *ERROR*

extracted the assertions which are php version independent into minmax.php

@staabm
Copy link
Contributor Author

staabm commented Jan 3, 2023

the build error is legit: we no longer trigger the false-positive

Error: Ignored error pattern #^Parameter \#2 \$length of function str_pad expects int, int\<0, max\>\|false given\.$# in path /home/runner/work/phpstan-src/phpstan-src/e2e/integration/repo/src/TextUI/DefaultResultPrinter.php was not matched in reported errors.
 ------ ----------------------------------------------------------------------- 
  Line   src/TextUI/DefaultResultPrinter.php                                    
 ------ ----------------------------------------------------------------------- 
         Ignored error pattern #^Parameter \#2 \$length of function str_pad     
         expects int, int<0, max>\|false given\.$# in path                      
         /home/runner/work/phpstan-src/phpstan-src/e2e/integration/repo/src/Te  
         xtUI/DefaultResultPrinter.php was not matched in reported errors.      
 ------ ----------------------------------------------------------------------- 

in https://github.com/sebastianbergmann/phpunit/blob/93d4bf4c37aec6384bb9e5d390d9049a463a7256/src/TextUI/DefaultResultPrinter.php#L541-L547

@staabm staabm marked this pull request as ready for review January 3, 2023 16:10
@phpstan-bot
Copy link
Collaborator

This pull request has been marked as ready for review.

@ondrejmirtes ondrejmirtes merged commit 02753c6 into phpstan:1.9.x Jan 4, 2023
@ondrejmirtes
Copy link
Member

Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants