.php_cs 44 KB

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