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

Open
wants to merge 1 commit into
base: 2.0.x
Choose a base branch
from

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.

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