README.rst 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453
  1. PHP Coding Standards Fixer
  2. ==========================
  3. The PHP Coding Standards Fixer tool fixes *most* issues in your code when you
  4. want to follow the PHP coding standards as defined in the PSR-1 and PSR-2
  5. documents and many more.
  6. If you are already using a linter to identify coding standards problems in your
  7. code, you know that fixing them by hand is tedious, especially on large
  8. projects. This tool does not only detect them, but also fixes them for you.
  9. Requirements
  10. ------------
  11. PHP needs to be a minimum version of PHP 5.6.0.
  12. Installation
  13. ------------
  14. Locally
  15. ~~~~~~~
  16. Download the `php-cs-fixer.phar`_ file and store it somewhere on your computer.
  17. Globally (manual)
  18. ~~~~~~~~~~~~~~~~~
  19. You can run these commands to easily access latest ``php-cs-fixer`` from anywhere on
  20. your system:
  21. .. code-block:: bash
  22. $ wget http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -O php-cs-fixer
  23. or with specified version:
  24. .. code-block:: bash
  25. $ wget https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v2.4.0/php-cs-fixer.phar -O php-cs-fixer
  26. or with curl:
  27. .. code-block:: bash
  28. $ curl -L http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar -o php-cs-fixer
  29. then:
  30. .. code-block:: bash
  31. $ sudo chmod a+x php-cs-fixer
  32. $ sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
  33. Then, just run ``php-cs-fixer``.
  34. Globally (Composer)
  35. ~~~~~~~~~~~~~~~~~~~
  36. To install PHP CS Fixer, `install Composer <https://getcomposer.org/download/>`_ and issue the following command:
  37. .. code-block:: bash
  38. $ composer global require friendsofphp/php-cs-fixer
  39. Then make sure you have the global Composer binaries directory in your ``PATH``. This directory is platform-dependent, see `Composer documentation <https://getcomposer.org/doc/03-cli.md#composer-home>`_ for details. Example for some Unix systems:
  40. .. code-block:: bash
  41. $ export PATH="$PATH:$HOME/.composer/vendor/bin"
  42. Globally (homebrew)
  43. ~~~~~~~~~~~~~~~~~~~
  44. PHP-CS-Fixer is part of the homebrew-php project. Follow the installation
  45. instructions at https://github.com/homebrew/homebrew-php if you don't
  46. already have it.
  47. .. code-block:: bash
  48. $ brew install homebrew/php/php-cs-fixer
  49. Update
  50. ------
  51. Locally
  52. ~~~~~~~
  53. The ``self-update`` command tries to update ``php-cs-fixer`` itself:
  54. .. code-block:: bash
  55. $ php php-cs-fixer.phar self-update
  56. Globally (manual)
  57. ~~~~~~~~~~~~~~~~~
  58. You can update ``php-cs-fixer`` through this command:
  59. .. code-block:: bash
  60. $ sudo php-cs-fixer self-update
  61. Globally (Composer)
  62. ~~~~~~~~~~~~~~~~~~~
  63. You can update ``php-cs-fixer`` through this command:
  64. .. code-block:: bash
  65. $ ./composer.phar global update friendsofphp/php-cs-fixer
  66. Globally (homebrew)
  67. ~~~~~~~~~~~~~~~~~~~
  68. You can update ``php-cs-fixer`` through this command:
  69. .. code-block:: bash
  70. $ brew upgrade php-cs-fixer
  71. Usage
  72. -----
  73. The ``fix`` command tries to fix as much coding standards
  74. problems as possible on a given file or files in a given directory and its subdirectories:
  75. .. code-block:: bash
  76. $ php php-cs-fixer.phar fix /path/to/dir
  77. $ php php-cs-fixer.phar fix /path/to/file
  78. By default ``--path-mode`` is set to ``override``, which means, that if you specify the path to a file or a directory via
  79. command arguments, then the paths provided to a ``Finder`` in config file will be ignored. You can use ``--path-mode=intersection``
  80. to merge paths from the config file and from the argument:
  81. .. code-block:: bash
  82. $ php php-cs-fixer.phar fix --path-mode=intersection /path/to/dir
  83. The ``--format`` option for the output format. Supported formats are ``txt`` (default one), ``json``, ``xml`` and ``junit``.
  84. NOTE: When using ``junit`` format report generates in accordance with JUnit xml schema from Jenkins (see docs/junit-10.xsd).
  85. The ``--verbose`` option will show the applied rules. When using the ``txt`` format it will also displays progress notifications.
  86. The ``--rules`` option limits the rules to apply on the
  87. project:
  88. .. code-block:: bash
  89. $ php php-cs-fixer.phar fix /path/to/project --rules=@PSR2
  90. By default the PSR1 and PSR2 rules are used.
  91. The ``--rules`` option lets you choose the exact rules to
  92. apply (the rule names must be separated by a comma):
  93. .. code-block:: bash
  94. $ php php-cs-fixer.phar fix /path/to/dir --rules=line_ending,full_opening_tag,indentation_type
  95. You can also blacklist the rules you don't want by placing a dash in front of the rule name, if this is more convenient,
  96. using ``-name_of_fixer``:
  97. .. code-block:: bash
  98. $ php php-cs-fixer.phar fix /path/to/dir --rules=-full_opening_tag,-indentation_type
  99. When using combinations of exact and blacklist rules, applying exact rules along with above blacklisted results:
  100. .. code-block:: bash
  101. $ php php-cs-fixer.phar fix /path/to/project --rules=@Symfony,-@PSR1,-blank_line_before_return,strict_comparison
  102. Complete configuration for rules can be supplied using a ``json`` formatted string.
  103. .. code-block:: bash
  104. $ php php-cs-fixer.phar fix /path/to/project --rules='{"concat_space": {"spacing": "none"}}'
  105. A combination of ``--dry-run`` and ``--diff`` will
  106. display a summary of proposed fixes, leaving your files unchanged.
  107. The ``--allow-risky`` option (pass ``yes`` or ``no``) allows you to set whether risky rules may run. Default value is taken from config file.
  108. Risky rule is a rule, which could change code behaviour. By default no risky rules are run.
  109. The ``--stop-on-violation`` flag stops execution upon first file that needs to be fixed.
  110. The ``--show-progress`` option allows you to choose the way process progress is rendered:
  111. * ``none``: disables progress output;
  112. * ``run-in``: simple single-line progress output;
  113. * ``estimating``: multiline progress output with number of files and percentage on each line. Note that with this option, the files list is evaluated before processing to get the total number of files and then kept in memory to avoid using the file iterator twice. This has an impact on memory usage so using this option is not recommended on very large projects;
  114. * ``estimating-max``: same as ``estimating`` but using all terminal columns instead of default 80.
  115. If the option is not provided, it defaults to ``run-in`` unless a config file that disables output is used, in which case it defaults to ``none``. This option has no effect if the verbosity of the command is less than ``verbose``.
  116. .. code-block:: bash
  117. $ php php-cs-fixer.phar fix --verbose --show-progress=estimating
  118. The command can also read from standard input, in which case it won't
  119. automatically fix anything:
  120. .. code-block:: bash
  121. $ cat foo.php | php php-cs-fixer.phar fix --diff -
  122. Choose from the list of available rules:
  123. * **align_multiline_comment**
  124. Each line of multi-line DocComments must have an asterisk [PSR-5] and
  125. must be aligned with the first one.
  126. Configuration options:
  127. - ``comment_type`` (``'all_multiline'``, ``'phpdocs_like'``, ``'phpdocs_only'``): whether
  128. to fix PHPDoc comments only (``phpdocs_only``), any multi-line comment
  129. whose lines all start with an asterisk (``phpdocs_like``) or any
  130. multi-line comment (``all_multiline``); defaults to ``'phpdocs_only'``
  131. * **array_syntax**
  132. PHP arrays should be declared using the configured syntax.
  133. Configuration options:
  134. - ``syntax`` (``'long'``, ``'short'``): whether to use the ``long`` or ``short`` array
  135. syntax; defaults to ``'long'``
  136. * **binary_operator_spaces** [@Symfony]
  137. Binary operators should be surrounded by at least one space.
  138. Configuration options:
  139. - ``align_double_arrow`` (``false``, ``null``, ``true``): whether to apply, remove or
  140. ignore double arrows alignment; defaults to ``false``
  141. - ``align_equals`` (``false``, ``null``, ``true``): whether to apply, remove or ignore
  142. equals alignment; defaults to ``false``
  143. * **blank_line_after_namespace** [@PSR2, @Symfony]
  144. There MUST be one blank line after the namespace declaration.
  145. * **blank_line_after_opening_tag** [@Symfony]
  146. Ensure there is no code on the same line as the PHP open tag and it is
  147. followed by a blank line.
  148. * **blank_line_before_return**
  149. An empty line feed should precede a return statement (deprecated, use
  150. ``blank_line_before_statement`` instead).
  151. * **blank_line_before_statement** [@Symfony]
  152. An empty line feed must precede any configured statement.
  153. Configuration options:
  154. - ``statements`` (``array``): list of statements which must be must be preceded by
  155. an empty line; defaults to ``['break', 'continue', 'declare', 'return',
  156. 'throw', 'try']``
  157. * **braces** [@PSR2, @Symfony]
  158. The body of each structure MUST be enclosed by braces. Braces should be
  159. properly placed. Body of braces should be properly indented.
  160. Configuration options:
  161. - ``allow_single_line_closure`` (``bool``): whether single line lambda notation
  162. should be allowed; defaults to ``false``
  163. - ``position_after_anonymous_constructs`` (``'next'``, ``'same'``): whether the
  164. opening brace should be placed on "next" or "same" line after anonymous
  165. constructs (anonymous classes and lambda functions); defaults to ``'same'``
  166. - ``position_after_control_structures`` (``'next'``, ``'same'``): whether the opening
  167. brace should be placed on "next" or "same" line after control
  168. structures; defaults to ``'same'``
  169. - ``position_after_functions_and_oop_constructs`` (``'next'``, ``'same'``): whether
  170. the opening brace should be placed on "next" or "same" line after
  171. classy constructs (non-anonymous classes, interfaces, traits, methods
  172. and non-lambda functions); defaults to ``'next'``
  173. * **cast_spaces** [@Symfony]
  174. A single space or none should be between cast and variable.
  175. Configuration options:
  176. - ``space`` (``'none'``, ``'single'``): spacing to apply between cast and variable;
  177. defaults to ``'single'``
  178. * **class_definition** [@PSR2, @Symfony]
  179. Whitespace around the keywords of a class, trait or interfaces
  180. definition should be one space.
  181. Configuration options:
  182. - ``multiLineExtendsEachSingleLine`` (``bool``): whether definitions should be
  183. multiline; defaults to ``false``
  184. - ``singleItemSingleLine`` (``bool``): whether definitions should be single line
  185. when including a single item; defaults to ``false``
  186. - ``singleLine`` (``bool``): whether definitions should be single line; defaults
  187. to ``false``
  188. * **class_keyword_remove**
  189. Converts ``::class`` keywords to FQCN strings.
  190. * **combine_consecutive_unsets**
  191. Calling ``unset`` on multiple items should be done in one call.
  192. * **concat_space** [@Symfony]
  193. Concatenation should be spaced according configuration.
  194. Configuration options:
  195. - ``spacing`` (``'none'``, ``'one'``): spacing to apply around concatenation operator;
  196. defaults to ``'none'``
  197. * **declare_equal_normalize** [@Symfony]
  198. Equal sign in declare statement should be surrounded by spaces or not
  199. following configuration.
  200. Configuration options:
  201. - ``space`` (``'none'``, ``'single'``): spacing to apply around the equal sign;
  202. defaults to ``'none'``
  203. * **declare_strict_types** [@PHP70Migration:risky, @PHP71Migration:risky]
  204. Force strict types declaration in all files. Requires PHP >= 7.0.
  205. *Risky rule: forcing strict types will stop non strict code from working.*
  206. * **dir_constant** [@Symfony:risky]
  207. Replaces ``dirname(__FILE__)`` expression with equivalent ``__DIR__``
  208. constant.
  209. *Risky rule: risky when the function ``dirname()`` is overridden.*
  210. * **doctrine_annotation_array_assignment** [@DoctrineAnnotation]
  211. Doctrine annotations must use configured operator for assignment in
  212. arrays.
  213. Configuration options:
  214. - ``ignored_tags`` (``array``): list of tags that must not be treated as Doctrine
  215. Annotations; defaults to ``['abstract', 'access', 'code', 'deprec',
  216. 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc',
  217. 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar',
  218. 'staticVar', 'throw', 'api', 'author', 'category', 'copyright',
  219. 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal',
  220. 'license', 'link', 'method', 'package', 'param', 'property',
  221. 'property-read', 'property-write', 'return', 'see', 'since', 'source',
  222. 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var',
  223. 'version', 'after', 'afterClass', 'backupGlobals',
  224. 'backupStaticAttributes', 'before', 'beforeClass',
  225. 'codeCoverageIgnore', 'codeCoverageIgnoreStart',
  226. 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass',
  227. 'coversNothing', 'dataProvider', 'depends', 'expectedException',
  228. 'expectedExceptionCode', 'expectedExceptionMessage',
  229. 'expectedExceptionMessageRegExp', 'group', 'large', 'medium',
  230. 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses',
  231. 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses',
  232. 'SuppressWarnings', 'noinspection', 'package_version', 'enduml',
  233. 'startuml', 'fix', 'FIXME', 'fixme', 'override']``
  234. - ``operator`` (``':'``, ``'='``): the operator to use; defaults to ``'='``
  235. * **doctrine_annotation_braces** [@DoctrineAnnotation]
  236. Doctrine annotations without arguments must use the configured syntax.
  237. Configuration options:
  238. - ``ignored_tags`` (``array``): list of tags that must not be treated as Doctrine
  239. Annotations; defaults to ``['abstract', 'access', 'code', 'deprec',
  240. 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc',
  241. 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar',
  242. 'staticVar', 'throw', 'api', 'author', 'category', 'copyright',
  243. 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal',
  244. 'license', 'link', 'method', 'package', 'param', 'property',
  245. 'property-read', 'property-write', 'return', 'see', 'since', 'source',
  246. 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var',
  247. 'version', 'after', 'afterClass', 'backupGlobals',
  248. 'backupStaticAttributes', 'before', 'beforeClass',
  249. 'codeCoverageIgnore', 'codeCoverageIgnoreStart',
  250. 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass',
  251. 'coversNothing', 'dataProvider', 'depends', 'expectedException',
  252. 'expectedExceptionCode', 'expectedExceptionMessage',
  253. 'expectedExceptionMessageRegExp', 'group', 'large', 'medium',
  254. 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses',
  255. 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses',
  256. 'SuppressWarnings', 'noinspection', 'package_version', 'enduml',
  257. 'startuml', 'fix', 'FIXME', 'fixme', 'override']``
  258. - ``syntax`` (``'with_braces'``, ``'without_braces'``): whether to add or remove
  259. braces; defaults to ``'without_braces'``
  260. * **doctrine_annotation_indentation** [@DoctrineAnnotation]
  261. Doctrine annotations must be indented with four spaces.
  262. Configuration options:
  263. - ``ignored_tags`` (``array``): list of tags that must not be treated as Doctrine
  264. Annotations; defaults to ``['abstract', 'access', 'code', 'deprec',
  265. 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc',
  266. 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar',
  267. 'staticVar', 'throw', 'api', 'author', 'category', 'copyright',
  268. 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal',
  269. 'license', 'link', 'method', 'package', 'param', 'property',
  270. 'property-read', 'property-write', 'return', 'see', 'since', 'source',
  271. 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var',
  272. 'version', 'after', 'afterClass', 'backupGlobals',
  273. 'backupStaticAttributes', 'before', 'beforeClass',
  274. 'codeCoverageIgnore', 'codeCoverageIgnoreStart',
  275. 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass',
  276. 'coversNothing', 'dataProvider', 'depends', 'expectedException',
  277. 'expectedExceptionCode', 'expectedExceptionMessage',
  278. 'expectedExceptionMessageRegExp', 'group', 'large', 'medium',
  279. 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses',
  280. 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses',
  281. 'SuppressWarnings', 'noinspection', 'package_version', 'enduml',
  282. 'startuml', 'fix', 'FIXME', 'fixme', 'override']``
  283. - ``indent_mixed_lines`` (``bool``): whether to indent lines that have content
  284. before closing parenthesis; defaults to ``false``
  285. * **doctrine_annotation_spaces** [@DoctrineAnnotation]
  286. Fixes spaces in Doctrine annotations.
  287. Configuration options:
  288. - ``after_argument_assignments`` (``null``, ``bool``): whether to add, remove or
  289. ignore spaces after argument assignment operator; defaults to ``false``
  290. - ``after_array_assignments_colon`` (``null``, ``bool``): whether to add, remove or
  291. ignore spaces after array assignment ``:`` operator; defaults to ``true``
  292. - ``after_array_assignments_equals`` (``null``, ``bool``): whether to add, remove or
  293. ignore spaces after array assignment ``=`` operator; defaults to ``true``
  294. - ``around_argument_assignments`` (``bool``): whether to fix spaces around
  295. argument assignment operator (deprecated, use
  296. ``before_argument_assignments`` and ``after_argument_assignments`` options
  297. instead); defaults to ``true``
  298. - ``around_array_assignments`` (``bool``): whether to fix spaces around array
  299. assignment operators (deprecated, use ``before_array_assignments_*`` and
  300. ``after_array_assignments_*`` options instead); defaults to ``true``
  301. - ``around_commas`` (``bool``): whether to fix spaces around commas; defaults to
  302. ``true``
  303. - ``around_parentheses`` (``bool``): whether to fix spaces around parentheses;
  304. defaults to ``true``
  305. - ``before_argument_assignments`` (``null``, ``bool``): whether to add, remove or
  306. ignore spaces before argument assignment operator; defaults to ``false``
  307. - ``before_array_assignments_colon`` (``null``, ``bool``): whether to add, remove or
  308. ignore spaces before array ``:`` assignment operator; defaults to ``true``
  309. - ``before_array_assignments_equals`` (``null``, ``bool``): whether to add, remove or
  310. ignore spaces before array ``=`` assignment operator; defaults to ``true``
  311. - ``ignored_tags`` (``array``): list of tags that must not be treated as Doctrine
  312. Annotations; defaults to ``['abstract', 'access', 'code', 'deprec',
  313. 'encode', 'exception', 'final', 'ingroup', 'inheritdoc', 'inheritDoc',
  314. 'magic', 'name', 'toc', 'tutorial', 'private', 'static', 'staticvar',
  315. 'staticVar', 'throw', 'api', 'author', 'category', 'copyright',
  316. 'deprecated', 'example', 'filesource', 'global', 'ignore', 'internal',
  317. 'license', 'link', 'method', 'package', 'param', 'property',
  318. 'property-read', 'property-write', 'return', 'see', 'since', 'source',
  319. 'subpackage', 'throws', 'todo', 'TODO', 'usedBy', 'uses', 'var',
  320. 'version', 'after', 'afterClass', 'backupGlobals',
  321. 'backupStaticAttributes', 'before', 'beforeClass',
  322. 'codeCoverageIgnore', 'codeCoverageIgnoreStart',
  323. 'codeCoverageIgnoreEnd', 'covers', 'coversDefaultClass',
  324. 'coversNothing', 'dataProvider', 'depends', 'expectedException',
  325. 'expectedExceptionCode', 'expectedExceptionMessage',
  326. 'expectedExceptionMessageRegExp', 'group', 'large', 'medium',
  327. 'preserveGlobalState', 'requires', 'runTestsInSeparateProcesses',
  328. 'runInSeparateProcess', 'small', 'test', 'testdox', 'ticket', 'uses',
  329. 'SuppressWarnings', 'noinspection', 'package_version', 'enduml',
  330. 'startuml', 'fix', 'FIXME', 'fixme', 'override']``
  331. * **elseif** [@PSR2, @Symfony]
  332. The keyword ``elseif`` should be used instead of ``else if`` so that all
  333. control keywords look like single words.
  334. * **encoding** [@PSR1, @PSR2, @Symfony]
  335. PHP code MUST use only UTF-8 without BOM (remove BOM).
  336. * **ereg_to_preg** [@Symfony:risky]
  337. Replace deprecated ``ereg`` regular expression functions with preg.
  338. *Risky rule: risky if the ``ereg`` funcion is overridden.*
  339. * **full_opening_tag** [@PSR1, @PSR2, @Symfony]
  340. PHP code must use the long ``<?php`` tags or short-echo ``<?=`` tags and not
  341. other tag variations.
  342. * **function_declaration** [@PSR2, @Symfony]
  343. Spaces should be properly placed in a function declaration.
  344. Configuration options:
  345. - ``closure_function_spacing`` (``'none'``, ``'one'``): spacing to use before open
  346. parenthesis for closures; defaults to ``'one'``
  347. * **function_to_constant** [@Symfony:risky]
  348. Replace core functions calls returning constants with the constants.
  349. *Risky rule: risky when any of the configured functions to replace are overridden.*
  350. Configuration options:
  351. - ``functions`` (``array``): list of function names to fix; defaults to
  352. ``['get_class', 'php_sapi_name', 'phpversion', 'pi']``
  353. * **function_typehint_space** [@Symfony]
  354. Add missing space between function's argument and its typehint.
  355. * **general_phpdoc_annotation_remove**
  356. Configured annotations should be omitted from phpdocs.
  357. Configuration options:
  358. - ``annotations`` (``array``): list of annotations to remove, e.g. ``["author"]``;
  359. defaults to ``[]``
  360. * **hash_to_slash_comment** [@Symfony]
  361. Single line comments should use double slashes ``//`` and not hash ``#``.
  362. DEPRECATED: Use "single_line_comment_style" instead.
  363. * **header_comment**
  364. Add, replace or remove header comment.
  365. Configuration options:
  366. - ``commentType`` (``'comment'``, ``'PHPDoc'``): comment syntax type; defaults to
  367. ``'comment'``
  368. - ``header`` (``string``): proper header content; required
  369. - ``location`` (``'after_declare_strict'``, ``'after_open'``): the location of the
  370. inserted header; defaults to ``'after_declare_strict'``
  371. - ``separate`` (``'both'``, ``'bottom'``, ``'none'``, ``'top'``): whether the header should be
  372. separated from the file content with a new line; defaults to ``'both'``
  373. * **heredoc_to_nowdoc**
  374. Convert ``heredoc`` to ``nowdoc`` where possible.
  375. * **include** [@Symfony]
  376. Include/Require and file path should be divided with a single space.
  377. File path should not be placed under brackets.
  378. * **indentation_type** [@PSR2, @Symfony]
  379. Code MUST use configured indentation type.
  380. * **is_null** [@Symfony:risky]
  381. Replaces is_null(parameter) expression with ``null === parameter``.
  382. *Risky rule: risky when the function ``is_null()`` is overridden.*
  383. Configuration options:
  384. - ``use_yoda_style`` (``bool``): whether Yoda style conditions should be used;
  385. defaults to ``true``
  386. * **line_ending** [@PSR2, @Symfony]
  387. All PHP files must use same line ending.
  388. * **linebreak_after_opening_tag**
  389. Ensure there is no code on the same line as the PHP open tag.
  390. * **list_syntax**
  391. List (``array`` destructuring) assignment should be declared using the
  392. configured syntax. Requires PHP >= 7.1.
  393. Configuration options:
  394. - ``syntax`` (``'long'``, ``'short'``): whether to use the ``long`` or ``short`` ``list``
  395. syntax; defaults to ``'long'``
  396. * **lowercase_cast** [@Symfony]
  397. Cast should be written in lower case.
  398. * **lowercase_constants** [@PSR2, @Symfony]
  399. The PHP constants ``true``, ``false``, and ``null`` MUST be in lower case.
  400. * **lowercase_keywords** [@PSR2, @Symfony]
  401. PHP keywords MUST be in lower case.
  402. * **magic_constant_casing** [@Symfony]
  403. Magic constants should be referred to using the correct casing.
  404. * **mb_str_functions**
  405. Replace non multibyte-safe functions with corresponding mb function.
  406. *Risky rule: risky when any of the functions are overridden.*
  407. * **method_argument_space** [@PSR2, @Symfony]
  408. In method arguments and method call, there MUST NOT be a space before
  409. each comma and there MUST be one space after each comma. Argument lists
  410. MAY be split across multiple lines, where each subsequent line is
  411. indented once. When doing so, the first item in the list MUST be on the
  412. next line, and there MUST be only one argument per line.
  413. Configuration options:
  414. - ``ensure_fully_multiline`` (``bool``): ensure every argument of a multiline
  415. argument list is on its own line; defaults to ``false``
  416. - ``keep_multiple_spaces_after_comma`` (``bool``): whether keep multiple spaces
  417. after comma; defaults to ``false``
  418. * **method_separation** [@Symfony]
  419. Methods must be separated with one blank line.
  420. * **modernize_types_casting** [@Symfony:risky]
  421. Replaces ``intval``, ``floatval``, ``doubleval``, ``strval`` and ``boolval``
  422. function calls with according type casting operator.
  423. *Risky rule: risky if any of the functions ``intval``, ``floatval``, ``doubleval``, ``strval`` or ``boolval`` are overridden.*
  424. * **native_function_casing** [@Symfony]
  425. Function defined by PHP should be called using the correct casing.
  426. * **native_function_invocation**
  427. Add leading ``\`` before function invocation of internal function to speed
  428. up resolving.
  429. *Risky rule: risky when any of the functions are overridden.*
  430. Configuration options:
  431. - ``exclude`` (``array``): list of functions to ignore; defaults to ``[]``
  432. * **new_with_braces** [@Symfony]
  433. All instances created with new keyword must be followed by braces.
  434. * **no_alias_functions** [@Symfony:risky]
  435. Master functions shall be used instead of aliases.
  436. *Risky rule: risky when any of the alias functions are overridden.*
  437. * **no_blank_lines_after_class_opening** [@Symfony]
  438. There should be no empty lines after class opening brace.
  439. * **no_blank_lines_after_phpdoc** [@Symfony]
  440. There should not be blank lines between docblock and the documented
  441. element.
  442. * **no_blank_lines_before_namespace**
  443. There should be no blank lines before a namespace declaration.
  444. * **no_break_comment** [@PSR2, @Symfony]
  445. There must be a comment when fall-through is intentional in a non-empty
  446. case body.
  447. Configuration options:
  448. - ``comment_text`` (``string``): the text to use in the added comment and to
  449. detect it; defaults to ``'no break'``
  450. * **no_closing_tag** [@PSR2, @Symfony]
  451. The closing ``?>`` tag MUST be omitted from files containing only PHP.
  452. * **no_empty_comment** [@Symfony]
  453. There should not be any empty comments.
  454. * **no_empty_phpdoc** [@Symfony]
  455. There should not be empty PHPDoc blocks.
  456. * **no_empty_statement** [@Symfony]
  457. Remove useless semicolon statements.
  458. * **no_extra_consecutive_blank_lines** [@Symfony]
  459. Removes extra blank lines and/or blank lines following configuration.
  460. Configuration options:
  461. - ``tokens`` (``array``): list of tokens to fix; defaults to ``['extra']``
  462. * **no_leading_import_slash** [@Symfony]
  463. Remove leading slashes in use clauses.
  464. * **no_leading_namespace_whitespace** [@Symfony]
  465. The namespace declaration line shouldn't contain leading whitespace.
  466. * **no_mixed_echo_print** [@Symfony]
  467. Either language construct ``print`` or ``echo`` should be used.
  468. Configuration options:
  469. - ``use`` (``'echo'``, ``'print'``): the desired language construct; defaults to
  470. ``'echo'``
  471. * **no_multiline_whitespace_around_double_arrow** [@Symfony]
  472. Operator ``=>`` should not be surrounded by multi-line whitespaces.
  473. * **no_multiline_whitespace_before_semicolons**
  474. Multi-line whitespace before closing semicolon are prohibited.
  475. * **no_null_property_initialization**
  476. Properties MUST not be explicitly initialized with ``null``.
  477. * **no_php4_constructor**
  478. Convert PHP4-style constructors to ``__construct``.
  479. *Risky rule: risky when old style constructor being fixed is overridden or overrides parent one.*
  480. * **no_short_bool_cast** [@Symfony]
  481. Short cast ``bool`` using double exclamation mark should not be used.
  482. * **no_short_echo_tag**
  483. Replace short-echo ``<?=`` with long format ``<?php echo`` syntax.
  484. * **no_singleline_whitespace_before_semicolons** [@Symfony]
  485. Single-line whitespace before closing semicolon are prohibited.
  486. * **no_spaces_after_function_name** [@PSR2, @Symfony]
  487. When making a method or function call, there MUST NOT be a space between
  488. the method or function name and the opening parenthesis.
  489. * **no_spaces_around_offset** [@Symfony]
  490. There MUST NOT be spaces around offset braces.
  491. Configuration options:
  492. - ``positions`` (``array``): whether spacing should be fixed inside and/or outside
  493. the offset braces; defaults to ``['inside', 'outside']``
  494. * **no_spaces_inside_parenthesis** [@PSR2, @Symfony]
  495. There MUST NOT be a space after the opening parenthesis. There MUST NOT
  496. be a space before the closing parenthesis.
  497. * **no_superfluous_elseif**
  498. Replaces superfluous ``elseif`` with ``if``.
  499. * **no_trailing_comma_in_list_call** [@Symfony]
  500. Remove trailing commas in list function calls.
  501. * **no_trailing_comma_in_singleline_array** [@Symfony]
  502. PHP single-line arrays should not have trailing comma.
  503. * **no_trailing_whitespace** [@PSR2, @Symfony]
  504. Remove trailing whitespace at the end of non-blank lines.
  505. * **no_trailing_whitespace_in_comment** [@PSR2, @Symfony]
  506. There MUST be no trailing spaces inside comments and phpdocs.
  507. * **no_unneeded_control_parentheses** [@Symfony]
  508. Removes unneeded parentheses around control statements.
  509. Configuration options:
  510. - ``statements`` (``array``): list of control statements to fix; defaults to
  511. ``['break', 'clone', 'continue', 'echo_print', 'return', 'switch_case',
  512. 'yield']``
  513. * **no_unneeded_curly_braces**
  514. Removes unneeded curly braces that are superfluous and aren't part of a
  515. control structure's body.
  516. * **no_unneeded_final_method**
  517. A final class must not have final methods.
  518. * **no_unreachable_default_argument_value**
  519. In function arguments there must not be arguments with default values
  520. before non-default ones.
  521. *Risky rule: modifies the signature of functions; therefore risky when using systems (such as some Symfony components) that rely on those (for example through reflection).*
  522. * **no_unused_imports** [@Symfony]
  523. Unused use statements must be removed.
  524. * **no_useless_else**
  525. There should not be useless ``else`` cases.
  526. * **no_useless_return**
  527. There should not be an empty return statement at the end of a function.
  528. * **no_whitespace_before_comma_in_array** [@Symfony]
  529. In array declaration, there MUST NOT be a whitespace before each comma.
  530. * **no_whitespace_in_blank_line** [@Symfony]
  531. Remove trailing whitespace at the end of blank lines.
  532. * **non_printable_character** [@Symfony:risky, @PHP70Migration, @PHP71Migration]
  533. Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other
  534. invisible unicode symbols.
  535. *Risky rule: risky when strings contain intended invisible characters.*
  536. Configuration options:
  537. - ``use_escape_sequences_in_strings`` (``bool``): whether characters should be
  538. replaced with escape sequences in strings; defaults to ``false``
  539. * **normalize_index_brace** [@Symfony]
  540. Array index should always be written by using square braces.
  541. * **not_operator_with_space**
  542. Logical NOT operators (``!``) should have leading and trailing
  543. whitespaces.
  544. * **not_operator_with_successor_space**
  545. Logical NOT operators (``!``) should have one trailing whitespace.
  546. * **object_operator_without_whitespace** [@Symfony]
  547. There should not be space before or after object ``T_OBJECT_OPERATOR``
  548. ``->``.
  549. * **ordered_class_elements**
  550. Orders the elements of classes/interfaces/traits.
  551. Configuration options:
  552. - ``order`` (``array``): list of strings defining order of elements; defaults to
  553. ``['use_trait', 'constant_public', 'constant_protected',
  554. 'constant_private', 'property_public', 'property_protected',
  555. 'property_private', 'construct', 'destruct', 'magic', 'phpunit',
  556. 'method_public', 'method_protected', 'method_private']``
  557. * **ordered_imports**
  558. Ordering use statements.
  559. Configuration options:
  560. - ``importsOrder`` (``array``, ``null``): defines the order of import types; defaults
  561. to ``null``
  562. - ``sortAlgorithm`` (``'alpha'``, ``'length'``): whether the statements should be
  563. sorted alphabetically or by length; defaults to ``'alpha'``
  564. * **php_unit_construct** [@Symfony:risky]
  565. PHPUnit assertion method calls like "->assertSame(true, $foo)" should be
  566. written with dedicated method like "->assertTrue($foo)".
  567. *Risky rule: fixer could be risky if one is overriding PHPUnit's native methods.*
  568. Configuration options:
  569. - ``assertions`` (``array``): list of assertion methods to fix; defaults to
  570. ``['assertEquals', 'assertSame', 'assertNotEquals', 'assertNotSame']``
  571. * **php_unit_dedicate_assert** [@Symfony:risky]
  572. PHPUnit assertions like "assertInternalType", "assertFileExists", should
  573. be used over "assertTrue".
  574. *Risky rule: fixer could be risky if one is overriding PHPUnit's native methods.*
  575. Configuration options:
  576. - ``functions`` (``array``): list of assertions to fix; defaults to
  577. ``['array_key_exists', 'empty', 'file_exists', 'is_infinite', 'is_nan',
  578. 'is_null', 'is_array', 'is_bool', 'is_boolean', 'is_callable',
  579. 'is_double', 'is_float', 'is_int', 'is_integer', 'is_long',
  580. 'is_numeric', 'is_object', 'is_real', 'is_resource', 'is_scalar',
  581. 'is_string']``
  582. * **php_unit_fqcn_annotation** [@Symfony]
  583. PHPUnit annotations should be a FQCNs including a root namespace.
  584. * **php_unit_strict**
  585. PHPUnit methods like ``assertSame`` should be used instead of
  586. ``assertEquals``.
  587. *Risky rule: risky when any of the functions are overridden.*
  588. Configuration options:
  589. - ``assertions`` (``array``): list of assertion methods to fix; defaults to
  590. ``['assertAttributeEquals', 'assertAttributeNotEquals', 'assertEquals',
  591. 'assertNotEquals']``
  592. * **php_unit_test_class_requires_covers**
  593. Adds a default ``@coversNothing`` annotation to PHPUnit test classes that
  594. have no ``@covers*`` annotation.
  595. * **phpdoc_add_missing_param_annotation**
  596. Phpdoc should contain @param for all params.
  597. Configuration options:
  598. - ``only_untyped`` (``bool``): whether to add missing ``@param`` annotations for
  599. untyped parameters only; defaults to ``true``
  600. * **phpdoc_align** [@Symfony]
  601. All items of the given phpdoc tags must be aligned vertically.
  602. Configuration options:
  603. - ``tags`` (``array``): the tags that should be aligned; defaults to ``['param',
  604. 'return', 'throws', 'type', 'var']``
  605. * **phpdoc_annotation_without_dot** [@Symfony]
  606. Phpdocs annotation descriptions should not be a sentence.
  607. * **phpdoc_indent** [@Symfony]
  608. Docblocks should have the same indentation as the documented subject.
  609. * **phpdoc_inline_tag** [@Symfony]
  610. Fix phpdoc inline tags, make inheritdoc always inline.
  611. * **phpdoc_no_access** [@Symfony]
  612. @access annotations should be omitted from phpdocs.
  613. * **phpdoc_no_alias_tag** [@Symfony]
  614. No alias PHPDoc tags should be used.
  615. Configuration options:
  616. - ``replacements`` (``array``): mapping between replaced annotations with new
  617. ones; defaults to ``['property-read' => 'property', 'property-write' =>
  618. 'property', 'type' => 'var', 'link' => 'see']``
  619. * **phpdoc_no_empty_return** [@Symfony]
  620. @return void and @return null annotations should be omitted from
  621. phpdocs.
  622. * **phpdoc_no_package** [@Symfony]
  623. @package and @subpackage annotations should be omitted from phpdocs.
  624. * **phpdoc_no_useless_inheritdoc** [@Symfony]
  625. Classy that does not inherit must not have inheritdoc tags.
  626. * **phpdoc_order**
  627. Annotations in phpdocs should be ordered so that param annotations come
  628. first, then throws annotations, then return annotations.
  629. * **phpdoc_return_self_reference** [@Symfony]
  630. The type of ``@return`` annotations of methods returning a reference to
  631. itself must the configured one.
  632. Configuration options:
  633. - ``replacements`` (``array``): mapping between replaced return types with new
  634. ones; defaults to ``['this' => '$this', '@this' => '$this', '$self' =>
  635. 'self', '@self' => 'self', '$static' => 'static', '@static' =>
  636. 'static']``
  637. * **phpdoc_scalar** [@Symfony]
  638. Scalar types should always be written in the same form. ``int`` not
  639. ``integer``, ``bool`` not ``boolean``, ``float`` not ``real`` or ``double``.
  640. * **phpdoc_separation** [@Symfony]
  641. Annotations in phpdocs should be grouped together so that annotations of
  642. the same type immediately follow each other, and annotations of a
  643. different type are separated by a single blank line.
  644. * **phpdoc_single_line_var_spacing** [@Symfony]
  645. Single line @var PHPDoc should have proper spacing.
  646. * **phpdoc_summary** [@Symfony]
  647. Phpdocs summary should end in either a full stop, exclamation mark, or
  648. question mark.
  649. * **phpdoc_to_comment** [@Symfony]
  650. Docblocks should only be used on structural elements.
  651. * **phpdoc_trim** [@Symfony]
  652. Phpdocs should start and end with content, excluding the very first and
  653. last line of the docblocks.
  654. * **phpdoc_types** [@Symfony]
  655. The correct case must be used for standard PHP types in phpdoc.
  656. * **phpdoc_types_order**
  657. Sorts PHPDoc types.
  658. Configuration options:
  659. - ``null_adjustment`` (``'always_first'``, ``'always_last'``, ``'none'``): forces the
  660. position of ``null`` (overrides ``sort_algorithm``); defaults to
  661. ``'always_first'``
  662. - ``sort_algorithm`` (``'alpha'``, ``'none'``): the sorting algorithm to apply;
  663. defaults to ``'alpha'``
  664. * **phpdoc_var_without_name** [@Symfony]
  665. @var and @type annotations should not contain the variable name.
  666. * **pow_to_exponentiation** [@PHP56Migration, @PHP70Migration, @PHP71Migration]
  667. Converts ``pow()`` to the ``**`` operator.
  668. *Risky rule: risky when the function ``pow()`` is overridden.*
  669. * **pre_increment** [@Symfony]
  670. Pre incrementation/decrementation should be used if possible.
  671. * **protected_to_private** [@Symfony]
  672. Converts ``protected`` variables and methods to ``private`` where possible.
  673. * **psr0**
  674. Classes must be in a path that matches their namespace, be at least one
  675. namespace deep and the class name should match the file name.
  676. *Risky rule: this fixer may change your class name, which will break the code that is depended on old name.*
  677. Configuration options:
  678. - ``dir`` (``string``): the directory where the project code is placed; defaults
  679. to ``''``
  680. * **psr4** [@Symfony:risky]
  681. Class names should match the file name.
  682. *Risky rule: this fixer may change you class name, which will break the code that is depended on old name.*
  683. * **random_api_migration** [@PHP70Migration, @PHP71Migration]
  684. Replaces ``rand``, ``srand``, ``getrandmax`` functions calls with their ``mt_*``
  685. analogs.
  686. *Risky rule: risky when the configured functions are overridden.*
  687. Configuration options:
  688. - ``replacements`` (``array``): mapping between replaced functions with the new
  689. ones; defaults to ``['getrandmax' => 'mt_getrandmax', 'rand' =>
  690. 'mt_rand', 'srand' => 'mt_srand']``
  691. * **return_type_declaration** [@Symfony]
  692. There should be one or no space before colon, and one space after it in
  693. return type declarations, according to configuration.
  694. Configuration options:
  695. - ``space_before`` (``'none'``, ``'one'``): spacing to apply before colon; defaults to
  696. ``'none'``
  697. * **self_accessor** [@Symfony]
  698. Inside a classy element "self" should be preferred to the class name
  699. itself.
  700. * **semicolon_after_instruction**
  701. Instructions must be terminated with a semicolon.
  702. * **short_scalar_cast** [@Symfony]
  703. Cast ``(boolean)`` and ``(integer)`` should be written as ``(bool)`` and
  704. ``(int)``, ``(double)`` and ``(real)`` as ``(float)``.
  705. * **silenced_deprecation_error** [@Symfony:risky]
  706. Ensures deprecation notices are silenced.
  707. *Risky rule: silencing of deprecation errors might cause changes to code behaviour.*
  708. * **simplified_null_return**
  709. A return statement wishing to return ``void`` should not return ``null``.
  710. *Risky rule: risky since PHP 7.1 as ``null`` and ``void`` can be hinted as return type and have different meaning.*
  711. * **single_blank_line_at_eof** [@PSR2, @Symfony]
  712. A PHP file without end tag must always end with a single empty line
  713. feed.
  714. * **single_blank_line_before_namespace** [@Symfony]
  715. There should be exactly one blank line before a namespace declaration.
  716. * **single_class_element_per_statement** [@PSR2, @Symfony]
  717. There MUST NOT be more than one property or constant declared per
  718. statement.
  719. Configuration options:
  720. - ``elements`` (``array``): list of strings which element should be modified;
  721. defaults to ``['const', 'property']``
  722. * **single_import_per_statement** [@PSR2, @Symfony]
  723. There MUST be one use keyword per declaration.
  724. * **single_line_after_imports** [@PSR2, @Symfony]
  725. Each namespace use MUST go on its own line and there MUST be one blank
  726. line after the use statements block.
  727. * **single_line_comment_style**
  728. Single-line comments and multi-line comments with only one line of
  729. actual content should use the ``//`` syntax.
  730. Configuration options:
  731. - ``comment_types`` (``array``): list of comment types to fix; defaults to
  732. ``['asterisk', 'hash']``
  733. * **single_quote** [@Symfony]
  734. Convert double quotes to single quotes for simple strings.
  735. * **space_after_semicolon** [@Symfony]
  736. Fix whitespace after a semicolon.
  737. * **standardize_not_equals** [@Symfony]
  738. Replace all ``<>`` with ``!=``.
  739. * **strict_comparison**
  740. Comparisons should be strict.
  741. *Risky rule: changing comparisons to strict might change code behavior.*
  742. * **strict_param**
  743. Functions should be used with ``$strict`` param set to ``true``.
  744. *Risky rule: risky when the fixed function is overridden or if the code relies on non-strict usage.*
  745. * **switch_case_semicolon_to_colon** [@PSR2, @Symfony]
  746. A case should be followed by a colon and not a semicolon.
  747. * **switch_case_space** [@PSR2, @Symfony]
  748. Removes extra spaces between colon and case value.
  749. * **ternary_operator_spaces** [@Symfony]
  750. Standardize spaces around ternary operator.
  751. * **ternary_to_null_coalescing** [@PHP70Migration, @PHP71Migration]
  752. Use ``null`` coalescing operator ``??`` where possible. Requires PHP >= 7.0.
  753. * **trailing_comma_in_multiline_array** [@Symfony]
  754. PHP multi-line arrays should have a trailing comma.
  755. * **trim_array_spaces** [@Symfony]
  756. Arrays should be formatted like function/method arguments, without
  757. leading or trailing single line space.
  758. * **unary_operator_spaces** [@Symfony]
  759. Unary operators should be placed adjacent to their operands.
  760. * **visibility_required** [@PSR2, @Symfony, @PHP71Migration]
  761. Visibility MUST be declared on all properties and methods; abstract and
  762. final MUST be declared before the visibility; static MUST be declared
  763. after the visibility.
  764. Configuration options:
  765. - ``elements`` (``array``): the structural elements to fix (PHP >= 7.1 required
  766. for ``const``); defaults to ``['property', 'method']``
  767. * **void_return** [@PHP71Migration:risky]
  768. Add void return type to functions with missing or empty return
  769. statements, but priority is given to ``@return`` annotations. Requires
  770. PHP >= 7.1.
  771. *Risky rule: modifies the signature of functions.*
  772. * **whitespace_after_comma_in_array** [@Symfony]
  773. In array declaration, there MUST be a whitespace after each comma.
  774. The ``--dry-run`` option displays the files that need to be
  775. fixed but without actually modifying them:
  776. .. code-block:: bash
  777. $ php php-cs-fixer.phar fix /path/to/code --dry-run
  778. Instead of using command line options to customize the rule, you can save the
  779. project configuration in a ``.php_cs.dist`` file in the root directory of your project.
  780. The file must return an instance of `PhpCsFixer\\ConfigInterface <https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v2.4.0/src/ConfigInterface.php>`_
  781. which lets you configure the rules, the files and directories that
  782. need to be analyzed. You may also create ``.php_cs`` file, which is
  783. the local configuration that will be used instead of the project configuration. It
  784. is a good practice to add that file into your ``.gitignore`` file.
  785. With the ``--config`` option you can specify the path to the
  786. ``.php_cs`` file.
  787. The example below will add two rules to the default list of PSR2 set rules:
  788. .. code-block:: php
  789. <?php
  790. $finder = PhpCsFixer\Finder::create()
  791. ->exclude('somedir')
  792. ->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
  793. ->in(__DIR__)
  794. ;
  795. return PhpCsFixer\Config::create()
  796. ->setRules([
  797. '@PSR2' => true,
  798. 'strict_param' => true,
  799. 'array_syntax' => ['syntax' => 'short'],
  800. ])
  801. ->setFinder($finder)
  802. ;
  803. **NOTE**: ``exclude`` will work only for directories, so if you need to exclude file, try ``notPath``.
  804. See `Symfony\\Finder <http://symfony.com/doc/current/components/finder.html>`_
  805. online documentation for other `Finder` methods.
  806. You may also use a blacklist for the rules instead of the above shown whitelist approach.
  807. The following example shows how to use all ``Symfony`` rules but the ``full_opening_tag`` rule.
  808. .. code-block:: php
  809. <?php
  810. $finder = PhpCsFixer\Finder::create()
  811. ->exclude('somedir')
  812. ->in(__DIR__)
  813. ;
  814. return PhpCsFixer\Config::create()
  815. ->setRules([
  816. '@Symfony' => true,
  817. 'full_opening_tag' => false,
  818. ])
  819. ->setFinder($finder)
  820. ;
  821. You may want to use non-linux whitespaces in your project. Then you need to
  822. configure them in your config file.
  823. .. code-block:: php
  824. <?php
  825. return PhpCsFixer\Config::create()
  826. ->setIndent("\t")
  827. ->setLineEnding("\r\n")
  828. ;
  829. By using ``--using-cache`` option with ``yes`` or ``no`` you can set if the caching
  830. mechanism should be used.
  831. Caching
  832. -------
  833. The caching mechanism is enabled by default. This will speed up further runs by
  834. fixing only files that were modified since the last run. The tool will fix all
  835. files if the tool version has changed or the list of rules has changed.
  836. Cache is supported only for tool downloaded as phar file or installed via
  837. composer.
  838. Cache can be disabled via ``--using-cache`` option or config file:
  839. .. code-block:: php
  840. <?php
  841. return PhpCsFixer\Config::create()
  842. ->setUsingCache(false)
  843. ;
  844. Cache file can be specified via ``--cache-file`` option or config file:
  845. .. code-block:: php
  846. <?php
  847. return PhpCsFixer\Config::create()
  848. ->setCacheFile(__DIR__.'/.php_cs.cache')
  849. ;
  850. Using PHP CS Fixer on CI
  851. ------------------------
  852. Require ``friendsofphp/php-cs-fixer`` as a ``dev`` dependency:
  853. .. code-block:: bash
  854. $ ./composer.phar require --dev friendsofphp/php-cs-fixer
  855. Then, add the following command to your CI:
  856. .. code-block:: bash
  857. $ IFS=$'\n'; CHANGED_FILES=($(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")); unset IFS
  858. $ EXTRA_ARGS=('--path-mode=intersection' '--' "${CHANGED_FILES[@]}")
  859. $ vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no "${EXTRA_ARGS[@]}"
  860. Where ``$COMMIT_RANGE`` is your range of commits, eg ``$TRAVIS_COMMIT_RANGE`` or ``HEAD~..HEAD``.
  861. Exit codes
  862. ----------
  863. Exit code is build using following bit flags:
  864. * 0 OK.
  865. * 1 General error (or PHP minimal requirement not matched).
  866. * 4 Some files have invalid syntax (only in dry-run mode).
  867. * 8 Some files need fixing (only in dry-run mode).
  868. * 16 Configuration error of the application.
  869. * 32 Configuration error of a Fixer.
  870. * 64 Exception raised within the application.
  871. (applies to exit codes of the `fix` command only)
  872. Helpers
  873. -------
  874. Dedicated plugins exist for:
  875. * `Atom`_
  876. * `NetBeans`_
  877. * `PhpStorm`_
  878. * `Sublime Text`_
  879. * `Vim`_
  880. Contribute
  881. ----------
  882. The tool comes with quite a few built-in fixers, but everyone is more than
  883. welcome to `contribute`_ more of them.
  884. Fixers
  885. ~~~~~~
  886. A *fixer* is a class that tries to fix one CS issue (a ``Fixer`` class must
  887. implement ``FixerInterface``).
  888. Configs
  889. ~~~~~~~
  890. A *config* knows about the CS rules and the files and directories that must be
  891. scanned by the tool when run in the directory of your project. It is useful for
  892. projects that follow a well-known directory structures (like for Symfony
  893. projects for instance).
  894. .. _php-cs-fixer.phar: http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar
  895. .. _Atom: https://github.com/Glavin001/atom-beautify
  896. .. _NetBeans: http://plugins.netbeans.org/plugin/49042/php-cs-fixer
  897. .. _PhpStorm: https://medium.com/@valeryan/how-to-configure-phpstorm-to-use-php-cs-fixer-1844991e521f
  898. .. _Sublime Text: https://github.com/benmatselby/sublime-phpcs
  899. .. _Vim: https://github.com/stephpy/vim-php-cs-fixer
  900. .. _contribute: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/CONTRIBUTING.md