unary_operator_spaces.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. ==============================
  2. Rule ``unary_operator_spaces``
  3. ==============================
  4. Unary operators should be placed adjacent to their operands.
  5. Configuration
  6. -------------
  7. ``only_dec_inc``
  8. ~~~~~~~~~~~~~~~~
  9. Limit to increment and decrement operators.
  10. Allowed types: ``bool``
  11. Default value: ``false``
  12. Examples
  13. --------
  14. Example #1
  15. ~~~~~~~~~~
  16. *Default* configuration.
  17. .. code-block:: diff
  18. --- Original
  19. +++ New
  20. <?php
  21. -$sample ++;
  22. --- $sample;
  23. -$sample = ! ! $a;
  24. -$sample = ~ $c;
  25. -function & foo(){}
  26. +$sample++;
  27. +--$sample;
  28. +$sample = !!$a;
  29. +$sample = ~$c;
  30. +function &foo(){}
  31. Example #2
  32. ~~~~~~~~~~
  33. With configuration: ``['only_dec_inc' => false]``.
  34. .. code-block:: diff
  35. --- Original
  36. +++ New
  37. <?php
  38. -function foo($a, ... $b) { return (-- $a) * ($b ++);}
  39. +function foo($a, ...$b) { return (--$a) * ($b++);}
  40. Example #3
  41. ~~~~~~~~~~
  42. With configuration: ``['only_dec_inc' => true]``.
  43. .. code-block:: diff
  44. --- Original
  45. +++ New
  46. <?php
  47. -function foo($a, ... $b) { return (-- $a) * ($b ++);}
  48. +function foo($a, ... $b) { return (--$a) * ($b++);}
  49. Rule sets
  50. ---------
  51. The rule is part of the following rule sets:
  52. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  53. ``['only_dec_inc' => true]``
  54. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  55. ``['only_dec_inc' => true]``
  56. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_ with config:
  57. ``['only_dec_inc' => true]``
  58. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  59. ``['only_dec_inc' => true]``
  60. - `@PSR12 <./../../ruleSets/PSR12.rst>`_ with config:
  61. ``['only_dec_inc' => true]``
  62. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  63. - `@Symfony <./../../ruleSets/Symfony.rst>`_
  64. References
  65. ----------
  66. - Fixer class: `PhpCsFixer\\Fixer\\Operator\\UnaryOperatorSpacesFixer <./../../../src/Fixer/Operator/UnaryOperatorSpacesFixer.php>`_
  67. - Test class: `PhpCsFixer\\Tests\\Fixer\\Operator\\UnaryOperatorSpacesFixerTest <./../../../tests/Fixer/Operator/UnaryOperatorSpacesFixerTest.php>`_
  68. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.