logical_operators.rst 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. ==========================
  2. Rule ``logical_operators``
  3. ==========================
  4. Use ``&&`` and ``||`` logical operators instead of ``and`` and ``or``.
  5. Warning
  6. -------
  7. Using this rule is risky
  8. ~~~~~~~~~~~~~~~~~~~~~~~~
  9. Risky, because you must double-check if using and/or with lower precedence was
  10. intentional.
  11. Examples
  12. --------
  13. Example #1
  14. ~~~~~~~~~~
  15. .. code-block:: diff
  16. --- Original
  17. +++ New
  18. <?php
  19. -if ($a == "foo" and ($b == "bar" or $c == "baz")) {
  20. +if ($a == "foo" && ($b == "bar" || $c == "baz")) {
  21. }
  22. Rule sets
  23. ---------
  24. The rule is part of the following rule sets:
  25. - `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_
  26. - `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_
  27. References
  28. ----------
  29. - Fixer class: `PhpCsFixer\\Fixer\\Operator\\LogicalOperatorsFixer <./../../../src/Fixer/Operator/LogicalOperatorsFixer.php>`_
  30. - Test class: `PhpCsFixer\\Tests\\Fixer\\Operator\\LogicalOperatorsFixerTest <./../../../tests/Fixer/Operator/LogicalOperatorsFixerTest.php>`_
  31. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.