.php_cs 63 KB

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