-
Notifications
You must be signed in to change notification settings - Fork 464
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
get_defined_vars() return type contains know variables #3624
base: 2.0.x
Are you sure you want to change the base?
get_defined_vars() return type contains know variables #3624
Conversation
0bd65db
to
5eea5cb
Compare
5eea5cb
to
8b88081
Compare
8b88081
to
e9ee834
Compare
e9ee834
to
4b62aaa
Compare
assertType('array{param: int, local: \'foo\'}', get_defined_vars()); | ||
assertType('array{\'param\', \'local\'}', array_keys(get_defined_vars())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When escaping single quotes, I always (when possible) switch to double quoted string to prevent that.
- easier on the eyes
- easier to copy and paste
- easier to search for the unescaped string in the codebase
assertType('array{param: int, local: \'foo\'}', get_defined_vars()); | |
assertType('array{\'param\', \'local\'}', array_keys(get_defined_vars())); | |
assertType("array{param: int, local: 'foo'}", get_defined_vars()); | |
assertType("array{'param', 'local'}", array_keys(get_defined_vars())); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do that too but I checked how it is done in other parts of PHPStan and found out that escaping seems to be standard here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I also often do the double quote. but I think in general it's very inconsistent :D not sure if such thing exists, but a coding standard rule might be good for this 😊
UPDATE: on the other hand - in those tests files it wouldn't be enforced anyway I guess..
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(the unrelated lint build errors will be fixed after rebase; please remove the merge commit) |
6eed675
to
1f7ebbe
Compare
@staabm Removed merge commit. Should be ready to merge - two failing checks are unrelated. |
the "Lint / Coding Standard (pull_request) " fail is related to the PR. just run |
Co-Authored-By: Ruud Kamphuis <[email protected]>
1f7ebbe
to
ddba1cd
Compare
CS fixed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also it might be useful to still do it on 1.12.x instead?
$maybeIndexes = range(count($definedVariables), count($definedVariables) + count($maybeVariables)); | ||
} | ||
|
||
return new ConstantArrayType($keys, $values, [0], $maybeIndexes); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ConstantArrayTypeBuilder instead.
Solves phpstan/phpstan#11948
Solves phpstan/phpstan#11740
Credits to @ruudk