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

Squiz.Objects.ObjectInstantiation: null coalesce operators are not recognized as assignment #3333

Closed
KacerCZ opened this issue May 5, 2021 · 3 comments · Fixed by #3348
Closed
Milestone

Comments

@KacerCZ
Copy link

KacerCZ commented May 5, 2021

Describe the bug
Sniff Squiz.Objects.ObjectInstantiation does not recognizes ?? and ??= operators as assignment.

Code sample

$time1 = new \DateTime();
$time2 ??= new \DateTime();
$time3 = $time1 ?? new \DateTime();

Custom ruleset

<?xml version="1.0"?>
<ruleset name="My Custom Standard">
  <rule ref="Squiz.Objects.ObjectInstantiation" />
</ruleset>

To reproduce
Steps to reproduce the behavior:

  1. Create a file called test.php with the code sample above...
  2. Run phpcs test.php ...
  3. See error message displayed
----------------------------------------------------------------------
FOUND 2 ERRORS AFFECTING 2 LINES
----------------------------------------------------------------------
 4 | ERROR | New objects must be assigned to a variable
 5 | ERROR | New objects must be assigned to a variable

Expected behavior
Error Squiz.Objects.ObjectInstantiation.NotAssigned is not reported for any of the lines.

Versions (please complete the following information):

  • OS: Ubuntu Linux 20.10
  • PHP: 8.0.5
  • PHPCS: 3.6.0
  • Standard: custom
@jrfnl
Copy link
Contributor

jrfnl commented May 11, 2021

Thanks for reporting this @KacerCZ . PR #3348 should fix this. Testing appreciated.

@gsherwood gsherwood added this to the 3.6.1 milestone May 11, 2021
@KacerCZ
Copy link
Author

KacerCZ commented May 14, 2021

@jrfnl Today I tested your fix and it works. Thank you.

@jrfnl
Copy link
Contributor

jrfnl commented May 14, 2021

@KacerCZ Thanks for testing & confirming the fix.

@gsherwood gsherwood changed the title Squiz.Objects.ObjectInstantiation: null coalesce operators are nor recognized as assignment Squiz.Objects.ObjectInstantiation: null coalesce operators are not recognized as assignment Aug 12, 2021
gsherwood added a commit that referenced this issue Aug 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants