logical_operators.rst 721 B

123456789101112131415161718192021222324252627282930313233343536373839
  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>`_