PhpdocParamOrderFixerTest.php 28 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036
  1. <?php
  2. declare(strict_types=1);
  3. /*
  4. * This file is part of PHP CS Fixer.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. namespace PhpCsFixer\Tests\Fixer\Phpdoc;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Jonathan Gruber <gruberjonathan@gmail.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\Phpdoc\PhpdocParamOrderFixer
  20. */
  21. final class PhpdocParamOrderFixerTest extends AbstractFixerTestCase
  22. {
  23. public function testNoChanges(): void
  24. {
  25. $expected = <<<'EOT'
  26. <?php
  27. class C {
  28. /**
  29. * @param $a
  30. */
  31. public function m($a) {}
  32. }
  33. EOT;
  34. $this->doTest($expected);
  35. }
  36. public function testNoChangesMultiple(): void
  37. {
  38. $expected = <<<'EOT'
  39. <?php
  40. class C {
  41. /**
  42. * @param string $a
  43. * @param bool $b
  44. */
  45. public function m($a, $b) {}
  46. }
  47. EOT;
  48. $this->doTest($expected);
  49. }
  50. public function testOnlyParamsUntyped(): void
  51. {
  52. $expected = <<<'EOT'
  53. <?php
  54. class C {
  55. /**
  56. * @param $a
  57. * @param $b
  58. * @param $c
  59. * @param $d
  60. * @param $e
  61. */
  62. public function m($a, $b, $c, $d, $e) {}
  63. }
  64. EOT;
  65. $input = <<<'EOT'
  66. <?php
  67. class C {
  68. /**
  69. * @param $b
  70. * @param $e
  71. * @param $a
  72. * @param $c
  73. * @param $d
  74. */
  75. public function m($a, $b, $c, $d, $e) {}
  76. }
  77. EOT;
  78. $this->doTest($expected, $input);
  79. }
  80. public function testOnlyParamsUntypedMixed(): void
  81. {
  82. $expected = <<<'EOT'
  83. <?php
  84. class C {
  85. /**
  86. * @param int $a
  87. * @param $b
  88. * @param $c
  89. * @param bool $d
  90. * @param $e
  91. */
  92. public function m($a, $b, $c, $d, $e) {}
  93. }
  94. EOT;
  95. $input = <<<'EOT'
  96. <?php
  97. class C {
  98. /**
  99. * @param $c
  100. * @param $e
  101. * @param int $a
  102. * @param $b
  103. * @param bool $d
  104. */
  105. public function m($a, $b, $c, $d, $e) {}
  106. }
  107. EOT;
  108. $this->doTest($expected, $input);
  109. }
  110. public function testOnlyParamsTyped(): void
  111. {
  112. $expected = <<<'EOT'
  113. <?php
  114. class C {
  115. /**
  116. * @param string $a
  117. * @param bool $b
  118. * @param string $c
  119. * @param string $d
  120. * @param int $e
  121. */
  122. public function m($a, $b, $c, $d, $e) {}
  123. }
  124. EOT;
  125. $input = <<<'EOT'
  126. <?php
  127. class C {
  128. /**
  129. * @param bool $b
  130. * @param string $a
  131. * @param string $c
  132. * @param int $e
  133. * @param string $d
  134. */
  135. public function m($a, $b, $c, $d, $e) {}
  136. }
  137. EOT;
  138. $this->doTest($expected, $input);
  139. }
  140. public function testOnlyParamsUndocumented(): void
  141. {
  142. $expected = <<<'EOT'
  143. <?php
  144. class C {
  145. /**
  146. * @param $a
  147. * @param $b
  148. * @param $c
  149. * @param $d
  150. */
  151. public function m($a, $b, $c, $d, $e, $f) {}
  152. }
  153. EOT;
  154. $input = <<<'EOT'
  155. <?php
  156. class C {
  157. /**
  158. * @param $a
  159. * @param $c
  160. * @param $d
  161. * @param $b
  162. */
  163. public function m($a, $b, $c, $d, $e, $f) {}
  164. }
  165. EOT;
  166. $this->doTest($expected, $input);
  167. }
  168. public function testOnlyParamsSuperfluousAnnotation(): void
  169. {
  170. $expected = <<<'EOT'
  171. <?php
  172. class C {
  173. /**
  174. * @param $a
  175. * @param $b
  176. * @param $c
  177. * @param $superfluous
  178. */
  179. public function m($a, $b, $c) {}
  180. }
  181. EOT;
  182. $input = <<<'EOT'
  183. <?php
  184. class C {
  185. /**
  186. * @param $a
  187. * @param $superfluous
  188. * @param $b
  189. * @param $c
  190. */
  191. public function m($a, $b, $c) {}
  192. }
  193. EOT;
  194. $this->doTest($expected, $input);
  195. }
  196. public function testOnlyParamsSuperfluousAnnotations(): void
  197. {
  198. $expected = <<<'EOT'
  199. <?php
  200. class C {
  201. /**
  202. * @param $a
  203. * @param $b
  204. * @param $c
  205. * @param $superfluous2
  206. * @param $superfluous1
  207. * @param $superfluous3
  208. */
  209. public function m($a, $b, $c) {}
  210. }
  211. EOT;
  212. $input = <<<'EOT'
  213. <?php
  214. class C {
  215. /**
  216. * @param $a
  217. * @param $superfluous2
  218. * @param $b
  219. * @param $superfluous1
  220. * @param $c
  221. * @param $superfluous3
  222. */
  223. public function m($a, $b, $c) {}
  224. }
  225. EOT;
  226. $this->doTest($expected, $input);
  227. }
  228. public function testParamsUntyped(): void
  229. {
  230. $expected = <<<'EOT'
  231. <?php
  232. class C {
  233. /**
  234. * Some function
  235. *
  236. * @param $a
  237. * @param $b
  238. * @param $c
  239. *
  240. * @throws \Exception
  241. *
  242. * @return bool
  243. */
  244. public function m($a, $b, $c, $d, $e) {}
  245. }
  246. EOT;
  247. $input = <<<'EOT'
  248. <?php
  249. class C {
  250. /**
  251. * Some function
  252. *
  253. * @param $b
  254. * @param $c
  255. * @param $a
  256. *
  257. * @throws \Exception
  258. *
  259. * @return bool
  260. */
  261. public function m($a, $b, $c, $d, $e) {}
  262. }
  263. EOT;
  264. $this->doTest($expected, $input);
  265. }
  266. public function testParamsTyped(): void
  267. {
  268. $expected = <<<'EOT'
  269. <?php
  270. class C {
  271. /**
  272. * Some function
  273. *
  274. * @param Foo $a
  275. * @param int $b
  276. * @param bool $c
  277. *
  278. * @throws \Exception
  279. *
  280. * @return bool
  281. */
  282. public function m($a, $b, $c, $d, $e) {}
  283. }
  284. EOT;
  285. $input = <<<'EOT'
  286. <?php
  287. class C {
  288. /**
  289. * Some function
  290. *
  291. * @param int $b
  292. * @param bool $c
  293. * @param Foo $a
  294. *
  295. * @throws \Exception
  296. *
  297. * @return bool
  298. */
  299. public function m($a, $b, $c, $d, $e) {}
  300. }
  301. EOT;
  302. $this->doTest($expected, $input);
  303. }
  304. public function testParamsDescription(): void
  305. {
  306. $expected = <<<'EOT'
  307. <?php
  308. class C {
  309. /**
  310. * Some function
  311. *
  312. * @param Foo $a A parameter
  313. * @param int $b B parameter
  314. * @param bool $c C parameter
  315. *
  316. * @throws \Exception
  317. *
  318. * @return bool
  319. */
  320. public function m($a, $b, $c, $d, $e) {}
  321. }
  322. EOT;
  323. $input = <<<'EOT'
  324. <?php
  325. class C {
  326. /**
  327. * Some function
  328. *
  329. * @param int $b B parameter
  330. * @param bool $c C parameter
  331. * @param Foo $a A parameter
  332. *
  333. * @throws \Exception
  334. *
  335. * @return bool
  336. */
  337. public function m($a, $b, $c, $d, $e) {}
  338. }
  339. EOT;
  340. $this->doTest($expected, $input);
  341. }
  342. public function testParamsMultilineDescription(): void
  343. {
  344. $expected = <<<'EOT'
  345. <?php
  346. class C {
  347. /**
  348. * Some function
  349. *
  350. * @param Foo $a A parameter
  351. * @param int $b B parameter
  352. * @param bool $c Another multiline, longer
  353. * description of C parameter
  354. * @param bool $d Multiline description
  355. * of D parameter
  356. *
  357. * @throws \Exception
  358. *
  359. * @return bool
  360. */
  361. public function m($a, $b, $c, $d) {}
  362. }
  363. EOT;
  364. $input = <<<'EOT'
  365. <?php
  366. class C {
  367. /**
  368. * Some function
  369. *
  370. * @param int $b B parameter
  371. * @param bool $d Multiline description
  372. * of D parameter
  373. * @param bool $c Another multiline, longer
  374. * description of C parameter
  375. * @param Foo $a A parameter
  376. *
  377. * @throws \Exception
  378. *
  379. * @return bool
  380. */
  381. public function m($a, $b, $c, $d) {}
  382. }
  383. EOT;
  384. $this->doTest($expected, $input);
  385. }
  386. public function testComplexTypes(): void
  387. {
  388. $expected = <<<'EOT'
  389. <?php
  390. class C {
  391. /**
  392. * @param Foo[]|\Bar\Baz $a
  393. * @param Foo|Bar $b
  394. * @param array<int, FooInterface>|string $c
  395. * @param array<array{int, int}> $d
  396. * @param ?Foo $e
  397. * @param \Closure(( $b is Bar ? bool : int)): $this $f
  398. */
  399. public function m($a, $b, $c, $d, $e, $f) {}
  400. }
  401. EOT;
  402. $input = <<<'EOT'
  403. <?php
  404. class C {
  405. /**
  406. * @param array<int, FooInterface>|string $c
  407. * @param Foo|Bar $b
  408. * @param array<array{int, int}> $d
  409. * @param ?Foo $e
  410. * @param \Closure(( $b is Bar ? bool : int)): $this $f
  411. * @param Foo[]|\Bar\Baz $a
  412. */
  413. public function m($a, $b, $c, $d, $e, $f) {}
  414. }
  415. EOT;
  416. $this->doTest($expected, $input);
  417. }
  418. public function testVariousMethodDeclarations(): void
  419. {
  420. $expected = <<<'EOT'
  421. <?php
  422. abstract class C {
  423. /**
  424. * @param Foo $a
  425. * @param array $b
  426. * @param $c
  427. * @param mixed $d
  428. */
  429. final public static function m1(Foo $a, array $b, $c, $d) {}
  430. /**
  431. * @param array $a
  432. * @param $b
  433. * @throws Exception
  434. *
  435. * @return bool
  436. */
  437. abstract public function m2(array $a, $b);
  438. /**
  439. * Description of
  440. * method
  441. *
  442. * @param int $a
  443. * @param Foo $b
  444. * @param $c
  445. * @param Bar $d
  446. * @param string $e
  447. */
  448. protected static function m3($a, Foo $b, $c, Bar $d, $e) {}
  449. /**
  450. * @see Something
  451. *
  452. * @param callable $a
  453. * @param $b
  454. * @param array $c
  455. * @param array $d
  456. *
  457. * @return int
  458. *
  459. * Text
  460. */
  461. final protected function m4(Callable $a, $b, array $c, array $d) {}
  462. /**
  463. * @param Bar $a
  464. * @param Bar $b
  465. * @param $c
  466. * @param int $d
  467. * @param array $e
  468. * @param $f
  469. *
  470. * @return Foo|null
  471. */
  472. abstract protected function m5(Bar $a, Bar $b, $c, $d, array $e, $f);
  473. /**
  474. * @param array $a
  475. * @param $b
  476. */
  477. private function m6(array $a, $b) {}
  478. /**
  479. * @param Foo $a
  480. * @param array $b
  481. * @param mixed $c
  482. */
  483. private static function m7(Foo $a, array $b, $c) {}
  484. }
  485. EOT;
  486. $input = <<<'EOT'
  487. <?php
  488. abstract class C {
  489. /**
  490. * @param array $b
  491. * @param Foo $a
  492. * @param mixed $d
  493. * @param $c
  494. */
  495. final public static function m1(Foo $a, array $b, $c, $d) {}
  496. /**
  497. * @param $b
  498. * @param array $a
  499. * @throws Exception
  500. *
  501. * @return bool
  502. */
  503. abstract public function m2(array $a, $b);
  504. /**
  505. * Description of
  506. * method
  507. *
  508. * @param string $e
  509. * @param int $a
  510. * @param Foo $b
  511. * @param Bar $d
  512. * @param $c
  513. */
  514. protected static function m3($a, Foo $b, $c, Bar $d, $e) {}
  515. /**
  516. * @see Something
  517. *
  518. * @param $b
  519. * @param array $d
  520. * @param array $c
  521. * @param callable $a
  522. *
  523. * @return int
  524. *
  525. * Text
  526. */
  527. final protected function m4(Callable $a, $b, array $c, array $d) {}
  528. /**
  529. * @param Bar $b
  530. * @param $f
  531. * @param int $d
  532. * @param array $e
  533. * @param $c
  534. * @param Bar $a
  535. *
  536. * @return Foo|null
  537. */
  538. abstract protected function m5(Bar $a, Bar $b, $c, $d, array $e, $f);
  539. /**
  540. * @param $b
  541. * @param array $a
  542. */
  543. private function m6(array $a, $b) {}
  544. /**
  545. * @param array $b
  546. * @param mixed $c
  547. * @param Foo $a
  548. */
  549. private static function m7(Foo $a, array $b, $c) {}
  550. }
  551. EOT;
  552. $this->doTest($expected, $input);
  553. }
  554. public function testParamsWithOtherAnnotationsInBetween(): void
  555. {
  556. $expected = <<<'EOT'
  557. <?php
  558. /**
  559. * [c1] Method description
  560. * [c2] over multiple lines
  561. *
  562. * @see Baz
  563. *
  564. * @param int $a Long param
  565. * description
  566. * @param mixed $b
  567. * @param mixed $superflous1 With text
  568. * @param int $superflous2
  569. * @return array Long return
  570. * description
  571. * @throws Exception
  572. * @throws FooException
  573. */
  574. function foo($a, $b) {}
  575. EOT;
  576. $input = <<<'EOT'
  577. <?php
  578. /**
  579. * [c1] Method description
  580. * [c2] over multiple lines
  581. *
  582. * @see Baz
  583. *
  584. * @param mixed $b
  585. * @param mixed $superflous1 With text
  586. * @return array Long return
  587. * description
  588. * @param int $superflous2
  589. * @throws Exception
  590. * @param int $a Long param
  591. * description
  592. * @throws FooException
  593. */
  594. function foo($a, $b) {}
  595. EOT;
  596. $this->doTest($expected, $input);
  597. }
  598. public function testParamsBlankLines(): void
  599. {
  600. $expected = <<<'EOT'
  601. <?php
  602. class C {
  603. /**
  604. * Some function
  605. *
  606. * @param $a
  607. * @param $b
  608. *
  609. * @param $c
  610. *
  611. *
  612. * @param $d
  613. *
  614. * @param $e
  615. *
  616. * @throws \Exception
  617. *
  618. * @return bool
  619. */
  620. public function m($a, $b, $c, $d, $e) {}
  621. }
  622. EOT;
  623. $input = <<<'EOT'
  624. <?php
  625. class C {
  626. /**
  627. * Some function
  628. *
  629. * @param $b
  630. * @param $e
  631. *
  632. * @param $c
  633. *
  634. *
  635. * @param $a
  636. *
  637. * @param $d
  638. *
  639. * @throws \Exception
  640. *
  641. * @return bool
  642. */
  643. public function m($a, $b, $c, $d, $e) {}
  644. }
  645. EOT;
  646. $this->doTest($expected, $input);
  647. }
  648. public function testNestedPhpdoc(): void
  649. {
  650. $expected = <<<'EOT'
  651. <?php
  652. /**
  653. * @param string[] $array
  654. * @param callable $callback {
  655. * @param string $value
  656. * @param int $key
  657. * @param mixed $userdata
  658. * }
  659. * @param mixed $userdata
  660. *
  661. * @return bool
  662. */
  663. function string_array_walk(array &$array, callable $callback, $userdata = null) {}
  664. EOT;
  665. $input = <<<'EOT'
  666. <?php
  667. /**
  668. * @param callable $callback {
  669. * @param string $value
  670. * @param int $key
  671. * @param mixed $userdata
  672. * }
  673. * @param mixed $userdata
  674. * @param string[] $array
  675. *
  676. * @return bool
  677. */
  678. function string_array_walk(array &$array, callable $callback, $userdata = null) {}
  679. EOT;
  680. $this->doTest($expected, $input);
  681. }
  682. public function testMultiNestedPhpdoc(): void
  683. {
  684. $expected = <<<'EOT'
  685. <?php
  686. /**
  687. * @param string[] $a
  688. * @param callable $b {
  689. * @param string $a
  690. * @param callable {
  691. * @param string $d
  692. * @param int $a
  693. * @param callable $c {
  694. * $param string $e
  695. * }
  696. * }
  697. * @param mixed $b2
  698. * }
  699. * @param mixed $c
  700. * @param int $d
  701. *
  702. * @return bool
  703. */
  704. function m(array &$a, callable $b, $c = null, $d) {}
  705. EOT;
  706. $input = <<<'EOT'
  707. <?php
  708. /**
  709. * @param mixed $c
  710. * @param callable $b {
  711. * @param string $a
  712. * @param callable {
  713. * @param string $d
  714. * @param int $a
  715. * @param callable $c {
  716. * $param string $e
  717. * }
  718. * }
  719. * @param mixed $b2
  720. * }
  721. * @param int $d
  722. * @param string[] $a
  723. *
  724. * @return bool
  725. */
  726. function m(array &$a, callable $b, $c = null, $d) {}
  727. EOT;
  728. $this->doTest($expected, $input);
  729. }
  730. public function testMultipleNestedPhpdoc(): void
  731. {
  732. $expected = <<<'EOT'
  733. <?php
  734. /**
  735. * @param string[] $array
  736. * @param callable $callback {
  737. * @param string $value
  738. * @param int $key
  739. * @param mixed $userdata {
  740. * $param array $array
  741. * }
  742. * }
  743. * @param mixed $userdata
  744. * @param callable $foo {
  745. * @param callable {
  746. * @param string $inner1
  747. * @param int $inner2
  748. * }
  749. * @param mixed $userdata
  750. * }
  751. * @param $superflous1 Superflous
  752. * @param $superflous2 Superflous
  753. *
  754. * @return bool
  755. */
  756. function string_array_walk(array &$array, callable $callback, $userdata = null, $foo) {}
  757. EOT;
  758. $input = <<<'EOT'
  759. <?php
  760. /**
  761. * @param $superflous1 Superflous
  762. * @param callable $callback {
  763. * @param string $value
  764. * @param int $key
  765. * @param mixed $userdata {
  766. * $param array $array
  767. * }
  768. * }
  769. * @param $superflous2 Superflous
  770. * @param callable $foo {
  771. * @param callable {
  772. * @param string $inner1
  773. * @param int $inner2
  774. * }
  775. * @param mixed $userdata
  776. * }
  777. * @param mixed $userdata
  778. * @param string[] $array
  779. *
  780. * @return bool
  781. */
  782. function string_array_walk(array &$array, callable $callback, $userdata = null, $foo) {}
  783. EOT;
  784. $this->doTest($expected, $input);
  785. }
  786. public function testNonMatchingParamName(): void
  787. {
  788. $expected = <<<'EOT'
  789. <?php
  790. /**
  791. * @param Foo $fooBar
  792. * @param $fooSomethingNotMatchingTheName
  793. * @param OtherClassLorem $x
  794. */
  795. function f(Foo $fooBar, Payment $foo, OtherClassLoremIpsum $y) {}
  796. EOT;
  797. $input = <<<'EOT'
  798. <?php
  799. /**
  800. * @param $fooSomethingNotMatchingTheName
  801. * @param Foo $fooBar
  802. * @param OtherClassLorem $x
  803. */
  804. function f(Foo $fooBar, Payment $foo, OtherClassLoremIpsum $y) {}
  805. EOT;
  806. $this->doTest($expected, $input);
  807. }
  808. public function testPlainFunction(): void
  809. {
  810. $expected = <<<'EOT'
  811. <?php
  812. /**
  813. * A plain function
  814. *
  815. * @param $a
  816. * @param $b
  817. * @param $c
  818. * @param $d
  819. */
  820. function m($a, $b, $c, $d) {}
  821. EOT;
  822. $input = <<<'EOT'
  823. <?php
  824. /**
  825. * A plain function
  826. *
  827. * @param $c
  828. * @param $b
  829. * @param $d
  830. * @param $a
  831. */
  832. function m($a, $b, $c, $d) {}
  833. EOT;
  834. $this->doTest($expected, $input);
  835. }
  836. public function testCommentsInSignature(): void
  837. {
  838. $expected = <<<'EOT'
  839. <?php
  840. class C {
  841. /**
  842. * @param $a
  843. * @param $b
  844. * @param $c
  845. * @param $d
  846. */
  847. public/*1*/function/*2*/m/*3*/(/*4*/$a, $b,/*5*/$c, $d){}
  848. }
  849. EOT;
  850. $input = <<<'EOT'
  851. <?php
  852. class C {
  853. /**
  854. * @param $d
  855. * @param $a
  856. * @param $b
  857. * @param $c
  858. */
  859. public/*1*/function/*2*/m/*3*/(/*4*/$a, $b,/*5*/$c, $d){}
  860. }
  861. EOT;
  862. $this->doTest($expected, $input);
  863. }
  864. public function testClosure(): void
  865. {
  866. $expected = <<<'EOT'
  867. <?php
  868. /**
  869. * @param array $a
  870. * @param $b
  871. * @param Foo $c
  872. * @param int $d
  873. */
  874. $closure = function (array $a, $b, Foo $c, $d) {};
  875. EOT;
  876. $input = <<<'EOT'
  877. <?php
  878. /**
  879. * @param $b
  880. * @param int $d
  881. * @param Foo $c
  882. * @param array $a
  883. */
  884. $closure = function (array $a, $b, Foo $c, $d) {};
  885. EOT;
  886. $this->doTest($expected, $input);
  887. }
  888. public function testArrowFunction(): void
  889. {
  890. $expected = <<<'EOT'
  891. <?php
  892. /**
  893. * @param array $a
  894. * @param $b
  895. * @param Foo $c
  896. * @param int $d
  897. */
  898. $closure = fn (array $a, $b, Foo $c, $d) => null;
  899. EOT;
  900. $input = <<<'EOT'
  901. <?php
  902. /**
  903. * @param $b
  904. * @param int $d
  905. * @param Foo $c
  906. * @param array $a
  907. */
  908. $closure = fn (array $a, $b, Foo $c, $d) => null;
  909. EOT;
  910. $this->doTest($expected, $input);
  911. }
  912. public function testInterface(): void
  913. {
  914. $expected = <<<'EOT'
  915. <?php
  916. Interface I
  917. {
  918. /**
  919. * @param string $a
  920. * @param array $b
  921. * @param Foo $c
  922. *
  923. * @return int|null
  924. */
  925. public function foo($a, array $b, Foo $c);
  926. /**
  927. * @param array $a
  928. * @param $b
  929. *
  930. * @return bool
  931. */
  932. public static function bar(array $a, $b);
  933. }
  934. EOT;
  935. $input = <<<'EOT'
  936. <?php
  937. Interface I
  938. {
  939. /**
  940. * @param Foo $c
  941. * @param string $a
  942. * @param array $b
  943. *
  944. * @return int|null
  945. */
  946. public function foo($a, array $b, Foo $c);
  947. /**
  948. * @param $b
  949. * @param array $a
  950. *
  951. * @return bool
  952. */
  953. public static function bar(array $a, $b);
  954. }
  955. EOT;
  956. $this->doTest($expected, $input);
  957. }
  958. public function testPhp7ParamTypes(): void
  959. {
  960. $expected = <<<'EOT'
  961. <?php
  962. class C {
  963. /**
  964. * @param array $a
  965. * @param $b
  966. * @param bool $c
  967. */
  968. public function m(array $a, $b, bool $c) {}
  969. }
  970. EOT;
  971. $input = <<<'EOT'
  972. <?php
  973. class C {
  974. /**
  975. * @param $b
  976. * @param bool $c
  977. * @param array $a
  978. */
  979. public function m(array $a, $b, bool $c) {}
  980. }
  981. EOT;
  982. $this->doTest($expected, $input);
  983. }
  984. }