Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add rule checking arguments to unset (#2605) #25

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

Closed
leongersen wants to merge 5 commits into phpstan:master from leongersen:unset-rule

Conversation

@leongersen
Copy link
Contributor

@leongersen leongersen commented Nov 26, 2019

Adds a rule for checking the arguments to unset. Fixes #2605.

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.

This is really nice :) Also make sure to run vendor/bin/phing locally before submitting a PR next time, thanks.

I found a few points. Also, I'm not sure if we want to report "possibly undefined variable" - it's perfectly fine to unset something that might (but doesn't have to) exist.

Copy link
Contributor Author

I've removed the "possibly undefined variable" check and fixed your other remarks, thanks for reviewing.

Copy link
Member

Hi, I spent a little bit more time to bring the rule over the finish line. Here are the changes from your PR to mine: https://gist.github.com/ondrejmirtes/1f8b2512798df18baa579a39453946f9

  1. You forgot to add the rule to a level. It wouldn't run at all.
  2. Changed namespace.
  3. I moved the if about iterable key type to IterableType.
  4. I changed the return type of canBeUnset to ?RuleError.
  5. I added recursion so that this case is reported too: unset($notSetVariable['a']);

Copy link
Member

Thanks!

Copy link
Member

Please feel free to do a similar thing for ?? operator - PhpParser\Node\Expr\BinaryOp\Coalesce node.

Also, similarly, this isn't detected: https://phpstan.org/r/b56820c1-0e96-45b5-9f98-58dc0fe96d58

We only have VariableCertaintyInIssetRule.

Copy link
Contributor Author

Thanks for finishing this up! I just realized I kept missing the Travis warnings when running the build locally (on windows), because it stops somewhere along the way. I'll try to figure out why that is.

@leongersen leongersen deleted the unset-rule branch November 28, 2019 07:27
Copy link
Member

ondrejmirtes commented Nov 28, 2019 via email

Yeah, Windows build isn’t in a great shape but at least it finishes on Travis.
On 2019年11月28日 at 08:27, Leon Gersen ***@***.***> wrote: Thanks for finishing this up! I just realized I kept missing the Travis warnings when running the build locally (on windows), because it stops somewhere along the way. I'll try to figure out why that is. — You are receiving this because you modified the open/close state. Reply to this email directly, view it on GitHub <#25?email_source=notifications&email_token=AAAZTOATKIVNYAJOPJMAJVTQV5XGFA5CNFSM4JRVWDFKYY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEFLWASQ#issuecomment-559374410>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AAAZTOAEJ2YAJZHYIALXCELQV5XGFANCNFSM4JRVWDFA> .
-- Ondřej Mirtes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ondrejmirtes ondrejmirtes ondrejmirtes requested changes

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Missing type check within unset

AltStyle によって変換されたページ (->オリジナル) /