NoPhp4ConstructorFixerTest.php 17 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261
  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\ClassNotation;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. /**
  15. * @author Matteo Beccati <matteo@beccati.com>
  16. *
  17. * @internal
  18. *
  19. * @covers \PhpCsFixer\Fixer\ClassNotation\NoPhp4ConstructorFixer
  20. */
  21. final class NoPhp4ConstructorFixerTest extends AbstractFixerTestCase
  22. {
  23. /**
  24. * @dataProvider provideFix70Cases
  25. * @requires PHP 7.0
  26. */
  27. public function testFix70(string $expected, ?string $input = null): void
  28. {
  29. $this->doTest($expected, $input);
  30. }
  31. public function provideFix70Cases()
  32. {
  33. return [
  34. [
  35. '<?php $a = new class {};',
  36. ],
  37. [
  38. '<?php $a = new class {}?>',
  39. ],
  40. [
  41. '<?php
  42. $a = new Foo() <=> 1;
  43. $a = new Foo <=> 1;
  44. $a = new class() {};
  45. $a = new class() implements Foo{};
  46. $a = new class() /**/ extends Bar1{};
  47. $a = new class() extends Bar2 implements Foo{};
  48. $a = new class() extends Bar3 implements Foo, Foo2{};
  49. $a = new class() {};
  50. $a = new class {};
  51. $a = new class implements Foo{};
  52. $a = new class /**/ extends Bar1{};
  53. $a = new class extends Bar2 implements Foo{};
  54. $a = new class extends Bar3 implements Foo, Foo2{};
  55. $a = new class {}?>
  56. ',
  57. ],
  58. ];
  59. }
  60. /**
  61. * @dataProvider provideSimpleCases
  62. */
  63. public function testSimpleClass(string $expected, ?string $input = null): void
  64. {
  65. $this->doTest($expected, $input);
  66. }
  67. public function provideSimpleCases()
  68. {
  69. return [
  70. [
  71. <<<'EOF'
  72. <?php
  73. class Foo
  74. {
  75. public function __construct($bar)
  76. {
  77. var_dump(1);
  78. }
  79. }
  80. EOF
  81. ,
  82. <<<'EOF'
  83. <?php
  84. class Foo
  85. {
  86. public function Foo($bar)
  87. {
  88. var_dump(1);
  89. }
  90. }
  91. EOF
  92. ],
  93. [
  94. <<<'EOF'
  95. <?php
  96. class Foo
  97. {
  98. public#
  99. function#
  100. __construct#
  101. (#
  102. $bar#
  103. )#
  104. {}
  105. }
  106. EOF
  107. ,
  108. <<<'EOF'
  109. <?php
  110. class Foo
  111. {
  112. public#
  113. function#
  114. Foo#
  115. (#
  116. $bar#
  117. )#
  118. {}
  119. }
  120. EOF
  121. ],
  122. ];
  123. }
  124. public function testNamespaces(): void
  125. {
  126. $expected = <<<'EOF'
  127. <?php
  128. namespace Baz\Qux;
  129. class Foo
  130. {
  131. public function __construct($bar)
  132. {
  133. var_dump(1);
  134. }
  135. public function Foo($bar)
  136. {
  137. var_dump(2);
  138. }
  139. }
  140. EOF;
  141. $this->doTest($expected);
  142. }
  143. public function testNamespaces2(): void
  144. {
  145. $expected = <<<'EOF'
  146. <?php
  147. namespace Baz\Qux
  148. {
  149. class Foo
  150. {
  151. public function __construct($bar)
  152. {
  153. var_dump(1);
  154. }
  155. public function Foo($bar)
  156. {
  157. var_dump(2);
  158. }
  159. }
  160. class Bar
  161. {
  162. public function Bar()
  163. {
  164. var_dump(3);
  165. }
  166. }
  167. }
  168. EOF;
  169. $this->doTest($expected);
  170. }
  171. public function testNamespaceGlobal(): void
  172. {
  173. $expected = <<<'EOF'
  174. <?php
  175. namespace {
  176. class Foo
  177. {
  178. function __construct($bar)
  179. {
  180. var_dump(1);
  181. }
  182. }
  183. }
  184. EOF;
  185. $input = <<<'EOF'
  186. <?php
  187. namespace {
  188. class Foo
  189. {
  190. function Foo($bar)
  191. {
  192. var_dump(1);
  193. }
  194. }
  195. }
  196. EOF;
  197. $this->doTest($expected, $input);
  198. }
  199. public function testPhp5Only(): void
  200. {
  201. $expected = <<<'EOF'
  202. <?php
  203. class Foo
  204. {
  205. function __construct($bar)
  206. {
  207. var_dump(1);
  208. }
  209. function bar()
  210. {
  211. var_dump(3);
  212. }
  213. }
  214. EOF;
  215. $this->doTest($expected);
  216. }
  217. public function testPhp4Only(): void
  218. {
  219. $expected = <<<'EOF'
  220. <?php
  221. class Foo
  222. {
  223. /**
  224. * Constructor
  225. */
  226. function __construct($bar)
  227. {
  228. var_dump(1);
  229. }
  230. function bar()
  231. {
  232. var_dump(3);
  233. }
  234. }
  235. EOF;
  236. $input = <<<'EOF'
  237. <?php
  238. class Foo
  239. {
  240. /**
  241. * Constructor
  242. */
  243. function foO($bar)
  244. {
  245. var_dump(1);
  246. }
  247. function bar()
  248. {
  249. var_dump(3);
  250. }
  251. }
  252. EOF;
  253. $this->doTest($expected, $input);
  254. }
  255. public function testBothTheRightWay1(): void
  256. {
  257. $expected = <<<'EOF'
  258. <?php
  259. class Foo
  260. {
  261. /**
  262. * Constructor
  263. */
  264. public function __construct()
  265. {
  266. var_dump(1);
  267. }
  268. public function bar()
  269. {
  270. var_dump(3);
  271. }
  272. }
  273. EOF;
  274. $input = <<<'EOF'
  275. <?php
  276. class Foo
  277. {
  278. /**
  279. * Constructor
  280. */
  281. public function __construct()
  282. {
  283. var_dump(1);
  284. }
  285. /**
  286. * PHP-4 Constructor
  287. */
  288. function Foo()
  289. {
  290. // Call PHP5!
  291. $this->__construct();
  292. }
  293. public function bar()
  294. {
  295. var_dump(3);
  296. }
  297. }
  298. EOF;
  299. $this->doTest($expected, $input);
  300. }
  301. public function testBothTheRightWay2(): void
  302. {
  303. $expected = <<<'EOF'
  304. <?php
  305. class Foo
  306. {
  307. /**
  308. * Constructor
  309. */
  310. public function __construct($bar)
  311. {
  312. var_dump(1);
  313. }
  314. public function bar()
  315. {
  316. var_dump(3);
  317. }
  318. }
  319. EOF;
  320. $input = <<<'EOF'
  321. <?php
  322. class Foo
  323. {
  324. /**
  325. * Constructor
  326. */
  327. public function __construct($bar)
  328. {
  329. var_dump(1);
  330. }
  331. /**
  332. * PHP-4 Constructor
  333. */
  334. function Foo($bar)
  335. {
  336. // Call PHP5!
  337. $this->__construct($bar);
  338. }
  339. public function bar()
  340. {
  341. var_dump(3);
  342. }
  343. }
  344. EOF;
  345. $this->doTest($expected, $input);
  346. }
  347. public function testBothTheRightWay3(): void
  348. {
  349. $expected = <<<'EOF'
  350. <?php
  351. class Foo
  352. {
  353. /**
  354. * Constructor
  355. */
  356. public function __construct($bar = 1, $baz = null)
  357. {
  358. var_dump(1);
  359. }
  360. public function bar()
  361. {
  362. var_dump(3);
  363. }
  364. }
  365. EOF;
  366. $input = <<<'EOF'
  367. <?php
  368. class Foo
  369. {
  370. /**
  371. * Constructor
  372. */
  373. public function __construct($bar = 1, $baz = null)
  374. {
  375. var_dump(1);
  376. }
  377. /**
  378. * PHP-4 Constructor
  379. */
  380. function Foo($bar = 1, $baz = null)
  381. {
  382. // Call PHP5!
  383. $this->__construct($bar, $baz);
  384. }
  385. public function bar()
  386. {
  387. var_dump(3);
  388. }
  389. }
  390. EOF;
  391. $this->doTest($expected, $input);
  392. }
  393. public function testBothTheOtherWayAround(): void
  394. {
  395. $expected = <<<'EOF'
  396. <?php
  397. class Foo
  398. {
  399. /**
  400. * PHP-4 Constructor.
  401. *
  402. * This is the real constructor. It's the one that most likely contains any meaningful info in the docblock.
  403. */
  404. private function __construct($bar)
  405. {
  406. var_dump(1);
  407. }
  408. function bar()
  409. {
  410. var_dump(3);
  411. }
  412. }
  413. EOF;
  414. $input = <<<'EOF'
  415. <?php
  416. class Foo
  417. {
  418. /**
  419. * PHP-5 Constructor.
  420. *
  421. * This docblock is removed, along with the entire wrapper method.
  422. */
  423. protected function __construct($bar)
  424. {
  425. // Call The Real Constructor, not the hippy fake one!
  426. $this->Foo($bar);
  427. }
  428. /**
  429. * PHP-4 Constructor.
  430. *
  431. * This is the real constructor. It's the one that most likely contains any meaningful info in the docblock.
  432. */
  433. private function Foo($bar)
  434. {
  435. var_dump(1);
  436. }
  437. function bar()
  438. {
  439. var_dump(3);
  440. }
  441. }
  442. EOF;
  443. $this->doTest($expected, $input);
  444. }
  445. public function testPhp4Parent(): void
  446. {
  447. $expected = <<<'EOF'
  448. <?php
  449. class Foo extends FooParEnt
  450. {
  451. /**
  452. * Constructor
  453. */
  454. function __construct($bar)
  455. {
  456. parent::__construct(1);
  457. var_dump(9);
  458. }
  459. function bar()
  460. {
  461. var_dump(3);
  462. }
  463. }
  464. EOF;
  465. $input = <<<'EOF'
  466. <?php
  467. class Foo extends FooParEnt
  468. {
  469. /**
  470. * Constructor
  471. */
  472. function Foo($bar)
  473. {
  474. parent::FooPaRent(1);
  475. var_dump(9);
  476. }
  477. function bar()
  478. {
  479. var_dump(3);
  480. }
  481. }
  482. EOF;
  483. $this->doTest($expected, $input);
  484. }
  485. public function testPhp4ParentInit(): void
  486. {
  487. $expected = <<<'EOF'
  488. <?php
  489. class Foo extends FooParent
  490. {
  491. /**
  492. * Constructor
  493. */
  494. function __construct($bar)
  495. {
  496. parent::init(1);
  497. var_dump(9);
  498. }
  499. function bar()
  500. {
  501. var_dump(3);
  502. }
  503. }
  504. EOF;
  505. $input = <<<'EOF'
  506. <?php
  507. class Foo extends FooParent
  508. {
  509. /**
  510. * Constructor
  511. */
  512. function Foo($bar)
  513. {
  514. parent::init(1);
  515. var_dump(9);
  516. }
  517. function bar()
  518. {
  519. var_dump(3);
  520. }
  521. }
  522. EOF;
  523. $this->doTest($expected, $input);
  524. }
  525. public function testMixedParent(): void
  526. {
  527. $expected = <<<'EOF'
  528. <?php
  529. class Foo extends FooParent
  530. {
  531. /**
  532. * Constructor
  533. */
  534. function __construcT($bar)
  535. {
  536. parent::__construct(1);
  537. var_dump(9);
  538. }
  539. function bar()
  540. {
  541. var_dump(3);
  542. }
  543. }
  544. EOF;
  545. $input = <<<'EOF'
  546. <?php
  547. class Foo extends FooParent
  548. {
  549. /**
  550. * Constructor
  551. */
  552. function __construcT($bar)
  553. {
  554. parent::FooParenT(1);
  555. var_dump(9);
  556. }
  557. function bar()
  558. {
  559. var_dump(3);
  560. }
  561. }
  562. EOF;
  563. $this->doTest($expected, $input);
  564. }
  565. public function testMixedParent2(): void
  566. {
  567. $expected = <<<'EOF'
  568. <?php
  569. class Foo extends FooParent
  570. {
  571. /**
  572. * Constructor
  573. */
  574. function __construcT($bar)
  575. {
  576. parent::__construct(1);
  577. var_dump(9);
  578. }
  579. function bar()
  580. {
  581. var_dump(3);
  582. }
  583. }
  584. EOF;
  585. $input = <<<'EOF'
  586. <?php
  587. class Foo extends FooParent
  588. {
  589. /**
  590. * Constructor
  591. */
  592. function __construcT($bar)
  593. {
  594. $this->FooParenT(1);
  595. var_dump(9);
  596. }
  597. function bar()
  598. {
  599. var_dump(3);
  600. }
  601. }
  602. EOF;
  603. $this->doTest($expected, $input);
  604. }
  605. public function testParentOther(): void
  606. {
  607. $expected = <<<'EOF'
  608. <?php
  609. class Foo extends FooParent
  610. {
  611. /**
  612. * Constructor
  613. */
  614. function __construct($bar)
  615. {
  616. parent::__construct(1);
  617. var_dump(9);
  618. }
  619. function bar()
  620. {
  621. var_dump(3);
  622. }
  623. }
  624. EOF;
  625. $input = <<<'EOF'
  626. <?php
  627. class Foo extends FooParent
  628. {
  629. /**
  630. * Constructor
  631. */
  632. function Foo($bar)
  633. {
  634. $this->FooParent(1);
  635. var_dump(9);
  636. }
  637. function bar()
  638. {
  639. var_dump(3);
  640. }
  641. }
  642. EOF;
  643. $this->doTest($expected, $input);
  644. }
  645. public function testParentOther2(): void
  646. {
  647. $expected = <<<'EOF'
  648. <?php
  649. class Foo extends FooParent
  650. {
  651. /**
  652. * Constructor
  653. */
  654. function __construct($bar)
  655. {
  656. parent::__construct(1);
  657. var_dump(9);
  658. }
  659. function bar()
  660. {
  661. var_dump(3);
  662. }
  663. }
  664. EOF;
  665. $input = <<<'EOF'
  666. <?php
  667. class Foo extends FooParent
  668. {
  669. /**
  670. * Constructor
  671. */
  672. function Foo($bar)
  673. {
  674. FooParent::FooParent(1);
  675. var_dump(9);
  676. }
  677. function bar()
  678. {
  679. var_dump(3);
  680. }
  681. }
  682. EOF;
  683. $this->doTest($expected, $input);
  684. }
  685. public function testClassWithAnonymous(): void
  686. {
  687. $expected = <<<'EOF'
  688. <?php
  689. class Foo {
  690. private $bar;
  691. public function __construct()
  692. {
  693. $this->bar = function () {};
  694. }
  695. }
  696. EOF;
  697. $input = <<<'EOF'
  698. <?php
  699. class Foo {
  700. private $bar;
  701. public function Foo()
  702. {
  703. $this->bar = function () {};
  704. }
  705. }
  706. EOF;
  707. $this->doTest($expected, $input);
  708. }
  709. public function testClassWithComments(): void
  710. {
  711. $expected = <<<'EOF'
  712. <?php
  713. class /* test */
  714. // another
  715. Foo {
  716. public function /* test */ __construct($param) {
  717. }
  718. }
  719. EOF;
  720. $input = <<<'EOF'
  721. <?php
  722. class /* test */
  723. // another
  724. Foo {
  725. public function /* test */ Foo($param) {
  726. }
  727. }
  728. EOF;
  729. $this->doTest($expected, $input);
  730. }
  731. public function testAlphaBeta(): void
  732. {
  733. $expected = <<<'EOF'
  734. <?php
  735. class Foo
  736. {
  737. public function Foo()
  738. {
  739. echo 'alpha';
  740. }
  741. public function __construct()
  742. {
  743. echo 'beta';
  744. }
  745. }
  746. EOF;
  747. $this->doTest($expected);
  748. }
  749. public function testAlphaBetaTrick1(): void
  750. {
  751. $expected = <<<'EOF'
  752. <?php
  753. class Foo
  754. {
  755. public function Foo()
  756. {
  757. // This is not $this->__construct()
  758. echo 'alpha';
  759. }
  760. public function __construct()
  761. {
  762. echo 'beta';
  763. }
  764. }
  765. EOF;
  766. $this->doTest($expected);
  767. }
  768. public function testAlphaBetaTrick2(): void
  769. {
  770. $expected = <<<'EOF'
  771. <?php
  772. class Foo
  773. {
  774. public function Foo()
  775. {
  776. echo 'alpha';
  777. }
  778. public function __construct()
  779. {
  780. // This is not $this->Foo()
  781. echo 'beta';
  782. }
  783. }
  784. EOF;
  785. $this->doTest($expected);
  786. }
  787. public function testAlphaBetaTrick3(): void
  788. {
  789. $expected = <<<'EOF'
  790. <?php
  791. class Foo
  792. {
  793. public function Foo()
  794. {
  795. echo 'alpha';
  796. /* yeah, ok let's construct it anyway */
  797. $this->__construct();
  798. }
  799. public function __construct()
  800. {
  801. echo 'beta';
  802. }
  803. }
  804. EOF;
  805. $this->doTest($expected);
  806. }
  807. public function testAlphaBetaTrick4WithAnotherClass(): void
  808. {
  809. $expected = <<<'EOF'
  810. <?php
  811. class Foo
  812. {
  813. public function Foo()
  814. {
  815. echo 'alpha';
  816. }
  817. public function __construct()
  818. {
  819. $this->Foo();
  820. // Do something more!
  821. echo 'beta';
  822. }
  823. }
  824. Class Bar
  825. {
  826. function __construct()
  827. {
  828. $this->foo = 1;
  829. }
  830. }
  831. EOF;
  832. $input = <<<'EOF'
  833. <?php
  834. class Foo
  835. {
  836. public function Foo()
  837. {
  838. echo 'alpha';
  839. }
  840. public function __construct()
  841. {
  842. $this->Foo();
  843. // Do something more!
  844. echo 'beta';
  845. }
  846. }
  847. Class Bar
  848. {
  849. function bar()
  850. {
  851. $this->foo = 1;
  852. }
  853. }
  854. EOF;
  855. $this->doTest($expected, $input);
  856. }
  857. public function testAbstract(): void
  858. {
  859. $expected = <<<'EOF'
  860. <?php
  861. abstract class Foo
  862. {
  863. abstract function Foo();
  864. }
  865. EOF;
  866. $this->doTest($expected);
  867. }
  868. public function testAbstractTrick(): void
  869. {
  870. $expected = <<<'EOF'
  871. <?php
  872. abstract class Foo
  873. {
  874. abstract public function Foo();
  875. public function bar()
  876. {
  877. // This is messed up, I know
  878. $this->__construct();
  879. }
  880. public function __construct()
  881. {
  882. $this->baz = 1;
  883. }
  884. }
  885. EOF;
  886. $this->doTest($expected);
  887. }
  888. public function testParentMultipleClasses(): void
  889. {
  890. $expected = <<<'EOF'
  891. <?php
  892. class Class1 extends Parent1
  893. {
  894. function __construct($foo)
  895. {
  896. parent::__construct();
  897. echo "something";
  898. }
  899. }
  900. class Class2 extends Parent2
  901. {
  902. function __construct($foo)
  903. {
  904. echo "something";
  905. }
  906. }
  907. ?>
  908. EOF;
  909. $input = <<<'EOF'
  910. <?php
  911. class Class1 extends Parent1
  912. {
  913. function __construct($foo)
  914. {
  915. $this->Parent1();
  916. echo "something";
  917. }
  918. }
  919. class Class2 extends Parent2
  920. {
  921. function __construct($foo)
  922. {
  923. echo "something";
  924. }
  925. }
  926. ?>
  927. EOF;
  928. $this->doTest($expected, $input);
  929. }
  930. public function testInfiniteRecursion(): void
  931. {
  932. $expected = <<<'EOF'
  933. <?php
  934. class Parent1
  935. {
  936. function __construct()
  937. {
  938. echo "foobar";
  939. }
  940. }
  941. class Class1 extends Parent1
  942. {
  943. function __construct($foo)
  944. {
  945. parent::__construct();
  946. echo "something";
  947. }
  948. }
  949. ?>
  950. EOF;
  951. $input = <<<'EOF'
  952. <?php
  953. class Parent1
  954. {
  955. function __construct()
  956. {
  957. echo "foobar";
  958. }
  959. }
  960. class Class1 extends Parent1
  961. {
  962. function Class1($foo)
  963. {
  964. $this->__construct();
  965. echo "something";
  966. }
  967. }
  968. ?>
  969. EOF;
  970. $this->doTest($expected, $input);
  971. }
  972. /**
  973. * @dataProvider provideFixPhp80Cases
  974. * @requires PHP 8.0
  975. */
  976. public function testFixPhp80(string $expected, ?string $input = null): void
  977. {
  978. $this->doTest($expected, $input);
  979. }
  980. public function provideFixPhp80Cases()
  981. {
  982. yield [
  983. <<<'EOF'
  984. <?php
  985. class Foo
  986. {
  987. public function __construct($bar,)
  988. {
  989. var_dump(1);
  990. }
  991. }
  992. EOF
  993. ,
  994. <<<'EOF'
  995. <?php
  996. class Foo
  997. {
  998. public function Foo($bar,)
  999. {
  1000. var_dump(1);
  1001. }
  1002. }
  1003. EOF
  1004. ];
  1005. yield [
  1006. '<?php
  1007. class Foo
  1008. {
  1009. public function __construct()
  1010. {
  1011. }
  1012. }',
  1013. '<?php
  1014. class Foo
  1015. {
  1016. public function Foo()
  1017. {
  1018. }
  1019. }',
  1020. ];
  1021. yield [
  1022. '<?php
  1023. class Foo
  1024. {
  1025. public function __construct()
  1026. {
  1027. $this?->__construct();
  1028. }
  1029. }',
  1030. '<?php
  1031. class Foo
  1032. {
  1033. public function Foo()
  1034. {
  1035. $this?->__construct();
  1036. }
  1037. }',
  1038. ];
  1039. yield [
  1040. '<?php
  1041. class Foo extends Bar
  1042. {
  1043. public function __construct()
  1044. {
  1045. parent::__construct();
  1046. }
  1047. }',
  1048. '<?php
  1049. class Foo extends Bar
  1050. {
  1051. public function Foo()
  1052. {
  1053. $this?->Bar();
  1054. }
  1055. }',
  1056. ];
  1057. yield [
  1058. '<?php
  1059. class Foo
  1060. {
  1061. /**
  1062. * Constructor
  1063. */
  1064. public function __construct($bar = 1, $baz = null)
  1065. {
  1066. var_dump(1);
  1067. }
  1068. }
  1069. ',
  1070. '<?php
  1071. class Foo
  1072. {
  1073. /**
  1074. * Constructor
  1075. */
  1076. public function __construct($bar = 1, $baz = null)
  1077. {
  1078. var_dump(1);
  1079. }
  1080. /**
  1081. * PHP-4 Constructor
  1082. */
  1083. function Foo($bar = 1, $baz = null)
  1084. {
  1085. $this?->__construct($bar, $baz);
  1086. }
  1087. }
  1088. ',
  1089. ];
  1090. }
  1091. }