.php-cs-fixer.php 51 KB

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