123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848 |
- <?php
- declare(strict_types=1);
- /*
- * This file is part of PHP CS Fixer.
- *
- * (c) Fabien Potencier <fabien@symfony.com>
- * Dariusz Rumiński <dariusz.ruminski@gmail.com>
- *
- * This source file is subject to the MIT license that is bundled
- * with this source code in the file LICENSE.
- */
- namespace PhpCsFixer\Tests\Fixer\ControlStructure;
- use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
- /**
- * @author Sullivan Senechal <soullivaneuh@gmail.com>
- * @author Gregor Harlan <gharlan@web.de>
- *
- * @internal
- *
- * @covers \PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer
- *
- * @extends AbstractFixerTestCase<\PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer>
- *
- * @phpstan-import-type _AutogeneratedInputConfiguration from \PhpCsFixer\Fixer\ControlStructure\NoUnneededControlParenthesesFixer
- */
- final class NoUnneededControlParenthesesFixerTest extends AbstractFixerTestCase
- {
- /**
- * @dataProvider provideFixCases
- */
- public function testFix(string $expected, ?string $input = null): void
- {
- $this->fixer->configure(
- [
- 'statements' => [
- 'break',
- 'clone',
- 'continue',
- 'echo_print',
- 'return',
- 'switch_case',
- 'yield',
- 'yield_from',
- 'others',
- ],
- ],
- );
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{0: string, 1?: string, 2?: string}>
- */
- public static function provideFixCases(): iterable
- {
- yield [
- '<?php while ($x) { while ($y) { break 2; } }',
- '<?php while ($x) { while ($y) { break (2); } }',
- ];
- yield [
- '<?php while ($x) { while ($y) { break 2; } }',
- '<?php while ($x) { while ($y) { break(2); } }',
- ];
- yield [
- '<?php while ($x) { while ($y) { continue 2; } }',
- '<?php while ($x) { while ($y) { continue (2); } }',
- ];
- yield [
- '<?php while ($x) { while ($y) { continue 2; } }',
- '<?php while ($x) { while ($y) { continue(2); } }',
- ];
- yield [
- '<?php
- $var = clone ($obj1 ?: $obj2);
- $var = clone ($obj1 ? $obj1->getSubject() : $obj2);
- ',
- ];
- yield [
- '<?php clone $object;',
- '<?php clone ($object);',
- ];
- yield [
- '<?php clone new Foo();',
- '<?php clone (new Foo());',
- ];
- yield [
- '<?php
- foo(clone $a);
- foo(clone $a, 1);
- $a = $b ? clone $b : $c;
- ',
- '<?php
- foo(clone($a));
- foo(clone($a), 1);
- $a = $b ? clone($b) : $c;
- ',
- ];
- yield [
- '<?php
- echo (1 + 2) . $foo;
- print (1 + 2) . $foo;
- ',
- ];
- yield [
- '<?php echo (1 + 2) * 10, "\n";',
- ];
- yield [
- '<?php echo (1 + 2) * 10, "\n" ?>',
- ];
- yield [
- '<?php echo "foo" ?>',
- '<?php echo ("foo") ?>',
- ];
- yield [
- '<?php print "foo" ?>',
- '<?php print ("foo") ?>',
- ];
- yield [
- '<?php echo "foo2"; print "foo";',
- '<?php echo ("foo2"); print ("foo");',
- ];
- yield [
- '<?php echo "foo"; print "foo1";',
- '<?php echo("foo"); print("foo1");',
- ];
- yield [
- '<?php echo 2; print 2;',
- '<?php echo(2); print(2);',
- ];
- yield [
- '<?php
- echo $a ? $b : $c;
- echo ($a ? $b : $c) ? $d : $e;
- echo 10 * (2 + 3);
- echo ("foo"), ("bar");
- echo my_awesome_function("foo");
- echo $this->getOutput(1);
- ',
- '<?php
- echo ($a ? $b : $c);
- echo ($a ? $b : $c) ? $d : $e;
- echo 10 * (2 + 3);
- echo ("foo"), ("bar");
- echo my_awesome_function("foo");
- echo $this->getOutput(1);
- ',
- ];
- yield [
- '<?php return (1 + 2) * 10;',
- '<?php return ((1 + 2) * 10);',
- ];
- yield [
- '<?php return "prod";',
- '<?php return ("prod");',
- ];
- yield [
- '<?php return $x;',
- '<?php return($x);',
- ];
- yield [
- '<?php return 2;',
- '<?php return(2);',
- ];
- yield [
- '<?php return 2?>',
- '<?php return(2)?>',
- ];
- yield [
- '<?php
- switch ($a) {
- case "prod":
- break;
- }
- ',
- ];
- yield [
- '<?php
- switch ($a) {
- case "prod":
- break;
- }
- ',
- '<?php
- switch ($a) {
- case ("prod"):
- break;
- }
- ',
- 'switch_case',
- ];
- yield [
- '<?php
- switch ($a) {
- case $x;
- }
- ',
- '<?php
- switch ($a) {
- case($x);
- }
- ',
- ];
- yield [
- '<?php
- switch ($a) {
- case 2;
- }
- ',
- '<?php
- switch ($a) {
- case(2);
- }
- ',
- ];
- yield [
- '<?php
- $a = 5.1;
- $b = 1.0;
- switch($a) {
- case (int) $a < 1 : {
- echo "leave alone";
- break;
- }
- case $a < 2/* test */: {
- echo "fix 1";
- break;
- }
- case 3 : {
- echo "fix 2";
- break;
- }
- case /**//**/ // test
- 4
- /**///
- /**/: {
- echo "fix 3";
- break;
- }
- case ((int)$b) + 4.1: {
- echo "fix 4";
- break;
- }
- case ($b + 1) * 2: {
- echo "leave alone";
- break;
- }
- }
- ',
- '<?php
- $a = 5.1;
- $b = 1.0;
- switch($a) {
- case (int) $a < 1 : {
- echo "leave alone";
- break;
- }
- case ($a < 2)/* test */: {
- echo "fix 1";
- break;
- }
- case (3) : {
- echo "fix 2";
- break;
- }
- case /**/(/**/ // test
- 4
- /**/)//
- /**/: {
- echo "fix 3";
- break;
- }
- case (((int)$b) + 4.1): {
- echo "fix 4";
- break;
- }
- case ($b + 1) * 2: {
- echo "leave alone";
- break;
- }
- }
- ',
- 'switch_case',
- ];
- yield [
- '<?php while ($x) { while ($y) { break#
- #
- 2#
- #
- ; } }',
- '<?php while ($x) { while ($y) { break#
- (#
- 2#
- )#
- ; } }',
- ];
- yield [
- '<?php
- function foo() { yield "prod"; }
- ',
- ];
- yield [
- '<?php
- function foo() { yield (1 + 2) * 10; }
- ',
- ];
- yield [
- '<?php
- function foo() { yield (1 + 2) * 10; }
- ',
- '<?php
- function foo() { yield ((1 + 2) * 10); }
- ',
- ];
- yield [
- '<?php
- function foo() { yield "prod"; }
- ',
- '<?php
- function foo() { yield ("prod"); }
- ',
- ];
- yield [
- '<?php
- function foo() { yield 2; }
- ',
- '<?php
- function foo() { yield(2); }
- ',
- ];
- yield [
- '<?php
- function foo() { $a = (yield $x); }
- ',
- '<?php
- function foo() { $a = (yield($x)); }
- ',
- ];
- yield [
- '<?php
- $var = clone ($obj1->getSubject() ?? $obj2);
- ',
- ];
- }
- /**
- * @dataProvider provideFixAllCases
- */
- public function testFixAll(string $expected, ?string $input = null): void
- {
- $this->fixer->configure(
- [
- 'statements' => [
- 'break',
- 'clone',
- 'continue',
- 'echo_print',
- 'return',
- 'switch_case',
- 'yield',
- 'yield_from',
- 'others',
- 'negative_instanceof',
- ],
- ],
- );
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<int|string, array{0: string, 1?: string}>
- */
- public static function provideFixAllCases(): iterable
- {
- yield '===' => [
- '<?php $at = $a === $b;',
- '<?php $at = ($a) === ($b);',
- ];
- yield 'yield/from fun' => [
- '<?php
- function foo3() { $a = (yield $x); }
- function foo4() { yield from (1 + 2) * 10; }
- function foo5() { yield from "prod"; }
- function foo6() { $a = (yield $x); }
- function foo7() { yield from 2; }
- function foo8() { $a = (yield from $x); }
- ',
- '<?php
- function foo3() { $a = (yield $x); }
- function foo4() { yield from ((1 + 2) * 10); }
- function foo5() { yield from ("prod"); }
- function foo6() { $a = (yield($x)); }
- function foo7() { yield from(2); }
- function foo8() { $a = (yield from($x)); }
- ',
- ];
- yield 'clone stuff' => [
- '<?php
- clone new $f[0];
- $a1 = clone new foo;
- $a2 = clone new foo();
- $a3 = [clone $f];
- $a4 = [1, clone $f];
- $a5 = [clone $f, 2];
- $a6 = [1, clone $f, 2];
- $c1 = fn() => clone $z;
- for ( clone new Bar(1+2) ; $i < 100; ++$i) {
- $i = foo();
- }
- clone $object2[0]->foo()[2] /* 1 */ ?>',
- '<?php
- clone (new $f[0]);
- $a1 = clone (new foo);
- $a2 = clone (new foo());
- $a3 = [clone ($f)];
- $a4 = [1, clone ($f)];
- $a5 = [clone ($f), 2];
- $a6 = [1, clone ($f), 2];
- $c1 = fn() => clone ($z);
- for ( clone(new Bar(1+2) ); $i < 100; ++$i) {
- $i = foo();
- }
- clone ($object2[0]->foo()[2]) /* 1 */ ?>',
- ];
- yield 'print unary wrapped sequence' => [
- '<?php $b7 =[ print !$a ,];',
- '<?php $b7 =[ print !($a) ,];',
- ];
- yield 'print - sequence' => [
- '<?php
- $b7 =[ print $a, 1];
- $b7 =[1, print $a];
- ',
- '<?php
- $b7 =[ print ($a), 1];
- $b7 =[1, print ($a)];
- ',
- ];
- yield 'print - wrapped block' => [
- '<?php $b7 =[ print $a ];',
- '<?php $b7 =[ print ($a) ];',
- ];
- yield 'print fun' => [
- '<?php
- for ( print $b+1; foo(); ++$i ) {}
- for( print $b+1; foo(); ++$i ) {}
- $b1 = $c[print $e+5];
- $b2 = [1, print $e++];
- $b3 = [print $e+9, 1];
- $b4 = [1, 1 + print $e, 1];
- $b51 = fn() => print $b."something";
- $b52 = fn() => print $b."else";
- $b6 = foo(print $a);
- $b7 =[ print $a ,];
- $b8 =[ print ($a+1) . "1" ,];
- ',
- '<?php
- for ( (print $b+1); foo(); ++$i ) {}
- for( print ($b+1); foo(); ++$i ) {}
- $b1 = $c[(print $e+5)];
- $b2 = [1, (print $e++)];
- $b3 = [(print $e+9), 1];
- $b4 = [1, (1 + print $e), 1];
- $b51 = fn() => (print $b."something");
- $b52 = fn() => print ($b."else");
- $b6 = foo(print ($a));
- $b7 =[ (print ($a)) ,];
- $b8 =[ (print ($a+1) . "1") ,];
- ',
- ];
- yield 'simple' => [
- '<?php $aw?><?php $av;',
- '<?php ($aw)?><?php ($av);',
- ];
- yield 'simple, echo open tag' => [
- '<?= $a;',
- '<?= ($a);',
- ];
- yield '+ (X),' => [
- '<?php $bw = [1 + !!$a, 2 + $b,];',
- '<?php $bw = [1 + !!($a), 2 + ($b),];',
- ];
- yield 'op ns' => [
- '<?php $aq = A\B::c . $d;',
- '<?php $aq = (A\B::c) . $d;',
- ];
- yield 'wrapped FN' => [
- '<?php $fn1 = fn($x) => $x + $y;',
- '<?php $fn1 = fn($x) => ($x + $y);',
- ];
- yield 'wrapped FN 2 with pre and reference' => [
- '<?php $fn1 = fn & ($x) => !$x;',
- '<?php $fn1 = fn & ($x) => !($x);',
- ];
- yield 'wrapped FN with `,`' => [
- '<?php
- $fn1 = array_map(fn() => 1, $array);
- $fn2 = array_map($array, fn() => 2);
- $fn3 = array_map($array, fn() => 3, $array);
- ',
- '<?php
- $fn1 = array_map(fn() => (1), $array);
- $fn2 = array_map($array, fn() => (2));
- $fn3 = array_map($array, fn() => (3), $array);
- ',
- ];
- yield 'wrapped FN with return type' => [
- '<?php
- $fn8 = fn(): int => 123456;
- ',
- '<?php
- $fn8 = fn(): int => (123456);
- ',
- ];
- yield 'wrapped `for` elements' => [
- '<?php
- for (!$a; $a < 10; ++$a){
- echo $a;
- }
- ',
- '<?php
- for (!($a); ($a < 10); (++$a)){
- echo $a;
- }
- ',
- ];
- $statements = [
- 'echo',
- 'print',
- 'return',
- 'throw',
- 'yield from',
- 'yield',
- ];
- foreach ($statements as $statement) {
- yield $statement.', no op, space' => [
- '<?php function foo(){ '.$statement.' $e; }',
- '<?php function foo(){ '.$statement.' ($e); }',
- ];
- yield $statement.', wrapped op, no space' => [
- '<?php function foo(){;'.$statement.' $e.$f; }',
- '<?php function foo(){;'.$statement.'($e.$f); }',
- ];
- }
- yield 'yield wrapped unary' => [
- '<?php $a = function($a) {yield ++$a;};',
- '<?php $a = function($a) {yield (++$a);};',
- ];
- $constants = [
- '__CLASS__',
- '__DIR__',
- '__FILE__',
- '__FUNCTION__',
- '__LINE__',
- '__METHOD__',
- '__NAMESPACE__',
- '__TRAIT__',
- ];
- foreach ($constants as $constant) {
- yield $constant.'+ op' => [
- \sprintf('<?php $a = %s . $b;', $constant),
- \sprintf('<?php $a = (%s) . $b;', $constant),
- ];
- }
- yield 'break/continue' => [
- '<?php
- while(foo() && $f) {
- while(bar()) {
- if ($a) {
- break 2;
- } else {
- continue 2;
- }
- }
- }
- ',
- '<?php
- while((foo() && $f)) {
- while(bar()) {
- if ($a) {
- break (2);
- } else {
- continue (2);
- }
- }
- }
- ',
- ];
- yield 'switch case' => [
- '<?php switch($a) {
- case 1: echo 1;
- case !$a; echo 2;
- }',
- '<?php switch($a) {
- case(1): echo 1;
- case !($a); echo 2;
- }',
- ];
- yield 'switch case II' => [
- '<?php
- switch ($x) {
- case $a + 1 + 3:
- break;
- case 1 + $a + 4:
- break;
- }
- ',
- '<?php
- switch ($x) {
- case ($a) + 1 + 3:
- break;
- case 1 + ($a) + 4:
- break;
- }
- ',
- ];
- yield 'bin pre bin' => [
- '<?php $t = 1+ $i +1;',
- '<?php $t = 1+($i)+1;',
- ];
- yield 'bin, (X))' => [
- '<?php $ap = 1 + $a;',
- '<?php $ap = 1 + ($a);',
- ];
- yield 'bin close tag' => [
- '<?php $d + 2; ?>',
- '<?php ($d) + 2; ?>',
- ];
- yield 'bin after open echo' => [
- '<?= $d - 55;',
- '<?= ($d) - 55;',
- ];
- yield 'more bin + sequences combinations' => [
- '<?php
- $b1 = [1 + $d];
- $b2 = [1 + $d,];
- $b3 = [1,1 + $d + 1];
- $b4 = [1,1 + $d,];
- ',
- '<?php
- $b1 = [1 + ($d)];
- $b2 = [1 + ($d),];
- $b3 = [1,1 + ($d) + 1];
- $b4 = [1,1 + ($d),];
- ',
- ];
- yield 'bin doggybag' => [
- '<?php
- while(foo()[1]){bar();}
- $aR . "";
- $e = [$a] + $b;
- $f = [$a] + $b[1];
- $a = $b + !$c + $d;
- $b = !$a[1]++;
- $c = $c + !!!(bool) -$a;
- throw $b . "";
- ',
- '<?php
- while((foo())[1]){bar();}
- ($aR) . "";
- $e = [$a] + ($b);
- $f = [$a] + ($b)[1];
- $a = $b + !($c) + $d;
- $b = !($a)[1]++;
- $c = $c + !!!(bool) -($a);
- throw($b) . "";
- ',
- ];
- $statements = [
- 'while(foo()){echo 1;}',
- ';;;;',
- 'echo',
- 'print',
- 'return',
- 'throw',
- '',
- ];
- foreach ($statements as $statement) {
- yield $statement.' (X) bin' => [
- '<?php '.$statement.' $e . "foo";',
- '<?php '.$statement.' ($e) . "foo";',
- ];
- }
- yield 'bin after' => [
- '<?php
- $d * 5;
- ; $a - $b;
- while(foo() + 1 < 100){} $z - 6 ?>',
- '<?php
- ($d) * 5;
- ; ($a) - $b;
- while((foo()) + 1 < 100){} ($z) - 6 ?>',
- ];
- yield 'bin after throw/return' => [
- '<?php
- function foo() {
- if($b) {
- throw $e . "";
- }
- return ((string)$dd)[1] . "a";
- }',
- '<?php
- function foo() {
- if(($b)) {
- throw($e) . "";
- }
- return(((string)$dd)[1] . "a");
- }',
- ];
- yield 'multiple fixes' => [
- '<?php
- $a = [];
- $b = [1, []];
- foo();
- while(foo()){
- $a = foo2();
- }
- ',
- '<?php
- $a = ([]);
- $b = ([1,([])]);
- (foo());
- while(foo()){
- $a = (foo2());
- }
- ',
- ];
- yield 'access' => [
- '<?php
- $ag = $b->A::$foo;
- $a1 = $b->$c[1];
- $a2 = $b->c[1][2];
- $a3 = $b->$c[1]->$a[2]->${"abc"};
- $a4 = $b->$c[1][2]->${"abc"}(22);
- $a5 = $o->$foo();
- $o->$c[] = 6;
- $a7 = $o->$c[8] (7);
- $a9 = $o->abc($a);
- $a10 = $o->abc($a)[1];
- $a11 = $o->{$bar};
- $a12 = $o->{$c->d}($e)[1](2)[$f]->$c[1]()?>
- ',
- '<?php
- $ag = (($b)->A::$foo);
- $a1 = (($b)->$c[1]);
- $a2 = (($b)->c[1][2]);
- $a3 = (($b)->$c[1]->$a[2]->${"abc"});
- $a4 = (($b)->$c[1][2]->${"abc"}(22));
- $a5 = (($o)->$foo());
- ($o)->$c[] = 6;
- $a7 = (($o)->$c[8] (7));
- $a9 = (($o)->abc($a));
- $a10 = (($o)->abc($a)[1]);
- $a11 = (($o)->{$bar});
- $a12 = (($o)->{$c->d}($e)[1](2)[$f]->$c[1]())?>
- ',
- ];
- yield 'simple unary `!`' => [
- '<?php
- $a1 = !$foo;
- $a2 = +$f;
- $a3 = -$f;
- $a4 = @bar();
- ',
- '<?php
- $a1 = !($foo);
- $a2 = +($f);
- $a3 = -($f);
- $a4 = @(bar());
- ',
- ];
- yield 'pre op ! function call' => [
- '<?php $a9 = !foo($a + 1);',
- '<?php $a9 = !(foo($a + 1));',
- ];
- yield 'multiple pre in wrapped array init' => [
- '<?php $d7 = [!!!!!!!$a5];',
- '<?php $d7 = [!!!!!!!($a5)];',
- ];
- yield 'pre op cast' => [
- '<?php $a6 = (bool)$foo;',
- '<?php $a6 = (bool)($foo);',
- ];
- yield 'pre op ! wrapped' => [
- '<?php if (!$z) {echo 1;}',
- '<?php if ((!($z))) {echo 1;}',
- ];
- yield 'crazy unary' => [
- '<?php
- $b0 = !!!(bool) $a1;
- $b1 = [!!!(bool) $a2,1];
- !!!(bool) $a3;
- !!!(bool) $a4;
- $b = 1 + (!!!!!!!$a5);
- $a = !$a[1]++;
- while(!!!(bool) $a2[1] ){echo 1;}
- $b = @$a[1];
- $b = ++$a[1];
- ',
- '<?php
- $b0 = !!!(bool) ($a1);
- $b1 = [!!!(bool) ($a2),1];
- (!!!(bool) (($a3)));
- (!!!(bool) ($a4));
- $b = 1 + (!!!!!!!($a5));
- $a = !($a)[1]++;
- while(!!!(bool) ($a2)[1] ){echo 1;}
- $b = @($a)[1];
- $b = ++($a)[1];
- ',
- ];
- yield 'logic &&' => [
- '<?php $arr = $a && $b;',
- '<?php $arr = ($a) && $b;',
- ];
- yield 'bin before' => [
- '<?php
- $ax = $d + $a;
- $dx = 1 + $z ?>',
- '<?php
- $ax = $d + ($a);
- $dx = 1 + ($z) ?>',
- ];
- yield 'bin before and after' => [
- '<?php
- echo 1 + 2 + 3;
- echo 1.5 + 2.5 + 3.5;
- echo 1 + $obj->value + 3;
- echo 1 + Obj::VALUE + 3;
- ',
- '<?php
- echo 1 + (2) + 3;
- echo 1.5 + (2.5) + 3.5;
- echo 1 + ($obj->value) + 3;
- echo 1 + (Obj::VALUE) + 3;
- ',
- ];
- yield 'new class as sequence element' => [
- '<?php $a7 = [1, new class($a+$b) {}];',
- '<?php $a7 = [1, (new class($a+$b) {})];',
- ];
- yield 'pre @ sequence' => [
- '<?php $a8 = [1, @ ($f.$b)() ];',
- '<?php $a8 = [1, @( ($f.$b)() )];',
- ];
- yield 'inside `{` and `}`' => [
- '<?php
- while(foo()) { bar(); }
- while(bar()){foo1();};
- if($a){foo();}
- ',
- '<?php
- while(foo()) { (bar()); }
- while(bar()){(foo1());};
- if($a){(foo());}
- ',
- ];
- yield 'block type dynamic var brace' => [
- '<?php ${$bar};',
- '<?php ${($bar)};',
- ];
- yield 'block type dynamic prop brace' => [
- '<?php $foo->{$bar};',
- '<?php $foo->{($bar)};',
- ];
- yield 'anonymous class wrapped init' => [
- '<?php $a11 = new class(1){};',
- '<?php $a11 = new class((1)){};',
- ];
- yield 'return, new long array notation, no space' => [
- '<?php return array();',
- '<?php return(array());',
- ];
- yield 'block type array square brace' => [
- '<?php
- echo $a13 = [1];
- $bX = [1,];
- $b0 = [1, 2, 3,];
- $b1 = [$a + 1];
- $b2 = [-1 + $a];
- $b3 = [2 + $c];
- ',
- '<?php
- echo $a13 = [(1)];
- $bX = [(1),];
- $b0 = [(1),(2),(3),];
- $b1 = [($a) + 1];
- $b2 = [-1 + ($a)];
- $b3 = [2 + ($c)];
- ',
- ];
- yield 'multiple array construct elements' => [
- '<?php echo $a14 = [1, $a(1,$b(3)), 3+4]?>',
- '<?php echo $a14 = [(1),($a(1,$b(3))),(3+4)]?>',
- ];
- yield 'double comma and `)`' => [
- '<?php echo sprintf("%d%s", $e, $f);',
- '<?php echo sprintf("%d%s", ($e), ($f));',
- ];
- yield 'two wrapped function calls' => [
- '<?php foo(); $ap = foo();',
- '<?php (foo()); $ap = (foo());',
- ];
- yield 'wrapped function call, op + call as arg' => [
- '<?php $bk = foo(1 + bar()) ?>',
- '<?php $bk = (foo(1 + bar())) ?>',
- ];
- yield 'wrapped function call, short open, semicolon' => [
- '<?= foo1z() ?>',
- '<?=(foo1z()) ?>',
- ];
- yield 'wrapped function call, short open, close tag' => [
- '<?= foo2A();',
- '<?=( foo2A());',
- ];
- yield 'wrapped returns' => [
- '<?php function A($a) {return 1;}',
- '<?php function A($a) {return (1);}',
- ];
- yield 'wrapped returns ops' => [
- '<?php function A($a1,$b2) {return ++$a1+$b2;}',
- '<?php function A($a1,$b2) {return (++$a1+$b2);}',
- ];
- yield 'throws, no space' => [
- '<?php throw $z . 2;',
- '<?php throw($z . 2);',
- ];
- yield 'throws + op, wrapped in {}' => [
- '<?php if (k()) { throw new $a.$b(1,2); } ?>',
- '<?php if (k()) { throw (new $a.$b(1,2)); } ?>',
- ];
- yield 'dynamic class name op' => [
- '<?php $xX = ($d+$e)->test();',
- '<?php $xX = (($d+$e))->test();',
- ];
- yield 'token type changing edge case' => [
- '<?php $y1 = (new Foo())->bar;',
- '<?php $y1 = ((new Foo()))->bar;',
- ];
- yield 'brace class instantiation open, double wrapped, no assign' => [
- '<?php (new Foo())->bar();',
- '<?php (((new Foo())))->bar();',
- ];
- yield 'brace class instantiation open, multiple wrapped' => [
- '<?php $y0 = (new Foo())->bar;',
- '<?php $y0 = (((((new Foo())))))->bar;',
- ];
- yield 'wrapped instance check' => [
- '<?php
- ; $foo instanceof Foo;
- ; $foo() instanceof Foo;
- $l1 = $foo instanceof $z;
- $l2 = $foo instanceof $z[1];
- $l3 = [$foo instanceof $z->a[1]];
- $l4 = [1, $foo instanceof $a[1]->$f];
- $l5 = [$foo instanceof Foo, 1];
- $l6 = [1, $foo instanceof Foo, 1];
- $fn1 = fn($x) => $fx instanceof Foo;
- for ($foo instanceof Foo ; $i < 1; ++$i) { echo $i; }
- class foo {
- public function bar() {
- self instanceof static;
- self instanceof self;
- $a instanceof static;
- self instanceof $a;
- $a instanceof self;
- }
- }
- ',
- '<?php
- ; ($foo instanceof Foo);
- ; ($foo() instanceof Foo);
- $l1 = ($foo instanceof $z);
- $l2 = ($foo instanceof $z[1]);
- $l3 = [($foo instanceof $z->a[1])];
- $l4 = [1, ($foo instanceof $a[1]->$f)];
- $l5 = [($foo instanceof Foo), 1];
- $l6 = [1, ($foo instanceof Foo), 1];
- $fn1 = fn($x) => ($fx instanceof Foo);
- for (($foo instanceof Foo) ; $i < 1; ++$i) { echo $i; }
- class foo {
- public function bar() {
- (self instanceof static);
- (self instanceof self);
- ($a instanceof static);
- (self instanceof $a);
- ($a instanceof self);
- }
- }
- ',
- ];
- yield 'wrapped negative instanceof' => [
- '<?php
- !$z instanceof $z[1];
- $z2 = !$foo[1]->b(1)[2] instanceof A\Foo;
- $z3 = [!$z instanceof Foo\Bar::$a];
- $z4 = [1, !$z instanceof Foo\Bar::$a];
- $z5 = [!$z instanceof Foo\Bar::$a, 2];
- $z6 = [8, !$z instanceof Foo\Bar::$a, 2];
- for( !$z instanceof Foo\Bar::$a ; $a < 100; ++$a) {
- foo();
- }
- $c1 = fn() => !$z instanceof $z[1];
- if (!$x instanceof $v) {
- echo 123;
- }
- ',
- '<?php
- !($z instanceof $z[1]);
- $z2 = !($foo[1]->b(1)[2] instanceof A\Foo);
- $z3 = [!($z instanceof Foo\Bar::$a)];
- $z4 = [1, !($z instanceof Foo\Bar::$a)];
- $z5 = [!($z instanceof Foo\Bar::$a), 2];
- $z6 = [8, !($z instanceof Foo\Bar::$a), 2];
- for( !($z instanceof Foo\Bar::$a) ; $a < 100; ++$a) {
- foo();
- }
- $c1 = fn() => !($z instanceof $z[1]);
- if (!($x instanceof $v)) {
- echo 123;
- }
- ',
- ];
- yield 'wrapped negative instanceof 2' => [
- '<?php
- class foo {
- public function bar() {
- !self instanceof static;
- !self instanceof self;
- !$a instanceof static;
- !self instanceof $a;
- !$a instanceof self;
- }
- }',
- '<?php
- class foo {
- public function bar() {
- !(self instanceof static);
- !(self instanceof self);
- !($a instanceof static);
- !(self instanceof $a);
- !($a instanceof self);
- }
- }',
- ];
- yield '(x,y' => [
- '<?php $n = ["".foo(1+2),3];',
- '<?php $n = [("".foo(1+2)),3];',
- ];
- yield 'x,y) = ' => [
- '<?php $m = [$x, $y];',
- '<?php $m = [$x,($y)];',
- ];
- yield '(x,y,x)' => [
- '<?php $aj = [1, "".foo(1+2),3];',
- '<?php $aj = [1,("".foo(1+2)),3];',
- ];
- yield 'block type index square brace' => [
- '<?php $n = $foo[1];',
- '<?php $n = $foo[(1)];',
- ];
- yield 'multiple wrapped call' => [
- '<?php
- $u = $z($b);
- $a = bar/*1*/ ($a) /*2*/;',
- '<?php
- $u = $z(($b));
- $a = bar/*1*/ (((($a)))) /*2*/;',
- ];
- yield 'if' => [
- '<?php if ($z) {echo 1;}',
- '<?php if ((($z))) {echo 1;}',
- ];
- yield 'destructuring square brace + comments' => [
- '<?php
- [/*A*/$a/*B*/] = z();
- [/*A*/$a/*B*/, $c] = z();
- ',
- '<?php
- [/*A*/($a)/*B*/] = z();
- [/*A*/($a)/*B*/,($c)] = z();
- ',
- ];
- yield 'multiple fix cases' => [
- '<?php
- $aF=array(1);$a=array(1);$a=array(1);$a=array(1);
- $bF=array(1);$b=array(1);$b=array(1);$b=array(1);
- $cF=array(1);$c=array(1);$c=array(1);$c=array(1);
- ',
- '<?php
- $aF=array((1));$a=array((1));$a=array((1));$a=array((1));
- $bF=array((1));$b=array((1));$b=array((1));$b=array((1));
- $cF=array((1));$c=array((1));$c=array((1));$c=array((1));
- ',
- ];
- yield 'multiple fix cases with space inserts' => [
- '<?php $a=$b. 1 .$c;$a=$b. 1 .$c;$a=$b. 1 .$c;$a=$b. 1 .$c;$a=$b. 1 .$c;$a=$b./*1*/1/*2*/.$c;',
- '<?php $a=$b.(1).$c;$a=$b.(1).$c;$a=$b.(1).$c;$a=$b.(1).$c;$a=$b.(1).$c;$a=$b./*1*/(1)/*2*/.$c;',
- ];
- yield 'empty exit/die' => [
- '<?php exit; die;',
- '<?php exit(); die();',
- ];
- yield 'more space around concat handling' => [
- '<?php
- $s2 = "a". 0.1 . 2 . "b" . "c";
- $f = \'x\' . \'y\' . \'z\';
- ',
- '<?php
- $s2 = "a".(0.1). (2) . ("b") . "c";
- $f = \'x\' . ( \'y\' ) . \'z\';
- ',
- ];
- $assignOperators = [
- 'and equal' => '&=',
- 'coalesce_equal' => '??=',
- 'concat_equal' => '.=',
- 'div equal' => '/=',
- 'minus equal' => '!=',
- 'mod equal' => '%=',
- 'mul equal' => '*=',
- 'or equal' => '|=',
- 'plus equal' => '+=',
- 'pow equal' => '**=',
- 'sl equal' => '<<=',
- 'sr equal' => '>>=',
- 'xor equal' => '^=',
- ];
- foreach ($assignOperators as $assignOperator) {
- yield [
- '<?php $a '.$assignOperator.' $x;',
- '<?php $a '.$assignOperator.' ($x);',
- ];
- }
- yield 'after `}`' => [
- '<?php
- while(foo()){} ++$i;
- for(;;){}++$i;
- foreach ($a as $b){}++$i;
- if (foo()) {}++$i;
- if (foo()) {} else {}++$i;
- if (foo()) {} elseif(bar()) {}++$i;
- switch(foo()){case 1: echo 1;}++$i;
- switch (foo()){
- case 1: {}++$i; break;
- }
- function Bar(): array {
- $i++;
- return [];
- }
- function Foo1(){}++$i;
- function & Foo2(){}++$i;
- class A{}++$i;
- class A1 extends BD{}++$i;
- class A2 extends BD implements CE{}++$i;
- class A3 extends BD implements CE,DE{}++$i;
- interface B{}++$i;
- interface B1 extends A{}++$i;
- interface B2 extends A,B{}++$i;
- trait X{}++$i;
- try{}catch(E $e){}$i++;
- try {} finally {}++$i;
- ',
- '<?php
- while(foo()){} (++$i);
- for(;;){}(++$i);
- foreach ($a as $b){}(++$i);
- if (foo()) {}(++$i);
- if (foo()) {} else {}(++$i);
- if (foo()) {} elseif(bar()) {}(++$i);
- switch(foo()){case 1: echo 1;}(++$i);
- switch (foo()){
- case 1: {}(++$i); break;
- }
- function Bar(): array {
- ($i++);
- return [];
- }
- function Foo1(){}(++$i);
- function & Foo2(){}(++$i);
- class A{}(++$i);
- class A1 extends BD{}(++$i);
- class A2 extends BD implements CE{}(++$i);
- class A3 extends BD implements CE,DE{}(++$i);
- interface B{}(++$i);
- interface B1 extends A{}(++$i);
- interface B2 extends A,B{}(++$i);
- trait X{}(++$i);
- try{}catch(E $e){}($i++);
- try {} finally {}(++$i);
- ',
- ];
- yield 'do not fix' => [
- '<?php
- $b = ($a+=$c);
- foo();
- foo(1);
- foo(1,$a,3);
- foo(1,3,);
- foo($a)->$b;
- ${foo}();
- foo(+ $a, -$b);
- $a[1](2);
- $b = $c();
- $z = foo(1) + 2;
- $a = ${\'foo\'}();
- $b["foo"]($bar);
- namespace\func();
- Y::class();
- $z = (print \'a\') + 2;
- $fn1 = fn($x) => $x + $y;
- $d = function() use ($d) {};
- function provideFixCases(): iterable{}
- $z = function &($x) {++$x;};
- final class Foo { public static function bar() { return new static(); } }
- $a = (print 1) + 1;
- $b = $c(print $e);
- $c = foo(print $e);
- $c2 =[ print !($a + 1) ,];
- $a = ($a && !$c) && $b;
- $a = (1 + foo()) * 2;
- $a = -($f+$a);
- $a = !($f ? $a : $b);
- $a = @( ($f.$b)() . foo() );
- $a = $b ? ($c)($d + 2) : $d;
- $d = ($c && $a ? true : false) ? 1 : 2; // PHP Deprecated: Unparenthesized `a ? b : c ? d : e` is deprecated.
- $z = $b ? ($c)($d + 2) : $d;
- $x = $b ? foo($c)[$a](1) : $d;
- $a = [1,($a.$foo[1])[2]];
- $b = [ $d[4]($a[1].$b) , ];
- $c = [$d[4]($a[1].$b)];
- $a = ($a ? 1 : 2) ? 1 : 2;
- $a = $a ? ($a ? 1 : 2): 2;
- $a = $a ? 1 : ($a ? 1 : 2);
- $a = 1 + ($a + 1) ? 1 : 2;
- $a = $a ? ($a + 1) + 3 : 2;
- $a = $a ? 3 + ($a + 1) : 2;
- $a = $a ? 3 : 1 + ($a + 1);
- $a = $a ? 3 : ($a + 1) + 2;
- $b += ($a+=$c);
- $a = isset( ( (array) $b) [1] );
- $a = ( (array) $b) [1] ;
- exit(4);
- exit (foo()) + 1;
- $a = array();
- $b = new class(){};
- declare(ticks=1);
- $d = empty($e);
- $e = eval($b);
- list($f) = $f;
- try {foo();} catch (E $e){}
- if ($a){ echo 1; } elseif($b) { echo 2; }
- switch($a) {case 1: echo 1;}
- foreach ($a1 as $b){}
- foreach ($a2 as $b => $c){}
- for ($a =0; $a < 1; --$a){}
- while(bar()) {}
- while(!!!(bool) $a1() ){echo 1;}
- while( ($a2)(1) ){echo 1;}
- $d = isset($c);
- $d = isset($c,$a,$z);
- $y = isset($foo) && isset($foo2);
- unset($d);
- unset($d,$e);
- // from https://www.php.net/manual/en/language.operators.precedence.php
- $a = 1;
- echo $a + ($a++); // echo $a + $a++; // may print either 2 or 3
- $i = 1;
- $array[$i] = ($i++); // $array[$i] = $i++; // may set either index 1 or 2
- $t = 1+($i++)+1;
- echo (("x minus one equals " . $x) - 1) . ", or so I hope\n";
- echo "x minus one equals " . ($x-1) . ", or so I hope\n";
- $bool = (true and false);
- $a = ($a instanceof MyClass) && true;
- $a = foo($a instanceof MyClass);
- $a = $a || ($a instanceof MyClass);
- $a = clone ($a)[0];
- // handled by the `include` rule
- require (__DIR__."/foo2.php");
- require_once (__DIR__."/foo.php");
- include ($a);
- include_once ($b);
- // halt compiler
- __halt_compiler();
- ',
- ];
- yield 'do not fix ' => [
- '<?php
- SomeClass::{$method}(
- $variableA,
- $variableB
- );',
- ];
- yield 'do not fix 2' => [
- '<?php SomeClass::{$method}(2) + 1;',
- ];
- yield 'do not fix 3' => [
- '<?php $object::{$method}(...$args);',
- ];
- yield 'alternative syntax is not completely supported' => [
- '<?php if ($a):(++$i); endif;',
- ];
- }
- /**
- * @param _AutogeneratedInputConfiguration $config
- *
- * @dataProvider provideWithConfigCases
- */
- public function testWithConfig(array $config, string $expected, string $input): void
- {
- $this->fixer->configure($config);
- $this->doTest($expected, $input);
- $this->fixer->configure(['statements' => []]);
- $this->doTest($input);
- }
- public static function provideWithConfigCases(): iterable
- {
- yield 'config: break' => [
- ['statements' => ['break']],
- '<?php
- while (foo()) {
- while (foo()) {
- break 2;
- }
- }
- ',
- '<?php
- while (foo()) {
- while (foo()) {
- break (2);
- }
- }
- ',
- ];
- yield 'config: clone' => [
- ['statements' => ['clone']],
- '<?php ; clone $f;',
- '<?php ; clone($f);',
- ];
- yield 'config: continue' => [
- ['statements' => ['continue']],
- '<?php
- while (foo()) {
- while (foo()) {
- continue 2;
- }
- }
- ',
- '<?php
- while (foo()) {
- while (foo()) {
- continue (2);
- }
- }
- ',
- ];
- yield 'config: echo_print' => [
- ['statements' => ['echo_print']],
- '<?php
- echo 1; print 2;
- ',
- '<?php
- echo (1); print (2);
- ',
- ];
- yield 'config: return' => [
- ['statements' => ['return']],
- '<?php ; return 999 ?>',
- '<?php ; return (999) ?>',
- ];
- yield 'config: switch_case' => [
- ['statements' => ['switch_case']],
- '<?php
- switch ($a) {
- case 22: echo 1;
- }
- ',
- '<?php
- switch ($a) {
- case (22): echo 1;
- }
- ',
- ];
- yield 'config: yield' => [
- ['statements' => ['yield']],
- '<?php function foo() { yield "prod"; }',
- '<?php function foo() { yield ("prod"); }',
- ];
- yield 'config: yield_from' => [
- ['statements' => ['yield_from']],
- '<?php function foo() { ; yield from $a; }',
- '<?php function foo() { ; yield from ($a); }',
- ];
- yield 'config: negative_instanceof' => [
- ['statements' => ['negative_instanceof']],
- '<?php !$foo instanceof $b;',
- '<?php !($foo instanceof $b);',
- ];
- yield 'config: others' => [
- ['statements' => ['others']],
- '<?php ; ++$v[1];',
- '<?php ; ++($v)[1];',
- ];
- }
- /**
- * @dataProvider providePrePhp8Cases
- *
- * @requires PHP <8.0
- */
- public function testPrePhp8(string $expected, string $input): void
- {
- $this->fixer->configure(
- [
- 'statements' => [
- 'break',
- 'clone',
- 'continue',
- 'echo_print',
- 'return',
- 'switch_case',
- 'yield',
- 'yield_from',
- 'others',
- ],
- ],
- );
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<string, array{string, string}>
- */
- public static function providePrePhp8Cases(): iterable
- {
- yield 'block type array index curly brace' => [
- '<?php echo $a12 = $a{1};',
- '<?php echo $a12 = $a{(1)};',
- ];
- yield 'PHP8 bin doggybag' => [
- '<?php
- $s = $a{$d}(1) + 1;
- $t = $a{1}(2);
- ',
- '<?php
- $s = ($a{$d}(1)) + 1;
- $t = ($a{1}(2));
- ',
- ];
- }
- /**
- * @dataProvider provideFixPhp80Cases
- *
- * @requires PHP 8.0
- */
- public function testFixPhp80(string $expected, ?string $input = null): void
- {
- $this->fixer->configure(
- [
- 'statements' => [
- 'break',
- 'clone',
- 'continue',
- 'echo_print',
- 'return',
- 'switch_case',
- 'yield',
- 'yield_from',
- 'others',
- ],
- ],
- );
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<int|string, array{string, string}>
- */
- public static function provideFixPhp80Cases(): iterable
- {
- yield 'fn throw' => [
- '<?php $triggerError = fn () => throw new MyError();',
- '<?php $triggerError = fn () => (throw new MyError());',
- ];
- yield 'match' => [
- "<?php
- \$r = match (\$food) {
- 'apple' => 'An apple',
- 'cake' => 'Some cake',
- };
- ",
- "<?php
- \$r = match ((\$food)) {
- 'apple' => 'An apple',
- 'cake' => 'Some cake',
- };
- ",
- ];
- yield 'wrapped FN with return types' => [
- '<?php
- $fn8 = fn(): int|bool => 123456;
- ',
- '<?php
- $fn8 = fn(): int|bool => (123456);
- ',
- ];
- yield [
- '<?php echo 1 + $obj?->value + 3;',
- '<?php echo 1 + ($obj?->value) + 3;',
- ];
- }
- /**
- * @dataProvider provideFixPhp81Cases
- *
- * @requires PHP 8.1
- */
- public function testFixPhp81(string $expected, ?string $input = null): void
- {
- $this->fixer->configure(
- [
- 'statements' => [
- 'break',
- 'clone',
- 'continue',
- 'echo_print',
- 'return',
- 'switch_case',
- 'yield',
- 'yield_from',
- 'others',
- ],
- ],
- );
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<int|string, array{string, string}>
- */
- public static function provideFixPhp81Cases(): iterable
- {
- yield [
- '<?php
- enum Foo: string
- {
- case Bar = "do fix";
- }
- ',
- '<?php
- enum Foo: string
- {
- case Bar = ("do fix");
- }
- ',
- ];
- yield [
- '<?php echo Number::Two->value;',
- '<?php echo (Number::Two)->value;',
- ];
- yield 'wrapped FN with return types' => [
- '<?php
- $fn8 = fn(): A&B => new C();
- ',
- '<?php
- $fn8 = fn(): A&B => (new C());
- ',
- ];
- yield 'wrapped FN with return types and ref' => [
- '<?php
- $fn9 = fn & (): D & E => new F();
- ',
- '<?php
- $fn9 = fn & (): D & E => (new F());
- ',
- ];
- yield [
- '<?php
- enum Suit
- {
- case Hearts;
- }$i++;
- ',
- '<?php
- enum Suit
- {
- case Hearts;
- }($i++);
- ',
- ];
- }
- /**
- * @param _AutogeneratedInputConfiguration $configuration
- *
- * @dataProvider provideFixPre84Cases
- *
- * @requires PHP <8.4
- */
- public function testFixPre84(string $expected, ?string $input = null, array $configuration = []): void
- {
- $this->fixer->configure($configuration);
- $this->doTest($expected, $input);
- }
- /**
- * @return iterable<array{string, string, _AutogeneratedInputConfiguration}>
- */
- public static function provideFixPre84Cases(): iterable
- {
- yield 'access' => [
- '<?php $a = $o->{$c->d}($e)[1](2){$f}->$c[1]();',
- '<?php $a = (($o)->{$c->d}($e)[1](2){$f}->$c[1]());',
- ['statements' => ['others']],
- ];
- }
- }
|