new_with_braces.rst 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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. @PSR12
  52. Using the `@PSR12 <./../../ruleSets/PSR12.rst>`_ rule set will enable the ``new_with_braces`` rule with the default config.
  53. @PhpCsFixer
  54. Using the `@PhpCsFixer <./../../ruleSets/PhpCsFixer.rst>`_ rule set will enable the ``new_with_braces`` rule with the default config.
  55. @Symfony
  56. Using the `@Symfony <./../../ruleSets/Symfony.rst>`_ rule set will enable the ``new_with_braces`` rule with the default config.