Skip to content

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

@KacerCZ

Description

@KacerCZ

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions