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 coalesces #36

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 1 commit into phpstan:master from leongersen:coalesce-rule

Conversation

@leongersen
Copy link
Contributor

@leongersen leongersen commented Dec 2, 2019

In a similar vein to #25, this adds a rule checking that the left side of a coalesce statement is actually valid.

AJenbo reacted with thumbs up emoji
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.

Again, the rule isn't added to any level. Should be level 1.

@leongersen leongersen force-pushed the coalesce-rule branch 2 times, most recently from 5702089 to dbcbfd9 Compare January 21, 2020 12:34
Copy link
Contributor Author

@ondrejmirtes, @BackEndTea I think I've addressed your comments on this PR, let me know if there's anything else you'd like me to improve. Thanks for your reviews so far!

Copy link
Contributor

How does this behave when the left side is a function call?

e.g.

$a = rand(0,1) ?? 10;

I'd expect an error here, as rand cant return null.

Also, how does this behave with 'always null'? e.g.

function (?string $a) : void
{
 if(!is_string($a) {
 $a ?? = 'foo';
 }
}

This always triggers are $a is always null here.

Copy link
Contributor Author

@BackEndTea Good points. I've added support for FuncCall, as well as PropertyFetch and StaticPropertyFetch. I've also added checks for "type is always null" everywhere.

Copy link
Contributor

@BackEndTea BackEndTea left a comment

Choose a reason for hiding this comment

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

👍 Looks pretty good to me, it even found a fault in the phpstan source code

Copy link
Member

Hi, I just merged it as: 3608ded

I made some mostly cosmetic changes to the error messages, and cover more cases. The core logic is really solid and I appreciate it, it couldn't be easy to come up with it! :)

I have more work to be done I will cover myself over this weekend:

  1. Reuse the same logic in existing VariableCertaintyInIssetRule.
  2. Report variables on level 1 and the rest on level 4. Currently all of this is reported on level 1.
  3. Create a new rule that reports the same things for isset() on level 4.

Copy link
Contributor Author

@ondrejmirtes Thanks a bunch for your help on this one!

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

Reviewers

@ondrejmirtes ondrejmirtes Awaiting requested review from ondrejmirtes

1 more reviewer

@BackEndTea BackEndTea BackEndTea approved these changes

Reviewers whose approvals may not affect merge requirements

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

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