README.rst 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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.3.6.
  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 ``php-cs-fixer`` from anywhere on
  20. your system:
  21. .. code-block:: bash
  22. $ wget http://get.sensiolabs.org/php-cs-fixer.phar -O php-cs-fixer
  23. # With a specific version
  24. $ wget http://get.sensiolabs.org/php-cs-fixer-v1.11.phar -O php-cs-fixer
  25. or with curl:
  26. .. code-block:: bash
  27. $ curl http://get.sensiolabs.org/php-cs-fixer.phar -o php-cs-fixer
  28. # With a specific version
  29. $ curl http://get.sensiolabs.org/php-cs-fixer-v1.11.phar -o php-cs-fixer
  30. then:
  31. .. code-block:: bash
  32. $ sudo chmod a+x php-cs-fixer
  33. $ sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
  34. Then, just run ``php-cs-fixer``.
  35. Globally (Composer)
  36. ~~~~~~~~~~~~~~~~~~~
  37. To install PHP-CS-Fixer, install Composer and issue the following command:
  38. .. code-block:: bash
  39. $ ./composer.phar global require fabpot/php-cs-fixer
  40. Then make sure you have ``~/.composer/vendor/bin`` in your ``PATH`` and
  41. you're good to go:
  42. .. code-block:: bash
  43. export PATH="$PATH:$HOME/.composer/vendor/bin"
  44. Globally (homebrew)
  45. ~~~~~~~~~~~~~~~~~~~
  46. PHP-CS-Fixer is part of the homebrew-php project. Follow the installation
  47. instructions at https://github.com/homebrew/homebrew-php if you don't
  48. already have it.
  49. .. code-block:: bash
  50. $ brew install homebrew/php/php-cs-fixer
  51. Update
  52. ------
  53. Locally
  54. ~~~~~~~
  55. The ``self-update`` command tries to update ``php-cs-fixer`` itself:
  56. .. code-block:: bash
  57. $ php php-cs-fixer.phar self-update
  58. Globally (manual)
  59. ~~~~~~~~~~~~~~~~~
  60. You can update ``php-cs-fixer`` through this command:
  61. .. code-block:: bash
  62. $ sudo php-cs-fixer self-update
  63. Globally (Composer)
  64. ~~~~~~~~~~~~~~~~~~~
  65. You can update ``php-cs-fixer`` through this command:
  66. .. code-block:: bash
  67. $ ./composer.phar global update fabpot/php-cs-fixer
  68. Globally (homebrew)
  69. ~~~~~~~~~~~~~~~~~~~
  70. You can update ``php-cs-fixer`` through this command:
  71. .. code-block:: bash
  72. $ brew upgrade php-cs-fixer
  73. Usage
  74. -----
  75. The ``fix`` command tries to fix as much coding standards
  76. problems as possible on a given file or files in a given directory and its subdirectories:
  77. .. code-block:: bash
  78. php php-cs-fixer.phar fix /path/to/dir
  79. php php-cs-fixer.phar fix /path/to/file
  80. The ``--format`` option for the output format. Supported formats are ``txt`` (default one), ``json`` and ``xml``.
  81. The ``--verbose`` option will show the applied fixers. When using the ``txt`` format it will also displays progress notifications.
  82. The ``--rules`` option limits the rules to apply on the
  83. project:
  84. .. code-block:: bash
  85. php php-cs-fixer.phar fix /path/to/project --rules=@PSR2
  86. By default, all PSR fixers are run.
  87. The ``--rules`` option lets you choose the exact fixers to
  88. apply (the fixer names must be separated by a comma):
  89. .. code-block:: bash
  90. php php-cs-fixer.phar fix /path/to/dir --rules=unix_line_endings,full_opening_tag,no_tab_indentation
  91. You can also blacklist the fixers you don't want by placing a dash in front of the fixer name, if this is more convenient,
  92. using ``-name_of_fixer``:
  93. .. code-block:: bash
  94. php php-cs-fixer.phar fix /path/to/dir --rules=-full_opening_tag,-no_tab_indentation
  95. When using combinations of exact and blacklist fixers, applying exact fixers along with above blacklisted results:
  96. .. code-block:: bash
  97. php php-cs-fixer.phar fix /path/to/project --rules=@Symfony,-@PSR1,-return,strict
  98. A combination of ``--dry-run`` and ``--diff`` will
  99. display a summary of proposed fixes, leaving your files unchanged.
  100. The ``--allow-risky`` option allows you to set whether riskys fixer may run. Default value is taken from config file.
  101. Risky fixer is a fixer, which could change code behaviour. By default no risky fixers are run.
  102. The command can also read from standard input, in which case it won't
  103. automatically fix anything:
  104. .. code-block:: bash
  105. cat foo.php | php php-cs-fixer.phar fix --diff -
  106. Choose from the list of available fixers:
  107. * **align_double_arrow**
  108. Align double arrow symbols in
  109. consecutive lines.
  110. * **align_equals**
  111. Align equals symbols in
  112. consecutive lines.
  113. * **binary_operator_spaces** [@Symfony]
  114. Binary operators should be
  115. surrounded by at least one
  116. space.
  117. * **blank_line_after_namespace** [@PSR2, @Symfony]
  118. There MUST be one blank line
  119. after the namespace
  120. declaration.
  121. * **blank_line_after_opening_tag** [@Symfony]
  122. Ensure there is no code on the
  123. same line as the PHP open tag
  124. and it is followed by a
  125. blankline.
  126. * **blank_line_before_return** [@Symfony]
  127. An empty line feed should
  128. precede a return statement.
  129. * **braces** [@PSR2, @Symfony]
  130. The body of each structure
  131. MUST be enclosed by braces.
  132. Braces should be properly
  133. placed. Body of braces should
  134. be properly indented.
  135. * **class_definition** [@PSR2, @Symfony]
  136. Whitespace around the key
  137. words of a class, trait or
  138. interfaces definition should
  139. be one space.
  140. * **concat_with_spaces**
  141. Concatenation should be used
  142. with at least one whitespace
  143. around.
  144. * **concat_without_spaces** [@Symfony]
  145. Concatenation should be used
  146. without spaces.
  147. * **double_arrow_no_multiline_whitespace** [@Symfony]
  148. Operator => should not be
  149. surrounded by multi-line
  150. whitespaces.
  151. * **echo_to_print**
  152. Converts echo language
  153. construct to print if
  154. possible.
  155. * **elseif** [@PSR2, @Symfony]
  156. The keyword elseif should be
  157. used instead of else if so
  158. that all control keywords look
  159. like single words.
  160. * **encoding** [@PSR1, @PSR2, @Symfony]
  161. PHP code MUST use only UTF-8
  162. without BOM (remove BOM).
  163. * **ereg_to_preg**
  164. Replace deprecated ereg
  165. regular expression functions
  166. with preg. (Risky fixer!)
  167. * **full_opening_tag** [@PSR1, @PSR2, @Symfony]
  168. PHP code must use the long
  169. <?php ?> tags or the
  170. short-echo <?= ?> tags; it
  171. must not use the other tag
  172. variations.
  173. * **function_declaration** [@PSR2, @Symfony]
  174. Spaces should be properly
  175. placed in a function
  176. declaration.
  177. * **function_typehint_space** [@Symfony]
  178. Add missing space between
  179. function's argument and its
  180. typehint.
  181. * **hash_to_slash_comment** [@Symfony]
  182. Single line comments should
  183. use double slashes (//) and
  184. not hash (#).
  185. * **header_comment**
  186. Add, replace or remove header
  187. comment.
  188. * **heredoc_to_nowdoc** [@Symfony]
  189. Convert heredoc to nowdoc if
  190. possible.
  191. * **include** [@Symfony]
  192. Include/Require and file path
  193. should be divided with a
  194. single space. File path should
  195. not be placed under brackets.
  196. * **linebreak_after_opening_tag**
  197. Ensure there is no code on the
  198. same line as the PHP open tag.
  199. * **long_array_syntax**
  200. Arrays should use the long
  201. syntax.
  202. * **lowercase_cast** [@Symfony]
  203. Cast should be written in
  204. lower case.
  205. * **lowercase_constants** [@PSR2, @Symfony]
  206. The PHP constants true, false,
  207. and null MUST be in lower
  208. case.
  209. * **lowercase_keywords** [@PSR2, @Symfony]
  210. PHP keywords MUST be in lower
  211. case.
  212. * **method_argument_space** [@PSR2, @Symfony]
  213. In method arguments and method
  214. call, there MUST NOT be a
  215. space before each comma and
  216. there MUST be one space after
  217. each comma.
  218. * **method_separation** [@Symfony]
  219. Methods must be separated with
  220. one blank line.
  221. * **native_function_casing** [@Symfony]
  222. Function defined by PHP should
  223. be called using the correct
  224. casing.
  225. * **new_with_braces** [@Symfony]
  226. All instances created with new
  227. keyword must be followed by
  228. braces.
  229. * **no_alias_functions** [@Symfony]
  230. Master functions shall be used
  231. instead of aliases.
  232. * **no_blank_lines_after_class_opening** [@Symfony]
  233. There should be no empty lines
  234. after class opening brace.
  235. * **no_blank_lines_after_phpdoc** [@Symfony]
  236. There should not be blank
  237. lines between docblock and the
  238. documented element.
  239. * **no_blank_lines_before_namespace**
  240. There should be no blank lines
  241. before a namespace
  242. declaration.
  243. * **no_blank_lines_between_uses** [@Symfony]
  244. Removes line breaks between
  245. use statements.
  246. * **no_closing_tag** [@PSR2, @Symfony]
  247. The closing ?> tag MUST be
  248. omitted from files containing
  249. only PHP.
  250. * **no_duplicate_semicolons** [@Symfony]
  251. Remove duplicated semicolons.
  252. * **no_extra_consecutive_blank_lines** [@Symfony]
  253. Removes extra blank lines
  254. and/or blank lines following
  255. configuration.
  256. * **no_leading_import_slash** [@Symfony]
  257. Remove leading slashes in use
  258. clauses.
  259. * **no_leading_namespace_whitespace** [@Symfony]
  260. The namespace declaration line
  261. shouldn't contain leading
  262. whitespace.
  263. * **no_multiline_whitespace_before_semicolons**
  264. Multi-line whitespace before
  265. closing semicolon are
  266. prohibited.
  267. * **no_php4_constructor**
  268. Convert PHP4-style
  269. constructors to __construct.
  270. (Risky fixer!)
  271. * **no_short_bool_cast** [@Symfony]
  272. Short cast bool using double
  273. exclamation mark should not be
  274. used.
  275. * **no_short_echo_tag**
  276. Replace short-echo <?= with
  277. long format <?php echo syntax.
  278. * **no_singleline_whitespace_before_semicolons** [@Symfony]
  279. Single-line whitespace before
  280. closing semicolon are
  281. prohibited.
  282. * **no_spaces_after_function_name** [@PSR2, @Symfony]
  283. When making a method or
  284. function call, there MUST NOT
  285. be a space between the method
  286. or function name and the
  287. opening parenthesis.
  288. * **no_spaces_inside_parenthesis** [@PSR2, @Symfony]
  289. There MUST NOT be a space
  290. after the opening parenthesis.
  291. There MUST NOT be a space
  292. before the closing
  293. parenthesis.
  294. * **no_tab_indentation** [@PSR2, @Symfony]
  295. Code MUST use an indent of 4
  296. spaces, and MUST NOT use tabs
  297. for indenting.
  298. * **no_trailing_comma_in_list_call** [@Symfony]
  299. Remove trailing commas in list
  300. function calls.
  301. * **no_trailing_comma_in_singleline_array** [@Symfony]
  302. PHP single-line arrays should
  303. not have trailing comma.
  304. * **no_trailing_whitespace** [@PSR2, @Symfony]
  305. Remove trailing whitespace at
  306. the end of non-blank lines.
  307. * **no_unneeded_control_parentheses** [@Symfony]
  308. Removes unneeded parentheses
  309. around control statements.
  310. * **no_unreachable_default_argument_value** [@Symfony]
  311. In method arguments there must
  312. not be arguments with default
  313. values before non-default
  314. ones.
  315. * **no_unused_imports** [@Symfony]
  316. Unused use statements must be
  317. removed.
  318. * **no_whitespace_before_comma_in_array** [@Symfony]
  319. In array declaration, there
  320. MUST NOT be a whitespace
  321. before each comma.
  322. * **not_operator_with_successor_space**
  323. Logical NOT operators (!)
  324. should have one trailing
  325. whitespace.
  326. * **not_operators_with_space**
  327. Logical NOT operators (!)
  328. should have leading and
  329. trailing whitespaces.
  330. * **object_operator_without_whitespace** [@Symfony]
  331. There should not be space
  332. before or after object
  333. T_OBJECT_OPERATOR.
  334. * **ordered_imports**
  335. Ordering use statements.
  336. * **php_unit_construct**
  337. PHPUnit assertion method calls
  338. like "->assertSame(true,
  339. $foo)" should be written with
  340. dedicated method like
  341. "->assertTrue($foo)". (Risky
  342. fixer!)
  343. * **php_unit_strict**
  344. PHPUnit methods like
  345. "assertSame" should be used
  346. instead of "assertEquals".
  347. (Risky fixer!)
  348. * **phpdoc_align** [@Symfony]
  349. All items of the @param,
  350. @throws, @return, @var, and
  351. @type phpdoc tags must be
  352. aligned vertically.
  353. * **phpdoc_indent** [@Symfony]
  354. Docblocks should have the same
  355. indentation as the documented
  356. subject.
  357. * **phpdoc_inline_tag** [@Symfony]
  358. Fix PHPDoc inline tags, make
  359. inheritdoc always inline.
  360. * **phpdoc_no_access** [@Symfony]
  361. @access annotations should be
  362. omitted from phpdocs.
  363. * **phpdoc_no_package** [@Symfony]
  364. @package and @subpackage
  365. annotations should be omitted
  366. from phpdocs.
  367. * **phpdoc_no_simplified_null_return** [@Symfony]
  368. @return void and @return null
  369. annotations should be omitted
  370. from phpdocs.
  371. * **phpdoc_order**
  372. Annotations in phpdocs should
  373. be ordered so that param
  374. annotations come first, then
  375. throws annotations, then
  376. return annotations.
  377. * **phpdoc_property**
  378. @property tags should be used
  379. rather than other variants.
  380. * **phpdoc_scalar** [@Symfony]
  381. Scalar types should always be
  382. written in the same form.
  383. "int", not "integer"; "bool",
  384. not "boolean"; "float", not
  385. "real" or "double".
  386. * **phpdoc_separation** [@Symfony]
  387. Annotations in phpdocs should
  388. be grouped together so that
  389. annotations of the same type
  390. immediately follow each other,
  391. and annotations of a different
  392. type are separated by a single
  393. blank line.
  394. * **phpdoc_summary** [@Symfony]
  395. Phpdocs summary should end in
  396. either a full stop,
  397. exclamation mark, or question
  398. mark.
  399. * **phpdoc_to_comment** [@Symfony]
  400. Docblocks should only be used
  401. on structural elements.
  402. * **phpdoc_trim** [@Symfony]
  403. Phpdocs should start and end
  404. with content, excluding the
  405. very first and last line of
  406. the docblocks.
  407. * **phpdoc_type_to_var** [@Symfony]
  408. @type should always be written
  409. as @var.
  410. * **phpdoc_types** [@Symfony]
  411. The correct case must be used
  412. for standard PHP types in
  413. phpdoc.
  414. * **phpdoc_var_to_type**
  415. @var should always be written
  416. as @type.
  417. * **phpdoc_var_without_name** [@Symfony]
  418. @var and @type annotations
  419. should not contain the
  420. variable name.
  421. * **pre_increment** [@Symfony]
  422. Pre
  423. incrementation/decrementation
  424. should be used if possible.
  425. * **print_to_echo** [@Symfony]
  426. Converts print language
  427. construct to echo if possible.
  428. * **psr0**
  429. Classes must be in a path that
  430. matches their namespace, be at
  431. least one namespace deep and
  432. the class name should match
  433. the file name. (Risky fixer!)
  434. * **self_accessor** [@Symfony]
  435. Inside a classy element "self"
  436. should be preferred to the
  437. class name itself.
  438. * **short_array_syntax**
  439. PHP arrays should use the PHP
  440. 5.4 short-syntax.
  441. * **short_scalar_cast** [@Symfony]
  442. Cast "(boolean)" and
  443. "(integer)" should be written
  444. as "(bool)" and "(int)".
  445. "(double)" and "(real)" as
  446. "(float)".
  447. * **simplified_null_return** [@Symfony]
  448. A return statement wishing to
  449. return nothing should be
  450. simply "return".
  451. * **single_blank_line_at_eof** [@PSR2, @Symfony]
  452. A file must always end with a
  453. single empty line feed.
  454. * **single_blank_line_before_namespace** [@Symfony]
  455. There should be exactly one
  456. blank line before a namespace
  457. declaration.
  458. * **single_import_per_statement** [@PSR2, @Symfony]
  459. There MUST be one use keyword
  460. per declaration.
  461. * **single_line_after_imports** [@PSR2, @Symfony]
  462. Each namespace use MUST go on
  463. its own line and there MUST be
  464. one blank line after the use
  465. statements block.
  466. * **single_quote** [@Symfony]
  467. Convert double quotes to
  468. single quotes for simple
  469. strings.
  470. * **space_after_semicolon** [@Symfony]
  471. Fix whitespace after a
  472. semicolon.
  473. * **spaces_cast** [@Symfony]
  474. A single space should be
  475. between cast and variable.
  476. * **standardize_not_equals** [@Symfony]
  477. Replace all <> with !=.
  478. * **strict**
  479. Comparison should be strict.
  480. (Risky fixer!)
  481. * **strict_param**
  482. Functions should be used with
  483. $strict param. (Risky fixer!)
  484. * **switch_case_semicolon_to_colon** [@PSR2, @Symfony]
  485. A case should be followed by a
  486. colon and not a semicolon.
  487. * **switch_case_space** [@PSR2, @Symfony]
  488. Removes extra spaces between
  489. colon and case value.
  490. * **ternary_operator_spaces** [@Symfony]
  491. Standardize spaces around
  492. ternary operator.
  493. * **trailing_comma_in_multiline_array** [@Symfony]
  494. PHP multi-line arrays should
  495. have a trailing comma.
  496. * **trim_array_spaces** [@Symfony]
  497. Arrays should be formatted
  498. like function/method
  499. arguments, without leading or
  500. trailing single line space.
  501. * **unalign_double_arrow** [@Symfony]
  502. Unalign double arrow symbols.
  503. * **unalign_equals** [@Symfony]
  504. Unalign equals symbols.
  505. * **unary_operator_spaces** [@Symfony]
  506. Unary operators should be
  507. placed adjacent to their
  508. operands.
  509. * **unix_line_endings** [@PSR2, @Symfony]
  510. All PHP files must use the
  511. Unix LF line ending.
  512. * **visibility_required** [@PSR2, @Symfony]
  513. Visibility MUST be declared on
  514. all properties and methods;
  515. abstract and final MUST be
  516. declared before the
  517. visibility; static MUST be
  518. declared after the visibility.
  519. * **whitespace_after_comma_in_array** [@Symfony]
  520. In array declaration, there
  521. MUST be a whitespace after
  522. each comma.
  523. * **whitespacy_lines** [@Symfony]
  524. Remove trailing whitespace at
  525. the end of blank lines.
  526. The ``--dry-run`` option displays the files that need to be
  527. fixed but without actually modifying them:
  528. .. code-block:: bash
  529. php php-cs-fixer.phar fix /path/to/code --dry-run
  530. Instead of using command line options to customize the fixer, you can save the
  531. project configuration in a ``.php_cs.dist`` file in the root directory
  532. of your project. The file must return an instance of ``Symfony\CS\ConfigInterface``,
  533. which lets you configure the rules, the files and directories that
  534. need to be analyzed. You may also create ``.php_cs`` file, which is
  535. the local configuration that will be used instead of the project configuration. It
  536. is a good practice to add that file into your ``.gitignore`` file.
  537. With the ``--config-file`` option you can specify the path to the
  538. ``.php_cs`` file.
  539. The example below will add two fixers to the default list of PSR2 set fixers:
  540. .. code-block:: php
  541. <?php
  542. $finder = Symfony\CS\Finder::create()
  543. ->exclude('somedir')
  544. ->in(__DIR__)
  545. ;
  546. return Symfony\CS\Config::create()
  547. ->setRules(array(
  548. '@PSR2' => true,
  549. 'strict_param' => true,
  550. 'short_array_syntax' => true,
  551. ))
  552. ->finder($finder)
  553. ;
  554. You may also use a blacklist for the Fixers instead of the above shown whitelist approach.
  555. The following example shows how to use all ``Symfony`` Fixers but the ``full_opening_tag`` Fixer.
  556. .. code-block:: php
  557. <?php
  558. $finder = Symfony\CS\Finder::create()
  559. ->exclude('somedir')
  560. ->in(__DIR__)
  561. ;
  562. return Symfony\CS\Config::create()
  563. ->setRules(array(
  564. '@Symfony' => true,
  565. 'full_opening_tag' => false,
  566. ))
  567. ->finder($finder)
  568. ;
  569. By using ``--using-cache`` option with yes or no you can set if the caching
  570. mechanism should be used.
  571. Caching
  572. -------
  573. The caching mechanism is enabled by default. This will speed up further runs by
  574. fixing only files that were modified since the last run. The tool will fix all
  575. files if the tool version has changed or the list of fixers has changed.
  576. Cache is supported only for tool downloaded as phar file or installed via
  577. composer.
  578. Cache can be disabled via ``--using-cache`` option or config file:
  579. .. code-block:: php
  580. <?php
  581. return Symfony\CS\Config::create()
  582. ->setUsingCache(false)
  583. ;
  584. Cache file can be specified via ``--cache-file`` option or config file:
  585. .. code-block:: php
  586. <?php
  587. return Symfony\CS\Config::create()
  588. ->setCacheFile(__DIR__.'/.php_cs.cache')
  589. ;
  590. Using PHP CS Fixer on Travis
  591. ----------------------------
  592. Require ``fabpot/php-cs-fixer`` as a `dev`` dependency:
  593. .. code-block:: bash
  594. $ ./composer.phar require --dev fabpot/php-cs-fixer
  595. Create a build file to run ``php-cs-fixer`` on Travis. It's advisable to create a dedicated directory
  596. for PHP CS Fixer cache files and have Travis cache it between builds.
  597. .. code-block:: yaml
  598. language: php
  599. php:
  600. - 5.5
  601. sudo: false
  602. cache:
  603. directories:
  604. - "$HOME/.composer/cache"
  605. - "$HOME/.php-cs-fixer"
  606. before_script:
  607. - mkdir -p "$HOME/.php-cs-fixer"
  608. script:
  609. - vendor/bin/php-cs-fixer fix --cache-file "$HOME/.php-cs-fixer/.php_cs.cache" --dry-run --diff --verbose
  610. Note: This will only trigger a build if you have a subscription for Travis
  611. or are using their free open source plan.
  612. Exit codes
  613. ----------
  614. Exit code are build using following bit flags:
  615. * 0 OK
  616. * 4 Some files have invalid syntax (only in dry-run mode)
  617. * 8 Some files need fixing (only in dry-run mode)
  618. * 16 Configuration error of the application
  619. * 32 Configuration error of a Fixer
  620. Helpers
  621. -------
  622. Dedicated plugins exist for:
  623. * `Atom`_
  624. * `NetBeans`_
  625. * `PhpStorm`_
  626. * `Sublime Text`_
  627. * `Vim`_
  628. Contribute
  629. ----------
  630. The tool comes with quite a few built-in fixers and finders, but everyone is
  631. more than welcome to `contribute`_ more of them.
  632. Fixers
  633. ~~~~~~
  634. A *fixer* is a class that tries to fix one CS issue (a ``Fixer`` class must
  635. implement ``FixerInterface``).
  636. Configs
  637. ~~~~~~~
  638. A *config* knows about the CS rules and the files and directories that must be
  639. scanned by the tool when run in the directory of your project. It is useful for
  640. projects that follow a well-known directory structures (like for Symfony
  641. projects for instance).
  642. .. _php-cs-fixer.phar: http://get.sensiolabs.org/php-cs-fixer.phar
  643. .. _Atom: https://github.com/Glavin001/atom-beautify
  644. .. _NetBeans: http://plugins.netbeans.org/plugin/49042/php-cs-fixer
  645. .. _PhpStorm: http://tzfrs.de/2015/01/automatically-format-code-to-match-psr-standards-with-phpstorm
  646. .. _Sublime Text: https://github.com/benmatselby/sublime-phpcs
  647. .. _Vim: https://github.com/stephpy/vim-php-cs-fixer
  648. .. _contribute: https://github.com/FriendsOfPhp/php-cs-fixer/blob/master/CONTRIBUTING.md