doctrine_annotation_spaces.rst 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  1. ===================================
  2. Rule ``doctrine_annotation_spaces``
  3. ===================================
  4. Fixes spaces in Doctrine annotations.
  5. Description
  6. -----------
  7. There must not be any space around parentheses; commas must be preceded by no
  8. space and followed by one space; there must be no space around named arguments
  9. assignment operator; there must be one space around array assignment operator.
  10. Configuration
  11. -------------
  12. ``after_argument_assignments``
  13. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  14. Whether to add, remove or ignore spaces after argument assignment operator.
  15. Allowed types: ``null`` and ``bool``
  16. Default value: ``false``
  17. ``after_array_assignments_colon``
  18. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  19. Whether to add, remove or ignore spaces after array assignment ``:`` operator.
  20. Allowed types: ``null`` and ``bool``
  21. Default value: ``true``
  22. ``after_array_assignments_equals``
  23. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  24. Whether to add, remove or ignore spaces after array assignment ``=`` operator.
  25. Allowed types: ``null`` and ``bool``
  26. Default value: ``true``
  27. ``around_commas``
  28. ~~~~~~~~~~~~~~~~~
  29. Whether to fix spaces around commas.
  30. Allowed types: ``bool``
  31. Default value: ``true``
  32. ``around_parentheses``
  33. ~~~~~~~~~~~~~~~~~~~~~~
  34. Whether to fix spaces around parentheses.
  35. Allowed types: ``bool``
  36. Default value: ``true``
  37. ``before_argument_assignments``
  38. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  39. Whether to add, remove or ignore spaces before argument assignment operator.
  40. Allowed types: ``null`` and ``bool``
  41. Default value: ``false``
  42. ``before_array_assignments_colon``
  43. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  44. Whether to add, remove or ignore spaces before array ``:`` assignment operator.
  45. Allowed types: ``null`` and ``bool``
  46. Default value: ``true``
  47. ``before_array_assignments_equals``
  48. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  49. Whether to add, remove or ignore spaces before array ``=`` assignment operator.
  50. Allowed types: ``null`` and ``bool``
  51. Default value: ``true``
  52. ``ignored_tags``
  53. ~~~~~~~~~~~~~~~~
  54. List of tags that must not be treated as Doctrine Annotations.
  55. Allowed types: ``list<string>``
  56. Default value: ``['abstract', 'access', 'code', 'deprec', 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc', 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar', 'staticVar', 'throw', 'api', 'author', 'category', 'copyright', 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal', 'license', 'link', 'method', 'package', 'param', 'property', 'property-read', 'property-write', 'return', 'see', 'since', 'source', 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var', 'version', 'after', 'afterClass', 'backupGlobals', 'backupStaticAttributes', 'before', 'beforeClass', 'codeCoverageIgnore', 'codeCoverageIgnoreStart', 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass', 'coversNothing', 'dataProvider', 'depends', 'expectedException', 'expectedExceptionCode', 'expectedExceptionMessage', 'expectedExceptionMessageRegExp', 'group', 'large', 'medium', 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses', 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses', 'SuppressWarnings', 'noinspection', 'package_version', 'enduml', 'startuml', 'psalm', 'phpstan', 'template', 'fix', 'FIXME', 'fixme', 'override']``
  57. Examples
  58. --------
  59. Example #1
  60. ~~~~~~~~~~
  61. *Default* configuration.
  62. .. code-block:: diff
  63. --- Original
  64. +++ New
  65. <?php
  66. /**
  67. - * @Foo ( )
  68. + * @Foo()
  69. */
  70. class Bar {}
  71. /**
  72. - * @Foo("bar" ,"baz")
  73. + * @Foo("bar", "baz")
  74. */
  75. class Bar2 {}
  76. /**
  77. - * @Foo(foo = "foo", bar = {"foo":"foo", "bar"="bar"})
  78. + * @Foo(foo="foo", bar={"foo" : "foo", "bar" = "bar"})
  79. */
  80. class Bar3 {}
  81. Example #2
  82. ~~~~~~~~~~
  83. With configuration: ``['after_array_assignments_equals' => false, 'before_array_assignments_equals' => false]``.
  84. .. code-block:: diff
  85. --- Original
  86. +++ New
  87. <?php
  88. /**
  89. - * @Foo(foo = "foo", bar = {"foo":"foo", "bar"="bar"})
  90. + * @Foo(foo="foo", bar={"foo" : "foo", "bar"="bar"})
  91. */
  92. class Bar {}
  93. Rule sets
  94. ---------
  95. The rule is part of the following rule set:
  96. - `@DoctrineAnnotation <./../../ruleSets/DoctrineAnnotation.rst>`_ with config:
  97. ``['before_array_assignments_colon' => false]``
  98. References
  99. ----------
  100. - Fixer class: `PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationSpacesFixer <./../../../src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php>`_
  101. - Test class: `PhpCsFixer\\Tests\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationSpacesFixerTest <./../../../tests/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixerTest.php>`_
  102. The test class defines officially supported behaviour. Each test case is a part of our backward compatibility promise.