BracesFixerTest.php 102 KB

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