-
Notifications
You must be signed in to change notification settings - Fork 473
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
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 |
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.
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.
Rewritten
How to do it properly? Can I just change target branch? |
ddba1cd
to
2110e67
Compare
try locally running a rebase against 1.12.x. if it works cleanly just force push it and change the target branch of the PR |
2110e67
to
7a7c05c
Compare
Co-Authored-By: Ruud Kamphuis <[email protected]>
7a7c05c
to
a503e9b
Compare
Well for some reason (maby I messed up) I was a bit more complicated but it seems it is ok now. I will see if check find any issue and fix it eventualy. |
Ok it should be ready for merge into 1.12.x |
Perfect, thank you! |
Solves phpstan/phpstan#11948
Solves phpstan/phpstan#11740
Credits to @ruudk