.php-cs-fixer.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * PHP Code Style Fixer (config created for version 3.0.0 (Constitution)).
  5. *
  6. * Use one of the following console commands to just see the
  7. * changes that will be made.
  8. * - `php-cs-fixer fix --config='.php-cs-fixer.php' --dry-run`
  9. * - `php '.php-cs-fixer.php'`
  10. *
  11. * Use one of the following console commands to fix PHP code:
  12. * - `php-cs-fixer fix --config='.php-cs-fixer.php'
  13. * - `php '.php-cs-fixer.php' --force`
  14. *
  15. * @see https://cs.symfony.com/
  16. */
  17. $rules = [
  18. /*
  19. * Each line of multi-line DocComments must have an asterisk [PSR-5]
  20. * and must be aligned with the first one.
  21. */
  22. 'align_multiline_comment' => true,
  23. // Each element of an array must be indented exactly once.
  24. 'array_indentation' => true,
  25. /*
  26. * Converts simple usages of `array_push($x, $y);` to `$x[] = $y;`.
  27. *
  28. * Risky!
  29. * Risky when the function `array_push` is overridden.
  30. */
  31. 'array_push' => true,
  32. // PHP arrays should be declared using the configured syntax.
  33. 'array_syntax' => [
  34. 'syntax' => 'short',
  35. ],
  36. /*
  37. * Converts backtick operators to `shell_exec` calls.
  38. *
  39. * Conversion is done only when it is non risky, so when special
  40. * chars like single-quotes, double-quotes and backticks are not
  41. * used inside the command.
  42. */
  43. 'backtick_to_shell_exec' => true,
  44. // Binary operators should be surrounded by space as configured.
  45. 'binary_operator_spaces' => true,
  46. // There MUST be one blank line after the namespace declaration.
  47. 'blank_line_after_namespace' => true,
  48. /*
  49. * Ensure there is no code on the same line as the PHP open tag and
  50. * it is followed by a blank line.
  51. */
  52. 'blank_line_after_opening_tag' => true,
  53. // An empty line feed must precede any configured statement.
  54. 'blank_line_before_statement' => true,
  55. /*
  56. * The body of each structure MUST be enclosed by braces. Braces
  57. * should be properly placed. Body of braces should be properly
  58. * indented.
  59. */
  60. 'braces' => [
  61. 'allow_single_line_closure' => true,
  62. ],
  63. // A single space or none should be between cast and variable.
  64. 'cast_spaces' => true,
  65. /*
  66. * Class, trait and interface elements must be separated with one or
  67. * none blank line.
  68. */
  69. 'class_attributes_separation' => true,
  70. /*
  71. * Whitespace around the keywords of a class, trait or interfaces
  72. * definition should be one space.
  73. */
  74. 'class_definition' => [
  75. 'single_item_single_line' => true,
  76. ],
  77. // Converts `::class` keywords to FQCN strings.
  78. 'class_keyword_remove' => false,
  79. // Namespace must not contain spacing, comments or PHPDoc.
  80. 'clean_namespace' => true,
  81. // Using `isset($var) &&` multiple times should be done in one call.
  82. 'combine_consecutive_issets' => true,
  83. // Calling `unset` on multiple items should be done in one call.
  84. 'combine_consecutive_unsets' => true,
  85. /*
  86. * Replace multiple nested calls of `dirname` by only one call with
  87. * second `$level` parameter. Requires PHP >= 7.0.
  88. *
  89. * Risky!
  90. * Risky when the function `dirname` is overridden.
  91. */
  92. 'combine_nested_dirname' => true,
  93. /*
  94. * Comments with annotation should be docblock when used on
  95. * structural elements.
  96. *
  97. * Risky!
  98. * Risky as new docblocks might mean more, e.g. a Doctrine entity
  99. * might have a new column in database.
  100. */
  101. 'comment_to_phpdoc' => [
  102. 'ignored_tags' => [
  103. 'noinspection',
  104. ],
  105. ],
  106. /*
  107. * Remove extra spaces in a nullable typehint.
  108. *
  109. * Rule is applied only in a PHP 7.1+ environment.
  110. */
  111. 'compact_nullable_typehint' => true,
  112. // Concatenation should be spaced according configuration.
  113. 'concat_space' => [
  114. 'spacing' => 'one',
  115. ],
  116. /*
  117. * The PHP constants `true`, `false`, and `null` MUST be written
  118. * using the correct casing.
  119. */
  120. 'constant_case' => true,
  121. /*
  122. * Class `DateTimeImmutable` should be used instead of `DateTime`.
  123. *
  124. * Risky!
  125. * Risky when the code relies on modifying `DateTime` objects or if
  126. * any of the `date_create*` functions are overridden.
  127. */
  128. 'date_time_immutable' => true,
  129. /*
  130. * Equal sign in declare statement should be surrounded by spaces or
  131. * not following configuration.
  132. */
  133. 'declare_equal_normalize' => true,
  134. /*
  135. * Force strict types declaration in all files. Requires PHP >= 7.0.
  136. *
  137. * Risky!
  138. * Forcing strict types will stop non strict code from working.
  139. */
  140. 'declare_strict_types' => false,
  141. /*
  142. * Replaces `dirname(__FILE__)` expression with equivalent `__DIR__`
  143. * constant.
  144. *
  145. * Risky!
  146. * Risky when the function `dirname` is overridden.
  147. */
  148. 'dir_constant' => true,
  149. /*
  150. * Doctrine annotations must use configured operator for assignment
  151. * in arrays.
  152. */
  153. 'doctrine_annotation_array_assignment' => [
  154. 'operator' => ':',
  155. ],
  156. /*
  157. * Doctrine annotations without arguments must use the configured
  158. * syntax.
  159. */
  160. 'doctrine_annotation_braces' => true,
  161. // Doctrine annotations must be indented with four spaces.
  162. 'doctrine_annotation_indentation' => true,
  163. /*
  164. * Fixes spaces in Doctrine annotations.
  165. *
  166. * There must not be any space around parentheses; commas must be
  167. * preceded by no space and followed by one space; there must be no
  168. * space around named arguments assignment operator; there must be
  169. * one space around array assignment operator.
  170. */
  171. 'doctrine_annotation_spaces' => [
  172. 'before_array_assignments_colon' => false,
  173. ],
  174. /*
  175. * Replaces short-echo `<?=` with long format `<?php echo`/`<?php
  176. * print` syntax, or vice-versa.
  177. */
  178. 'echo_tag_syntax' => true,
  179. /*
  180. * The keyword `elseif` should be used instead of `else if` so that
  181. * all control keywords look like single words.
  182. */
  183. 'elseif' => true,
  184. // PHP code MUST use only UTF-8 without BOM (remove BOM).
  185. 'encoding' => true,
  186. /*
  187. * Replace deprecated `ereg` regular expression functions with
  188. * `preg`.
  189. *
  190. * Risky!
  191. * Risky if the `ereg` function is overridden.
  192. */
  193. 'ereg_to_preg' => true,
  194. /*
  195. * Error control operator should be added to deprecation notices
  196. * and/or removed from other cases.
  197. *
  198. * Risky!
  199. * Risky because adding/removing `@` might cause changes to code
  200. * behaviour or if `trigger_error` function is overridden.
  201. */
  202. 'error_suppression' => [
  203. 'mute_deprecation_error' => true,
  204. 'noise_remaining_usages' => true,
  205. 'noise_remaining_usages_exclude' => [
  206. 'fclose',
  207. 'fopen',
  208. 'gzinflate',
  209. 'iconv',
  210. 'mime_content_type',
  211. 'rename',
  212. 'rmdir',
  213. 'unlink',
  214. ],
  215. ],
  216. /*
  217. * Escape implicit backslashes in strings and heredocs to ease the
  218. * understanding of which are special chars interpreted by PHP and
  219. * which not.
  220. *
  221. * In PHP double-quoted strings and heredocs some chars like `n`,
  222. * `$` or `u` have special meanings if preceded by a backslash (and
  223. * some are special only if followed by other special chars), while
  224. * a backslash preceding other chars are interpreted like a plain
  225. * backslash. The precise list of those special chars is hard to
  226. * remember and to identify quickly: this fixer escapes backslashes
  227. * that do not start a special interpretation with the char after
  228. * them.
  229. * It is possible to fix also single-quoted strings: in this case
  230. * there is no special chars apart from single-quote and backslash
  231. * itself, so the fixer simply ensure that all backslashes are
  232. * escaped. Both single and double backslashes are allowed in
  233. * single-quoted strings, so the purpose in this context is mainly
  234. * to have a uniformed way to have them written all over the
  235. * codebase.
  236. */
  237. 'escape_implicit_backslashes' => true,
  238. /*
  239. * Add curly braces to indirect variables to make them clear to
  240. * understand. Requires PHP >= 7.0.
  241. */
  242. 'explicit_indirect_variable' => true,
  243. /*
  244. * Converts implicit variables into explicit ones in double-quoted
  245. * strings or heredoc syntax.
  246. *
  247. * The reasoning behind this rule is the following:
  248. * - When there are two valid ways of doing the same thing, using
  249. * both is confusing, there should be a coding standard to follow
  250. * - PHP manual marks `"$var"` syntax as implicit and `"${var}"`
  251. * syntax as explicit: explicit code should always be preferred
  252. * - Explicit syntax allows word concatenation inside strings, e.g.
  253. * `"${var}IsAVar"`, implicit doesn't
  254. * - Explicit syntax is easier to detect for IDE/editors and
  255. * therefore has colors/highlight with higher contrast, which is
  256. * easier to read
  257. * Backtick operator is skipped because it is harder to handle; you
  258. * can use `backtick_to_shell_exec` fixer to normalize backticks to
  259. * strings
  260. */
  261. 'explicit_string_variable' => true,
  262. /*
  263. * All classes must be final, except abstract ones and Doctrine
  264. * entities.
  265. *
  266. * No exception and no configuration are intentional. Beside
  267. * Doctrine entities and of course abstract classes, there is no
  268. * single reason not to declare all classes final. If you want to
  269. * subclass a class, mark the parent class as abstract and create
  270. * two child classes, one empty if necessary: you'll gain much more
  271. * fine grained type-hinting. If you need to mock a standalone
  272. * class, create an interface, or maybe it's a value-object that
  273. * shouldn't be mocked at all. If you need to extend a standalone
  274. * class, create an interface and use the Composite pattern. If you
  275. * aren't ready yet for serious OOP, go with
  276. * FinalInternalClassFixer, it's fine.
  277. *
  278. * Risky!
  279. * Risky when subclassing non-abstract classes.
  280. */
  281. 'final_class' => false,
  282. /*
  283. * Internal classes should be `final`.
  284. *
  285. * Risky!
  286. * Changing classes to `final` might cause code execution to break.
  287. */
  288. 'final_internal_class' => false,
  289. /*
  290. * All `public` methods of `abstract` classes should be `final`.
  291. *
  292. * Enforce API encapsulation in an inheritance architecture. If you
  293. * want to override a method, use the Template method pattern.
  294. *
  295. * Risky!
  296. * Risky when overriding `public` methods of `abstract` classes.
  297. */
  298. 'final_public_method_for_abstract_class' => false,
  299. /*
  300. * Order the flags in `fopen` calls, `b` and `t` must be last.
  301. *
  302. * Risky!
  303. * Risky when the function `fopen` is overridden.
  304. */
  305. 'fopen_flag_order' => true,
  306. /*
  307. * The flags in `fopen` calls must omit `t`, and `b` must be omitted
  308. * or included consistently.
  309. *
  310. * Risky!
  311. * Risky when the function `fopen` is overridden.
  312. */
  313. 'fopen_flags' => [
  314. 'b_mode' => true,
  315. ],
  316. /*
  317. * PHP code must use the long `<?php` tags or short-echo `<?=` tags
  318. * and not other tag variations.
  319. */
  320. 'full_opening_tag' => true,
  321. /*
  322. * Transforms imported FQCN parameters and return types in function
  323. * arguments to short version.
  324. */
  325. 'fully_qualified_strict_types' => true,
  326. // Spaces should be properly placed in a function declaration.
  327. 'function_declaration' => true,
  328. /*
  329. * Replace core functions calls returning constants with the
  330. * constants.
  331. *
  332. * Risky!
  333. * Risky when any of the configured functions to replace are
  334. * overridden.
  335. */
  336. 'function_to_constant' => true,
  337. // Ensure single space between function's argument and its typehint.
  338. 'function_typehint_space' => true,
  339. // Configured annotations should be omitted from PHPDoc.
  340. 'general_phpdoc_annotation_remove' => true,
  341. // Renames PHPDoc tags.
  342. 'general_phpdoc_tag_rename' => [
  343. 'replacements' => [
  344. 'inheritDocs' => 'inheritDoc',
  345. ],
  346. ],
  347. // Imports or fully qualifies global classes/functions/constants.
  348. 'global_namespace_import' => [
  349. 'import_constants' => false,
  350. 'import_functions' => false,
  351. 'import_classes' => false,
  352. ],
  353. // There MUST be group use for the same namespaces.
  354. 'group_import' => false,
  355. // Add, replace or remove header comment.
  356. 'header_comment' => false,
  357. /*
  358. * Heredoc/nowdoc content must be properly indented. Requires PHP >=
  359. * 7.3.
  360. */
  361. 'heredoc_indentation' => false,
  362. // Convert `heredoc` to `nowdoc` where possible.
  363. 'heredoc_to_nowdoc' => true,
  364. /*
  365. * Function `implode` must be called with 2 arguments in the
  366. * documented order.
  367. *
  368. * Risky!
  369. * Risky when the function `implode` is overridden.
  370. */
  371. 'implode_call' => true,
  372. /*
  373. * Include/Require and file path should be divided with a single
  374. * space. File path should not be placed under brackets.
  375. */
  376. 'include' => true,
  377. /*
  378. * Pre- or post-increment and decrement operators should be used if
  379. * possible.
  380. */
  381. 'increment_style' => false,
  382. // Code MUST use configured indentation type.
  383. 'indentation_type' => true,
  384. /*
  385. * Replaces `is_null($var)` expression with `null === $var`.
  386. *
  387. * Risky!
  388. * Risky when the function `is_null` is overridden.
  389. */
  390. 'is_null' => true,
  391. // Lambda must not import variables it doesn't use.
  392. 'lambda_not_used_import' => true,
  393. // All PHP files must use same line ending.
  394. 'line_ending' => true,
  395. // Ensure there is no code on the same line as the PHP open tag.
  396. 'linebreak_after_opening_tag' => true,
  397. /*
  398. * List (`array` destructuring) assignment should be declared using
  399. * the configured syntax. Requires PHP >= 7.1.
  400. */
  401. 'list_syntax' => false,
  402. /*
  403. * Use `&&` and `||` logical operators instead of `and` and `or`.
  404. *
  405. * Risky!
  406. * Risky, because you must double-check if using and/or with lower
  407. * precedence was intentional.
  408. */
  409. 'logical_operators' => true,
  410. // Cast should be written in lower case.
  411. 'lowercase_cast' => true,
  412. // PHP keywords MUST be in lower case.
  413. 'lowercase_keywords' => true,
  414. /*
  415. * Class static references `self`, `static` and `parent` MUST be in
  416. * lower case.
  417. */
  418. 'lowercase_static_reference' => true,
  419. // Magic constants should be referred to using the correct casing.
  420. 'magic_constant_casing' => true,
  421. /*
  422. * Magic method definitions and calls must be using the correct
  423. * casing.
  424. */
  425. 'magic_method_casing' => true,
  426. /*
  427. * Replace non multibyte-safe functions with corresponding mb
  428. * function.
  429. *
  430. * Risky!
  431. * Risky when any of the functions are overridden.
  432. */
  433. 'mb_str_functions' => false,
  434. /*
  435. * In method arguments and method call, there MUST NOT be a space
  436. * before each comma and there MUST be one space after each comma.
  437. * Argument lists MAY be split across multiple lines, where each
  438. * subsequent line is indented once. When doing so, the first item
  439. * in the list MUST be on the next line, and there MUST be only one
  440. * argument per line.
  441. */
  442. 'method_argument_space' => [
  443. 'on_multiline' => 'ensure_fully_multiline',
  444. ],
  445. /*
  446. * Method chaining MUST be properly indented. Method chaining with
  447. * different levels of indentation is not supported.
  448. */
  449. 'method_chaining_indentation' => true,
  450. /*
  451. * Replaces `intval`, `floatval`, `doubleval`, `strval` and
  452. * `boolval` function calls with according type casting operator.
  453. *
  454. * Risky!
  455. * Risky if any of the functions `intval`, `floatval`, `doubleval`,
  456. * `strval` or `boolval` are overridden.
  457. */
  458. 'modernize_types_casting' => true,
  459. /*
  460. * DocBlocks must start with two asterisks, multiline comments must
  461. * start with a single asterisk, after the opening slash. Both must
  462. * end with a single asterisk before the closing slash.
  463. */
  464. 'multiline_comment_opening_closing' => true,
  465. /*
  466. * Forbid multi-line whitespace before the closing semicolon or move
  467. * the semicolon to the new line for chained calls.
  468. */
  469. 'multiline_whitespace_before_semicolons' => [
  470. 'strategy' => 'new_line_for_chained_calls',
  471. ],
  472. /*
  473. * Add leading `\` before constant invocation of internal constant
  474. * to speed up resolving. Constant name match is case-sensitive,
  475. * except for `null`, `false` and `true`.
  476. *
  477. * Risky!
  478. * Risky when any of the constants are namespaced or overridden.
  479. */
  480. 'native_constant_invocation' => true,
  481. /*
  482. * Function defined by PHP should be called using the correct
  483. * casing.
  484. */
  485. 'native_function_casing' => true,
  486. /*
  487. * Add leading `\` before function invocation to speed up resolving.
  488. *
  489. * Risky!
  490. * Risky when any of the functions are overridden.
  491. */
  492. 'native_function_invocation' => [
  493. 'include' => [
  494. '@compiler_optimized',
  495. ],
  496. 'scope' => 'namespaced',
  497. 'strict' => true,
  498. ],
  499. // Native type hints for functions should use the correct case.
  500. 'native_function_type_declaration_casing' => true,
  501. /*
  502. * All instances created with new keyword must be followed by
  503. * braces.
  504. */
  505. 'new_with_braces' => true,
  506. /*
  507. * Master functions shall be used instead of aliases.
  508. *
  509. * Risky!
  510. * Risky when any of the alias functions are overridden.
  511. */
  512. 'no_alias_functions' => [
  513. 'sets' => [
  514. '@all',
  515. ],
  516. ],
  517. // Master language constructs shall be used instead of aliases.
  518. 'no_alias_language_construct_call' => true,
  519. // Replace control structure alternative syntax to use braces.
  520. 'no_alternative_syntax' => true,
  521. // There should not be a binary flag before strings.
  522. 'no_binary_string' => true,
  523. // There should be no empty lines after class opening brace.
  524. 'no_blank_lines_after_class_opening' => true,
  525. /*
  526. * There should not be blank lines between docblock and the
  527. * documented element.
  528. */
  529. 'no_blank_lines_after_phpdoc' => true,
  530. // There should be no blank lines before a namespace declaration.
  531. 'no_blank_lines_before_namespace' => false,
  532. /*
  533. * There must be a comment when fall-through is intentional in a
  534. * non-empty case body.
  535. *
  536. * Adds a "no break" comment before fall-through cases, and removes
  537. * it if there is no fall-through.
  538. */
  539. 'no_break_comment' => [
  540. 'comment_text' => 'no break',
  541. ],
  542. /*
  543. * The closing `?>` tag MUST be omitted from files containing only
  544. * PHP.
  545. */
  546. 'no_closing_tag' => true,
  547. // There should not be any empty comments.
  548. 'no_empty_comment' => true,
  549. // There should not be empty PHPDoc blocks.
  550. 'no_empty_phpdoc' => true,
  551. // Remove useless (semicolon) statements.
  552. 'no_empty_statement' => true,
  553. /*
  554. * Removes extra blank lines and/or blank lines following
  555. * configuration.
  556. */
  557. 'no_extra_blank_lines' => true,
  558. /*
  559. * Replace accidental usage of homoglyphs (non ascii characters) in
  560. * names.
  561. *
  562. * Risky!
  563. * Renames classes and cannot rename the files. You might have
  564. * string references to renamed code (`$$name`).
  565. */
  566. 'no_homoglyph_names' => true,
  567. // Remove leading slashes in `use` clauses.
  568. 'no_leading_import_slash' => true,
  569. /*
  570. * The namespace declaration line shouldn't contain leading
  571. * whitespace.
  572. */
  573. 'no_leading_namespace_whitespace' => true,
  574. // Either language construct `print` or `echo` should be used.
  575. 'no_mixed_echo_print' => true,
  576. // Operator `=>` should not be surrounded by multi-line whitespaces.
  577. 'no_multiline_whitespace_around_double_arrow' => true,
  578. /*
  579. * Properties MUST not be explicitly initialized with `null` except
  580. * when they have a type declaration (PHP 7.4).
  581. */
  582. 'no_null_property_initialization' => true,
  583. /*
  584. * Convert PHP4-style constructors to `__construct`.
  585. *
  586. * Risky!
  587. * Risky when old style constructor being fixed is overridden or
  588. * overrides parent one.
  589. */
  590. 'no_php4_constructor' => true,
  591. /*
  592. * Short cast `bool` using double exclamation mark should not be
  593. * used.
  594. */
  595. 'no_short_bool_cast' => true,
  596. // Single-line whitespace before closing semicolon are prohibited.
  597. 'no_singleline_whitespace_before_semicolons' => true,
  598. /*
  599. * When making a method or function call, there MUST NOT be a space
  600. * between the method or function name and the opening parenthesis.
  601. */
  602. 'no_spaces_after_function_name' => true,
  603. // There MUST NOT be spaces around offset braces.
  604. 'no_spaces_around_offset' => true,
  605. /*
  606. * There MUST NOT be a space after the opening parenthesis. There
  607. * MUST NOT be a space before the closing parenthesis.
  608. */
  609. 'no_spaces_inside_parenthesis' => true,
  610. // Replaces superfluous `elseif` with `if`.
  611. 'no_superfluous_elseif' => true,
  612. /*
  613. * Removes `@param`, `@return` and `@var` tags that don't provide
  614. * any useful information.
  615. */
  616. 'no_superfluous_phpdoc_tags' => false,
  617. // Remove trailing commas in list function calls.
  618. 'no_trailing_comma_in_list_call' => true,
  619. // PHP single-line arrays should not have trailing comma.
  620. 'no_trailing_comma_in_singleline_array' => true,
  621. // Remove trailing whitespace at the end of non-blank lines.
  622. 'no_trailing_whitespace' => true,
  623. // There MUST be no trailing spaces inside comment or PHPDoc.
  624. 'no_trailing_whitespace_in_comment' => true,
  625. /*
  626. * There must be no trailing whitespace in strings.
  627. *
  628. * Risky!
  629. * Changing the whitespaces in strings might affect string
  630. * comparisons and outputs.
  631. */
  632. 'no_trailing_whitespace_in_string' => false,
  633. // Removes unneeded parentheses around control statements.
  634. 'no_unneeded_control_parentheses' => [
  635. 'statements' => [
  636. 'break',
  637. 'clone',
  638. 'continue',
  639. 'echo_print',
  640. 'return',
  641. 'switch_case',
  642. 'yield',
  643. 'yield_from',
  644. ],
  645. ],
  646. /*
  647. * Removes unneeded curly braces that are superfluous and aren't
  648. * part of a control structure's body.
  649. */
  650. 'no_unneeded_curly_braces' => [
  651. 'namespaces' => true,
  652. ],
  653. /*
  654. * A `final` class must not have `final` methods and `private`
  655. * methods must not be `final`.
  656. *
  657. * Risky!
  658. * Risky when child class overrides a `private` method.
  659. */
  660. 'no_unneeded_final_method' => true,
  661. /*
  662. * In function arguments there must not be arguments with default
  663. * values before non-default ones.
  664. *
  665. * Risky!
  666. * Modifies the signature of functions; therefore risky when using
  667. * systems (such as some Symfony components) that rely on those (for
  668. * example through reflection).
  669. */
  670. 'no_unreachable_default_argument_value' => false,
  671. // Variables must be set `null` instead of using `(unset)` casting.
  672. 'no_unset_cast' => true,
  673. /*
  674. * Properties should be set to `null` instead of using `unset`.
  675. *
  676. * Risky!
  677. * Risky when relying on attributes to be removed using `unset`
  678. * rather than be set to `null`. Changing variables to `null`
  679. * instead of unsetting means these still show up when looping over
  680. * class variables and reference properties remain unbroken. With
  681. * PHP 7.4, this rule might introduce `null` assignments to
  682. * properties whose type declaration does not allow it.
  683. */
  684. 'no_unset_on_property' => true,
  685. // Unused `use` statements must be removed.
  686. 'no_unused_imports' => true,
  687. // There should not be useless `else` cases.
  688. 'no_useless_else' => true,
  689. /*
  690. * There should not be an empty `return` statement at the end of a
  691. * function.
  692. */
  693. 'no_useless_return' => true,
  694. /*
  695. * There must be no `sprintf` calls with only the first argument.
  696. *
  697. * Risky!
  698. * Risky when if the `sprintf` function is overridden.
  699. */
  700. 'no_useless_sprintf' => true,
  701. /*
  702. * In array declaration, there MUST NOT be a whitespace before each
  703. * comma.
  704. */
  705. 'no_whitespace_before_comma_in_array' => true,
  706. // Remove trailing whitespace at the end of blank lines.
  707. 'no_whitespace_in_blank_line' => true,
  708. /*
  709. * Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and
  710. * other invisible unicode symbols.
  711. *
  712. * Risky!
  713. * Risky when strings contain intended invisible characters.
  714. */
  715. 'non_printable_character' => true,
  716. // Array index should always be written by using square braces.
  717. 'normalize_index_brace' => true,
  718. /*
  719. * Logical NOT operators (`!`) should have leading and trailing
  720. * whitespaces.
  721. */
  722. 'not_operator_with_space' => false,
  723. // Logical NOT operators (`!`) should have one trailing whitespace.
  724. 'not_operator_with_successor_space' => false,
  725. /*
  726. * Adds or removes `?` before type declarations for parameters with
  727. * a default `null` value.
  728. *
  729. * Rule is applied only in a PHP 7.1+ environment.
  730. */
  731. 'nullable_type_declaration_for_default_null_value' => false,
  732. /*
  733. * There should not be space before or after object operators `->`
  734. * and `?->`.
  735. */
  736. 'object_operator_without_whitespace' => true,
  737. /*
  738. * Operators - when multiline - must always be at the beginning or
  739. * at the end of the line.
  740. */
  741. 'operator_linebreak' => true,
  742. // Orders the elements of classes/interfaces/traits.
  743. 'ordered_class_elements' => [
  744. 'order' => [
  745. 'use_trait',
  746. 'constant_public',
  747. 'constant_protected',
  748. 'constant_private',
  749. 'property_public',
  750. 'property_protected',
  751. 'property_private',
  752. 'construct',
  753. 'destruct',
  754. 'magic',
  755. 'phpunit',
  756. ],
  757. ],
  758. // Ordering `use` statements.
  759. 'ordered_imports' => [
  760. 'sort_algorithm' => 'alpha',
  761. 'imports_order' => [
  762. 'class',
  763. 'const',
  764. 'function',
  765. ],
  766. ],
  767. /*
  768. * Orders the interfaces in an `implements` or `interface extends`
  769. * clause.
  770. *
  771. * Risky!
  772. * Risky for `implements` when specifying both an interface and its
  773. * parent interface, because PHP doesn't break on `parent, child`
  774. * but does on `child, parent`.
  775. */
  776. 'ordered_interfaces' => false,
  777. /*
  778. * Trait `use` statements must be sorted alphabetically.
  779. *
  780. * Risky!
  781. * Risky when depending on order of the imports.
  782. */
  783. 'ordered_traits' => false,
  784. /*
  785. * PHPUnit assertion method calls like `->assertSame(true, $foo)`
  786. * should be written with dedicated method like
  787. * `->assertTrue($foo)`.
  788. *
  789. * Risky!
  790. * Fixer could be risky if one is overriding PHPUnit's native
  791. * methods.
  792. */
  793. 'php_unit_construct' => true,
  794. /*
  795. * PHPUnit assertions like `assertInternalType`, `assertFileExists`,
  796. * should be used over `assertTrue`.
  797. *
  798. * Risky!
  799. * Fixer could be risky if one is overriding PHPUnit's native
  800. * methods.
  801. */
  802. 'php_unit_dedicate_assert' => true,
  803. /*
  804. * PHPUnit assertions like `assertIsArray` should be used over
  805. * `assertInternalType`.
  806. *
  807. * Risky!
  808. * Risky when PHPUnit methods are overridden or when project has
  809. * PHPUnit incompatibilities.
  810. */
  811. 'php_unit_dedicate_assert_internal_type' => true,
  812. /*
  813. * Usages of `->setExpectedException*` methods MUST be replaced by
  814. * `->expectException*` methods.
  815. *
  816. * Risky!
  817. * Risky when PHPUnit classes are overridden or not accessible, or
  818. * when project has PHPUnit incompatibilities.
  819. */
  820. 'php_unit_expectation' => [
  821. 'target' => '5.6',
  822. ],
  823. // PHPUnit annotations should be a FQCNs including a root namespace.
  824. 'php_unit_fqcn_annotation' => true,
  825. // All PHPUnit test classes should be marked as internal.
  826. 'php_unit_internal_class' => true,
  827. /*
  828. * Enforce camel (or snake) case for PHPUnit test methods, following
  829. * configuration.
  830. */
  831. 'php_unit_method_casing' => true,
  832. /*
  833. * Usages of `->getMock` and
  834. * `->getMockWithoutInvokingTheOriginalConstructor` methods MUST be
  835. * replaced by `->createMock` or `->createPartialMock` methods.
  836. *
  837. * Risky!
  838. * Risky when PHPUnit classes are overridden or not accessible, or
  839. * when project has PHPUnit incompatibilities.
  840. */
  841. 'php_unit_mock' => true,
  842. /*
  843. * Usage of PHPUnit's mock e.g. `->will($this->returnValue(..))`
  844. * must be replaced by its shorter equivalent such as
  845. * `->willReturn(...)`.
  846. *
  847. * Risky!
  848. * Risky when PHPUnit classes are overridden or not accessible, or
  849. * when project has PHPUnit incompatibilities.
  850. */
  851. 'php_unit_mock_short_will_return' => true,
  852. /*
  853. * PHPUnit classes MUST be used in namespaced version, e.g.
  854. * `\PHPUnit\Framework\TestCase` instead of
  855. * `\PHPUnit_Framework_TestCase`.
  856. *
  857. * PHPUnit v6 has finally fully switched to namespaces.
  858. * You could start preparing the upgrade by switching from
  859. * non-namespaced TestCase to namespaced one.
  860. * Forward compatibility layer (`\PHPUnit\Framework\TestCase` class)
  861. * was backported to PHPUnit v4.8.35 and PHPUnit v5.4.0.
  862. * Extended forward compatibility layer (`PHPUnit\Framework\Assert`,
  863. * `PHPUnit\Framework\BaseTestListener`,
  864. * `PHPUnit\Framework\TestListener` classes) was introduced in
  865. * v5.7.0.
  866. *
  867. * Risky!
  868. * Risky when PHPUnit classes are overridden or not accessible, or
  869. * when project has PHPUnit incompatibilities.
  870. */
  871. 'php_unit_namespaced' => true,
  872. /*
  873. * Usages of `@expectedException*` annotations MUST be replaced by
  874. * `->setExpectedException*` methods.
  875. *
  876. * Risky!
  877. * Risky when PHPUnit classes are overridden or not accessible, or
  878. * when project has PHPUnit incompatibilities.
  879. */
  880. 'php_unit_no_expectation_annotation' => [
  881. 'target' => 'newest',
  882. ],
  883. /*
  884. * Changes the visibility of the `setUp()` and `tearDown()`
  885. * functions of PHPUnit to `protected`, to match the PHPUnit
  886. * TestCase.
  887. *
  888. * Risky!
  889. * This fixer may change functions named `setUp()` or `tearDown()`
  890. * outside of PHPUnit tests, when a class is wrongly seen as a
  891. * PHPUnit test.
  892. */
  893. 'php_unit_set_up_tear_down_visibility' => true,
  894. /*
  895. * All PHPUnit test cases should have `@small`, `@medium` or
  896. * `@large` annotation to enable run time limits.
  897. *
  898. * The special groups [small, medium, large] provides a way to
  899. * identify tests that are taking long to be executed.
  900. */
  901. 'php_unit_size_class' => true,
  902. /*
  903. * PHPUnit methods like `assertSame` should be used instead of
  904. * `assertEquals`.
  905. *
  906. * Risky!
  907. * Risky when any of the functions are overridden or when testing
  908. * object equality.
  909. */
  910. 'php_unit_strict' => false,
  911. /*
  912. * Adds or removes @test annotations from tests, following
  913. * configuration.
  914. *
  915. * Risky!
  916. * This fixer may change the name of your tests, and could cause
  917. * incompatibility with abstract classes or interfaces.
  918. */
  919. 'php_unit_test_annotation' => true,
  920. /*
  921. * Calls to `PHPUnit\Framework\TestCase` static methods must all be
  922. * of the same type, either `$this->`, `self::` or `static::`.
  923. *
  924. * Risky!
  925. * Risky when PHPUnit methods are overridden or not accessible, or
  926. * when project has PHPUnit incompatibilities.
  927. */
  928. 'php_unit_test_case_static_method_calls' => true,
  929. /*
  930. * Adds a default `@coversNothing` annotation to PHPUnit test
  931. * classes that have no `@covers*` annotation.
  932. */
  933. 'php_unit_test_class_requires_covers' => false,
  934. // PHPDoc should contain `@param` for all params.
  935. 'phpdoc_add_missing_param_annotation' => [
  936. 'only_untyped' => false,
  937. ],
  938. /*
  939. * All items of the given phpdoc tags must be either left-aligned or
  940. * (by default) aligned vertically.
  941. */
  942. 'phpdoc_align' => true,
  943. // PHPDoc annotation descriptions should not be a sentence.
  944. 'phpdoc_annotation_without_dot' => true,
  945. /*
  946. * Docblocks should have the same indentation as the documented
  947. * subject.
  948. */
  949. 'phpdoc_indent' => true,
  950. // Fixes PHPDoc inline tags.
  951. 'phpdoc_inline_tag_normalizer' => true,
  952. /*
  953. * Changes doc blocks from single to multi line, or reversed. Works
  954. * for class constants, properties and methods only.
  955. */
  956. 'phpdoc_line_span' => [
  957. 'const' => 'single',
  958. 'property' => 'single',
  959. 'method' => 'multi',
  960. ],
  961. // `@access` annotations should be omitted from PHPDoc.
  962. 'phpdoc_no_access' => true,
  963. // No alias PHPDoc tags should be used.
  964. 'phpdoc_no_alias_tag' => true,
  965. /*
  966. * `@return void` and `@return null` annotations should be omitted
  967. * from PHPDoc.
  968. */
  969. 'phpdoc_no_empty_return' => true,
  970. /*
  971. * `@package` and `@subpackage` annotations should be omitted from
  972. * PHPDoc.
  973. */
  974. 'phpdoc_no_package' => true,
  975. // Classy that does not inherit must not have `@inheritdoc` tags.
  976. 'phpdoc_no_useless_inheritdoc' => true,
  977. /*
  978. * Annotations in PHPDoc should be ordered so that `@param`
  979. * annotations come first, then `@throws` annotations, then
  980. * `@return` annotations.
  981. */
  982. 'phpdoc_order' => true,
  983. // Order phpdoc tags by value.
  984. 'phpdoc_order_by_value' => [
  985. 'annotations' => [
  986. 'covers',
  987. 'method',
  988. 'property',
  989. 'property-read',
  990. 'property-write',
  991. ],
  992. ],
  993. /*
  994. * The type of `@return` annotations of methods returning a
  995. * reference to itself must the configured one.
  996. */
  997. 'phpdoc_return_self_reference' => true,
  998. /*
  999. * Scalar types should always be written in the same form. `int` not
  1000. * `integer`, `bool` not `boolean`, `float` not `real` or `double`.
  1001. */
  1002. 'phpdoc_scalar' => true,
  1003. /*
  1004. * Annotations in PHPDoc should be grouped together so that
  1005. * annotations of the same type immediately follow each other, and
  1006. * annotations of a different type are separated by a single blank
  1007. * line.
  1008. */
  1009. 'phpdoc_separation' => true,
  1010. // Single line `@var` PHPDoc should have proper spacing.
  1011. 'phpdoc_single_line_var_spacing' => true,
  1012. /*
  1013. * PHPDoc summary should end in either a full stop, exclamation
  1014. * mark, or question mark.
  1015. */
  1016. 'phpdoc_summary' => true,
  1017. // Fixes casing of PHPDoc tags.
  1018. 'phpdoc_tag_casing' => true,
  1019. // Forces PHPDoc tags to be either regular annotations or inline.
  1020. 'phpdoc_tag_type' => [
  1021. 'tags' => [
  1022. 'inheritDoc' => 'inline',
  1023. ],
  1024. ],
  1025. // Docblocks should only be used on structural elements.
  1026. 'phpdoc_to_comment' => false,
  1027. /*
  1028. * EXPERIMENTAL: Takes `@param` annotations of non-mixed types and
  1029. * adjusts accordingly the function signature. Requires PHP >= 7.0.
  1030. *
  1031. * Risky!
  1032. * This rule is EXPERIMENTAL and [1] is not covered with backward
  1033. * compatibility promise. [2] `@param` annotation is mandatory for
  1034. * the fixer to make changes, signatures of methods without it (no
  1035. * docblock, inheritdocs) will not be fixed. [3] Manual actions are
  1036. * required if inherited signatures are not properly documented.
  1037. */
  1038. 'phpdoc_to_param_type' => false,
  1039. /*
  1040. * EXPERIMENTAL: Takes `@var` annotation of non-mixed types and
  1041. * adjusts accordingly the property signature. Requires PHP >= 7.4.
  1042. *
  1043. * Risky!
  1044. * This rule is EXPERIMENTAL and [1] is not covered with backward
  1045. * compatibility promise. [2] `@var` annotation is mandatory for the
  1046. * fixer to make changes, signatures of properties without it (no
  1047. * docblock) will not be fixed. [3] Manual actions might be required
  1048. * for newly typed properties that are read before initialization.
  1049. */
  1050. 'phpdoc_to_property_type' => false,
  1051. /*
  1052. * EXPERIMENTAL: Takes `@return` annotation of non-mixed types and
  1053. * adjusts accordingly the function signature. Requires PHP >= 7.0.
  1054. *
  1055. * Risky!
  1056. * This rule is EXPERIMENTAL and [1] is not covered with backward
  1057. * compatibility promise. [2] `@return` annotation is mandatory for
  1058. * the fixer to make changes, signatures of methods without it (no
  1059. * docblock, inheritdocs) will not be fixed. [3] Manual actions are
  1060. * required if inherited signatures are not properly documented.
  1061. */
  1062. 'phpdoc_to_return_type' => false,
  1063. /*
  1064. * PHPDoc should start and end with content, excluding the very
  1065. * first and last line of the docblocks.
  1066. */
  1067. 'phpdoc_trim' => true,
  1068. /*
  1069. * Removes extra blank lines after summary and after description in
  1070. * PHPDoc.
  1071. */
  1072. 'phpdoc_trim_consecutive_blank_line_separation' => true,
  1073. // The correct case must be used for standard PHP types in PHPDoc.
  1074. 'phpdoc_types' => true,
  1075. // Sorts PHPDoc types.
  1076. 'phpdoc_types_order' => [
  1077. 'sort_algorithm' => 'none',
  1078. 'null_adjustment' => 'always_last',
  1079. ],
  1080. /*
  1081. * `@var` and `@type` annotations must have type and name in the
  1082. * correct order.
  1083. */
  1084. 'phpdoc_var_annotation_correct_order' => true,
  1085. /*
  1086. * `@var` and `@type` annotations of classy properties should not
  1087. * contain the name.
  1088. */
  1089. 'phpdoc_var_without_name' => false,
  1090. /*
  1091. * Converts `pow` to the `**` operator.
  1092. *
  1093. * Risky!
  1094. * Risky when the function `pow` is overridden.
  1095. */
  1096. 'pow_to_exponentiation' => true,
  1097. /*
  1098. * Converts `protected` variables and methods to `private` where
  1099. * possible.
  1100. */
  1101. 'protected_to_private' => true,
  1102. /*
  1103. * Classes must be in a path that matches their namespace, be at
  1104. * least one namespace deep and the class name should match the file
  1105. * name.
  1106. *
  1107. * Risky!
  1108. * This fixer may change your class name, which will break the code
  1109. * that depends on the old name.
  1110. */
  1111. 'psr_autoloading' => false,
  1112. /*
  1113. * Replaces `rand`, `srand`, `getrandmax` functions calls with their
  1114. * `mt_*` analogs.
  1115. *
  1116. * Risky!
  1117. * Risky when the configured functions are overridden.
  1118. */
  1119. 'random_api_migration' => [
  1120. 'replacements' => [
  1121. 'mt_rand' => 'random_int',
  1122. 'rand' => 'random_int',
  1123. ],
  1124. ],
  1125. /*
  1126. * Callables must be called without using `call_user_func*` when
  1127. * possible.
  1128. *
  1129. * Risky!
  1130. * Risky when the `call_user_func` or `call_user_func_array`
  1131. * function is overridden or when are used in constructions that
  1132. * should be avoided, like `call_user_func_array('foo', ['bar' =>
  1133. * 'baz'])` or `call_user_func($foo, $foo = 'bar')`.
  1134. */
  1135. 'regular_callable_call' => true,
  1136. /*
  1137. * Local, dynamic and directly referenced variables should not be
  1138. * assigned and directly returned by a function or method.
  1139. */
  1140. 'return_assignment' => true,
  1141. /*
  1142. * There should be one or no space before colon, and one space after
  1143. * it in return type declarations, according to configuration.
  1144. *
  1145. * Rule is applied only in a PHP 7+ environment.
  1146. */
  1147. 'return_type_declaration' => true,
  1148. /*
  1149. * Inside class or interface element `self` should be preferred to
  1150. * the class name itself.
  1151. *
  1152. * Risky!
  1153. * Risky when using dynamic calls like get_called_class() or late
  1154. * static binding.
  1155. */
  1156. 'self_accessor' => true,
  1157. /*
  1158. * Inside a `final` class or anonymous class `self` should be
  1159. * preferred to `static`.
  1160. */
  1161. 'self_static_accessor' => true,
  1162. // Instructions must be terminated with a semicolon.
  1163. 'semicolon_after_instruction' => true,
  1164. /*
  1165. * Cast shall be used, not `settype`.
  1166. *
  1167. * Risky!
  1168. * Risky when the `settype` function is overridden or when used as
  1169. * the 2nd or 3rd expression in a `for` loop .
  1170. */
  1171. 'set_type_to_cast' => true,
  1172. /*
  1173. * Cast `(boolean)` and `(integer)` should be written as `(bool)`
  1174. * and `(int)`, `(double)` and `(real)` as `(float)`, `(binary)` as
  1175. * `(string)`.
  1176. */
  1177. 'short_scalar_cast' => true,
  1178. /*
  1179. * Converts explicit variables in double-quoted strings and heredoc
  1180. * syntax from simple to complex format (`${` to `{$`).
  1181. *
  1182. * Doesn't touch implicit variables. Works together nicely with
  1183. * `explicit_string_variable`.
  1184. */
  1185. 'simple_to_complex_string_variable' => true,
  1186. /*
  1187. * Simplify `if` control structures that return the boolean result
  1188. * of their condition.
  1189. */
  1190. 'simplified_if_return' => true,
  1191. /*
  1192. * A return statement wishing to return `void` should not return
  1193. * `null`.
  1194. */
  1195. 'simplified_null_return' => false,
  1196. /*
  1197. * A PHP file without end tag must always end with a single empty
  1198. * line feed.
  1199. */
  1200. 'single_blank_line_at_eof' => true,
  1201. /*
  1202. * There should be exactly one blank line before a namespace
  1203. * declaration.
  1204. */
  1205. 'single_blank_line_before_namespace' => true,
  1206. /*
  1207. * There MUST NOT be more than one property or constant declared per
  1208. * statement.
  1209. */
  1210. 'single_class_element_per_statement' => true,
  1211. // There MUST be one use keyword per declaration.
  1212. 'single_import_per_statement' => true,
  1213. /*
  1214. * Each namespace use MUST go on its own line and there MUST be one
  1215. * blank line after the use statements block.
  1216. */
  1217. 'single_line_after_imports' => true,
  1218. /*
  1219. * Single-line comments and multi-line comments with only one line
  1220. * of actual content should use the `//` syntax.
  1221. */
  1222. 'single_line_comment_style' => true,
  1223. // Throwing exception must be done in single line.
  1224. 'single_line_throw' => false,
  1225. // Convert double quotes to single quotes for simple strings.
  1226. 'single_quote' => [
  1227. 'strings_containing_single_quote_chars' => false,
  1228. ],
  1229. // Ensures a single space after language constructs.
  1230. 'single_space_after_construct' => true,
  1231. // Each trait `use` must be done as single statement.
  1232. 'single_trait_insert_per_statement' => true,
  1233. // Fix whitespace after a semicolon.
  1234. 'space_after_semicolon' => true,
  1235. // Increment and decrement operators should be used if possible.
  1236. 'standardize_increment' => true,
  1237. // Replace all `<>` with `!=`.
  1238. 'standardize_not_equals' => true,
  1239. /*
  1240. * Lambdas not (indirect) referencing `$this` must be declared
  1241. * `static`.
  1242. *
  1243. * Risky!
  1244. * Risky when using `->bindTo` on lambdas without referencing to
  1245. * `$this`.
  1246. */
  1247. 'static_lambda' => true,
  1248. /*
  1249. * Comparisons should be strict.
  1250. *
  1251. * Risky!
  1252. * Changing comparisons to strict might change code behavior.
  1253. */
  1254. 'strict_comparison' => false,
  1255. /*
  1256. * Functions should be used with `$strict` param set to `true`.
  1257. *
  1258. * The functions "array_keys", "array_search", "base64_decode",
  1259. * "in_array" and "mb_detect_encoding" should be used with $strict
  1260. * param.
  1261. *
  1262. * Risky!
  1263. * Risky when the fixed function is overridden or if the code relies
  1264. * on non-strict usage.
  1265. */
  1266. 'strict_param' => false,
  1267. /*
  1268. * All multi-line strings must use correct line ending.
  1269. *
  1270. * Risky!
  1271. * Changing the line endings of multi-line strings might affect
  1272. * string comparisons and outputs.
  1273. */
  1274. 'string_line_ending' => true,
  1275. // A case should be followed by a colon and not a semicolon.
  1276. 'switch_case_semicolon_to_colon' => true,
  1277. // Removes extra spaces between colon and case value.
  1278. 'switch_case_space' => true,
  1279. // Switch case must not be ended with `continue` but with `break`.
  1280. 'switch_continue_to_break' => true,
  1281. // Standardize spaces around ternary operator.
  1282. 'ternary_operator_spaces' => true,
  1283. /*
  1284. * Use the Elvis operator `?:` where possible.
  1285. *
  1286. * Risky!
  1287. * Risky when relying on functions called on both sides of the `?`
  1288. * operator.
  1289. */
  1290. 'ternary_to_elvis_operator' => true,
  1291. /*
  1292. * Use `null` coalescing operator `??` where possible. Requires PHP
  1293. * >= 7.0.
  1294. */
  1295. 'ternary_to_null_coalescing' => true,
  1296. /*
  1297. * Multi-line arrays, arguments list and parameters list must have a
  1298. * trailing comma.
  1299. */
  1300. 'trailing_comma_in_multiline' => true,
  1301. /*
  1302. * Arrays should be formatted like function/method arguments,
  1303. * without leading or trailing single line space.
  1304. */
  1305. 'trim_array_spaces' => true,
  1306. // Unary operators should be placed adjacent to their operands.
  1307. 'unary_operator_spaces' => true,
  1308. /*
  1309. * Anonymous functions with one-liner return statement must use
  1310. * arrow functions.
  1311. *
  1312. * Risky!
  1313. * Risky when using `isset()` on outside variables that are not
  1314. * imported with `use ()`.
  1315. */
  1316. 'use_arrow_functions' => false,
  1317. /*
  1318. * Visibility MUST be declared on all properties and methods;
  1319. * `abstract` and `final` MUST be declared before the visibility;
  1320. * `static` MUST be declared after the visibility.
  1321. */
  1322. 'visibility_required' => [
  1323. 'elements' => [
  1324. 'method',
  1325. 'property',
  1326. ],
  1327. ],
  1328. /*
  1329. * Add `void` return type to functions with missing or empty return
  1330. * statements, but priority is given to `@return` annotations.
  1331. * Requires PHP >= 7.1.
  1332. *
  1333. * Risky!
  1334. * Modifies the signature of functions.
  1335. */
  1336. 'void_return' => false,
  1337. /*
  1338. * In array declaration, there MUST be a whitespace after each
  1339. * comma.
  1340. */
  1341. 'whitespace_after_comma_in_array' => true,
  1342. /*
  1343. * Write conditions in Yoda style (`true`), non-Yoda style
  1344. * (`['equal' => false, 'identical' => false, 'less_and_greater' =>
  1345. * false]`) or ignore those conditions (`null`) based on
  1346. * configuration.
  1347. */
  1348. 'yoda_style' => [
  1349. 'equal' => false,
  1350. 'identical' => false,
  1351. 'less_and_greater' => false,
  1352. ],
  1353. ];
  1354. if (\PHP_SAPI === 'cli' && !class_exists(\PhpCsFixer\Config::class)) {
  1355. $binFixer = __DIR__ . '/vendor/bin/php-cs-fixer';
  1356. if (!is_file($binFixer)) {
  1357. $binFixer = 'php-cs-fixer';
  1358. }
  1359. $dryRun = !in_array('--force', $_SERVER['argv'], true);
  1360. $command = escapeshellarg($binFixer) . ' fix --config ' . escapeshellarg(__FILE__) . ' --diff --ansi -vv';
  1361. if ($dryRun) {
  1362. $command .= ' --dry-run';
  1363. }
  1364. system($command, $returnCode);
  1365. if ($dryRun || $returnCode === 8) {
  1366. fwrite(\STDOUT, "\n\e[1;40;93m\e[K\n");
  1367. fwrite(\STDOUT, " [DEBUG] Dry run php-cs-fixer config.\e[K\n");
  1368. fwrite(\STDOUT, " Only shows which files would have been modified.\e[K\n");
  1369. fwrite(\STDOUT, " To apply the rules, use the --force option:\e[K\n\e[K\n");
  1370. fwrite(\STDOUT, " \e[1;40;92mphp {$_SERVER['argv'][0]} --force\e[K\n\e[0m\n");
  1371. } elseif ($returnCode !== 0) {
  1372. fwrite(\STDERR, "\n\e[1;41;97m\e[K\n ERROR CODE: {$returnCode}\e[K\n\e[0m\n");
  1373. }
  1374. exit($returnCode);
  1375. }
  1376. return (new \PhpCsFixer\Config())
  1377. ->setUsingCache(true)
  1378. ->setCacheFile(__DIR__ . '/.php-cs-fixer.cache')
  1379. ->setRules($rules)
  1380. ->setRiskyAllowed(true)
  1381. ->setFinder(
  1382. \PhpCsFixer\Finder::create()
  1383. ->ignoreUnreadableDirs()
  1384. ->in(__DIR__)
  1385. )
  1386. ;