.php_cs 44 KB

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