2
0

.php-cs-fixer.php 51 KB

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