new_with_braces.rst 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. ========================
  2. Rule ``new_with_braces``
  3. ========================
  4. All instances created with ``new`` keyword must (not) be followed by braces.
  5. Configuration
  6. -------------
  7. ``named_class``
  8. ~~~~~~~~~~~~~~~
  9. Whether named classes should be followed by parentheses.
  10. Allowed types: ``bool``
  11. Default value: ``true``
  12. ``anonymous_class``
  13. ~~~~~~~~~~~~~~~~~~~
  14. Whether anonymous classes should be followed by parentheses.
  15. Allowed types: ``bool``
  16. Default value: ``true``
  17. Examples
  18. --------
  19. Example #1
  20. ~~~~~~~~~~
  21. *Default* configuration.
  22. .. code-block:: diff
  23. --- Original
  24. +++ New
  25. <?php
  26. -$x = new X;
  27. -$y = new class {};
  28. +$x = new X();
  29. +$y = new class() {};
  30. Example #2
  31. ~~~~~~~~~~
  32. With configuration: ``['anonymous_class' => false]``.
  33. .. code-block:: diff
  34. --- Original
  35. +++ New
  36. <?php
  37. -$y = new class() {};
  38. +$y = new class {};
  39. Example #3
  40. ~~~~~~~~~~
  41. With configuration: ``['named_class' => false]``.
  42. .. code-block:: diff
  43. --- Original
  44. +++ New
  45. <?php
  46. -$x = new X();
  47. +$x = new X;
  48. Rule sets
  49. ---------
  50. The rule is part of the following rule sets:
  51. - `@PER <./../../ruleSets/PER.rst>`_
  52. - `@PER-CS1.0 <./../../ruleSets/PER-CS1.0.rst>`_
  53. - `@PER-CS2.0 <./../../ruleSets/PER-CS2.0.rst>`_
  54. - `@PSR12 <./../../ruleSets/PSR12.rst>`_
  55. - `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_
  56. - `@Symfony <./../../ruleSets/Symfony.rst>`_