.php_cs 44 KB

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