new_with_braces.rst 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. ========================
  2. Rule ``new_with_braces``
  3. ========================
  4. All instances created with ``new`` keyword must (not) be followed by braces.
  5. Warning
  6. -------
  7. This rule is deprecated and will be removed in the next major version
  8. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  9. You should use ``new_with_parentheses`` instead.
  10. Configuration
  11. -------------
  12. ``anonymous_class``
  13. ~~~~~~~~~~~~~~~~~~~
  14. Whether anonymous classes should be followed by parentheses.
  15. Allowed types: ``bool``
  16. Default value: ``true``
  17. ``named_class``
  18. ~~~~~~~~~~~~~~~
  19. Whether named classes should be followed by parentheses.
  20. Allowed types: ``bool``
  21. Default value: ``true``
  22. Examples
  23. --------
  24. Example #1
  25. ~~~~~~~~~~
  26. *Default* configuration.
  27. .. code-block:: diff
  28. --- Original
  29. +++ New
  30. <?php
  31. -$x = new X;
  32. -$y = new class {};
  33. +$x = new X();
  34. +$y = new class() {};
  35. Example #2
  36. ~~~~~~~~~~
  37. With configuration: ``['anonymous_class' => false]``.
  38. .. code-block:: diff
  39. --- Original
  40. +++ New
  41. <?php
  42. -$y = new class() {};
  43. +$y = new class {};
  44. Example #3
  45. ~~~~~~~~~~
  46. With configuration: ``['named_class' => false]``.
  47. .. code-block:: diff
  48. --- Original
  49. +++ New
  50. <?php
  51. -$x = new X();
  52. +$x = new X;
  53. References
  54. ----------
  55. - Fixer class: `PhpCsFixer\\Fixer\\Operator\\NewWithBracesFixer <./../../../src/Fixer/Operator/NewWithBracesFixer.php>`_
  56. - Test class: `PhpCsFixer\\Tests\\Fixer\\Operator\\NewWithBracesFixerTest <./../../../tests/Fixer/Operator/NewWithBracesFixerTest.php>`_
  57. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.