BracesFixerTest.php 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505
  1. <?php
  2. /*
  3. * This file is part of PHP CS Fixer.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  7. *
  8. * This source file is subject to the MIT license that is bundled
  9. * with this source code in the file LICENSE.
  10. */
  11. namespace PhpCsFixer\Tests\Fixer\Basic;
  12. use PhpCsFixer\Fixer\Basic\BracesFixer;
  13. use PhpCsFixer\Tests\Test\AbstractFixerTestCase;
  14. use PhpCsFixer\WhitespacesFixerConfig;
  15. /**
  16. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  17. *
  18. * @internal
  19. *
  20. * @covers \PhpCsFixer\Fixer\Basic\BracesFixer
  21. */
  22. final class BracesFixerTest extends AbstractFixerTestCase
  23. {
  24. private static $configurationOopPositionSameLine = ['position_after_functions_and_oop_constructs' => BracesFixer::LINE_SAME];
  25. private static $configurationCtrlStructPositionNextLine = ['position_after_control_structures' => BracesFixer::LINE_NEXT];
  26. private static $configurationAnonymousPositionNextLine = ['position_after_anonymous_constructs' => BracesFixer::LINE_NEXT];
  27. public function testInvalidConfigurationClassyConstructs()
  28. {
  29. $this->expectException(\PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException::class);
  30. $this->expectExceptionMessageMatches('#^\[braces\] Invalid configuration: The option "position_after_functions_and_oop_constructs" with value "neither" is invalid\. Accepted values are: "next", "same"\.$#');
  31. $this->fixer->configure(['position_after_functions_and_oop_constructs' => 'neither']);
  32. }
  33. /**
  34. * @param string $expected
  35. * @param null|string $input
  36. *
  37. * @dataProvider provideFixControlContinuationBracesCases
  38. */
  39. public function testFixControlContinuationBraces($expected, $input = null, array $configuration = [])
  40. {
  41. $this->fixer->configure($configuration);
  42. $this->doTest($expected, $input);
  43. }
  44. public function provideFixControlContinuationBracesCases()
  45. {
  46. return [
  47. [
  48. '<?php
  49. $a = function() {
  50. $a = 1;
  51. while (false);
  52. };',
  53. ],
  54. [
  55. '<?php
  56. $a = function() {
  57. $a = 1;
  58. for ($i=0;$i<5;++$i);
  59. };',
  60. ],
  61. [
  62. '<?php
  63. class Foo
  64. {
  65. public function A()
  66. {
  67. ?>
  68. Test<?php echo $foobar; ?>Test
  69. <?php
  70. $a = 1;
  71. }
  72. }',
  73. ],
  74. [
  75. '<?php
  76. if (true) {
  77. $a = 1;
  78. } else {
  79. $b = 2;
  80. }',
  81. '<?php
  82. if (true) {
  83. $a = 1;
  84. }
  85. else {
  86. $b = 2;
  87. }',
  88. ],
  89. [
  90. '<?php
  91. try {
  92. throw new \Exception();
  93. } catch (\LogicException $e) {
  94. // do nothing
  95. } catch (\Exception $e) {
  96. // do nothing
  97. }',
  98. '<?php
  99. try {
  100. throw new \Exception();
  101. }catch (\LogicException $e) {
  102. // do nothing
  103. }
  104. catch (\Exception $e) {
  105. // do nothing
  106. }',
  107. ],
  108. [
  109. '<?php
  110. if (true) {
  111. echo 1;
  112. } elseif (true) {
  113. echo 2;
  114. }',
  115. '<?php
  116. if (true) {
  117. echo 1;
  118. } elseif (true)
  119. {
  120. echo 2;
  121. }',
  122. ],
  123. [
  124. '<?php
  125. try {
  126. echo 1;
  127. } catch (Exception $e) {
  128. echo 2;
  129. }',
  130. '<?php
  131. try
  132. {
  133. echo 1;
  134. }
  135. catch (Exception $e)
  136. {
  137. echo 2;
  138. }',
  139. ],
  140. [
  141. '<?php
  142. class Foo
  143. {
  144. public function bar(
  145. FooInterface $foo,
  146. BarInterface $bar,
  147. array $data = []
  148. ) {
  149. }
  150. }',
  151. '<?php
  152. class Foo
  153. {
  154. public function bar(
  155. FooInterface $foo,
  156. BarInterface $bar,
  157. array $data = []
  158. ){
  159. }
  160. }',
  161. ],
  162. [
  163. '<?php
  164. if (1) {
  165. self::${$key} = $val;
  166. self::${$type}[$rule] = $pattern;
  167. self::${$type}[$rule] = array_merge($pattern, self::${$type}[$rule]);
  168. self::${$type}[$rule] = $pattern + self::${$type}["rules"];
  169. }
  170. ',
  171. ],
  172. [
  173. '<?php
  174. if (1) {
  175. do {
  176. $a = 1;
  177. } while (true);
  178. }',
  179. ],
  180. [
  181. '<?php
  182. if /* 1 */ (2) {
  183. }',
  184. '<?php
  185. if /* 1 */ (2) {}',
  186. ],
  187. [
  188. '<?php
  189. if (1) {
  190. echo $items{0}->foo;
  191. echo $collection->items{1}->property;
  192. }
  193. ',
  194. ],
  195. [
  196. '<?php
  197. $a = function() {
  198. $a = 1;
  199. while (false);
  200. };',
  201. null,
  202. self::$configurationOopPositionSameLine,
  203. ],
  204. [
  205. '<?php
  206. $a = function()
  207. {
  208. $a = 1;
  209. while (false);
  210. };',
  211. '<?php
  212. $a = function() {
  213. $a = 1;
  214. while (false);
  215. };',
  216. self::$configurationAnonymousPositionNextLine,
  217. ],
  218. [
  219. '<?php
  220. $a = function() {
  221. $a = 1;
  222. for ($i=0;$i<5;++$i);
  223. };',
  224. null,
  225. self::$configurationOopPositionSameLine,
  226. ],
  227. [
  228. '<?php
  229. $a = function()
  230. {
  231. $a = 1;
  232. for ($i=0;$i<5;++$i);
  233. };',
  234. '<?php
  235. $a = function() {
  236. $a = 1;
  237. for ($i=0;$i<5;++$i);
  238. };',
  239. self::$configurationAnonymousPositionNextLine,
  240. ],
  241. [
  242. '<?php
  243. class Foo {
  244. public function A() {
  245. ?>
  246. Test<?php echo $foobar; ?>Test
  247. <?php
  248. $a = 1;
  249. }
  250. }',
  251. '<?php
  252. class Foo
  253. {
  254. public function A()
  255. {
  256. ?>
  257. Test<?php echo $foobar; ?>Test
  258. <?php
  259. $a = 1;
  260. }
  261. }',
  262. self::$configurationOopPositionSameLine,
  263. ],
  264. [
  265. '<?php
  266. if (true) {
  267. $a = 1;
  268. } else {
  269. $b = 2;
  270. }',
  271. '<?php
  272. if (true) {
  273. $a = 1;
  274. }
  275. else {
  276. $b = 2;
  277. }',
  278. self::$configurationOopPositionSameLine,
  279. ],
  280. [
  281. '<?php
  282. if (true)
  283. {
  284. $a = 1;
  285. }
  286. else
  287. {
  288. $b = 2;
  289. }',
  290. '<?php
  291. if (true) {
  292. $a = 1;
  293. }
  294. else {
  295. $b = 2;
  296. }',
  297. self::$configurationCtrlStructPositionNextLine,
  298. ],
  299. [
  300. '<?php
  301. try {
  302. throw new \Exception();
  303. } catch (\LogicException $e) {
  304. // do nothing
  305. } catch (\Exception $e) {
  306. // do nothing
  307. }',
  308. '<?php
  309. try {
  310. throw new \Exception();
  311. }catch (\LogicException $e) {
  312. // do nothing
  313. }
  314. catch (\Exception $e) {
  315. // do nothing
  316. }',
  317. self::$configurationOopPositionSameLine,
  318. ],
  319. [
  320. '<?php
  321. try
  322. {
  323. throw new \Exception();
  324. }
  325. catch (\LogicException $e)
  326. {
  327. // do nothing
  328. }
  329. catch (\Exception $e)
  330. {
  331. // do nothing
  332. }',
  333. '<?php
  334. try {
  335. throw new \Exception();
  336. }catch (\LogicException $e) {
  337. // do nothing
  338. }
  339. catch (\Exception $e) {
  340. // do nothing
  341. }',
  342. self::$configurationCtrlStructPositionNextLine,
  343. ],
  344. [
  345. '<?php
  346. if (true) {
  347. echo 1;
  348. } elseif (true) {
  349. echo 2;
  350. }',
  351. '<?php
  352. if (true) {
  353. echo 1;
  354. } elseif (true)
  355. {
  356. echo 2;
  357. }',
  358. self::$configurationOopPositionSameLine,
  359. ],
  360. [
  361. '<?php
  362. try {
  363. echo 1;
  364. } catch (Exception $e) {
  365. echo 2;
  366. }',
  367. '<?php
  368. try
  369. {
  370. echo 1;
  371. }
  372. catch (Exception $e)
  373. {
  374. echo 2;
  375. }',
  376. self::$configurationOopPositionSameLine,
  377. ],
  378. [
  379. '<?php
  380. class Foo {
  381. public function bar(
  382. FooInterface $foo,
  383. BarInterface $bar,
  384. array $data = []
  385. ) {
  386. }
  387. }',
  388. '<?php
  389. class Foo
  390. {
  391. public function bar(
  392. FooInterface $foo,
  393. BarInterface $bar,
  394. array $data = []
  395. ){
  396. }
  397. }',
  398. self::$configurationOopPositionSameLine,
  399. ],
  400. [
  401. '<?php
  402. if (1) {
  403. self::${$key} = $val;
  404. self::${$type}[$rule] = $pattern;
  405. self::${$type}[$rule] = array_merge($pattern, self::${$type}[$rule]);
  406. self::${$type}[$rule] = $pattern + self::${$type}["rules"];
  407. }
  408. ',
  409. null,
  410. self::$configurationOopPositionSameLine,
  411. ],
  412. [
  413. '<?php
  414. if (1) {
  415. do {
  416. $a = 1;
  417. } while (true);
  418. }',
  419. null,
  420. self::$configurationOopPositionSameLine,
  421. ],
  422. [
  423. '<?php
  424. if /* 1 */ (2) {
  425. }',
  426. '<?php
  427. if /* 1 */ (2) {}',
  428. self::$configurationOopPositionSameLine,
  429. ],
  430. [
  431. '<?php
  432. if (1) {
  433. echo $items{0}->foo;
  434. echo $collection->items{1}->property;
  435. }
  436. ',
  437. null,
  438. self::$configurationOopPositionSameLine,
  439. ],
  440. [
  441. '<?php class A
  442. /** */
  443. {
  444. }',
  445. null,
  446. self::$configurationOopPositionSameLine,
  447. ],
  448. [
  449. '<?php
  450. class Foo
  451. {
  452. public function foo()
  453. {
  454. foo();
  455. // baz
  456. bar();
  457. }
  458. }',
  459. '<?php
  460. class Foo
  461. {
  462. public function foo(){
  463. foo();
  464. // baz
  465. bar();
  466. }
  467. }',
  468. ],
  469. [
  470. '<?php
  471. class Foo
  472. {
  473. public function foo($foo)
  474. {
  475. return $foo // foo
  476. ? \'foo\'
  477. : \'bar\'
  478. ;
  479. }
  480. }',
  481. ],
  482. [
  483. '<?php
  484. class Foo
  485. {
  486. /**
  487. * Foo.
  488. */
  489. public $foo;
  490. /**
  491. * Bar.
  492. */
  493. public $bar;
  494. }',
  495. '<?php
  496. class Foo {
  497. /**
  498. * Foo.
  499. */
  500. public $foo;
  501. /**
  502. * Bar.
  503. */
  504. public $bar;
  505. }',
  506. ],
  507. [
  508. '<?php
  509. class Foo
  510. {
  511. /*
  512. * Foo.
  513. */
  514. public $foo;
  515. /*
  516. * Bar.
  517. */
  518. public $bar;
  519. }',
  520. '<?php
  521. class Foo {
  522. /*
  523. * Foo.
  524. */
  525. public $foo;
  526. /*
  527. * Bar.
  528. */
  529. public $bar;
  530. }',
  531. ],
  532. [
  533. '<?php
  534. if (1==1) {
  535. $a = 1;
  536. // test
  537. $b = 2;
  538. }',
  539. '<?php
  540. if (1==1) {
  541. $a = 1;
  542. // test
  543. $b = 2;
  544. }',
  545. ],
  546. [
  547. '<?php
  548. if (1==1) {
  549. $a = 1;
  550. # test
  551. $b = 2;
  552. }',
  553. '<?php
  554. if (1==1) {
  555. $a = 1;
  556. # test
  557. $b = 2;
  558. }',
  559. ],
  560. [
  561. '<?php
  562. if (1==1) {
  563. $a = 1;
  564. /** @var int $b */
  565. $b = a();
  566. }',
  567. '<?php
  568. if (1==1) {
  569. $a = 1;
  570. /** @var int $b */
  571. $b = a();
  572. }',
  573. ],
  574. [
  575. '<?php
  576. if ($b) {
  577. if (1==1) {
  578. $a = 1;
  579. // test
  580. $b = 2;
  581. }
  582. }
  583. ',
  584. '<?php
  585. if ($b) {
  586. if (1==1) {
  587. $a = 1;
  588. // test
  589. $b = 2;
  590. }
  591. }
  592. ',
  593. ],
  594. [
  595. '<?php
  596. if ($b) {
  597. if (1==1) {
  598. $a = 1;
  599. /* test */
  600. $b = 2;
  601. echo 123;//
  602. }
  603. }
  604. ',
  605. '<?php
  606. if ($b) {
  607. if (1==1) {
  608. $a = 1;
  609. /* test */
  610. $b = 2;
  611. echo 123;//
  612. }
  613. }
  614. ',
  615. ],
  616. [
  617. '<?php
  618. class A
  619. {
  620. public function B()
  621. {/*
  622. */
  623. $a = 1;
  624. }
  625. }',
  626. '<?php
  627. class A {
  628. public function B()
  629. {/*
  630. */
  631. $a = 1;
  632. }
  633. }',
  634. ],
  635. [
  636. '<?php
  637. class B
  638. {
  639. public function B()
  640. {
  641. /*
  642. *//**/
  643. $a = 1;
  644. }
  645. }',
  646. '<?php
  647. class B {
  648. public function B()
  649. {
  650. /*
  651. *//**/
  652. $a = 1;
  653. }
  654. }',
  655. ],
  656. [
  657. '<?php
  658. class C
  659. {
  660. public function C()
  661. {
  662. /* */#
  663. $a = 1;
  664. }
  665. }',
  666. '<?php
  667. class C {
  668. public function C()
  669. {
  670. /* */#
  671. $a = 1;
  672. }
  673. }',
  674. ],
  675. [
  676. '<?php
  677. if ($a) { /*
  678. */
  679. echo 1;
  680. }',
  681. '<?php
  682. if ($a){ /*
  683. */
  684. echo 1;
  685. }',
  686. ],
  687. [
  688. '<?php
  689. if ($a) { /**/ /*
  690. */
  691. echo 1;
  692. echo 2;
  693. }',
  694. '<?php
  695. if ($a){ /**/ /*
  696. */
  697. echo 1;
  698. echo 2;
  699. }',
  700. ],
  701. [
  702. '<?php
  703. foreach ($foo as $bar) {
  704. if (true) {
  705. }
  706. // comment
  707. elseif (false) {
  708. }
  709. }',
  710. ],
  711. [
  712. '<?php
  713. function foo()
  714. {
  715. $bar = 1; // multiline ...
  716. // ... comment
  717. $baz = 2; // next comment
  718. }',
  719. ],
  720. [
  721. '<?php
  722. function foo()
  723. {
  724. $foo = 1;
  725. // multiline...
  726. // ... comment
  727. return $foo;
  728. }',
  729. '<?php
  730. function foo()
  731. {
  732. $foo = 1;
  733. // multiline...
  734. // ... comment
  735. return $foo;
  736. }',
  737. ],
  738. [
  739. '<?php
  740. function foo()
  741. {
  742. $bar = 1; /* bar */ // multiline ...
  743. // ... comment
  744. $baz = 2; /* baz */ // next comment
  745. }',
  746. ],
  747. [
  748. '<?php
  749. class Foo
  750. {
  751. public function bar()
  752. {
  753. foreach (new Bar() as $file) {
  754. foo();
  755. }
  756. }
  757. }',
  758. '<?php
  759. class Foo {
  760. public function bar() {
  761. foreach (new Bar() as $file)
  762. {
  763. foo();
  764. }
  765. }
  766. }',
  767. ],
  768. [
  769. '<?php if ($condition) { ?>
  770. echo 1;
  771. <?php } else { ?>
  772. echo 2;
  773. <?php } ?>
  774. ',
  775. ],
  776. ];
  777. }
  778. /**
  779. * @param string $expected
  780. * @param null|string $input
  781. *
  782. * @dataProvider provideFixMissingBracesAndIndentCases
  783. */
  784. public function testFixMissingBracesAndIndent($expected, $input = null, array $configuration = [])
  785. {
  786. $this->fixer->configure($configuration);
  787. $this->doTest($expected, $input);
  788. }
  789. public function provideFixMissingBracesAndIndentCases()
  790. {
  791. return [
  792. [
  793. '<?php
  794. if (true):
  795. $foo = 0;
  796. endif;',
  797. ],
  798. [
  799. '<?php
  800. if (true) :
  801. $foo = 0;
  802. endif;',
  803. ],
  804. [
  805. '<?php
  806. if (true) : $foo = 1; endif;',
  807. ],
  808. [
  809. '<?php
  810. if (true) {
  811. $foo = 1;
  812. }',
  813. '<?php
  814. if (true)$foo = 1;',
  815. ],
  816. [
  817. '<?php
  818. if (true) {
  819. $foo = 2;
  820. }',
  821. '<?php
  822. if (true) $foo = 2;',
  823. ],
  824. [
  825. '<?php
  826. if (true) {
  827. $foo = 3;
  828. }',
  829. '<?php
  830. if (true){$foo = 3;}',
  831. ],
  832. [
  833. '<?php
  834. if (true) {
  835. echo 1;
  836. } else {
  837. echo 2;
  838. }',
  839. '<?php
  840. if(true) { echo 1; } else echo 2;',
  841. ],
  842. [
  843. '<?php
  844. if (true) {
  845. echo 3;
  846. } else {
  847. echo 4;
  848. }',
  849. '<?php
  850. if(true) echo 3; else { echo 4; }',
  851. ],
  852. [
  853. '<?php
  854. if (true) {
  855. echo 5;
  856. } else {
  857. echo 6;
  858. }',
  859. '<?php
  860. if (true) echo 5; else echo 6;',
  861. ],
  862. [
  863. '<?php
  864. if (true) {
  865. while (true) {
  866. $foo = 1;
  867. $bar = 2;
  868. }
  869. }',
  870. '<?php
  871. if (true) while (true) { $foo = 1; $bar = 2;}',
  872. ],
  873. [
  874. '<?php
  875. if (true) {
  876. if (true) {
  877. echo 1;
  878. } else {
  879. echo 2;
  880. }
  881. } else {
  882. echo 3;
  883. }',
  884. '<?php
  885. if (true) if (true) echo 1; else echo 2; else echo 3;',
  886. ],
  887. [
  888. '<?php
  889. if (true) {
  890. // sth here...
  891. if ($a && ($b || $c)) {
  892. $d = 1;
  893. }
  894. }',
  895. '<?php
  896. if (true) {
  897. // sth here...
  898. if ($a && ($b || $c)) $d = 1;
  899. }',
  900. ],
  901. [
  902. '<?php
  903. for ($i = 1; $i < 10; ++$i) {
  904. echo $i;
  905. }
  906. for ($i = 1; $i < 10; ++$i) {
  907. echo $i;
  908. }',
  909. '<?php
  910. for ($i = 1; $i < 10; ++$i) echo $i;
  911. for ($i = 1; $i < 10; ++$i) { echo $i; }',
  912. ],
  913. [
  914. '<?php
  915. for ($i = 1; $i < 5; ++$i) {
  916. for ($i = 1; $i < 10; ++$i) {
  917. echo $i;
  918. }
  919. }',
  920. '<?php
  921. for ($i = 1; $i < 5; ++$i) for ($i = 1; $i < 10; ++$i) { echo $i; }',
  922. ],
  923. [
  924. '<?php
  925. do {
  926. echo 1;
  927. } while (false);',
  928. '<?php
  929. do { echo 1; } while (false);',
  930. ],
  931. [
  932. '<?php
  933. while ($foo->next());',
  934. ],
  935. [
  936. '<?php
  937. foreach ($foo as $bar) {
  938. echo $bar;
  939. }',
  940. '<?php
  941. foreach ($foo as $bar) echo $bar;',
  942. ],
  943. [
  944. '<?php
  945. if (true) {
  946. $a = 1;
  947. }',
  948. '<?php
  949. if (true) {$a = 1;}',
  950. ],
  951. [
  952. '<?php
  953. if (true) {
  954. $a = 1;
  955. }',
  956. '<?php
  957. if (true) {
  958. $a = 1;
  959. }',
  960. ],
  961. [
  962. '<?php
  963. if (true) {
  964. $a = 1;
  965. $b = 2;
  966. while (true) {
  967. $c = 3;
  968. }
  969. $d = 4;
  970. }',
  971. '<?php
  972. if (true) {
  973. $a = 1;
  974. $b = 2;
  975. while (true) {
  976. $c = 3;
  977. }
  978. $d = 4;
  979. }',
  980. ],
  981. [
  982. '<?php
  983. if (true) {
  984. $a = 1;
  985. $b = 2;
  986. }',
  987. ],
  988. [
  989. '<?php
  990. if (1) {
  991. $a = 1;
  992. // comment at end
  993. }',
  994. ],
  995. [
  996. '<?php
  997. if (1) {
  998. if (2) {
  999. $a = "a";
  1000. } elseif (3) {
  1001. $b = "b";
  1002. // comment
  1003. } else {
  1004. $c = "c";
  1005. }
  1006. $d = "d";
  1007. }',
  1008. ],
  1009. [
  1010. '<?php
  1011. foreach ($numbers as $num) {
  1012. for ($i = 0; $i < $num; ++$i) {
  1013. $a = "a";
  1014. }
  1015. $b = "b";
  1016. }',
  1017. ],
  1018. [
  1019. '<?php
  1020. if (1) {
  1021. if (2) {
  1022. $foo = 2;
  1023. if (3) {
  1024. $foo = 3;
  1025. }
  1026. }
  1027. }',
  1028. ],
  1029. [
  1030. '<?php
  1031. declare(ticks = 1) {
  1032. $ticks = 1;
  1033. }',
  1034. '<?php
  1035. declare (
  1036. ticks = 1 ) {
  1037. $ticks = 1;
  1038. }',
  1039. ],
  1040. [
  1041. '<?php
  1042. if (true) {
  1043. foo();
  1044. } elseif (true) {
  1045. bar();
  1046. }',
  1047. '<?php
  1048. if (true)
  1049. {
  1050. foo();
  1051. } elseif (true)
  1052. {
  1053. bar();
  1054. }',
  1055. ],
  1056. [
  1057. '<?php
  1058. while (true) {
  1059. foo();
  1060. }',
  1061. '<?php
  1062. while (true)
  1063. {
  1064. foo();
  1065. }',
  1066. ],
  1067. [
  1068. '<?php
  1069. do {
  1070. echo $test;
  1071. } while ($test = $this->getTest());',
  1072. '<?php
  1073. do
  1074. {
  1075. echo $test;
  1076. }
  1077. while ($test = $this->getTest());',
  1078. ],
  1079. [
  1080. '<?php
  1081. do {
  1082. echo $test;
  1083. } while ($test = $this->getTest());',
  1084. '<?php
  1085. do
  1086. {
  1087. echo $test;
  1088. }while ($test = $this->getTest());',
  1089. ],
  1090. [
  1091. '<?php
  1092. class ClassName
  1093. {
  1094. /**
  1095. * comment
  1096. */
  1097. public $foo = null;
  1098. }',
  1099. '<?php
  1100. class ClassName
  1101. {
  1102. /**
  1103. * comment
  1104. */
  1105. public $foo = null;
  1106. }',
  1107. ],
  1108. [
  1109. '<?php
  1110. while ($true) {
  1111. try {
  1112. throw new \Exception();
  1113. } catch (\Exception $e) {
  1114. // do nothing
  1115. }
  1116. }',
  1117. ],
  1118. [
  1119. '<?php
  1120. interface Foo
  1121. {
  1122. public function setConfig(ConfigInterface $config);
  1123. }',
  1124. ],
  1125. [
  1126. '<?php
  1127. function bar()
  1128. {
  1129. $a = 1; //comment
  1130. }',
  1131. ],
  1132. [
  1133. '<?php
  1134. function & lambda()
  1135. {
  1136. return function () {
  1137. };
  1138. }',
  1139. ],
  1140. [
  1141. '<?php
  1142. function nested()
  1143. {
  1144. $a = "a{$b->c()}d";
  1145. }',
  1146. ],
  1147. [
  1148. '<?php
  1149. function foo()
  1150. {
  1151. $a = $b->{$c->d}($e);
  1152. $f->{$g} = $h;
  1153. $i->{$j}[$k] = $l;
  1154. $m = $n->{$o};
  1155. $p = array($q->{$r}, $s->{$t});
  1156. $u->{$v}->w = 1;
  1157. }',
  1158. ],
  1159. [
  1160. '<?php
  1161. function mixed()
  1162. {
  1163. $a = $b->{"a{$c}d"}();
  1164. }',
  1165. ],
  1166. [
  1167. '<?php
  1168. function mixedComplex()
  1169. {
  1170. $a = $b->{"a{$c->{\'foo-bar\'}()}d"}();
  1171. }',
  1172. ],
  1173. [
  1174. '<?php
  1175. function mixedComplex()
  1176. {
  1177. $a = ${"b{$foo}"}->{"a{$c->{\'foo-bar\'}()}d"}();
  1178. }',
  1179. ],
  1180. [
  1181. '<?php
  1182. if (true):
  1183. echo 1;
  1184. else:
  1185. echo 2;
  1186. endif;
  1187. ',
  1188. ],
  1189. [
  1190. '<?php
  1191. if ($test) { //foo
  1192. echo 1;
  1193. }',
  1194. ],
  1195. [
  1196. '<?php
  1197. if (true) {
  1198. // foo
  1199. // bar
  1200. if (true) {
  1201. print("foo");
  1202. print("bar");
  1203. }
  1204. }',
  1205. '<?php
  1206. if (true)
  1207. // foo
  1208. // bar
  1209. {
  1210. if (true)
  1211. {
  1212. print("foo");
  1213. print("bar");
  1214. }
  1215. }',
  1216. ],
  1217. [
  1218. '<?php
  1219. if (true) {
  1220. // foo
  1221. /* bar */
  1222. if (true) {
  1223. print("foo");
  1224. print("bar");
  1225. }
  1226. }',
  1227. '<?php
  1228. if (true)
  1229. // foo
  1230. /* bar */{
  1231. if (true)
  1232. {
  1233. print("foo");
  1234. print("bar");
  1235. }
  1236. }',
  1237. ],
  1238. [
  1239. '<?php if (true) {
  1240. echo "s";
  1241. } ?>x',
  1242. '<?php if (true) echo "s" ?>x',
  1243. ],
  1244. [
  1245. '<?php
  1246. class Foo
  1247. {
  1248. public function getFaxNumbers()
  1249. {
  1250. if (1) {
  1251. return $this->phoneNumbers->filter(function ($phone) {
  1252. $a = 1;
  1253. $b = 1;
  1254. $c = 1;
  1255. return ($phone->getType() === 1) ? true : false;
  1256. });
  1257. }
  1258. }
  1259. }',
  1260. '<?php
  1261. class Foo
  1262. {
  1263. public function getFaxNumbers()
  1264. {
  1265. if (1)
  1266. return $this->phoneNumbers->filter(function ($phone) {
  1267. $a = 1;
  1268. $b = 1;
  1269. $c = 1;
  1270. return ($phone->getType() === 1) ? true : false;
  1271. });
  1272. }
  1273. }',
  1274. ],
  1275. [
  1276. '<?php
  1277. if (true) {
  1278. if (true) {
  1279. echo 1;
  1280. } elseif (true) {
  1281. echo 2;
  1282. } else {
  1283. echo 3;
  1284. }
  1285. }
  1286. ',
  1287. '<?php
  1288. if(true)
  1289. if(true)
  1290. echo 1;
  1291. elseif(true)
  1292. echo 2;
  1293. else
  1294. echo 3;
  1295. ',
  1296. ],
  1297. [
  1298. '<?php
  1299. if (true) {
  1300. if (true) {
  1301. echo 1;
  1302. } elseif (true) {
  1303. echo 2;
  1304. } else {
  1305. echo 3;
  1306. }
  1307. }
  1308. echo 4;
  1309. ',
  1310. '<?php
  1311. if(true)
  1312. if(true)
  1313. echo 1;
  1314. elseif(true)
  1315. echo 2;
  1316. else
  1317. echo 3;
  1318. echo 4;
  1319. ',
  1320. ],
  1321. [
  1322. '<?php
  1323. if (true) {
  1324. if (true) {
  1325. echo 1;
  1326. } elseif (true) {
  1327. echo 2;
  1328. } else {
  1329. echo 3;
  1330. }
  1331. }',
  1332. '<?php
  1333. if(true) if(true) echo 1; elseif(true) echo 2; else echo 3;',
  1334. ],
  1335. [
  1336. '<?php
  1337. if (true) {
  1338. if (true) {
  1339. echo 1;
  1340. } else {
  1341. echo 2;
  1342. }
  1343. } else {
  1344. echo 3;
  1345. }',
  1346. '<?php
  1347. if(true) if(true) echo 1; else echo 2; else echo 3;',
  1348. ],
  1349. [
  1350. '<?php
  1351. foreach ($data as $val) {
  1352. // test val
  1353. if ($val === "errors") {
  1354. echo "!";
  1355. }
  1356. }',
  1357. '<?php
  1358. foreach ($data as $val)
  1359. // test val
  1360. if ($val === "errors") {
  1361. echo "!";
  1362. }',
  1363. ],
  1364. [
  1365. '<?php
  1366. if (1) {
  1367. foreach ($data as $val) {
  1368. // test val
  1369. if ($val === "errors") {
  1370. echo "!";
  1371. }
  1372. }
  1373. }',
  1374. '<?php
  1375. if (1)
  1376. foreach ($data as $val)
  1377. // test val
  1378. if ($val === "errors") {
  1379. echo "!";
  1380. }',
  1381. ],
  1382. [
  1383. '<?php
  1384. class Foo
  1385. {
  1386. public function main()
  1387. {
  1388. echo "Hello";
  1389. }
  1390. }',
  1391. '<?php
  1392. class Foo
  1393. {
  1394. public function main()
  1395. {
  1396. echo "Hello";
  1397. }
  1398. }',
  1399. ],
  1400. [
  1401. '<?php
  1402. class Foo
  1403. {
  1404. public function main()
  1405. {
  1406. echo "Hello";
  1407. }
  1408. }',
  1409. '<?php
  1410. class Foo
  1411. {
  1412. public function main()
  1413. {
  1414. echo "Hello";
  1415. }
  1416. }',
  1417. ],
  1418. [
  1419. '<?php
  1420. class Foo
  1421. {
  1422. public $bar;
  1423. public $baz;
  1424. }',
  1425. '<?php
  1426. class Foo
  1427. {
  1428. public $bar;
  1429. public $baz;
  1430. }',
  1431. ],
  1432. [
  1433. '<?php
  1434. function myFunction($foo, $bar)
  1435. {
  1436. return \Foo::{$foo}($bar);
  1437. }',
  1438. ],
  1439. [
  1440. '<?php
  1441. class C
  1442. {
  1443. public function __construct(
  1444. )
  1445. //comment
  1446. {
  1447. }
  1448. }',
  1449. '<?php
  1450. class C {
  1451. public function __construct(
  1452. )
  1453. //comment
  1454. {}
  1455. }',
  1456. ],
  1457. [
  1458. '<?php
  1459. if (true):
  1460. $foo = 0;
  1461. endif;',
  1462. null,
  1463. self::$configurationOopPositionSameLine,
  1464. ],
  1465. [
  1466. '<?php
  1467. if (true) :
  1468. $foo = 0;
  1469. endif;',
  1470. null,
  1471. self::$configurationOopPositionSameLine,
  1472. ],
  1473. [
  1474. '<?php
  1475. if (true) : $foo = 1; endif;',
  1476. null,
  1477. self::$configurationOopPositionSameLine,
  1478. ],
  1479. [
  1480. '<?php
  1481. if (true) {
  1482. $foo = 1;
  1483. }',
  1484. '<?php
  1485. if (true)$foo = 1;',
  1486. self::$configurationOopPositionSameLine,
  1487. ],
  1488. [
  1489. '<?php
  1490. if (true) {
  1491. $foo = 2;
  1492. }',
  1493. '<?php
  1494. if (true) $foo = 2;',
  1495. self::$configurationOopPositionSameLine,
  1496. ],
  1497. [
  1498. '<?php
  1499. if (true) {
  1500. $foo = 3;
  1501. }',
  1502. '<?php
  1503. if (true){$foo = 3;}',
  1504. self::$configurationOopPositionSameLine,
  1505. ],
  1506. [
  1507. '<?php
  1508. if (true) {
  1509. echo 1;
  1510. } else {
  1511. echo 2;
  1512. }',
  1513. '<?php
  1514. if(true) { echo 1; } else echo 2;',
  1515. self::$configurationOopPositionSameLine,
  1516. ],
  1517. [
  1518. '<?php
  1519. if (true) {
  1520. echo 3;
  1521. } else {
  1522. echo 4;
  1523. }',
  1524. '<?php
  1525. if(true) echo 3; else { echo 4; }',
  1526. self::$configurationOopPositionSameLine,
  1527. ],
  1528. [
  1529. '<?php
  1530. if (true) {
  1531. echo 5;
  1532. } else {
  1533. echo 6;
  1534. }',
  1535. '<?php
  1536. if (true) echo 5; else echo 6;',
  1537. self::$configurationOopPositionSameLine,
  1538. ],
  1539. [
  1540. '<?php
  1541. if (true) {
  1542. while (true) {
  1543. $foo = 1;
  1544. $bar = 2;
  1545. }
  1546. }',
  1547. '<?php
  1548. if (true) while (true) { $foo = 1; $bar = 2;}',
  1549. self::$configurationOopPositionSameLine,
  1550. ],
  1551. [
  1552. '<?php
  1553. if (true) {
  1554. if (true) {
  1555. echo 1;
  1556. } else {
  1557. echo 2;
  1558. }
  1559. } else {
  1560. echo 3;
  1561. }',
  1562. '<?php
  1563. if (true) if (true) echo 1; else echo 2; else echo 3;',
  1564. self::$configurationOopPositionSameLine,
  1565. ],
  1566. [
  1567. '<?php
  1568. if (true) {
  1569. // sth here...
  1570. if ($a && ($b || $c)) {
  1571. $d = 1;
  1572. }
  1573. }',
  1574. '<?php
  1575. if (true) {
  1576. // sth here...
  1577. if ($a && ($b || $c)) $d = 1;
  1578. }',
  1579. self::$configurationOopPositionSameLine,
  1580. ],
  1581. [
  1582. '<?php
  1583. for ($i = 1; $i < 10; ++$i) {
  1584. echo $i;
  1585. }
  1586. for ($i = 1; $i < 10; ++$i) {
  1587. echo $i;
  1588. }',
  1589. '<?php
  1590. for ($i = 1; $i < 10; ++$i) echo $i;
  1591. for ($i = 1; $i < 10; ++$i) { echo $i; }',
  1592. self::$configurationOopPositionSameLine,
  1593. ],
  1594. [
  1595. '<?php
  1596. for ($i = 1; $i < 5; ++$i) {
  1597. for ($i = 1; $i < 10; ++$i) {
  1598. echo $i;
  1599. }
  1600. }',
  1601. '<?php
  1602. for ($i = 1; $i < 5; ++$i) for ($i = 1; $i < 10; ++$i) { echo $i; }',
  1603. self::$configurationOopPositionSameLine,
  1604. ],
  1605. [
  1606. '<?php
  1607. do {
  1608. echo 1;
  1609. } while (false);',
  1610. '<?php
  1611. do { echo 1; } while (false);',
  1612. self::$configurationOopPositionSameLine,
  1613. ],
  1614. [
  1615. '<?php
  1616. while ($foo->next());',
  1617. null,
  1618. self::$configurationOopPositionSameLine,
  1619. ],
  1620. [
  1621. '<?php
  1622. foreach ($foo as $bar) {
  1623. echo $bar;
  1624. }',
  1625. '<?php
  1626. foreach ($foo as $bar) echo $bar;',
  1627. self::$configurationOopPositionSameLine,
  1628. ],
  1629. [
  1630. '<?php
  1631. if (true) {
  1632. $a = 1;
  1633. }',
  1634. '<?php
  1635. if (true) {$a = 1;}',
  1636. self::$configurationOopPositionSameLine,
  1637. ],
  1638. [
  1639. '<?php
  1640. if (true) {
  1641. $a = 1;
  1642. }',
  1643. '<?php
  1644. if (true) {
  1645. $a = 1;
  1646. }',
  1647. self::$configurationOopPositionSameLine,
  1648. ],
  1649. [
  1650. '<?php
  1651. if (true) {
  1652. $a = 1;
  1653. $b = 2;
  1654. while (true) {
  1655. $c = 3;
  1656. }
  1657. $d = 4;
  1658. }',
  1659. '<?php
  1660. if (true) {
  1661. $a = 1;
  1662. $b = 2;
  1663. while (true) {
  1664. $c = 3;
  1665. }
  1666. $d = 4;
  1667. }',
  1668. self::$configurationOopPositionSameLine,
  1669. ],
  1670. [
  1671. '<?php
  1672. if (true) {
  1673. $a = 1;
  1674. $b = 2;
  1675. }',
  1676. null,
  1677. self::$configurationOopPositionSameLine,
  1678. ],
  1679. [
  1680. '<?php
  1681. if (1) {
  1682. $a = 1;
  1683. // comment at end
  1684. }',
  1685. null,
  1686. self::$configurationOopPositionSameLine,
  1687. ],
  1688. [
  1689. '<?php
  1690. if (1) {
  1691. if (2) {
  1692. $a = "a";
  1693. } elseif (3) {
  1694. $b = "b";
  1695. // comment
  1696. } else {
  1697. $c = "c";
  1698. }
  1699. $d = "d";
  1700. }',
  1701. null,
  1702. self::$configurationOopPositionSameLine,
  1703. ],
  1704. [
  1705. '<?php
  1706. foreach ($numbers as $num) {
  1707. for ($i = 0; $i < $num; ++$i) {
  1708. $a = "a";
  1709. }
  1710. $b = "b";
  1711. }',
  1712. null,
  1713. self::$configurationOopPositionSameLine,
  1714. ],
  1715. [
  1716. '<?php
  1717. if (1) {
  1718. if (2) {
  1719. $foo = 2;
  1720. if (3) {
  1721. $foo = 3;
  1722. }
  1723. }
  1724. }',
  1725. null,
  1726. self::$configurationOopPositionSameLine,
  1727. ],
  1728. [
  1729. '<?php
  1730. declare(ticks = 1) {
  1731. $ticks = 1;
  1732. }',
  1733. '<?php
  1734. declare (
  1735. ticks = 1 ) {
  1736. $ticks = 1;
  1737. }',
  1738. self::$configurationOopPositionSameLine,
  1739. ],
  1740. [
  1741. '<?php
  1742. if (true) {
  1743. foo();
  1744. } elseif (true) {
  1745. bar();
  1746. }',
  1747. '<?php
  1748. if (true)
  1749. {
  1750. foo();
  1751. } elseif (true)
  1752. {
  1753. bar();
  1754. }',
  1755. self::$configurationOopPositionSameLine,
  1756. ],
  1757. [
  1758. '<?php
  1759. while (true) {
  1760. foo();
  1761. }',
  1762. '<?php
  1763. while (true)
  1764. {
  1765. foo();
  1766. }',
  1767. self::$configurationOopPositionSameLine,
  1768. ],
  1769. [
  1770. '<?php
  1771. do {
  1772. echo $test;
  1773. } while ($test = $this->getTest());',
  1774. '<?php
  1775. do
  1776. {
  1777. echo $test;
  1778. }
  1779. while ($test = $this->getTest());',
  1780. self::$configurationOopPositionSameLine,
  1781. ],
  1782. [
  1783. '<?php
  1784. do {
  1785. echo $test;
  1786. } while ($test = $this->getTest());',
  1787. '<?php
  1788. do
  1789. {
  1790. echo $test;
  1791. }while ($test = $this->getTest());',
  1792. self::$configurationOopPositionSameLine,
  1793. ],
  1794. [
  1795. '<?php
  1796. class ClassName {
  1797. /**
  1798. * comment
  1799. */
  1800. public $foo = null;
  1801. }',
  1802. '<?php
  1803. class ClassName
  1804. {
  1805. /**
  1806. * comment
  1807. */
  1808. public $foo = null;
  1809. }',
  1810. self::$configurationOopPositionSameLine,
  1811. ],
  1812. [
  1813. '<?php
  1814. class ClassName {
  1815. /**
  1816. * comment
  1817. */
  1818. public $foo = null;
  1819. }',
  1820. '<?php
  1821. class ClassName
  1822. {
  1823. /**
  1824. * comment
  1825. */
  1826. public $foo = null;
  1827. }',
  1828. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  1829. ],
  1830. [
  1831. '<?php
  1832. while ($true) {
  1833. try {
  1834. throw new \Exception();
  1835. } catch (\Exception $e) {
  1836. // do nothing
  1837. }
  1838. }',
  1839. null,
  1840. self::$configurationOopPositionSameLine,
  1841. ],
  1842. [
  1843. '<?php
  1844. while ($true)
  1845. {
  1846. try
  1847. {
  1848. throw new \Exception();
  1849. }
  1850. catch (\Exception $e)
  1851. {
  1852. // do nothing
  1853. }
  1854. }',
  1855. '<?php
  1856. while ($true) {
  1857. try {
  1858. throw new \Exception();
  1859. } catch (\Exception $e) {
  1860. // do nothing
  1861. }
  1862. }',
  1863. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  1864. ],
  1865. [
  1866. '<?php
  1867. interface Foo {
  1868. public function setConfig(ConfigInterface $config);
  1869. }',
  1870. '<?php
  1871. interface Foo
  1872. {
  1873. public function setConfig(ConfigInterface $config);
  1874. }',
  1875. self::$configurationOopPositionSameLine,
  1876. ],
  1877. [
  1878. '<?php
  1879. interface Foo {
  1880. public function setConfig(ConfigInterface $config);
  1881. }',
  1882. '<?php
  1883. interface Foo
  1884. {
  1885. public function setConfig(ConfigInterface $config);
  1886. }',
  1887. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  1888. ],
  1889. [
  1890. '<?php
  1891. function bar() {
  1892. $a = 1; //comment
  1893. }',
  1894. '<?php
  1895. function bar()
  1896. {
  1897. $a = 1; //comment
  1898. }',
  1899. self::$configurationOopPositionSameLine,
  1900. ],
  1901. [
  1902. '<?php
  1903. function & lambda() {
  1904. return function () {
  1905. };
  1906. }',
  1907. '<?php
  1908. function & lambda()
  1909. {
  1910. return function () {
  1911. };
  1912. }',
  1913. self::$configurationOopPositionSameLine,
  1914. ],
  1915. [
  1916. '<?php
  1917. function & lambda() {
  1918. return function ()
  1919. {
  1920. };
  1921. }',
  1922. '<?php
  1923. function & lambda()
  1924. {
  1925. return function () {
  1926. };
  1927. }',
  1928. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  1929. ],
  1930. [
  1931. '<?php
  1932. function & lambda() {
  1933. return function () {
  1934. };
  1935. }',
  1936. '<?php
  1937. function & lambda()
  1938. {
  1939. return function () {
  1940. };
  1941. }',
  1942. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  1943. ],
  1944. [
  1945. '<?php
  1946. function nested() {
  1947. $a = "a{$b->c()}d";
  1948. }',
  1949. '<?php
  1950. function nested()
  1951. {
  1952. $a = "a{$b->c()}d";
  1953. }',
  1954. self::$configurationOopPositionSameLine,
  1955. ],
  1956. [
  1957. '<?php
  1958. function nested() {
  1959. $a = "a{$b->c()}d";
  1960. }',
  1961. '<?php
  1962. function nested()
  1963. {
  1964. $a = "a{$b->c()}d";
  1965. }',
  1966. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  1967. ],
  1968. [
  1969. '<?php
  1970. function foo() {
  1971. $a = $b->{$c->d}($e);
  1972. $f->{$g} = $h;
  1973. $i->{$j}[$k] = $l;
  1974. $m = $n->{$o};
  1975. $p = array($q->{$r}, $s->{$t});
  1976. $u->{$v}->w = 1;
  1977. }',
  1978. '<?php
  1979. function foo()
  1980. {
  1981. $a = $b->{$c->d}($e);
  1982. $f->{$g} = $h;
  1983. $i->{$j}[$k] = $l;
  1984. $m = $n->{$o};
  1985. $p = array($q->{$r}, $s->{$t});
  1986. $u->{$v}->w = 1;
  1987. }',
  1988. self::$configurationOopPositionSameLine,
  1989. ],
  1990. [
  1991. '<?php
  1992. function foo() {
  1993. $a = $b->{$c->d}($e);
  1994. $f->{$g} = $h;
  1995. $i->{$j}[$k] = $l;
  1996. $m = $n->{$o};
  1997. $p = array($q->{$r}, $s->{$t});
  1998. $u->{$v}->w = 1;
  1999. }',
  2000. '<?php
  2001. function foo()
  2002. {
  2003. $a = $b->{$c->d}($e);
  2004. $f->{$g} = $h;
  2005. $i->{$j}[$k] = $l;
  2006. $m = $n->{$o};
  2007. $p = array($q->{$r}, $s->{$t});
  2008. $u->{$v}->w = 1;
  2009. }',
  2010. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  2011. ],
  2012. [
  2013. '<?php
  2014. function mixed() {
  2015. $a = $b->{"a{$c}d"}();
  2016. }',
  2017. '<?php
  2018. function mixed()
  2019. {
  2020. $a = $b->{"a{$c}d"}();
  2021. }',
  2022. self::$configurationOopPositionSameLine,
  2023. ],
  2024. [
  2025. '<?php
  2026. function mixedComplex() {
  2027. $a = $b->{"a{$c->{\'foo-bar\'}()}d"}();
  2028. }',
  2029. '<?php
  2030. function mixedComplex()
  2031. {
  2032. $a = $b->{"a{$c->{\'foo-bar\'}()}d"}();
  2033. }',
  2034. self::$configurationOopPositionSameLine,
  2035. ],
  2036. [
  2037. '<?php
  2038. function mixedComplex() {
  2039. $a = ${"b{$foo}"}->{"a{$c->{\'foo-bar\'}()}d"}();
  2040. }',
  2041. '<?php
  2042. function mixedComplex()
  2043. {
  2044. $a = ${"b{$foo}"}->{"a{$c->{\'foo-bar\'}()}d"}();
  2045. }',
  2046. self::$configurationOopPositionSameLine,
  2047. ],
  2048. [
  2049. '<?php
  2050. if (true):
  2051. echo 1;
  2052. else:
  2053. echo 2;
  2054. endif;
  2055. ',
  2056. null,
  2057. self::$configurationOopPositionSameLine,
  2058. ],
  2059. [
  2060. '<?php
  2061. if (true):
  2062. echo 1;
  2063. else:
  2064. echo 2;
  2065. endif;
  2066. ',
  2067. null,
  2068. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  2069. ],
  2070. [
  2071. '<?php
  2072. if ($test) { //foo
  2073. echo 1;
  2074. }',
  2075. null,
  2076. self::$configurationOopPositionSameLine,
  2077. ],
  2078. [
  2079. '<?php
  2080. if (true) {
  2081. // foo
  2082. // bar
  2083. if (true) {
  2084. print("foo");
  2085. print("bar");
  2086. }
  2087. }',
  2088. '<?php
  2089. if (true)
  2090. // foo
  2091. // bar
  2092. {
  2093. if (true)
  2094. {
  2095. print("foo");
  2096. print("bar");
  2097. }
  2098. }',
  2099. self::$configurationOopPositionSameLine,
  2100. ],
  2101. [
  2102. '<?php
  2103. if (true)
  2104. {
  2105. // foo
  2106. // bar
  2107. if (true)
  2108. {
  2109. print("foo");
  2110. print("bar");
  2111. }
  2112. }',
  2113. '<?php
  2114. if (true)
  2115. // foo
  2116. // bar
  2117. {
  2118. if (true)
  2119. {
  2120. print("foo");
  2121. print("bar");
  2122. }
  2123. }',
  2124. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  2125. ],
  2126. [
  2127. '<?php
  2128. if (true) {
  2129. // foo
  2130. /* bar */
  2131. if (true) {
  2132. print("foo");
  2133. print("bar");
  2134. }
  2135. }',
  2136. '<?php
  2137. if (true)
  2138. // foo
  2139. /* bar */{
  2140. if (true)
  2141. {
  2142. print("foo");
  2143. print("bar");
  2144. }
  2145. }',
  2146. self::$configurationOopPositionSameLine,
  2147. ],
  2148. [
  2149. '<?php if (true) {
  2150. echo "s";
  2151. } ?>x',
  2152. '<?php if (true) echo "s" ?>x',
  2153. self::$configurationOopPositionSameLine,
  2154. ],
  2155. [
  2156. '<?php
  2157. class Foo {
  2158. public function getFaxNumbers() {
  2159. if (1) {
  2160. return $this->phoneNumbers->filter(function ($phone) {
  2161. $a = 1;
  2162. $b = 1;
  2163. $c = 1;
  2164. return ($phone->getType() === 1) ? true : false;
  2165. });
  2166. }
  2167. }
  2168. }',
  2169. '<?php
  2170. class Foo
  2171. {
  2172. public function getFaxNumbers()
  2173. {
  2174. if (1)
  2175. return $this->phoneNumbers->filter(function ($phone) {
  2176. $a = 1;
  2177. $b = 1;
  2178. $c = 1;
  2179. return ($phone->getType() === 1) ? true : false;
  2180. });
  2181. }
  2182. }',
  2183. self::$configurationOopPositionSameLine,
  2184. ],
  2185. [
  2186. '<?php
  2187. class Foo {
  2188. public function getFaxNumbers() {
  2189. if (1)
  2190. {
  2191. return $this->phoneNumbers->filter(function ($phone) {
  2192. $a = 1;
  2193. $b = 1;
  2194. $c = 1;
  2195. return ($phone->getType() === 1) ? true : false;
  2196. });
  2197. }
  2198. }
  2199. }',
  2200. '<?php
  2201. class Foo
  2202. {
  2203. public function getFaxNumbers()
  2204. {
  2205. if (1)
  2206. return $this->phoneNumbers->filter(function ($phone) {
  2207. $a = 1;
  2208. $b = 1;
  2209. $c = 1;
  2210. return ($phone->getType() === 1) ? true : false;
  2211. });
  2212. }
  2213. }',
  2214. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  2215. ],
  2216. [
  2217. '<?php
  2218. class Foo {
  2219. public function getFaxNumbers() {
  2220. if (1)
  2221. {
  2222. return $this->phoneNumbers->filter(function ($phone)
  2223. {
  2224. $a = 1;
  2225. $b = 1;
  2226. $c = 1;
  2227. return ($phone->getType() === 1) ? true : false;
  2228. });
  2229. }
  2230. }
  2231. }',
  2232. '<?php
  2233. class Foo
  2234. {
  2235. public function getFaxNumbers()
  2236. {
  2237. if (1)
  2238. return $this->phoneNumbers->filter(function ($phone) {
  2239. $a = 1;
  2240. $b = 1;
  2241. $c = 1;
  2242. return ($phone->getType() === 1) ? true : false;
  2243. });
  2244. }
  2245. }',
  2246. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine + self::$configurationAnonymousPositionNextLine,
  2247. ],
  2248. [
  2249. '<?php
  2250. if (true) {
  2251. if (true) {
  2252. echo 1;
  2253. } elseif (true) {
  2254. echo 2;
  2255. } else {
  2256. echo 3;
  2257. }
  2258. }
  2259. ',
  2260. '<?php
  2261. if(true)
  2262. if(true)
  2263. echo 1;
  2264. elseif(true)
  2265. echo 2;
  2266. else
  2267. echo 3;
  2268. ',
  2269. self::$configurationOopPositionSameLine,
  2270. ],
  2271. [
  2272. '<?php
  2273. if (true) {
  2274. if (true) {
  2275. echo 1;
  2276. } elseif (true) {
  2277. echo 2;
  2278. } else {
  2279. echo 3;
  2280. }
  2281. }
  2282. echo 4;
  2283. ',
  2284. '<?php
  2285. if(true)
  2286. if(true)
  2287. echo 1;
  2288. elseif(true)
  2289. echo 2;
  2290. else
  2291. echo 3;
  2292. echo 4;
  2293. ',
  2294. self::$configurationOopPositionSameLine,
  2295. ],
  2296. [
  2297. '<?php
  2298. if (true) {
  2299. if (true) {
  2300. echo 1;
  2301. } elseif (true) {
  2302. echo 2;
  2303. } else {
  2304. echo 3;
  2305. }
  2306. }',
  2307. '<?php
  2308. if(true) if(true) echo 1; elseif(true) echo 2; else echo 3;',
  2309. self::$configurationOopPositionSameLine,
  2310. ],
  2311. [
  2312. '<?php
  2313. if (true) {
  2314. if (true) {
  2315. echo 1;
  2316. } else {
  2317. echo 2;
  2318. }
  2319. } else {
  2320. echo 3;
  2321. }',
  2322. '<?php
  2323. if(true) if(true) echo 1; else echo 2; else echo 3;',
  2324. self::$configurationOopPositionSameLine,
  2325. ],
  2326. [
  2327. '<?php
  2328. foreach ($data as $val) {
  2329. // test val
  2330. if ($val === "errors") {
  2331. echo "!";
  2332. }
  2333. }',
  2334. '<?php
  2335. foreach ($data as $val)
  2336. // test val
  2337. if ($val === "errors") {
  2338. echo "!";
  2339. }',
  2340. self::$configurationOopPositionSameLine,
  2341. ],
  2342. [
  2343. '<?php
  2344. if (1) {
  2345. foreach ($data as $val) {
  2346. // test val
  2347. if ($val === "errors") {
  2348. echo "!";
  2349. }
  2350. }
  2351. }',
  2352. '<?php
  2353. if (1)
  2354. foreach ($data as $val)
  2355. // test val
  2356. if ($val === "errors") {
  2357. echo "!";
  2358. }',
  2359. self::$configurationOopPositionSameLine,
  2360. ],
  2361. [
  2362. '<?php
  2363. class Foo {
  2364. public function main() {
  2365. echo "Hello";
  2366. }
  2367. }',
  2368. '<?php
  2369. class Foo
  2370. {
  2371. public function main()
  2372. {
  2373. echo "Hello";
  2374. }
  2375. }',
  2376. self::$configurationOopPositionSameLine,
  2377. ],
  2378. [
  2379. '<?php
  2380. class Foo {
  2381. public function main() {
  2382. echo "Hello";
  2383. }
  2384. }',
  2385. '<?php
  2386. class Foo
  2387. {
  2388. public function main()
  2389. {
  2390. echo "Hello";
  2391. }
  2392. }',
  2393. self::$configurationOopPositionSameLine,
  2394. ],
  2395. [
  2396. '<?php
  2397. class Foo {
  2398. public function main() {
  2399. echo "Hello";
  2400. }
  2401. }',
  2402. '<?php
  2403. class Foo
  2404. {
  2405. public function main()
  2406. {
  2407. echo "Hello";
  2408. }
  2409. }',
  2410. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  2411. ],
  2412. [
  2413. '<?php
  2414. class Foo {
  2415. public $bar;
  2416. public $baz;
  2417. }',
  2418. '<?php
  2419. class Foo
  2420. {
  2421. public $bar;
  2422. public $baz;
  2423. }',
  2424. self::$configurationOopPositionSameLine,
  2425. ],
  2426. [
  2427. '<?php
  2428. function myFunction($foo, $bar) {
  2429. return \Foo::{$foo}($bar);
  2430. }',
  2431. '<?php
  2432. function myFunction($foo, $bar)
  2433. {
  2434. return \Foo::{$foo}($bar);
  2435. }',
  2436. self::$configurationOopPositionSameLine,
  2437. ],
  2438. [
  2439. '<?php
  2440. class C {
  2441. public function __construct(
  2442. )
  2443. //comment
  2444. {
  2445. }
  2446. }',
  2447. '<?php
  2448. class C {
  2449. public function __construct(
  2450. )
  2451. //comment
  2452. {}
  2453. }',
  2454. self::$configurationOopPositionSameLine,
  2455. ],
  2456. [
  2457. '<?php
  2458. class Something # a
  2459. {
  2460. public function sth() //
  2461. {
  2462. return function (int $foo) use ($bar) {
  2463. return $bar;
  2464. };
  2465. }
  2466. }
  2467. function C() /**/ // # /**/
  2468. {
  2469. }
  2470. function D() /**
  2471. *
  2472. */
  2473. {
  2474. }',
  2475. '<?php
  2476. class Something # a
  2477. {
  2478. public function sth() //
  2479. {
  2480. return function (int $foo) use ($bar) { return $bar; };
  2481. }
  2482. }
  2483. function C() /**/ // # /**/
  2484. {
  2485. }
  2486. function D() /**
  2487. *
  2488. */
  2489. {
  2490. }',
  2491. self::$configurationOopPositionSameLine,
  2492. ],
  2493. ];
  2494. }
  2495. /**
  2496. * @param string $expected
  2497. * @param null|string $input
  2498. *
  2499. * @dataProvider provideFixClassyBracesCases
  2500. */
  2501. public function testFixClassyBraces($expected, $input = null, array $configuration = [])
  2502. {
  2503. $this->fixer->configure($configuration);
  2504. $this->doTest($expected, $input);
  2505. }
  2506. public function provideFixClassyBracesCases()
  2507. {
  2508. return [
  2509. [
  2510. '<?php
  2511. class FooA
  2512. {
  2513. }',
  2514. '<?php
  2515. class FooA {}',
  2516. ],
  2517. [
  2518. '<?php
  2519. class FooB
  2520. {
  2521. }',
  2522. '<?php
  2523. class FooB{}',
  2524. ],
  2525. [
  2526. '<?php
  2527. class FooC
  2528. {
  2529. }',
  2530. '<?php
  2531. class FooC
  2532. {}',
  2533. ],
  2534. [
  2535. '<?php
  2536. interface FooD
  2537. {
  2538. }',
  2539. '<?php
  2540. interface FooD {}',
  2541. ],
  2542. [
  2543. '<?php
  2544. class TestClass extends BaseTestClass implements TestInterface
  2545. {
  2546. private $foo;
  2547. }',
  2548. '<?php
  2549. class TestClass extends BaseTestClass implements TestInterface { private $foo;}',
  2550. ],
  2551. [
  2552. '<?php
  2553. abstract class Foo
  2554. {
  2555. public function getProcess($foo)
  2556. {
  2557. return true;
  2558. }
  2559. }',
  2560. ],
  2561. ['<?php
  2562. function foo()
  2563. {
  2564. return "$c ($d)";
  2565. }',
  2566. ],
  2567. [
  2568. '<?php
  2569. class FooA {
  2570. }',
  2571. '<?php
  2572. class FooA {}',
  2573. self::$configurationOopPositionSameLine,
  2574. ],
  2575. [
  2576. '<?php
  2577. class FooB {
  2578. }',
  2579. '<?php
  2580. class FooB{}',
  2581. self::$configurationOopPositionSameLine,
  2582. ],
  2583. [
  2584. '<?php
  2585. class FooC {
  2586. }',
  2587. '<?php
  2588. class FooC
  2589. {}',
  2590. self::$configurationOopPositionSameLine,
  2591. ],
  2592. [
  2593. '<?php
  2594. interface FooD {
  2595. }',
  2596. '<?php
  2597. interface FooD {}',
  2598. self::$configurationOopPositionSameLine,
  2599. ],
  2600. [
  2601. '<?php
  2602. class TestClass extends BaseTestClass implements TestInterface {
  2603. private $foo;
  2604. }',
  2605. '<?php
  2606. class TestClass extends BaseTestClass implements TestInterface { private $foo;}',
  2607. self::$configurationOopPositionSameLine,
  2608. ],
  2609. [
  2610. '<?php
  2611. abstract class Foo {
  2612. public function getProcess($foo) {
  2613. return true;
  2614. }
  2615. }',
  2616. '<?php
  2617. abstract class Foo
  2618. {
  2619. public function getProcess($foo)
  2620. {
  2621. return true;
  2622. }
  2623. }',
  2624. self::$configurationOopPositionSameLine,
  2625. ],
  2626. [
  2627. '<?php
  2628. function foo() {
  2629. return "$c ($d)";
  2630. }',
  2631. '<?php
  2632. function foo()
  2633. {
  2634. return "$c ($d)";
  2635. }',
  2636. self::$configurationOopPositionSameLine,
  2637. ],
  2638. [
  2639. '<?php
  2640. trait TFoo
  2641. {
  2642. public $a;
  2643. }',
  2644. '<?php
  2645. trait TFoo {public $a;}',
  2646. ],
  2647. [
  2648. '<?php
  2649. trait TFoo {
  2650. public $a;
  2651. }',
  2652. '<?php
  2653. trait TFoo {public $a;}',
  2654. self::$configurationOopPositionSameLine,
  2655. ],
  2656. [
  2657. '<?php
  2658. trait TFoo
  2659. {
  2660. public $a;
  2661. }',
  2662. '<?php
  2663. trait TFoo {public $a;}',
  2664. ],
  2665. [
  2666. '<?php
  2667. trait TFoo {
  2668. public $a;
  2669. }',
  2670. '<?php
  2671. trait TFoo {public $a;}',
  2672. self::$configurationOopPositionSameLine,
  2673. ],
  2674. ];
  2675. }
  2676. /**
  2677. * @param string $expected
  2678. * @param null|string $input
  2679. *
  2680. * @dataProvider provideFixAnonFunctionInShortArraySyntaxCases
  2681. */
  2682. public function testFixAnonFunctionInShortArraySyntax($expected, $input = null, array $configuration = [])
  2683. {
  2684. $this->fixer->configure($configuration);
  2685. $this->doTest($expected, $input);
  2686. }
  2687. public function provideFixAnonFunctionInShortArraySyntaxCases()
  2688. {
  2689. return [
  2690. [
  2691. '<?php
  2692. function myFunction()
  2693. {
  2694. return [
  2695. [
  2696. "callback" => function ($data) {
  2697. return true;
  2698. }
  2699. ],
  2700. [
  2701. "callback" => function ($data) {
  2702. return true;
  2703. },
  2704. ],
  2705. ];
  2706. }',
  2707. '<?php
  2708. function myFunction()
  2709. {
  2710. return [
  2711. [
  2712. "callback" => function ($data) {
  2713. return true;
  2714. }
  2715. ],
  2716. [
  2717. "callback" => function ($data) { return true; },
  2718. ],
  2719. ];
  2720. }',
  2721. ],
  2722. [
  2723. '<?php
  2724. function myFunction() {
  2725. return [
  2726. [
  2727. "callback" => function ($data) {
  2728. return true;
  2729. }
  2730. ],
  2731. [
  2732. "callback" => function ($data) {
  2733. return true;
  2734. },
  2735. ],
  2736. ];
  2737. }',
  2738. '<?php
  2739. function myFunction()
  2740. {
  2741. return [
  2742. [
  2743. "callback" => function ($data) {
  2744. return true;
  2745. }
  2746. ],
  2747. [
  2748. "callback" => function ($data) { return true; },
  2749. ],
  2750. ];
  2751. }',
  2752. self::$configurationOopPositionSameLine,
  2753. ],
  2754. [
  2755. '<?php
  2756. function myFunction() {
  2757. return [
  2758. [
  2759. "callback" => function ($data)
  2760. {
  2761. return true;
  2762. }
  2763. ],
  2764. [
  2765. "callback" => function ($data)
  2766. {
  2767. return true;
  2768. },
  2769. ],
  2770. ];
  2771. }',
  2772. '<?php
  2773. function myFunction()
  2774. {
  2775. return [
  2776. [
  2777. "callback" => function ($data) {
  2778. return true;
  2779. }
  2780. ],
  2781. [
  2782. "callback" => function ($data) { return true; },
  2783. ],
  2784. ];
  2785. }',
  2786. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  2787. ],
  2788. ];
  2789. }
  2790. /**
  2791. * @param string $expected
  2792. * @param null|string $input
  2793. *
  2794. * @dataProvider provideFixCommentBeforeBraceCases
  2795. */
  2796. public function testFixCommentBeforeBrace($expected, $input = null, array $configuration = [])
  2797. {
  2798. $this->fixer->configure($configuration);
  2799. $this->doTest($expected, $input);
  2800. }
  2801. public function provideFixCommentBeforeBraceCases()
  2802. {
  2803. return [
  2804. [
  2805. '<?php ',
  2806. ],
  2807. [
  2808. '<?php
  2809. if ($test) { // foo
  2810. echo 1;
  2811. }',
  2812. '<?php
  2813. if ($test) // foo
  2814. {
  2815. echo 1;
  2816. }',
  2817. ],
  2818. [
  2819. '<?php
  2820. $foo = function ($x) use ($y) { // foo
  2821. echo 1;
  2822. };',
  2823. '<?php
  2824. $foo = function ($x) use ($y) // foo
  2825. {
  2826. echo 1;
  2827. };',
  2828. ],
  2829. [
  2830. '<?php ',
  2831. null,
  2832. self::$configurationOopPositionSameLine,
  2833. ],
  2834. [
  2835. '<?php
  2836. if ($test) { // foo
  2837. echo 1;
  2838. }',
  2839. '<?php
  2840. if ($test) // foo
  2841. {
  2842. echo 1;
  2843. }',
  2844. self::$configurationOopPositionSameLine,
  2845. ],
  2846. [
  2847. '<?php
  2848. $foo = function ($x) use ($y) { // foo
  2849. echo 1;
  2850. };',
  2851. '<?php
  2852. $foo = function ($x) use ($y) // foo
  2853. {
  2854. echo 1;
  2855. };',
  2856. self::$configurationOopPositionSameLine,
  2857. ],
  2858. [
  2859. '<?php
  2860. // 2.5+ API
  2861. if (isNewApi()) {
  2862. echo "new API";
  2863. // 2.4- API
  2864. } elseif (isOldApi()) {
  2865. echo "old API";
  2866. // 2.4- API
  2867. } else {
  2868. echo "unknown API";
  2869. // sth
  2870. }
  2871. return $this->guess($class, $property, function (Constraint $constraint) use ($guesser) {
  2872. return $guesser->guessRequiredForConstraint($constraint);
  2873. // Fallback to false...
  2874. // ... due to sth...
  2875. }, false);
  2876. ',
  2877. ],
  2878. [
  2879. '<?php
  2880. if ($a) { //
  2881. ?><?php ++$a;
  2882. } ?>',
  2883. ],
  2884. [
  2885. '<?php
  2886. if ($a) { /* */ /* */ /* */ /* */ /* */
  2887. ?><?php ++$a;
  2888. } ?>',
  2889. ],
  2890. ];
  2891. }
  2892. /**
  2893. * @param string $expected
  2894. * @param null|string $input
  2895. *
  2896. * @dataProvider provideFixCommentBeforeBrace70Cases
  2897. * @requires PHP 7.0
  2898. */
  2899. public function testFixCommentBeforeBrace70($expected, $input = null, array $configuration = [])
  2900. {
  2901. $this->fixer->configure($configuration);
  2902. $this->doTest($expected, $input);
  2903. }
  2904. public function provideFixCommentBeforeBrace70Cases()
  2905. {
  2906. return [
  2907. [
  2908. '<?php
  2909. $foo = new class ($a) extends Foo implements Bar { // foo
  2910. private $x;
  2911. };',
  2912. '<?php
  2913. $foo = new class ($a) extends Foo implements Bar // foo
  2914. {
  2915. private $x;
  2916. };',
  2917. ],
  2918. [
  2919. '<?php
  2920. $foo = new class ($a) extends Foo implements Bar { // foo
  2921. private $x;
  2922. };',
  2923. '<?php
  2924. $foo = new class ($a) extends Foo implements Bar // foo
  2925. {
  2926. private $x;
  2927. };',
  2928. self::$configurationOopPositionSameLine,
  2929. ],
  2930. ];
  2931. }
  2932. /**
  2933. * @param string $expected
  2934. * @param null|string $input
  2935. *
  2936. * @dataProvider provideFixWhitespaceBeforeBraceCases
  2937. */
  2938. public function testFixWhitespaceBeforeBrace($expected, $input = null, array $configuration = [])
  2939. {
  2940. $this->fixer->configure($configuration);
  2941. $this->doTest($expected, $input);
  2942. }
  2943. public function provideFixWhitespaceBeforeBraceCases()
  2944. {
  2945. return [
  2946. [
  2947. '<?php
  2948. if (true) {
  2949. echo 1;
  2950. }',
  2951. '<?php
  2952. if (true)
  2953. {
  2954. echo 1;
  2955. }',
  2956. ],
  2957. [
  2958. '<?php
  2959. if (true) {
  2960. echo 1;
  2961. }',
  2962. '<?php
  2963. if (true){
  2964. echo 1;
  2965. }',
  2966. ],
  2967. [
  2968. '<?php
  2969. if (true) {
  2970. echo 1;
  2971. }',
  2972. '<?php
  2973. if (true) {
  2974. echo 1;
  2975. }',
  2976. ],
  2977. [
  2978. '<?php
  2979. while ($file = $this->getFile()) {
  2980. }',
  2981. '<?php
  2982. while ($file = $this->getFile())
  2983. {
  2984. }',
  2985. ],
  2986. [
  2987. '<?php
  2988. switch (n) {
  2989. case label1:
  2990. echo 1;
  2991. echo 2;
  2992. break;
  2993. default:
  2994. echo 3;
  2995. echo 4;
  2996. }',
  2997. '<?php
  2998. switch (n)
  2999. {
  3000. case label1:
  3001. echo 1;
  3002. echo 2;
  3003. break;
  3004. default:
  3005. echo 3;
  3006. echo 4;
  3007. }',
  3008. ],
  3009. [
  3010. '<?php
  3011. if (true) {
  3012. echo 1;
  3013. }',
  3014. '<?php
  3015. if (true)
  3016. {
  3017. echo 1;
  3018. }',
  3019. self::$configurationOopPositionSameLine,
  3020. ],
  3021. [
  3022. '<?php
  3023. if (true) {
  3024. echo 1;
  3025. }',
  3026. '<?php
  3027. if (true){
  3028. echo 1;
  3029. }',
  3030. self::$configurationOopPositionSameLine,
  3031. ],
  3032. [
  3033. '<?php
  3034. if (true) {
  3035. echo 1;
  3036. }',
  3037. '<?php
  3038. if (true) {
  3039. echo 1;
  3040. }',
  3041. self::$configurationOopPositionSameLine,
  3042. ],
  3043. [
  3044. '<?php
  3045. while ($file = $this->getFile()) {
  3046. }',
  3047. '<?php
  3048. while ($file = $this->getFile())
  3049. {
  3050. }',
  3051. self::$configurationOopPositionSameLine,
  3052. ],
  3053. [
  3054. '<?php
  3055. switch (n) {
  3056. case label1:
  3057. echo 1;
  3058. echo 2;
  3059. break;
  3060. default:
  3061. echo 3;
  3062. echo 4;
  3063. }',
  3064. '<?php
  3065. switch (n)
  3066. {
  3067. case label1:
  3068. echo 1;
  3069. echo 2;
  3070. break;
  3071. default:
  3072. echo 3;
  3073. echo 4;
  3074. }',
  3075. self::$configurationOopPositionSameLine,
  3076. ],
  3077. [
  3078. '<?php
  3079. if (true) {
  3080. echo 1;
  3081. }',
  3082. '<?php
  3083. if (true)
  3084. {
  3085. echo 1;
  3086. }',
  3087. self::$configurationAnonymousPositionNextLine,
  3088. ],
  3089. [
  3090. '<?php
  3091. if (true) {
  3092. echo 1;
  3093. }',
  3094. '<?php
  3095. if (true){
  3096. echo 1;
  3097. }',
  3098. self::$configurationAnonymousPositionNextLine,
  3099. ],
  3100. [
  3101. '<?php
  3102. if (true) {
  3103. echo 1;
  3104. }',
  3105. '<?php
  3106. if (true) {
  3107. echo 1;
  3108. }',
  3109. self::$configurationAnonymousPositionNextLine,
  3110. ],
  3111. [
  3112. '<?php
  3113. while ($file = $this->getFile()) {
  3114. }',
  3115. '<?php
  3116. while ($file = $this->getFile())
  3117. {
  3118. }',
  3119. self::$configurationAnonymousPositionNextLine,
  3120. ],
  3121. [
  3122. '<?php
  3123. switch (n) {
  3124. case label1:
  3125. echo 1;
  3126. echo 2;
  3127. break;
  3128. default:
  3129. echo 3;
  3130. echo 4;
  3131. }',
  3132. '<?php
  3133. switch (n)
  3134. {
  3135. case label1:
  3136. echo 1;
  3137. echo 2;
  3138. break;
  3139. default:
  3140. echo 3;
  3141. echo 4;
  3142. }',
  3143. self::$configurationAnonymousPositionNextLine,
  3144. ],
  3145. ];
  3146. }
  3147. /**
  3148. * @param string $expected
  3149. * @param null|string $input
  3150. *
  3151. * @dataProvider provideFixFunctionsCases
  3152. */
  3153. public function testFixFunctions($expected, $input = null, array $configuration = [])
  3154. {
  3155. $this->fixer->configure($configuration);
  3156. $this->doTest($expected, $input);
  3157. }
  3158. public function provideFixFunctionsCases()
  3159. {
  3160. return [
  3161. [
  3162. '<?php
  3163. function download()
  3164. {
  3165. }',
  3166. '<?php
  3167. function download() {
  3168. }',
  3169. ],
  3170. [
  3171. '<?php
  3172. class Foo
  3173. {
  3174. public function AAAA()
  3175. {
  3176. }
  3177. public function BBBB()
  3178. {
  3179. }
  3180. public function CCCC()
  3181. {
  3182. }
  3183. }',
  3184. '<?php
  3185. class Foo
  3186. {
  3187. public function AAAA(){
  3188. }
  3189. public function BBBB() {
  3190. }
  3191. public function CCCC()
  3192. {
  3193. }
  3194. }',
  3195. ],
  3196. [
  3197. '<?php
  3198. filter(function () {
  3199. return true;
  3200. });
  3201. ',
  3202. ],
  3203. [
  3204. '<?php
  3205. filter(function ($a) {
  3206. });',
  3207. '<?php
  3208. filter(function ($a)
  3209. {});',
  3210. ],
  3211. [
  3212. '<?php
  3213. filter(function ($b) {
  3214. });',
  3215. '<?php
  3216. filter(function ($b){});',
  3217. ],
  3218. [
  3219. '<?php
  3220. foo(array_map(function ($object) use ($x, $y) {
  3221. return array_filter($object->bar(), function ($o) {
  3222. return $o->isBaz();
  3223. });
  3224. }, $collection));',
  3225. '<?php
  3226. foo(array_map(function ($object) use ($x, $y) { return array_filter($object->bar(), function ($o) { return $o->isBaz(); }); }, $collection));',
  3227. ],
  3228. [
  3229. '<?php
  3230. class Foo
  3231. {
  3232. public static function bar()
  3233. {
  3234. return 1;
  3235. }
  3236. }',
  3237. ],
  3238. [
  3239. '<?php
  3240. usort($this->fixers, function &($a, $b) use ($selfName) {
  3241. return 1;
  3242. });',
  3243. ],
  3244. [
  3245. '<?php
  3246. usort(
  3247. $this->fixers,
  3248. function &($a, $b) use ($selfName) {
  3249. return 1;
  3250. }
  3251. );',
  3252. ],
  3253. [
  3254. '<?php
  3255. $fnc = function ($a, $b) { // random comment
  3256. return 0;
  3257. };',
  3258. '<?php
  3259. $fnc = function ($a, $b) // random comment
  3260. {
  3261. return 0;
  3262. };',
  3263. ],
  3264. [
  3265. '<?php
  3266. $fnc = function ($a, $b) { # random comment
  3267. return 0;
  3268. };',
  3269. '<?php
  3270. $fnc = function ($a, $b) # random comment
  3271. {
  3272. return 0;
  3273. };',
  3274. ],
  3275. [
  3276. '<?php
  3277. $fnc = function ($a, $b) /* random comment */ {
  3278. return 0;
  3279. };',
  3280. '<?php
  3281. $fnc = function ($a, $b) /* random comment */
  3282. {
  3283. return 0;
  3284. };',
  3285. ],
  3286. [
  3287. '<?php
  3288. $fnc = function ($a, $b) /** random comment */ {
  3289. return 0;
  3290. };',
  3291. '<?php
  3292. $fnc = function ($a, $b) /** random comment */
  3293. {
  3294. return 0;
  3295. };',
  3296. ],
  3297. [
  3298. '<?php
  3299. function download() {
  3300. }',
  3301. null,
  3302. self::$configurationOopPositionSameLine,
  3303. ],
  3304. [
  3305. '<?php
  3306. class Foo {
  3307. public function AAAA() {
  3308. }
  3309. public function BBBB() {
  3310. }
  3311. public function CCCC() {
  3312. }
  3313. }',
  3314. '<?php
  3315. class Foo
  3316. {
  3317. public function AAAA(){
  3318. }
  3319. public function BBBB() {
  3320. }
  3321. public function CCCC()
  3322. {
  3323. }
  3324. }',
  3325. self::$configurationOopPositionSameLine,
  3326. ],
  3327. [
  3328. '<?php
  3329. filter(function () {
  3330. return true;
  3331. });
  3332. ',
  3333. null,
  3334. self::$configurationOopPositionSameLine,
  3335. ],
  3336. [
  3337. '<?php
  3338. filter(function ($a) {
  3339. });',
  3340. '<?php
  3341. filter(function ($a)
  3342. {});',
  3343. self::$configurationOopPositionSameLine,
  3344. ],
  3345. [
  3346. '<?php
  3347. filter(function ($b) {
  3348. });',
  3349. '<?php
  3350. filter(function ($b){});',
  3351. self::$configurationOopPositionSameLine,
  3352. ],
  3353. [
  3354. '<?php
  3355. foo(array_map(function ($object) use ($x, $y) {
  3356. return array_filter($object->bar(), function ($o) {
  3357. return $o->isBaz();
  3358. });
  3359. }, $collection));',
  3360. '<?php
  3361. foo(array_map(function ($object) use ($x, $y) { return array_filter($object->bar(), function ($o) { return $o->isBaz(); }); }, $collection));',
  3362. self::$configurationOopPositionSameLine,
  3363. ],
  3364. [
  3365. '<?php
  3366. foo(array_map(function ($object) use ($x, $y)
  3367. {
  3368. return array_filter($object->bar(), function ($o)
  3369. {
  3370. return $o->isBaz();
  3371. });
  3372. }, $collection));',
  3373. '<?php
  3374. foo(array_map(function ($object) use ($x, $y) { return array_filter($object->bar(), function ($o) { return $o->isBaz(); }); }, $collection));',
  3375. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  3376. ],
  3377. [
  3378. '<?php
  3379. class Foo {
  3380. public static function bar() {
  3381. return 1;
  3382. }
  3383. }',
  3384. '<?php
  3385. class Foo
  3386. {
  3387. public static function bar()
  3388. {
  3389. return 1;
  3390. }
  3391. }',
  3392. self::$configurationOopPositionSameLine,
  3393. ],
  3394. [
  3395. '<?php
  3396. class Foo {
  3397. public static function bar() {
  3398. return 1;
  3399. }
  3400. }',
  3401. '<?php
  3402. class Foo
  3403. {
  3404. public static function bar()
  3405. {
  3406. return 1;
  3407. }
  3408. }',
  3409. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  3410. ],
  3411. [
  3412. '<?php
  3413. class Foo {
  3414. public static function bar() {
  3415. return 1;
  3416. }
  3417. }',
  3418. '<?php
  3419. class Foo
  3420. {
  3421. public static function bar()
  3422. {
  3423. return 1;
  3424. }
  3425. }',
  3426. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  3427. ],
  3428. [
  3429. '<?php
  3430. usort($this->fixers, function &($a, $b) use ($selfName) {
  3431. return 1;
  3432. });',
  3433. null,
  3434. self::$configurationOopPositionSameLine,
  3435. ],
  3436. [
  3437. '<?php
  3438. usort(
  3439. $this->fixers,
  3440. function &($a, $b) use ($selfName) {
  3441. return 1;
  3442. }
  3443. );',
  3444. null,
  3445. self::$configurationOopPositionSameLine,
  3446. ],
  3447. [
  3448. '<?php
  3449. $fnc = function ($a, $b) { // random comment
  3450. return 0;
  3451. };',
  3452. '<?php
  3453. $fnc = function ($a, $b) // random comment
  3454. {
  3455. return 0;
  3456. };',
  3457. self::$configurationOopPositionSameLine,
  3458. ],
  3459. [
  3460. '<?php
  3461. $fnc = function ($a, $b) { # random comment
  3462. return 0;
  3463. };',
  3464. '<?php
  3465. $fnc = function ($a, $b) # random comment
  3466. {
  3467. return 0;
  3468. };',
  3469. self::$configurationOopPositionSameLine,
  3470. ],
  3471. [
  3472. '<?php
  3473. $fnc = function ($a, $b) /* random comment */ {
  3474. return 0;
  3475. };',
  3476. '<?php
  3477. $fnc = function ($a, $b) /* random comment */
  3478. {
  3479. return 0;
  3480. };',
  3481. self::$configurationOopPositionSameLine,
  3482. ],
  3483. [
  3484. '<?php
  3485. $fnc = function ($a, $b) /** random comment */ {
  3486. return 0;
  3487. };',
  3488. '<?php
  3489. $fnc = function ($a, $b) /** random comment */
  3490. {
  3491. return 0;
  3492. };',
  3493. self::$configurationOopPositionSameLine,
  3494. ],
  3495. ];
  3496. }
  3497. /**
  3498. * @param string $expected
  3499. * @param null|string $input
  3500. *
  3501. * @dataProvider provideFixMultiLineStructuresCases
  3502. */
  3503. public function testFixMultiLineStructures($expected, $input = null, array $configuration = [])
  3504. {
  3505. $this->fixer->configure($configuration);
  3506. $this->doTest($expected, $input);
  3507. }
  3508. public function provideFixMultiLineStructuresCases()
  3509. {
  3510. return [
  3511. [
  3512. '<?php
  3513. if (true === true
  3514. && true === true
  3515. ) {
  3516. }',
  3517. '<?php
  3518. if(true === true
  3519. && true === true
  3520. )
  3521. {
  3522. }',
  3523. self::$configurationCtrlStructPositionNextLine,
  3524. ],
  3525. [
  3526. '<?php
  3527. foreach (
  3528. $boo as $bar => $fooBarBazBuzz
  3529. ) {
  3530. }',
  3531. '<?php
  3532. foreach (
  3533. $boo as $bar => $fooBarBazBuzz
  3534. )
  3535. {
  3536. }',
  3537. self::$configurationCtrlStructPositionNextLine,
  3538. ],
  3539. [
  3540. '<?php
  3541. $foo = function (
  3542. $baz,
  3543. $boo
  3544. ) {
  3545. };',
  3546. '<?php
  3547. $foo = function (
  3548. $baz,
  3549. $boo
  3550. )
  3551. {
  3552. };',
  3553. self::$configurationAnonymousPositionNextLine,
  3554. ],
  3555. [
  3556. '<?php
  3557. class Foo
  3558. {
  3559. public static function bar(
  3560. $baz,
  3561. $boo
  3562. ) {
  3563. }
  3564. }',
  3565. '<?php
  3566. class Foo
  3567. {
  3568. public static function bar(
  3569. $baz,
  3570. $boo
  3571. )
  3572. {
  3573. }
  3574. }',
  3575. self::$configurationCtrlStructPositionNextLine,
  3576. ],
  3577. [
  3578. '<?php
  3579. if (true === true
  3580. && true === true
  3581. ) {
  3582. }',
  3583. '<?php
  3584. if(true === true
  3585. && true === true
  3586. )
  3587. {
  3588. }',
  3589. self::$configurationCtrlStructPositionNextLine,
  3590. ],
  3591. [
  3592. '<?php
  3593. if ($foo)
  3594. {
  3595. }
  3596. elseif (
  3597. true === true
  3598. && true === true
  3599. ) {
  3600. }',
  3601. '<?php
  3602. if ($foo)
  3603. {
  3604. }
  3605. elseif (
  3606. true === true
  3607. && true === true
  3608. )
  3609. {
  3610. }',
  3611. self::$configurationCtrlStructPositionNextLine,
  3612. ],
  3613. ];
  3614. }
  3615. /**
  3616. * @param string $expected
  3617. * @param null|string $input
  3618. *
  3619. * @dataProvider provideFixSpaceAroundTokenCases
  3620. */
  3621. public function testFixSpaceAroundToken($expected, $input = null, array $configuration = [])
  3622. {
  3623. $this->fixer->configure($configuration);
  3624. $this->doTest($expected, $input);
  3625. }
  3626. public function provideFixSpaceAroundTokenCases()
  3627. {
  3628. return [
  3629. [
  3630. '<?php
  3631. try {
  3632. throw new Exception();
  3633. } catch (Exception $e) {
  3634. log($e);
  3635. }',
  3636. '<?php
  3637. try{
  3638. throw new Exception();
  3639. }catch (Exception $e){
  3640. log($e);
  3641. }',
  3642. ],
  3643. [
  3644. '<?php
  3645. do {
  3646. echo 1;
  3647. } while ($test);',
  3648. '<?php
  3649. do{
  3650. echo 1;
  3651. }while($test);',
  3652. ],
  3653. [
  3654. '<?php
  3655. if (true === true
  3656. && true === true
  3657. ) {
  3658. }',
  3659. '<?php
  3660. if(true === true
  3661. && true === true
  3662. ) {
  3663. }',
  3664. ],
  3665. [
  3666. '<?php
  3667. if (1) {
  3668. }
  3669. if ($this->tesT ($test)) {
  3670. }',
  3671. '<?php
  3672. if(1){
  3673. }
  3674. if ($this->tesT ($test)) {
  3675. }',
  3676. ],
  3677. [
  3678. '<?php
  3679. if (true) {
  3680. } elseif (false) {
  3681. } else {
  3682. }',
  3683. '<?php
  3684. if(true){
  3685. }elseif(false){
  3686. }else{
  3687. }',
  3688. ],
  3689. [
  3690. '<?php
  3691. $foo = function& () use ($bar) {
  3692. };',
  3693. '<?php
  3694. $foo = function& ()use($bar){};',
  3695. ],
  3696. [
  3697. '<?php
  3698. // comment
  3699. declare(strict_types=1);
  3700. // comment
  3701. while (true) {
  3702. }',
  3703. ],
  3704. [
  3705. '<?php
  3706. declare(ticks = 1) {
  3707. }',
  3708. '<?php
  3709. declare ( ticks = 1 ) {
  3710. }',
  3711. ],
  3712. [
  3713. '<?php
  3714. try {
  3715. throw new Exception();
  3716. } catch (Exception $e) {
  3717. log($e);
  3718. }',
  3719. '<?php
  3720. try{
  3721. throw new Exception();
  3722. }catch (Exception $e){
  3723. log($e);
  3724. }',
  3725. self::$configurationOopPositionSameLine,
  3726. ],
  3727. [
  3728. '<?php
  3729. do {
  3730. echo 1;
  3731. } while ($test);',
  3732. '<?php
  3733. do{
  3734. echo 1;
  3735. }while($test);',
  3736. self::$configurationOopPositionSameLine,
  3737. ],
  3738. [
  3739. '<?php
  3740. if (true === true
  3741. && true === true
  3742. ) {
  3743. }',
  3744. '<?php
  3745. if(true === true
  3746. && true === true
  3747. ) {
  3748. }',
  3749. self::$configurationOopPositionSameLine,
  3750. ],
  3751. [
  3752. '<?php
  3753. if (1) {
  3754. }
  3755. if ($this->tesT ($test)) {
  3756. }',
  3757. '<?php
  3758. if(1){
  3759. }
  3760. if ($this->tesT ($test)) {
  3761. }',
  3762. self::$configurationOopPositionSameLine,
  3763. ],
  3764. [
  3765. '<?php
  3766. if (true) {
  3767. } elseif (false) {
  3768. } else {
  3769. }',
  3770. '<?php
  3771. if(true){
  3772. }elseif(false){
  3773. }else{
  3774. }',
  3775. self::$configurationOopPositionSameLine,
  3776. ],
  3777. [
  3778. '<?php
  3779. $foo = function& () use ($bar) {
  3780. };',
  3781. '<?php
  3782. $foo = function& ()use($bar){};',
  3783. self::$configurationOopPositionSameLine,
  3784. ],
  3785. [
  3786. '<?php
  3787. // comment
  3788. declare(strict_types=1);
  3789. // comment
  3790. while (true) {
  3791. }',
  3792. null,
  3793. self::$configurationOopPositionSameLine,
  3794. ],
  3795. [
  3796. '<?php
  3797. declare(ticks = 1) {
  3798. }',
  3799. '<?php
  3800. declare ( ticks = 1 ) {
  3801. }',
  3802. self::$configurationOopPositionSameLine,
  3803. ],
  3804. ];
  3805. }
  3806. /**
  3807. * @param string $expected
  3808. * @param null|string $input
  3809. *
  3810. * @dataProvider provideFinallyCases
  3811. */
  3812. public function testFinally($expected, $input = null, array $configuration = [])
  3813. {
  3814. $this->fixer->configure($configuration);
  3815. $this->doTest($expected, $input);
  3816. }
  3817. public function provideFinallyCases()
  3818. {
  3819. return [
  3820. [
  3821. '<?php
  3822. try {
  3823. throw new \Exception();
  3824. } catch (\LogicException $e) {
  3825. // do nothing
  3826. } catch (\Exception $e) {
  3827. // do nothing
  3828. } finally {
  3829. echo "finish!";
  3830. }',
  3831. '<?php
  3832. try {
  3833. throw new \Exception();
  3834. }catch (\LogicException $e) {
  3835. // do nothing
  3836. }
  3837. catch (\Exception $e) {
  3838. // do nothing
  3839. }
  3840. finally {
  3841. echo "finish!";
  3842. }',
  3843. ],
  3844. [
  3845. '<?php
  3846. try {
  3847. throw new \Exception();
  3848. } catch (\LogicException $e) {
  3849. // do nothing
  3850. } catch (\Exception $e) {
  3851. // do nothing
  3852. } finally {
  3853. echo "finish!";
  3854. }',
  3855. '<?php
  3856. try {
  3857. throw new \Exception();
  3858. }catch (\LogicException $e) {
  3859. // do nothing
  3860. }
  3861. catch (\Exception $e) {
  3862. // do nothing
  3863. }
  3864. finally {
  3865. echo "finish!";
  3866. }',
  3867. self::$configurationOopPositionSameLine,
  3868. ],
  3869. [
  3870. '<?php
  3871. try
  3872. {
  3873. throw new \Exception();
  3874. }
  3875. catch (\LogicException $e)
  3876. {
  3877. // do nothing
  3878. }
  3879. catch (\Exception $e)
  3880. {
  3881. // do nothing
  3882. }
  3883. finally
  3884. {
  3885. echo "finish!";
  3886. }',
  3887. '<?php
  3888. try {
  3889. throw new \Exception();
  3890. }catch (\LogicException $e) {
  3891. // do nothing
  3892. }
  3893. catch (\Exception $e) {
  3894. // do nothing
  3895. }
  3896. finally {
  3897. echo "finish!";
  3898. }',
  3899. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  3900. ],
  3901. ];
  3902. }
  3903. /**
  3904. * @param string $expected
  3905. * @param null|string $input
  3906. *
  3907. * @dataProvider provideFunctionImportCases
  3908. */
  3909. public function testFunctionImport($expected, $input = null, array $configuration = [])
  3910. {
  3911. $this->fixer->configure($configuration);
  3912. $this->doTest($expected, $input);
  3913. }
  3914. public function provideFunctionImportCases()
  3915. {
  3916. return [
  3917. [
  3918. '<?php
  3919. use function Foo\bar;
  3920. if (true) {
  3921. }',
  3922. ],
  3923. [
  3924. '<?php
  3925. use function Foo\bar;
  3926. if (true) {
  3927. }',
  3928. null,
  3929. self::$configurationOopPositionSameLine,
  3930. ],
  3931. [
  3932. '<?php
  3933. use function Foo\bar;
  3934. if (true)
  3935. {
  3936. }',
  3937. '<?php
  3938. use function Foo\bar;
  3939. if (true) {
  3940. }',
  3941. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  3942. ],
  3943. [
  3944. '<?php
  3945. use function Foo\bar;
  3946. if (true) {
  3947. }',
  3948. ],
  3949. ];
  3950. }
  3951. /**
  3952. * @param string $expected
  3953. * @param null|string $input
  3954. *
  3955. * @dataProvider provideFix70Cases
  3956. * @requires PHP 7.0
  3957. */
  3958. public function testFix70($expected, $input = null, array $configuration = [])
  3959. {
  3960. $this->fixer->configure($configuration);
  3961. $this->doTest($expected, $input);
  3962. }
  3963. public function provideFix70Cases()
  3964. {
  3965. return [
  3966. [
  3967. '<?php
  3968. function foo($a)
  3969. {
  3970. // foo
  3971. $foo = new class($a) extends Foo {
  3972. public function bar()
  3973. {
  3974. }
  3975. };
  3976. }',
  3977. '<?php
  3978. function foo($a)
  3979. {
  3980. // foo
  3981. $foo = new class($a) extends Foo { public function bar() {} };
  3982. }',
  3983. ],
  3984. [
  3985. '<?php
  3986. foo(1, new class implements Logger {
  3987. public function log($message)
  3988. {
  3989. log($message);
  3990. }
  3991. }, 3);',
  3992. '<?php
  3993. foo(1, new class implements Logger { public function log($message) { log($message); } }, 3);',
  3994. ],
  3995. [
  3996. '<?php
  3997. $message = (new class() implements FooInterface {
  3998. });',
  3999. '<?php
  4000. $message = (new class() implements FooInterface{});',
  4001. ],
  4002. [
  4003. '<?php $message = (new class() {
  4004. });',
  4005. '<?php $message = (new class() {});',
  4006. ],
  4007. [
  4008. '<?php
  4009. if (1) {
  4010. $message = (new class() extends Foo {
  4011. public function bar()
  4012. {
  4013. echo 1;
  4014. }
  4015. });
  4016. }',
  4017. '<?php
  4018. if (1) {
  4019. $message = (new class() extends Foo
  4020. {
  4021. public function bar() { echo 1; }
  4022. });
  4023. }',
  4024. ],
  4025. [
  4026. '<?php
  4027. class Foo
  4028. {
  4029. public function use()
  4030. {
  4031. }
  4032. public function use1(): string
  4033. {
  4034. }
  4035. }
  4036. ',
  4037. '<?php
  4038. class Foo
  4039. {
  4040. public function use() {
  4041. }
  4042. public function use1(): string {
  4043. }
  4044. }
  4045. ',
  4046. ],
  4047. [
  4048. '<?php
  4049. $a = function (int $foo): string {
  4050. echo $foo;
  4051. };
  4052. $b = function (int $foo) use ($bar): string {
  4053. echo $foo . $bar;
  4054. };
  4055. function a()
  4056. {
  4057. }
  4058. ',
  4059. '<?php
  4060. $a = function (int $foo): string
  4061. {
  4062. echo $foo;
  4063. };
  4064. $b = function (int $foo) use($bar): string
  4065. {
  4066. echo $foo . $bar;
  4067. };
  4068. function a() {
  4069. }
  4070. ',
  4071. ],
  4072. [
  4073. '<?php
  4074. class Something
  4075. {
  4076. public function sth(): string
  4077. {
  4078. return function (int $foo) use ($bar): string {
  4079. return $bar;
  4080. };
  4081. }
  4082. }',
  4083. '<?php
  4084. class Something
  4085. {
  4086. public function sth(): string
  4087. {
  4088. return function (int $foo) use ($bar): string { return $bar; };
  4089. }
  4090. }',
  4091. ],
  4092. [
  4093. '<?php
  4094. use function some\a\{
  4095. test1,
  4096. test2
  4097. };
  4098. test();',
  4099. ],
  4100. [
  4101. '<?php
  4102. use some\a\{ClassA, ClassB, ClassC as C};
  4103. use function some\a\{fn_a, fn_b, fn_c};
  4104. use const some\a\{ConstA, ConstB, ConstC};
  4105. ',
  4106. ],
  4107. [
  4108. '<?php
  4109. function foo($a) {
  4110. // foo
  4111. $foo = new class($a) extends Foo {
  4112. public function bar() {
  4113. }
  4114. };
  4115. }',
  4116. '<?php
  4117. function foo($a)
  4118. {
  4119. // foo
  4120. $foo = new class($a) extends Foo { public function bar() {} };
  4121. }',
  4122. self::$configurationOopPositionSameLine,
  4123. ],
  4124. [
  4125. '<?php
  4126. function foo($a)
  4127. {
  4128. // foo
  4129. $foo = new class($a) extends Foo {
  4130. public function bar()
  4131. {
  4132. }
  4133. };
  4134. }',
  4135. '<?php
  4136. function foo($a)
  4137. {
  4138. // foo
  4139. $foo = new class($a) extends Foo { public function bar() {} };
  4140. }',
  4141. self::$configurationCtrlStructPositionNextLine,
  4142. ],
  4143. [
  4144. '<?php
  4145. function foo($a) {
  4146. // foo
  4147. $foo = new class($a) extends Foo {
  4148. public function bar() {
  4149. }
  4150. };
  4151. }',
  4152. '<?php
  4153. function foo($a)
  4154. {
  4155. // foo
  4156. $foo = new class($a) extends Foo { public function bar() {} };
  4157. }',
  4158. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4159. ],
  4160. [
  4161. '<?php
  4162. function foo($a)
  4163. {
  4164. // foo
  4165. $foo = new class($a) extends Foo
  4166. {
  4167. public function bar()
  4168. {
  4169. }
  4170. };
  4171. }',
  4172. '<?php
  4173. function foo($a)
  4174. {
  4175. // foo
  4176. $foo = new class($a) extends Foo { public function bar() {} };
  4177. }',
  4178. self::$configurationAnonymousPositionNextLine,
  4179. ],
  4180. [
  4181. '<?php
  4182. function foo($a) {
  4183. // foo
  4184. $foo = new class($a) extends Foo
  4185. {
  4186. public function bar() {
  4187. }
  4188. };
  4189. }',
  4190. '<?php
  4191. function foo($a)
  4192. {
  4193. // foo
  4194. $foo = new class($a) extends Foo { public function bar() {} };
  4195. }',
  4196. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4197. ],
  4198. [
  4199. '<?php
  4200. foo(1, new class implements Logger {
  4201. public function log($message) {
  4202. log($message);
  4203. }
  4204. }, 3);',
  4205. '<?php
  4206. foo(1, new class implements Logger { public function log($message) { log($message); } }, 3);',
  4207. self::$configurationOopPositionSameLine,
  4208. ],
  4209. [
  4210. '<?php
  4211. foo(1, new class implements Logger {
  4212. public function log($message)
  4213. {
  4214. log($message);
  4215. }
  4216. }, 3);',
  4217. '<?php
  4218. foo(1, new class implements Logger { public function log($message) { log($message); } }, 3);',
  4219. self::$configurationCtrlStructPositionNextLine,
  4220. ],
  4221. [
  4222. '<?php
  4223. foo(1, new class implements Logger
  4224. {
  4225. public function log($message) {
  4226. log($message);
  4227. }
  4228. }, 3);',
  4229. '<?php
  4230. foo(1, new class implements Logger { public function log($message) { log($message); } }, 3);',
  4231. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4232. ],
  4233. [
  4234. '<?php
  4235. $message = (new class() implements FooInterface {
  4236. });',
  4237. '<?php
  4238. $message = (new class() implements FooInterface{});',
  4239. self::$configurationOopPositionSameLine,
  4240. ],
  4241. [
  4242. '<?php
  4243. $message = (new class() implements FooInterface {
  4244. });',
  4245. '<?php
  4246. $message = (new class() implements FooInterface{});',
  4247. self::$configurationCtrlStructPositionNextLine,
  4248. ],
  4249. [
  4250. '<?php
  4251. $message = (new class() implements FooInterface
  4252. {
  4253. });',
  4254. '<?php
  4255. $message = (new class() implements FooInterface{});',
  4256. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4257. ],
  4258. [
  4259. '<?php $message = (new class() {
  4260. });',
  4261. '<?php $message = (new class() {});',
  4262. self::$configurationOopPositionSameLine,
  4263. ],
  4264. [
  4265. '<?php $message = (new class() {
  4266. });',
  4267. '<?php $message = (new class() {});',
  4268. self::$configurationCtrlStructPositionNextLine,
  4269. ],
  4270. [
  4271. '<?php $message = (new class()
  4272. {
  4273. });',
  4274. '<?php $message = (new class() {});',
  4275. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4276. ],
  4277. [
  4278. '<?php
  4279. if (1) {
  4280. $message = (new class() extends Foo {
  4281. public function bar() {
  4282. echo 1;
  4283. }
  4284. });
  4285. }',
  4286. '<?php
  4287. if (1) {
  4288. $message = (new class() extends Foo
  4289. {
  4290. public function bar() { echo 1; }
  4291. });
  4292. }',
  4293. self::$configurationOopPositionSameLine,
  4294. ],
  4295. [
  4296. '<?php
  4297. if (1)
  4298. {
  4299. $message = (new class() extends Foo {
  4300. public function bar()
  4301. {
  4302. echo 1;
  4303. }
  4304. });
  4305. }',
  4306. '<?php
  4307. if (1) {
  4308. $message = (new class() extends Foo
  4309. {
  4310. public function bar() { echo 1; }
  4311. });
  4312. }',
  4313. self::$configurationCtrlStructPositionNextLine,
  4314. ],
  4315. [
  4316. '<?php
  4317. if (1) {
  4318. $message = (new class() extends Foo
  4319. {
  4320. public function bar() {
  4321. echo 1;
  4322. }
  4323. });
  4324. }',
  4325. '<?php
  4326. if (1) {
  4327. $message = (new class() extends Foo
  4328. {
  4329. public function bar() { echo 1; }
  4330. });
  4331. }',
  4332. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4333. ],
  4334. [
  4335. '<?php
  4336. if (1) {
  4337. $message = (new class() extends Foo
  4338. {
  4339. public function bar() {
  4340. echo 1;
  4341. }
  4342. });
  4343. }',
  4344. '<?php
  4345. if (1) {
  4346. $message = (new class() extends Foo
  4347. {
  4348. public function bar() { echo 1; }
  4349. });
  4350. }',
  4351. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4352. ],
  4353. [
  4354. '<?php
  4355. if (1)
  4356. {
  4357. $message = (new class() extends Foo
  4358. {
  4359. public function bar()
  4360. {
  4361. echo 1;
  4362. }
  4363. });
  4364. }',
  4365. '<?php
  4366. if (1) {
  4367. $message = (new class() extends Foo
  4368. {
  4369. public function bar() { echo 1; }
  4370. });
  4371. }',
  4372. self::$configurationCtrlStructPositionNextLine + self::$configurationAnonymousPositionNextLine,
  4373. ],
  4374. [
  4375. '<?php
  4376. if (1)
  4377. {
  4378. $message = (new class() extends Foo
  4379. {
  4380. public function bar() {
  4381. echo 1;
  4382. }
  4383. });
  4384. }',
  4385. '<?php
  4386. if (1) {
  4387. $message = (new class() extends Foo
  4388. {
  4389. public function bar() { echo 1; }
  4390. });
  4391. }',
  4392. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine + self::$configurationAnonymousPositionNextLine,
  4393. ],
  4394. [
  4395. '<?php
  4396. class Foo {
  4397. public function use() {
  4398. }
  4399. public function use1(): string {
  4400. }
  4401. }
  4402. ',
  4403. '<?php
  4404. class Foo
  4405. {
  4406. public function use() {
  4407. }
  4408. public function use1(): string {
  4409. }
  4410. }
  4411. ',
  4412. self::$configurationOopPositionSameLine,
  4413. ],
  4414. [
  4415. '<?php
  4416. class Foo {
  4417. public function use() {
  4418. }
  4419. public function use1(): string {
  4420. }
  4421. }
  4422. ',
  4423. '<?php
  4424. class Foo
  4425. {
  4426. public function use() {
  4427. }
  4428. public function use1(): string {
  4429. }
  4430. }
  4431. ',
  4432. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4433. ],
  4434. [
  4435. '<?php
  4436. $a = function (int $foo): string {
  4437. echo $foo;
  4438. };
  4439. $b = function (int $foo) use ($bar): string {
  4440. echo $foo . $bar;
  4441. };
  4442. function a() {
  4443. }
  4444. ',
  4445. '<?php
  4446. $a = function (int $foo): string
  4447. {
  4448. echo $foo;
  4449. };
  4450. $b = function (int $foo) use($bar): string
  4451. {
  4452. echo $foo . $bar;
  4453. };
  4454. function a() {
  4455. }
  4456. ',
  4457. self::$configurationOopPositionSameLine,
  4458. ],
  4459. [
  4460. '<?php
  4461. $a = function (int $foo): string
  4462. {
  4463. echo $foo;
  4464. };
  4465. $b = function (int $foo) use ($bar): string
  4466. {
  4467. echo $foo . $bar;
  4468. };
  4469. function a() {
  4470. }
  4471. ',
  4472. '<?php
  4473. $a = function (int $foo): string
  4474. {
  4475. echo $foo;
  4476. };
  4477. $b = function (int $foo) use($bar): string
  4478. {
  4479. echo $foo . $bar;
  4480. };
  4481. function a() {
  4482. }
  4483. ',
  4484. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4485. ],
  4486. [
  4487. '<?php
  4488. class Something {
  4489. public function sth(): string {
  4490. return function (int $foo) use ($bar): string {
  4491. return $bar;
  4492. };
  4493. }
  4494. }',
  4495. '<?php
  4496. class Something
  4497. {
  4498. public function sth(): string
  4499. {
  4500. return function (int $foo) use ($bar): string { return $bar; };
  4501. }
  4502. }',
  4503. self::$configurationOopPositionSameLine,
  4504. ],
  4505. [
  4506. '<?php
  4507. class Something {
  4508. public function sth(): string {
  4509. return function (int $foo) use ($bar): string
  4510. {
  4511. return $bar;
  4512. };
  4513. }
  4514. }',
  4515. '<?php
  4516. class Something
  4517. {
  4518. public function sth(): string
  4519. {
  4520. return function (int $foo) use ($bar): string { return $bar; };
  4521. }
  4522. }',
  4523. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4524. ],
  4525. [
  4526. '<?php
  4527. use function some\a\{
  4528. test1,
  4529. test2
  4530. };
  4531. test();',
  4532. null,
  4533. self::$configurationOopPositionSameLine,
  4534. ],
  4535. [
  4536. '<?php
  4537. use function some\a\{
  4538. test1,
  4539. test2
  4540. };
  4541. test();',
  4542. null,
  4543. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4544. ],
  4545. [
  4546. '<?php
  4547. use function some\a\{
  4548. test1,
  4549. test2
  4550. };
  4551. test();',
  4552. null,
  4553. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4554. ],
  4555. [
  4556. '<?php
  4557. use some\a\{ClassA, ClassB, ClassC as C};
  4558. use function some\a\{fn_a, fn_b, fn_c};
  4559. use const some\a\{ConstA, ConstB, ConstC};
  4560. ',
  4561. null,
  4562. self::$configurationOopPositionSameLine,
  4563. ],
  4564. [
  4565. '<?php
  4566. use some\a\{ClassA, ClassB, ClassC as C};
  4567. use function some\a\{fn_a, fn_b, fn_c};
  4568. use const some\a\{ConstA, ConstB, ConstC};
  4569. ',
  4570. null,
  4571. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4572. ],
  4573. [
  4574. '<?php
  4575. use some\a\{ClassA, ClassB, ClassC as C};
  4576. use function some\a\{fn_a, fn_b, fn_c};
  4577. use const some\a\{ConstA, ConstB, ConstC};
  4578. ',
  4579. null,
  4580. self::$configurationOopPositionSameLine + self::$configurationAnonymousPositionNextLine,
  4581. ],
  4582. [
  4583. '<?php
  4584. $foo = new class () extends \Exception {
  4585. };
  4586. ',
  4587. '<?php
  4588. $foo = new class () extends \Exception {};
  4589. ',
  4590. ],
  4591. [
  4592. '<?php
  4593. $foo = new class () extends \Exception {};
  4594. ',
  4595. null,
  4596. ['allow_single_line_anonymous_class_with_empty_body' => true],
  4597. ],
  4598. [
  4599. '<?php
  4600. $foo = new class() {}; // comment
  4601. ',
  4602. null,
  4603. ['allow_single_line_anonymous_class_with_empty_body' => true],
  4604. ],
  4605. [
  4606. '<?php
  4607. $foo = new class() { /* comment */ }; // another comment
  4608. ',
  4609. null,
  4610. ['allow_single_line_anonymous_class_with_empty_body' => true],
  4611. ],
  4612. [
  4613. '<?php
  4614. $foo = new class () extends \Exception {
  4615. protected $message = "Surprise";
  4616. };
  4617. ',
  4618. '<?php
  4619. $foo = new class () extends \Exception { protected $message = "Surprise"; };
  4620. ',
  4621. ['allow_single_line_anonymous_class_with_empty_body' => true],
  4622. ],
  4623. ];
  4624. }
  4625. /**
  4626. * @param string $expected
  4627. * @param null|string $input
  4628. *
  4629. * @dataProvider providePreserveLineAfterControlBraceCases
  4630. */
  4631. public function testPreserveLineAfterControlBrace($expected, $input = null, array $configuration = [])
  4632. {
  4633. $this->fixer->configure($configuration);
  4634. $this->doTest($expected, $input);
  4635. }
  4636. public function providePreserveLineAfterControlBraceCases()
  4637. {
  4638. return [
  4639. [
  4640. '<?php
  4641. if (1==1) { // test
  4642. $a = 1;
  4643. }
  4644. echo $a;',
  4645. '<?php
  4646. if (1==1) // test
  4647. { $a = 1; }
  4648. echo $a;',
  4649. ],
  4650. [
  4651. '<?php
  4652. if ($test) { // foo
  4653. echo 1;
  4654. }
  4655. if (1 === 1) {//a
  4656. $a = "b"; /*d*/
  4657. }//c
  4658. echo $a;
  4659. if ($a === 3) /**/
  4660. {echo 1;}
  4661. ',
  4662. '<?php
  4663. if ($test) // foo
  4664. {
  4665. echo 1;
  4666. }
  4667. if (1 === 1)//a
  4668. {$a = "b"; /*d*/}//c
  4669. echo $a;
  4670. if ($a === 3) /**/
  4671. {echo 1;}
  4672. ',
  4673. ],
  4674. [
  4675. '<?php
  4676. if (true) {
  4677. // The blank line helps with legibility in nested control structures
  4678. if (true) {
  4679. // if body
  4680. }
  4681. // if body
  4682. }',
  4683. ],
  4684. [
  4685. "<?php if (true) {\r\n\r\n// CRLF newline\n}",
  4686. ],
  4687. [
  4688. '<?php
  4689. if (true) {
  4690. // The blank line helps with legibility in nested control structures
  4691. if (true) {
  4692. // if body
  4693. }
  4694. // if body
  4695. }',
  4696. null,
  4697. self::$configurationOopPositionSameLine,
  4698. ],
  4699. [
  4700. '<?php
  4701. if (true)
  4702. {
  4703. // The blank line helps with legibility in nested control structures
  4704. if (true)
  4705. {
  4706. // if body
  4707. }
  4708. // if body
  4709. }',
  4710. '<?php
  4711. if (true) {
  4712. // The blank line helps with legibility in nested control structures
  4713. if (true) {
  4714. // if body
  4715. }
  4716. // if body
  4717. }',
  4718. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4719. ],
  4720. [
  4721. "<?php if (true) {\r\n\r\n// CRLF newline\n}",
  4722. null,
  4723. self::$configurationOopPositionSameLine,
  4724. ],
  4725. [
  4726. "<?php if (true)
  4727. {\r\n\r\n// CRLF newline\n}",
  4728. "<?php if (true){\r\n\r\n// CRLF newline\n}",
  4729. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4730. ],
  4731. ];
  4732. }
  4733. /**
  4734. * @param string $expected
  4735. * @param null|string $input
  4736. *
  4737. * @dataProvider provideFixWithAllowOnelineLambdaCases
  4738. */
  4739. public function testFixWithAllowSingleLineClosure($expected, $input = null)
  4740. {
  4741. $this->fixer->configure([
  4742. 'allow_single_line_closure' => true,
  4743. ]);
  4744. $this->doTest($expected, $input);
  4745. }
  4746. public function provideFixWithAllowOnelineLambdaCases()
  4747. {
  4748. return [
  4749. [
  4750. '<?php
  4751. $callback = function () { return true; };',
  4752. ],
  4753. [
  4754. '<?php
  4755. $callback = function () { if ($a) { return true; } return false; };',
  4756. '<?php
  4757. $callback = function () { if($a){ return true; } return false; };',
  4758. ],
  4759. [
  4760. '<?php
  4761. $callback = function () { if ($a) { return true; } return false; };',
  4762. '<?php
  4763. $callback = function () { if($a) return true; return false; };',
  4764. ],
  4765. [
  4766. '<?php
  4767. $callback = function () {
  4768. if ($a) {
  4769. return true;
  4770. }
  4771. return false;
  4772. };',
  4773. '<?php
  4774. $callback = function () { if($a) return true;
  4775. return false; };',
  4776. ],
  4777. ];
  4778. }
  4779. /**
  4780. * @param string $expected
  4781. * @param null|string $input
  4782. *
  4783. * @dataProvider provideDoWhileLoopInsideAnIfWithoutBracketsCases
  4784. */
  4785. public function testDoWhileLoopInsideAnIfWithoutBrackets($expected, $input = null)
  4786. {
  4787. $this->doTest($expected, $input);
  4788. }
  4789. public function provideDoWhileLoopInsideAnIfWithoutBracketsCases()
  4790. {
  4791. return [
  4792. [
  4793. '<?php
  4794. if (true) {
  4795. do {
  4796. echo 1;
  4797. } while (false);
  4798. }',
  4799. '<?php
  4800. if (true)
  4801. do {
  4802. echo 1;
  4803. } while (false);',
  4804. ],
  4805. ];
  4806. }
  4807. /**
  4808. * @param string $expected
  4809. * @param null|string $input
  4810. *
  4811. * @dataProvider provideMessyWhitespacesCases
  4812. */
  4813. public function testMessyWhitespaces($expected, $input = null, array $configuration = [])
  4814. {
  4815. $this->fixer->configure($configuration);
  4816. $this->fixer->setWhitespacesConfig(new WhitespacesFixerConfig("\t", "\r\n"));
  4817. $this->doTest($expected, $input);
  4818. }
  4819. public function provideMessyWhitespacesCases()
  4820. {
  4821. return [
  4822. [
  4823. '<?php
  4824. if (true) {'."\r\n"
  4825. ."\t".'if (true) {'."\r\n"
  4826. ."\t\t".'echo 1;'."\r\n"
  4827. ."\t".'} elseif (true) {'."\r\n"
  4828. ."\t\t".'echo 2;'."\r\n"
  4829. ."\t".'} else {'."\r\n"
  4830. ."\t\t".'echo 3;'."\r\n"
  4831. ."\t".'}'."\r\n"
  4832. .'}',
  4833. '<?php
  4834. if(true) if(true) echo 1; elseif(true) echo 2; else echo 3;',
  4835. ],
  4836. [
  4837. '<?php
  4838. if (true) {'."\r\n"
  4839. ."\t".'if (true) {'."\r\n"
  4840. ."\t\t".'echo 1;'."\r\n"
  4841. ."\t".'} elseif (true) {'."\r\n"
  4842. ."\t\t".'echo 2;'."\r\n"
  4843. ."\t".'} else {'."\r\n"
  4844. ."\t\t".'echo 3;'."\r\n"
  4845. ."\t".'}'."\r\n"
  4846. .'}',
  4847. '<?php
  4848. if(true) if(true) echo 1; elseif(true) echo 2; else echo 3;',
  4849. self::$configurationOopPositionSameLine,
  4850. ],
  4851. [
  4852. '<?php
  4853. if (true)'
  4854. ."\r\n".'{'."\r\n"
  4855. ."\t".'if (true)'."\r\n\t".'{'."\r\n"
  4856. ."\t\t".'echo 1;'."\r\n"
  4857. ."\t".'}'
  4858. ."\r\n\t".'elseif (true)'
  4859. ."\r\n\t".'{'."\r\n"
  4860. ."\t\t".'echo 2;'."\r\n"
  4861. ."\t".'}'
  4862. ."\r\n\t".'else'
  4863. ."\r\n\t".'{'."\r\n"
  4864. ."\t\t".'echo 3;'."\r\n"
  4865. ."\t".'}'."\r\n"
  4866. .'}',
  4867. '<?php
  4868. if(true) if(true) echo 1; elseif(true) echo 2; else echo 3;',
  4869. self::$configurationOopPositionSameLine + self::$configurationCtrlStructPositionNextLine,
  4870. ],
  4871. ];
  4872. }
  4873. /**
  4874. * @param string $expected
  4875. * @param null|string $input
  4876. *
  4877. * @dataProvider provideNowdocInTemplatesCases
  4878. */
  4879. public function testNowdocInTemplates($expected, $input = null)
  4880. {
  4881. $this->doTest($expected, $input);
  4882. }
  4883. public function provideNowdocInTemplatesCases()
  4884. {
  4885. return [
  4886. [
  4887. <<<'EOT'
  4888. <?php
  4889. if (true) {
  4890. $var = <<<'NOWDOC'
  4891. NOWDOC;
  4892. ?>
  4893. <?php
  4894. }
  4895. EOT
  4896. ,
  4897. <<<'EOT'
  4898. <?php
  4899. if (true) {
  4900. $var = <<<'NOWDOC'
  4901. NOWDOC;
  4902. ?>
  4903. <?php
  4904. }
  4905. EOT
  4906. ,
  4907. ],
  4908. [
  4909. <<<'EOT'
  4910. <?php
  4911. if (true) {
  4912. $var = <<<HEREDOC
  4913. HEREDOC;
  4914. ?>
  4915. <?php
  4916. }
  4917. EOT
  4918. ,
  4919. <<<'EOT'
  4920. <?php
  4921. if (true) {
  4922. $var = <<<HEREDOC
  4923. HEREDOC;
  4924. ?>
  4925. <?php
  4926. }
  4927. EOT
  4928. ,
  4929. ],
  4930. ];
  4931. }
  4932. /**
  4933. * @param string $expected
  4934. * @param null|string $input
  4935. *
  4936. * @dataProvider provideFixCommentsCases
  4937. */
  4938. public function testFixComments($expected, $input = null)
  4939. {
  4940. $this->doTest($expected, $input);
  4941. $this->doTest(str_replace('//', '#', $expected), null === $input ? null : str_replace('//', '#', $input));
  4942. }
  4943. public function provideFixCommentsCases()
  4944. {
  4945. return [
  4946. [
  4947. '<?php
  4948. function test()
  4949. {
  4950. // $closure = function ($callback) use ($query) {
  4951. // doSomething();
  4952. //
  4953. // return true;
  4954. // };
  4955. $a = 3;
  4956. }',
  4957. ],
  4958. [
  4959. '<?php
  4960. function test()
  4961. {
  4962. // $closure = function ($callback) use ($query) {
  4963. // doSomething();
  4964. // '.'
  4965. // return true;
  4966. // };
  4967. $a = 3;
  4968. }',
  4969. ],
  4970. [
  4971. '<?php
  4972. if ($foo) {
  4973. foo();
  4974. // if ($bar === \'bar\') {
  4975. // return [];
  4976. // }
  4977. } else {
  4978. bar();
  4979. }
  4980. ',
  4981. ],
  4982. [
  4983. '<?php
  4984. if ($foo) {
  4985. foo();
  4986. // if ($bar === \'bar\') {
  4987. // return [];
  4988. // }
  4989. } else {
  4990. bar();
  4991. }
  4992. ',
  4993. ],
  4994. [
  4995. '<?php
  4996. if ($foo) {
  4997. foo();
  4998. // if ($bar === \'bar\') {
  4999. // return [];
  5000. // }
  5001. '.'
  5002. $bar = \'bar\';
  5003. } else {
  5004. bar();
  5005. }
  5006. ',
  5007. ],
  5008. [
  5009. '<?php
  5010. if ($foo) {
  5011. foo();
  5012. // bar();
  5013. '.'
  5014. $bar = \'bar\';
  5015. } else {
  5016. bar();
  5017. }
  5018. ',
  5019. ],
  5020. [
  5021. '<?php
  5022. if ($foo) {
  5023. foo();
  5024. // bar();
  5025. '.'
  5026. $bar = \'bar\';
  5027. } else {
  5028. bar();
  5029. }
  5030. ',
  5031. ],
  5032. [
  5033. '<?php
  5034. if ($foo) {
  5035. foo();
  5036. '.'
  5037. // bar();
  5038. $bar = \'bar\';
  5039. } else {
  5040. bar();
  5041. }
  5042. ',
  5043. ],
  5044. [
  5045. '<?php
  5046. if ($foo) {
  5047. foo();
  5048. '.'
  5049. // bar();
  5050. } else {
  5051. bar();
  5052. }
  5053. ',
  5054. ],
  5055. [
  5056. '<?php
  5057. function foo()
  5058. {
  5059. $a = 1;
  5060. // we will return sth
  5061. return $a;
  5062. }
  5063. ',
  5064. '<?php
  5065. function foo()
  5066. {
  5067. $a = 1;
  5068. // we will return sth
  5069. return $a;
  5070. }
  5071. ',
  5072. ],
  5073. [
  5074. '<?php
  5075. function foo()
  5076. {
  5077. $a = 1;
  5078. '.'
  5079. // bar();
  5080. // we will return sth
  5081. return $a;
  5082. }
  5083. ',
  5084. '<?php
  5085. function foo()
  5086. {
  5087. $a = 1;
  5088. '.'
  5089. // bar();
  5090. // we will return sth
  5091. return $a;
  5092. }
  5093. ',
  5094. ],
  5095. [
  5096. '<?php
  5097. function foo()
  5098. {
  5099. $a = 1;
  5100. // if ($a === \'bar\') {
  5101. // return [];
  5102. // }
  5103. // we will return sth
  5104. return $a;
  5105. }
  5106. ',
  5107. '<?php
  5108. function foo()
  5109. {
  5110. $a = 1;
  5111. // if ($a === \'bar\') {
  5112. // return [];
  5113. // }
  5114. // we will return sth
  5115. return $a;
  5116. }
  5117. ',
  5118. ],
  5119. ];
  5120. }
  5121. public function testDynamicStaticMethodCallNotTouched()
  5122. {
  5123. $this->doTest(
  5124. '<?php
  5125. SomeClass::{$method}(new \stdClass());
  5126. SomeClass::{\'test\'}(new \stdClass());
  5127. function example()
  5128. {
  5129. SomeClass::{$method}(new \stdClass());
  5130. SomeClass::{\'test\'}(new \stdClass());
  5131. }'
  5132. );
  5133. }
  5134. /**
  5135. * @param string $expected
  5136. * @param null|string $input
  5137. *
  5138. * @dataProvider provideIndentCommentCases
  5139. */
  5140. public function testIndentComment($expected, $input, WhitespacesFixerConfig $config = null)
  5141. {
  5142. if (null !== $config) {
  5143. $this->fixer->setWhitespacesConfig($config);
  5144. }
  5145. $this->doTest($expected, $input);
  5146. }
  5147. public function provideIndentCommentCases()
  5148. {
  5149. yield [
  5150. "<?php
  5151. if (true) {
  5152. \t\$i += 2;
  5153. \treturn foo(\$i);
  5154. \t/*
  5155. \t \$i += 3;
  5156. \t // 1
  5157. "."
  5158. \t return foo(\$i);
  5159. \t */
  5160. }",
  5161. '<?php
  5162. if (true) {
  5163. $i += 2;
  5164. return foo($i);
  5165. /*
  5166. $i += 3;
  5167. // 1
  5168. '.'
  5169. return foo($i);
  5170. */
  5171. }',
  5172. new WhitespacesFixerConfig("\t", "\n"),
  5173. ];
  5174. yield [
  5175. '<?php
  5176. class MyClass extends SomeClass
  5177. {
  5178. /* public function myFunction() {
  5179. $MyItems = [];
  5180. return $MyItems;
  5181. }
  5182. */
  5183. }',
  5184. '<?php
  5185. class MyClass extends SomeClass {
  5186. /* public function myFunction() {
  5187. $MyItems = [];
  5188. return $MyItems;
  5189. }
  5190. */
  5191. }',
  5192. ];
  5193. yield [
  5194. '<?php
  5195. if (true) {
  5196. $i += 2;
  5197. return foo($i);
  5198. /*
  5199. $i += 3;
  5200. return foo($i);
  5201. */
  5202. }',
  5203. '<?php
  5204. if (true) {
  5205. $i += 2;
  5206. return foo($i);
  5207. /*
  5208. $i += 3;
  5209. return foo($i);
  5210. */
  5211. }',
  5212. ];
  5213. }
  5214. /**
  5215. * @param string $expected
  5216. * @param null|string $input
  5217. *
  5218. * @dataProvider provideFixAlternativeSyntaxCases
  5219. */
  5220. public function testFixAlternativeSyntax($expected, $input = null)
  5221. {
  5222. $this->doTest($expected, $input);
  5223. }
  5224. public function provideFixAlternativeSyntaxCases()
  5225. {
  5226. yield [
  5227. '<?php if (foo()) {
  5228. while (bar()) {
  5229. }
  5230. }',
  5231. '<?php if (foo()) while (bar()) {}',
  5232. ];
  5233. yield [
  5234. '<?php if ($a) {
  5235. foreach ($b as $c) {
  5236. }
  5237. }',
  5238. '<?php if ($a) foreach ($b as $c) {}',
  5239. ];
  5240. yield [
  5241. '<?php if ($a) foreach ($b as $c): ?> X <?php endforeach; ?>',
  5242. ];
  5243. yield [
  5244. '<?php if ($a) while ($b): ?> X <?php endwhile; ?>',
  5245. ];
  5246. yield [
  5247. '<?php if ($a) for (;;): ?> X <?php endfor; ?>',
  5248. ];
  5249. yield [
  5250. '<?php if ($a) switch ($a): case 1: ?> X <?php endswitch; ?>',
  5251. ];
  5252. yield [
  5253. '<?php if ($a): elseif ($b): for (;;): ?> X <?php endfor; endif; ?>',
  5254. ];
  5255. yield [
  5256. '<?php switch ($a): case 1: for (;;): ?> X <?php endfor; endswitch; ?>,',
  5257. ];
  5258. yield [
  5259. '<?php
  5260. if ($a) foreach ($b as $c): ?>
  5261. <?php if ($a) for (;;): ?>
  5262. <?php if ($a) foreach ($b as $c): ?>
  5263. <?php if ($a) for (;;): ?>
  5264. <?php if ($a) while ($b): ?>
  5265. <?php if ($a) while ($b): ?>
  5266. <?php if ($a) foreach ($b as $c): ?>
  5267. <?php if ($a) for (;;): ?>
  5268. <?php if ($a) while ($b): ?>
  5269. <?php if ($a) while ($b): ?>
  5270. <?php endwhile; ?>
  5271. <?php endwhile; ?>
  5272. <?php endfor; ?>
  5273. <?php endforeach; ?>
  5274. <?php endwhile; ?>
  5275. <?php endwhile; ?>
  5276. <?php endfor; ?>
  5277. <?php endforeach; ?>
  5278. <?php endfor; ?>
  5279. <?php endforeach; ?>',
  5280. ];
  5281. }
  5282. /**
  5283. * @requires PHP 8.0
  5284. *
  5285. * @param string $input
  5286. * @param string $expected
  5287. *
  5288. * @dataProvider provideFix80Cases
  5289. */
  5290. public function testFix80($expected, $input)
  5291. {
  5292. $this->doTest($expected, $input);
  5293. }
  5294. public function provideFix80Cases()
  5295. {
  5296. yield 'match' => [
  5297. '<?php echo match ($x) {
  5298. 1, 2 => "Same for 1 and 2",
  5299. };',
  5300. '<?php echo match($x)
  5301. {
  5302. 1, 2 => "Same for 1 and 2",
  5303. };',
  5304. ];
  5305. }
  5306. }