new_with_parentheses.rst 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. =============================
  2. Rule ``new_with_parentheses``
  3. =============================
  4. All instances created with ``new`` keyword must (not) be followed by
  5. parentheses.
  6. Configuration
  7. -------------
  8. ``anonymous_class``
  9. ~~~~~~~~~~~~~~~~~~~
  10. Whether anonymous classes should be followed by parentheses.
  11. Allowed types: ``bool``
  12. Default value: ``true``
  13. ``named_class``
  14. ~~~~~~~~~~~~~~~
  15. Whether named classes should be followed by parentheses.
  16. Allowed types: ``bool``
  17. Default value: ``true``
  18. Examples
  19. --------
  20. Example #1
  21. ~~~~~~~~~~
  22. *Default* configuration.
  23. .. code-block:: diff
  24. --- Original
  25. +++ New
  26. <?php
  27. -$x = new X;
  28. -$y = new class {};
  29. +$x = new X();
  30. +$y = new class() {};
  31. Example #2
  32. ~~~~~~~~~~
  33. With configuration: ``['anonymous_class' => false]``.
  34. .. code-block:: diff
  35. --- Original
  36. +++ New
  37. <?php
  38. -$y = new class() {};
  39. +$y = new class {};
  40. Example #3
  41. ~~~~~~~~~~
  42. With configuration: ``['named_class' => false]``.
  43. .. code-block:: diff
  44. --- Original
  45. +++ New
  46. <?php
  47. -$x = new X();
  48. +$x = new X;
  49. Rule sets
  50. ---------
  51. The rule is part of the following rule sets:
  52. - `@PER <./../../ruleSets/PER.rst>`_ with config:
  53. ``['anonymous_class' => false]``
  54. - `@PER-CS <./../../ruleSets/PER-CS.rst>`_ with config:
  55. ``['anonymous_class' => false]``
  56. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  57. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_ with config:
  58. ``['anonymous_class' => false]``
  59. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  60. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ with config:
  61. ``['anonymous_class' => false]``
  62. - `@Symfony <./../../ruleSets/Symfony.rst>`_ with config:
  63. ``['anonymous_class' => false]``
  64. References
  65. ----------
  66. - Fixer class: `PhpCsFixer\\Fixer\\Operator\\NewWithParenthesesFixer <./../../../src/Fixer/Operator/NewWithParenthesesFixer.php>`_
  67. - Test class: `PhpCsFixer\\Tests\\Fixer\\Operator\\NewWithParenthesesFixerTest <./../../../tests/Fixer/Operator/NewWithParenthesesFixerTest.php>`_
  68. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.