Skip to content
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

declare assert-if-true for filesystem functions #1993

Draft
wants to merge 2 commits into
base: 1.9.x
Choose a base branch
from

Conversation

staabm
Copy link
Contributor

@staabm staabm commented Nov 13, 2022

Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

Two problems here:

  1. chdir($dir) ? 'foo' : 'bar' - in the else branch $dir will be considered ''
  2. If you pass non-empty-string to chdir(...), you'll get "always true" error.

Both can be solved with =non-empty-string. See: phpstan/phpstan#8348 + phpstan/phpstan#8351

@clxmstaab clxmstaab force-pushed the file-fn branch 2 times, most recently from 49564b7 to 766c8d9 Compare November 14, 2022 14:12
Copy link
Member

@ondrejmirtes ondrejmirtes left a comment

Choose a reason for hiding this comment

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

To make sure that = actually fixes these problems, you should have tested the else condition types and also put a test about this in ImpossibleCheckTypeFunctionCallRule (before adding the = everywhere). Please verify this was originally a problem and that it's fixed after the change. I'm sure you can find the previous version in your reflog :) It's e117fce or 49564b7.

@staabm
Copy link
Contributor Author

staabm commented Nov 20, 2022

good point.

2) PHPStan\Rules\Comparison\ImpossibleCheckTypeFunctionCallRuleTest::testBug6788
Failed asserting that two strings are identical.
--- Expected
+++ Actual
@@ @@
-'
+'13: Call to function chdir() with non-empty-string will always evaluate to true.
+    💡 Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.
+15: Call to function chdir() with non-falsy-string will always evaluate to true.
+    💡 Because the type is coming from a PHPDoc, you can turn off this check by setting <fg=cyan>treatPhpDocTypesAsCertain: false</> in your <fg=cyan>%configurationFile%</>.
 '

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