Skip to content

Conversation

rodrigoprimo
Copy link
Contributor

Description

This PR changes the Generic.ControlStructures.DisallowYodaConditions sniff so that the null coalescing operator (??) does not trigger it.

Suggested changelog entry

Generic.ControlStructures.DisallowYodaConditions: null coalescing operator (??) should not trigger the sniff

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
    • This change is only breaking for integrators, not for external standards or end-users.
  • Documentation improvement

PR checklist

  • I have checked there is no other PR open for the same change.
  • I have read the Contribution Guidelines.
  • I grant the project the right to include and distribute the code under the BSD-3-Clause license (and I have the right to grant these rights).
  • I have added tests to cover my changes.
  • I have verified that the code complies with the projects coding standards.
  • [Required for new sniffs] I have added XML documentation for the sniff.
This commit changes the DisallowYodaConditions sniff so that the null coalescing operator (`??`) does not trigger it.
Copy link
Member

@jrfnl jrfnl left a comment

Choose a reason for hiding this comment

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

Good call @rodrigoprimo. LGTM.

For the record: it is unlikely that the null coalesce operator being listened to by this sniff would ever have caused an issue in real life code as the code sample - as per the test file - which would trigger the sniff, is not a realistic code sample.

1 ?? $var desugars to isset(1) ? 1 : $var and doing an isset() on a hard-coded value doesn't make any sense.

@jrfnl jrfnl added this to the 3.9.2 milestone Apr 22, 2024
@jrfnl jrfnl merged commit 5f38ce0 into PHPCSStandards:master Apr 22, 2024
@rodrigoprimo rodrigoprimo deleted the disallow-yoda-condition-drop-null-coalescing-operator branch April 24, 2024 11:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment