BracesFixerTest.php 101 KB

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