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

get_defined_vars() return type contains know variables #3624

Merged
merged 1 commit into from
Nov 29, 2024

Conversation

MartinMystikJonas
Copy link
Contributor

@MartinMystikJonas MartinMystikJonas commented Nov 11, 2024

@MartinMystikJonas MartinMystikJonas force-pushed the get-defined-vars branch 4 times, most recently from 0bd65db to 5eea5cb Compare November 11, 2024 17:07
Comment on lines +13 to +14
assertType('array{param: int, local: \'foo\'}', get_defined_vars());
assertType('array{\'param\', \'local\'}', array_keys(get_defined_vars()));
Copy link
Contributor

@ruudk ruudk Nov 13, 2024

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
Suggested change
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()));

Copy link
Contributor Author

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.

Copy link
Contributor

@herndlm herndlm Nov 13, 2024

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..

Copy link
Contributor

Choose a reason for hiding this comment

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

@staabm
Copy link
Contributor

staabm commented Nov 13, 2024

(the unrelated lint build errors will be fixed after rebase; please remove the merge commit)

@MartinMystikJonas MartinMystikJonas force-pushed the get-defined-vars branch 2 times, most recently from 6eed675 to 1f7ebbe Compare November 13, 2024 08:56
@MartinMystikJonas
Copy link
Contributor Author

@staabm Removed merge commit. Should be ready to merge - two failing checks are unrelated.

@staabm
Copy link
Contributor

staabm commented Nov 13, 2024

the "Lint / Coding Standard (pull_request) " fail is related to the PR. just run make cs-fix locally and commit the fix

@MartinMystikJonas
Copy link
Contributor Author

CS fixed

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.

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);
Copy link
Member

Choose a reason for hiding this comment

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

Use ConstantArrayTypeBuilder instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Rewritten

@MartinMystikJonas
Copy link
Contributor Author

Also it might be useful to still do it on 1.12.x instead?

How to do it properly? Can I just change target branch?

@staabm
Copy link
Contributor

staabm commented Nov 29, 2024

How to do it properly? Can I just change target branch?

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
(make sure your 1.12.x local branch is up 2 date before)

@MartinMystikJonas MartinMystikJonas changed the base branch from 0.12.x to 2.0.x November 29, 2024 13:55
@MartinMystikJonas MartinMystikJonas changed the base branch from 2.0.x to 1.12.x November 29, 2024 13:55
@MartinMystikJonas
Copy link
Contributor Author

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.

@MartinMystikJonas
Copy link
Contributor Author

Ok it should be ready for merge into 1.12.x

@ondrejmirtes ondrejmirtes merged commit 8d67d7a into phpstan:1.12.x Nov 29, 2024
452 checks passed
@ondrejmirtes
Copy link
Member

Perfect, 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.

5 participants