assign_null_coalescing_to_coalesce_equal.rst 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. =================================================
  2. Rule ``assign_null_coalescing_to_coalesce_equal``
  3. =================================================
  4. Use the null coalescing assignment operator ``??=`` where possible.
  5. Examples
  6. --------
  7. Example #1
  8. ~~~~~~~~~~
  9. .. code-block:: diff
  10. --- Original
  11. +++ New
  12. <?php
  13. -$foo = $foo ?? 1;
  14. +$foo ??= 1;
  15. Rule sets
  16. ---------
  17. The rule is part of the following rule sets:
  18. - `@PHP74Migration <./../../ruleSets/PHP74Migration.rst>`_
  19. - `@PHP80Migration <./../../ruleSets/PHP80Migration.rst>`_
  20. - `@PHP81Migration <./../../ruleSets/PHP81Migration.rst>`_
  21. - `@PHP82Migration <./../../ruleSets/PHP82Migration.rst>`_
  22. - `@PHP83Migration <./../../ruleSets/PHP83Migration.rst>`_
  23. - `@PHP84Migration <./../../ruleSets/PHP84Migration.rst>`_
  24. References
  25. ----------
  26. - Fixer class: `PhpCsFixer\\Fixer\\Operator\\AssignNullCoalescingToCoalesceEqualFixer <./../../../src/Fixer/Operator/AssignNullCoalescingToCoalesceEqualFixer.php>`_
  27. - Test class: `PhpCsFixer\\Tests\\Fixer\\Operator\\AssignNullCoalescingToCoalesceEqualFixerTest <./../../../tests/Fixer/Operator/AssignNullCoalescingToCoalesceEqualFixerTest.php>`_
  28. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.