logical_operators.rst 877 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. ==========================
  2. Rule ``logical_operators``
  3. ==========================
  4. Use ``&&`` and ``||`` logical operators instead of ``and`` and ``or``.
  5. .. warning:: Using this rule is risky.
  6. Risky, because you must double-check if using and/or with lower precedence
  7. was intentional.
  8. Examples
  9. --------
  10. Example #1
  11. ~~~~~~~~~~
  12. .. code-block:: diff
  13. --- Original
  14. +++ New
  15. @@ -1,4 +1,4 @@
  16. <?php
  17. -if ($a == "foo" and ($b == "bar" or $c == "baz")) {
  18. +if ($a == "foo" && ($b == "bar" || $c == "baz")) {
  19. }
  20. Rule sets
  21. ---------
  22. The rule is part of the following rule sets:
  23. @PhpCsFixer:risky
  24. Using the `@PhpCsFixer:risky <./../../ruleSets/PhpCsFixerRisky.rst>`_ rule set will enable the ``logical_operators`` rule.
  25. @Symfony:risky
  26. Using the `@Symfony:risky <./../../ruleSets/SymfonyRisky.rst>`_ rule set will enable the ``logical_operators`` rule.