cs-fixer.phar 1.6 MB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420214212142221423214242142521426214272142821429214302143121432214332143421435214362143721438214392144021441214422144321444214452144621447214482144921450214512145221453214542145521456214572145821459214602146121462214632146421465214662146721468214692147021471214722147321474214752147621477214782147921480214812148221483214842148521486214872148821489214902149121492214932149421495214962149721498214992150021501215022150321504215052150621507215082150921510215112151221513215142151521516215172151821519215202152121522215232152421525215262152721528215292153021531215322153321534215352153621537215382153921540215412154221543215442154521546215472154821549215502155121552215532155421555215562155721558215592156021561215622156321564215652156621567215682156921570215712157221573215742157521576215772157821579215802158121582215832158421585215862158721588215892159021591215922159321594215952159621597215982159921600216012160221603216042160521606216072160821609216102161121612216132161421615216162161721618216192162021621216222162321624216252162621627216282162921630216312163221633216342163521636216372163821639216402164121642216432164421645216462164721648216492165021651216522165321654216552165621657216582165921660216612166221663216642166521666216672166821669216702167121672216732167421675216762167721678216792168021681216822168321684216852168621687216882168921690216912169221693216942169521696216972169821699217002170121702217032170421705217062170721708217092171021711217122171321714217152171621717217182171921720217212172221723217242172521726217272172821729217302173121732217332173421735217362173721738217392174021741217422174321744217452174621747217482174921750217512175221753217542175521756217572175821759217602176121762217632176421765217662176721768217692177021771217722177321774217752177621777217782177921780217812178221783217842178521786217872178821789217902179121792217932179421795217962179721798217992180021801218022180321804218052180621807218082180921810218112181221813218142181521816218172181821819218202182121822218232182421825218262182721828218292183021831218322183321834218352183621837218382183921840218412184221843218442184521846218472184821849218502185121852218532185421855218562185721858218592186021861218622186321864218652186621867218682186921870218712187221873218742187521876218772187821879218802188121882218832188421885218862188721888218892189021891218922189321894218952189621897218982189921900219012190221903219042190521906219072190821909219102191121912219132191421915219162191721918219192192021921219222192321924219252192621927219282192921930219312193221933219342193521936219372193821939219402194121942219432194421945219462194721948219492195021951219522195321954219552195621957219582195921960219612196221963219642196521966219672196821969219702197121972219732197421975219762197721978219792198021981219822198321984219852198621987219882198921990219912199221993219942199521996219972199821999220002200122002220032200422005220062200722008220092201022011220122201322014220152201622017220182201922020220212202222023220242202522026220272202822029220302203122032220332203422035220362203722038220392204022041220422204322044220452204622047220482204922050220512205222053220542205522056220572205822059220602206122062220632206422065220662206722068220692207022071220722207322074220752207622077220782207922080220812208222083220842208522086220872208822089220902209122092220932209422095220962209722098220992210022101221022210322104221052210622107221082210922110221112211222113221142211522116221172211822119221202212122122221232212422125221262212722128221292213022131221322213322134221352213622137221382213922140221412214222143221442214522146221472214822149221502215122152221532215422155221562215722158221592216022161221622216322164221652216622167221682216922170221712217222173221742217522176221772217822179221802218122182221832218422185221862218722188221892219022191221922219322194221952219622197221982219922200222012220222203222042220522206222072220822209222102221122212222132221422215222162221722218222192222022221222222222322224222252222622227222282222922230222312223222233222342223522236222372223822239222402224122242222432224422245222462224722248222492225022251222522225322254222552225622257222582225922260222612226222263222642226522266222672226822269222702227122272222732227422275222762227722278222792228022281222822228322284222852228622287222882228922290222912229222293222942229522296222972229822299223002230122302223032230422305223062230722308223092231022311223122231322314223152231622317223182231922320223212232222323223242232522326223272232822329223302233122332223332233422335223362233722338223392234022341223422234322344223452234622347223482234922350223512235222353223542235522356223572235822359223602236122362223632236422365223662236722368223692237022371223722237322374223752237622377223782237922380223812238222383223842238522386223872238822389223902239122392223932239422395223962239722398223992240022401224022240322404224052240622407224082240922410224112241222413224142241522416224172241822419224202242122422224232242422425224262242722428224292243022431224322243322434224352243622437224382243922440224412244222443224442244522446224472244822449224502245122452224532245422455224562245722458224592246022461224622246322464224652246622467224682246922470224712247222473224742247522476224772247822479224802248122482224832248422485224862248722488224892249022491224922249322494224952249622497224982249922500225012250222503225042250522506225072250822509225102251122512225132251422515225162251722518225192252022521225222252322524225252252622527225282252922530225312253222533225342253522536225372253822539225402254122542225432254422545225462254722548225492255022551225522255322554225552255622557225582255922560225612256222563225642256522566225672256822569225702257122572225732257422575225762257722578225792258022581225822258322584225852258622587225882258922590225912259222593225942259522596225972259822599226002260122602226032260422605226062260722608226092261022611226122261322614226152261622617226182261922620226212262222623226242262522626226272262822629226302263122632226332263422635226362263722638226392264022641226422264322644226452264622647226482264922650226512265222653226542265522656226572265822659226602266122662226632266422665226662266722668226692267022671226722267322674226752267622677226782267922680226812268222683226842268522686226872268822689226902269122692226932269422695226962269722698226992270022701227022270322704227052270622707227082270922710227112271222713227142271522716227172271822719227202272122722227232272422725227262272722728227292273022731227322273322734227352273622737227382273922740227412274222743227442274522746227472274822749227502275122752227532275422755227562275722758227592276022761227622276322764227652276622767227682276922770227712277222773227742277522776227772277822779227802278122782227832278422785227862278722788227892279022791227922279322794227952279622797227982279922800228012280222803228042280522806228072280822809228102281122812228132281422815228162281722818228192282022821228222282322824228252282622827228282282922830228312283222833228342283522836228372283822839228402284122842228432284422845228462284722848228492285022851228522285322854228552285622857228582285922860228612286222863228642286522866228672286822869228702287122872228732287422875228762287722878228792288022881228822288322884228852288622887228882288922890228912289222893228942289522896228972289822899229002290122902229032290422905229062290722908229092291022911229122291322914229152291622917229182291922920229212292222923229242292522926229272292822929229302293122932229332293422935229362293722938229392294022941229422294322944229452294622947229482294922950229512295222953229542295522956229572295822959229602296122962229632296422965229662296722968229692297022971229722297322974229752297622977229782297922980229812298222983229842298522986229872298822989229902299122992229932299422995229962299722998229992300023001230022300323004230052300623007230082300923010230112301223013230142301523016230172301823019230202302123022230232302423025230262302723028230292303023031230322303323034230352303623037230382303923040230412304223043230442304523046230472304823049230502305123052230532305423055230562305723058230592306023061230622306323064230652306623067230682306923070230712307223073230742307523076230772307823079230802308123082230832308423085230862308723088230892309023091230922309323094230952309623097230982309923100231012310223103231042310523106231072310823109231102311123112231132311423115231162311723118231192312023121231222312323124231252312623127231282312923130231312313223133231342313523136231372313823139231402314123142231432314423145231462314723148231492315023151231522315323154231552315623157231582315923160231612316223163231642316523166231672316823169231702317123172231732317423175231762317723178231792318023181231822318323184231852318623187231882318923190231912319223193231942319523196231972319823199232002320123202232032320423205232062320723208232092321023211232122321323214232152321623217232182321923220232212322223223232242322523226232272322823229232302323123232232332323423235232362323723238232392324023241232422324323244232452324623247232482324923250232512325223253232542325523256232572325823259232602326123262232632326423265232662326723268232692327023271232722327323274232752327623277232782327923280232812328223283232842328523286232872328823289232902329123292232932329423295232962329723298232992330023301233022330323304233052330623307233082330923310233112331223313233142331523316233172331823319233202332123322233232332423325233262332723328233292333023331233322333323334233352333623337233382333923340233412334223343233442334523346233472334823349233502335123352233532335423355233562335723358233592336023361233622336323364233652336623367233682336923370233712337223373233742337523376233772337823379233802338123382233832338423385233862338723388233892339023391233922339323394233952339623397233982339923400234012340223403234042340523406234072340823409234102341123412234132341423415234162341723418234192342023421234222342323424234252342623427234282342923430234312343223433234342343523436234372343823439234402344123442234432344423445234462344723448234492345023451234522345323454234552345623457234582345923460234612346223463234642346523466234672346823469234702347123472234732347423475234762347723478234792348023481234822348323484234852348623487234882348923490234912349223493234942349523496234972349823499235002350123502235032350423505235062350723508235092351023511235122351323514235152351623517235182351923520235212352223523235242352523526235272352823529235302353123532235332353423535235362353723538235392354023541235422354323544235452354623547235482354923550235512355223553235542355523556235572355823559235602356123562235632356423565235662356723568235692357023571235722357323574235752357623577235782357923580235812358223583235842358523586235872358823589235902359123592235932359423595235962359723598235992360023601236022360323604236052360623607236082360923610236112361223613236142361523616236172361823619236202362123622236232362423625236262362723628236292363023631236322363323634236352363623637236382363923640236412364223643236442364523646236472364823649236502365123652236532365423655236562365723658236592366023661236622366323664236652366623667236682366923670236712367223673236742367523676236772367823679236802368123682236832368423685236862368723688236892369023691236922369323694236952369623697236982369923700237012370223703237042370523706237072370823709237102371123712237132371423715237162371723718237192372023721237222372323724237252372623727237282372923730237312373223733237342373523736237372373823739237402374123742237432374423745237462374723748237492375023751237522375323754237552375623757237582375923760237612376223763237642376523766237672376823769237702377123772237732377423775237762377723778237792378023781237822378323784237852378623787237882378923790237912379223793237942379523796237972379823799238002380123802238032380423805238062380723808238092381023811238122381323814238152381623817238182381923820238212382223823238242382523826238272382823829238302383123832238332383423835238362383723838238392384023841238422384323844238452384623847238482384923850238512385223853238542385523856238572385823859238602386123862238632386423865238662386723868238692387023871238722387323874238752387623877238782387923880238812388223883238842388523886238872388823889238902389123892238932389423895238962389723898238992390023901239022390323904239052390623907239082390923910239112391223913239142391523916239172391823919239202392123922239232392423925239262392723928239292393023931239322393323934239352393623937239382393923940239412394223943239442394523946239472394823949239502395123952239532395423955239562395723958239592396023961239622396323964239652396623967239682396923970239712397223973239742397523976239772397823979239802398123982239832398423985239862398723988239892399023991239922399323994239952399623997239982399924000240012400224003240042400524006240072400824009240102401124012240132401424015240162401724018240192402024021240222402324024240252402624027240282402924030240312403224033240342403524036240372403824039240402404124042240432404424045240462404724048240492405024051240522405324054240552405624057240582405924060240612406224063240642406524066240672406824069240702407124072240732407424075240762407724078240792408024081240822408324084240852408624087240882408924090240912409224093240942409524096240972409824099241002410124102241032410424105241062410724108241092411024111241122411324114241152411624117241182411924120241212412224123241242412524126241272412824129241302413124132241332413424135241362413724138241392414024141241422414324144241452414624147241482414924150241512415224153241542415524156241572415824159241602416124162241632416424165241662416724168241692417024171241722417324174241752417624177241782417924180241812418224183241842418524186241872418824189241902419124192241932419424195241962419724198241992420024201242022420324204242052420624207242082420924210242112421224213242142421524216242172421824219242202422124222242232422424225242262422724228242292423024231242322423324234242352423624237242382423924240242412424224243242442424524246242472424824249242502425124252242532425424255242562425724258242592426024261242622426324264242652426624267242682426924270242712427224273242742427524276242772427824279242802428124282242832428424285242862428724288242892429024291242922429324294242952429624297242982429924300243012430224303243042430524306243072430824309243102431124312243132431424315243162431724318243192432024321243222432324324243252432624327243282432924330243312433224333243342433524336243372433824339243402434124342243432434424345243462434724348243492435024351243522435324354243552435624357243582435924360243612436224363243642436524366243672436824369243702437124372243732437424375243762437724378243792438024381243822438324384243852438624387243882438924390243912439224393243942439524396243972439824399244002440124402244032440424405244062440724408244092441024411244122441324414244152441624417244182441924420244212442224423244242442524426244272442824429244302443124432244332443424435244362443724438244392444024441244422444324444244452444624447244482444924450244512445224453244542445524456244572445824459244602446124462244632446424465244662446724468244692447024471244722447324474244752447624477244782447924480244812448224483244842448524486244872448824489244902449124492244932449424495244962449724498244992450024501245022450324504245052450624507245082450924510245112451224513245142451524516245172451824519245202452124522245232452424525245262452724528245292453024531245322453324534245352453624537245382453924540245412454224543245442454524546245472454824549245502455124552245532455424555245562455724558245592456024561245622456324564245652456624567245682456924570245712457224573245742457524576245772457824579245802458124582245832458424585245862458724588245892459024591245922459324594245952459624597245982459924600246012460224603246042460524606246072460824609246102461124612246132461424615246162461724618246192462024621246222462324624246252462624627246282462924630246312463224633246342463524636246372463824639246402464124642246432464424645246462464724648246492465024651246522465324654246552465624657246582465924660246612466224663246642466524666246672466824669246702467124672246732467424675246762467724678246792468024681246822468324684246852468624687246882468924690246912469224693246942469524696246972469824699247002470124702247032470424705247062470724708247092471024711247122471324714247152471624717247182471924720247212472224723247242472524726247272472824729247302473124732247332473424735247362473724738247392474024741247422474324744247452474624747247482474924750247512475224753247542475524756247572475824759247602476124762247632476424765247662476724768247692477024771247722477324774247752477624777247782477924780247812478224783247842478524786247872478824789247902479124792247932479424795247962479724798247992480024801248022480324804248052480624807248082480924810248112481224813248142481524816248172481824819248202482124822248232482424825248262482724828248292483024831248322483324834248352483624837248382483924840248412484224843248442484524846248472484824849248502485124852248532485424855248562485724858248592486024861248622486324864248652486624867248682486924870248712487224873248742487524876248772487824879248802488124882248832488424885248862488724888248892489024891248922489324894248952489624897248982489924900249012490224903249042490524906249072490824909249102491124912249132491424915249162491724918249192492024921249222492324924249252492624927249282492924930249312493224933249342493524936249372493824939249402494124942249432494424945249462494724948249492495024951249522495324954249552495624957249582495924960249612496224963249642496524966249672496824969249702497124972249732497424975249762497724978249792498024981249822498324984249852498624987249882498924990249912499224993249942499524996249972499824999250002500125002250032500425005250062500725008250092501025011250122501325014250152501625017250182501925020250212502225023250242502525026250272502825029250302503125032250332503425035250362503725038250392504025041250422504325044250452504625047250482504925050250512505225053250542505525056250572505825059250602506125062250632506425065250662506725068250692507025071250722507325074250752507625077250782507925080250812508225083250842508525086250872508825089250902509125092250932509425095250962509725098250992510025101251022510325104251052510625107251082510925110251112511225113251142511525116251172511825119251202512125122251232512425125251262512725128251292513025131251322513325134251352513625137251382513925140251412514225143251442514525146251472514825149251502515125152251532515425155251562515725158251592516025161251622516325164251652516625167251682516925170251712517225173251742517525176251772517825179251802518125182251832518425185251862518725188251892519025191251922519325194251952519625197251982519925200252012520225203252042520525206252072520825209252102521125212252132521425215252162521725218252192522025221252222522325224252252522625227252282522925230252312523225233252342523525236252372523825239252402524125242252432524425245252462524725248252492525025251252522525325254252552525625257252582525925260252612526225263252642526525266252672526825269252702527125272252732527425275252762527725278252792528025281252822528325284252852528625287252882528925290252912529225293252942529525296252972529825299253002530125302253032530425305253062530725308253092531025311253122531325314253152531625317253182531925320253212532225323253242532525326253272532825329253302533125332253332533425335253362533725338253392534025341253422534325344253452534625347253482534925350253512535225353253542535525356253572535825359253602536125362253632536425365253662536725368253692537025371253722537325374253752537625377253782537925380253812538225383253842538525386253872538825389253902539125392253932539425395253962539725398253992540025401254022540325404254052540625407254082540925410254112541225413254142541525416254172541825419254202542125422254232542425425254262542725428254292543025431254322543325434254352543625437254382543925440254412544225443254442544525446254472544825449254502545125452254532545425455254562545725458254592546025461254622546325464254652546625467254682546925470254712547225473254742547525476254772547825479254802548125482254832548425485254862548725488254892549025491254922549325494254952549625497254982549925500255012550225503255042550525506255072550825509255102551125512255132551425515255162551725518255192552025521255222552325524255252552625527255282552925530255312553225533255342553525536255372553825539255402554125542255432554425545255462554725548255492555025551255522555325554255552555625557255582555925560255612556225563255642556525566255672556825569255702557125572255732557425575255762557725578255792558025581255822558325584255852558625587255882558925590255912559225593255942559525596255972559825599256002560125602256032560425605256062560725608256092561025611256122561325614256152561625617256182561925620256212562225623256242562525626256272562825629256302563125632256332563425635256362563725638256392564025641256422564325644256452564625647256482564925650256512565225653256542565525656256572565825659256602566125662256632566425665256662566725668256692567025671256722567325674256752567625677256782567925680256812568225683256842568525686256872568825689256902569125692256932569425695256962569725698256992570025701257022570325704257052570625707257082570925710257112571225713257142571525716257172571825719257202572125722257232572425725257262572725728257292573025731257322573325734257352573625737257382573925740257412574225743257442574525746257472574825749257502575125752257532575425755257562575725758257592576025761257622576325764257652576625767257682576925770257712577225773257742577525776257772577825779257802578125782257832578425785257862578725788257892579025791257922579325794257952579625797257982579925800258012580225803258042580525806258072580825809258102581125812258132581425815258162581725818258192582025821258222582325824258252582625827258282582925830258312583225833258342583525836258372583825839258402584125842258432584425845258462584725848258492585025851258522585325854258552585625857258582585925860258612586225863258642586525866258672586825869258702587125872258732587425875258762587725878258792588025881258822588325884258852588625887258882588925890258912589225893258942589525896258972589825899259002590125902259032590425905259062590725908259092591025911259122591325914259152591625917259182591925920259212592225923259242592525926259272592825929259302593125932259332593425935259362593725938259392594025941259422594325944259452594625947259482594925950259512595225953259542595525956259572595825959259602596125962259632596425965259662596725968259692597025971259722597325974259752597625977259782597925980259812598225983259842598525986259872598825989259902599125992259932599425995259962599725998259992600026001260022600326004260052600626007260082600926010260112601226013260142601526016260172601826019260202602126022260232602426025260262602726028260292603026031260322603326034260352603626037260382603926040260412604226043260442604526046260472604826049260502605126052260532605426055260562605726058260592606026061260622606326064260652606626067260682606926070260712607226073260742607526076260772607826079260802608126082260832608426085260862608726088260892609026091260922609326094260952609626097260982609926100261012610226103261042610526106261072610826109261102611126112261132611426115261162611726118261192612026121261222612326124261252612626127261282612926130261312613226133261342613526136261372613826139261402614126142261432614426145261462614726148261492615026151261522615326154261552615626157261582615926160261612616226163261642616526166261672616826169261702617126172261732617426175261762617726178261792618026181261822618326184261852618626187261882618926190261912619226193261942619526196261972619826199262002620126202262032620426205262062620726208262092621026211262122621326214262152621626217262182621926220262212622226223262242622526226262272622826229262302623126232262332623426235262362623726238262392624026241262422624326244262452624626247262482624926250262512625226253262542625526256262572625826259262602626126262262632626426265262662626726268262692627026271262722627326274262752627626277262782627926280262812628226283262842628526286262872628826289262902629126292262932629426295262962629726298262992630026301263022630326304263052630626307263082630926310263112631226313263142631526316263172631826319263202632126322263232632426325263262632726328263292633026331263322633326334263352633626337263382633926340263412634226343263442634526346263472634826349263502635126352263532635426355263562635726358263592636026361263622636326364263652636626367263682636926370263712637226373263742637526376263772637826379263802638126382263832638426385263862638726388263892639026391263922639326394263952639626397263982639926400264012640226403264042640526406264072640826409264102641126412264132641426415264162641726418264192642026421264222642326424264252642626427264282642926430264312643226433264342643526436264372643826439264402644126442264432644426445264462644726448264492645026451264522645326454264552645626457264582645926460264612646226463264642646526466264672646826469264702647126472264732647426475264762647726478264792648026481264822648326484264852648626487264882648926490264912649226493264942649526496264972649826499265002650126502265032650426505265062650726508265092651026511265122651326514265152651626517265182651926520265212652226523265242652526526265272652826529265302653126532265332653426535265362653726538265392654026541265422654326544265452654626547265482654926550265512655226553265542655526556265572655826559265602656126562265632656426565265662656726568265692657026571265722657326574265752657626577265782657926580265812658226583265842658526586265872658826589265902659126592265932659426595265962659726598265992660026601266022660326604266052660626607266082660926610266112661226613266142661526616266172661826619266202662126622266232662426625266262662726628266292663026631266322663326634266352663626637266382663926640266412664226643266442664526646266472664826649266502665126652266532665426655266562665726658266592666026661266622666326664266652666626667266682666926670266712667226673266742667526676266772667826679266802668126682266832668426685266862668726688266892669026691266922669326694266952669626697266982669926700267012670226703267042670526706267072670826709267102671126712267132671426715267162671726718267192672026721267222672326724267252672626727267282672926730267312673226733267342673526736267372673826739267402674126742267432674426745267462674726748267492675026751267522675326754267552675626757267582675926760267612676226763267642676526766267672676826769267702677126772267732677426775267762677726778267792678026781267822678326784267852678626787267882678926790267912679226793267942679526796267972679826799268002680126802268032680426805268062680726808268092681026811268122681326814268152681626817268182681926820268212682226823268242682526826268272682826829268302683126832268332683426835268362683726838268392684026841268422684326844268452684626847268482684926850268512685226853268542685526856268572685826859268602686126862268632686426865268662686726868268692687026871268722687326874268752687626877268782687926880268812688226883268842688526886268872688826889268902689126892268932689426895268962689726898268992690026901269022690326904269052690626907269082690926910269112691226913269142691526916269172691826919269202692126922269232692426925269262692726928269292693026931269322693326934269352693626937269382693926940269412694226943269442694526946269472694826949269502695126952269532695426955269562695726958269592696026961269622696326964269652696626967269682696926970269712697226973269742697526976269772697826979269802698126982269832698426985269862698726988269892699026991269922699326994269952699626997269982699927000270012700227003270042700527006270072700827009270102701127012270132701427015270162701727018270192702027021270222702327024270252702627027270282702927030270312703227033270342703527036270372703827039270402704127042270432704427045270462704727048270492705027051270522705327054270552705627057270582705927060270612706227063270642706527066270672706827069270702707127072270732707427075270762707727078270792708027081270822708327084270852708627087270882708927090270912709227093270942709527096270972709827099271002710127102271032710427105271062710727108271092711027111271122711327114271152711627117271182711927120271212712227123271242712527126271272712827129271302713127132271332713427135271362713727138271392714027141271422714327144271452714627147271482714927150271512715227153271542715527156271572715827159271602716127162271632716427165271662716727168271692717027171271722717327174271752717627177271782717927180271812718227183271842718527186271872718827189271902719127192271932719427195271962719727198271992720027201272022720327204272052720627207272082720927210272112721227213272142721527216272172721827219272202722127222272232722427225272262722727228272292723027231272322723327234272352723627237272382723927240272412724227243272442724527246272472724827249272502725127252272532725427255272562725727258272592726027261272622726327264272652726627267272682726927270272712727227273272742727527276272772727827279272802728127282272832728427285272862728727288272892729027291272922729327294272952729627297272982729927300273012730227303273042730527306273072730827309273102731127312273132731427315273162731727318273192732027321273222732327324273252732627327273282732927330273312733227333273342733527336273372733827339273402734127342273432734427345273462734727348273492735027351273522735327354273552735627357273582735927360273612736227363273642736527366273672736827369273702737127372273732737427375273762737727378273792738027381273822738327384273852738627387273882738927390273912739227393273942739527396273972739827399274002740127402274032740427405274062740727408274092741027411274122741327414274152741627417274182741927420274212742227423274242742527426274272742827429274302743127432274332743427435274362743727438274392744027441274422744327444274452744627447274482744927450274512745227453274542745527456274572745827459274602746127462274632746427465274662746727468274692747027471274722747327474274752747627477274782747927480274812748227483274842748527486274872748827489274902749127492274932749427495274962749727498274992750027501275022750327504275052750627507275082750927510275112751227513275142751527516275172751827519275202752127522275232752427525275262752727528275292753027531275322753327534275352753627537275382753927540275412754227543275442754527546275472754827549275502755127552275532755427555275562755727558275592756027561275622756327564275652756627567275682756927570275712757227573275742757527576275772757827579275802758127582275832758427585275862758727588275892759027591275922759327594275952759627597275982759927600276012760227603276042760527606276072760827609276102761127612276132761427615276162761727618276192762027621276222762327624276252762627627276282762927630276312763227633276342763527636276372763827639276402764127642276432764427645276462764727648276492765027651276522765327654276552765627657276582765927660276612766227663276642766527666276672766827669276702767127672276732767427675276762767727678276792768027681276822768327684276852768627687276882768927690276912769227693276942769527696276972769827699277002770127702277032770427705277062770727708277092771027711277122771327714277152771627717277182771927720277212772227723277242772527726277272772827729277302773127732277332773427735277362773727738277392774027741277422774327744277452774627747277482774927750277512775227753277542775527756277572775827759277602776127762277632776427765277662776727768277692777027771277722777327774277752777627777277782777927780277812778227783277842778527786277872778827789277902779127792277932779427795277962779727798277992780027801278022780327804278052780627807278082780927810278112781227813278142781527816278172781827819278202782127822278232782427825278262782727828278292783027831278322783327834278352783627837278382783927840278412784227843278442784527846278472784827849278502785127852278532785427855278562785727858278592786027861278622786327864278652786627867278682786927870278712787227873278742787527876278772787827879278802788127882278832788427885278862788727888278892789027891278922789327894278952789627897278982789927900279012790227903279042790527906279072790827909279102791127912279132791427915279162791727918279192792027921279222792327924279252792627927279282792927930279312793227933279342793527936279372793827939279402794127942279432794427945279462794727948279492795027951279522795327954279552795627957279582795927960279612796227963279642796527966279672796827969279702797127972279732797427975279762797727978279792798027981279822798327984279852798627987279882798927990279912799227993279942799527996279972799827999280002800128002280032800428005280062800728008280092801028011280122801328014280152801628017280182801928020280212802228023280242802528026280272802828029280302803128032280332803428035280362803728038280392804028041280422804328044280452804628047280482804928050280512805228053280542805528056280572805828059280602806128062280632806428065280662806728068280692807028071280722807328074280752807628077280782807928080280812808228083280842808528086280872808828089280902809128092280932809428095280962809728098280992810028101281022810328104281052810628107281082810928110281112811228113281142811528116281172811828119281202812128122281232812428125281262812728128281292813028131281322813328134281352813628137281382813928140281412814228143281442814528146281472814828149281502815128152281532815428155281562815728158281592816028161281622816328164281652816628167281682816928170281712817228173281742817528176281772817828179281802818128182281832818428185281862818728188281892819028191281922819328194281952819628197281982819928200282012820228203282042820528206282072820828209282102821128212282132821428215282162821728218282192822028221282222822328224282252822628227282282822928230282312823228233282342823528236282372823828239282402824128242282432824428245282462824728248282492825028251282522825328254282552825628257282582825928260282612826228263282642826528266282672826828269282702827128272282732827428275282762827728278282792828028281282822828328284282852828628287282882828928290282912829228293282942829528296282972829828299283002830128302283032830428305283062830728308283092831028311283122831328314283152831628317283182831928320283212832228323283242832528326283272832828329283302833128332283332833428335283362833728338283392834028341283422834328344283452834628347283482834928350283512835228353283542835528356283572835828359283602836128362283632836428365283662836728368283692837028371283722837328374283752837628377283782837928380283812838228383283842838528386283872838828389283902839128392283932839428395283962839728398283992840028401284022840328404284052840628407284082840928410284112841228413284142841528416284172841828419284202842128422284232842428425284262842728428284292843028431284322843328434284352843628437284382843928440284412844228443284442844528446284472844828449284502845128452284532845428455284562845728458284592846028461284622846328464284652846628467284682846928470284712847228473284742847528476284772847828479284802848128482284832848428485284862848728488284892849028491284922849328494284952849628497284982849928500285012850228503285042850528506285072850828509285102851128512285132851428515285162851728518285192852028521285222852328524285252852628527285282852928530285312853228533285342853528536285372853828539285402854128542285432854428545285462854728548285492855028551285522855328554285552855628557285582855928560285612856228563285642856528566285672856828569285702857128572285732857428575285762857728578285792858028581285822858328584285852858628587285882858928590285912859228593285942859528596285972859828599286002860128602286032860428605286062860728608286092861028611286122861328614286152861628617286182861928620286212862228623286242862528626286272862828629286302863128632286332863428635286362863728638286392864028641286422864328644286452864628647286482864928650286512865228653286542865528656286572865828659286602866128662286632866428665286662866728668286692867028671286722867328674286752867628677286782867928680286812868228683286842868528686286872868828689286902869128692286932869428695286962869728698286992870028701287022870328704287052870628707287082870928710287112871228713287142871528716287172871828719287202872128722287232872428725287262872728728287292873028731287322873328734287352873628737287382873928740287412874228743287442874528746287472874828749287502875128752287532875428755287562875728758287592876028761287622876328764287652876628767287682876928770287712877228773287742877528776287772877828779287802878128782287832878428785287862878728788287892879028791287922879328794287952879628797287982879928800288012880228803288042880528806288072880828809288102881128812288132881428815288162881728818288192882028821288222882328824288252882628827288282882928830288312883228833288342883528836288372883828839288402884128842288432884428845288462884728848288492885028851288522885328854288552885628857288582885928860288612886228863288642886528866288672886828869288702887128872288732887428875288762887728878288792888028881288822888328884288852888628887288882888928890288912889228893288942889528896288972889828899289002890128902289032890428905289062890728908289092891028911289122891328914289152891628917289182891928920289212892228923289242892528926289272892828929289302893128932289332893428935289362893728938289392894028941289422894328944289452894628947289482894928950289512895228953289542895528956289572895828959289602896128962289632896428965289662896728968289692897028971289722897328974289752897628977289782897928980289812898228983289842898528986289872898828989289902899128992289932899428995289962899728998289992900029001290022900329004290052900629007290082900929010290112901229013290142901529016290172901829019290202902129022290232902429025290262902729028290292903029031290322903329034290352903629037290382903929040290412904229043290442904529046290472904829049290502905129052290532905429055290562905729058290592906029061290622906329064290652906629067290682906929070290712907229073290742907529076290772907829079290802908129082290832908429085290862908729088290892909029091290922909329094290952909629097290982909929100291012910229103291042910529106291072910829109291102911129112291132911429115291162911729118291192912029121291222912329124291252912629127291282912929130291312913229133291342913529136291372913829139291402914129142291432914429145291462914729148291492915029151291522915329154291552915629157291582915929160291612916229163291642916529166291672916829169291702917129172291732917429175291762917729178291792918029181291822918329184291852918629187291882918929190291912919229193291942919529196291972919829199292002920129202292032920429205292062920729208292092921029211292122921329214292152921629217292182921929220292212922229223292242922529226292272922829229292302923129232292332923429235292362923729238292392924029241292422924329244292452924629247292482924929250292512925229253292542925529256292572925829259292602926129262292632926429265292662926729268292692927029271292722927329274292752927629277292782927929280292812928229283292842928529286292872928829289292902929129292292932929429295292962929729298292992930029301293022930329304293052930629307293082930929310293112931229313293142931529316293172931829319293202932129322293232932429325293262932729328293292933029331293322933329334293352933629337293382933929340293412934229343293442934529346293472934829349293502935129352293532935429355293562935729358293592936029361293622936329364293652936629367293682936929370293712937229373293742937529376293772937829379293802938129382293832938429385293862938729388293892939029391293922939329394293952939629397293982939929400294012940229403294042940529406294072940829409294102941129412294132941429415294162941729418294192942029421294222942329424294252942629427294282942929430294312943229433294342943529436294372943829439294402944129442294432944429445294462944729448294492945029451294522945329454294552945629457294582945929460294612946229463294642946529466294672946829469294702947129472294732947429475294762947729478294792948029481294822948329484294852948629487294882948929490294912949229493294942949529496294972949829499295002950129502295032950429505295062950729508295092951029511295122951329514295152951629517295182951929520295212952229523295242952529526295272952829529295302953129532295332953429535295362953729538295392954029541295422954329544295452954629547295482954929550295512955229553295542955529556295572955829559295602956129562295632956429565295662956729568295692957029571295722957329574295752957629577295782957929580295812958229583295842958529586295872958829589295902959129592295932959429595295962959729598295992960029601296022960329604296052960629607296082960929610296112961229613296142961529616296172961829619296202962129622296232962429625296262962729628296292963029631296322963329634296352963629637296382963929640296412964229643296442964529646296472964829649296502965129652296532965429655296562965729658296592966029661296622966329664296652966629667296682966929670296712967229673296742967529676296772967829679296802968129682296832968429685296862968729688296892969029691296922969329694296952969629697296982969929700297012970229703297042970529706297072970829709297102971129712297132971429715297162971729718297192972029721297222972329724297252972629727297282972929730297312973229733297342973529736297372973829739297402974129742297432974429745297462974729748297492975029751297522975329754297552975629757297582975929760297612976229763297642976529766297672976829769297702977129772297732977429775297762977729778297792978029781297822978329784297852978629787297882978929790297912979229793297942979529796297972979829799298002980129802298032980429805298062980729808298092981029811298122981329814298152981629817298182981929820298212982229823298242982529826298272982829829298302983129832298332983429835298362983729838298392984029841298422984329844298452984629847298482984929850298512985229853298542985529856298572985829859298602986129862298632986429865298662986729868298692987029871298722987329874298752987629877298782987929880298812988229883298842988529886298872988829889298902989129892298932989429895298962989729898298992990029901299022990329904299052990629907299082990929910299112991229913299142991529916299172991829919299202992129922299232992429925299262992729928299292993029931299322993329934299352993629937299382993929940299412994229943299442994529946299472994829949299502995129952299532995429955299562995729958299592996029961299622996329964299652996629967299682996929970299712997229973299742997529976299772997829979299802998129982299832998429985299862998729988299892999029991299922999329994299952999629997299982999930000300013000230003300043000530006300073000830009300103001130012300133001430015300163001730018300193002030021300223002330024300253002630027300283002930030300313003230033300343003530036300373003830039300403004130042300433004430045300463004730048300493005030051300523005330054300553005630057300583005930060300613006230063300643006530066300673006830069300703007130072300733007430075300763007730078300793008030081300823008330084300853008630087300883008930090300913009230093300943009530096300973009830099301003010130102301033010430105301063010730108301093011030111301123011330114301153011630117301183011930120301213012230123301243012530126301273012830129301303013130132301333013430135301363013730138301393014030141301423014330144301453014630147301483014930150301513015230153301543015530156301573015830159301603016130162301633016430165301663016730168301693017030171301723017330174301753017630177301783017930180301813018230183301843018530186301873018830189301903019130192301933019430195301963019730198301993020030201302023020330204302053020630207302083020930210302113021230213302143021530216302173021830219302203022130222302233022430225302263022730228302293023030231302323023330234302353023630237302383023930240302413024230243302443024530246302473024830249302503025130252302533025430255302563025730258302593026030261302623026330264302653026630267302683026930270302713027230273302743027530276302773027830279302803028130282302833028430285302863028730288302893029030291302923029330294302953029630297302983029930300303013030230303303043030530306303073030830309303103031130312303133031430315303163031730318303193032030321303223032330324303253032630327303283032930330303313033230333303343033530336303373033830339303403034130342303433034430345303463034730348303493035030351303523035330354303553035630357303583035930360303613036230363303643036530366303673036830369303703037130372303733037430375303763037730378303793038030381303823038330384303853038630387303883038930390303913039230393303943039530396303973039830399304003040130402304033040430405304063040730408304093041030411304123041330414304153041630417304183041930420304213042230423304243042530426304273042830429304303043130432304333043430435304363043730438304393044030441304423044330444304453044630447304483044930450304513045230453304543045530456304573045830459304603046130462304633046430465304663046730468304693047030471304723047330474304753047630477304783047930480304813048230483304843048530486304873048830489304903049130492304933049430495304963049730498304993050030501305023050330504305053050630507305083050930510305113051230513305143051530516305173051830519305203052130522305233052430525305263052730528305293053030531305323053330534305353053630537305383053930540305413054230543305443054530546305473054830549305503055130552305533055430555305563055730558305593056030561305623056330564305653056630567305683056930570305713057230573305743057530576305773057830579305803058130582305833058430585305863058730588305893059030591305923059330594305953059630597305983059930600306013060230603306043060530606306073060830609306103061130612306133061430615306163061730618306193062030621306223062330624306253062630627306283062930630306313063230633306343063530636306373063830639306403064130642306433064430645306463064730648306493065030651306523065330654306553065630657306583065930660306613066230663306643066530666306673066830669306703067130672306733067430675306763067730678306793068030681306823068330684306853068630687306883068930690306913069230693306943069530696306973069830699307003070130702307033070430705307063070730708307093071030711307123071330714307153071630717307183071930720307213072230723307243072530726307273072830729307303073130732307333073430735307363073730738307393074030741307423074330744307453074630747307483074930750307513075230753307543075530756307573075830759307603076130762307633076430765307663076730768307693077030771307723077330774307753077630777307783077930780307813078230783307843078530786307873078830789307903079130792307933079430795307963079730798307993080030801308023080330804308053080630807308083080930810308113081230813308143081530816308173081830819308203082130822308233082430825308263082730828308293083030831308323083330834308353083630837308383083930840308413084230843308443084530846308473084830849308503085130852308533085430855308563085730858308593086030861308623086330864308653086630867308683086930870308713087230873308743087530876308773087830879308803088130882308833088430885308863088730888308893089030891308923089330894308953089630897308983089930900309013090230903309043090530906309073090830909309103091130912309133091430915309163091730918309193092030921309223092330924309253092630927309283092930930309313093230933309343093530936309373093830939309403094130942309433094430945309463094730948309493095030951309523095330954309553095630957309583095930960309613096230963309643096530966309673096830969309703097130972309733097430975309763097730978309793098030981309823098330984309853098630987309883098930990309913099230993309943099530996309973099830999310003100131002310033100431005310063100731008310093101031011310123101331014310153101631017310183101931020310213102231023310243102531026310273102831029310303103131032310333103431035310363103731038310393104031041310423104331044310453104631047310483104931050310513105231053310543105531056310573105831059310603106131062310633106431065310663106731068310693107031071310723107331074310753107631077310783107931080310813108231083310843108531086310873108831089310903109131092310933109431095310963109731098310993110031101311023110331104311053110631107311083110931110311113111231113311143111531116311173111831119311203112131122311233112431125311263112731128311293113031131311323113331134311353113631137311383113931140311413114231143311443114531146311473114831149311503115131152311533115431155311563115731158311593116031161311623116331164311653116631167311683116931170311713117231173311743117531176311773117831179311803118131182311833118431185311863118731188311893119031191311923119331194311953119631197311983119931200312013120231203312043120531206312073120831209312103121131212312133121431215312163121731218312193122031221312223122331224312253122631227312283122931230312313123231233312343123531236312373123831239312403124131242312433124431245312463124731248312493125031251312523125331254312553125631257312583125931260312613126231263312643126531266312673126831269312703127131272312733127431275312763127731278312793128031281312823128331284312853128631287312883128931290312913129231293312943129531296312973129831299313003130131302313033130431305313063130731308313093131031311313123131331314313153131631317313183131931320313213132231323313243132531326313273132831329313303133131332313333133431335313363133731338313393134031341313423134331344313453134631347313483134931350313513135231353313543135531356313573135831359313603136131362313633136431365313663136731368313693137031371313723137331374313753137631377313783137931380313813138231383313843138531386313873138831389313903139131392313933139431395313963139731398313993140031401314023140331404314053140631407314083140931410314113141231413314143141531416314173141831419314203142131422314233142431425314263142731428314293143031431314323143331434314353143631437314383143931440314413144231443314443144531446314473144831449314503145131452314533145431455314563145731458314593146031461314623146331464314653146631467314683146931470314713147231473314743147531476314773147831479314803148131482314833148431485314863148731488314893149031491314923149331494314953149631497314983149931500315013150231503315043150531506315073150831509315103151131512315133151431515315163151731518315193152031521315223152331524315253152631527315283152931530315313153231533315343153531536315373153831539315403154131542315433154431545315463154731548315493155031551315523155331554315553155631557315583155931560315613156231563315643156531566315673156831569315703157131572315733157431575315763157731578315793158031581315823158331584315853158631587315883158931590315913159231593315943159531596315973159831599316003160131602316033160431605316063160731608316093161031611316123161331614316153161631617316183161931620316213162231623316243162531626316273162831629316303163131632316333163431635316363163731638316393164031641316423164331644316453164631647316483164931650316513165231653316543165531656316573165831659316603166131662316633166431665316663166731668316693167031671316723167331674316753167631677316783167931680316813168231683316843168531686316873168831689316903169131692316933169431695316963169731698316993170031701317023170331704317053170631707317083170931710317113171231713317143171531716317173171831719317203172131722317233172431725317263172731728317293173031731317323173331734317353173631737317383173931740317413174231743317443174531746317473174831749317503175131752317533175431755317563175731758317593176031761317623176331764317653176631767317683176931770317713177231773317743177531776317773177831779317803178131782317833178431785317863178731788317893179031791317923179331794317953179631797317983179931800318013180231803318043180531806318073180831809318103181131812318133181431815318163181731818318193182031821318223182331824318253182631827318283182931830318313183231833318343183531836318373183831839318403184131842318433184431845318463184731848318493185031851318523185331854318553185631857318583185931860318613186231863318643186531866318673186831869318703187131872318733187431875318763187731878318793188031881318823188331884318853188631887318883188931890318913189231893318943189531896318973189831899319003190131902319033190431905319063190731908319093191031911319123191331914319153191631917319183191931920319213192231923319243192531926319273192831929319303193131932319333193431935319363193731938319393194031941319423194331944319453194631947319483194931950319513195231953319543195531956319573195831959319603196131962319633196431965319663196731968319693197031971319723197331974319753197631977319783197931980319813198231983319843198531986319873198831989319903199131992319933199431995319963199731998319993200032001320023200332004320053200632007320083200932010320113201232013320143201532016320173201832019320203202132022320233202432025320263202732028320293203032031320323203332034320353203632037320383203932040320413204232043320443204532046320473204832049320503205132052320533205432055320563205732058320593206032061320623206332064320653206632067320683206932070320713207232073320743207532076320773207832079320803208132082320833208432085320863208732088320893209032091320923209332094320953209632097320983209932100321013210232103321043210532106321073210832109321103211132112321133211432115321163211732118321193212032121321223212332124321253212632127321283212932130321313213232133321343213532136321373213832139321403214132142321433214432145321463214732148321493215032151321523215332154321553215632157321583215932160321613216232163321643216532166321673216832169321703217132172321733217432175321763217732178321793218032181321823218332184321853218632187321883218932190321913219232193321943219532196321973219832199322003220132202322033220432205322063220732208322093221032211322123221332214322153221632217322183221932220322213222232223322243222532226322273222832229322303223132232322333223432235322363223732238322393224032241322423224332244322453224632247322483224932250322513225232253322543225532256322573225832259322603226132262322633226432265322663226732268322693227032271322723227332274322753227632277322783227932280322813228232283322843228532286322873228832289322903229132292322933229432295322963229732298322993230032301323023230332304323053230632307323083230932310323113231232313323143231532316323173231832319323203232132322323233232432325323263232732328323293233032331323323233332334323353233632337323383233932340323413234232343323443234532346323473234832349323503235132352323533235432355323563235732358323593236032361323623236332364323653236632367323683236932370323713237232373323743237532376323773237832379323803238132382323833238432385323863238732388323893239032391323923239332394323953239632397323983239932400324013240232403324043240532406324073240832409324103241132412324133241432415324163241732418324193242032421324223242332424324253242632427324283242932430324313243232433324343243532436324373243832439324403244132442324433244432445324463244732448324493245032451324523245332454324553245632457324583245932460324613246232463324643246532466324673246832469324703247132472324733247432475324763247732478324793248032481324823248332484324853248632487324883248932490324913249232493324943249532496324973249832499325003250132502325033250432505325063250732508325093251032511325123251332514325153251632517325183251932520325213252232523325243252532526325273252832529325303253132532325333253432535325363253732538325393254032541325423254332544325453254632547325483254932550325513255232553325543255532556325573255832559325603256132562325633256432565325663256732568325693257032571325723257332574325753257632577325783257932580325813258232583325843258532586325873258832589325903259132592325933259432595325963259732598325993260032601326023260332604326053260632607326083260932610326113261232613326143261532616326173261832619326203262132622326233262432625326263262732628326293263032631326323263332634326353263632637326383263932640326413264232643326443264532646326473264832649326503265132652326533265432655326563265732658326593266032661326623266332664326653266632667326683266932670326713267232673326743267532676326773267832679326803268132682326833268432685326863268732688326893269032691326923269332694326953269632697326983269932700327013270232703327043270532706327073270832709327103271132712327133271432715327163271732718327193272032721327223272332724327253272632727327283272932730327313273232733327343273532736327373273832739327403274132742327433274432745327463274732748327493275032751327523275332754327553275632757327583275932760327613276232763327643276532766327673276832769327703277132772327733277432775327763277732778327793278032781327823278332784327853278632787327883278932790327913279232793327943279532796327973279832799328003280132802328033280432805328063280732808328093281032811328123281332814328153281632817328183281932820328213282232823328243282532826328273282832829328303283132832328333283432835328363283732838328393284032841328423284332844328453284632847328483284932850328513285232853328543285532856328573285832859328603286132862328633286432865328663286732868328693287032871328723287332874328753287632877328783287932880328813288232883328843288532886328873288832889328903289132892328933289432895328963289732898328993290032901329023290332904329053290632907329083290932910329113291232913329143291532916329173291832919329203292132922329233292432925329263292732928329293293032931329323293332934329353293632937329383293932940329413294232943329443294532946329473294832949329503295132952329533295432955329563295732958329593296032961329623296332964329653296632967329683296932970329713297232973329743297532976329773297832979329803298132982329833298432985329863298732988329893299032991329923299332994329953299632997329983299933000330013300233003330043300533006330073300833009330103301133012330133301433015330163301733018330193302033021330223302333024330253302633027330283302933030330313303233033330343303533036330373303833039330403304133042330433304433045330463304733048330493305033051330523305333054330553305633057330583305933060330613306233063330643306533066330673306833069330703307133072330733307433075330763307733078330793308033081330823308333084330853308633087330883308933090330913309233093330943309533096330973309833099331003310133102331033310433105331063310733108331093311033111331123311333114331153311633117331183311933120331213312233123331243312533126331273312833129331303313133132331333313433135331363313733138331393314033141331423314333144331453314633147331483314933150331513315233153331543315533156331573315833159331603316133162331633316433165331663316733168331693317033171331723317333174331753317633177331783317933180331813318233183331843318533186331873318833189331903319133192331933319433195331963319733198331993320033201332023320333204332053320633207332083320933210332113321233213332143321533216332173321833219332203322133222332233322433225332263322733228332293323033231332323323333234332353323633237332383323933240332413324233243332443324533246332473324833249332503325133252332533325433255332563325733258332593326033261332623326333264332653326633267332683326933270332713327233273332743327533276332773327833279332803328133282332833328433285332863328733288332893329033291332923329333294332953329633297332983329933300333013330233303333043330533306333073330833309333103331133312333133331433315333163331733318333193332033321333223332333324333253332633327333283332933330333313333233333333343333533336333373333833339333403334133342333433334433345333463334733348333493335033351333523335333354333553335633357333583335933360333613336233363333643336533366333673336833369333703337133372333733337433375333763337733378333793338033381333823338333384333853338633387333883338933390333913339233393333943339533396333973339833399334003340133402334033340433405334063340733408334093341033411334123341333414334153341633417334183341933420334213342233423334243342533426334273342833429334303343133432334333343433435334363343733438334393344033441334423344333444334453344633447334483344933450334513345233453334543345533456334573345833459334603346133462334633346433465334663346733468334693347033471334723347333474334753347633477334783347933480334813348233483334843348533486334873348833489334903349133492334933349433495334963349733498334993350033501335023350333504335053350633507335083350933510335113351233513335143351533516335173351833519335203352133522335233352433525335263352733528335293353033531335323353333534335353353633537335383353933540335413354233543335443354533546335473354833549335503355133552335533355433555335563355733558335593356033561335623356333564335653356633567335683356933570335713357233573335743357533576335773357833579335803358133582335833358433585335863358733588335893359033591335923359333594335953359633597335983359933600336013360233603336043360533606336073360833609336103361133612336133361433615336163361733618336193362033621336223362333624336253362633627336283362933630336313363233633336343363533636336373363833639336403364133642336433364433645336463364733648336493365033651336523365333654336553365633657336583365933660336613366233663336643366533666336673366833669336703367133672336733367433675336763367733678336793368033681336823368333684336853368633687336883368933690336913369233693336943369533696336973369833699337003370133702337033370433705337063370733708337093371033711337123371333714337153371633717337183371933720337213372233723337243372533726337273372833729337303373133732337333373433735337363373733738337393374033741337423374333744337453374633747337483374933750337513375233753337543375533756337573375833759337603376133762337633376433765337663376733768337693377033771337723377333774337753377633777337783377933780337813378233783337843378533786337873378833789337903379133792337933379433795337963379733798337993380033801338023380333804338053380633807338083380933810338113381233813338143381533816338173381833819338203382133822338233382433825338263382733828338293383033831338323383333834338353383633837338383383933840338413384233843338443384533846338473384833849338503385133852338533385433855338563385733858338593386033861338623386333864338653386633867338683386933870338713387233873338743387533876338773387833879338803388133882338833388433885338863388733888338893389033891338923389333894338953389633897338983389933900339013390233903339043390533906339073390833909339103391133912339133391433915339163391733918339193392033921339223392333924339253392633927339283392933930339313393233933339343393533936339373393833939339403394133942339433394433945339463394733948339493395033951339523395333954339553395633957339583395933960339613396233963339643396533966339673396833969339703397133972339733397433975339763397733978339793398033981339823398333984339853398633987339883398933990339913399233993339943399533996339973399833999340003400134002340033400434005340063400734008340093401034011340123401334014340153401634017340183401934020340213402234023340243402534026340273402834029340303403134032340333403434035340363403734038340393404034041340423404334044340453404634047340483404934050340513405234053340543405534056340573405834059340603406134062340633406434065340663406734068340693407034071340723407334074340753407634077340783407934080340813408234083340843408534086340873408834089340903409134092340933409434095340963409734098340993410034101341023410334104341053410634107341083410934110341113411234113341143411534116341173411834119341203412134122341233412434125341263412734128341293413034131341323413334134341353413634137341383413934140341413414234143341443414534146341473414834149341503415134152341533415434155341563415734158341593416034161341623416334164341653416634167341683416934170341713417234173341743417534176341773417834179341803418134182341833418434185341863418734188341893419034191341923419334194341953419634197341983419934200342013420234203342043420534206342073420834209342103421134212342133421434215342163421734218342193422034221342223422334224342253422634227342283422934230342313423234233342343423534236342373423834239342403424134242342433424434245342463424734248342493425034251342523425334254342553425634257342583425934260342613426234263342643426534266342673426834269342703427134272342733427434275342763427734278342793428034281342823428334284342853428634287342883428934290342913429234293342943429534296342973429834299343003430134302343033430434305343063430734308343093431034311343123431334314343153431634317343183431934320343213432234323343243432534326343273432834329343303433134332343333433434335343363433734338343393434034341343423434334344343453434634347343483434934350343513435234353343543435534356343573435834359343603436134362343633436434365343663436734368343693437034371343723437334374343753437634377343783437934380343813438234383343843438534386343873438834389343903439134392343933439434395343963439734398343993440034401344023440334404344053440634407344083440934410344113441234413344143441534416344173441834419344203442134422344233442434425344263442734428344293443034431344323443334434344353443634437344383443934440344413444234443344443444534446344473444834449344503445134452344533445434455344563445734458344593446034461344623446334464344653446634467344683446934470344713447234473344743447534476344773447834479344803448134482344833448434485344863448734488344893449034491344923449334494344953449634497344983449934500345013450234503345043450534506345073450834509345103451134512345133451434515345163451734518345193452034521345223452334524345253452634527345283452934530345313453234533345343453534536345373453834539345403454134542345433454434545345463454734548345493455034551345523455334554345553455634557345583455934560345613456234563345643456534566345673456834569345703457134572345733457434575345763457734578345793458034581345823458334584345853458634587345883458934590345913459234593345943459534596345973459834599346003460134602346033460434605346063460734608346093461034611346123461334614346153461634617346183461934620346213462234623346243462534626346273462834629346303463134632346333463434635346363463734638346393464034641346423464334644346453464634647346483464934650346513465234653346543465534656346573465834659346603466134662346633466434665346663466734668346693467034671346723467334674346753467634677346783467934680346813468234683346843468534686346873468834689346903469134692346933469434695346963469734698346993470034701347023470334704347053470634707347083470934710347113471234713347143471534716347173471834719347203472134722347233472434725347263472734728347293473034731347323473334734347353473634737347383473934740347413474234743347443474534746347473474834749347503475134752347533475434755347563475734758347593476034761347623476334764347653476634767347683476934770347713477234773347743477534776347773477834779347803478134782347833478434785347863478734788347893479034791347923479334794347953479634797347983479934800348013480234803348043480534806348073480834809348103481134812348133481434815348163481734818348193482034821348223482334824348253482634827348283482934830348313483234833348343483534836348373483834839348403484134842348433484434845348463484734848348493485034851348523485334854348553485634857348583485934860348613486234863348643486534866348673486834869348703487134872348733487434875348763487734878348793488034881348823488334884348853488634887348883488934890348913489234893348943489534896348973489834899349003490134902349033490434905349063490734908349093491034911349123491334914349153491634917349183491934920349213492234923349243492534926349273492834929349303493134932349333493434935349363493734938349393494034941349423494334944349453494634947349483494934950349513495234953349543495534956349573495834959349603496134962349633496434965349663496734968349693497034971349723497334974349753497634977349783497934980349813498234983349843498534986349873498834989349903499134992349933499434995349963499734998349993500035001350023500335004350053500635007350083500935010350113501235013350143501535016350173501835019350203502135022350233502435025350263502735028350293503035031350323503335034350353503635037350383503935040350413504235043350443504535046350473504835049350503505135052350533505435055350563505735058350593506035061350623506335064350653506635067350683506935070350713507235073350743507535076350773507835079350803508135082350833508435085350863508735088350893509035091350923509335094350953509635097350983509935100351013510235103351043510535106351073510835109351103511135112351133511435115351163511735118351193512035121351223512335124351253512635127351283512935130351313513235133351343513535136351373513835139351403514135142351433514435145351463514735148351493515035151351523515335154351553515635157351583515935160351613516235163351643516535166351673516835169351703517135172351733517435175351763517735178351793518035181351823518335184351853518635187351883518935190351913519235193351943519535196351973519835199352003520135202352033520435205352063520735208352093521035211352123521335214352153521635217352183521935220352213522235223352243522535226352273522835229352303523135232352333523435235352363523735238352393524035241352423524335244352453524635247352483524935250352513525235253352543525535256352573525835259352603526135262352633526435265352663526735268352693527035271352723527335274352753527635277352783527935280352813528235283352843528535286352873528835289352903529135292352933529435295352963529735298352993530035301353023530335304353053530635307353083530935310353113531235313353143531535316353173531835319353203532135322353233532435325353263532735328353293533035331353323533335334353353533635337353383533935340353413534235343353443534535346353473534835349353503535135352353533535435355353563535735358353593536035361353623536335364353653536635367353683536935370353713537235373353743537535376353773537835379353803538135382353833538435385353863538735388353893539035391353923539335394353953539635397353983539935400354013540235403354043540535406354073540835409354103541135412354133541435415354163541735418354193542035421354223542335424354253542635427354283542935430354313543235433354343543535436354373543835439354403544135442354433544435445354463544735448354493545035451354523545335454354553545635457354583545935460354613546235463354643546535466354673546835469354703547135472354733547435475354763547735478354793548035481354823548335484354853548635487354883548935490354913549235493354943549535496354973549835499355003550135502355033550435505355063550735508355093551035511355123551335514355153551635517355183551935520355213552235523355243552535526355273552835529355303553135532355333553435535355363553735538355393554035541355423554335544355453554635547355483554935550355513555235553355543555535556355573555835559355603556135562355633556435565355663556735568355693557035571355723557335574355753557635577355783557935580355813558235583355843558535586355873558835589355903559135592355933559435595355963559735598355993560035601356023560335604356053560635607356083560935610356113561235613356143561535616356173561835619356203562135622356233562435625356263562735628356293563035631356323563335634356353563635637356383563935640356413564235643356443564535646356473564835649356503565135652356533565435655356563565735658356593566035661356623566335664356653566635667356683566935670356713567235673356743567535676356773567835679356803568135682356833568435685356863568735688356893569035691356923569335694356953569635697356983569935700357013570235703357043570535706357073570835709357103571135712357133571435715357163571735718357193572035721357223572335724357253572635727357283572935730357313573235733357343573535736357373573835739357403574135742357433574435745357463574735748357493575035751357523575335754357553575635757357583575935760357613576235763357643576535766357673576835769357703577135772357733577435775357763577735778357793578035781357823578335784357853578635787357883578935790357913579235793357943579535796357973579835799358003580135802358033580435805358063580735808358093581035811358123581335814358153581635817358183581935820358213582235823358243582535826358273582835829358303583135832358333583435835358363583735838358393584035841358423584335844358453584635847358483584935850358513585235853358543585535856358573585835859358603586135862358633586435865358663586735868358693587035871358723587335874358753587635877358783587935880358813588235883358843588535886358873588835889358903589135892358933589435895358963589735898358993590035901359023590335904359053590635907359083590935910359113591235913359143591535916359173591835919359203592135922359233592435925359263592735928359293593035931359323593335934359353593635937359383593935940359413594235943359443594535946359473594835949359503595135952359533595435955359563595735958359593596035961359623596335964359653596635967359683596935970359713597235973359743597535976359773597835979359803598135982359833598435985359863598735988359893599035991359923599335994359953599635997359983599936000360013600236003360043600536006360073600836009360103601136012360133601436015360163601736018360193602036021360223602336024360253602636027360283602936030360313603236033360343603536036360373603836039360403604136042360433604436045360463604736048360493605036051360523605336054360553605636057360583605936060360613606236063360643606536066360673606836069360703607136072360733607436075360763607736078360793608036081360823608336084360853608636087360883608936090360913609236093360943609536096360973609836099361003610136102361033610436105361063610736108361093611036111361123611336114361153611636117361183611936120361213612236123361243612536126361273612836129361303613136132361333613436135361363613736138361393614036141361423614336144361453614636147361483614936150361513615236153361543615536156361573615836159361603616136162361633616436165361663616736168361693617036171361723617336174361753617636177361783617936180361813618236183361843618536186361873618836189361903619136192361933619436195361963619736198361993620036201362023620336204362053620636207362083620936210362113621236213362143621536216362173621836219362203622136222362233622436225362263622736228362293623036231362323623336234362353623636237362383623936240362413624236243362443624536246362473624836249362503625136252362533625436255362563625736258362593626036261362623626336264362653626636267362683626936270362713627236273362743627536276362773627836279362803628136282362833628436285362863628736288362893629036291362923629336294362953629636297362983629936300363013630236303363043630536306363073630836309363103631136312363133631436315363163631736318363193632036321363223632336324363253632636327363283632936330363313633236333363343633536336363373633836339363403634136342363433634436345363463634736348363493635036351363523635336354363553635636357363583635936360363613636236363363643636536366363673636836369363703637136372363733637436375363763637736378363793638036381363823638336384363853638636387363883638936390363913639236393363943639536396363973639836399364003640136402364033640436405364063640736408364093641036411364123641336414364153641636417364183641936420364213642236423364243642536426364273642836429364303643136432364333643436435364363643736438364393644036441364423644336444364453644636447364483644936450364513645236453364543645536456364573645836459364603646136462364633646436465364663646736468364693647036471364723647336474364753647636477364783647936480364813648236483364843648536486364873648836489364903649136492364933649436495364963649736498364993650036501365023650336504365053650636507365083650936510365113651236513365143651536516365173651836519365203652136522365233652436525365263652736528365293653036531365323653336534365353653636537365383653936540365413654236543365443654536546365473654836549365503655136552365533655436555365563655736558365593656036561365623656336564365653656636567365683656936570365713657236573365743657536576365773657836579365803658136582365833658436585365863658736588365893659036591365923659336594365953659636597365983659936600366013660236603366043660536606366073660836609366103661136612366133661436615366163661736618366193662036621366223662336624366253662636627366283662936630366313663236633366343663536636366373663836639366403664136642366433664436645366463664736648366493665036651366523665336654366553665636657366583665936660366613666236663366643666536666366673666836669366703667136672366733667436675366763667736678366793668036681366823668336684366853668636687366883668936690366913669236693366943669536696366973669836699367003670136702367033670436705367063670736708367093671036711367123671336714367153671636717367183671936720367213672236723367243672536726367273672836729367303673136732367333673436735367363673736738367393674036741367423674336744367453674636747367483674936750367513675236753367543675536756367573675836759367603676136762367633676436765367663676736768367693677036771367723677336774367753677636777367783677936780367813678236783367843678536786367873678836789367903679136792367933679436795367963679736798367993680036801368023680336804368053680636807368083680936810368113681236813368143681536816368173681836819368203682136822368233682436825368263682736828368293683036831368323683336834368353683636837368383683936840368413684236843368443684536846368473684836849368503685136852368533685436855368563685736858368593686036861368623686336864368653686636867368683686936870368713687236873368743687536876368773687836879368803688136882368833688436885368863688736888368893689036891368923689336894368953689636897368983689936900369013690236903369043690536906369073690836909369103691136912369133691436915369163691736918369193692036921369223692336924369253692636927369283692936930369313693236933369343693536936369373693836939369403694136942369433694436945369463694736948369493695036951369523695336954369553695636957369583695936960369613696236963369643696536966369673696836969369703697136972369733697436975369763697736978369793698036981369823698336984369853698636987369883698936990369913699236993369943699536996369973699836999370003700137002370033700437005370063700737008370093701037011370123701337014370153701637017370183701937020370213702237023370243702537026370273702837029370303703137032370333703437035370363703737038370393704037041370423704337044370453704637047370483704937050370513705237053370543705537056370573705837059370603706137062370633706437065370663706737068370693707037071370723707337074370753707637077370783707937080370813708237083370843708537086370873708837089370903709137092370933709437095370963709737098370993710037101371023710337104371053710637107371083710937110371113711237113371143711537116371173711837119371203712137122371233712437125371263712737128371293713037131371323713337134371353713637137371383713937140371413714237143371443714537146371473714837149371503715137152371533715437155371563715737158371593716037161371623716337164371653716637167371683716937170371713717237173371743717537176371773717837179371803718137182371833718437185371863718737188371893719037191371923719337194371953719637197371983719937200372013720237203372043720537206372073720837209372103721137212372133721437215372163721737218372193722037221372223722337224372253722637227372283722937230372313723237233372343723537236372373723837239372403724137242372433724437245372463724737248372493725037251372523725337254372553725637257372583725937260372613726237263372643726537266372673726837269372703727137272372733727437275372763727737278372793728037281372823728337284372853728637287372883728937290372913729237293372943729537296372973729837299373003730137302373033730437305373063730737308373093731037311373123731337314373153731637317373183731937320373213732237323373243732537326373273732837329373303733137332373333733437335373363733737338373393734037341373423734337344373453734637347373483734937350373513735237353373543735537356373573735837359373603736137362373633736437365373663736737368373693737037371373723737337374373753737637377373783737937380373813738237383373843738537386373873738837389373903739137392373933739437395373963739737398373993740037401374023740337404374053740637407374083740937410374113741237413374143741537416374173741837419374203742137422374233742437425374263742737428374293743037431374323743337434374353743637437374383743937440374413744237443374443744537446374473744837449374503745137452374533745437455374563745737458374593746037461374623746337464374653746637467374683746937470374713747237473374743747537476374773747837479374803748137482374833748437485374863748737488374893749037491374923749337494374953749637497374983749937500375013750237503375043750537506375073750837509375103751137512375133751437515375163751737518375193752037521375223752337524375253752637527375283752937530375313753237533375343753537536375373753837539375403754137542375433754437545375463754737548375493755037551375523755337554375553755637557375583755937560375613756237563375643756537566375673756837569375703757137572375733757437575375763757737578375793758037581375823758337584375853758637587375883758937590375913759237593375943759537596375973759837599376003760137602376033760437605376063760737608376093761037611376123761337614376153761637617376183761937620376213762237623376243762537626376273762837629376303763137632376333763437635376363763737638376393764037641376423764337644376453764637647376483764937650376513765237653376543765537656376573765837659376603766137662376633766437665376663766737668376693767037671376723767337674376753767637677376783767937680376813768237683376843768537686376873768837689376903769137692376933769437695376963769737698376993770037701377023770337704377053770637707377083770937710377113771237713377143771537716377173771837719377203772137722377233772437725377263772737728377293773037731377323773337734377353773637737377383773937740377413774237743377443774537746377473774837749377503775137752377533775437755377563775737758377593776037761377623776337764377653776637767377683776937770377713777237773377743777537776377773777837779377803778137782377833778437785377863778737788377893779037791377923779337794377953779637797377983779937800378013780237803378043780537806378073780837809378103781137812378133781437815378163781737818378193782037821378223782337824378253782637827378283782937830378313783237833378343783537836378373783837839378403784137842378433784437845378463784737848378493785037851378523785337854378553785637857378583785937860378613786237863378643786537866378673786837869378703787137872378733787437875378763787737878378793788037881378823788337884378853788637887378883788937890378913789237893378943789537896378973789837899379003790137902379033790437905379063790737908379093791037911379123791337914379153791637917379183791937920379213792237923379243792537926379273792837929379303793137932379333793437935379363793737938379393794037941379423794337944379453794637947379483794937950379513795237953379543795537956379573795837959379603796137962379633796437965379663796737968379693797037971379723797337974379753797637977379783797937980379813798237983379843798537986379873798837989379903799137992379933799437995379963799737998379993800038001380023800338004380053800638007380083800938010380113801238013380143801538016380173801838019380203802138022380233802438025380263802738028380293803038031380323803338034380353803638037380383803938040380413804238043380443804538046380473804838049380503805138052380533805438055380563805738058380593806038061380623806338064380653806638067380683806938070380713807238073380743807538076380773807838079380803808138082380833808438085380863808738088380893809038091380923809338094380953809638097380983809938100381013810238103381043810538106381073810838109381103811138112381133811438115381163811738118381193812038121381223812338124381253812638127381283812938130381313813238133381343813538136381373813838139381403814138142381433814438145381463814738148381493815038151381523815338154381553815638157381583815938160381613816238163381643816538166381673816838169381703817138172381733817438175381763817738178381793818038181381823818338184381853818638187381883818938190381913819238193381943819538196381973819838199382003820138202382033820438205382063820738208382093821038211382123821338214382153821638217382183821938220382213822238223382243822538226382273822838229382303823138232382333823438235382363823738238382393824038241382423824338244382453824638247382483824938250382513825238253382543825538256382573825838259382603826138262382633826438265382663826738268382693827038271382723827338274382753827638277382783827938280382813828238283382843828538286382873828838289382903829138292382933829438295382963829738298382993830038301383023830338304383053830638307383083830938310383113831238313383143831538316383173831838319383203832138322383233832438325383263832738328383293833038331383323833338334383353833638337383383833938340383413834238343383443834538346383473834838349383503835138352383533835438355383563835738358383593836038361383623836338364383653836638367383683836938370383713837238373383743837538376383773837838379383803838138382383833838438385383863838738388383893839038391383923839338394383953839638397383983839938400384013840238403384043840538406384073840838409384103841138412384133841438415384163841738418384193842038421384223842338424384253842638427384283842938430384313843238433384343843538436384373843838439384403844138442384433844438445384463844738448384493845038451384523845338454384553845638457384583845938460384613846238463384643846538466384673846838469384703847138472384733847438475384763847738478384793848038481384823848338484384853848638487384883848938490384913849238493384943849538496384973849838499385003850138502385033850438505385063850738508385093851038511385123851338514385153851638517385183851938520385213852238523385243852538526385273852838529385303853138532385333853438535385363853738538385393854038541385423854338544385453854638547385483854938550385513855238553385543855538556385573855838559385603856138562385633856438565385663856738568385693857038571385723857338574385753857638577385783857938580385813858238583385843858538586385873858838589385903859138592385933859438595385963859738598385993860038601386023860338604386053860638607386083860938610386113861238613386143861538616386173861838619386203862138622386233862438625386263862738628386293863038631386323863338634386353863638637386383863938640386413864238643386443864538646386473864838649386503865138652386533865438655386563865738658386593866038661386623866338664386653866638667386683866938670386713867238673386743867538676386773867838679386803868138682386833868438685386863868738688386893869038691386923869338694386953869638697386983869938700387013870238703387043870538706387073870838709387103871138712387133871438715387163871738718387193872038721387223872338724387253872638727387283872938730387313873238733387343873538736387373873838739387403874138742387433874438745387463874738748387493875038751387523875338754387553875638757387583875938760387613876238763387643876538766387673876838769387703877138772387733877438775387763877738778387793878038781387823878338784387853878638787387883878938790387913879238793387943879538796387973879838799388003880138802388033880438805388063880738808388093881038811388123881338814388153881638817388183881938820388213882238823388243882538826388273882838829388303883138832388333883438835388363883738838388393884038841388423884338844388453884638847388483884938850388513885238853388543885538856388573885838859388603886138862388633886438865388663886738868388693887038871388723887338874388753887638877388783887938880388813888238883388843888538886388873888838889388903889138892388933889438895388963889738898388993890038901389023890338904389053890638907389083890938910389113891238913389143891538916389173891838919389203892138922389233892438925389263892738928389293893038931389323893338934389353893638937389383893938940389413894238943389443894538946389473894838949389503895138952389533895438955389563895738958389593896038961389623896338964389653896638967389683896938970389713897238973389743897538976389773897838979389803898138982389833898438985389863898738988389893899038991389923899338994389953899638997389983899939000390013900239003390043900539006390073900839009390103901139012390133901439015390163901739018390193902039021390223902339024390253902639027390283902939030390313903239033390343903539036390373903839039390403904139042390433904439045390463904739048390493905039051390523905339054390553905639057390583905939060390613906239063390643906539066390673906839069390703907139072390733907439075390763907739078390793908039081390823908339084390853908639087390883908939090390913909239093390943909539096390973909839099391003910139102391033910439105391063910739108391093911039111391123911339114391153911639117391183911939120391213912239123391243912539126391273912839129391303913139132391333913439135391363913739138391393914039141391423914339144391453914639147391483914939150391513915239153391543915539156391573915839159391603916139162391633916439165391663916739168391693917039171391723917339174391753917639177391783917939180391813918239183391843918539186391873918839189391903919139192391933919439195391963919739198391993920039201392023920339204392053920639207392083920939210392113921239213392143921539216392173921839219392203922139222392233922439225392263922739228392293923039231392323923339234392353923639237392383923939240392413924239243392443924539246392473924839249392503925139252392533925439255392563925739258392593926039261392623926339264392653926639267392683926939270392713927239273392743927539276392773927839279392803928139282392833928439285392863928739288392893929039291392923929339294392953929639297392983929939300393013930239303393043930539306393073930839309393103931139312393133931439315393163931739318393193932039321393223932339324393253932639327393283932939330393313933239333393343933539336393373933839339393403934139342393433934439345393463934739348393493935039351393523935339354393553935639357393583935939360393613936239363393643936539366393673936839369393703937139372393733937439375393763937739378393793938039381393823938339384393853938639387393883938939390393913939239393393943939539396393973939839399394003940139402394033940439405394063940739408394093941039411394123941339414394153941639417394183941939420394213942239423394243942539426394273942839429394303943139432394333943439435394363943739438394393944039441394423944339444394453944639447394483944939450394513945239453394543945539456394573945839459394603946139462394633946439465394663946739468394693947039471394723947339474394753947639477394783947939480394813948239483394843948539486394873948839489394903949139492394933949439495394963949739498394993950039501395023950339504395053950639507395083950939510395113951239513395143951539516395173951839519395203952139522395233952439525395263952739528395293953039531395323953339534395353953639537395383953939540395413954239543395443954539546395473954839549395503955139552395533955439555395563955739558395593956039561395623956339564395653956639567395683956939570395713957239573395743957539576395773957839579395803958139582395833958439585395863958739588395893959039591395923959339594395953959639597395983959939600396013960239603396043960539606396073960839609396103961139612396133961439615396163961739618396193962039621396223962339624396253962639627396283962939630396313963239633396343963539636396373963839639396403964139642396433964439645396463964739648396493965039651396523965339654396553965639657396583965939660396613966239663396643966539666396673966839669396703967139672396733967439675396763967739678396793968039681396823968339684396853968639687396883968939690396913969239693396943969539696396973969839699397003970139702397033970439705397063970739708397093971039711397123971339714397153971639717397183971939720397213972239723397243972539726397273972839729397303973139732397333973439735397363973739738397393974039741397423974339744397453974639747397483974939750397513975239753397543975539756397573975839759397603976139762397633976439765397663976739768397693977039771397723977339774397753977639777397783977939780397813978239783397843978539786397873978839789397903979139792397933979439795397963979739798397993980039801398023980339804398053980639807398083980939810398113981239813398143981539816398173981839819398203982139822398233982439825398263982739828398293983039831398323983339834398353983639837398383983939840398413984239843398443984539846398473984839849398503985139852398533985439855398563985739858398593986039861398623986339864398653986639867398683986939870398713987239873398743987539876398773987839879398803988139882398833988439885398863988739888398893989039891398923989339894398953989639897398983989939900399013990239903399043990539906399073990839909399103991139912399133991439915399163991739918399193992039921399223992339924399253992639927399283992939930399313993239933399343993539936399373993839939399403994139942399433994439945399463994739948399493995039951399523995339954399553995639957399583995939960399613996239963399643996539966399673996839969399703997139972399733997439975399763997739978399793998039981399823998339984399853998639987399883998939990399913999239993399943999539996399973999839999400004000140002400034000440005400064000740008400094001040011400124001340014400154001640017400184001940020400214002240023400244002540026400274002840029400304003140032400334003440035400364003740038400394004040041400424004340044400454004640047400484004940050400514005240053400544005540056400574005840059400604006140062400634006440065400664006740068400694007040071400724007340074400754007640077400784007940080400814008240083400844008540086400874008840089400904009140092400934009440095400964009740098400994010040101401024010340104401054010640107401084010940110401114011240113401144011540116401174011840119401204012140122401234012440125401264012740128401294013040131401324013340134401354013640137401384013940140401414014240143401444014540146401474014840149401504015140152401534015440155401564015740158401594016040161401624016340164401654016640167401684016940170401714017240173401744017540176401774017840179401804018140182401834018440185401864018740188401894019040191401924019340194401954019640197401984019940200402014020240203402044020540206402074020840209402104021140212402134021440215402164021740218402194022040221402224022340224402254022640227402284022940230402314023240233402344023540236402374023840239402404024140242402434024440245402464024740248402494025040251402524025340254402554025640257402584025940260402614026240263402644026540266402674026840269402704027140272402734027440275402764027740278402794028040281402824028340284402854028640287402884028940290402914029240293402944029540296402974029840299403004030140302403034030440305403064030740308403094031040311403124031340314403154031640317403184031940320403214032240323403244032540326403274032840329403304033140332403334033440335403364033740338403394034040341403424034340344403454034640347403484034940350403514035240353403544035540356403574035840359403604036140362403634036440365403664036740368403694037040371403724037340374403754037640377403784037940380403814038240383403844038540386403874038840389403904039140392403934039440395403964039740398403994040040401404024040340404404054040640407404084040940410404114041240413404144041540416404174041840419404204042140422404234042440425404264042740428404294043040431404324043340434404354043640437404384043940440404414044240443404444044540446404474044840449404504045140452404534045440455404564045740458404594046040461404624046340464404654046640467404684046940470404714047240473404744047540476404774047840479404804048140482404834048440485404864048740488404894049040491404924049340494404954049640497404984049940500405014050240503405044050540506405074050840509405104051140512405134051440515405164051740518405194052040521405224052340524405254052640527405284052940530405314053240533405344053540536405374053840539405404054140542405434054440545405464054740548405494055040551405524055340554405554055640557405584055940560405614056240563405644056540566405674056840569405704057140572405734057440575405764057740578405794058040581405824058340584405854058640587405884058940590405914059240593405944059540596405974059840599406004060140602406034060440605406064060740608406094061040611406124061340614406154061640617406184061940620406214062240623406244062540626406274062840629406304063140632406334063440635406364063740638406394064040641406424064340644406454064640647406484064940650406514065240653406544065540656406574065840659406604066140662406634066440665406664066740668406694067040671406724067340674406754067640677406784067940680406814068240683406844068540686406874068840689406904069140692406934069440695406964069740698406994070040701407024070340704407054070640707407084070940710407114071240713407144071540716407174071840719407204072140722407234072440725407264072740728407294073040731407324073340734407354073640737407384073940740407414074240743407444074540746407474074840749407504075140752407534075440755407564075740758407594076040761407624076340764407654076640767407684076940770407714077240773407744077540776407774077840779407804078140782407834078440785407864078740788407894079040791407924079340794407954079640797407984079940800408014080240803408044080540806408074080840809408104081140812408134081440815408164081740818408194082040821408224082340824408254082640827408284082940830408314083240833408344083540836408374083840839408404084140842408434084440845408464084740848408494085040851408524085340854408554085640857408584085940860408614086240863408644086540866408674086840869408704087140872408734087440875408764087740878408794088040881408824088340884408854088640887408884088940890408914089240893408944089540896408974089840899409004090140902409034090440905409064090740908409094091040911409124091340914409154091640917409184091940920409214092240923409244092540926409274092840929409304093140932409334093440935409364093740938409394094040941409424094340944409454094640947409484094940950409514095240953409544095540956409574095840959409604096140962409634096440965409664096740968409694097040971409724097340974409754097640977409784097940980409814098240983409844098540986409874098840989409904099140992409934099440995409964099740998409994100041001410024100341004410054100641007410084100941010410114101241013410144101541016410174101841019410204102141022410234102441025410264102741028410294103041031410324103341034410354103641037410384103941040410414104241043410444104541046410474104841049410504105141052410534105441055410564105741058410594106041061410624106341064410654106641067410684106941070410714107241073410744107541076410774107841079410804108141082410834108441085410864108741088410894109041091410924109341094410954109641097410984109941100411014110241103411044110541106411074110841109411104111141112411134111441115411164111741118411194112041121411224112341124411254112641127411284112941130411314113241133411344113541136411374113841139411404114141142411434114441145411464114741148411494115041151411524115341154411554115641157411584115941160411614116241163411644116541166411674116841169411704117141172411734117441175411764117741178411794118041181411824118341184411854118641187411884118941190411914119241193411944119541196411974119841199412004120141202412034120441205412064120741208412094121041211412124121341214412154121641217412184121941220412214122241223412244122541226412274122841229412304123141232412334123441235412364123741238412394124041241412424124341244412454124641247412484124941250412514125241253412544125541256412574125841259412604126141262412634126441265412664126741268412694127041271412724127341274412754127641277412784127941280412814128241283412844128541286412874128841289412904129141292412934129441295412964129741298412994130041301413024130341304413054130641307413084130941310413114131241313413144131541316413174131841319413204132141322413234132441325413264132741328413294133041331413324133341334413354133641337413384133941340413414134241343413444134541346413474134841349413504135141352413534135441355413564135741358413594136041361413624136341364413654136641367413684136941370413714137241373413744137541376413774137841379413804138141382413834138441385413864138741388413894139041391413924139341394413954139641397413984139941400414014140241403414044140541406414074140841409414104141141412414134141441415414164141741418414194142041421414224142341424414254142641427414284142941430414314143241433414344143541436414374143841439414404144141442414434144441445414464144741448414494145041451414524145341454414554145641457414584145941460414614146241463414644146541466414674146841469414704147141472414734147441475414764147741478414794148041481414824148341484414854148641487414884148941490414914149241493414944149541496414974149841499415004150141502415034150441505415064150741508415094151041511415124151341514415154151641517415184151941520415214152241523415244152541526415274152841529415304153141532415334153441535415364153741538415394154041541415424154341544415454154641547415484154941550415514155241553415544155541556415574155841559415604156141562415634156441565415664156741568415694157041571415724157341574415754157641577415784157941580415814158241583415844158541586415874158841589415904159141592415934159441595415964159741598415994160041601416024160341604416054160641607416084160941610416114161241613416144161541616416174161841619416204162141622416234162441625416264162741628416294163041631416324163341634416354163641637416384163941640416414164241643416444164541646416474164841649416504165141652416534165441655416564165741658416594166041661416624166341664416654166641667416684166941670416714167241673416744167541676416774167841679416804168141682416834168441685416864168741688416894169041691416924169341694416954169641697416984169941700417014170241703417044170541706417074170841709417104171141712417134171441715417164171741718417194172041721417224172341724417254172641727417284172941730417314173241733417344173541736417374173841739417404174141742417434174441745417464174741748417494175041751417524175341754417554175641757417584175941760417614176241763417644176541766417674176841769417704177141772417734177441775417764177741778417794178041781417824178341784417854178641787417884178941790417914179241793417944179541796417974179841799418004180141802418034180441805418064180741808418094181041811418124181341814418154181641817418184181941820418214182241823418244182541826418274182841829418304183141832418334183441835418364183741838418394184041841418424184341844418454184641847418484184941850418514185241853418544185541856418574185841859418604186141862418634186441865418664186741868418694187041871418724187341874418754187641877418784187941880418814188241883418844188541886418874188841889418904189141892418934189441895418964189741898418994190041901419024190341904419054190641907419084190941910419114191241913419144191541916419174191841919419204192141922419234192441925419264192741928419294193041931419324193341934419354193641937419384193941940419414194241943419444194541946419474194841949419504195141952419534195441955419564195741958419594196041961419624196341964419654196641967419684196941970419714197241973419744197541976419774197841979419804198141982419834198441985419864198741988419894199041991419924199341994419954199641997419984199942000420014200242003420044200542006420074200842009420104201142012420134201442015420164201742018420194202042021420224202342024420254202642027420284202942030420314203242033420344203542036420374203842039420404204142042420434204442045420464204742048420494205042051420524205342054420554205642057420584205942060420614206242063420644206542066420674206842069420704207142072420734207442075420764207742078420794208042081420824208342084420854208642087420884208942090420914209242093420944209542096420974209842099421004210142102421034210442105421064210742108421094211042111421124211342114421154211642117421184211942120421214212242123421244212542126421274212842129421304213142132421334213442135421364213742138421394214042141421424214342144421454214642147421484214942150421514215242153421544215542156421574215842159421604216142162421634216442165421664216742168421694217042171421724217342174421754217642177421784217942180421814218242183421844218542186421874218842189421904219142192421934219442195421964219742198421994220042201422024220342204422054220642207422084220942210422114221242213422144221542216422174221842219422204222142222422234222442225422264222742228422294223042231422324223342234422354223642237422384223942240422414224242243422444224542246422474224842249422504225142252422534225442255422564225742258422594226042261422624226342264422654226642267422684226942270422714227242273422744227542276422774227842279422804228142282422834228442285422864228742288422894229042291422924229342294422954229642297422984229942300423014230242303423044230542306423074230842309423104231142312423134231442315423164231742318423194232042321423224232342324423254232642327423284232942330423314233242333423344233542336423374233842339423404234142342423434234442345423464234742348423494235042351423524235342354423554235642357423584235942360423614236242363423644236542366423674236842369423704237142372423734237442375423764237742378423794238042381423824238342384423854238642387423884238942390423914239242393423944239542396423974239842399424004240142402424034240442405424064240742408424094241042411424124241342414424154241642417424184241942420424214242242423424244242542426424274242842429424304243142432424334243442435424364243742438424394244042441424424244342444424454244642447424484244942450424514245242453424544245542456424574245842459424604246142462424634246442465424664246742468424694247042471424724247342474424754247642477424784247942480424814248242483424844248542486424874248842489424904249142492424934249442495424964249742498424994250042501425024250342504425054250642507425084250942510425114251242513425144251542516425174251842519425204252142522425234252442525425264252742528425294253042531425324253342534425354253642537425384253942540425414254242543425444254542546425474254842549425504255142552425534255442555425564255742558425594256042561425624256342564425654256642567425684256942570425714257242573425744257542576425774257842579425804258142582425834258442585425864258742588425894259042591425924259342594425954259642597425984259942600426014260242603426044260542606426074260842609426104261142612426134261442615426164261742618426194262042621426224262342624426254262642627426284262942630426314263242633426344263542636426374263842639426404264142642426434264442645426464264742648426494265042651426524265342654426554265642657426584265942660426614266242663426644266542666426674266842669426704267142672426734267442675426764267742678426794268042681426824268342684426854268642687426884268942690426914269242693426944269542696426974269842699427004270142702427034270442705427064270742708427094271042711427124271342714427154271642717427184271942720427214272242723427244272542726427274272842729427304273142732427334273442735427364273742738427394274042741427424274342744427454274642747427484274942750427514275242753427544275542756427574275842759427604276142762427634276442765427664276742768427694277042771427724277342774427754277642777427784277942780427814278242783427844278542786427874278842789427904279142792427934279442795427964279742798427994280042801428024280342804428054280642807428084280942810428114281242813428144281542816428174281842819428204282142822428234282442825428264282742828428294283042831428324283342834428354283642837428384283942840428414284242843428444284542846428474284842849428504285142852428534285442855428564285742858428594286042861428624286342864428654286642867428684286942870428714287242873428744287542876428774287842879428804288142882428834288442885428864288742888428894289042891428924289342894428954289642897428984289942900429014290242903429044290542906429074290842909429104291142912429134291442915429164291742918429194292042921429224292342924429254292642927429284292942930429314293242933429344293542936429374293842939429404294142942429434294442945429464294742948429494295042951429524295342954429554295642957429584295942960429614296242963429644296542966429674296842969429704297142972429734297442975429764297742978429794298042981429824298342984429854298642987429884298942990429914299242993429944299542996429974299842999430004300143002430034300443005430064300743008430094301043011430124301343014430154301643017430184301943020430214302243023430244302543026430274302843029430304303143032430334303443035430364303743038430394304043041430424304343044430454304643047430484304943050430514305243053430544305543056430574305843059430604306143062430634306443065430664306743068430694307043071430724307343074430754307643077430784307943080430814308243083430844308543086430874308843089430904309143092430934309443095430964309743098430994310043101431024310343104431054310643107431084310943110431114311243113431144311543116431174311843119431204312143122431234312443125431264312743128431294313043131431324313343134431354313643137431384313943140431414314243143431444314543146431474314843149431504315143152431534315443155431564315743158431594316043161431624316343164431654316643167431684316943170431714317243173431744317543176431774317843179431804318143182431834318443185431864318743188431894319043191431924319343194431954319643197431984319943200432014320243203432044320543206432074320843209432104321143212432134321443215432164321743218432194322043221432224322343224432254322643227432284322943230432314323243233432344323543236432374323843239432404324143242432434324443245432464324743248432494325043251432524325343254432554325643257432584325943260432614326243263432644326543266432674326843269432704327143272432734327443275432764327743278432794328043281432824328343284432854328643287432884328943290432914329243293432944329543296432974329843299433004330143302433034330443305433064330743308433094331043311433124331343314433154331643317433184331943320433214332243323433244332543326433274332843329433304333143332433334333443335433364333743338433394334043341433424334343344433454334643347433484334943350433514335243353433544335543356433574335843359433604336143362433634336443365433664336743368433694337043371433724337343374433754337643377433784337943380433814338243383433844338543386433874338843389433904339143392433934339443395433964339743398433994340043401434024340343404434054340643407434084340943410434114341243413434144341543416434174341843419434204342143422434234342443425434264342743428434294343043431434324343343434434354343643437434384343943440434414344243443434444344543446434474344843449434504345143452434534345443455434564345743458434594346043461434624346343464434654346643467434684346943470434714347243473434744347543476434774347843479434804348143482434834348443485434864348743488434894349043491434924349343494434954349643497434984349943500435014350243503435044350543506435074350843509435104351143512435134351443515435164351743518435194352043521435224352343524435254352643527435284352943530435314353243533435344353543536435374353843539435404354143542435434354443545435464354743548435494355043551435524355343554435554355643557435584355943560435614356243563435644356543566435674356843569435704357143572435734357443575435764357743578435794358043581435824358343584435854358643587435884358943590435914359243593435944359543596435974359843599436004360143602436034360443605436064360743608436094361043611436124361343614436154361643617436184361943620436214362243623436244362543626436274362843629436304363143632436334363443635436364363743638436394364043641436424364343644436454364643647436484364943650436514365243653436544365543656436574365843659436604366143662436634366443665436664366743668436694367043671436724367343674436754367643677436784367943680436814368243683436844368543686436874368843689436904369143692436934369443695436964369743698436994370043701437024370343704437054370643707437084370943710437114371243713437144371543716437174371843719437204372143722437234372443725437264372743728437294373043731437324373343734437354373643737437384373943740437414374243743437444374543746437474374843749437504375143752437534375443755437564375743758437594376043761437624376343764437654376643767437684376943770437714377243773437744377543776437774377843779437804378143782437834378443785437864378743788437894379043791437924379343794437954379643797437984379943800438014380243803438044380543806438074380843809438104381143812438134381443815438164381743818438194382043821438224382343824438254382643827438284382943830438314383243833438344383543836438374383843839438404384143842438434384443845438464384743848438494385043851438524385343854438554385643857438584385943860438614386243863438644386543866438674386843869438704387143872438734387443875438764387743878438794388043881438824388343884438854388643887438884388943890438914389243893438944389543896438974389843899439004390143902439034390443905439064390743908439094391043911439124391343914439154391643917439184391943920439214392243923439244392543926439274392843929439304393143932439334393443935439364393743938439394394043941439424394343944439454394643947439484394943950439514395243953439544395543956439574395843959439604396143962439634396443965439664396743968439694397043971439724397343974439754397643977439784397943980439814398243983439844398543986439874398843989439904399143992439934399443995439964399743998439994400044001440024400344004440054400644007440084400944010440114401244013440144401544016440174401844019440204402144022440234402444025440264402744028440294403044031440324403344034440354403644037440384403944040440414404244043440444404544046440474404844049440504405144052440534405444055440564405744058440594406044061440624406344064440654406644067440684406944070440714407244073440744407544076440774407844079440804408144082440834408444085440864408744088440894409044091440924409344094440954409644097440984409944100441014410244103441044410544106441074410844109441104411144112441134411444115441164411744118441194412044121441224412344124441254412644127441284412944130441314413244133441344413544136441374413844139441404414144142441434414444145441464414744148441494415044151441524415344154441554415644157441584415944160441614416244163441644416544166441674416844169441704417144172441734417444175441764417744178441794418044181441824418344184441854418644187441884418944190441914419244193441944419544196441974419844199442004420144202442034420444205442064420744208442094421044211442124421344214442154421644217442184421944220442214422244223442244422544226442274422844229442304423144232442334423444235442364423744238442394424044241442424424344244442454424644247442484424944250442514425244253442544425544256442574425844259442604426144262442634426444265442664426744268442694427044271442724427344274442754427644277442784427944280442814428244283442844428544286442874428844289442904429144292442934429444295442964429744298442994430044301443024430344304443054430644307443084430944310443114431244313443144431544316443174431844319443204432144322443234432444325443264432744328443294433044331443324433344334443354433644337443384433944340443414434244343443444434544346443474434844349443504435144352443534435444355443564435744358443594436044361443624436344364443654436644367443684436944370443714437244373443744437544376443774437844379443804438144382443834438444385443864438744388443894439044391443924439344394443954439644397443984439944400444014440244403444044440544406444074440844409444104441144412444134441444415444164441744418444194442044421444224442344424444254442644427444284442944430444314443244433444344443544436444374443844439444404444144442444434444444445444464444744448444494445044451444524445344454444554445644457444584445944460444614446244463444644446544466444674446844469444704447144472444734447444475444764447744478444794448044481444824448344484444854448644487444884448944490444914449244493444944449544496444974449844499445004450144502445034450444505445064450744508445094451044511445124451344514445154451644517445184451944520445214452244523445244452544526445274452844529445304453144532445334453444535445364453744538445394454044541445424454344544445454454644547445484454944550445514455244553445544455544556445574455844559445604456144562445634456444565445664456744568445694457044571445724457344574445754457644577445784457944580445814458244583445844458544586445874458844589445904459144592445934459444595445964459744598445994460044601446024460344604446054460644607446084460944610446114461244613446144461544616446174461844619446204462144622446234462444625446264462744628446294463044631446324463344634446354463644637446384463944640446414464244643446444464544646446474464844649446504465144652446534465444655446564465744658446594466044661446624466344664446654466644667446684466944670446714467244673446744467544676446774467844679446804468144682446834468444685446864468744688446894469044691446924469344694446954469644697446984469944700447014470244703447044470544706447074470844709447104471144712447134471444715447164471744718447194472044721447224472344724447254472644727447284472944730447314473244733447344473544736447374473844739447404474144742447434474444745447464474744748447494475044751447524475344754447554475644757447584475944760447614476244763447644476544766447674476844769447704477144772447734477444775447764477744778447794478044781447824478344784447854478644787447884478944790447914479244793447944479544796447974479844799448004480144802448034480444805448064480744808448094481044811448124481344814448154481644817448184481944820448214482244823448244482544826448274482844829448304483144832448334483444835448364483744838448394484044841448424484344844448454484644847448484484944850448514485244853448544485544856448574485844859448604486144862448634486444865448664486744868448694487044871448724487344874448754487644877448784487944880448814488244883448844488544886448874488844889448904489144892448934489444895448964489744898448994490044901449024490344904449054490644907449084490944910449114491244913449144491544916449174491844919449204492144922449234492444925449264492744928449294493044931449324493344934449354493644937449384493944940449414494244943449444494544946449474494844949449504495144952449534495444955449564495744958449594496044961449624496344964449654496644967449684496944970449714497244973449744497544976449774497844979449804498144982449834498444985449864498744988449894499044991449924499344994449954499644997449984499945000450014500245003450044500545006450074500845009450104501145012450134501445015450164501745018450194502045021450224502345024450254502645027450284502945030450314503245033450344503545036450374503845039450404504145042450434504445045450464504745048450494505045051450524505345054450554505645057450584505945060450614506245063450644506545066450674506845069450704507145072450734507445075450764507745078450794508045081450824508345084450854508645087450884508945090450914509245093450944509545096450974509845099451004510145102451034510445105451064510745108451094511045111451124511345114451154511645117451184511945120451214512245123451244512545126451274512845129451304513145132451334513445135451364513745138451394514045141451424514345144451454514645147451484514945150451514515245153451544515545156451574515845159451604516145162451634516445165451664516745168451694517045171451724517345174451754517645177451784517945180451814518245183451844518545186451874518845189451904519145192451934519445195451964519745198451994520045201452024520345204452054520645207452084520945210452114521245213452144521545216452174521845219452204522145222452234522445225452264522745228452294523045231452324523345234452354523645237452384523945240452414524245243452444524545246452474524845249452504525145252452534525445255452564525745258452594526045261452624526345264452654526645267452684526945270452714527245273452744527545276452774527845279452804528145282452834528445285452864528745288452894529045291452924529345294452954529645297452984529945300453014530245303453044530545306453074530845309453104531145312453134531445315453164531745318453194532045321453224532345324453254532645327453284532945330453314533245333453344533545336453374533845339453404534145342453434534445345453464534745348453494535045351453524535345354453554535645357453584535945360453614536245363453644536545366453674536845369453704537145372453734537445375453764537745378453794538045381453824538345384453854538645387453884538945390453914539245393453944539545396453974539845399454004540145402454034540445405454064540745408454094541045411454124541345414454154541645417454184541945420454214542245423454244542545426454274542845429454304543145432454334543445435454364543745438454394544045441454424544345444454454544645447454484544945450454514545245453454544545545456454574545845459454604546145462454634546445465454664546745468454694547045471454724547345474454754547645477454784547945480454814548245483454844548545486454874548845489454904549145492454934549445495454964549745498454994550045501455024550345504455054550645507455084550945510455114551245513455144551545516455174551845519455204552145522455234552445525455264552745528455294553045531455324553345534455354553645537455384553945540455414554245543455444554545546455474554845549455504555145552455534555445555455564555745558455594556045561455624556345564455654556645567455684556945570455714557245573455744557545576455774557845579455804558145582455834558445585455864558745588455894559045591455924559345594455954559645597455984559945600456014560245603456044560545606456074560845609456104561145612456134561445615456164561745618456194562045621456224562345624456254562645627456284562945630456314563245633456344563545636456374563845639456404564145642456434564445645456464564745648456494565045651456524565345654456554565645657456584565945660456614566245663456644566545666456674566845669456704567145672456734567445675456764567745678456794568045681456824568345684456854568645687456884568945690456914569245693456944569545696456974569845699457004570145702457034570445705457064570745708457094571045711457124571345714457154571645717457184571945720457214572245723457244572545726457274572845729457304573145732457334573445735457364573745738457394574045741457424574345744457454574645747457484574945750457514575245753457544575545756457574575845759457604576145762457634576445765457664576745768457694577045771457724577345774457754577645777457784577945780457814578245783457844578545786457874578845789457904579145792457934579445795457964579745798457994580045801458024580345804458054580645807458084580945810458114581245813458144581545816458174581845819458204582145822458234582445825458264582745828458294583045831458324583345834458354583645837458384583945840458414584245843458444584545846458474584845849458504585145852458534585445855458564585745858458594586045861458624586345864458654586645867458684586945870458714587245873458744587545876458774587845879458804588145882458834588445885458864588745888458894589045891458924589345894458954589645897458984589945900459014590245903459044590545906459074590845909459104591145912459134591445915459164591745918459194592045921459224592345924459254592645927459284592945930459314593245933459344593545936459374593845939459404594145942459434594445945459464594745948459494595045951459524595345954459554595645957459584595945960459614596245963459644596545966459674596845969459704597145972459734597445975459764597745978459794598045981459824598345984459854598645987459884598945990459914599245993459944599545996459974599845999460004600146002460034600446005460064600746008460094601046011460124601346014460154601646017460184601946020460214602246023460244602546026460274602846029460304603146032460334603446035460364603746038460394604046041460424604346044460454604646047460484604946050460514605246053460544605546056460574605846059460604606146062460634606446065460664606746068460694607046071460724607346074460754607646077460784607946080460814608246083460844608546086460874608846089460904609146092460934609446095460964609746098460994610046101461024610346104461054610646107461084610946110461114611246113461144611546116461174611846119461204612146122461234612446125461264612746128461294613046131461324613346134461354613646137461384613946140461414614246143461444614546146461474614846149461504615146152461534615446155461564615746158461594616046161461624616346164461654616646167461684616946170461714617246173461744617546176461774617846179461804618146182461834618446185461864618746188461894619046191461924619346194461954619646197461984619946200462014620246203462044620546206462074620846209462104621146212462134621446215462164621746218462194622046221462224622346224462254622646227462284622946230462314623246233462344623546236462374623846239462404624146242462434624446245462464624746248462494625046251462524625346254462554625646257462584625946260462614626246263462644626546266462674626846269462704627146272462734627446275462764627746278462794628046281462824628346284462854628646287462884628946290462914629246293462944629546296462974629846299463004630146302463034630446305463064630746308463094631046311463124631346314463154631646317463184631946320463214632246323463244632546326463274632846329463304633146332463334633446335463364633746338463394634046341463424634346344463454634646347463484634946350463514635246353463544635546356463574635846359463604636146362463634636446365463664636746368463694637046371463724637346374463754637646377463784637946380463814638246383463844638546386463874638846389463904639146392463934639446395463964639746398463994640046401464024640346404464054640646407464084640946410464114641246413464144641546416464174641846419464204642146422464234642446425464264642746428464294643046431464324643346434464354643646437464384643946440464414644246443464444644546446464474644846449464504645146452464534645446455464564645746458464594646046461464624646346464464654646646467464684646946470464714647246473464744647546476464774647846479464804648146482464834648446485464864648746488464894649046491464924649346494464954649646497464984649946500465014650246503465044650546506465074650846509465104651146512465134651446515465164651746518465194652046521465224652346524465254652646527465284652946530465314653246533465344653546536465374653846539465404654146542465434654446545465464654746548465494655046551465524655346554465554655646557465584655946560465614656246563465644656546566465674656846569465704657146572465734657446575465764657746578465794658046581465824658346584465854658646587465884658946590465914659246593465944659546596465974659846599466004660146602466034660446605466064660746608466094661046611466124661346614466154661646617466184661946620466214662246623466244662546626466274662846629466304663146632466334663446635466364663746638466394664046641466424664346644466454664646647466484664946650466514665246653466544665546656466574665846659466604666146662466634666446665466664666746668466694667046671466724667346674466754667646677466784667946680466814668246683466844668546686466874668846689466904669146692466934669446695466964669746698466994670046701467024670346704467054670646707467084670946710467114671246713467144671546716467174671846719467204672146722467234672446725467264672746728467294673046731467324673346734467354673646737467384673946740467414674246743467444674546746467474674846749467504675146752467534675446755467564675746758467594676046761467624676346764467654676646767467684676946770467714677246773467744677546776467774677846779467804678146782467834678446785467864678746788467894679046791467924679346794467954679646797467984679946800468014680246803468044680546806468074680846809468104681146812468134681446815468164681746818468194682046821468224682346824468254682646827468284682946830468314683246833468344683546836468374683846839468404684146842468434684446845468464684746848468494685046851468524685346854468554685646857468584685946860468614686246863468644686546866468674686846869468704687146872468734687446875468764687746878468794688046881468824688346884468854688646887468884688946890468914689246893468944689546896468974689846899469004690146902469034690446905469064690746908469094691046911469124691346914469154691646917469184691946920469214692246923469244692546926469274692846929469304693146932469334693446935469364693746938469394694046941469424694346944469454694646947469484694946950469514695246953469544695546956469574695846959469604696146962469634696446965469664696746968469694697046971469724697346974469754697646977469784697946980469814698246983469844698546986469874698846989469904699146992469934699446995469964699746998469994700047001470024700347004470054700647007470084700947010470114701247013470144701547016470174701847019470204702147022470234702447025470264702747028470294703047031470324703347034470354703647037470384703947040470414704247043470444704547046470474704847049470504705147052470534705447055470564705747058470594706047061470624706347064470654706647067470684706947070470714707247073470744707547076470774707847079470804708147082470834708447085470864708747088470894709047091470924709347094470954709647097470984709947100471014710247103471044710547106471074710847109471104711147112471134711447115471164711747118471194712047121471224712347124471254712647127471284712947130471314713247133471344713547136471374713847139471404714147142471434714447145471464714747148471494715047151471524715347154471554715647157471584715947160471614716247163471644716547166471674716847169471704717147172471734717447175471764717747178471794718047181471824718347184471854718647187471884718947190471914719247193471944719547196471974719847199472004720147202472034720447205472064720747208472094721047211472124721347214472154721647217472184721947220472214722247223472244722547226472274722847229472304723147232472334723447235472364723747238472394724047241472424724347244472454724647247472484724947250472514725247253472544725547256472574725847259472604726147262472634726447265472664726747268472694727047271472724727347274472754727647277472784727947280472814728247283472844728547286472874728847289472904729147292472934729447295472964729747298472994730047301473024730347304473054730647307473084730947310473114731247313473144731547316473174731847319473204732147322473234732447325473264732747328473294733047331473324733347334473354733647337473384733947340473414734247343473444734547346473474734847349473504735147352473534735447355473564735747358473594736047361473624736347364473654736647367473684736947370473714737247373473744737547376473774737847379473804738147382473834738447385473864738747388473894739047391473924739347394473954739647397473984739947400474014740247403474044740547406474074740847409474104741147412474134741447415474164741747418474194742047421474224742347424474254742647427474284742947430474314743247433474344743547436474374743847439474404744147442474434744447445474464744747448474494745047451474524745347454474554745647457474584745947460474614746247463474644746547466474674746847469474704747147472474734747447475474764747747478474794748047481474824748347484474854748647487474884748947490474914749247493474944749547496474974749847499475004750147502475034750447505475064750747508475094751047511475124751347514475154751647517475184751947520475214752247523475244752547526475274752847529475304753147532475334753447535475364753747538475394754047541475424754347544475454754647547475484754947550475514755247553475544755547556475574755847559475604756147562475634756447565475664756747568475694757047571475724757347574475754757647577475784757947580475814758247583475844758547586475874758847589475904759147592475934759447595475964759747598475994760047601476024760347604476054760647607476084760947610476114761247613476144761547616476174761847619476204762147622476234762447625476264762747628476294763047631476324763347634476354763647637476384763947640476414764247643476444764547646476474764847649476504765147652476534765447655476564765747658476594766047661476624766347664476654766647667476684766947670476714767247673476744767547676476774767847679476804768147682476834768447685476864768747688476894769047691476924769347694476954769647697476984769947700477014770247703477044770547706477074770847709477104771147712477134771447715477164771747718477194772047721477224772347724477254772647727477284772947730477314773247733477344773547736477374773847739477404774147742477434774447745477464774747748477494775047751477524775347754477554775647757477584775947760477614776247763477644776547766477674776847769477704777147772477734777447775477764777747778477794778047781477824778347784477854778647787477884778947790477914779247793477944779547796477974779847799478004780147802478034780447805478064780747808478094781047811478124781347814478154781647817478184781947820478214782247823478244782547826478274782847829478304783147832478334783447835478364783747838478394784047841478424784347844478454784647847478484784947850478514785247853478544785547856478574785847859478604786147862478634786447865478664786747868478694787047871478724787347874478754787647877478784787947880478814788247883478844788547886478874788847889478904789147892478934789447895478964789747898478994790047901479024790347904479054790647907479084790947910479114791247913479144791547916479174791847919479204792147922479234792447925479264792747928479294793047931479324793347934479354793647937479384793947940479414794247943479444794547946479474794847949479504795147952479534795447955479564795747958479594796047961479624796347964479654796647967479684796947970479714797247973479744797547976479774797847979479804798147982479834798447985479864798747988479894799047991479924799347994479954799647997479984799948000480014800248003480044800548006480074800848009480104801148012480134801448015480164801748018480194802048021480224802348024480254802648027480284802948030480314803248033480344803548036480374803848039480404804148042480434804448045480464804748048480494805048051480524805348054480554805648057480584805948060480614806248063480644806548066480674806848069480704807148072480734807448075480764807748078480794808048081480824808348084480854808648087480884808948090480914809248093480944809548096480974809848099481004810148102481034810448105481064810748108481094811048111481124811348114481154811648117481184811948120481214812248123481244812548126481274812848129481304813148132481334813448135481364813748138481394814048141481424814348144481454814648147481484814948150481514815248153481544815548156481574815848159481604816148162481634816448165481664816748168481694817048171481724817348174481754817648177481784817948180481814818248183481844818548186481874818848189481904819148192481934819448195481964819748198481994820048201482024820348204482054820648207482084820948210482114821248213482144821548216482174821848219482204822148222482234822448225482264822748228482294823048231482324823348234482354823648237482384823948240482414824248243482444824548246482474824848249482504825148252482534825448255482564825748258482594826048261482624826348264482654826648267482684826948270482714827248273482744827548276482774827848279482804828148282482834828448285482864828748288482894829048291482924829348294482954829648297482984829948300483014830248303483044830548306483074830848309483104831148312483134831448315483164831748318483194832048321483224832348324483254832648327483284832948330483314833248333483344833548336483374833848339483404834148342483434834448345483464834748348483494835048351483524835348354483554835648357483584835948360483614836248363483644836548366483674836848369483704837148372483734837448375483764837748378483794838048381483824838348384483854838648387483884838948390483914839248393483944839548396483974839848399484004840148402484034840448405484064840748408484094841048411484124841348414484154841648417484184841948420484214842248423484244842548426484274842848429484304843148432484334843448435484364843748438484394844048441484424844348444484454844648447484484844948450484514845248453484544845548456484574845848459484604846148462484634846448465484664846748468484694847048471484724847348474484754847648477484784847948480484814848248483484844848548486484874848848489484904849148492484934849448495484964849748498484994850048501485024850348504485054850648507485084850948510485114851248513485144851548516485174851848519485204852148522485234852448525485264852748528485294853048531485324853348534485354853648537485384853948540485414854248543485444854548546485474854848549485504855148552485534855448555485564855748558485594856048561485624856348564485654856648567485684856948570485714857248573485744857548576485774857848579485804858148582485834858448585485864858748588485894859048591485924859348594485954859648597485984859948600486014860248603486044860548606486074860848609486104861148612486134861448615486164861748618486194862048621486224862348624486254862648627486284862948630486314863248633486344863548636486374863848639486404864148642486434864448645486464864748648486494865048651486524865348654486554865648657486584865948660486614866248663486644866548666486674866848669486704867148672486734867448675486764867748678486794868048681486824868348684486854868648687486884868948690486914869248693486944869548696486974869848699487004870148702487034870448705487064870748708487094871048711487124871348714487154871648717487184871948720487214872248723487244872548726487274872848729487304873148732487334873448735487364873748738487394874048741487424874348744487454874648747487484874948750487514875248753487544875548756487574875848759487604876148762487634876448765487664876748768487694877048771487724877348774487754877648777487784877948780487814878248783487844878548786487874878848789487904879148792487934879448795487964879748798487994880048801488024880348804488054880648807488084880948810488114881248813488144881548816488174881848819488204882148822488234882448825488264882748828488294883048831488324883348834488354883648837488384883948840488414884248843488444884548846488474884848849488504885148852488534885448855488564885748858488594886048861488624886348864488654886648867488684886948870488714887248873488744887548876488774887848879488804888148882488834888448885488864888748888488894889048891488924889348894488954889648897488984889948900489014890248903489044890548906489074890848909489104891148912489134891448915489164891748918489194892048921489224892348924489254892648927489284892948930489314893248933489344893548936489374893848939489404894148942489434894448945489464894748948489494895048951489524895348954489554895648957489584895948960489614896248963489644896548966489674896848969489704897148972489734897448975489764897748978489794898048981489824898348984489854898648987489884898948990489914899248993489944899548996489974899848999490004900149002490034900449005490064900749008490094901049011490124901349014490154901649017490184901949020490214902249023490244902549026490274902849029490304903149032490334903449035490364903749038490394904049041490424904349044490454904649047490484904949050490514905249053490544905549056490574905849059490604906149062490634906449065490664906749068490694907049071490724907349074490754907649077490784907949080490814908249083490844908549086490874908849089490904909149092490934909449095490964909749098490994910049101491024910349104491054910649107491084910949110491114911249113491144911549116491174911849119491204912149122491234912449125491264912749128491294913049131491324913349134491354913649137491384913949140491414914249143491444914549146491474914849149491504915149152491534915449155491564915749158491594916049161491624916349164491654916649167491684916949170491714917249173491744917549176491774917849179491804918149182491834918449185491864918749188491894919049191491924919349194491954919649197491984919949200492014920249203492044920549206492074920849209492104921149212492134921449215492164921749218492194922049221492224922349224492254922649227492284922949230492314923249233492344923549236492374923849239492404924149242492434924449245492464924749248492494925049251492524925349254492554925649257492584925949260492614926249263492644926549266492674926849269492704927149272492734927449275492764927749278492794928049281492824928349284492854928649287492884928949290492914929249293492944929549296492974929849299493004930149302493034930449305493064930749308493094931049311493124931349314493154931649317493184931949320493214932249323493244932549326493274932849329493304933149332493334933449335493364933749338493394934049341493424934349344493454934649347493484934949350493514935249353493544935549356493574935849359493604936149362493634936449365493664936749368493694937049371493724937349374493754937649377493784937949380493814938249383493844938549386493874938849389493904939149392493934939449395493964939749398493994940049401494024940349404494054940649407494084940949410494114941249413494144941549416494174941849419494204942149422494234942449425494264942749428494294943049431494324943349434494354943649437494384943949440494414944249443494444944549446494474944849449494504945149452494534945449455494564945749458494594946049461494624946349464494654946649467494684946949470494714947249473494744947549476494774947849479494804948149482494834948449485494864948749488494894949049491494924949349494494954949649497494984949949500495014950249503495044950549506495074950849509495104951149512495134951449515495164951749518495194952049521495224952349524495254952649527495284952949530495314953249533495344953549536495374953849539495404954149542495434954449545495464954749548495494955049551495524955349554495554955649557495584955949560495614956249563495644956549566495674956849569495704957149572495734957449575495764957749578495794958049581495824958349584495854958649587495884958949590495914959249593495944959549596495974959849599496004960149602496034960449605496064960749608496094961049611496124961349614496154961649617496184961949620496214962249623496244962549626496274962849629496304963149632496334963449635496364963749638496394964049641496424964349644496454964649647496484964949650496514965249653496544965549656496574965849659496604966149662496634966449665496664966749668496694967049671496724967349674496754967649677496784967949680496814968249683496844968549686496874968849689496904969149692496934969449695496964969749698496994970049701497024970349704497054970649707497084970949710497114971249713497144971549716497174971849719497204972149722497234972449725497264972749728497294973049731497324973349734497354973649737497384973949740497414974249743497444974549746497474974849749497504975149752497534975449755497564975749758497594976049761497624976349764497654976649767497684976949770497714977249773497744977549776497774977849779497804978149782497834978449785497864978749788497894979049791497924979349794497954979649797497984979949800498014980249803498044980549806498074980849809498104981149812498134981449815498164981749818498194982049821498224982349824498254982649827498284982949830498314983249833498344983549836498374983849839498404984149842498434984449845498464984749848498494985049851498524985349854498554985649857498584985949860498614986249863498644986549866498674986849869498704987149872498734987449875498764987749878498794988049881498824988349884498854988649887498884988949890498914989249893498944989549896498974989849899499004990149902499034990449905499064990749908499094991049911499124991349914499154991649917499184991949920499214992249923499244992549926499274992849929499304993149932499334993449935499364993749938499394994049941499424994349944499454994649947499484994949950499514995249953499544995549956499574995849959499604996149962499634996449965499664996749968499694997049971499724997349974499754997649977499784997949980499814998249983499844998549986499874998849989499904999149992499934999449995499964999749998499995000050001500025000350004500055000650007500085000950010500115001250013500145001550016500175001850019500205002150022500235002450025500265002750028500295003050031500325003350034500355003650037500385003950040500415004250043500445004550046500475004850049500505005150052500535005450055500565005750058500595006050061500625006350064500655006650067500685006950070500715007250073500745007550076500775007850079500805008150082500835008450085500865008750088500895009050091500925009350094500955009650097500985009950100501015010250103501045010550106501075010850109501105011150112501135011450115501165011750118501195012050121501225012350124501255012650127501285012950130501315013250133501345013550136501375013850139501405014150142501435014450145501465014750148501495015050151501525015350154501555015650157501585015950160501615016250163501645016550166501675016850169501705017150172501735017450175501765017750178501795018050181501825018350184501855018650187501885018950190501915019250193501945019550196501975019850199502005020150202502035020450205502065020750208502095021050211502125021350214502155021650217502185021950220502215022250223502245022550226502275022850229502305023150232502335023450235502365023750238502395024050241502425024350244502455024650247502485024950250502515025250253502545025550256502575025850259502605026150262502635026450265502665026750268502695027050271502725027350274502755027650277502785027950280502815028250283502845028550286502875028850289502905029150292502935029450295502965029750298502995030050301503025030350304503055030650307503085030950310503115031250313503145031550316503175031850319503205032150322503235032450325503265032750328503295033050331503325033350334503355033650337503385033950340503415034250343503445034550346503475034850349503505035150352503535035450355503565035750358503595036050361503625036350364503655036650367503685036950370503715037250373503745037550376503775037850379503805038150382503835038450385503865038750388503895039050391503925039350394503955039650397503985039950400504015040250403504045040550406504075040850409504105041150412504135041450415504165041750418504195042050421504225042350424504255042650427504285042950430504315043250433504345043550436504375043850439504405044150442504435044450445504465044750448504495045050451504525045350454504555045650457504585045950460504615046250463504645046550466504675046850469504705047150472504735047450475504765047750478504795048050481504825048350484504855048650487504885048950490504915049250493504945049550496504975049850499505005050150502505035050450505505065050750508505095051050511505125051350514505155051650517505185051950520505215052250523505245052550526505275052850529505305053150532505335053450535505365053750538505395054050541505425054350544505455054650547505485054950550505515055250553505545055550556505575055850559505605056150562505635056450565505665056750568505695057050571505725057350574505755057650577505785057950580505815058250583505845058550586505875058850589505905059150592505935059450595505965059750598505995060050601506025060350604506055060650607506085060950610506115061250613506145061550616506175061850619506205062150622506235062450625506265062750628506295063050631506325063350634506355063650637506385063950640506415064250643506445064550646506475064850649506505065150652506535065450655506565065750658506595066050661506625066350664506655066650667506685066950670506715067250673506745067550676506775067850679506805068150682506835068450685506865068750688506895069050691506925069350694506955069650697506985069950700507015070250703507045070550706507075070850709507105071150712507135071450715507165071750718507195072050721507225072350724507255072650727507285072950730507315073250733507345073550736507375073850739507405074150742507435074450745507465074750748507495075050751507525075350754507555075650757507585075950760507615076250763507645076550766507675076850769507705077150772507735077450775507765077750778507795078050781507825078350784507855078650787507885078950790507915079250793507945079550796507975079850799508005080150802508035080450805508065080750808508095081050811508125081350814508155081650817508185081950820508215082250823508245082550826508275082850829508305083150832508335083450835508365083750838508395084050841508425084350844508455084650847508485084950850508515085250853508545085550856508575085850859508605086150862508635086450865508665086750868508695087050871508725087350874508755087650877508785087950880508815088250883508845088550886508875088850889508905089150892508935089450895508965089750898508995090050901509025090350904509055090650907509085090950910509115091250913509145091550916509175091850919509205092150922509235092450925509265092750928509295093050931509325093350934509355093650937509385093950940509415094250943509445094550946509475094850949509505095150952509535095450955509565095750958509595096050961509625096350964509655096650967509685096950970509715097250973509745097550976509775097850979509805098150982509835098450985509865098750988509895099050991509925099350994509955099650997509985099951000510015100251003510045100551006510075100851009510105101151012510135101451015510165101751018510195102051021510225102351024510255102651027510285102951030510315103251033510345103551036510375103851039510405104151042510435104451045510465104751048510495105051051510525105351054510555105651057510585105951060510615106251063510645106551066510675106851069510705107151072510735107451075510765107751078510795108051081510825108351084510855108651087510885108951090510915109251093510945109551096510975109851099511005110151102511035110451105511065110751108511095111051111511125111351114511155111651117511185111951120511215112251123511245112551126511275112851129511305113151132511335113451135511365113751138511395114051141511425114351144511455114651147511485114951150511515115251153511545115551156511575115851159511605116151162511635116451165511665116751168511695117051171511725117351174511755117651177511785117951180511815118251183511845118551186511875118851189511905119151192511935119451195511965119751198511995120051201512025120351204512055120651207512085120951210512115121251213512145121551216512175121851219512205122151222512235122451225512265122751228512295123051231512325123351234512355123651237512385123951240512415124251243512445124551246512475124851249512505125151252512535125451255512565125751258512595126051261512625126351264512655126651267512685126951270512715127251273512745127551276512775127851279512805128151282512835128451285512865128751288512895129051291512925129351294512955129651297512985129951300513015130251303513045130551306513075130851309513105131151312513135131451315513165131751318513195132051321513225132351324513255132651327513285132951330513315133251333513345133551336513375133851339513405134151342513435134451345513465134751348513495135051351513525135351354513555135651357513585135951360513615136251363513645136551366513675136851369513705137151372513735137451375513765137751378513795138051381513825138351384513855138651387513885138951390513915139251393513945139551396513975139851399514005140151402514035140451405514065140751408514095141051411514125141351414514155141651417514185141951420514215142251423514245142551426514275142851429514305143151432514335143451435514365143751438514395144051441514425144351444514455144651447514485144951450514515145251453514545145551456514575145851459514605146151462514635146451465514665146751468514695147051471514725147351474514755147651477514785147951480514815148251483514845148551486514875148851489514905149151492514935149451495514965149751498514995150051501515025150351504515055150651507515085150951510515115151251513515145151551516515175151851519515205152151522515235152451525515265152751528515295153051531515325153351534515355153651537515385153951540515415154251543515445154551546515475154851549515505155151552515535155451555515565155751558515595156051561515625156351564515655156651567515685156951570515715157251573515745157551576515775157851579515805158151582515835158451585515865158751588515895159051591515925159351594515955159651597515985159951600516015160251603516045160551606516075160851609516105161151612516135161451615516165161751618516195162051621516225162351624516255162651627516285162951630516315163251633516345163551636516375163851639516405164151642516435164451645516465164751648516495165051651516525165351654516555165651657516585165951660516615166251663516645166551666516675166851669516705167151672516735167451675516765167751678516795168051681516825168351684516855168651687516885168951690516915169251693516945169551696516975169851699517005170151702517035170451705517065170751708517095171051711517125171351714517155171651717517185171951720517215172251723517245172551726517275172851729517305173151732517335173451735517365173751738517395174051741517425174351744517455174651747517485174951750517515175251753517545175551756517575175851759517605176151762517635176451765517665176751768517695177051771517725177351774517755177651777517785177951780517815178251783517845178551786517875178851789517905179151792517935179451795517965179751798517995180051801518025180351804518055180651807518085180951810518115181251813518145181551816518175181851819518205182151822518235182451825518265182751828518295183051831518325183351834518355183651837518385183951840518415184251843518445184551846518475184851849518505185151852518535185451855518565185751858518595186051861518625186351864518655186651867518685186951870518715187251873518745187551876518775187851879518805188151882518835188451885518865188751888518895189051891518925189351894518955189651897518985189951900519015190251903519045190551906519075190851909519105191151912519135191451915519165191751918519195192051921519225192351924519255192651927519285192951930519315193251933519345193551936519375193851939519405194151942519435194451945519465194751948519495195051951519525195351954519555195651957519585195951960519615196251963519645196551966519675196851969519705197151972519735197451975519765197751978519795198051981519825198351984519855198651987519885198951990519915199251993519945199551996519975199851999520005200152002520035200452005520065200752008520095201052011520125201352014520155201652017520185201952020520215202252023520245202552026520275202852029520305203152032520335203452035520365203752038520395204052041520425204352044520455204652047520485204952050520515205252053520545205552056520575205852059520605206152062520635206452065520665206752068520695207052071520725207352074520755207652077520785207952080520815208252083520845208552086520875208852089520905209152092520935209452095520965209752098520995210052101521025210352104521055210652107521085210952110521115211252113521145211552116521175211852119521205212152122521235212452125521265212752128521295213052131521325213352134521355213652137521385213952140521415214252143521445214552146521475214852149521505215152152521535215452155521565215752158521595216052161521625216352164521655216652167521685216952170521715217252173521745217552176521775217852179521805218152182521835218452185521865218752188521895219052191521925219352194521955219652197521985219952200522015220252203522045220552206522075220852209522105221152212522135221452215522165221752218522195222052221522225222352224522255222652227522285222952230522315223252233522345223552236522375223852239522405224152242522435224452245522465224752248522495225052251522525225352254522555225652257522585225952260522615226252263522645226552266522675226852269522705227152272522735227452275522765227752278522795228052281522825228352284522855228652287522885228952290522915229252293522945229552296522975229852299523005230152302523035230452305523065230752308523095231052311523125231352314523155231652317523185231952320523215232252323523245232552326523275232852329523305233152332523335233452335523365233752338523395234052341523425234352344523455234652347523485234952350523515235252353523545235552356523575235852359523605236152362523635236452365523665236752368523695237052371523725237352374523755237652377523785237952380523815238252383523845238552386523875238852389523905239152392523935239452395523965239752398523995240052401524025240352404524055240652407524085240952410524115241252413524145241552416524175241852419524205242152422524235242452425524265242752428524295243052431524325243352434524355243652437524385243952440524415244252443524445244552446524475244852449524505245152452524535245452455524565245752458524595246052461524625246352464524655246652467524685246952470524715247252473524745247552476524775247852479524805248152482524835248452485524865248752488524895249052491524925249352494524955249652497524985249952500525015250252503525045250552506525075250852509525105251152512525135251452515525165251752518525195252052521525225252352524525255252652527525285252952530525315253252533525345253552536525375253852539525405254152542525435254452545525465254752548525495255052551525525255352554525555255652557525585255952560525615256252563525645256552566525675256852569525705257152572525735257452575525765257752578525795258052581525825258352584525855258652587525885258952590525915259252593525945259552596525975259852599526005260152602526035260452605526065260752608526095261052611526125261352614526155261652617526185261952620526215262252623526245262552626526275262852629526305263152632526335263452635526365263752638526395264052641526425264352644526455264652647526485264952650526515265252653526545265552656526575265852659526605266152662526635266452665526665266752668526695267052671526725267352674526755267652677526785267952680526815268252683526845268552686526875268852689526905269152692526935269452695526965269752698526995270052701527025270352704527055270652707527085270952710527115271252713527145271552716527175271852719527205272152722527235272452725527265272752728527295273052731527325273352734527355273652737527385273952740527415274252743527445274552746527475274852749527505275152752527535275452755527565275752758527595276052761527625276352764527655276652767527685276952770527715277252773527745277552776527775277852779527805278152782527835278452785527865278752788527895279052791527925279352794527955279652797527985279952800528015280252803528045280552806528075280852809528105281152812528135281452815528165281752818528195282052821528225282352824528255282652827528285282952830528315283252833528345283552836528375283852839528405284152842528435284452845528465284752848528495285052851528525285352854528555285652857528585285952860528615286252863528645286552866528675286852869528705287152872528735287452875528765287752878528795288052881528825288352884528855288652887528885288952890528915289252893528945289552896528975289852899529005290152902529035290452905529065290752908529095291052911529125291352914529155291652917529185291952920529215292252923529245292552926529275292852929529305293152932529335293452935529365293752938529395294052941529425294352944529455294652947529485294952950529515295252953529545295552956529575295852959529605296152962529635296452965529665296752968529695297052971529725297352974529755297652977529785297952980529815298252983529845298552986529875298852989529905299152992529935299452995529965299752998529995300053001530025300353004530055300653007530085300953010530115301253013530145301553016530175301853019530205302153022530235302453025530265302753028530295303053031530325303353034530355303653037530385303953040530415304253043530445304553046530475304853049530505305153052530535305453055530565305753058530595306053061530625306353064530655306653067530685306953070530715307253073530745307553076530775307853079530805308153082530835308453085530865308753088530895309053091530925309353094530955309653097530985309953100531015310253103531045310553106531075310853109531105311153112531135311453115531165311753118531195312053121531225312353124531255312653127531285312953130531315313253133531345313553136531375313853139531405314153142531435314453145531465314753148531495315053151531525315353154531555315653157531585315953160531615316253163531645316553166531675316853169531705317153172531735317453175531765317753178531795318053181531825318353184531855318653187531885318953190531915319253193531945319553196531975319853199532005320153202532035320453205532065320753208532095321053211532125321353214532155321653217532185321953220532215322253223532245322553226532275322853229532305323153232532335323453235532365323753238532395324053241532425324353244532455324653247532485324953250532515325253253532545325553256532575325853259532605326153262532635326453265532665326753268532695327053271532725327353274532755327653277532785327953280532815328253283532845328553286532875328853289532905329153292532935329453295532965329753298532995330053301533025330353304533055330653307533085330953310533115331253313533145331553316533175331853319533205332153322533235332453325533265332753328533295333053331533325333353334533355333653337533385333953340533415334253343533445334553346533475334853349533505335153352533535335453355533565335753358533595336053361533625336353364533655336653367533685336953370533715337253373533745337553376533775337853379533805338153382533835338453385533865338753388533895339053391533925339353394533955339653397533985339953400534015340253403534045340553406534075340853409534105341153412534135341453415534165341753418534195342053421534225342353424534255342653427534285342953430534315343253433534345343553436534375343853439534405344153442534435344453445534465344753448534495345053451534525345353454534555345653457534585345953460534615346253463534645346553466534675346853469534705347153472534735347453475534765347753478534795348053481534825348353484534855348653487534885348953490534915349253493534945349553496534975349853499535005350153502535035350453505535065350753508535095351053511535125351353514535155351653517535185351953520535215352253523535245352553526535275352853529535305353153532535335353453535535365353753538535395354053541535425354353544535455354653547535485354953550535515355253553535545355553556535575355853559535605356153562535635356453565535665356753568535695357053571535725357353574535755357653577535785357953580535815358253583535845358553586535875358853589535905359153592535935359453595535965359753598535995360053601536025360353604536055360653607536085360953610536115361253613536145361553616536175361853619536205362153622536235362453625536265362753628536295363053631536325363353634536355363653637536385363953640536415364253643536445364553646536475364853649536505365153652536535365453655536565365753658536595366053661536625366353664536655366653667536685366953670536715367253673536745367553676536775367853679536805368153682536835368453685536865368753688536895369053691536925369353694536955369653697536985369953700537015370253703537045370553706537075370853709537105371153712537135371453715537165371753718537195372053721537225372353724537255372653727537285372953730537315373253733537345373553736537375373853739537405374153742537435374453745537465374753748537495375053751537525375353754537555375653757537585375953760537615376253763537645376553766537675376853769537705377153772537735377453775537765377753778537795378053781537825378353784537855378653787537885378953790537915379253793537945379553796537975379853799538005380153802538035380453805538065380753808538095381053811538125381353814538155381653817538185381953820538215382253823538245382553826538275382853829538305383153832538335383453835538365383753838538395384053841538425384353844538455384653847538485384953850538515385253853538545385553856538575385853859538605386153862538635386453865538665386753868538695387053871538725387353874538755387653877538785387953880538815388253883538845388553886538875388853889538905389153892538935389453895538965389753898538995390053901539025390353904539055390653907539085390953910539115391253913539145391553916539175391853919539205392153922539235392453925539265392753928539295393053931539325393353934539355393653937539385393953940539415394253943539445394553946539475394853949539505395153952539535395453955539565395753958539595396053961539625396353964539655396653967539685396953970539715397253973539745397553976539775397853979539805398153982539835398453985539865398753988539895399053991539925399353994539955399653997539985399954000540015400254003540045400554006540075400854009540105401154012540135401454015540165401754018540195402054021540225402354024540255402654027540285402954030540315403254033540345403554036540375403854039540405404154042540435404454045540465404754048540495405054051540525405354054540555405654057540585405954060540615406254063540645406554066540675406854069540705407154072540735407454075540765407754078540795408054081540825408354084540855408654087540885408954090540915409254093540945409554096540975409854099541005410154102541035410454105541065410754108541095411054111541125411354114541155411654117541185411954120541215412254123541245412554126541275412854129541305413154132541335413454135541365413754138541395414054141541425414354144541455414654147541485414954150541515415254153541545415554156541575415854159541605416154162541635416454165541665416754168541695417054171541725417354174541755417654177541785417954180541815418254183541845418554186541875418854189541905419154192541935419454195541965419754198541995420054201542025420354204542055420654207542085420954210542115421254213542145421554216542175421854219542205422154222542235422454225542265422754228542295423054231542325423354234542355423654237542385423954240542415424254243542445424554246542475424854249542505425154252542535425454255542565425754258542595426054261542625426354264542655426654267542685426954270542715427254273542745427554276542775427854279542805428154282542835428454285542865428754288542895429054291542925429354294542955429654297542985429954300543015430254303543045430554306543075430854309543105431154312543135431454315543165431754318543195432054321543225432354324543255432654327543285432954330543315433254333543345433554336543375433854339543405434154342543435434454345543465434754348543495435054351543525435354354543555435654357543585435954360543615436254363543645436554366543675436854369543705437154372543735437454375543765437754378543795438054381543825438354384543855438654387543885438954390543915439254393543945439554396543975439854399544005440154402544035440454405544065440754408544095441054411544125441354414544155441654417544185441954420544215442254423544245442554426544275442854429544305443154432544335443454435544365443754438544395444054441544425444354444544455444654447544485444954450544515445254453544545445554456544575445854459544605446154462544635446454465544665446754468544695447054471544725447354474544755447654477544785447954480544815448254483544845448554486544875448854489544905449154492544935449454495544965449754498544995450054501545025450354504545055450654507545085450954510545115451254513545145451554516545175451854519545205452154522545235452454525545265452754528545295453054531545325453354534545355453654537545385453954540545415454254543545445454554546545475454854549545505455154552545535455454555545565455754558545595456054561545625456354564545655456654567545685456954570545715457254573545745457554576545775457854579545805458154582545835458454585545865458754588545895459054591545925459354594545955459654597545985459954600546015460254603546045460554606546075460854609546105461154612546135461454615546165461754618546195462054621546225462354624546255462654627546285462954630546315463254633546345463554636546375463854639546405464154642546435464454645546465464754648546495465054651546525465354654546555465654657546585465954660546615466254663546645466554666546675466854669546705467154672546735467454675546765467754678546795468054681546825468354684546855468654687546885468954690546915469254693546945469554696546975469854699547005470154702547035470454705547065470754708547095471054711547125471354714547155471654717547185471954720547215472254723547245472554726547275472854729547305473154732547335473454735547365473754738547395474054741547425474354744547455474654747547485474954750547515475254753547545475554756547575475854759547605476154762547635476454765547665476754768547695477054771547725477354774547755477654777547785477954780547815478254783547845478554786547875478854789547905479154792547935479454795547965479754798547995480054801548025480354804548055480654807548085480954810548115481254813548145481554816548175481854819548205482154822548235482454825548265482754828548295483054831548325483354834548355483654837548385483954840548415484254843548445484554846548475484854849548505485154852548535485454855548565485754858548595486054861548625486354864548655486654867548685486954870548715487254873548745487554876548775487854879548805488154882548835488454885548865488754888548895489054891548925489354894548955489654897548985489954900549015490254903549045490554906549075490854909549105491154912549135491454915549165491754918549195492054921549225492354924549255492654927549285492954930549315493254933549345493554936549375493854939549405494154942549435494454945549465494754948549495495054951549525495354954549555495654957549585495954960549615496254963549645496554966549675496854969549705497154972549735497454975549765497754978549795498054981549825498354984549855498654987549885498954990549915499254993549945499554996549975499854999550005500155002550035500455005550065500755008550095501055011550125501355014550155501655017550185501955020550215502255023550245502555026550275502855029550305503155032550335503455035550365503755038550395504055041550425504355044550455504655047550485504955050550515505255053550545505555056550575505855059550605506155062550635506455065550665506755068550695507055071550725507355074550755507655077550785507955080550815508255083550845508555086550875508855089550905509155092550935509455095550965509755098550995510055101551025510355104551055510655107551085510955110551115511255113551145511555116551175511855119551205512155122551235512455125551265512755128551295513055131551325513355134551355513655137551385513955140551415514255143551445514555146551475514855149551505515155152551535515455155551565515755158551595516055161551625516355164551655516655167551685516955170551715517255173551745517555176551775517855179551805518155182551835518455185551865518755188551895519055191551925519355194551955519655197551985519955200552015520255203552045520555206552075520855209552105521155212552135521455215552165521755218552195522055221552225522355224552255522655227552285522955230552315523255233552345523555236552375523855239552405524155242552435524455245552465524755248552495525055251552525525355254552555525655257552585525955260552615526255263552645526555266552675526855269552705527155272552735527455275552765527755278552795528055281552825528355284552855528655287552885528955290552915529255293552945529555296552975529855299553005530155302553035530455305553065530755308553095531055311553125531355314553155531655317553185531955320553215532255323553245532555326553275532855329553305533155332553335533455335553365533755338553395534055341553425534355344553455534655347553485534955350553515535255353553545535555356553575535855359553605536155362553635536455365553665536755368553695537055371553725537355374553755537655377553785537955380553815538255383553845538555386553875538855389553905539155392553935539455395553965539755398553995540055401554025540355404554055540655407554085540955410554115541255413554145541555416554175541855419554205542155422554235542455425554265542755428554295543055431554325543355434554355543655437554385543955440554415544255443554445544555446554475544855449554505545155452554535545455455554565545755458554595546055461554625546355464554655546655467554685546955470554715547255473554745547555476554775547855479554805548155482554835548455485554865548755488554895549055491554925549355494554955549655497554985549955500555015550255503555045550555506555075550855509555105551155512555135551455515555165551755518555195552055521555225552355524555255552655527555285552955530555315553255533555345553555536555375553855539555405554155542555435554455545555465554755548555495555055551555525555355554555555555655557555585555955560555615556255563555645556555566555675556855569555705557155572555735557455575555765557755578555795558055581555825558355584555855558655587555885558955590555915559255593555945559555596555975559855599556005560155602556035560455605556065560755608556095561055611556125561355614556155561655617556185561955620556215562255623556245562555626556275562855629556305563155632556335563455635556365563755638556395564055641556425564355644556455564655647556485564955650556515565255653556545565555656556575565855659556605566155662556635566455665556665566755668556695567055671556725567355674556755567655677556785567955680556815568255683556845568555686556875568855689556905569155692556935569455695556965569755698556995570055701557025570355704557055570655707557085570955710557115571255713557145571555716557175571855719557205572155722557235572455725557265572755728557295573055731557325573355734557355573655737557385573955740557415574255743557445574555746557475574855749557505575155752557535575455755557565575755758557595576055761557625576355764557655576655767557685576955770557715577255773557745577555776557775577855779557805578155782557835578455785557865578755788557895579055791557925579355794557955579655797557985579955800558015580255803558045580555806558075580855809558105581155812558135581455815558165581755818558195582055821558225582355824558255582655827558285582955830558315583255833558345583555836558375583855839558405584155842558435584455845558465584755848558495585055851558525585355854558555585655857558585585955860558615586255863558645586555866558675586855869558705587155872558735587455875558765587755878558795588055881558825588355884558855588655887558885588955890558915589255893558945589555896558975589855899559005590155902559035590455905559065590755908559095591055911559125591355914559155591655917559185591955920559215592255923559245592555926559275592855929559305593155932559335593455935559365593755938559395594055941559425594355944559455594655947559485594955950559515595255953559545595555956559575595855959559605596155962559635596455965559665596755968559695597055971559725597355974559755597655977559785597955980559815598255983559845598555986559875598855989559905599155992559935599455995559965599755998559995600056001560025600356004560055600656007560085600956010560115601256013560145601556016560175601856019560205602156022560235602456025560265602756028560295603056031560325603356034560355603656037560385603956040560415604256043560445604556046560475604856049560505605156052560535605456055560565605756058560595606056061560625606356064560655606656067560685606956070560715607256073560745607556076560775607856079560805608156082560835608456085560865608756088560895609056091560925609356094560955609656097560985609956100561015610256103561045610556106561075610856109561105611156112561135611456115561165611756118561195612056121561225612356124561255612656127561285612956130561315613256133561345613556136561375613856139561405614156142561435614456145561465614756148561495615056151561525615356154561555615656157561585615956160561615616256163561645616556166561675616856169561705617156172561735617456175561765617756178561795618056181561825618356184561855618656187561885618956190561915619256193561945619556196561975619856199562005620156202562035620456205562065620756208562095621056211562125621356214562155621656217562185621956220562215622256223562245622556226562275622856229562305623156232562335623456235562365623756238562395624056241562425624356244562455624656247562485624956250562515625256253562545625556256562575625856259562605626156262562635626456265562665626756268562695627056271562725627356274562755627656277562785627956280562815628256283562845628556286562875628856289562905629156292562935629456295562965629756298562995630056301563025630356304563055630656307563085630956310563115631256313563145631556316563175631856319563205632156322563235632456325563265632756328563295633056331563325633356334563355633656337563385633956340563415634256343563445634556346563475634856349563505635156352563535635456355563565635756358563595636056361563625636356364563655636656367563685636956370563715637256373563745637556376563775637856379563805638156382563835638456385563865638756388563895639056391563925639356394563955639656397563985639956400564015640256403564045640556406564075640856409564105641156412564135641456415564165641756418564195642056421564225642356424564255642656427564285642956430564315643256433564345643556436564375643856439564405644156442564435644456445564465644756448564495645056451564525645356454564555645656457564585645956460564615646256463564645646556466564675646856469564705647156472564735647456475564765647756478564795648056481564825648356484564855648656487564885648956490564915649256493564945649556496564975649856499565005650156502565035650456505565065650756508565095651056511565125651356514565155651656517565185651956520565215652256523565245652556526565275652856529565305653156532565335653456535565365653756538565395654056541565425654356544565455654656547565485654956550565515655256553565545655556556565575655856559565605656156562565635656456565565665656756568565695657056571565725657356574565755657656577565785657956580565815658256583565845658556586565875658856589565905659156592565935659456595565965659756598565995660056601566025660356604566055660656607566085660956610566115661256613566145661556616566175661856619566205662156622566235662456625566265662756628566295663056631566325663356634566355663656637566385663956640566415664256643566445664556646566475664856649566505665156652566535665456655566565665756658566595666056661566625666356664566655666656667566685666956670566715667256673566745667556676566775667856679566805668156682566835668456685566865668756688566895669056691566925669356694566955669656697566985669956700567015670256703567045670556706567075670856709567105671156712567135671456715567165671756718567195672056721567225672356724567255672656727567285672956730567315673256733567345673556736567375673856739567405674156742567435674456745567465674756748567495675056751567525675356754567555675656757567585675956760567615676256763567645676556766567675676856769567705677156772567735677456775567765677756778567795678056781567825678356784567855678656787567885678956790567915679256793567945679556796567975679856799568005680156802568035680456805568065680756808568095681056811568125681356814568155681656817568185681956820568215682256823568245682556826568275682856829568305683156832568335683456835568365683756838568395684056841568425684356844568455684656847568485684956850568515685256853568545685556856568575685856859568605686156862568635686456865568665686756868568695687056871568725687356874568755687656877568785687956880568815688256883568845688556886568875688856889568905689156892568935689456895568965689756898568995690056901569025690356904569055690656907569085690956910569115691256913569145691556916569175691856919569205692156922569235692456925569265692756928569295693056931569325693356934569355693656937569385693956940569415694256943569445694556946569475694856949569505695156952569535695456955569565695756958569595696056961569625696356964569655696656967569685696956970569715697256973569745697556976569775697856979569805698156982569835698456985569865698756988569895699056991569925699356994569955699656997569985699957000570015700257003570045700557006570075700857009570105701157012570135701457015570165701757018570195702057021570225702357024570255702657027570285702957030570315703257033570345703557036570375703857039570405704157042570435704457045570465704757048570495705057051570525705357054570555705657057570585705957060570615706257063570645706557066570675706857069570705707157072570735707457075570765707757078570795708057081570825708357084570855708657087570885708957090570915709257093570945709557096570975709857099571005710157102571035710457105571065710757108571095711057111571125711357114571155711657117571185711957120571215712257123571245712557126571275712857129571305713157132571335713457135571365713757138571395714057141571425714357144571455714657147571485714957150571515715257153571545715557156571575715857159571605716157162571635716457165571665716757168571695717057171571725717357174571755717657177571785717957180571815718257183571845718557186571875718857189571905719157192571935719457195571965719757198571995720057201572025720357204572055720657207572085720957210572115721257213572145721557216572175721857219572205722157222572235722457225572265722757228572295723057231572325723357234572355723657237572385723957240572415724257243572445724557246572475724857249572505725157252572535725457255572565725757258572595726057261572625726357264572655726657267572685726957270572715727257273572745727557276572775727857279572805728157282572835728457285572865728757288572895729057291572925729357294572955729657297572985729957300573015730257303573045730557306573075730857309573105731157312573135731457315573165731757318573195732057321573225732357324573255732657327573285732957330573315733257333573345733557336573375733857339573405734157342573435734457345573465734757348573495735057351573525735357354573555735657357573585735957360573615736257363573645736557366573675736857369573705737157372573735737457375573765737757378573795738057381573825738357384573855738657387573885738957390573915739257393573945739557396573975739857399574005740157402574035740457405574065740757408574095741057411574125741357414574155741657417574185741957420574215742257423574245742557426574275742857429574305743157432574335743457435574365743757438574395744057441574425744357444574455744657447574485744957450574515745257453574545745557456574575745857459574605746157462574635746457465574665746757468574695747057471574725747357474574755747657477574785747957480574815748257483574845748557486574875748857489574905749157492574935749457495574965749757498574995750057501575025750357504575055750657507575085750957510575115751257513575145751557516575175751857519575205752157522575235752457525575265752757528575295753057531575325753357534575355753657537575385753957540575415754257543575445754557546575475754857549575505755157552575535755457555575565755757558575595756057561575625756357564575655756657567575685756957570575715757257573575745757557576575775757857579575805758157582575835758457585575865758757588575895759057591575925759357594575955759657597575985759957600576015760257603576045760557606576075760857609576105761157612576135761457615576165761757618576195762057621576225762357624576255762657627576285762957630576315763257633576345763557636576375763857639576405764157642576435764457645576465764757648576495765057651576525765357654576555765657657576585765957660576615766257663576645766557666576675766857669576705767157672576735767457675576765767757678576795768057681576825768357684576855768657687576885768957690576915769257693576945769557696576975769857699577005770157702577035770457705577065770757708577095771057711577125771357714577155771657717577185771957720577215772257723577245772557726577275772857729577305773157732577335773457735577365773757738577395774057741577425774357744577455774657747577485774957750577515775257753577545775557756577575775857759577605776157762577635776457765577665776757768577695777057771577725777357774577755777657777577785777957780577815778257783577845778557786577875778857789577905779157792577935779457795577965779757798577995780057801578025780357804578055780657807578085780957810578115781257813578145781557816578175781857819578205782157822578235782457825578265782757828578295783057831578325783357834578355783657837578385783957840578415784257843578445784557846578475784857849578505785157852578535785457855578565785757858578595786057861578625786357864578655786657867578685786957870578715787257873578745787557876578775787857879578805788157882578835788457885578865788757888578895789057891578925789357894578955789657897578985789957900579015790257903579045790557906579075790857909579105791157912579135791457915579165791757918579195792057921579225792357924579255792657927579285792957930579315793257933579345793557936579375793857939579405794157942579435794457945579465794757948579495795057951579525795357954579555795657957579585795957960579615796257963579645796557966579675796857969579705797157972579735797457975579765797757978579795798057981579825798357984579855798657987579885798957990579915799257993579945799557996579975799857999580005800158002580035800458005580065800758008580095801058011580125801358014580155801658017580185801958020580215802258023580245802558026580275802858029580305803158032580335803458035580365803758038580395804058041580425804358044580455804658047580485804958050580515805258053580545805558056580575805858059580605806158062580635806458065580665806758068580695807058071580725807358074580755807658077580785807958080580815808258083580845808558086580875808858089580905809158092580935809458095580965809758098580995810058101581025810358104581055810658107581085810958110581115811258113581145811558116581175811858119581205812158122581235812458125581265812758128581295813058131581325813358134581355813658137581385813958140581415814258143581445814558146581475814858149581505815158152581535815458155581565815758158581595816058161581625816358164581655816658167581685816958170581715817258173581745817558176581775817858179581805818158182581835818458185581865818758188581895819058191581925819358194581955819658197581985819958200582015820258203582045820558206582075820858209582105821158212582135821458215582165821758218582195822058221582225822358224582255822658227582285822958230582315823258233582345823558236582375823858239582405824158242582435824458245582465824758248582495825058251582525825358254582555825658257582585825958260582615826258263582645826558266582675826858269582705827158272582735827458275582765827758278582795828058281582825828358284582855828658287582885828958290582915829258293582945829558296582975829858299583005830158302583035830458305583065830758308583095831058311583125831358314583155831658317583185831958320583215832258323583245832558326583275832858329583305833158332583335833458335583365833758338583395834058341583425834358344583455834658347583485834958350583515835258353583545835558356583575835858359583605836158362583635836458365583665836758368583695837058371583725837358374583755837658377583785837958380583815838258383583845838558386583875838858389583905839158392583935839458395583965839758398583995840058401584025840358404584055840658407584085840958410584115841258413584145841558416584175841858419584205842158422584235842458425584265842758428584295843058431584325843358434584355843658437584385843958440584415844258443584445844558446584475844858449584505845158452584535845458455584565845758458584595846058461584625846358464584655846658467584685846958470584715847258473584745847558476584775847858479584805848158482584835848458485584865848758488584895849058491584925849358494584955849658497584985849958500585015850258503585045850558506585075850858509585105851158512585135851458515585165851758518585195852058521585225852358524585255852658527585285852958530585315853258533585345853558536585375853858539585405854158542585435854458545585465854758548585495855058551585525855358554585555855658557585585855958560585615856258563585645856558566585675856858569585705857158572585735857458575585765857758578585795858058581585825858358584585855858658587585885858958590585915859258593585945859558596585975859858599586005860158602586035860458605586065860758608586095861058611586125861358614586155861658617586185861958620586215862258623586245862558626586275862858629586305863158632586335863458635586365863758638586395864058641586425864358644586455864658647586485864958650586515865258653586545865558656586575865858659586605866158662586635866458665586665866758668586695867058671586725867358674586755867658677586785867958680586815868258683586845868558686586875868858689586905869158692586935869458695586965869758698586995870058701587025870358704587055870658707587085870958710587115871258713587145871558716587175871858719587205872158722587235872458725587265872758728587295873058731587325873358734587355873658737587385873958740587415874258743587445874558746587475874858749587505875158752587535875458755587565875758758587595876058761587625876358764587655876658767587685876958770587715877258773587745877558776587775877858779587805878158782587835878458785587865878758788587895879058791587925879358794587955879658797587985879958800588015880258803588045880558806588075880858809588105881158812588135881458815588165881758818588195882058821588225882358824588255882658827588285882958830588315883258833588345883558836588375883858839588405884158842588435884458845588465884758848588495885058851588525885358854588555885658857588585885958860588615886258863588645886558866588675886858869588705887158872588735887458875588765887758878588795888058881588825888358884588855888658887588885888958890588915889258893588945889558896588975889858899589005890158902589035890458905589065890758908589095891058911589125891358914589155891658917589185891958920589215892258923589245892558926589275892858929589305893158932589335893458935589365893758938589395894058941589425894358944589455894658947589485894958950589515895258953589545895558956589575895858959589605896158962589635896458965589665896758968589695897058971589725897358974589755897658977589785897958980589815898258983589845898558986589875898858989589905899158992589935899458995589965899758998589995900059001590025900359004590055900659007590085900959010590115901259013590145901559016590175901859019590205902159022590235902459025590265902759028590295903059031590325903359034590355903659037590385903959040590415904259043590445904559046590475904859049590505905159052590535905459055590565905759058590595906059061590625906359064590655906659067590685906959070590715907259073590745907559076590775907859079590805908159082590835908459085590865908759088590895909059091590925909359094590955909659097590985909959100591015910259103591045910559106591075910859109591105911159112591135911459115591165911759118591195912059121591225912359124591255912659127591285912959130591315913259133591345913559136591375913859139591405914159142591435914459145591465914759148591495915059151591525915359154591555915659157591585915959160591615916259163591645916559166591675916859169591705917159172591735917459175591765917759178591795918059181591825918359184591855918659187591885918959190591915919259193591945919559196591975919859199592005920159202592035920459205592065920759208592095921059211592125921359214592155921659217592185921959220592215922259223592245922559226592275922859229592305923159232592335923459235592365923759238592395924059241592425924359244592455924659247592485924959250592515925259253592545925559256592575925859259592605926159262592635926459265592665926759268592695927059271592725927359274592755927659277592785927959280592815928259283592845928559286592875928859289592905929159292592935929459295592965929759298592995930059301593025930359304593055930659307593085930959310593115931259313593145931559316593175931859319593205932159322593235932459325593265932759328593295933059331593325933359334593355933659337593385933959340593415934259343593445934559346593475934859349593505935159352593535935459355593565935759358593595936059361593625936359364593655936659367593685936959370593715937259373593745937559376593775937859379593805938159382593835938459385593865938759388593895939059391593925939359394593955939659397593985939959400594015940259403594045940559406594075940859409594105941159412594135941459415594165941759418594195942059421594225942359424594255942659427594285942959430594315943259433594345943559436594375943859439594405944159442594435944459445594465944759448594495945059451594525945359454594555945659457594585945959460594615946259463594645946559466594675946859469594705947159472594735947459475594765947759478594795948059481594825948359484594855948659487594885948959490594915949259493594945949559496594975949859499595005950159502595035950459505595065950759508595095951059511595125951359514595155951659517595185951959520595215952259523595245952559526595275952859529595305953159532595335953459535595365953759538595395954059541595425954359544595455954659547595485954959550595515955259553595545955559556595575955859559595605956159562595635956459565595665956759568595695957059571595725957359574595755957659577595785957959580595815958259583595845958559586595875958859589595905959159592595935959459595595965959759598595995960059601596025960359604596055960659607596085960959610596115961259613596145961559616596175961859619596205962159622596235962459625596265962759628596295963059631596325963359634596355963659637596385963959640596415964259643596445964559646596475964859649596505965159652596535965459655596565965759658596595966059661596625966359664596655966659667596685966959670596715967259673596745967559676596775967859679596805968159682596835968459685596865968759688596895969059691596925969359694596955969659697596985969959700597015970259703597045970559706597075970859709597105971159712597135971459715597165971759718597195972059721597225972359724597255972659727597285972959730597315973259733597345973559736597375973859739597405974159742597435974459745597465974759748597495975059751597525975359754597555975659757597585975959760597615976259763597645976559766597675976859769597705977159772597735977459775597765977759778597795978059781597825978359784597855978659787597885978959790597915979259793597945979559796597975979859799598005980159802598035980459805598065980759808598095981059811598125981359814598155981659817598185981959820598215982259823598245982559826598275982859829598305983159832598335983459835598365983759838598395984059841598425984359844598455984659847598485984959850598515985259853598545985559856598575985859859598605986159862598635986459865598665986759868598695987059871598725987359874598755987659877598785987959880598815988259883598845988559886598875988859889598905989159892598935989459895598965989759898598995990059901599025990359904599055990659907599085990959910599115991259913599145991559916599175991859919599205992159922599235992459925599265992759928599295993059931599325993359934599355993659937599385993959940599415994259943599445994559946599475994859949599505995159952599535995459955599565995759958599595996059961599625996359964599655996659967599685996959970599715997259973599745997559976599775997859979599805998159982599835998459985599865998759988599895999059991599925999359994599955999659997599985999960000600016000260003600046000560006600076000860009600106001160012600136001460015600166001760018600196002060021600226002360024600256002660027600286002960030600316003260033600346003560036600376003860039600406004160042600436004460045600466004760048600496005060051600526005360054600556005660057600586005960060600616006260063600646006560066600676006860069600706007160072600736007460075600766007760078600796008060081600826008360084600856008660087600886008960090600916009260093600946009560096600976009860099601006010160102601036010460105601066010760108601096011060111601126011360114601156011660117601186011960120601216012260123601246012560126601276012860129601306013160132601336013460135601366013760138601396014060141601426014360144601456014660147601486014960150601516015260153601546015560156601576015860159601606016160162601636016460165601666016760168601696017060171601726017360174601756017660177601786017960180601816018260183601846018560186601876018860189601906019160192601936019460195601966019760198601996020060201602026020360204602056020660207602086020960210602116021260213602146021560216602176021860219602206022160222602236022460225602266022760228602296023060231602326023360234602356023660237602386023960240602416024260243602446024560246602476024860249602506025160252602536025460255602566025760258602596026060261602626026360264602656026660267602686026960270602716027260273602746027560276602776027860279602806028160282602836028460285602866028760288602896029060291602926029360294602956029660297602986029960300603016030260303603046030560306603076030860309603106031160312603136031460315603166031760318603196032060321603226032360324603256032660327603286032960330603316033260333603346033560336603376033860339603406034160342603436034460345603466034760348603496035060351603526035360354603556035660357603586035960360603616036260363603646036560366603676036860369603706037160372603736037460375603766037760378603796038060381603826038360384603856038660387603886038960390603916039260393603946039560396603976039860399604006040160402604036040460405604066040760408604096041060411604126041360414604156041660417604186041960420604216042260423604246042560426604276042860429604306043160432604336043460435604366043760438604396044060441604426044360444604456044660447604486044960450604516045260453604546045560456604576045860459604606046160462604636046460465604666046760468604696047060471604726047360474604756047660477604786047960480604816048260483604846048560486604876048860489604906049160492604936049460495604966049760498604996050060501605026050360504605056050660507605086050960510605116051260513605146051560516605176051860519605206052160522605236052460525605266052760528605296053060531605326053360534605356053660537605386053960540605416054260543605446054560546605476054860549605506055160552605536055460555605566055760558605596056060561605626056360564605656056660567605686056960570605716057260573605746057560576605776057860579605806058160582605836058460585605866058760588605896059060591605926059360594605956059660597605986059960600606016060260603606046060560606606076060860609606106061160612606136061460615606166061760618606196062060621606226062360624606256062660627606286062960630606316063260633606346063560636606376063860639606406064160642606436064460645606466064760648606496065060651606526065360654606556065660657606586065960660606616066260663606646066560666606676066860669606706067160672606736067460675606766067760678606796068060681606826068360684606856068660687606886068960690606916069260693606946069560696606976069860699607006070160702607036070460705607066070760708607096071060711607126071360714607156071660717607186071960720607216072260723607246072560726607276072860729607306073160732607336073460735607366073760738607396074060741607426074360744607456074660747607486074960750607516075260753607546075560756607576075860759607606076160762607636076460765607666076760768607696077060771607726077360774607756077660777607786077960780607816078260783607846078560786607876078860789607906079160792607936079460795607966079760798607996080060801608026080360804608056080660807608086080960810608116081260813608146081560816608176081860819608206082160822608236082460825608266082760828608296083060831608326083360834608356083660837608386083960840608416084260843608446084560846608476084860849608506085160852608536085460855608566085760858608596086060861608626086360864608656086660867608686086960870608716087260873608746087560876608776087860879608806088160882608836088460885608866088760888608896089060891608926089360894608956089660897608986089960900609016090260903609046090560906609076090860909609106091160912609136091460915609166091760918609196092060921609226092360924609256092660927609286092960930609316093260933609346093560936609376093860939609406094160942609436094460945609466094760948609496095060951609526095360954609556095660957609586095960960609616096260963609646096560966609676096860969609706097160972609736097460975609766097760978609796098060981609826098360984609856098660987609886098960990609916099260993609946099560996609976099860999610006100161002610036100461005610066100761008610096101061011610126101361014610156101661017610186101961020610216102261023610246102561026610276102861029610306103161032610336103461035610366103761038610396104061041610426104361044610456104661047610486104961050610516105261053610546105561056610576105861059610606106161062610636106461065610666106761068610696107061071610726107361074610756107661077610786107961080610816108261083610846108561086610876108861089610906109161092610936109461095610966109761098610996110061101611026110361104611056110661107611086110961110611116111261113611146111561116611176111861119611206112161122611236112461125611266112761128611296113061131611326113361134611356113661137611386113961140611416114261143611446114561146611476114861149611506115161152611536115461155611566115761158611596116061161611626116361164611656116661167611686116961170611716117261173611746117561176611776117861179611806118161182611836118461185611866118761188611896119061191611926119361194611956119661197611986119961200612016120261203612046120561206612076120861209612106121161212612136121461215612166121761218612196122061221612226122361224612256122661227612286122961230612316123261233612346123561236612376123861239612406124161242612436124461245612466124761248612496125061251612526125361254612556125661257612586125961260612616126261263612646126561266612676126861269612706127161272612736127461275612766127761278612796128061281612826128361284612856128661287612886128961290612916129261293612946129561296612976129861299613006130161302613036130461305613066130761308613096131061311613126131361314613156131661317613186131961320613216132261323613246132561326613276132861329613306133161332613336133461335613366133761338613396134061341613426134361344613456134661347613486134961350613516135261353613546135561356613576135861359613606136161362613636136461365613666136761368613696137061371613726137361374613756137661377613786137961380613816138261383613846138561386613876138861389613906139161392613936139461395613966139761398613996140061401614026140361404614056140661407614086140961410614116141261413614146141561416614176141861419614206142161422614236142461425614266142761428614296143061431614326143361434614356143661437614386143961440614416144261443614446144561446614476144861449614506145161452614536145461455614566145761458614596146061461614626146361464614656146661467614686146961470614716147261473614746147561476614776147861479614806148161482614836148461485614866148761488614896149061491614926149361494614956149661497614986149961500615016150261503615046150561506615076150861509615106151161512615136151461515615166151761518615196152061521615226152361524615256152661527615286152961530615316153261533615346153561536615376153861539615406154161542615436154461545615466154761548615496155061551615526155361554615556155661557615586155961560615616156261563615646156561566615676156861569615706157161572615736157461575615766157761578615796158061581615826158361584615856158661587615886158961590615916159261593615946159561596615976159861599616006160161602616036160461605616066160761608616096161061611616126161361614616156161661617616186161961620616216162261623616246162561626616276162861629616306163161632616336163461635616366163761638616396164061641616426164361644616456164661647616486164961650616516165261653616546165561656616576165861659616606166161662616636166461665616666166761668616696167061671616726167361674616756167661677616786167961680616816168261683616846168561686616876168861689616906169161692616936169461695616966169761698616996170061701617026170361704617056170661707617086170961710617116171261713617146171561716617176171861719617206172161722617236172461725617266172761728617296173061731617326173361734617356173661737617386173961740617416174261743617446174561746617476174861749617506175161752617536175461755617566175761758617596176061761617626176361764617656176661767617686176961770617716177261773617746177561776617776177861779617806178161782617836178461785617866178761788617896179061791617926179361794617956179661797617986179961800618016180261803618046180561806618076180861809618106181161812618136181461815618166181761818618196182061821618226182361824618256182661827618286182961830618316183261833618346183561836618376183861839618406184161842618436184461845618466184761848618496185061851618526185361854618556185661857618586185961860618616186261863618646186561866618676186861869618706187161872618736187461875618766187761878618796188061881618826188361884618856188661887618886188961890618916189261893618946189561896618976189861899619006190161902619036190461905619066190761908619096191061911619126191361914619156191661917619186191961920619216192261923619246192561926619276192861929619306193161932619336193461935619366193761938619396194061941619426194361944619456194661947619486194961950619516195261953619546195561956619576195861959619606196161962619636196461965619666196761968619696197061971619726197361974619756197661977619786197961980619816198261983619846198561986619876198861989619906199161992619936199461995619966199761998619996200062001620026200362004620056200662007620086200962010620116201262013620146201562016620176201862019620206202162022620236202462025620266202762028620296203062031620326203362034620356203662037620386203962040620416204262043620446204562046620476204862049620506205162052620536205462055620566205762058620596206062061620626206362064620656206662067620686206962070620716207262073620746207562076620776207862079620806208162082620836208462085620866208762088620896209062091620926209362094620956209662097620986209962100621016210262103621046210562106621076210862109621106211162112621136211462115621166211762118621196212062121621226212362124621256212662127621286212962130621316213262133621346213562136621376213862139621406214162142621436214462145621466214762148621496215062151621526215362154621556215662157621586215962160621616216262163621646216562166621676216862169621706217162172621736217462175621766217762178621796218062181621826218362184621856218662187621886218962190621916219262193621946219562196621976219862199622006220162202622036220462205622066220762208622096221062211622126221362214622156221662217622186221962220622216222262223622246222562226622276222862229622306223162232622336223462235622366223762238622396224062241622426224362244622456224662247622486224962250622516225262253622546225562256622576225862259622606226162262622636226462265622666226762268622696227062271622726227362274622756227662277622786227962280622816228262283622846228562286622876228862289622906229162292622936229462295622966229762298622996230062301623026230362304623056230662307623086230962310623116231262313623146231562316623176231862319623206232162322623236232462325623266232762328623296233062331623326233362334623356233662337623386233962340623416234262343623446234562346623476234862349623506235162352623536235462355623566235762358623596236062361623626236362364623656236662367623686236962370623716237262373623746237562376623776237862379623806238162382623836238462385623866238762388623896239062391623926239362394623956239662397623986239962400624016240262403624046240562406624076240862409624106241162412624136241462415624166241762418624196242062421624226242362424624256242662427624286242962430624316243262433624346243562436624376243862439624406244162442624436244462445624466244762448624496245062451624526245362454624556245662457624586245962460624616246262463624646246562466624676246862469624706247162472624736247462475624766247762478624796248062481624826248362484624856248662487624886248962490624916249262493624946249562496624976249862499625006250162502625036250462505625066250762508625096251062511625126251362514625156251662517625186251962520625216252262523625246252562526625276252862529625306253162532625336253462535625366253762538625396254062541625426254362544625456254662547625486254962550625516255262553625546255562556625576255862559625606256162562625636256462565625666256762568625696257062571625726257362574625756257662577625786257962580625816258262583625846258562586625876258862589625906259162592625936259462595625966259762598625996260062601626026260362604626056260662607626086260962610626116261262613626146261562616626176261862619626206262162622626236262462625626266262762628626296263062631626326263362634626356263662637626386263962640626416264262643626446264562646626476264862649626506265162652626536265462655626566265762658626596266062661626626266362664626656266662667626686266962670626716267262673626746267562676626776267862679626806268162682626836268462685626866268762688626896269062691626926269362694626956269662697626986269962700627016270262703627046270562706627076270862709627106271162712627136271462715627166271762718627196272062721627226272362724627256272662727627286272962730627316273262733627346273562736627376273862739627406274162742627436274462745627466274762748627496275062751627526275362754627556275662757627586275962760627616276262763627646276562766627676276862769627706277162772627736277462775627766277762778627796278062781627826278362784627856278662787627886278962790627916279262793627946279562796627976279862799628006280162802628036280462805628066280762808628096281062811628126281362814628156281662817628186281962820628216282262823628246282562826628276282862829628306283162832628336283462835628366283762838628396284062841628426284362844628456284662847628486284962850628516285262853628546285562856628576285862859628606286162862628636286462865628666286762868628696287062871628726287362874628756287662877628786287962880628816288262883628846288562886628876288862889628906289162892628936289462895628966289762898628996290062901629026290362904629056290662907629086290962910629116291262913629146291562916629176291862919629206292162922629236292462925629266292762928629296293062931629326293362934629356293662937629386293962940629416294262943629446294562946629476294862949629506295162952629536295462955629566295762958629596296062961629626296362964629656296662967629686296962970629716297262973629746297562976629776297862979629806298162982629836298462985629866298762988629896299062991629926299362994629956299662997629986299963000630016300263003630046300563006630076300863009630106301163012630136301463015630166301763018630196302063021630226302363024630256302663027630286302963030630316303263033630346303563036630376303863039630406304163042630436304463045630466304763048630496305063051630526305363054630556305663057630586305963060630616306263063630646306563066630676306863069630706307163072630736307463075630766307763078630796308063081630826308363084630856308663087630886308963090630916309263093630946309563096630976309863099631006310163102631036310463105631066310763108631096311063111631126311363114631156311663117631186311963120631216312263123631246312563126631276312863129631306313163132631336313463135631366313763138631396314063141631426314363144631456314663147631486314963150631516315263153631546315563156631576315863159631606316163162631636316463165631666316763168631696317063171631726317363174631756317663177631786317963180631816318263183631846318563186631876318863189631906319163192631936319463195631966319763198631996320063201632026320363204632056320663207632086320963210632116321263213632146321563216632176321863219632206322163222632236322463225632266322763228632296323063231632326323363234632356323663237632386323963240632416324263243632446324563246632476324863249632506325163252632536325463255632566325763258632596326063261632626326363264632656326663267632686326963270632716327263273632746327563276632776327863279632806328163282632836328463285632866328763288632896329063291632926329363294632956329663297632986329963300633016330263303633046330563306633076330863309633106331163312633136331463315633166331763318633196332063321633226332363324633256332663327633286332963330633316333263333633346333563336633376333863339633406334163342633436334463345633466334763348633496335063351633526335363354633556335663357633586335963360633616336263363633646336563366633676336863369633706337163372633736337463375633766337763378633796338063381633826338363384633856338663387633886338963390633916339263393633946339563396633976339863399634006340163402634036340463405634066340763408634096341063411634126341363414634156341663417634186341963420634216342263423634246342563426634276342863429634306343163432634336343463435634366343763438634396344063441634426344363444634456344663447634486344963450634516345263453634546345563456634576345863459634606346163462634636346463465634666346763468634696347063471634726347363474634756347663477634786347963480634816348263483634846348563486634876348863489634906349163492634936349463495634966349763498634996350063501635026350363504635056350663507635086350963510635116351263513635146351563516635176351863519635206352163522635236352463525635266352763528635296353063531635326353363534635356353663537635386353963540635416354263543635446354563546635476354863549635506355163552635536355463555635566355763558635596356063561635626356363564635656356663567635686356963570635716357263573635746357563576635776357863579635806358163582635836358463585635866358763588635896359063591635926359363594635956359663597635986359963600636016360263603636046360563606636076360863609636106361163612636136361463615636166361763618636196362063621636226362363624636256362663627636286362963630636316363263633636346363563636636376363863639636406364163642636436364463645636466364763648636496365063651636526365363654636556365663657636586365963660636616366263663636646366563666636676366863669636706367163672636736367463675636766367763678636796368063681636826368363684636856368663687636886368963690636916369263693636946369563696636976369863699637006370163702637036370463705637066370763708637096371063711637126371363714637156371663717637186371963720637216372263723637246372563726637276372863729637306373163732637336373463735637366373763738637396374063741637426374363744637456374663747637486374963750637516375263753637546375563756637576375863759637606376163762637636376463765637666376763768637696377063771637726377363774637756377663777637786377963780637816378263783637846378563786637876378863789637906379163792637936379463795637966379763798637996380063801638026380363804638056380663807638086380963810638116381263813638146381563816638176381863819638206382163822638236382463825638266382763828638296383063831638326383363834638356383663837638386383963840638416384263843638446384563846638476384863849638506385163852638536385463855638566385763858638596386063861638626386363864638656386663867638686386963870638716387263873638746387563876638776387863879638806388163882638836388463885638866388763888638896389063891638926389363894638956389663897638986389963900639016390263903639046390563906639076390863909639106391163912639136391463915639166391763918639196392063921639226392363924639256392663927639286392963930639316393263933639346393563936639376393863939639406394163942639436394463945639466394763948639496395063951639526395363954639556395663957639586395963960639616396263963639646396563966639676396863969639706397163972639736397463975639766397763978639796398063981639826398363984639856398663987639886398963990639916399263993639946399563996639976399863999640006400164002640036400464005640066400764008640096401064011640126401364014640156401664017640186401964020640216402264023640246402564026640276402864029640306403164032640336403464035640366403764038640396404064041640426404364044640456404664047640486404964050640516405264053640546405564056640576405864059640606406164062640636406464065640666406764068640696407064071640726407364074640756407664077640786407964080640816408264083640846408564086640876408864089640906409164092640936409464095640966409764098640996410064101641026410364104641056410664107641086410964110641116411264113641146411564116641176411864119641206412164122641236412464125641266412764128641296413064131641326413364134641356413664137641386413964140641416414264143641446414564146641476414864149641506415164152641536415464155641566415764158641596416064161641626416364164641656416664167641686416964170641716417264173641746417564176641776417864179641806418164182641836418464185641866418764188641896419064191641926419364194641956419664197641986419964200642016420264203642046420564206642076420864209642106421164212642136421464215642166421764218642196422064221642226422364224642256422664227642286422964230642316423264233642346423564236642376423864239642406424164242642436424464245642466424764248642496425064251642526425364254642556425664257642586425964260642616426264263642646426564266642676426864269642706427164272642736427464275642766427764278642796428064281642826428364284642856428664287642886428964290642916429264293642946429564296642976429864299643006430164302643036430464305643066430764308643096431064311643126431364314643156431664317643186431964320643216432264323643246432564326643276432864329643306433164332643336433464335643366433764338643396434064341643426434364344643456434664347643486434964350643516435264353643546435564356643576435864359643606436164362643636436464365643666436764368643696437064371643726437364374643756437664377643786437964380643816438264383643846438564386643876438864389643906439164392643936439464395643966439764398643996440064401644026440364404644056440664407644086440964410644116441264413644146441564416644176441864419644206442164422644236442464425644266442764428644296443064431644326443364434644356443664437644386443964440644416444264443644446444564446644476444864449644506445164452644536445464455644566445764458644596446064461644626446364464644656446664467644686446964470644716447264473644746447564476644776447864479644806448164482644836448464485644866448764488644896449064491644926449364494644956449664497644986449964500645016450264503645046450564506645076450864509645106451164512645136451464515645166451764518645196452064521645226452364524645256452664527645286452964530645316453264533645346453564536645376453864539645406454164542645436454464545645466454764548645496455064551645526455364554645556455664557645586455964560645616456264563645646456564566645676456864569645706457164572645736457464575645766457764578645796458064581645826458364584645856458664587645886458964590645916459264593645946459564596645976459864599646006460164602646036460464605646066460764608646096461064611646126461364614646156461664617646186461964620646216462264623646246462564626646276462864629646306463164632646336463464635646366463764638646396464064641646426464364644646456464664647646486464964650646516465264653646546465564656646576465864659646606466164662646636466464665646666466764668646696467064671646726467364674646756467664677646786467964680646816468264683646846468564686646876468864689646906469164692646936469464695646966469764698646996470064701647026470364704647056470664707647086470964710647116471264713647146471564716647176471864719647206472164722647236472464725647266472764728647296473064731647326473364734647356473664737647386473964740647416474264743647446474564746647476474864749647506475164752647536475464755647566475764758647596476064761647626476364764647656476664767647686476964770647716477264773647746477564776647776477864779647806478164782647836478464785647866478764788647896479064791647926479364794647956479664797647986479964800648016480264803648046480564806648076480864809648106481164812648136481464815648166481764818648196482064821648226482364824648256482664827648286482964830648316483264833648346483564836648376483864839648406484164842648436484464845648466484764848648496485064851648526485364854648556485664857648586485964860648616486264863648646486564866648676486864869648706487164872648736487464875648766487764878648796488064881648826488364884648856488664887648886488964890648916489264893648946489564896648976489864899649006490164902649036490464905649066490764908649096491064911649126491364914649156491664917649186491964920649216492264923649246492564926649276492864929649306493164932649336493464935649366493764938649396494064941649426494364944649456494664947649486494964950649516495264953649546495564956649576495864959649606496164962649636496464965649666496764968649696497064971649726497364974649756497664977649786497964980649816498264983649846498564986649876498864989649906499164992649936499464995649966499764998649996500065001650026500365004650056500665007650086500965010650116501265013650146501565016650176501865019650206502165022650236502465025650266502765028650296503065031650326503365034650356503665037650386503965040650416504265043650446504565046650476504865049650506505165052650536505465055650566505765058650596506065061650626506365064650656506665067650686506965070650716507265073650746507565076650776507865079650806508165082650836508465085650866508765088650896509065091650926509365094650956509665097650986509965100651016510265103651046510565106651076510865109651106511165112651136511465115651166511765118651196512065121651226512365124651256512665127651286512965130651316513265133651346513565136651376513865139651406514165142651436514465145651466514765148651496515065151651526515365154651556515665157651586515965160651616516265163651646516565166651676516865169651706517165172651736517465175651766517765178651796518065181651826518365184651856518665187651886518965190651916519265193651946519565196651976519865199652006520165202652036520465205652066520765208652096521065211652126521365214652156521665217652186521965220652216522265223652246522565226652276522865229652306523165232652336523465235652366523765238652396524065241652426524365244652456524665247652486524965250652516525265253652546525565256652576525865259652606526165262652636526465265652666526765268652696527065271652726527365274652756527665277652786527965280652816528265283652846528565286652876528865289652906529165292652936529465295652966529765298652996530065301653026530365304653056530665307653086530965310653116531265313653146531565316653176531865319653206532165322653236532465325653266532765328653296533065331653326533365334653356533665337653386533965340653416534265343653446534565346653476534865349653506535165352653536535465355653566535765358653596536065361653626536365364653656536665367653686536965370653716537265373653746537565376653776537865379653806538165382653836538465385653866538765388653896539065391653926539365394653956539665397653986539965400654016540265403654046540565406654076540865409654106541165412654136541465415654166541765418654196542065421654226542365424654256542665427654286542965430654316543265433654346543565436654376543865439654406544165442654436544465445654466544765448654496545065451654526545365454654556545665457654586545965460654616546265463654646546565466654676546865469654706547165472654736547465475654766547765478654796548065481654826548365484654856548665487654886548965490654916549265493654946549565496654976549865499655006550165502655036550465505655066550765508655096551065511655126551365514655156551665517655186551965520655216552265523655246552565526655276552865529655306553165532655336553465535655366553765538655396554065541655426554365544655456554665547655486554965550655516555265553655546555565556655576555865559655606556165562655636556465565655666556765568655696557065571655726557365574655756557665577655786557965580655816558265583655846558565586655876558865589655906559165592655936559465595655966559765598655996560065601656026560365604656056560665607656086560965610656116561265613656146561565616656176561865619656206562165622656236562465625656266562765628656296563065631656326563365634656356563665637656386563965640656416564265643656446564565646656476564865649656506565165652656536565465655656566565765658656596566065661656626566365664656656566665667656686566965670656716567265673656746567565676656776567865679656806568165682656836568465685656866568765688656896569065691656926569365694656956569665697656986569965700657016570265703657046570565706657076570865709657106571165712657136571465715657166571765718657196572065721657226572365724657256572665727657286572965730657316573265733657346573565736657376573865739657406574165742657436574465745657466574765748657496575065751657526575365754657556575665757657586575965760657616576265763657646576565766657676576865769657706577165772657736577465775657766577765778657796578065781657826578365784657856578665787657886578965790657916579265793657946579565796657976579865799658006580165802658036580465805658066580765808658096581065811658126581365814658156581665817658186581965820658216582265823658246582565826658276582865829658306583165832658336583465835658366583765838658396584065841658426584365844658456584665847658486584965850658516585265853658546585565856658576585865859658606586165862658636586465865658666586765868658696587065871658726587365874658756587665877658786587965880658816588265883658846588565886658876588865889658906589165892658936589465895658966589765898658996590065901659026590365904659056590665907659086590965910659116591265913659146591565916659176591865919659206592165922659236592465925659266592765928659296593065931659326593365934659356593665937659386593965940659416594265943659446594565946659476594865949659506595165952659536595465955659566595765958659596596065961659626596365964659656596665967659686596965970659716597265973659746597565976659776597865979659806598165982659836598465985659866598765988659896599065991659926599365994659956599665997659986599966000660016600266003660046600566006660076600866009660106601166012660136601466015660166601766018660196602066021660226602366024660256602666027660286602966030660316603266033660346603566036660376603866039660406604166042660436604466045660466604766048660496605066051660526605366054660556605666057660586605966060660616606266063660646606566066660676606866069660706607166072660736607466075660766607766078660796608066081660826608366084660856608666087660886608966090660916609266093660946609566096660976609866099661006610166102661036610466105661066610766108661096611066111661126611366114661156611666117661186611966120661216612266123661246612566126661276612866129661306613166132661336613466135661366613766138661396614066141661426614366144661456614666147661486614966150661516615266153661546615566156661576615866159661606616166162661636616466165661666616766168661696617066171661726617366174661756617666177661786617966180661816618266183661846618566186661876618866189661906619166192661936619466195661966619766198661996620066201662026620366204662056620666207662086620966210662116621266213662146621566216662176621866219662206622166222662236622466225662266622766228662296623066231662326623366234662356623666237662386623966240662416624266243662446624566246662476624866249662506625166252662536625466255662566625766258662596626066261662626626366264662656626666267662686626966270662716627266273662746627566276662776627866279662806628166282662836628466285662866628766288662896629066291662926629366294662956629666297662986629966300663016630266303663046630566306663076630866309663106631166312663136631466315663166631766318663196632066321663226632366324663256632666327663286632966330663316633266333663346633566336663376633866339663406634166342663436634466345663466634766348663496635066351663526635366354663556635666357663586635966360663616636266363663646636566366663676636866369663706637166372663736637466375663766637766378663796638066381663826638366384663856638666387663886638966390663916639266393663946639566396663976639866399664006640166402664036640466405664066640766408664096641066411664126641366414664156641666417664186641966420664216642266423664246642566426664276642866429664306643166432664336643466435664366643766438664396644066441664426644366444664456644666447664486644966450664516645266453664546645566456664576645866459664606646166462664636646466465664666646766468664696647066471664726647366474664756647666477664786647966480664816648266483664846648566486664876648866489664906649166492664936649466495664966649766498664996650066501665026650366504665056650666507665086650966510665116651266513665146651566516665176651866519665206652166522665236652466525665266652766528665296653066531665326653366534665356653666537665386653966540665416654266543665446654566546665476654866549665506655166552665536655466555665566655766558665596656066561665626656366564665656656666567665686656966570665716657266573665746657566576665776657866579665806658166582665836658466585665866658766588665896659066591665926659366594665956659666597665986659966600666016660266603666046660566606666076660866609666106661166612666136661466615666166661766618666196662066621666226662366624666256662666627666286662966630666316663266633666346663566636666376663866639666406664166642666436664466645666466664766648666496665066651666526665366654666556665666657666586665966660666616666266663666646666566666666676666866669666706667166672666736667466675666766667766678666796668066681666826668366684666856668666687666886668966690666916669266693666946669566696666976669866699667006670166702667036670466705667066670766708667096671066711667126671366714667156671666717667186671966720667216672266723667246672566726667276672866729667306673166732667336673466735667366673766738667396674066741667426674366744667456674666747667486674966750667516675266753667546675566756667576675866759667606676166762667636676466765667666676766768667696677066771667726677366774667756677666777667786677966780667816678266783667846678566786667876678866789667906679166792667936679466795667966679766798667996680066801668026680366804668056680666807668086680966810668116681266813668146681566816668176681866819668206682166822668236682466825668266682766828668296683066831668326683366834668356683666837668386683966840668416684266843668446684566846668476684866849668506685166852668536685466855668566685766858668596686066861668626686366864668656686666867668686686966870668716687266873668746687566876668776687866879668806688166882668836688466885668866688766888668896689066891668926689366894668956689666897668986689966900669016690266903669046690566906669076690866909669106691166912669136691466915669166691766918669196692066921669226692366924669256692666927669286692966930669316693266933669346693566936669376693866939669406694166942669436694466945669466694766948669496695066951669526695366954669556695666957669586695966960669616696266963669646696566966669676696866969669706697166972669736697466975669766697766978669796698066981669826698366984669856698666987669886698966990669916699266993669946699566996669976699866999670006700167002670036700467005670066700767008670096701067011670126701367014670156701667017670186701967020670216702267023670246702567026670276702867029670306703167032670336703467035670366703767038670396704067041670426704367044670456704667047670486704967050670516705267053670546705567056670576705867059670606706167062670636706467065670666706767068670696707067071670726707367074670756707667077670786707967080670816708267083670846708567086670876708867089670906709167092670936709467095670966709767098670996710067101671026710367104671056710667107671086710967110671116711267113671146711567116671176711867119671206712167122671236712467125671266712767128671296713067131671326713367134671356713667137671386713967140671416714267143671446714567146671476714867149671506715167152671536715467155671566715767158671596716067161671626716367164671656716667167671686716967170671716717267173671746717567176671776717867179671806718167182671836718467185671866718767188671896719067191671926719367194671956719667197671986719967200672016720267203672046720567206672076720867209672106721167212672136721467215672166721767218672196722067221672226722367224672256722667227672286722967230672316723267233672346723567236672376723867239672406724167242672436724467245672466724767248672496725067251672526725367254672556725667257672586725967260672616726267263672646726567266672676726867269672706727167272672736727467275672766727767278672796728067281672826728367284672856728667287672886728967290672916729267293672946729567296672976729867299673006730167302673036730467305673066730767308673096731067311673126731367314673156731667317673186731967320673216732267323673246732567326673276732867329673306733167332673336733467335673366733767338673396734067341673426734367344673456734667347673486734967350673516735267353673546735567356673576735867359673606736167362673636736467365673666736767368673696737067371673726737367374673756737667377673786737967380673816738267383673846738567386673876738867389673906739167392673936739467395673966739767398673996740067401674026740367404674056740667407674086740967410674116741267413674146741567416674176741867419674206742167422674236742467425674266742767428674296743067431674326743367434674356743667437674386743967440674416744267443674446744567446674476744867449674506745167452674536745467455674566745767458674596746067461674626746367464674656746667467674686746967470674716747267473674746747567476674776747867479674806748167482674836748467485674866748767488674896749067491674926749367494674956749667497674986749967500675016750267503675046750567506675076750867509675106751167512675136751467515675166751767518675196752067521675226752367524675256752667527675286752967530675316753267533675346753567536675376753867539675406754167542675436754467545675466754767548675496755067551675526755367554675556755667557675586755967560675616756267563675646756567566675676756867569675706757167572675736757467575675766757767578675796758067581675826758367584675856758667587675886758967590675916759267593675946759567596675976759867599676006760167602676036760467605676066760767608676096761067611676126761367614676156761667617676186761967620676216762267623676246762567626676276762867629676306763167632676336763467635676366763767638676396764067641676426764367644676456764667647676486764967650676516765267653676546765567656676576765867659676606766167662676636766467665676666766767668676696767067671676726767367674676756767667677676786767967680676816768267683676846768567686676876768867689676906769167692676936769467695676966769767698676996770067701677026770367704677056770667707677086770967710677116771267713677146771567716677176771867719677206772167722677236772467725677266772767728677296773067731677326773367734677356773667737677386773967740677416774267743677446774567746677476774867749677506775167752677536775467755677566775767758677596776067761677626776367764677656776667767677686776967770677716777267773677746777567776677776777867779677806778167782677836778467785677866778767788677896779067791677926779367794677956779667797677986779967800678016780267803678046780567806678076780867809678106781167812678136781467815678166781767818678196782067821678226782367824678256782667827678286782967830678316783267833678346783567836678376783867839678406784167842678436784467845678466784767848678496785067851678526785367854678556785667857678586785967860678616786267863678646786567866678676786867869678706787167872678736787467875678766787767878678796788067881678826788367884678856788667887678886788967890678916789267893678946789567896678976789867899679006790167902679036790467905679066790767908679096791067911679126791367914679156791667917679186791967920679216792267923679246792567926679276792867929679306793167932679336793467935679366793767938679396794067941679426794367944679456794667947679486794967950679516795267953679546795567956679576795867959679606796167962679636796467965679666796767968679696797067971679726797367974679756797667977679786797967980679816798267983679846798567986679876798867989679906799167992679936799467995679966799767998679996800068001680026800368004680056800668007680086800968010680116801268013680146801568016680176801868019680206802168022680236802468025680266802768028680296803068031680326803368034680356803668037680386803968040680416804268043680446804568046680476804868049680506805168052680536805468055680566805768058680596806068061680626806368064680656806668067680686806968070680716807268073680746807568076680776807868079680806808168082680836808468085680866808768088680896809068091680926809368094680956809668097680986809968100681016810268103681046810568106681076810868109681106811168112681136811468115681166811768118681196812068121681226812368124681256812668127681286812968130681316813268133681346813568136681376813868139681406814168142681436814468145681466814768148681496815068151681526815368154681556815668157681586815968160681616816268163681646816568166681676816868169681706817168172681736817468175681766817768178681796818068181681826818368184681856818668187681886818968190681916819268193681946819568196681976819868199682006820168202682036820468205682066820768208682096821068211682126821368214682156821668217682186821968220682216822268223682246822568226682276822868229682306823168232682336823468235682366823768238682396824068241682426824368244682456824668247682486824968250682516825268253682546825568256682576825868259682606826168262682636826468265682666826768268682696827068271682726827368274682756827668277682786827968280682816828268283682846828568286682876828868289682906829168292682936829468295682966829768298682996830068301683026830368304683056830668307683086830968310683116831268313683146831568316683176831868319683206832168322683236832468325683266832768328683296833068331683326833368334683356833668337683386833968340683416834268343683446834568346683476834868349683506835168352683536835468355683566835768358683596836068361683626836368364683656836668367683686836968370683716837268373683746837568376683776837868379683806838168382683836838468385683866838768388683896839068391683926839368394683956839668397683986839968400684016840268403684046840568406684076840868409684106841168412684136841468415684166841768418684196842068421684226842368424684256842668427684286842968430684316843268433684346843568436684376843868439684406844168442684436844468445684466844768448684496845068451684526845368454684556845668457684586845968460684616846268463684646846568466684676846868469684706847168472684736847468475684766847768478684796848068481684826848368484684856848668487684886848968490684916849268493684946849568496684976849868499685006850168502685036850468505685066850768508685096851068511685126851368514685156851668517685186851968520685216852268523685246852568526685276852868529685306853168532685336853468535685366853768538685396854068541685426854368544685456854668547685486854968550685516855268553685546855568556685576855868559685606856168562685636856468565685666856768568685696857068571685726857368574685756857668577685786857968580685816858268583685846858568586685876858868589685906859168592685936859468595685966859768598685996860068601686026860368604686056860668607686086860968610686116861268613686146861568616686176861868619686206862168622686236862468625686266862768628686296863068631686326863368634686356863668637686386863968640686416864268643686446864568646686476864868649686506865168652686536865468655686566865768658686596866068661686626866368664686656866668667686686866968670686716867268673686746867568676686776867868679686806868168682686836868468685686866868768688686896869068691686926869368694686956869668697686986869968700687016870268703687046870568706687076870868709687106871168712687136871468715687166871768718687196872068721687226872368724687256872668727687286872968730687316873268733687346873568736687376873868739687406874168742687436874468745687466874768748687496875068751687526875368754687556875668757687586875968760687616876268763687646876568766687676876868769687706877168772687736877468775687766877768778687796878068781687826878368784687856878668787687886878968790687916879268793687946879568796687976879868799688006880168802688036880468805688066880768808688096881068811688126881368814688156881668817688186881968820688216882268823688246882568826688276882868829688306883168832688336883468835688366883768838688396884068841688426884368844688456884668847688486884968850688516885268853688546885568856688576885868859688606886168862688636886468865688666886768868688696887068871688726887368874688756887668877688786887968880688816888268883688846888568886688876888868889688906889168892688936889468895688966889768898688996890068901689026890368904689056890668907689086890968910689116891268913689146891568916689176891868919689206892168922689236892468925689266892768928689296893068931689326893368934689356893668937689386893968940689416894268943689446894568946689476894868949689506895168952689536895468955689566895768958689596896068961689626896368964689656896668967689686896968970689716897268973689746897568976689776897868979689806898168982689836898468985689866898768988689896899068991689926899368994689956899668997689986899969000690016900269003690046900569006690076900869009690106901169012690136901469015690166901769018690196902069021690226902369024690256902669027690286902969030690316903269033690346903569036690376903869039690406904169042690436904469045690466904769048690496905069051690526905369054690556905669057690586905969060690616906269063690646906569066690676906869069690706907169072690736907469075690766907769078690796908069081690826908369084690856908669087690886908969090690916909269093690946909569096690976909869099691006910169102691036910469105691066910769108691096911069111691126911369114691156911669117691186911969120691216912269123691246912569126691276912869129691306913169132691336913469135691366913769138691396914069141691426914369144691456914669147691486914969150691516915269153691546915569156691576915869159691606916169162691636916469165691666916769168691696917069171691726917369174691756917669177691786917969180691816918269183691846918569186691876918869189691906919169192691936919469195691966919769198691996920069201692026920369204692056920669207692086920969210692116921269213692146921569216692176921869219692206922169222692236922469225692266922769228692296923069231692326923369234692356923669237692386923969240692416924269243692446924569246692476924869249692506925169252692536925469255692566925769258692596926069261692626926369264692656926669267692686926969270692716927269273692746927569276692776927869279692806928169282692836928469285692866928769288692896929069291692926929369294692956929669297692986929969300693016930269303693046930569306693076930869309693106931169312693136931469315693166931769318693196932069321693226932369324693256932669327693286932969330693316933269333693346933569336693376933869339693406934169342693436934469345693466934769348693496935069351693526935369354693556935669357693586935969360693616936269363693646936569366693676936869369693706937169372693736937469375693766937769378693796938069381693826938369384693856938669387693886938969390693916939269393693946939569396693976939869399694006940169402694036940469405694066940769408694096941069411694126941369414694156941669417694186941969420694216942269423694246942569426694276942869429694306943169432694336943469435694366943769438694396944069441694426944369444694456944669447694486944969450694516945269453694546945569456694576945869459694606946169462694636946469465694666946769468694696947069471694726947369474694756947669477694786947969480694816948269483694846948569486694876948869489694906949169492694936949469495694966949769498694996950069501695026950369504695056950669507695086950969510695116951269513695146951569516695176951869519695206952169522695236952469525695266952769528695296953069531695326953369534695356953669537695386953969540695416954269543695446954569546695476954869549695506955169552695536955469555695566955769558695596956069561695626956369564695656956669567695686956969570695716957269573695746957569576695776957869579695806958169582695836958469585695866958769588695896959069591695926959369594695956959669597695986959969600696016960269603696046960569606696076960869609696106961169612696136961469615696166961769618696196962069621696226962369624696256962669627696286962969630696316963269633696346963569636696376963869639696406964169642696436964469645696466964769648696496965069651696526965369654696556965669657696586965969660696616966269663696646966569666696676966869669696706967169672696736967469675696766967769678696796968069681696826968369684696856968669687696886968969690696916969269693696946969569696696976969869699697006970169702697036970469705697066970769708697096971069711697126971369714697156971669717697186971969720697216972269723697246972569726697276972869729697306973169732697336973469735697366973769738697396974069741697426974369744697456974669747697486974969750697516975269753697546975569756697576975869759697606976169762697636976469765697666976769768697696977069771697726977369774697756977669777697786977969780697816978269783697846978569786697876978869789697906979169792697936979469795697966979769798697996980069801698026980369804698056980669807698086980969810698116981269813698146981569816698176981869819698206982169822698236982469825698266982769828698296983069831698326983369834698356983669837698386983969840698416984269843698446984569846698476984869849698506985169852698536985469855698566985769858698596986069861698626986369864698656986669867698686986969870698716987269873698746987569876698776987869879698806988169882698836988469885698866988769888698896989069891698926989369894698956989669897698986989969900699016990269903699046990569906699076990869909699106991169912699136991469915699166991769918699196992069921699226992369924699256992669927699286992969930699316993269933699346993569936699376993869939699406994169942699436994469945699466994769948699496995069951699526995369954699556995669957699586995969960699616996269963699646996569966699676996869969699706997169972699736997469975699766997769978699796998069981699826998369984699856998669987699886998969990699916999269993699946999569996699976999869999700007000170002700037000470005700067000770008700097001070011700127001370014700157001670017700187001970020700217002270023700247002570026700277002870029700307003170032700337003470035700367003770038700397004070041700427004370044700457004670047700487004970050700517005270053700547005570056700577005870059700607006170062700637006470065700667006770068700697007070071700727007370074700757007670077700787007970080700817008270083700847008570086700877008870089700907009170092700937009470095700967009770098700997010070101701027010370104701057010670107701087010970110701117011270113701147011570116701177011870119701207012170122701237012470125701267012770128701297013070131701327013370134701357013670137701387013970140701417014270143701447014570146701477014870149701507015170152701537015470155701567015770158701597016070161701627016370164701657016670167701687016970170701717017270173701747017570176701777017870179701807018170182701837018470185701867018770188701897019070191701927019370194701957019670197701987019970200702017020270203702047020570206702077020870209702107021170212702137021470215702167021770218702197022070221702227022370224702257022670227702287022970230702317023270233702347023570236702377023870239702407024170242702437024470245702467024770248702497025070251702527025370254702557025670257702587025970260702617026270263702647026570266702677026870269702707027170272702737027470275702767027770278702797028070281702827028370284702857028670287702887028970290702917029270293702947029570296702977029870299703007030170302703037030470305703067030770308703097031070311703127031370314703157031670317703187031970320703217032270323703247032570326703277032870329703307033170332703337033470335703367033770338703397034070341703427034370344703457034670347703487034970350703517035270353703547035570356703577035870359703607036170362703637036470365703667036770368703697037070371703727037370374703757037670377703787037970380703817038270383703847038570386703877038870389703907039170392703937039470395703967039770398703997040070401704027040370404704057040670407704087040970410704117041270413704147041570416704177041870419704207042170422704237042470425704267042770428704297043070431704327043370434704357043670437704387043970440704417044270443704447044570446704477044870449704507045170452704537045470455704567045770458704597046070461704627046370464704657046670467704687046970470704717047270473704747047570476704777047870479704807048170482704837048470485704867048770488704897049070491704927049370494704957049670497704987049970500705017050270503705047050570506705077050870509705107051170512705137051470515705167051770518705197052070521705227052370524705257052670527705287052970530705317053270533705347053570536705377053870539705407054170542705437054470545705467054770548705497055070551705527055370554705557055670557705587055970560705617056270563705647056570566705677056870569705707057170572705737057470575705767057770578705797058070581705827058370584705857058670587705887058970590705917059270593705947059570596705977059870599706007060170602706037060470605706067060770608706097061070611706127061370614706157061670617706187061970620706217062270623706247062570626706277062870629706307063170632706337063470635706367063770638706397064070641706427064370644706457064670647706487064970650706517065270653706547065570656706577065870659706607066170662706637066470665706667066770668706697067070671706727067370674706757067670677706787067970680706817068270683706847068570686706877068870689706907069170692706937069470695706967069770698706997070070701707027070370704707057070670707707087070970710707117071270713707147071570716707177071870719707207072170722707237072470725707267072770728707297073070731707327073370734707357073670737707387073970740707417074270743707447074570746707477074870749707507075170752707537075470755707567075770758707597076070761707627076370764707657076670767707687076970770707717077270773707747077570776707777077870779707807078170782707837078470785707867078770788707897079070791707927079370794707957079670797707987079970800708017080270803708047080570806708077080870809708107081170812708137081470815708167081770818708197082070821708227082370824708257082670827708287082970830708317083270833708347083570836708377083870839708407084170842708437084470845708467084770848708497085070851708527085370854708557085670857708587085970860708617086270863708647086570866708677086870869708707087170872708737087470875708767087770878708797088070881708827088370884708857088670887708887088970890708917089270893708947089570896708977089870899709007090170902709037090470905709067090770908709097091070911709127091370914709157091670917709187091970920709217092270923709247092570926709277092870929709307093170932709337093470935709367093770938709397094070941709427094370944709457094670947709487094970950709517095270953709547095570956709577095870959709607096170962709637096470965709667096770968709697097070971709727097370974709757097670977709787097970980709817098270983709847098570986709877098870989709907099170992709937099470995709967099770998709997100071001710027100371004710057100671007710087100971010710117101271013710147101571016710177101871019710207102171022710237102471025710267102771028710297103071031710327103371034710357103671037710387103971040710417104271043710447104571046710477104871049710507105171052710537105471055710567105771058710597106071061710627106371064710657106671067710687106971070710717107271073710747107571076710777107871079710807108171082710837108471085710867108771088710897109071091710927109371094710957109671097710987109971100711017110271103711047110571106711077110871109711107111171112711137111471115711167111771118711197112071121711227112371124711257112671127711287112971130711317113271133711347113571136711377113871139711407114171142711437114471145711467114771148711497115071151711527115371154711557115671157711587115971160711617116271163711647116571166711677116871169711707117171172711737117471175711767117771178711797118071181711827118371184711857118671187711887118971190711917119271193711947119571196711977119871199712007120171202712037120471205712067120771208712097121071211712127121371214712157121671217712187121971220712217122271223712247122571226712277122871229712307123171232712337123471235712367123771238712397124071241712427124371244712457124671247712487124971250712517125271253712547125571256712577125871259712607126171262712637126471265712667126771268712697127071271712727127371274712757127671277712787127971280712817128271283712847128571286712877128871289712907129171292712937129471295712967129771298712997130071301713027130371304713057130671307713087130971310713117131271313713147131571316713177131871319713207132171322713237132471325713267132771328713297133071331713327133371334713357133671337713387133971340713417134271343713447134571346713477134871349713507135171352713537135471355713567135771358713597136071361713627136371364713657136671367713687136971370713717137271373713747137571376713777137871379713807138171382713837138471385713867138771388713897139071391713927139371394713957139671397713987139971400714017140271403714047140571406714077140871409714107141171412714137141471415714167141771418714197142071421714227142371424714257142671427714287142971430714317143271433714347143571436714377143871439714407144171442714437144471445714467144771448714497145071451714527145371454714557145671457714587145971460714617146271463714647146571466714677146871469714707147171472714737147471475714767147771478714797148071481714827148371484714857148671487714887148971490714917149271493714947149571496714977149871499715007150171502715037150471505715067150771508715097151071511715127151371514715157151671517715187151971520715217152271523715247152571526715277152871529715307153171532715337153471535715367153771538715397154071541715427154371544715457154671547715487154971550715517155271553715547155571556715577155871559715607156171562715637156471565715667156771568715697157071571715727157371574715757157671577715787157971580715817158271583715847158571586715877158871589715907159171592715937159471595715967159771598715997160071601716027160371604716057160671607716087160971610716117161271613716147161571616716177161871619716207162171622716237162471625716267162771628716297163071631716327163371634716357163671637716387163971640716417164271643716447164571646716477164871649716507165171652716537165471655716567165771658716597166071661716627166371664716657166671667716687166971670716717167271673716747167571676716777167871679716807168171682716837168471685716867168771688716897169071691716927169371694716957169671697716987169971700717017170271703717047170571706717077170871709717107171171712717137171471715717167171771718717197172071721717227172371724717257172671727717287172971730717317173271733717347173571736717377173871739717407174171742717437174471745717467174771748717497175071751717527175371754717557175671757717587175971760717617176271763717647176571766717677176871769717707177171772717737177471775717767177771778717797178071781717827178371784717857178671787717887178971790717917179271793717947179571796717977179871799718007180171802718037180471805718067180771808718097181071811718127181371814718157181671817718187181971820718217182271823718247182571826718277182871829718307183171832718337183471835718367183771838718397184071841718427184371844718457184671847718487184971850718517185271853718547185571856718577185871859718607186171862718637186471865718667186771868718697187071871718727187371874718757187671877718787187971880718817188271883718847188571886718877188871889718907189171892718937189471895718967189771898718997190071901719027190371904719057190671907719087190971910719117191271913719147191571916719177191871919719207192171922719237192471925719267192771928719297193071931719327193371934719357193671937719387193971940719417194271943719447194571946719477194871949719507195171952719537195471955719567195771958719597196071961719627196371964719657196671967719687196971970719717197271973719747197571976719777197871979719807198171982719837198471985719867198771988719897199071991719927199371994719957199671997719987199972000720017200272003720047200572006720077200872009720107201172012720137201472015720167201772018720197202072021720227202372024720257202672027720287202972030720317203272033720347203572036720377203872039720407204172042720437204472045720467204772048720497205072051720527205372054720557205672057720587205972060720617206272063720647206572066720677206872069720707207172072720737207472075720767207772078720797208072081720827208372084720857208672087720887208972090720917209272093720947209572096720977209872099721007210172102721037210472105721067210772108721097211072111721127211372114721157211672117721187211972120721217212272123721247212572126721277212872129721307213172132721337213472135721367213772138721397214072141721427214372144721457214672147721487214972150721517215272153721547215572156721577215872159721607216172162721637216472165721667216772168721697217072171721727217372174721757217672177721787217972180721817218272183721847218572186721877218872189721907219172192721937219472195721967219772198721997220072201722027220372204722057220672207722087220972210722117221272213722147221572216722177221872219722207222172222722237222472225722267222772228722297223072231722327223372234722357223672237722387223972240722417224272243722447224572246722477224872249722507225172252722537225472255722567225772258722597226072261722627226372264722657226672267722687226972270722717227272273722747227572276722777227872279722807228172282722837228472285722867228772288722897229072291722927229372294722957229672297722987229972300723017230272303723047230572306723077230872309723107231172312723137231472315723167231772318723197232072321723227232372324723257232672327723287232972330723317233272333723347233572336723377233872339723407234172342723437234472345723467234772348723497235072351723527235372354723557235672357723587235972360723617236272363723647236572366723677236872369723707237172372723737237472375723767237772378723797238072381723827238372384723857238672387723887238972390723917239272393723947239572396723977239872399724007240172402724037240472405724067240772408724097241072411724127241372414724157241672417724187241972420724217242272423724247242572426724277242872429724307243172432724337243472435724367243772438724397244072441724427244372444724457244672447724487244972450724517245272453724547245572456724577245872459724607246172462724637246472465724667246772468724697247072471724727247372474724757247672477724787247972480724817248272483724847248572486724877248872489724907249172492724937249472495724967249772498724997250072501725027250372504725057250672507725087250972510725117251272513725147251572516725177251872519725207252172522725237252472525725267252772528725297253072531725327253372534725357253672537725387253972540725417254272543725447254572546725477254872549725507255172552725537255472555725567255772558725597256072561725627256372564725657256672567725687256972570725717257272573725747257572576725777257872579725807258172582725837258472585725867258772588725897259072591725927259372594725957259672597725987259972600726017260272603726047260572606726077260872609726107261172612726137261472615726167261772618726197262072621726227262372624726257262672627726287262972630726317263272633726347263572636726377263872639726407264172642726437264472645726467264772648726497265072651726527265372654726557265672657726587265972660726617266272663726647266572666726677266872669726707267172672726737267472675726767267772678726797268072681726827268372684726857268672687726887268972690726917269272693726947269572696726977269872699727007270172702727037270472705727067270772708727097271072711727127271372714727157271672717727187271972720727217272272723727247272572726727277272872729727307273172732727337273472735727367273772738727397274072741727427274372744727457274672747727487274972750727517275272753727547275572756727577275872759727607276172762727637276472765727667276772768727697277072771727727277372774727757277672777727787277972780727817278272783727847278572786727877278872789727907279172792727937279472795727967279772798727997280072801728027280372804728057280672807728087280972810728117281272813728147281572816728177281872819728207282172822728237282472825728267282772828728297283072831728327283372834728357283672837728387283972840728417284272843728447284572846728477284872849728507285172852728537285472855728567285772858728597286072861728627286372864728657286672867728687286972870728717287272873728747287572876728777287872879728807288172882728837288472885728867288772888728897289072891728927289372894728957289672897728987289972900729017290272903729047290572906729077290872909729107291172912729137291472915729167291772918729197292072921729227292372924729257292672927729287292972930729317293272933729347293572936729377293872939729407294172942729437294472945729467294772948729497295072951729527295372954729557295672957729587295972960729617296272963729647296572966729677296872969729707297172972729737297472975729767297772978729797298072981729827298372984729857298672987729887298972990729917299272993729947299572996729977299872999730007300173002730037300473005730067300773008730097301073011730127301373014730157301673017730187301973020730217302273023730247302573026730277302873029730307303173032730337303473035730367303773038730397304073041730427304373044730457304673047730487304973050730517305273053730547305573056730577305873059730607306173062730637306473065730667306773068730697307073071730727307373074730757307673077730787307973080730817308273083730847308573086730877308873089730907309173092730937309473095730967309773098730997310073101731027310373104731057310673107731087310973110731117311273113731147311573116731177311873119731207312173122731237312473125731267312773128731297313073131731327313373134731357313673137731387313973140731417314273143731447314573146731477314873149731507315173152731537315473155731567315773158731597316073161731627316373164731657316673167731687316973170731717317273173731747317573176731777317873179731807318173182731837318473185731867318773188731897319073191731927319373194731957319673197731987319973200732017320273203732047320573206732077320873209732107321173212732137321473215732167321773218732197322073221732227322373224732257322673227732287322973230732317323273233732347323573236732377323873239732407324173242732437324473245732467324773248732497325073251732527325373254732557325673257732587325973260732617326273263732647326573266732677326873269732707327173272732737327473275732767327773278732797328073281732827328373284732857328673287732887328973290732917329273293732947329573296732977329873299733007330173302733037330473305733067330773308733097331073311733127331373314733157331673317733187331973320733217332273323733247332573326733277332873329733307333173332733337333473335733367333773338733397334073341733427334373344733457334673347733487334973350733517335273353733547335573356733577335873359733607336173362733637336473365733667336773368733697337073371733727337373374733757337673377733787337973380733817338273383733847338573386733877338873389733907339173392733937339473395733967339773398733997340073401734027340373404734057340673407734087340973410734117341273413734147341573416734177341873419734207342173422734237342473425734267342773428734297343073431734327343373434734357343673437734387343973440734417344273443734447344573446734477344873449734507345173452734537345473455734567345773458734597346073461734627346373464734657346673467734687346973470734717347273473734747347573476734777347873479734807348173482734837348473485734867348773488734897349073491734927349373494734957349673497734987349973500735017350273503735047350573506735077350873509735107351173512735137351473515735167351773518735197352073521735227352373524735257352673527735287352973530735317353273533735347353573536735377353873539735407354173542735437354473545735467354773548735497355073551735527355373554735557355673557735587355973560735617356273563735647356573566735677356873569735707357173572735737357473575735767357773578735797358073581735827358373584735857358673587735887358973590735917359273593735947359573596735977359873599736007360173602736037360473605736067360773608736097361073611736127361373614736157361673617736187361973620736217362273623736247362573626736277362873629736307363173632736337363473635736367363773638736397364073641736427364373644736457364673647736487364973650736517365273653736547365573656736577365873659736607366173662736637366473665736667366773668736697367073671736727367373674736757367673677736787367973680736817368273683736847368573686736877368873689736907369173692736937369473695736967369773698736997370073701737027370373704737057370673707737087370973710737117371273713737147371573716737177371873719737207372173722737237372473725737267372773728737297373073731737327373373734737357373673737737387373973740737417374273743737447374573746737477374873749737507375173752737537375473755737567375773758737597376073761737627376373764737657376673767737687376973770737717377273773737747377573776737777377873779737807378173782737837378473785737867378773788737897379073791737927379373794737957379673797737987379973800738017380273803738047380573806738077380873809738107381173812738137381473815738167381773818738197382073821738227382373824738257382673827738287382973830738317383273833738347383573836738377383873839738407384173842738437384473845738467384773848738497385073851738527385373854738557385673857738587385973860738617386273863738647386573866738677386873869738707387173872738737387473875738767387773878738797388073881738827388373884738857388673887738887388973890738917389273893738947389573896738977389873899739007390173902739037390473905739067390773908739097391073911739127391373914739157391673917739187391973920739217392273923739247392573926739277392873929739307393173932739337393473935739367393773938739397394073941739427394373944739457394673947739487394973950739517395273953739547395573956739577395873959739607396173962739637396473965739667396773968739697397073971739727397373974739757397673977739787397973980739817398273983739847398573986739877398873989739907399173992739937399473995739967399773998739997400074001740027400374004740057400674007740087400974010740117401274013740147401574016740177401874019740207402174022740237402474025740267402774028740297403074031740327403374034740357403674037740387403974040740417404274043740447404574046740477404874049740507405174052740537405474055740567405774058740597406074061740627406374064740657406674067740687406974070740717407274073740747407574076740777407874079740807408174082740837408474085740867408774088740897409074091740927409374094740957409674097740987409974100741017410274103741047410574106741077410874109741107411174112741137411474115741167411774118741197412074121741227412374124741257412674127741287412974130741317413274133741347413574136741377413874139741407414174142741437414474145741467414774148741497415074151741527415374154741557415674157741587415974160741617416274163741647416574166741677416874169741707417174172741737417474175741767417774178741797418074181741827418374184741857418674187741887418974190741917419274193741947419574196741977419874199742007420174202742037420474205742067420774208742097421074211742127421374214742157421674217742187421974220742217422274223742247422574226742277422874229742307423174232742337423474235742367423774238742397424074241742427424374244742457424674247742487424974250742517425274253742547425574256742577425874259742607426174262742637426474265742667426774268742697427074271742727427374274742757427674277742787427974280742817428274283742847428574286742877428874289742907429174292742937429474295742967429774298742997430074301743027430374304743057430674307743087430974310743117431274313743147431574316743177431874319743207432174322743237432474325743267432774328743297433074331743327433374334743357433674337743387433974340743417434274343743447434574346743477434874349743507435174352743537435474355743567435774358743597436074361743627436374364743657436674367743687436974370743717437274373743747437574376743777437874379743807438174382743837438474385743867438774388743897439074391743927439374394743957439674397743987439974400744017440274403744047440574406744077440874409744107441174412744137441474415744167441774418744197442074421744227442374424744257442674427744287442974430744317443274433744347443574436744377443874439744407444174442744437444474445744467444774448744497445074451744527445374454744557445674457744587445974460744617446274463744647446574466744677446874469744707447174472744737447474475744767447774478744797448074481744827448374484744857448674487744887448974490744917449274493744947449574496744977449874499745007450174502745037450474505745067450774508745097451074511745127451374514745157451674517745187451974520745217452274523745247452574526745277452874529745307453174532745337453474535745367453774538745397454074541745427454374544745457454674547745487454974550745517455274553745547455574556745577455874559745607456174562745637456474565745667456774568745697457074571745727457374574745757457674577745787457974580745817458274583745847458574586745877458874589745907459174592745937459474595745967459774598745997460074601746027460374604746057460674607746087460974610746117461274613746147461574616746177461874619746207462174622746237462474625746267462774628746297463074631746327463374634746357463674637746387463974640746417464274643746447464574646746477464874649746507465174652746537465474655746567465774658746597466074661746627466374664746657466674667746687466974670746717467274673746747467574676746777467874679746807468174682746837468474685746867468774688746897469074691746927469374694746957469674697746987469974700747017470274703747047470574706747077470874709747107471174712747137471474715747167471774718747197472074721747227472374724747257472674727747287472974730747317473274733747347473574736747377473874739747407474174742747437474474745747467474774748747497475074751747527475374754747557475674757747587475974760747617476274763747647476574766747677476874769747707477174772747737477474775747767477774778747797478074781747827478374784747857478674787747887478974790747917479274793747947479574796747977479874799748007480174802748037480474805748067480774808748097481074811748127481374814748157481674817748187481974820748217482274823748247482574826748277482874829748307483174832748337483474835748367483774838748397484074841748427484374844748457484674847748487484974850748517485274853748547485574856748577485874859748607486174862748637486474865748667486774868748697487074871748727487374874748757487674877748787487974880748817488274883748847488574886748877488874889748907489174892748937489474895748967489774898748997490074901749027490374904749057490674907749087490974910749117491274913749147491574916749177491874919749207492174922749237492474925749267492774928749297493074931749327493374934749357493674937749387493974940749417494274943749447494574946749477494874949749507495174952749537495474955749567495774958749597496074961749627496374964749657496674967749687496974970749717497274973749747497574976749777497874979749807498174982749837498474985749867498774988749897499074991749927499374994749957499674997749987499975000750017500275003750047500575006750077500875009750107501175012750137501475015750167501775018750197502075021750227502375024750257502675027750287502975030750317503275033750347503575036750377503875039750407504175042750437504475045750467504775048750497505075051750527505375054750557505675057750587505975060750617506275063750647506575066750677506875069750707507175072750737507475075750767507775078750797508075081750827508375084750857508675087750887508975090750917509275093750947509575096750977509875099751007510175102751037510475105751067510775108751097511075111751127511375114751157511675117751187511975120751217512275123751247512575126751277512875129751307513175132751337513475135751367513775138751397514075141751427514375144751457514675147751487514975150751517515275153751547515575156751577515875159751607516175162751637516475165751667516775168751697517075171751727517375174751757517675177751787517975180751817518275183751847518575186751877518875189751907519175192751937519475195751967519775198751997520075201752027520375204752057520675207752087520975210752117521275213752147521575216752177521875219752207522175222752237522475225752267522775228752297523075231752327523375234752357523675237752387523975240752417524275243752447524575246752477524875249752507525175252752537525475255752567525775258752597526075261752627526375264752657526675267752687526975270752717527275273752747527575276752777527875279752807528175282752837528475285752867528775288752897529075291752927529375294752957529675297752987529975300753017530275303753047530575306753077530875309753107531175312753137531475315753167531775318753197532075321753227532375324753257532675327753287532975330753317533275333753347533575336753377533875339753407534175342753437534475345753467534775348753497535075351753527535375354753557535675357753587535975360753617536275363753647536575366753677536875369753707537175372753737537475375753767537775378753797538075381753827538375384753857538675387753887538975390753917539275393753947539575396753977539875399754007540175402754037540475405754067540775408754097541075411754127541375414754157541675417754187541975420754217542275423754247542575426754277542875429754307543175432754337543475435754367543775438754397544075441754427544375444754457544675447754487544975450754517545275453754547545575456754577545875459754607546175462754637546475465754667546775468754697547075471754727547375474754757547675477754787547975480754817548275483754847548575486754877548875489754907549175492754937549475495754967549775498754997550075501755027550375504755057550675507755087550975510755117551275513755147551575516755177551875519755207552175522755237552475525755267552775528755297553075531755327553375534755357553675537755387553975540755417554275543755447554575546755477554875549755507555175552755537555475555755567555775558755597556075561755627556375564755657556675567755687556975570755717557275573755747557575576755777557875579755807558175582755837558475585755867558775588755897559075591755927559375594755957559675597755987559975600756017560275603756047560575606756077560875609756107561175612756137561475615756167561775618756197562075621756227562375624756257562675627756287562975630756317563275633756347563575636756377563875639756407564175642756437564475645756467564775648756497565075651756527565375654756557565675657756587565975660756617566275663756647566575666756677566875669756707567175672756737567475675756767567775678756797568075681756827568375684756857568675687756887568975690756917569275693756947569575696756977569875699757007570175702757037570475705757067570775708757097571075711757127571375714757157571675717757187571975720757217572275723757247572575726757277572875729757307573175732757337573475735757367573775738757397574075741757427574375744757457574675747757487574975750757517575275753757547575575756757577575875759757607576175762757637576475765757667576775768757697577075771757727577375774757757577675777757787577975780757817578275783757847578575786757877578875789757907579175792757937579475795757967579775798757997580075801758027580375804758057580675807758087580975810758117581275813758147581575816758177581875819758207582175822758237582475825758267582775828758297583075831758327583375834758357583675837758387583975840758417584275843758447584575846758477584875849758507585175852758537585475855758567585775858758597586075861758627586375864758657586675867758687586975870758717587275873758747587575876758777587875879758807588175882758837588475885758867588775888758897589075891758927589375894758957589675897758987589975900759017590275903759047590575906759077590875909759107591175912759137591475915759167591775918759197592075921759227592375924759257592675927759287592975930759317593275933759347593575936759377593875939759407594175942759437594475945759467594775948759497595075951759527595375954759557595675957759587595975960759617596275963759647596575966759677596875969759707597175972759737597475975759767597775978759797598075981759827598375984759857598675987759887598975990759917599275993759947599575996759977599875999760007600176002760037600476005760067600776008760097601076011760127601376014760157601676017760187601976020760217602276023760247602576026760277602876029760307603176032760337603476035760367603776038760397604076041760427604376044760457604676047760487604976050760517605276053760547605576056760577605876059760607606176062760637606476065760667606776068760697607076071760727607376074760757607676077760787607976080760817608276083760847608576086760877608876089760907609176092760937609476095760967609776098760997610076101761027610376104761057610676107761087610976110761117611276113761147611576116761177611876119761207612176122761237612476125761267612776128761297613076131761327613376134761357613676137761387613976140761417614276143761447614576146761477614876149761507615176152761537615476155761567615776158761597616076161761627616376164761657616676167761687616976170761717617276173761747617576176761777617876179761807618176182761837618476185761867618776188761897619076191761927619376194761957619676197761987619976200762017620276203762047620576206762077620876209762107621176212762137621476215762167621776218762197622076221762227622376224762257622676227762287622976230762317623276233762347623576236762377623876239762407624176242762437624476245762467624776248762497625076251762527625376254762557625676257762587625976260762617626276263762647626576266762677626876269762707627176272762737627476275762767627776278762797628076281762827628376284762857628676287762887628976290762917629276293762947629576296762977629876299763007630176302763037630476305763067630776308763097631076311763127631376314763157631676317763187631976320763217632276323763247632576326763277632876329763307633176332763337633476335763367633776338763397634076341763427634376344763457634676347763487634976350763517635276353763547635576356763577635876359763607636176362763637636476365763667636776368763697637076371763727637376374763757637676377763787637976380763817638276383763847638576386763877638876389763907639176392763937639476395763967639776398763997640076401764027640376404764057640676407764087640976410764117641276413764147641576416764177641876419764207642176422764237642476425764267642776428764297643076431764327643376434764357643676437764387643976440764417644276443764447644576446764477644876449764507645176452764537645476455764567645776458764597646076461764627646376464764657646676467764687646976470764717647276473764747647576476764777647876479764807648176482764837648476485764867648776488764897649076491764927649376494764957649676497764987649976500765017650276503765047650576506765077650876509765107651176512765137651476515765167651776518765197652076521765227652376524765257652676527765287652976530765317653276533765347653576536765377653876539765407654176542765437654476545765467654776548765497655076551765527655376554765557655676557765587655976560765617656276563765647656576566765677656876569765707657176572765737657476575765767657776578765797658076581765827658376584765857658676587765887658976590765917659276593765947659576596765977659876599766007660176602766037660476605766067660776608766097661076611766127661376614766157661676617766187661976620766217662276623766247662576626766277662876629766307663176632766337663476635766367663776638766397664076641766427664376644766457664676647766487664976650766517665276653766547665576656766577665876659766607666176662766637666476665766667666776668766697667076671766727667376674766757667676677766787667976680766817668276683766847668576686766877668876689766907669176692766937669476695766967669776698766997670076701767027670376704767057670676707767087670976710767117671276713767147671576716767177671876719767207672176722767237672476725767267672776728767297673076731767327673376734767357673676737767387673976740767417674276743767447674576746767477674876749767507675176752767537675476755767567675776758767597676076761767627676376764767657676676767767687676976770767717677276773767747677576776767777677876779767807678176782767837678476785767867678776788767897679076791767927679376794767957679676797767987679976800768017680276803768047680576806768077680876809768107681176812768137681476815768167681776818768197682076821768227682376824768257682676827768287682976830768317683276833768347683576836768377683876839768407684176842768437684476845768467684776848768497685076851768527685376854768557685676857768587685976860768617686276863768647686576866768677686876869768707687176872768737687476875768767687776878768797688076881768827688376884768857688676887768887688976890768917689276893768947689576896768977689876899769007690176902769037690476905769067690776908769097691076911769127691376914769157691676917769187691976920769217692276923769247692576926769277692876929769307693176932769337693476935769367693776938769397694076941769427694376944769457694676947769487694976950769517695276953769547695576956769577695876959769607696176962769637696476965769667696776968769697697076971769727697376974769757697676977769787697976980769817698276983769847698576986769877698876989769907699176992769937699476995769967699776998769997700077001770027700377004770057700677007770087700977010770117701277013770147701577016770177701877019770207702177022770237702477025770267702777028770297703077031770327703377034770357703677037770387703977040770417704277043770447704577046770477704877049770507705177052770537705477055770567705777058770597706077061770627706377064770657706677067770687706977070770717707277073770747707577076770777707877079770807708177082770837708477085770867708777088770897709077091770927709377094770957709677097770987709977100771017710277103771047710577106771077710877109771107711177112771137711477115771167711777118771197712077121771227712377124771257712677127771287712977130771317713277133771347713577136771377713877139771407714177142771437714477145771467714777148771497715077151771527715377154771557715677157771587715977160771617716277163771647716577166771677716877169771707717177172771737717477175771767717777178771797718077181771827718377184771857718677187771887718977190771917719277193771947719577196771977719877199772007720177202772037720477205772067720777208772097721077211772127721377214772157721677217772187721977220772217722277223772247722577226772277722877229772307723177232772337723477235772367723777238772397724077241772427724377244772457724677247772487724977250772517725277253772547725577256772577725877259772607726177262772637726477265772667726777268772697727077271772727727377274772757727677277772787727977280772817728277283772847728577286772877728877289772907729177292772937729477295772967729777298772997730077301773027730377304773057730677307773087730977310773117731277313773147731577316773177731877319773207732177322773237732477325773267732777328773297733077331773327733377334773357733677337773387733977340773417734277343773447734577346773477734877349773507735177352773537735477355773567735777358773597736077361773627736377364773657736677367773687736977370773717737277373773747737577376773777737877379773807738177382773837738477385773867738777388773897739077391773927739377394773957739677397773987739977400774017740277403774047740577406774077740877409774107741177412774137741477415774167741777418774197742077421774227742377424774257742677427774287742977430774317743277433774347743577436774377743877439774407744177442774437744477445774467744777448774497745077451774527745377454774557745677457774587745977460774617746277463774647746577466774677746877469774707747177472774737747477475774767747777478774797748077481774827748377484774857748677487774887748977490774917749277493774947749577496774977749877499775007750177502775037750477505775067750777508775097751077511775127751377514775157751677517775187751977520775217752277523775247752577526775277752877529775307753177532775337753477535775367753777538775397754077541775427754377544775457754677547775487754977550775517755277553775547755577556775577755877559775607756177562775637756477565775667756777568775697757077571775727757377574775757757677577775787757977580775817758277583775847758577586775877758877589775907759177592775937759477595775967759777598775997760077601776027760377604776057760677607776087760977610776117761277613776147761577616776177761877619776207762177622776237762477625776267762777628776297763077631776327763377634776357763677637776387763977640776417764277643776447764577646776477764877649776507765177652776537765477655776567765777658776597766077661776627766377664776657766677667776687766977670776717767277673776747767577676776777767877679776807768177682776837768477685776867768777688776897769077691776927769377694776957769677697776987769977700777017770277703777047770577706777077770877709777107771177712777137771477715777167771777718777197772077721777227772377724777257772677727777287772977730777317773277733777347773577736777377773877739777407774177742777437774477745777467774777748777497775077751777527775377754777557775677757777587775977760777617776277763777647776577766777677776877769777707777177772777737777477775777767777777778777797778077781777827778377784777857778677787777887778977790777917779277793777947779577796777977779877799778007780177802778037780477805778067780777808778097781077811778127781377814778157781677817778187781977820778217782277823778247782577826778277782877829778307783177832778337783477835778367783777838778397784077841778427784377844778457784677847778487784977850778517785277853778547785577856778577785877859778607786177862778637786477865778667786777868778697787077871778727787377874778757787677877778787787977880778817788277883778847788577886778877788877889778907789177892778937789477895778967789777898778997790077901779027790377904779057790677907779087790977910779117791277913779147791577916779177791877919779207792177922779237792477925779267792777928779297793077931779327793377934779357793677937779387793977940779417794277943779447794577946779477794877949779507795177952779537795477955779567795777958779597796077961779627796377964779657796677967779687796977970779717797277973779747797577976779777797877979779807798177982779837798477985779867798777988779897799077991779927799377994779957799677997779987799978000780017800278003780047800578006780077800878009780107801178012780137801478015780167801778018780197802078021780227802378024780257802678027780287802978030780317803278033780347803578036780377803878039780407804178042780437804478045780467804778048780497805078051780527805378054780557805678057780587805978060780617806278063780647806578066780677806878069780707807178072780737807478075780767807778078780797808078081780827808378084780857808678087780887808978090780917809278093780947809578096780977809878099781007810178102781037810478105781067810778108781097811078111781127811378114781157811678117781187811978120781217812278123781247812578126781277812878129781307813178132781337813478135781367813778138781397814078141781427814378144781457814678147781487814978150781517815278153781547815578156781577815878159781607816178162781637816478165781667816778168781697817078171781727817378174781757817678177781787817978180781817818278183781847818578186781877818878189781907819178192781937819478195781967819778198781997820078201782027820378204782057820678207782087820978210782117821278213782147821578216782177821878219782207822178222782237822478225782267822778228782297823078231782327823378234782357823678237782387823978240782417824278243782447824578246782477824878249782507825178252782537825478255782567825778258782597826078261782627826378264782657826678267782687826978270782717827278273782747827578276782777827878279782807828178282782837828478285782867828778288782897829078291782927829378294782957829678297782987829978300783017830278303783047830578306783077830878309783107831178312783137831478315783167831778318783197832078321783227832378324783257832678327783287832978330783317833278333783347833578336783377833878339783407834178342783437834478345783467834778348783497835078351783527835378354783557835678357783587835978360783617836278363783647836578366783677836878369783707837178372783737837478375783767837778378783797838078381783827838378384783857838678387783887838978390783917839278393783947839578396783977839878399784007840178402784037840478405784067840778408784097841078411784127841378414784157841678417784187841978420784217842278423784247842578426784277842878429784307843178432784337843478435784367843778438784397844078441784427844378444784457844678447784487844978450784517845278453784547845578456784577845878459784607846178462784637846478465784667846778468784697847078471784727847378474784757847678477784787847978480784817848278483784847848578486784877848878489784907849178492784937849478495784967849778498784997850078501785027850378504785057850678507785087850978510785117851278513785147851578516785177851878519785207852178522785237852478525785267852778528785297853078531785327853378534785357853678537785387853978540785417854278543785447854578546785477854878549785507855178552785537855478555785567855778558785597856078561785627856378564785657856678567785687856978570785717857278573785747857578576785777857878579785807858178582785837858478585785867858778588785897859078591785927859378594785957859678597785987859978600786017860278603786047860578606786077860878609786107861178612786137861478615786167861778618786197862078621786227862378624786257862678627786287862978630786317863278633786347863578636786377863878639786407864178642786437864478645786467864778648786497865078651786527865378654786557865678657786587865978660786617866278663786647866578666786677866878669786707867178672786737867478675786767867778678786797868078681786827868378684786857868678687786887868978690786917869278693786947869578696786977869878699787007870178702787037870478705787067870778708787097871078711787127871378714787157871678717787187871978720787217872278723787247872578726787277872878729787307873178732787337873478735787367873778738787397874078741787427874378744787457874678747787487874978750787517875278753787547875578756787577875878759787607876178762787637876478765787667876778768787697877078771787727877378774787757877678777787787877978780787817878278783787847878578786787877878878789787907879178792787937879478795787967879778798787997880078801788027880378804788057880678807788087880978810788117881278813788147881578816788177881878819788207882178822788237882478825788267882778828788297883078831788327883378834788357883678837788387883978840788417884278843788447884578846788477884878849788507885178852788537885478855788567885778858788597886078861788627886378864788657886678867788687886978870788717887278873788747887578876788777887878879788807888178882788837888478885788867888778888788897889078891788927889378894788957889678897788987889978900789017890278903789047890578906789077890878909789107891178912789137891478915789167891778918789197892078921789227892378924789257892678927789287892978930789317893278933789347893578936789377893878939789407894178942789437894478945789467894778948789497895078951789527895378954789557895678957789587895978960789617896278963789647896578966789677896878969789707897178972789737897478975789767897778978789797898078981789827898378984789857898678987789887898978990789917899278993789947899578996789977899878999790007900179002790037900479005790067900779008790097901079011790127901379014790157901679017790187901979020790217902279023790247902579026790277902879029790307903179032790337903479035790367903779038790397904079041790427904379044790457904679047790487904979050790517905279053790547905579056790577905879059790607906179062790637906479065790667906779068790697907079071790727907379074790757907679077790787907979080790817908279083790847908579086790877908879089790907909179092790937909479095790967909779098790997910079101791027910379104791057910679107791087910979110791117911279113791147911579116791177911879119791207912179122791237912479125791267912779128791297913079131791327913379134791357913679137791387913979140791417914279143791447914579146791477914879149791507915179152791537915479155791567915779158791597916079161791627916379164791657916679167791687916979170791717917279173791747917579176791777917879179791807918179182791837918479185791867918779188791897919079191791927919379194791957919679197791987919979200792017920279203792047920579206792077920879209792107921179212792137921479215792167921779218792197922079221792227922379224792257922679227792287922979230792317923279233792347923579236792377923879239792407924179242792437924479245792467924779248792497925079251792527925379254792557925679257792587925979260792617926279263792647926579266792677926879269792707927179272792737927479275792767927779278792797928079281792827928379284792857928679287792887928979290792917929279293792947929579296792977929879299793007930179302793037930479305793067930779308793097931079311793127931379314793157931679317793187931979320793217932279323793247932579326793277932879329793307933179332793337933479335793367933779338793397934079341793427934379344793457934679347793487934979350793517935279353793547935579356793577935879359793607936179362793637936479365793667936779368793697937079371793727937379374793757937679377793787937979380793817938279383793847938579386793877938879389793907939179392793937939479395793967939779398793997940079401794027940379404794057940679407794087940979410794117941279413794147941579416794177941879419794207942179422794237942479425794267942779428794297943079431794327943379434794357943679437794387943979440794417944279443794447944579446794477944879449794507945179452794537945479455794567945779458794597946079461794627946379464794657946679467794687946979470794717947279473794747947579476794777947879479794807948179482794837948479485794867948779488794897949079491794927949379494794957949679497794987949979500795017950279503795047950579506795077950879509795107951179512795137951479515795167951779518795197952079521795227952379524795257952679527795287952979530795317953279533795347953579536795377953879539795407954179542795437954479545795467954779548795497955079551795527955379554795557955679557795587955979560795617956279563795647956579566795677956879569795707957179572795737957479575795767957779578795797958079581795827958379584795857958679587795887958979590795917959279593795947959579596795977959879599796007960179602796037960479605796067960779608796097961079611796127961379614796157961679617796187961979620796217962279623796247962579626796277962879629796307963179632796337963479635796367963779638796397964079641796427964379644796457964679647796487964979650796517965279653796547965579656796577965879659796607966179662796637966479665796667966779668796697967079671796727967379674796757967679677796787967979680796817968279683796847968579686796877968879689796907969179692796937969479695796967969779698796997970079701797027970379704797057970679707797087970979710797117971279713797147971579716797177971879719797207972179722797237972479725797267972779728797297973079731797327973379734797357973679737797387973979740797417974279743797447974579746797477974879749797507975179752797537975479755797567975779758797597976079761797627976379764797657976679767797687976979770797717977279773797747977579776797777977879779797807978179782797837978479785797867978779788797897979079791797927979379794797957979679797797987979979800798017980279803798047980579806798077980879809798107981179812798137981479815798167981779818798197982079821798227982379824798257982679827798287982979830798317983279833798347983579836798377983879839798407984179842798437984479845798467984779848798497985079851798527985379854798557985679857798587985979860798617986279863798647986579866798677986879869798707987179872798737987479875798767987779878798797988079881798827988379884798857988679887798887988979890798917989279893798947989579896798977989879899799007990179902799037990479905799067990779908799097991079911799127991379914799157991679917799187991979920799217992279923799247992579926799277992879929799307993179932799337993479935799367993779938799397994079941799427994379944799457994679947799487994979950799517995279953799547995579956799577995879959799607996179962799637996479965799667996779968799697997079971799727997379974799757997679977799787997979980799817998279983799847998579986799877998879989799907999179992799937999479995799967999779998799998000080001800028000380004800058000680007800088000980010800118001280013800148001580016800178001880019800208002180022800238002480025800268002780028800298003080031800328003380034800358003680037800388003980040800418004280043800448004580046800478004880049800508005180052800538005480055800568005780058800598006080061800628006380064800658006680067800688006980070800718007280073800748007580076800778007880079800808008180082800838008480085800868008780088800898009080091800928009380094800958009680097800988009980100801018010280103801048010580106801078010880109801108011180112801138011480115801168011780118801198012080121801228012380124801258012680127801288012980130801318013280133801348013580136801378013880139801408014180142801438014480145801468014780148801498015080151801528015380154801558015680157801588015980160801618016280163801648016580166801678016880169801708017180172801738017480175801768017780178801798018080181801828018380184801858018680187801888018980190801918019280193801948019580196801978019880199802008020180202802038020480205802068020780208802098021080211802128021380214802158021680217802188021980220802218022280223802248022580226802278022880229802308023180232802338023480235802368023780238802398024080241802428024380244802458024680247802488024980250802518025280253802548025580256802578025880259802608026180262802638026480265802668026780268802698027080271802728027380274802758027680277802788027980280802818028280283802848028580286802878028880289802908029180292802938029480295802968029780298802998030080301803028030380304803058030680307803088030980310803118031280313803148031580316803178031880319803208032180322803238032480325803268032780328803298033080331803328033380334803358033680337803388033980340803418034280343803448034580346803478034880349803508035180352803538035480355803568035780358803598036080361803628036380364803658036680367803688036980370803718037280373803748037580376803778037880379803808038180382803838038480385803868038780388803898039080391803928039380394803958039680397803988039980400804018040280403804048040580406804078040880409804108041180412804138041480415804168041780418804198042080421804228042380424804258042680427804288042980430804318043280433804348043580436804378043880439804408044180442804438044480445804468044780448804498045080451804528045380454804558045680457804588045980460804618046280463804648046580466804678046880469804708047180472804738047480475804768047780478804798048080481804828048380484804858048680487804888048980490804918049280493804948049580496804978049880499805008050180502805038050480505805068050780508805098051080511805128051380514805158051680517805188051980520805218052280523805248052580526805278052880529805308053180532805338053480535805368053780538805398054080541805428054380544805458054680547805488054980550805518055280553805548055580556805578055880559805608056180562805638056480565805668056780568805698057080571805728057380574805758057680577805788057980580805818058280583805848058580586805878058880589805908059180592805938059480595805968059780598805998060080601806028060380604806058060680607806088060980610806118061280613806148061580616806178061880619806208062180622806238062480625806268062780628806298063080631806328063380634806358063680637806388063980640806418064280643806448064580646806478064880649806508065180652806538065480655806568065780658806598066080661806628066380664806658066680667806688066980670806718067280673806748067580676806778067880679806808068180682806838068480685806868068780688806898069080691806928069380694806958069680697806988069980700807018070280703807048070580706807078070880709807108071180712807138071480715807168071780718807198072080721807228072380724807258072680727807288072980730807318073280733807348073580736807378073880739807408074180742807438074480745807468074780748807498075080751807528075380754807558075680757807588075980760807618076280763807648076580766807678076880769807708077180772807738077480775807768077780778807798078080781807828078380784807858078680787807888078980790807918079280793807948079580796807978079880799808008080180802808038080480805808068080780808808098081080811808128081380814808158081680817808188081980820808218082280823808248082580826808278082880829808308083180832808338083480835808368083780838808398084080841808428084380844808458084680847808488084980850808518085280853808548085580856808578085880859808608086180862808638086480865808668086780868808698087080871808728087380874808758087680877808788087980880808818088280883808848088580886808878088880889808908089180892808938089480895808968089780898808998090080901809028090380904809058090680907809088090980910809118091280913809148091580916809178091880919809208092180922809238092480925809268092780928809298093080931809328093380934809358093680937809388093980940809418094280943809448094580946809478094880949809508095180952809538095480955809568095780958809598096080961809628096380964809658096680967809688096980970809718097280973809748097580976809778097880979809808098180982809838098480985809868098780988809898099080991809928099380994809958099680997809988099981000810018100281003810048100581006810078100881009810108101181012810138101481015810168101781018810198102081021810228102381024810258102681027810288102981030810318103281033810348103581036810378103881039810408104181042810438104481045810468104781048810498105081051810528105381054810558105681057810588105981060810618106281063810648106581066810678106881069810708107181072810738107481075810768107781078810798108081081810828108381084810858108681087810888108981090810918109281093810948109581096810978109881099811008110181102811038110481105811068110781108811098111081111811128111381114811158111681117811188111981120811218112281123811248112581126811278112881129811308113181132811338113481135811368113781138811398114081141811428114381144811458114681147811488114981150811518115281153811548115581156811578115881159811608116181162811638116481165811668116781168811698117081171811728117381174811758117681177811788117981180811818118281183811848118581186811878118881189811908119181192811938119481195811968119781198811998120081201812028120381204812058120681207812088120981210812118121281213812148121581216812178121881219812208122181222812238122481225812268122781228812298123081231812328123381234812358123681237812388123981240812418124281243812448124581246812478124881249812508125181252812538125481255812568125781258812598126081261812628126381264812658126681267812688126981270812718127281273812748127581276812778127881279812808128181282812838128481285812868128781288812898129081291812928129381294812958129681297812988129981300813018130281303813048130581306813078130881309813108131181312813138131481315813168131781318813198132081321813228132381324813258132681327813288132981330813318133281333813348133581336813378133881339813408134181342813438134481345813468134781348813498135081351813528135381354813558135681357813588135981360813618136281363813648136581366813678136881369813708137181372813738137481375813768137781378813798138081381813828138381384813858138681387813888138981390813918139281393813948139581396813978139881399814008140181402814038140481405814068140781408814098141081411814128141381414814158141681417814188141981420814218142281423814248142581426814278142881429814308143181432814338143481435814368143781438814398144081441814428144381444814458144681447814488144981450814518145281453814548145581456814578145881459814608146181462814638146481465814668146781468814698147081471814728147381474814758147681477814788147981480814818148281483814848148581486814878148881489814908149181492814938149481495814968149781498814998150081501815028150381504815058150681507815088150981510815118151281513815148151581516815178151881519815208152181522815238152481525815268152781528815298153081531815328153381534815358153681537815388153981540815418154281543815448154581546815478154881549815508155181552815538155481555815568155781558815598156081561815628156381564815658156681567815688156981570815718157281573815748157581576815778157881579815808158181582815838158481585815868158781588815898159081591815928159381594815958159681597815988159981600816018160281603816048160581606816078160881609816108161181612816138161481615816168161781618816198162081621816228162381624816258162681627816288162981630816318163281633816348163581636816378163881639816408164181642816438164481645816468164781648816498165081651816528165381654816558165681657816588165981660816618166281663816648166581666816678166881669816708167181672816738167481675816768167781678816798168081681816828168381684816858168681687816888168981690816918169281693816948169581696816978169881699817008170181702817038170481705817068170781708817098171081711817128171381714817158171681717817188171981720817218172281723817248172581726817278172881729817308173181732817338173481735817368173781738817398174081741817428174381744817458174681747817488174981750817518175281753817548175581756817578175881759817608176181762817638176481765817668176781768817698177081771817728177381774817758177681777817788177981780817818178281783817848178581786817878178881789817908179181792817938179481795817968179781798817998180081801818028180381804818058180681807818088180981810818118181281813818148181581816818178181881819818208182181822818238182481825818268182781828818298183081831818328183381834818358183681837818388183981840818418184281843818448184581846818478184881849818508185181852818538185481855818568185781858818598186081861818628186381864818658186681867818688186981870818718187281873818748187581876818778187881879818808188181882818838188481885818868188781888818898189081891818928189381894818958189681897818988189981900819018190281903819048190581906819078190881909819108191181912819138191481915819168191781918819198192081921819228192381924819258192681927819288192981930819318193281933819348193581936819378193881939819408194181942819438194481945819468194781948819498195081951819528195381954819558195681957819588195981960819618196281963819648196581966819678196881969819708197181972819738197481975819768197781978819798198081981819828198381984819858198681987819888198981990819918199281993819948199581996819978199881999820008200182002820038200482005820068200782008820098201082011820128201382014820158201682017820188201982020820218202282023820248202582026820278202882029820308203182032820338203482035820368203782038820398204082041820428204382044820458204682047820488204982050820518205282053820548205582056820578205882059820608206182062820638206482065820668206782068820698207082071820728207382074820758207682077820788207982080820818208282083820848208582086820878208882089820908209182092820938209482095820968209782098820998210082101821028210382104821058210682107821088210982110821118211282113821148211582116821178211882119821208212182122821238212482125821268212782128821298213082131821328213382134821358213682137821388213982140821418214282143821448214582146821478214882149821508215182152821538215482155821568215782158821598216082161821628216382164821658216682167821688216982170821718217282173821748217582176821778217882179821808218182182821838218482185821868218782188821898219082191821928219382194821958219682197821988219982200822018220282203822048220582206822078220882209822108221182212822138221482215822168221782218822198222082221822228222382224822258222682227822288222982230822318223282233822348223582236822378223882239822408224182242822438224482245822468224782248822498225082251822528225382254822558225682257822588225982260822618226282263822648226582266822678226882269822708227182272822738227482275822768227782278822798228082281822828228382284822858228682287822888228982290822918229282293822948229582296822978229882299823008230182302823038230482305823068230782308823098231082311823128231382314823158231682317823188231982320823218232282323823248232582326823278232882329823308233182332823338233482335823368233782338823398234082341823428234382344823458234682347823488234982350823518235282353823548235582356823578235882359823608236182362823638236482365823668236782368823698237082371823728237382374823758237682377823788237982380823818238282383823848238582386823878238882389823908239182392823938239482395823968239782398823998240082401824028240382404824058240682407824088240982410824118241282413824148241582416824178241882419824208242182422824238242482425824268242782428824298243082431824328243382434824358243682437824388243982440824418244282443824448244582446824478244882449824508245182452824538245482455824568245782458824598246082461824628246382464824658246682467824688246982470824718247282473824748247582476824778247882479824808248182482824838248482485824868248782488824898249082491824928249382494824958249682497824988249982500825018250282503825048250582506825078250882509825108251182512825138251482515825168251782518825198252082521825228252382524825258252682527825288252982530825318253282533825348253582536825378253882539825408254182542825438254482545825468254782548825498255082551825528255382554825558255682557825588255982560825618256282563825648256582566825678256882569825708257182572825738257482575825768257782578825798258082581825828258382584825858258682587825888258982590825918259282593825948259582596825978259882599826008260182602826038260482605826068260782608826098261082611826128261382614826158261682617826188261982620826218262282623826248262582626826278262882629826308263182632826338263482635826368263782638826398264082641826428264382644826458264682647826488264982650826518265282653826548265582656826578265882659826608266182662826638266482665826668266782668826698267082671826728267382674826758267682677826788267982680826818268282683826848268582686826878268882689826908269182692826938269482695826968269782698826998270082701827028270382704827058270682707827088270982710827118271282713827148271582716827178271882719827208272182722827238272482725827268272782728827298273082731827328273382734827358273682737827388273982740827418274282743827448274582746827478274882749827508275182752827538275482755827568275782758827598276082761827628276382764827658276682767827688276982770827718277282773827748277582776827778277882779827808278182782827838278482785827868278782788827898279082791827928279382794827958279682797827988279982800828018280282803828048280582806828078280882809828108281182812828138281482815828168281782818828198282082821828228282382824828258282682827828288282982830828318283282833828348283582836828378283882839828408284182842828438284482845828468284782848828498285082851828528285382854828558285682857828588285982860828618286282863828648286582866828678286882869828708287182872828738287482875828768287782878828798288082881828828288382884828858288682887828888288982890828918289282893828948289582896828978289882899829008290182902829038290482905829068290782908829098291082911829128291382914829158291682917829188291982920829218292282923829248292582926829278292882929829308293182932829338293482935829368293782938829398294082941829428294382944829458294682947829488294982950829518295282953829548295582956829578295882959829608296182962829638296482965829668296782968829698297082971829728297382974829758297682977829788297982980829818298282983829848298582986829878298882989829908299182992829938299482995829968299782998829998300083001830028300383004830058300683007830088300983010830118301283013830148301583016830178301883019830208302183022830238302483025830268302783028830298303083031830328303383034830358303683037830388303983040830418304283043830448304583046830478304883049830508305183052830538305483055830568305783058830598306083061830628306383064830658306683067830688306983070830718307283073830748307583076830778307883079830808308183082830838308483085830868308783088830898309083091830928309383094830958309683097830988309983100831018310283103831048310583106831078310883109831108311183112831138311483115831168311783118831198312083121831228312383124831258312683127831288312983130831318313283133831348313583136831378313883139831408314183142831438314483145831468314783148831498315083151831528315383154831558315683157831588315983160831618316283163831648316583166831678316883169831708317183172831738317483175831768317783178831798318083181831828318383184831858318683187831888318983190831918319283193831948319583196831978319883199832008320183202832038320483205832068320783208832098321083211832128321383214832158321683217832188321983220832218322283223832248322583226832278322883229832308323183232832338323483235832368323783238832398324083241832428324383244832458324683247832488324983250832518325283253832548325583256832578325883259832608326183262832638326483265832668326783268832698327083271832728327383274832758327683277832788327983280832818328283283832848328583286832878328883289832908329183292832938329483295832968329783298832998330083301833028330383304833058330683307833088330983310833118331283313833148331583316833178331883319833208332183322833238332483325833268332783328833298333083331833328333383334833358333683337833388333983340833418334283343833448334583346833478334883349833508335183352833538335483355833568335783358833598336083361833628336383364833658336683367833688336983370833718337283373833748337583376833778337883379833808338183382833838338483385833868338783388833898339083391833928339383394833958339683397833988339983400834018340283403834048340583406834078340883409834108341183412834138341483415834168341783418834198342083421834228342383424834258342683427834288342983430834318343283433834348343583436834378343883439834408344183442834438344483445834468344783448834498345083451834528345383454834558345683457834588345983460834618346283463834648346583466834678346883469834708347183472834738347483475834768347783478834798348083481834828348383484834858348683487834888348983490834918349283493834948349583496834978349883499835008350183502835038350483505835068350783508835098351083511835128351383514835158351683517835188351983520835218352283523835248352583526835278352883529835308353183532835338353483535835368353783538835398354083541835428354383544835458354683547835488354983550835518355283553835548355583556835578355883559835608356183562835638356483565835668356783568835698357083571835728357383574835758357683577835788357983580835818358283583835848358583586835878358883589835908359183592835938359483595835968359783598835998360083601836028360383604836058360683607836088360983610836118361283613836148361583616836178361883619836208362183622836238362483625836268362783628836298363083631836328363383634836358363683637836388363983640836418364283643836448364583646836478364883649836508365183652836538365483655836568365783658836598366083661836628366383664836658366683667836688366983670836718367283673836748367583676836778367883679836808368183682836838368483685836868368783688836898369083691836928369383694836958369683697836988369983700837018370283703837048370583706837078370883709837108371183712837138371483715837168371783718837198372083721837228372383724837258372683727837288372983730837318373283733837348373583736837378373883739837408374183742837438374483745837468374783748837498375083751837528375383754837558375683757837588375983760837618376283763837648376583766837678376883769837708377183772837738377483775837768377783778837798378083781837828378383784837858378683787837888378983790837918379283793837948379583796837978379883799838008380183802838038380483805838068380783808838098381083811838128381383814838158381683817838188381983820838218382283823838248382583826838278382883829838308383183832838338383483835838368383783838838398384083841838428384383844838458384683847838488384983850838518385283853838548385583856838578385883859838608386183862838638386483865838668386783868838698387083871838728387383874838758387683877838788387983880838818388283883838848388583886838878388883889838908389183892838938389483895838968389783898838998390083901839028390383904839058390683907839088390983910839118391283913839148391583916839178391883919839208392183922839238392483925839268392783928839298393083931839328393383934839358393683937839388393983940839418394283943839448394583946839478394883949839508395183952839538395483955839568395783958839598396083961839628396383964839658396683967839688396983970839718397283973839748397583976839778397883979839808398183982839838398483985839868398783988839898399083991839928399383994839958399683997839988399984000840018400284003840048400584006840078400884009840108401184012840138401484015840168401784018840198402084021840228402384024840258402684027840288402984030840318403284033840348403584036840378403884039840408404184042840438404484045840468404784048840498405084051840528405384054840558405684057840588405984060840618406284063840648406584066840678406884069840708407184072840738407484075840768407784078840798408084081840828408384084840858408684087840888408984090840918409284093840948409584096840978409884099841008410184102841038410484105841068410784108841098411084111841128411384114841158411684117841188411984120841218412284123841248412584126841278412884129841308413184132841338413484135841368413784138841398414084141841428414384144841458414684147841488414984150841518415284153841548415584156841578415884159841608416184162841638416484165841668416784168841698417084171841728417384174841758417684177841788417984180841818418284183841848418584186841878418884189841908419184192841938419484195841968419784198841998420084201842028420384204842058420684207842088420984210842118421284213842148421584216842178421884219842208422184222842238422484225842268422784228842298423084231842328423384234842358423684237842388423984240842418424284243842448424584246842478424884249842508425184252842538425484255842568425784258842598426084261842628426384264842658426684267842688426984270842718427284273842748427584276842778427884279842808428184282842838428484285842868428784288842898429084291842928429384294842958429684297842988429984300843018430284303843048430584306843078430884309843108431184312843138431484315843168431784318843198432084321843228432384324843258432684327843288432984330843318433284333843348433584336843378433884339843408434184342843438434484345843468434784348843498435084351843528435384354843558435684357843588435984360843618436284363843648436584366843678436884369843708437184372843738437484375843768437784378843798438084381843828438384384843858438684387843888438984390843918439284393843948439584396843978439884399844008440184402844038440484405844068440784408844098441084411844128441384414844158441684417844188441984420844218442284423844248442584426844278442884429844308443184432844338443484435844368443784438844398444084441844428444384444844458444684447844488444984450844518445284453844548445584456844578445884459844608446184462844638446484465844668446784468844698447084471844728447384474844758447684477844788447984480844818448284483844848448584486844878448884489844908449184492844938449484495844968449784498844998450084501845028450384504845058450684507845088450984510845118451284513845148451584516845178451884519845208452184522845238452484525845268452784528845298453084531845328453384534845358453684537845388453984540845418454284543845448454584546845478454884549845508455184552845538455484555845568455784558845598456084561845628456384564845658456684567845688456984570845718457284573845748457584576845778457884579845808458184582845838458484585845868458784588845898459084591845928459384594845958459684597845988459984600846018460284603846048460584606846078460884609846108461184612846138461484615846168461784618846198462084621846228462384624846258462684627846288462984630846318463284633846348463584636846378463884639846408464184642846438464484645846468464784648846498465084651846528465384654846558465684657846588465984660846618466284663846648466584666846678466884669846708467184672846738467484675846768467784678846798468084681846828468384684846858468684687846888468984690846918469284693846948469584696846978469884699847008470184702847038470484705847068470784708847098471084711847128471384714847158471684717847188471984720847218472284723847248472584726847278472884729847308473184732847338473484735847368473784738847398474084741847428474384744847458474684747847488474984750847518475284753847548475584756847578475884759847608476184762847638476484765847668476784768847698477084771847728477384774847758477684777847788477984780847818478284783847848478584786847878478884789847908479184792847938479484795847968479784798847998480084801848028480384804848058480684807848088480984810848118481284813848148481584816848178481884819848208482184822848238482484825848268482784828848298483084831848328483384834848358483684837848388483984840848418484284843848448484584846848478484884849848508485184852848538485484855848568485784858848598486084861848628486384864848658486684867848688486984870848718487284873848748487584876848778487884879848808488184882848838488484885848868488784888848898489084891848928489384894848958489684897848988489984900849018490284903849048490584906849078490884909849108491184912849138491484915849168491784918849198492084921849228492384924849258492684927849288492984930849318493284933849348493584936849378493884939849408494184942849438494484945849468494784948849498495084951849528495384954849558495684957849588495984960849618496284963849648496584966849678496884969849708497184972849738497484975849768497784978849798498084981849828498384984849858498684987849888498984990849918499284993849948499584996849978499884999850008500185002850038500485005850068500785008850098501085011850128501385014850158501685017850188501985020850218502285023850248502585026850278502885029850308503185032850338503485035850368503785038850398504085041850428504385044850458504685047850488504985050850518505285053850548505585056850578505885059850608506185062850638506485065850668506785068850698507085071850728507385074850758507685077850788507985080850818508285083850848508585086850878508885089850908509185092850938509485095850968509785098850998510085101851028510385104851058510685107851088510985110851118511285113851148511585116851178511885119851208512185122851238512485125851268512785128851298513085131851328513385134851358513685137851388513985140851418514285143851448514585146851478514885149851508515185152851538515485155851568515785158851598516085161851628516385164851658516685167851688516985170851718517285173851748517585176851778517885179851808518185182851838518485185851868518785188851898519085191851928519385194851958519685197851988519985200852018520285203852048520585206852078520885209852108521185212852138521485215852168521785218852198522085221852228522385224852258522685227852288522985230852318523285233852348523585236852378523885239852408524185242852438524485245852468524785248852498525085251852528525385254852558525685257852588525985260852618526285263852648526585266852678526885269852708527185272852738527485275852768527785278852798528085281852828528385284852858528685287852888528985290852918529285293852948529585296852978529885299853008530185302853038530485305853068530785308853098531085311853128531385314853158531685317853188531985320853218532285323853248532585326853278532885329853308533185332853338533485335853368533785338853398534085341853428534385344853458534685347853488534985350853518535285353853548535585356853578535885359853608536185362853638536485365853668536785368853698537085371853728537385374853758537685377853788537985380853818538285383853848538585386853878538885389853908539185392853938539485395853968539785398853998540085401854028540385404854058540685407854088540985410854118541285413854148541585416854178541885419854208542185422854238542485425854268542785428854298543085431854328543385434854358543685437854388543985440854418544285443854448544585446854478544885449854508545185452854538545485455854568545785458854598546085461854628546385464854658546685467854688546985470854718547285473854748547585476854778547885479854808548185482854838548485485854868548785488854898549085491854928549385494854958549685497854988549985500855018550285503855048550585506855078550885509855108551185512855138551485515855168551785518855198552085521855228552385524855258552685527855288552985530855318553285533855348553585536855378553885539855408554185542855438554485545855468554785548855498555085551855528555385554855558555685557855588555985560855618556285563855648556585566855678556885569855708557185572855738557485575855768557785578855798558085581855828558385584855858558685587855888558985590855918559285593855948559585596855978559885599856008560185602856038560485605856068560785608856098561085611856128561385614856158561685617856188561985620856218562285623856248562585626856278562885629856308563185632856338563485635856368563785638856398564085641856428564385644856458564685647856488564985650856518565285653856548565585656856578565885659856608566185662856638566485665856668566785668856698567085671856728567385674856758567685677856788567985680856818568285683856848568585686856878568885689856908569185692856938569485695856968569785698856998570085701857028570385704857058570685707857088570985710857118571285713857148571585716857178571885719857208572185722857238572485725857268572785728857298573085731857328573385734857358573685737857388573985740857418574285743857448574585746857478574885749857508575185752857538575485755857568575785758857598576085761857628576385764857658576685767857688576985770857718577285773857748577585776857778577885779857808578185782857838578485785857868578785788857898579085791857928579385794857958579685797857988579985800858018580285803858048580585806858078580885809858108581185812858138581485815858168581785818858198582085821858228582385824858258582685827858288582985830858318583285833858348583585836858378583885839858408584185842858438584485845858468584785848858498585085851858528585385854858558585685857858588585985860858618586285863858648586585866858678586885869858708587185872858738587485875858768587785878858798588085881858828588385884858858588685887858888588985890858918589285893858948589585896858978589885899859008590185902859038590485905859068590785908859098591085911859128591385914859158591685917859188591985920859218592285923859248592585926859278592885929859308593185932859338593485935859368593785938859398594085941859428594385944859458594685947859488594985950859518595285953859548595585956859578595885959859608596185962859638596485965859668596785968859698597085971859728597385974859758597685977859788597985980859818598285983859848598585986859878598885989859908599185992859938599485995859968599785998859998600086001860028600386004860058600686007860088600986010860118601286013860148601586016860178601886019860208602186022860238602486025860268602786028860298603086031860328603386034860358603686037860388603986040860418604286043860448604586046860478604886049860508605186052860538605486055860568605786058860598606086061860628606386064860658606686067860688606986070860718607286073860748607586076860778607886079860808608186082860838608486085860868608786088860898609086091860928609386094860958609686097860988609986100861018610286103861048610586106861078610886109861108611186112861138611486115861168611786118861198612086121861228612386124861258612686127861288612986130861318613286133861348613586136861378613886139861408614186142861438614486145861468614786148861498615086151861528615386154861558615686157861588615986160861618616286163861648616586166861678616886169861708617186172861738617486175861768617786178861798618086181861828618386184861858618686187861888618986190861918619286193861948619586196861978619886199862008620186202862038620486205862068620786208862098621086211862128621386214862158621686217862188621986220862218622286223862248622586226862278622886229862308623186232862338623486235862368623786238862398624086241862428624386244862458624686247862488624986250862518625286253862548625586256862578625886259862608626186262862638626486265862668626786268862698627086271862728627386274862758627686277862788627986280862818628286283862848628586286862878628886289862908629186292862938629486295862968629786298862998630086301863028630386304863058630686307863088630986310863118631286313863148631586316863178631886319863208632186322863238632486325863268632786328863298633086331863328633386334863358633686337863388633986340863418634286343863448634586346863478634886349863508635186352863538635486355863568635786358863598636086361863628636386364863658636686367863688636986370863718637286373863748637586376863778637886379863808638186382863838638486385863868638786388863898639086391863928639386394863958639686397863988639986400864018640286403864048640586406864078640886409864108641186412864138641486415864168641786418864198642086421864228642386424864258642686427864288642986430864318643286433864348643586436864378643886439864408644186442864438644486445864468644786448864498645086451864528645386454864558645686457864588645986460864618646286463864648646586466864678646886469864708647186472864738647486475864768647786478864798648086481864828648386484864858648686487864888648986490864918649286493864948649586496864978649886499865008650186502865038650486505865068650786508865098651086511865128651386514865158651686517865188651986520865218652286523865248652586526865278652886529865308653186532865338653486535865368653786538865398654086541865428654386544865458654686547865488654986550865518655286553865548655586556865578655886559865608656186562865638656486565865668656786568865698657086571865728657386574865758657686577865788657986580865818658286583865848658586586865878658886589865908659186592865938659486595865968659786598865998660086601866028660386604866058660686607866088660986610866118661286613866148661586616866178661886619866208662186622866238662486625866268662786628866298663086631866328663386634866358663686637866388663986640866418664286643866448664586646866478664886649866508665186652866538665486655866568665786658866598666086661866628666386664866658666686667866688666986670866718667286673866748667586676866778667886679866808668186682866838668486685866868668786688866898669086691866928669386694866958669686697866988669986700867018670286703867048670586706867078670886709867108671186712867138671486715867168671786718867198672086721867228672386724867258672686727867288672986730867318673286733867348673586736867378673886739867408674186742867438674486745867468674786748867498675086751867528675386754867558675686757867588675986760867618676286763867648676586766867678676886769867708677186772867738677486775867768677786778867798678086781867828678386784867858678686787867888678986790867918679286793867948679586796867978679886799868008680186802868038680486805868068680786808868098681086811868128681386814868158681686817868188681986820868218682286823868248682586826868278682886829868308683186832868338683486835868368683786838868398684086841868428684386844868458684686847868488684986850868518685286853868548685586856868578685886859868608686186862868638686486865868668686786868868698687086871868728687386874868758687686877868788687986880868818688286883868848688586886868878688886889868908689186892868938689486895868968689786898868998690086901869028690386904869058690686907869088690986910869118691286913869148691586916869178691886919869208692186922869238692486925869268692786928869298693086931869328693386934869358693686937869388693986940869418694286943869448694586946869478694886949869508695186952869538695486955869568695786958869598696086961869628696386964869658696686967869688696986970869718697286973869748697586976869778697886979869808698186982869838698486985869868698786988869898699086991869928699386994869958699686997869988699987000870018700287003870048700587006870078700887009870108701187012870138701487015870168701787018870198702087021870228702387024870258702687027870288702987030870318703287033870348703587036870378703887039870408704187042870438704487045870468704787048870498705087051870528705387054870558705687057870588705987060870618706287063870648706587066870678706887069870708707187072870738707487075870768707787078870798708087081870828708387084870858708687087870888708987090870918709287093870948709587096870978709887099871008710187102871038710487105871068710787108871098711087111871128711387114871158711687117871188711987120871218712287123871248712587126871278712887129871308713187132871338713487135871368713787138871398714087141871428714387144871458714687147871488714987150871518715287153871548715587156871578715887159871608716187162871638716487165871668716787168871698717087171871728717387174871758717687177871788717987180871818718287183871848718587186871878718887189871908719187192871938719487195871968719787198871998720087201872028720387204872058720687207872088720987210872118721287213872148721587216872178721887219872208722187222872238722487225872268722787228872298723087231872328723387234872358723687237872388723987240872418724287243872448724587246872478724887249872508725187252872538725487255872568725787258872598726087261872628726387264872658726687267872688726987270872718727287273872748727587276872778727887279872808728187282872838728487285872868728787288872898729087291872928729387294872958729687297872988729987300873018730287303873048730587306873078730887309873108731187312873138731487315873168731787318873198732087321873228732387324873258732687327873288732987330873318733287333873348733587336873378733887339873408734187342873438734487345873468734787348873498735087351873528735387354873558735687357873588735987360873618736287363873648736587366873678736887369873708737187372873738737487375873768737787378873798738087381873828738387384873858738687387873888738987390873918739287393873948739587396873978739887399874008740187402874038740487405874068740787408874098741087411874128741387414874158741687417874188741987420874218742287423874248742587426874278742887429874308743187432874338743487435874368743787438874398744087441874428744387444874458744687447874488744987450874518745287453874548745587456874578745887459874608746187462874638746487465874668746787468874698747087471874728747387474874758747687477874788747987480874818748287483874848748587486874878748887489874908749187492874938749487495874968749787498874998750087501875028750387504875058750687507875088750987510875118751287513875148751587516875178751887519875208752187522875238752487525875268752787528875298753087531875328753387534875358753687537875388753987540875418754287543875448754587546875478754887549875508755187552875538755487555875568755787558875598756087561875628756387564875658756687567875688756987570875718757287573875748757587576875778757887579875808758187582875838758487585875868758787588875898759087591875928759387594875958759687597875988759987600876018760287603876048760587606876078760887609876108761187612876138761487615876168761787618876198762087621876228762387624876258762687627876288762987630876318763287633876348763587636876378763887639876408764187642876438764487645876468764787648876498765087651876528765387654876558765687657876588765987660876618766287663876648766587666876678766887669876708767187672876738767487675876768767787678876798768087681876828768387684876858768687687876888768987690876918769287693876948769587696876978769887699877008770187702877038770487705877068770787708877098771087711877128771387714877158771687717877188771987720877218772287723877248772587726877278772887729877308773187732877338773487735877368773787738877398774087741877428774387744877458774687747877488774987750877518775287753877548775587756877578775887759877608776187762877638776487765877668776787768877698777087771877728777387774877758777687777877788777987780877818778287783877848778587786877878778887789877908779187792877938779487795877968779787798877998780087801878028780387804878058780687807878088780987810878118781287813878148781587816878178781887819878208782187822878238782487825878268782787828878298783087831878328783387834878358783687837878388783987840878418784287843878448784587846878478784887849878508785187852878538785487855878568785787858878598786087861878628786387864878658786687867878688786987870878718787287873878748787587876878778787887879878808788187882878838788487885878868788787888878898789087891878928789387894878958789687897878988789987900879018790287903879048790587906879078790887909879108791187912879138791487915879168791787918879198792087921879228792387924879258792687927879288792987930879318793287933879348793587936879378793887939879408794187942879438794487945879468794787948879498795087951879528795387954879558795687957879588795987960879618796287963879648796587966879678796887969879708797187972879738797487975879768797787978879798798087981879828798387984879858798687987879888798987990879918799287993879948799587996879978799887999880008800188002880038800488005880068800788008880098801088011880128801388014880158801688017880188801988020880218802288023880248802588026880278802888029880308803188032880338803488035880368803788038880398804088041880428804388044880458804688047880488804988050880518805288053880548805588056880578805888059880608806188062880638806488065880668806788068880698807088071880728807388074880758807688077880788807988080880818808288083880848808588086880878808888089880908809188092880938809488095880968809788098880998810088101881028810388104881058810688107881088810988110881118811288113881148811588116881178811888119881208812188122881238812488125881268812788128881298813088131881328813388134881358813688137881388813988140881418814288143881448814588146881478814888149881508815188152881538815488155881568815788158881598816088161881628816388164881658816688167881688816988170881718817288173881748817588176881778817888179881808818188182881838818488185881868818788188881898819088191881928819388194881958819688197881988819988200882018820288203882048820588206882078820888209882108821188212882138821488215882168821788218882198822088221882228822388224882258822688227882288822988230882318823288233882348823588236882378823888239882408824188242882438824488245882468824788248882498825088251882528825388254
  1. #!/usr/bin/env php
  2. <?php
  3. /*
  4. * This file is part of the PHP CS utility.
  5. *
  6. * (c) Fabien Potencier <fabien@symfony.com>
  7. * Dariusz Rumiński <dariusz.ruminski@gmail.com>
  8. *
  9. * This source file is subject to the MIT license that is bundled
  10. * with this source code in the file LICENSE.
  11. */
  12. /**
  13. * @author Fabien Potencier <fabien@symfony.com>
  14. * @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
  15. */
  16. if (defined('HHVM_VERSION_ID')) {
  17. fwrite(STDERR, "HHVM is not supported.\n");
  18. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  19. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  20. } else {
  21. exit(1);
  22. }
  23. } elseif (!defined('PHP_VERSION_ID') || PHP_VERSION_ID < 50600 || PHP_VERSION_ID >= 70300) {
  24. fwrite(STDERR, "PHP needs to be a minimum version of PHP 5.6.0 and maximum version of PHP 7.2.*.\n");
  25. if (getenv('PHP_CS_FIXER_IGNORE_ENV')) {
  26. fwrite(STDERR, "Ignoring environment requirements because `PHP_CS_FIXER_IGNORE_ENV` is set. Execution may be unstable.\n");
  27. } else {
  28. exit(1);
  29. }
  30. }
  31. set_error_handler(function ($severity, $message, $file, $line) {
  32. if ($severity & error_reporting()) {
  33. throw new ErrorException($message, 0, $severity, $file, $line);
  34. }
  35. });
  36. try {
  37. // Maybe this file is used as phar-stub? Let's try!
  38. Phar::mapPhar('php-cs-fixer.phar');
  39. require_once 'phar://php-cs-fixer.phar/vendor/autoload.php';
  40. } catch (PharException $e) {
  41. // OK, it's not, let give Composer autoloader a try!
  42. if (file_exists($a = __DIR__.'/../../autoload.php')) {
  43. require_once $a;
  44. } else {
  45. require_once __DIR__.'/vendor/autoload.php';
  46. }
  47. }
  48. use PhpCsFixer\Console\Application;
  49. $application = new Application();
  50. $application->run();
  51. __HALT_COMPILER(); ?>
  52. ·��[�����������������dev-tools/ci-integration.sh‰��-SVZ‰���'OO¶������ ���src/AbstractAlignFixerHelper.phpÏ��-SVZÏ��˜…Ŷ������'���src/AbstractDoctrineAnnotationFixer.phpB ��-SVZB ��&œ¶���������src/AbstractFixer.phpÒ��-SVZÒ��ôµ¶������&���src/AbstractFunctionReferenceFixer.phpÝ��-SVZÝ��ö• ý¶������)���src/AbstractLinesBeforeNamespaceFixer.phpÊ��-SVZÊ��½ÏL³¶������"���src/AbstractNoUselessElseFixer.php½ ��-SVZ½ ��tÒrж������ ���src/AbstractPhpdocTypesFixer.phpà��-SVZà��¤¶���������src/AbstractProxyFixer.php2��-SVZ2��qUŶ������#���src/AbstractPsrAutoloadingFixer.php ��-SVZ ��°³nK¶���������src/Cache/Cache.php@��-SVZ@��w¥Ô"¶���������src/Cache/CacheInterface.php��-SVZ��'ë­¶������#���src/Cache/CacheManagerInterface.phpÁ���-SVZÁ���ÈD†¶���������src/Cache/Directory.phpM��-SVZM��•õ¦ ¶������ ���src/Cache/DirectoryInterface.php����-SVZ����ÐF’d¶���������src/Cache/FileCacheManager.phpÑ��-SVZÑ��
  53. çY4¶���������src/Cache/FileHandler.phpK��-SVZK��³½Ñí¶������"���src/Cache/FileHandlerInterface.phpÂ���-SVZÂ���éIŠ:¶���������src/Cache/NullCacheManager.phpè���-SVZè���Â4n¶���������src/Cache/Signature.php"��-SVZ"��ü—™á¶������ ���src/Cache/SignatureInterface.phpî���-SVZî���£Ìȶ���������src/Config.php ��-SVZ ��`ZY¶���������src/ConfigInterface.php\��-SVZ\��-Ž«Ì¶������<���src/ConfigurationException/InvalidConfigurationException.phpµ��-SVZµ��)U¸¶������A���src/ConfigurationException/InvalidFixerConfigurationException.php@��-SVZ@��ÿ÷™¶������G���src/ConfigurationException/InvalidForEnvFixerConfigurationException.php¨���-SVZ¨���wSõζ������B���src/ConfigurationException/RequiredFixerConfigurationException.php£���-SVZ£���‹”Œ¶���������src/Console/Application.phpÄ ��-SVZÄ ��Q¢Ár¶������'���src/Console/Command/DescribeCommand.php#��-SVZ#��Auø.¶������5���src/Console/Command/DescribeNameNotFoundException.php{��-SVZ{��BˆM�¶������"���src/Console/Command/FixCommand.php÷��-SVZ÷��I(¶������6���src/Console/Command/FixCommandExitStatusCalculator.php��-SVZ���çy�¶������#���src/Console/Command/HelpCommand.phpC?��-SVZC?��„Uv†¶������%���src/Console/Command/ReadmeCommand.phpÑ��-SVZÑ��^ûðô¶������)���src/Console/Command/SelfUpdateCommand.phpŽ��-SVZŽ��ÐâŶ������%���src/Console/ConfigurationResolver.phpÙC��-SVZÙC��n�+”¶������"���src/Console/Output/ErrorOutput.php$
  54. ��-SVZ$
  55. ��Ë:�¿¶������!���src/Console/Output/NullOutput.php™���-SVZ™���~|œU¶������$���src/Console/Output/ProcessOutput.phpð ��-SVZð ��S«$޶������-���src/Console/Output/ProcessOutputInterface.php~���-SVZ~���ßøÕƒ¶������'���src/Console/SelfUpdate/GithubClient.php·��-SVZ·��99⌶������0���src/Console/SelfUpdate/GithubClientInterface.php€���-SVZ€���´]ÆÎ¶������,���src/Console/SelfUpdate/NewVersionChecker.php|��-SVZ|��r“%~¶������5���src/Console/SelfUpdate/NewVersionCheckerInterface.php��-SVZ��,µKl¶������ ���src/Console/WarningsDetector.php”��-SVZ”��¬ürµ¶������#���src/Differ/DiffConsoleFormatter.phpM��-SVZM��¯šÛŶ���������src/Differ/DifferInterface.php|���-SVZ|���ÙhÄB¶���������src/Differ/NullDiffer.php›���-SVZ›���ø¨D¶������&���src/Differ/SebastianBergmannDiffer.php=��-SVZ=��–îq¶������+���src/Differ/SebastianBergmannShortDiffer.phpb��-SVZb��Z!¨5¶���������src/Differ/UnifiedDiffer.phpÏ��-SVZÏ��E‰!/¶���������src/DocBlock/Annotation.php� ��-SVZ� �� ý ¶���������src/DocBlock/DocBlock.php9��-SVZ9��äD&ê¶���������src/DocBlock/Line.php��-SVZ��+sQ¶���������src/DocBlock/Tag.phpr��-SVZr��x†Ðó¶���������src/DocBlock/TagComparator.phpn��-SVZn��Û"D'¶������!���src/Doctrine/Annotation/Token.phpà��-SVZà��»g™ª¶������"���src/Doctrine/Annotation/Tokens.phpç��-SVZç��ØÂ¶���������src/Error/Error.php��-SVZ��Ôàm¶���������src/Error/ErrorsManager.phpç��-SVZç��_x‰þ¶���������src/FileReader.phpG��-SVZG��½ÌØQ¶���������src/FileRemoval.phpW��-SVZW��‡_]¶���������src/Finder.php.��-SVZ.��¸Ý8Ͷ������,���src/Fixer/Alias/BacktickToShellExecFixer.php ��-SVZ ��”(:˜¶������#���src/Fixer/Alias/EregToPregFixer.php.
  56. ��-SVZ.
  57. ��ˆ(Jµ¶������'���src/Fixer/Alias/MbStrFunctionsFixer.phpƒ
  58. ��-SVZƒ
  59. ��ù(¥¶������)���src/Fixer/Alias/NoAliasFunctionsFixer.php ��-SVZ ��ˆ+†j¶������)���src/Fixer/Alias/NoMixedEchoPrintFixer.php¦
  60. ��-SVZ¦
  61. ��:8•?¶������,���src/Fixer/Alias/PowToExponentiationFixer.php©��-SVZ©��Ÿ¾ü¶������+���src/Fixer/Alias/RandomApiMigrationFixer.php���-SVZ���´Á'k¶������,���src/Fixer/ArrayNotation/ArraySyntaxFixer.php@ ��-SVZ@ ��üÎY¼¶������G���src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php½��-SVZ½��ÕÃ!ж������A���src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php��-SVZ��1&ŽÕ¶������?���src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.phpZ��-SVZZ���&˜¹¶������4���src/Fixer/ArrayNotation/NormalizeIndexBraceFixer.phpÈ��-SVZÈ��$Ý“�¶������>���src/Fixer/ArrayNotation/TrailingCommaInMultilineArrayFixer.php ��-SVZ ��Ñž^j¶������0���src/Fixer/ArrayNotation/TrimArraySpacesFixer.phpž��-SVZž��7�"£¶������<���src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php ��-SVZ ��ã«‘¶���������src/Fixer/Basic/BracesFixer.php]��-SVZ]��c`ªÙ¶������!���src/Fixer/Basic/EncodingFixer.php:��-SVZ:��>ª÷ݶ������.���src/Fixer/Basic/NonPrintableCharacterFixer.php!��-SVZ!��m–˜×¶���������src/Fixer/Basic/Psr0Fixer.php}��-SVZ}��i*¾°¶���������src/Fixer/Basic/Psr4Fixer.php ��-SVZ ��|}ÚT¶������,���src/Fixer/Casing/LowercaseConstantsFixer.phpÁ��-SVZÁ��ÌäJ…¶������+���src/Fixer/Casing/LowercaseKeywordsFixer.phpM��-SVZM�� ¢¼¶������-���src/Fixer/Casing/MagicConstantCasingFixer.php>��-SVZ>��…œ6ݶ������.���src/Fixer/Casing/NativeFunctionCasingFixer.phpD��-SVZD��E§V¶������*���src/Fixer/CastNotation/CastSpacesFixer.phpE��-SVZE��Òcš¶������-���src/Fixer/CastNotation/LowercaseCastFixer.phpr��-SVZr��ò\®ï¶������5���src/Fixer/CastNotation/ModernizeTypesCastingFixer.phpØ
  62. ��-SVZØ
  63. ��þ{úß¶������/���src/Fixer/CastNotation/NoShortBoolCastFixer.php²��-SVZ²��Äé]¶������/���src/Fixer/CastNotation/ShortScalarCastFixer.php<��-SVZ<��¬ ?޶������:���src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php¾��-SVZ¾��¾ö°Ÿ¶������0���src/Fixer/ClassNotation/ClassDefinitionFixer.phpò(��-SVZò(��œ·Ã¶������3���src/Fixer/ClassNotation/FinalInternalClassFixer.php(��-SVZ(��²)ø¶������1���src/Fixer/ClassNotation/MethodSeparationFixer.phpŸ��-SVZŸ��ÍT.ê¶������>���src/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixer.php‰��-SVZ‰��Ëo²¶������=���src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.phpY��-SVZY��t£¶������2���src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php ��-SVZ ��¡E¶������6���src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.phps��-SVZs��†�Á-¶������5���src/Fixer/ClassNotation/OrderedClassElementsFixer.php:!��-SVZ:!��Žaâ«¶������3���src/Fixer/ClassNotation/ProtectedToPrivateFixer.phpf��-SVZf��!^Þ¶������-���src/Fixer/ClassNotation/SelfAccessorFixer.php! ��-SVZ! ��ú2ÙB¶������?���src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php²��-SVZ²��„òŒ¶������3���src/Fixer/ClassNotation/VisibilityRequiredFixer.php��-SVZ�� ž|‚¶������-���src/Fixer/Comment/HashToSlashCommentFixer.phpú��-SVZú��MÔZ`¶������(���src/Fixer/Comment/HeaderCommentFixer.phpk��-SVZk�� J‘î¶������9���src/Fixer/Comment/MultilineCommentOpeningClosingFixer.phpò��-SVZò��|A8¶������)���src/Fixer/Comment/NoEmptyCommentFixer.php  ��-SVZ  ��ü|¶������8���src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php\��-SVZ\��u>zж������1���src/Fixer/Comment/SingleLineCommentStyleFixer.phpë ��-SVZë ��YH«=¶������(���src/Fixer/ConfigurableFixerInterface.php��-SVZ��¿§Å¶������3���src/Fixer/ConfigurationDefinitionFixerInterface.php��-SVZ��MÕãµ¶������*���src/Fixer/ControlStructure/ElseifFixer.phpú��-SVZú�� Ǹж������+���src/Fixer/ControlStructure/IncludeFixer.php��-SVZ��Na
  64. 4¶������2���src/Fixer/ControlStructure/NoBreakCommentFixer.php!��-SVZ!��üב.¶������7���src/Fixer/ControlStructure/NoSuperfluousElseifFixer.phpS��-SVZS��û•3•¶������=���src/Fixer/ControlStructure/NoTrailingCommaInListCallFixer.phpÎ��-SVZÎ��Y„ÊN¶������@���src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.phpW��-SVZW��$„¤ø¶������9���src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php��-SVZ��Þö�n¶������1���src/Fixer/ControlStructure/NoUselessElseFixer.phpš��-SVZš��Ì À¶������>���src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php���-SVZ���ÿ,é¶������3���src/Fixer/ControlStructure/SwitchCaseSpaceFixer.phpï��-SVZï��=«‰§¶������-���src/Fixer/ControlStructure/YodaStyleFixer.php�*��-SVZ�*��I½¬�¶������#���src/Fixer/DefinedFixerInterface.phpÍ���-SVZÍ���� ܶ������&���src/Fixer/DeprecatedFixerInterface.phpš���-SVZš���=r”T¶������G���src/Fixer/DoctrineAnnotation/DoctrineAnnotationArrayAssignmentFixer.phpø��-SVZø��K¸ ¶������>���src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php%
  65. ��-SVZ%
  66. ��ס������C���src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.phpé��-SVZé��Öåø¶������>���src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.phpj$��-SVZj$��¬fWó¶���������src/Fixer/FixerInterface.phpŽ��-SVZŽ��º…L¶������7���src/Fixer/FunctionNotation/FunctionDeclarationFixer.php5��-SVZ5��\²“6¶������9���src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php³��-SVZ³��A?W ¶������7���src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php¤��-SVZ¤��¶< ¶������<���src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.phpJ��-SVZJ��šÑ‹¶������=���src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php ��-SVZ ��ë—â8¶������E���src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php;��-SVZ;��ƒËn†¶������9���src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.phpë ��-SVZë ��á¼ì¶������0���src/Fixer/FunctionNotation/StaticLambdaFixer.phpt��-SVZt��õKÃL¶������.���src/Fixer/FunctionNotation/VoidReturnFixer.php?��-SVZ?��
  67. S Ú¶������.���src/Fixer/Import/NoLeadingImportSlashFixer.php��-SVZ��ç­q¶������)���src/Fixer/Import/NoUnusedImportsFixer.phph��-SVZh��`¶ŽÁ¶������(���src/Fixer/Import/OrderedImportsFixer.php8&��-SVZ8&��‹+à¶������2���src/Fixer/Import/SingleImportPerStatementFixer.phpS��-SVZS��:·,~¶������0���src/Fixer/Import/SingleLineAfterImportsFixer.phpÆ ��-SVZÆ ��òƒ¶������7���src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.phpç��-SVZç��6„é=¶������=���src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php7 ��-SVZ7 ��×T;¶������=���src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php  ��-SVZ  ��VÎ@%¶������:���src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php
  68. ��-SVZ
  69. ��;íĶ������0���src/Fixer/LanguageConstruct/DirConstantFixer.php¿��-SVZ¿��¯ƒ¶������=���src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.phpŽ��-SVZŽ��wð>€¶������7���src/Fixer/LanguageConstruct/FunctionToConstantFixer.phpS��-SVZS��­èýï¶������+���src/Fixer/LanguageConstruct/IsNullFixer.php¦��-SVZ¦��pS×¶������=���src/Fixer/LanguageConstruct/SilencedDeprecationErrorFixer.phpà��-SVZà��yØ2Ú¶������*���src/Fixer/ListNotation/ListSyntaxFixer.phpï ��-SVZï ��az˶������<���src/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixer.phpœ��-SVZœ��£ N`¶������@���src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.phpŽ��-SVZŽ��vÄó·¶������A���src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php5��-SVZ5��í@¶������C���src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php£��-SVZ£��„'3u¶������*���src/Fixer/Naming/NoHomoglyphNamesFixer.php° ��-SVZ° ��«J<ƶ������2���src/Fixer/Operator/AlignDoubleArrowFixerHelper.phpY ��-SVZY �� õd�¶������-���src/Fixer/Operator/AlignEqualsFixerHelper.phpÝ��-SVZÝ��±§º¶������0���src/Fixer/Operator/BinaryOperatorSpacesFixer.php6>��-SVZ6>��îÞòµ¶������'���src/Fixer/Operator/ConcatSpaceFixer.phpï
  70. ��-SVZï
  71. ��NÑ^„¶������*���src/Fixer/Operator/IncrementStyleFixer.php†��-SVZ†��‡Ú«õ¶������)���src/Fixer/Operator/NewWithBracesFixer.php# ��-SVZ# ��ê ]¶������0���src/Fixer/Operator/NotOperatorWithSpaceFixer.php,��-SVZ,��®¶������9���src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php��-SVZ���#jζ������;���src/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixer.phpå��-SVZå��MÐsĶ������(���src/Fixer/Operator/PreIncrementFixer.phpÞ��-SVZÞ��¿©­¶������0���src/Fixer/Operator/StandardizeNotEqualsFixer.php��-SVZ��ަǶ������1���src/Fixer/Operator/TernaryOperatorSpacesFixer.php2��-SVZ2��fçx¶������3���src/Fixer/Operator/TernaryToNullCoalescingFixer.php$��-SVZ$��ŒÍ<˶������/���src/Fixer/Operator/UnaryOperatorSpacesFixer.phpZ��-SVZZ��^ãç4¶������2���src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.phpß��-SVZß��O*›N¶������(���src/Fixer/PhpTag/FullOpeningTagFixer.php™��-SVZ™��: G­¶������2���src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.phpž��-SVZž��.€©t¶������&���src/Fixer/PhpTag/NoClosingTagFixer.phpV��-SVZV��|l9¨¶������(���src/Fixer/PhpTag/NoShortEchoTagFixer.phpû��-SVZû��ŠÞ8—¶������+���src/Fixer/PhpUnit/PhpUnitConstructFixer.php7��-SVZ7��JŒ(¶������0���src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php_��-SVZ_��ÆsËÿ¶������-���src/Fixer/PhpUnit/PhpUnitExpectationFixer.phpÆ��-SVZÆ��ZBAâ¶������0���src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.phpæ��-SVZæ��k7é'¶������&���src/Fixer/PhpUnit/PhpUnitMockFixer.phpã��-SVZã��ðh=¶������,���src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php‰��-SVZ‰�� èéf¶������9���src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.phpI��-SVZI��øÒ[¶������(���src/Fixer/PhpUnit/PhpUnitStrictFixer.php; ��-SVZ; ��£ßÝA¶������*���src/Fixer/PhpUnit/PhpUnitTargetVersion.php™��-SVZ™��ÏÈI¶������0���src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php}+��-SVZ}+��ëò4¶������9���src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.phpÇ ��-SVZÇ ��¤=H$¶������/���src/Fixer/Phpdoc/AlignMultilineCommentFixer.phpó ��-SVZó ��x\k@¶������7���src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php��-SVZ��FpÇ^¶������1���src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.phpª��-SVZª��C›Øª¶������'���src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php`��-SVZ`��a¤Þ&¶������9���src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php3��-SVZ3��Å(‡}¶������%���src/Fixer/Phpdoc/PhpdocAlignFixer.php—��-SVZ—��Z³uæ¶������4���src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php ��-SVZ ��{Ø‘;¶������&���src/Fixer/Phpdoc/PhpdocIndentFixer.php¾��-SVZ¾��*Éd¶������)���src/Fixer/Phpdoc/PhpdocInlineTagFixer.php"��-SVZ"��Â@~`¶������(���src/Fixer/Phpdoc/PhpdocNoAccessFixer.php’��-SVZ’��Ù¤uß¶������*���src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.phpï ��-SVZï ��•ZšX¶������-���src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.phpÓ��-SVZÓ��`‡Ù¶������)���src/Fixer/Phpdoc/PhpdocNoPackageFixer.php ��-SVZ ��¸€|ζ������3���src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.phpô ��-SVZô ��á\ ̶������%���src/Fixer/Phpdoc/PhpdocOrderFixer.php1 ��-SVZ1 ��íö¶������3���src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.phpe��-SVZe��M8"¶������&���src/Fixer/Phpdoc/PhpdocScalarFixer.phpÄ��-SVZÄ��2祶������*���src/Fixer/Phpdoc/PhpdocSeparationFixer.phpU
  72. ��-SVZU
  73. ��Ûò¶������4���src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php��-SVZ��£kÚ~¶������'���src/Fixer/Phpdoc/PhpdocSummaryFixer.phpg��-SVZg��V9¢j¶������)���src/Fixer/Phpdoc/PhpdocToCommentFixer.phpI��-SVZI��ÓÅAͶ������$���src/Fixer/Phpdoc/PhpdocTrimFixer.php‹��-SVZ‹��ÉþѾ¶������%���src/Fixer/Phpdoc/PhpdocTypesFixer.php—��-SVZ—��,À¥¶������*���src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php™��-SVZ™��Ã~sé¶������.���src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.phpP��-SVZP��U%©…¶������7���src/Fixer/ReturnNotation/BlankLineBeforeReturnFixer.php°��-SVZ°��BuQ±¶������1���src/Fixer/ReturnNotation/NoUselessReturnFixer.phpn��-SVZn��Ï™ôD¶������6���src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php’ ��-SVZ’ ��A†z¶������@���src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php³��-SVZ³��ˆ€5?¶������-���src/Fixer/Semicolon/NoEmptyStatementFixer.phpÅ ��-SVZÅ ��FI v¶������B���src/Fixer/Semicolon/NoMultilineWhitespaceBeforeSemicolonsFixer.phpÆ��-SVZÆ���ø‘.¶������C���src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.phpú��-SVZú��Ø5¬8¶������6���src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php³��-SVZ³��3ÆNQ¶������0���src/Fixer/Semicolon/SpaceAfterSemicolonFixer.phpÃ
  74. ��-SVZÃ
  75. ��©b8¦¶������,���src/Fixer/Strict/DeclareStrictTypesFixer.phpÐ
  76. ��-SVZÐ
  77. ��9²#6¶������*���src/Fixer/Strict/StrictComparisonFixer.phpB��-SVZB��9�K¶������%���src/Fixer/Strict/StrictParamFixer.phpƒ ��-SVZƒ ��^c=6¶������;���src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php5��-SVZ5��ŽwøY¶������8���src/Fixer/StringNotation/ExplicitStringVariableFixer.phpµ
  78. ��-SVZµ
  79. ��È{Ÿs¶������1���src/Fixer/StringNotation/HeredocToNowdocFixer.php+��-SVZ+��çÑ­¶������-���src/Fixer/StringNotation/SingleQuoteFixer.phph��-SVZh��Åfý¶������6���src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php]��-SVZ]��WIs½¶������5���src/Fixer/Whitespace/CompactNullableTypehintFixer.phpã��-SVZã��ÝBê¶������-���src/Fixer/Whitespace/IndentationTypeFixer.phpP ��-SVZP ��Zvå¶������(���src/Fixer/Whitespace/LineEndingFixer.phpb��-SVZb��MÄ"¶������7���src/Fixer/Whitespace/MethodChainingIndentationFixer.php¿ ��-SVZ¿ ��©§¶������/���src/Fixer/Whitespace/NoExtraBlankLinesFixer.php+��-SVZ+��Ígîí¶������:���src/Fixer/Whitespace/NoExtraConsecutiveBlankLinesFixer.php;��-SVZ;��Sêôж������2���src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.phpz ��-SVZz ��fhT ¶������7���src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php/��-SVZ/��Âîж������2���src/Fixer/Whitespace/NoTrailingWhitespaceFixer.phpë��-SVZë��ªHü¾¶������5���src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php°��-SVZ°��ùâm¶������2���src/Fixer/Whitespace/SingleBlankLineAtEofFixer.phpÆ��-SVZÆ��O£ú¶������,���src/Fixer/WhitespacesAwareFixerInterface.phpã���-SVZã���gó²s¶������5���src/FixerConfiguration/FixerConfigurationResolver.php��-SVZ��¸ é¶������>���src/FixerConfiguration/FixerConfigurationResolverInterface.phpÃ���-SVZÃ���÷–Ø#¶������=���src/FixerConfiguration/FixerConfigurationResolverRootless.php5��-SVZ5��7¼Ç;¶������&���src/FixerConfiguration/FixerOption.phpŒ��-SVZŒ��¼wWá¶������-���src/FixerConfiguration/FixerOptionBuilder.php��-SVZ��xÐ’7¶������/���src/FixerConfiguration/FixerOptionInterface.php\��-SVZ\��j,‰½¶������8���src/FixerConfiguration/FixerOptionValidatorGenerator.phpk��-SVZk��º],r¶������8���src/FixerConfiguration/InvalidOptionsForEnvException.phpØ���-SVZØ���˜ÈR¶������"���src/FixerDefinition/CodeSample.php¦��-SVZ¦��¯@—¶������+���src/FixerDefinition/CodeSampleInterface.php£���-SVZ£���ò—4/¶������.���src/FixerDefinition/FileSpecificCodeSample.phpj��-SVZj��•£¨d¶������7���src/FixerDefinition/FileSpecificCodeSampleInterface.php¬���-SVZ¬���ÒvO¶������'���src/FixerDefinition/FixerDefinition.php��-SVZ���þEá¶������0���src/FixerDefinition/FixerDefinitionInterface.phpb��-SVZb��4/¹¶������1���src/FixerDefinition/VersionSpecificCodeSample.phpÌ��-SVZÌ��±SÏö¶������:���src/FixerDefinition/VersionSpecificCodeSampleInterface.php¶���-SVZ¶���íƒál¶������,���src/FixerDefinition/VersionSpecification.phpk��-SVZk��­t*˶������5���src/FixerDefinition/VersionSpecificationInterface.php•���-SVZ•���ø¢Ý¬¶���������src/FixerFactory.php[��-SVZ[��¤õ!¾¶���������src/FixerFileProcessedEvent.php��-SVZ��£¼-_¶���������src/FixerNameValidator.php��-SVZ��IîØú¶������*���src/Indicator/PhpUnitTestCaseIndicator.php8��-SVZ8��õð;¶���������src/Linter/Linter.php8��-SVZ8��×XÂ϶���������src/Linter/LinterInterface.phpÆ���-SVZÆ���/X‹Æ¶���������src/Linter/LintingException.phpg���-SVZg���ÎKþ�¶������%���src/Linter/LintingResultInterface.phps���-SVZs���O:§N¶���������src/Linter/ProcessLinter.php2 ��-SVZ2 ��tÌC¶������*���src/Linter/ProcessLinterProcessBuilder.phpb��-SVZb��K,˜¶������#���src/Linter/ProcessLintingResult.php•��-SVZ•��€yȶ���������src/Linter/TokenizerLinter.php��-SVZ��ä»D¶������%���src/Linter/TokenizerLintingResult.phpË��-SVZË��Xnt¥¶������)���src/Linter/UnavailableLinterException.phps���-SVZs���¡ýGɶ���������src/PharChecker.phpp��-SVZp�� ¥Ìp¶���������src/PharCheckerInterface.php����-SVZ����Ñ�£¶������!���src/Report/CheckstyleReporter.php��-SVZ��IFqò¶���������src/Report/JsonReporter.phpÓ��-SVZÓ�� Ê(ʶ���������src/Report/JunitReporter.php� ��-SVZ� ��W¸hæ¶���������src/Report/ReportSummary.php©��-SVZ©��d¸¶���������src/Report/ReporterFactory.php¡��-SVZ¡��±Tãȶ������ ���src/Report/ReporterInterface.php²���-SVZ²���Y×9ý¶���������src/Report/TextReporter.phpf��-SVZf��äN X¶���������src/Report/XmlReporter.phpN
  80. ��-SVZN
  81. ��+f(%¶���������src/RuleSet.phpö#��-SVZö#��;ˆ ¶���������src/RuleSetInterface.php[��-SVZ[��À¯¶������)���src/Runner/FileCachingLintingIterator.php���-SVZ���ev
  82. ¯¶������!���src/Runner/FileFilterIterator.phpÒ��-SVZÒ��Õ�m¶������"���src/Runner/FileLintingIterator.php;��-SVZ;��>­|¶���������src/Runner/Runner.php:��-SVZ:��ÂÏÆ¶���������src/StdinFileInfo.php#��-SVZ#��`—)D¶������%���src/Tokenizer/AbstractTransformer.php��-SVZ��(erZ¶������,���src/Tokenizer/Analyzer/ArgumentsAnalyzer.phpÄ��-SVZÄ��ðŸ–>¶���������src/Tokenizer/CT.phpž��-SVZž��ìá“ù¶���������src/Tokenizer/CodeHasher.phpÑ���-SVZÑ���VâJþ¶���������src/Tokenizer/Token.phpJ!��-SVZJ!��¶³û,¶���������src/Tokenizer/Tokens.phpXK��-SVZXK��on ;¶������ ���src/Tokenizer/TokensAnalyzer.php%��-SVZ%��ó¤õ¶������6���src/Tokenizer/Transformer/ArrayTypehintTransformer.phpÛ��-SVZÛ��ÈùÍq¶������@���src/Tokenizer/Transformer/BraceClassInstantiationTransformer.phpÜ��-SVZÜ��­ ÁÔ¶������6���src/Tokenizer/Transformer/ClassConstantTransformer.php��-SVZ��š™ó´¶������3���src/Tokenizer/Transformer/CurlyBraceTransformer.php—��-SVZ—��ù:Ͷ������/���src/Tokenizer/Transformer/ImportTransformer.php#��-SVZ#�� “P‘¶������:���src/Tokenizer/Transformer/NamespaceOperatorTransformer.phpú��-SVZú��÷t�¶������5���src/Tokenizer/Transformer/NullableTypeTransformer.php��-SVZ��ZñPˆ¶������2���src/Tokenizer/Transformer/ReturnRefTransformer.php��-SVZ��ç¬>™¶������4���src/Tokenizer/Transformer/SquareBraceTransformer.phpl ��-SVZl ��òT•2¶������8���src/Tokenizer/Transformer/TypeAlternationTransformer.php���-SVZ���>%†ÿ¶������2���src/Tokenizer/Transformer/TypeColonTransformer.phpo��-SVZo��]6¶������,���src/Tokenizer/Transformer/UseTransformer.phpÇ��-SVZÇ��Hx9á¶������:���src/Tokenizer/Transformer/WhitespacyCommentTransformer.phpÏ��-SVZÏ��ÝŠkò¶������&���src/Tokenizer/TransformerInterface.phpP��-SVZP��ßÁÈY¶���������src/Tokenizer/Transformers.php"��-SVZ"��~GDN¶���������src/ToolInfo.php‰��-SVZ‰��Á¥6¶���������src/ToolInfoInterface.phpB��-SVZB��Ô-—W¶������ ���src/Utils.phpG ��-SVZG ��¿.è¶���������src/WhitespacesFixerConfig.phpª��-SVZª��D¸­ª¶���������src/WordMatcher.phpí��-SVZí��n¿ 1¶������W���vendor/php-cs-fixer/diff/src/GeckoPackages/DiffOutputBuilder/ConfigurationException.phpÞ��-SVZÞ��áz8¶������Y���vendor/php-cs-fixer/diff/src/GeckoPackages/DiffOutputBuilder/UnifiedDiffOutputBuilder.php��-SVZ��f“¶������+���vendor/php-cs-fixer/diff/src/v1_4/Chunk.php ��-SVZ ��ŽÅýÛ¶������*���vendor/php-cs-fixer/diff/src/v1_4/Diff.phpí��-SVZí��0}n¶������,���vendor/php-cs-fixer/diff/src/v1_4/Differ.phpi��-SVZi���1)¶������B���vendor/php-cs-fixer/diff/src/v1_4/LCS/LongestCommonSubsequence.php™���-SVZ™���÷)—¶������_���vendor/php-cs-fixer/diff/src/v1_4/LCS/MemoryEfficientLongestCommonSubsequenceImplementation.php��-SVZ��Í:ž¶������]���vendor/php-cs-fixer/diff/src/v1_4/LCS/TimeEfficientLongestCommonSubsequenceImplementation.phpÜ��-SVZÜ��® 8¶������*���vendor/php-cs-fixer/diff/src/v1_4/Line.php���-SVZ���!êâ/¶������,���vendor/php-cs-fixer/diff/src/v1_4/Parser.phpõ��-SVZõ��6qÑc¶������+���vendor/php-cs-fixer/diff/src/v2_0/Chunk.phpð��-SVZð��œk—˶������*���vendor/php-cs-fixer/diff/src/v2_0/Diff.phpè��-SVZè��¹ù’¶������,���vendor/php-cs-fixer/diff/src/v2_0/Differ.php3��-SVZ3��û¿‰î¶������9���vendor/php-cs-fixer/diff/src/v2_0/Exception/Exception.phpH���-SVZH���s�é-¶������H���vendor/php-cs-fixer/diff/src/v2_0/Exception/InvalidArgumentException.phpŠ���-SVZŠ���;—ž$¶������*���vendor/php-cs-fixer/diff/src/v2_0/Line.phpŒ��-SVZŒ��AŸQû¶������H���vendor/php-cs-fixer/diff/src/v2_0/LongestCommonSubsequenceCalculator.phpœ���-SVZœ���5ä¶������W���vendor/php-cs-fixer/diff/src/v2_0/MemoryEfficientLongestCommonSubsequenceCalculator.php
  83. ��-SVZ
  84. ��âh ¶������G���vendor/php-cs-fixer/diff/src/v2_0/Output/AbstractChunkOutputBuilder.php��-SVZ��1ò%|¶������B���vendor/php-cs-fixer/diff/src/v2_0/Output/DiffOnlyOutputBuilder.php¤��-SVZ¤��E{I¶������G���vendor/php-cs-fixer/diff/src/v2_0/Output/DiffOutputBuilderInterface.php‰���-SVZ‰���òu¤¶������E���vendor/php-cs-fixer/diff/src/v2_0/Output/UnifiedDiffOutputBuilder.phpŽ ��-SVZŽ ��.ÃÛ¶������,���vendor/php-cs-fixer/diff/src/v2_0/Parser.php÷��-SVZ÷��l°àC¶������U���vendor/php-cs-fixer/diff/src/v2_0/TimeEfficientLongestCommonSubsequenceCalculator.phpï��-SVZï��˜æìK¶������)���vendor/composer/semver/src/Comparator.php��-SVZ��wlƒï¶������<���vendor/composer/semver/src/Constraint/AbstractConstraint.php×��-SVZ×��õî>޶������4���vendor/composer/semver/src/Constraint/Constraint.phpª ��-SVZª ��ÇO7²¶������=���vendor/composer/semver/src/Constraint/ConstraintInterface.phpß���-SVZß���0C,‡¶������9���vendor/composer/semver/src/Constraint/EmptyConstraint.phpé��-SVZé��!-Ø™¶������9���vendor/composer/semver/src/Constraint/MultiConstraint.php1��-SVZ1��í xU¶������%���vendor/composer/semver/src/Semver.phpv��-SVZv��‹×È›¶������,���vendor/composer/semver/src/VersionParser.php¿*��-SVZ¿*��)mƶ������'���vendor/composer/autoload_namespaces.php®���-SVZ®���9ÖŠZ¶������!���vendor/composer/autoload_psr4.phpO��-SVZO��o¼A ¶������%���vendor/composer/autoload_classmap.phps�-SVZs�|”¥¶������"���vendor/composer/autoload_files.phpÙ��-SVZÙ��äãìo¶������#���vendor/composer/autoload_static.php®1�-SVZ®1�?|U„¶������!���vendor/composer/autoload_real.php���-SVZ���¬×¸:¶���������vendor/composer/ClassLoader.php���-SVZ���‚Aãd¶������7���vendor/symfony/process/Exception/ExceptionInterface.phpf���-SVZf���]ö>T¶������=���vendor/symfony/process/Exception/InvalidArgumentException.php¨���-SVZ¨���ÐÀ+_¶������3���vendor/symfony/process/Exception/LogicException.php”���-SVZ”��� ³ãñ¶������;���vendor/symfony/process/Exception/ProcessFailedException.phpx��-SVZx��¨Ìzy¶������=���vendor/symfony/process/Exception/ProcessTimedOutException.php��-SVZ��ï«¶������5���vendor/symfony/process/Exception/RuntimeException.php˜���-SVZ˜���¢Ø:¶������+���vendor/symfony/process/ExecutableFinder.php™��-SVZ™��|O¿é¶������&���vendor/symfony/process/InputStream.php'��-SVZ'��Tv9¶������.���vendor/symfony/process/PhpExecutableFinder.phpN��-SVZN��R”�¶������%���vendor/symfony/process/PhpProcess.phpÙ��-SVZÙ��ó“nl¶������.���vendor/symfony/process/Pipes/AbstractPipes.php|
  85. ��-SVZ|
  86. ��æ�²n¶������/���vendor/symfony/process/Pipes/PipesInterface.phpm��-SVZm��ï‹u¶������*���vendor/symfony/process/Pipes/UnixPipes.php���-SVZ���DÁ¶������-���vendor/symfony/process/Pipes/WindowsPipes.php` ��-SVZ` ���¨Bj¶������"���vendor/symfony/process/Process.phpl��-SVZl��ó#­þ¶������)���vendor/symfony/process/ProcessBuilder.php ��-SVZ ��XÖV,¶������'���vendor/symfony/process/ProcessUtils.php0��-SVZ0��t2‹é¶������$���vendor/symfony/stopwatch/Section.php®��-SVZ®��zZ¶������&���vendor/symfony/stopwatch/Stopwatch.php
  87. ��-SVZ
  88. ��îziÞ¶������+���vendor/symfony/stopwatch/StopwatchEvent.php¯ ��-SVZ¯ ��ë]±S¶������,���vendor/symfony/stopwatch/StopwatchPeriod.phpp��-SVZp��ΧÉ!¶������-���vendor/symfony/polyfill-mbstring/Mbstring.phpÄ6��-SVZÄ6��U.ݶ������@���vendor/symfony/polyfill-mbstring/Resources/unidata/lowerCase.php2A��-SVZ2A��½=¨¶������@���vendor/symfony/polyfill-mbstring/Resources/unidata/upperCase.php¡A��-SVZ¡A��Ú Í¶������.���vendor/symfony/polyfill-mbstring/bootstrap.php±��-SVZ±��|Š©Ò¶������(���vendor/symfony/debug/BufferingLogger.phpt��-SVZt��=�hܶ���������vendor/symfony/debug/Debug.phpí��-SVZí��•:z ¶������)���vendor/symfony/debug/DebugClassLoader.phpY(��-SVZY(��,Wý¶������%���vendor/symfony/debug/ErrorHandler.phpÆ>��-SVZÆ>��ÁWV¶������9���vendor/symfony/debug/Exception/ClassNotFoundException.php„��-SVZ„��n�¡…¶������8���vendor/symfony/debug/Exception/ContextErrorException.php��-SVZ��À„C¶������6���vendor/symfony/debug/Exception/FatalErrorException.php��-SVZ��¬>0¶������6���vendor/symfony/debug/Exception/FatalThrowableError.phpD��-SVZD��¡ Âí¶������3���vendor/symfony/debug/Exception/FlattenException.phpà��-SVZà��êÚq‰¶������7���vendor/symfony/debug/Exception/OutOfMemoryException.php~���-SVZ~���ë¨oâ¶������7���vendor/symfony/debug/Exception/SilencedErrorContext.php2��-SVZ2��¬7`o¶������=���vendor/symfony/debug/Exception/UndefinedFunctionException.phpˆ��-SVZˆ��¢G‚n¶������;���vendor/symfony/debug/Exception/UndefinedMethodException.php†��-SVZ†��¨LÚ:¶������)���vendor/symfony/debug/ExceptionHandler.php¼l��-SVZ¼l��²ãó+¶������I���vendor/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.phpE��-SVZE��ûúU¶������E���vendor/symfony/debug/FatalErrorHandler/FatalErrorHandlerInterface.php��-SVZ��ĹBV¶������M���vendor/symfony/debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.phpu��-SVZu��éj¶������K���vendor/symfony/debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.phpN��-SVZN��Ço-ç¶������&���vendor/symfony/console/Application.php=d��-SVZ=d��Â#õ¿¶������*���vendor/symfony/console/Command/Command.php ��-SVZ ��Š¥E–¶������.���vendor/symfony/console/Command/HelpCommand.php¦��-SVZ¦��^_z¶������.���vendor/symfony/console/Command/ListCommand.php(��-SVZ(��$ƒXɶ������0���vendor/symfony/console/Command/LockableTrait.php2��-SVZ2��N Òß¶������?���vendor/symfony/console/CommandLoader/CommandLoaderInterface.php>��-SVZ>��ÐeUE¶������?���vendor/symfony/console/CommandLoader/ContainerCommandLoader.php?��-SVZ?�� ºø@¶������=���vendor/symfony/console/CommandLoader/FactoryCommandLoader.php¡��-SVZ¡��þmŸ…¶������(���vendor/symfony/console/ConsoleEvents.php ��-SVZ �� ŒNÕ¶������D���vendor/symfony/console/DependencyInjection/AddConsoleCommandPass.phpŠ ��-SVZŠ ��]rĶ������<���vendor/symfony/console/Descriptor/ApplicationDescription.phpP ��-SVZP ��ÓŒz¶������0���vendor/symfony/console/Descriptor/Descriptor.php���-SVZ����N¬1¶������9���vendor/symfony/console/Descriptor/DescriptorInterface.phpü���-SVZü���±Qµ¶������4���vendor/symfony/console/Descriptor/JsonDescriptor.phpå��-SVZå��à“›—¶������8���vendor/symfony/console/Descriptor/MarkdownDescriptor.php¾��-SVZ¾��÷%*õ¶������4���vendor/symfony/console/Descriptor/TextDescriptor.php."��-SVZ."��íñf¶������3���vendor/symfony/console/Descriptor/XmlDescriptor.phpK��-SVZK��f�ïD¶������4���vendor/symfony/console/Event/ConsoleCommandEvent.php°��-SVZ°��!�ȶ������2���vendor/symfony/console/Event/ConsoleErrorEvent.php^��-SVZ^��Ú×Ha¶������-���vendor/symfony/console/Event/ConsoleEvent.phpÌ��-SVZÌ��ÙåÓ¶������6���vendor/symfony/console/Event/ConsoleExceptionEvent.phpÐ��-SVZÐ��*¦\ȶ������6���vendor/symfony/console/Event/ConsoleTerminateEvent.phpz��-SVZz��³,îL¶������6���vendor/symfony/console/EventListener/ErrorListener.php3��-SVZ3��Às•E¶������=���vendor/symfony/console/Exception/CommandNotFoundException.phpÔ��-SVZÔ��È÷ L¶������7���vendor/symfony/console/Exception/ExceptionInterface.phpf���-SVZf���¡ABª¶������=���vendor/symfony/console/Exception/InvalidArgumentException.php¦���-SVZ¦���Ö̽Z¶������;���vendor/symfony/console/Exception/InvalidOptionException.php¦���-SVZ¦���Ë×H¶������3���vendor/symfony/console/Exception/LogicException.php’���-SVZ’���ÍO\e¶������5���vendor/symfony/console/Exception/RuntimeException.php–���-SVZ–���Ùí,6¶������4���vendor/symfony/console/Formatter/OutputFormatter.phpr��-SVZr��’-¿ö¶������=���vendor/symfony/console/Formatter/OutputFormatterInterface.phpŒ��-SVZŒ��òññÀ¶������9���vendor/symfony/console/Formatter/OutputFormatterStyle.phpJ��-SVZJ��ÏDSȶ������B���vendor/symfony/console/Formatter/OutputFormatterStyleInterface.php„��-SVZ„��÷½G¶������>���vendor/symfony/console/Formatter/OutputFormatterStyleStack.php>��-SVZ>��[†¿–¶������6���vendor/symfony/console/Helper/DebugFormatterHelper.phpx��-SVZx��N©Ø¼¶������2���vendor/symfony/console/Helper/DescriptorHelper.phpw��-SVZw��ÅHð.¶������1���vendor/symfony/console/Helper/FormatterHelper.phpÙ��-SVZÙ��ý†Î¶������(���vendor/symfony/console/Helper/Helper.phpš��-SVZš��`o³¶������1���vendor/symfony/console/Helper/HelperInterface.phpå���-SVZå���Š ¶������+���vendor/symfony/console/Helper/HelperSet.phpo��-SVZo��­kè¶������2���vendor/symfony/console/Helper/InputAwareHelper.phpc��-SVZc��ñø�|¶������/���vendor/symfony/console/Helper/ProcessHelper.phpP ��-SVZP ��Ê_ùʶ������-���vendor/symfony/console/Helper/ProgressBar.php“%��-SVZ“%��Fltñ¶������3���vendor/symfony/console/Helper/ProgressIndicator.phpx��-SVZx��º“
  89. Ŷ������0���vendor/symfony/console/Helper/QuestionHelper.php/��-SVZ/��/׸š¶������7���vendor/symfony/console/Helper/SymfonyQuestionHelper.php, ��-SVZ, ��Z�¿ ¶������'���vendor/symfony/console/Helper/Table.php¿,��-SVZ¿,��p&Lœ¶������+���vendor/symfony/console/Helper/TableCell.php€��-SVZ€��Ìî*Û¶������0���vendor/symfony/console/Helper/TableSeparator.phpÊ���-SVZÊ���az¶������,���vendor/symfony/console/Helper/TableStyle.php
  90. ��-SVZ
  91. ��PÞµ¦¶������*���vendor/symfony/console/Input/ArgvInput.php ��-SVZ ��úXq¶������+���vendor/symfony/console/Input/ArrayInput.phpÔ ��-SVZÔ ��W¡?;¶������&���vendor/symfony/console/Input/Input.phpX ��-SVZX ��C÷ܶ������.���vendor/symfony/console/Input/InputArgument.php��-SVZ��&<¦¯¶������4���vendor/symfony/console/Input/InputAwareInterface.phpš���-SVZš���‡jTŸ¶������0���vendor/symfony/console/Input/InputDefinition.phpü��-SVZü��œøˆÖ¶������/���vendor/symfony/console/Input/InputInterface.phpÉ��-SVZÉ��ŸcÂ�¶������,���vendor/symfony/console/Input/InputOption.php ��-SVZ ��ùýN4¶������9���vendor/symfony/console/Input/StreamableInputInterface.phpÎ���-SVZÎ���ÖÕB›¶������,���vendor/symfony/console/Input/StringInput.phpa��-SVZa��ㄸ"¶������/���vendor/symfony/console/Logger/ConsoleLogger.php ��-SVZ ��Jæ˜&¶������0���vendor/symfony/console/Output/BufferedOutput.php_��-SVZ_��‹ >P¶������/���vendor/symfony/console/Output/ConsoleOutput.phpŽ��-SVZŽ��éa^ ¶������8���vendor/symfony/console/Output/ConsoleOutputInterface.phpà���-SVZà���‡†ÆÊ¶������,���vendor/symfony/console/Output/NullOutput.phpÏ��-SVZÏ��®˜‹Z¶������(���vendor/symfony/console/Output/Output.php˜ ��-SVZ˜ ��pf\¶������1���vendor/symfony/console/Output/OutputInterface.php£��-SVZ£��n ¶������.���vendor/symfony/console/Output/StreamOutput.phpÂ��-SVZÂ��¥<I¶������2���vendor/symfony/console/Question/ChoiceQuestion.phpw
  92. ��-SVZw
  93. ��2t¶������8���vendor/symfony/console/Question/ConfirmationQuestion.phpç��-SVZç�� ­òf¶������,���vendor/symfony/console/Question/Question.phpä ��-SVZä ��»Ñ»„¶������,���vendor/symfony/console/Style/OutputStyle.phpW��-SVZW��ê8îö¶������/���vendor/symfony/console/Style/StyleInterface.phpÏ��-SVZÏ��&nÅѶ������-���vendor/symfony/console/Style/SymfonyStyle.php#��-SVZ#�� Ùä¶������#���vendor/symfony/console/Terminal.phpú��-SVZú��sÁð¥¶������3���vendor/symfony/console/Tester/ApplicationTester.php+ ��-SVZ+ ��{¾ƒq¶������/���vendor/symfony/console/Tester/CommandTester.php.��-SVZ.��;˜H¶������:���vendor/symfony/filesystem/Exception/ExceptionInterface.phpi���-SVZi���$ ÿ›¶������=���vendor/symfony/filesystem/Exception/FileNotFoundException.php¼��-SVZ¼��pí\¶¶������3���vendor/symfony/filesystem/Exception/IOException.php‡��-SVZ‡��€ü#Ѷ������<���vendor/symfony/filesystem/Exception/IOExceptionInterface.php¦���-SVZ¦���jÙwM¶������(���vendor/symfony/filesystem/Filesystem.php¶8��-SVZ¶8��ᅳk¶������)���vendor/symfony/filesystem/LockHandler.phpÏ��-SVZÏ��fmm¶������A���vendor/symfony/event-dispatcher/ContainerAwareEventDispatcher.php¯��-SVZ¯��ŸII<¶������B���vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcher.phpW��-SVZW��ÇíïA¶������K���vendor/symfony/event-dispatcher/Debug/TraceableEventDispatcherInterface.php5��-SVZ5��fV¶������9���vendor/symfony/event-dispatcher/Debug/WrappedListener.php ��-SVZ ��Ý¢_w¶������M���vendor/symfony/event-dispatcher/DependencyInjection/RegisterListenersPass.php^��-SVZ^��J×äö¶������)���vendor/symfony/event-dispatcher/Event.php)��-SVZ)��@ƒÙB¶������3���vendor/symfony/event-dispatcher/EventDispatcher.php��-SVZ��‚ä\X¶������<���vendor/symfony/event-dispatcher/EventDispatcherInterface.phpŠ��-SVZŠ��p´«X¶������<���vendor/symfony/event-dispatcher/EventSubscriberInterface.php°���-SVZ°���Œo;y¶������0���vendor/symfony/event-dispatcher/GenericEvent.phpu��-SVZu��º–÷5¶������<���vendor/symfony/event-dispatcher/ImmutableEventDispatcher.phpq��-SVZq��ñ½¶������/���vendor/symfony/finder/Comparator/Comparator.phpŒ��-SVZŒ��wþT¶������3���vendor/symfony/finder/Comparator/DateComparator.php#��-SVZ#��°ζ������5���vendor/symfony/finder/Comparator/NumberComparator.php|��-SVZ|��ITÇͶ������9���vendor/symfony/finder/Exception/AccessDeniedException.php„���-SVZ„���½¾sœ¶������6���vendor/symfony/finder/Exception/ExceptionInterface.php†���-SVZ†���Lôà~¶������ ���vendor/symfony/finder/Finder.php(!��-SVZ(!��¸�¹¶���������vendor/symfony/finder/Glob.php³��-SVZ³��Ðn—ض������7���vendor/symfony/finder/Iterator/CustomFilterIterator.php[��-SVZ[��­åW¶������:���vendor/symfony/finder/Iterator/DateRangeFilterIterator.phpx��-SVZx��ôP¶������;���vendor/symfony/finder/Iterator/DepthRangeFilterIterator.phpî��-SVZî��üÍ�q¶������A���vendor/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.phpí��-SVZí��nõH¶������9���vendor/symfony/finder/Iterator/FileTypeFilterIterator.phpZ��-SVZZ��(&ø¶������<���vendor/symfony/finder/Iterator/FilecontentFilterIterator.php5��-SVZ5��ší¶������9���vendor/symfony/finder/Iterator/FilenameFilterIterator.phpr��-SVZr��tu¶������1���vendor/symfony/finder/Iterator/FilterIterator.phpÅ��-SVZÅ�� œ™¶������=���vendor/symfony/finder/Iterator/MultiplePcreFilterIterator.php-��-SVZ-��ºÎÒ_¶������5���vendor/symfony/finder/Iterator/PathFilterIterator.phpÏ��-SVZÏ��ºªÇ¶������=���vendor/symfony/finder/Iterator/RecursiveDirectoryIterator.php
  94. ��-SVZ
  95. ��ùΚѶ������:���vendor/symfony/finder/Iterator/SizeRangeFilterIterator.phpe��-SVZe��Ÿ’áé¶������3���vendor/symfony/finder/Iterator/SortableIterator.php*��-SVZ*��€õ´^¶������%���vendor/symfony/finder/SplFileInfo.phpý��-SVZý��`ØÓ¶������E���vendor/symfony/options-resolver/Debug/OptionsResolverIntrospector.phpy��-SVZy��Õhx¶������=���vendor/symfony/options-resolver/Exception/AccessException.phpž���-SVZž���›5¶������@���vendor/symfony/options-resolver/Exception/ExceptionInterface.phpn���-SVZn���Ìøy¶������F���vendor/symfony/options-resolver/Exception/InvalidArgumentException.php°���-SVZ°���²G¹¶������E���vendor/symfony/options-resolver/Exception/InvalidOptionsException.php’���-SVZ’���ëÿk ¶������E���vendor/symfony/options-resolver/Exception/MissingOptionsException.php’���-SVZ’���=¼½�¶������F���vendor/symfony/options-resolver/Exception/NoConfigurationException.phpõ���-SVZõ���j‘®E¶������C���vendor/symfony/options-resolver/Exception/NoSuchOptionException.php®���-SVZ®���g]Ýȶ������G���vendor/symfony/options-resolver/Exception/OptionDefinitionException.php§���-SVZ§���ó@4�¶������G���vendor/symfony/options-resolver/Exception/UndefinedOptionsException.php•���-SVZ•���p Í�¶������+���vendor/symfony/options-resolver/Options.php{���-SVZ{���é|·Š¶������3���vendor/symfony/options-resolver/OptionsResolver.php�6��-SVZ�6��¡^“¶������'���vendor/symfony/polyfill-php70/Php70.php}��-SVZ}��ùh!¶������A���vendor/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php/���-SVZ/���|mͶ������@���vendor/symfony/polyfill-php70/Resources/stubs/AssertionError.php.���-SVZ.���&8úy¶������E���vendor/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php3���-SVZ3���û�h;¶������7���vendor/symfony/polyfill-php70/Resources/stubs/Error.php)���-SVZ)���[k ¶������<���vendor/symfony/polyfill-php70/Resources/stubs/ParseError.php*���-SVZ*���•¨á¤¶������X���vendor/symfony/polyfill-php70/Resources/stubs/SessionUpdateTimestampHandlerInterface.php›���-SVZ›���£ú~ó¶������;���vendor/symfony/polyfill-php70/Resources/stubs/TypeError.php)���-SVZ)���â¸O_¶������+���vendor/symfony/polyfill-php70/bootstrap.phpm��-SVZm��¿f˜¶������'���vendor/symfony/polyfill-php72/Php72.php=��-SVZ=��hß¶������+���vendor/symfony/polyfill-php72/bootstrap.phpÛ��-SVZÛ��"’åø¶������)���vendor/psr/log/Psr/Log/AbstractLogger.php;��-SVZ;��ñ>3[¶������3���vendor/psr/log/Psr/Log/InvalidArgumentException.php`���-SVZ`��� ˆX1¶������#���vendor/psr/log/Psr/Log/LogLevel.phpû���-SVZû���jðñ8¶������/���vendor/psr/log/Psr/Log/LoggerAwareInterface.php|���-SVZ|���$£ˆ¶������+���vendor/psr/log/Psr/Log/LoggerAwareTrait.php§���-SVZ§���T½úB¶������*���vendor/psr/log/Psr/Log/LoggerInterface.phpÆ��-SVZÆ��»sg¶������&���vendor/psr/log/Psr/Log/LoggerTrait.phpi��-SVZi��35§Þ¶������%���vendor/psr/log/Psr/Log/NullLogger.phpž���-SVZž���Çö������A���vendor/doctrine/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.phpë
  96. ��-SVZë
  97. ��Ç•÷¶������J���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation.php)��-SVZ)��{É5¶������T���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attribute.php¯���-SVZ¯���fʓ۶������U���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attributes.php����-SVZ����¾~½Ä¶������O���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php���-SVZ���ðˆS]¶������[���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.phpð��-SVZð��¥ø¶������S���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Required.phpm���-SVZm���÷ÑZ’¶������Q���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php0��-SVZ0��Û u£¶������S���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php��-SVZ��;Rx{¶������P���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.phpO��-SVZO��êkXh¶������R���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.phpî��-SVZî��÷ޱü¶������L���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php\��-SVZ\��5�âh¶������H���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php^��-SVZ^��˜½ÞÀ¶������I���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.phpQT��-SVZQT��~x³¶������O���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/FileCacheReader.phpu��-SVZu��±# ™¶������M���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.phpÓ��-SVZÓ��nWS¶������I���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php��-SVZ��cIÕ—¶������F���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/Reader.php"��-SVZ"��Р@Ö¶������V���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php?��-SVZ?��ˆ\b¶������K���vendor/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.phpp��-SVZp��gÁþ^¶������I���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/AssertHelper.php��-SVZ��%{j¼¶������R���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/FileExistsAssertTrait.php5��-SVZ5��ýjE¶������R���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/FileSystemAssertTrait.phpQ��-SVZQ��<u©¶������M���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/RangeAssertTrait.phpÅ ��-SVZÅ ��ÇûѶ������N���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/ScalarAssertTrait.php2 ��-SVZ2 ���H*H¶������O���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/StringsAssertTrait.php¦��-SVZ¦���kq¶������K���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/XMLAssertTrait.php<��-SVZ<��BöI-¶������Y���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/DirectoryEmptyConstraint.phpÎ��-SVZÎ��¡+#¶������Z���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/DirectoryExistsConstraint.php��-SVZ��ç4˜©¶������U���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileExistsConstraint.php��-SVZ��åé>H¶������U���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileIsLinkConstraint.phpø��-SVZø��õ­À¶������Z���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileIsValidLinkConstraint.php ��-SVZ ��ÕHÑØ¶������e���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FilePermissionsIsIdenticalConstraint.phpp��-SVZp��vùµ¶������^���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FilePermissionsMaskConstraint.php2��-SVZ2��[Öe ¶������V���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/NumberRangeConstraint.php`��-SVZ`��Œ]
  98. F¶������V���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/SameStringsConstraint.php‘��-SVZ‘��|`.¶������Q���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/ScalarConstraint.php_��-SVZ_��j3�µ¶������V���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/UnsignedIntConstraint.php��-SVZ��È÷da¶������Z���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/AbstractXMLConstraint.phpý��-SVZý��:+g¶������\���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/XMLMatchesXSDConstraint.php¸��-SVZ¸���?á¶������W���vendor/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/XMLValidConstraint.php,��-SVZ,��ïbF7¶������8���vendor/paragonie/random_compat/lib/byte_safe_strings.php ��-SVZ ��ÊS7¶������2���vendor/paragonie/random_compat/lib/cast_to_int.phpû��-SVZû��¡ÎEš¶������5���vendor/paragonie/random_compat/lib/error_polyfill.php��-SVZ��úša4¶������-���vendor/paragonie/random_compat/lib/random.php ��-SVZ ��!,pÕ¶������>���vendor/paragonie/random_compat/lib/random_bytes_com_dotnet.phpá��-SVZá��2y=ê¶������?���vendor/paragonie/random_compat/lib/random_bytes_dev_urandom.php��-SVZ��‡ªB^¶������=���vendor/paragonie/random_compat/lib/random_bytes_libsodium.phpÔ��-SVZÔ��ô´r¶������D���vendor/paragonie/random_compat/lib/random_bytes_libsodium_legacy.phpæ��-SVZæ��h$;B¶������:���vendor/paragonie/random_compat/lib/random_bytes_mcrypt.php��-SVZ�� õ¼¶������1���vendor/paragonie/random_compat/lib/random_int.phpî��-SVZî��6« ª¶������3���vendor/paragonie/random_compat/other/build_phar.php‰��-SVZ‰��ï²
  99. ½¶������1���vendor/paragonie/random_compat/psalm-autoload.phpç���-SVZç���·ж���������vendor/autoload.phpŒ���-SVZŒ���blM޶���������LICENSES��-SVZS��t»†Ì¶������#!/usr/bin/env bash
  100. set -e
  101. CHANGED_FILES=$(git diff --name-only --diff-filter=ACMRTUXB "${COMMIT_RANGE}")
  102. if ! echo "${CHANGED_FILES}" | grep -qE "^(\\.php_cs(\\.dist)?|composer\\.lock)$"; then IFS=$'\n' EXTRA_ARGS=('--path-mode=intersection' '--' ${CHANGED_FILES[@]}); fi
  103. vendor/bin/php-cs-fixer fix --config=.php_cs.dist -v --dry-run --stop-on-violation --using-cache=no "${EXTRA_ARGS[@]}"
  104. <?php
  105. namespace PhpCsFixer;
  106. use PhpCsFixer\Tokenizer\Tokens;
  107. abstract class AbstractAlignFixerHelper
  108. {
  109. const ALIGNABLE_PLACEHOLDER = "\x2 ALIGNABLE%d \x3";
  110. protected $deepestLevel = 0;
  111. public function fix(Tokens $tokens)
  112. {
  113. $tokensClone = clone $tokens;
  114. $this->injectAlignmentPlaceholders($tokensClone, 0, count($tokens));
  115. $content = $this->replacePlaceholder($tokensClone);
  116. $tokens->setCode($content);
  117. }
  118. abstract protected function injectAlignmentPlaceholders(Tokens $tokens, $startAt, $endAt);
  119. protected function replacePlaceholder(Tokens $tokens)
  120. {
  121. $tmpCode = $tokens->generateCode();
  122. for ($j = 0; $j <= $this->deepestLevel; ++$j) {
  123. $placeholder = sprintf(self::ALIGNABLE_PLACEHOLDER, $j);
  124. if (false === strpos($tmpCode, $placeholder)) {
  125. continue;
  126. }
  127. $lines = explode("\n", $tmpCode);
  128. $linesWithPlaceholder = [];
  129. $blockSize = 0;
  130. $linesWithPlaceholder[$blockSize] = [];
  131. foreach ($lines as $index => $line) {
  132. if (substr_count($line, $placeholder) > 0) {
  133. $linesWithPlaceholder[$blockSize][] = $index;
  134. } else {
  135. ++$blockSize;
  136. $linesWithPlaceholder[$blockSize] = [];
  137. }
  138. }
  139. foreach ($linesWithPlaceholder as $group) {
  140. if (count($group) < 1) {
  141. continue;
  142. }
  143. $rightmostSymbol = 0;
  144. foreach ($group as $index) {
  145. $rightmostSymbol = max($rightmostSymbol, strpos(utf8_decode($lines[$index]), $placeholder));
  146. }
  147. foreach ($group as $index) {
  148. $line = $lines[$index];
  149. $currentSymbol = strpos(utf8_decode($line), $placeholder);
  150. $delta = abs($rightmostSymbol - $currentSymbol);
  151. if ($delta > 0) {
  152. $line = str_replace($placeholder, str_repeat(' ', $delta).$placeholder, $line);
  153. $lines[$index] = $line;
  154. }
  155. }
  156. }
  157. $tmpCode = str_replace($placeholder, '', implode("\n", $lines));
  158. }
  159. return $tmpCode;
  160. }
  161. }
  162. <?php
  163. namespace PhpCsFixer;
  164. use PhpCsFixer\Doctrine\Annotation\Tokens as DoctrineAnnotationTokens;
  165. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  166. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  167. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  168. use PhpCsFixer\Tokenizer\Token as PhpToken;
  169. use PhpCsFixer\Tokenizer\Tokens as PhpTokens;
  170. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  171. abstract class AbstractDoctrineAnnotationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  172. {
  173. private $classyElements;
  174. public function isCandidate(PhpTokens $tokens)
  175. {
  176. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  177. }
  178. protected function applyFix(\SplFileInfo $file, PhpTokens $phpTokens)
  179. {
  180. $analyzer = new TokensAnalyzer($phpTokens);
  181. $this->classyElements = $analyzer->getClassyElements();
  182. foreach ($phpTokens->findGivenKind(T_DOC_COMMENT) as $index => $docCommentToken) {
  183. if (!$this->nextElementAcceptsDoctrineAnnotations($phpTokens, $index)) {
  184. continue;
  185. }
  186. $tokens = DoctrineAnnotationTokens::createFromDocComment(
  187. $docCommentToken,
  188. $this->configuration['ignored_tags']
  189. );
  190. $this->fixAnnotations($tokens);
  191. $phpTokens[$index] = new PhpToken([T_DOC_COMMENT, $tokens->getCode()]);
  192. }
  193. }
  194. abstract protected function fixAnnotations(DoctrineAnnotationTokens $doctrineAnnotationTokens);
  195. protected function createConfigurationDefinition()
  196. {
  197. return new FixerConfigurationResolver([
  198. (new FixerOptionBuilder('ignored_tags', 'List of tags that must not be treated as Doctrine Annotations.'))
  199. ->setAllowedTypes(['array'])
  200. ->setAllowedValues([static function ($values) {
  201. foreach ($values as $value) {
  202. if (!is_string($value)) {
  203. return false;
  204. }
  205. }
  206. return true;
  207. }])
  208. ->setDefault([
  209. 'abstract',
  210. 'access',
  211. 'code',
  212. 'deprec',
  213. 'encode',
  214. 'exception',
  215. 'final',
  216. 'ingroup',
  217. 'inheritdoc',
  218. 'inheritDoc',
  219. 'magic',
  220. 'name',
  221. 'toc',
  222. 'tutorial',
  223. 'private',
  224. 'static',
  225. 'staticvar',
  226. 'staticVar',
  227. 'throw',
  228. 'api',
  229. 'author',
  230. 'category',
  231. 'copyright',
  232. 'deprecated',
  233. 'example',
  234. 'filesource',
  235. 'global',
  236. 'ignore',
  237. 'internal',
  238. 'license',
  239. 'link',
  240. 'method',
  241. 'package',
  242. 'param',
  243. 'property',
  244. 'property-read',
  245. 'property-write',
  246. 'return',
  247. 'see',
  248. 'since',
  249. 'source',
  250. 'subpackage',
  251. 'throws',
  252. 'todo',
  253. 'TODO',
  254. 'usedBy',
  255. 'uses',
  256. 'var',
  257. 'version',
  258. 'after',
  259. 'afterClass',
  260. 'backupGlobals',
  261. 'backupStaticAttributes',
  262. 'before',
  263. 'beforeClass',
  264. 'codeCoverageIgnore',
  265. 'codeCoverageIgnoreStart',
  266. 'codeCoverageIgnoreEnd',
  267. 'covers',
  268. 'coversDefaultClass',
  269. 'coversNothing',
  270. 'dataProvider',
  271. 'depends',
  272. 'expectedException',
  273. 'expectedExceptionCode',
  274. 'expectedExceptionMessage',
  275. 'expectedExceptionMessageRegExp',
  276. 'group',
  277. 'large',
  278. 'medium',
  279. 'preserveGlobalState',
  280. 'requires',
  281. 'runTestsInSeparateProcesses',
  282. 'runInSeparateProcess',
  283. 'small',
  284. 'test',
  285. 'testdox',
  286. 'ticket',
  287. 'uses',
  288. 'SuppressWarnings',
  289. 'noinspection',
  290. 'package_version',
  291. 'enduml',
  292. 'startuml',
  293. 'fix',
  294. 'FIXME',
  295. 'fixme',
  296. 'override',
  297. ])
  298. ->getOption(),
  299. ]);
  300. }
  301. private function nextElementAcceptsDoctrineAnnotations(PhpTokens $tokens, $index)
  302. {
  303. do {
  304. $index = $tokens->getNextMeaningfulToken($index);
  305. } while ($tokens[$index]->isGivenKind([T_ABSTRACT, T_FINAL]));
  306. if ($tokens[$index]->isClassy()) {
  307. return true;
  308. }
  309. while ($tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT])) {
  310. $index = $tokens->getNextMeaningfulToken($index);
  311. }
  312. return isset($this->classyElements[$index]);
  313. }
  314. }
  315. <?php
  316. namespace PhpCsFixer;
  317. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  318. use PhpCsFixer\ConfigurationException\InvalidForEnvFixerConfigurationException;
  319. use PhpCsFixer\ConfigurationException\RequiredFixerConfigurationException;
  320. use PhpCsFixer\Fixer\ConfigurableFixerInterface;
  321. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  322. use PhpCsFixer\Fixer\DefinedFixerInterface;
  323. use PhpCsFixer\Fixer\FixerInterface;
  324. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  325. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
  326. use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException;
  327. use PhpCsFixer\Tokenizer\Tokens;
  328. use Symfony\Component\OptionsResolver\Exception\ExceptionInterface;
  329. use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
  330. abstract class AbstractFixer implements FixerInterface, DefinedFixerInterface
  331. {
  332. protected $configuration;
  333. protected $whitespacesConfig;
  334. private $configurationDefinition;
  335. public function __construct()
  336. {
  337. if ($this instanceof ConfigurableFixerInterface) {
  338. try {
  339. $this->configure([]);
  340. } catch (RequiredFixerConfigurationException $e) {
  341. }
  342. }
  343. if ($this instanceof WhitespacesAwareFixerInterface) {
  344. $this->whitespacesConfig = $this->getDefaultWhitespacesFixerConfig();
  345. }
  346. }
  347. final public function fix(\SplFileInfo $file, Tokens $tokens)
  348. {
  349. if ($this instanceof ConfigurableFixerInterface && null === $this->configuration) {
  350. throw new RequiredFixerConfigurationException($this->getName(), 'Configuration is required.');
  351. }
  352. if (0 < $tokens->count() && $this->isCandidate($tokens) && $this->supports($file)) {
  353. $this->applyFix($file, $tokens);
  354. }
  355. }
  356. public function isRisky()
  357. {
  358. return false;
  359. }
  360. public function getName()
  361. {
  362. $nameParts = explode('\\', get_called_class());
  363. $name = substr(end($nameParts), 0, -strlen('Fixer'));
  364. return Utils::camelCaseToUnderscore($name);
  365. }
  366. public function getPriority()
  367. {
  368. return 0;
  369. }
  370. public function supports(\SplFileInfo $file)
  371. {
  372. return true;
  373. }
  374. public function configure(array $configuration = null)
  375. {
  376. if (!$this instanceof ConfigurationDefinitionFixerInterface) {
  377. throw new \LogicException('Cannot configure using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface".');
  378. }
  379. if (null === $configuration) {
  380. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  381. throw new \InvalidArgumentException('Parameter must not be `null`. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
  382. }
  383. @trigger_error(
  384. 'Passing NULL to set default configuration is deprecated and will not be supported in 3.0, use an empty array instead.',
  385. E_USER_DEPRECATED
  386. );
  387. $configuration = [];
  388. }
  389. try {
  390. $this->configuration = $this->getConfigurationDefinition()->resolve($configuration);
  391. } catch (MissingOptionsException $exception) {
  392. throw new RequiredFixerConfigurationException(
  393. $this->getName(),
  394. sprintf('Missing required configuration: %s', $exception->getMessage()),
  395. $exception
  396. );
  397. } catch (InvalidOptionsForEnvException $exception) {
  398. throw new InvalidForEnvFixerConfigurationException(
  399. $this->getName(),
  400. sprintf('Invalid configuration for env: %s', $exception->getMessage()),
  401. $exception
  402. );
  403. } catch (ExceptionInterface $exception) {
  404. throw new InvalidFixerConfigurationException(
  405. $this->getName(),
  406. sprintf('Invalid configuration: %s', $exception->getMessage()),
  407. $exception
  408. );
  409. }
  410. }
  411. public function getConfigurationDefinition()
  412. {
  413. if (!$this instanceof ConfigurationDefinitionFixerInterface) {
  414. throw new \LogicException('Cannot get configuration definition using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface".');
  415. }
  416. if (null === $this->configurationDefinition) {
  417. $this->configurationDefinition = $this->createConfigurationDefinition();
  418. }
  419. return $this->configurationDefinition;
  420. }
  421. public function setWhitespacesConfig(WhitespacesFixerConfig $config)
  422. {
  423. if (!$this instanceof WhitespacesAwareFixerInterface) {
  424. throw new \LogicException('Cannot run method for class not implementing "PhpCsFixer\Fixer\WhitespacesAwareFixerInterface".');
  425. }
  426. $this->whitespacesConfig = $config;
  427. }
  428. abstract protected function applyFix(\SplFileInfo $file, Tokens $tokens);
  429. protected function createConfigurationDefinition()
  430. {
  431. if (!$this instanceof ConfigurationDefinitionFixerInterface) {
  432. throw new \LogicException('Cannot create configuration definition using Abstract parent, child not implementing "PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface".');
  433. }
  434. throw new \LogicException('Not implemented.');
  435. }
  436. private function getDefaultWhitespacesFixerConfig()
  437. {
  438. static $defaultWhitespacesFixerConfig = null;
  439. if (null === $defaultWhitespacesFixerConfig) {
  440. $defaultWhitespacesFixerConfig = new WhitespacesFixerConfig(' ', "\n");
  441. }
  442. return $defaultWhitespacesFixerConfig;
  443. }
  444. }
  445. <?php
  446. namespace PhpCsFixer;
  447. use PhpCsFixer\Tokenizer\CT;
  448. use PhpCsFixer\Tokenizer\Tokens;
  449. abstract class AbstractFunctionReferenceFixer extends AbstractFixer
  450. {
  451. public function isRisky()
  452. {
  453. return true;
  454. }
  455. protected function find($functionNameToSearch, Tokens $tokens, $start = 0, $end = null)
  456. {
  457. $end = null === $end ? $tokens->count() : $end;
  458. $candidateSequence = [[T_STRING, $functionNameToSearch], '('];
  459. $matches = $tokens->findSequence($candidateSequence, $start, $end, false);
  460. if (null === $matches) {
  461. return null;
  462. }
  463. list($functionName, $openParenthesis) = array_keys($matches);
  464. $functionNamePrefix = $tokens->getPrevMeaningfulToken($functionName);
  465. $functionNamePrecedingToken = $tokens[$functionNamePrefix];
  466. if ($functionNamePrecedingToken->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, CT::T_RETURN_REF])) {
  467. return $this->find($functionNameToSearch, $tokens, $openParenthesis, $end);
  468. }
  469. if ($functionNamePrecedingToken->isGivenKind(T_NS_SEPARATOR)) {
  470. $namespaceCandidate = $tokens->getPrevMeaningfulToken($functionNamePrefix);
  471. $namespaceCandidateToken = $tokens[$namespaceCandidate];
  472. if ($namespaceCandidateToken->isGivenKind([T_NEW, T_STRING, CT::T_NAMESPACE_OPERATOR])) {
  473. return $this->find($functionNameToSearch, $tokens, $openParenthesis, $end);
  474. }
  475. }
  476. $closeParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openParenthesis);
  477. return [$functionName, $openParenthesis, $closeParenthesis];
  478. }
  479. }
  480. <?php
  481. namespace PhpCsFixer;
  482. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  483. use PhpCsFixer\Tokenizer\Token;
  484. use PhpCsFixer\Tokenizer\Tokens;
  485. abstract class AbstractLinesBeforeNamespaceFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  486. {
  487. protected function fixLinesBeforeNamespace(Tokens $tokens, $index, $expectedMin, $expectedMax)
  488. {
  489. $precedingNewlines = 0;
  490. $newlineInOpening = false;
  491. $openingToken = null;
  492. for ($i = 1; $i <= 2; ++$i) {
  493. if (isset($tokens[$index - $i])) {
  494. $token = $tokens[$index - $i];
  495. if ($token->isGivenKind(T_OPEN_TAG)) {
  496. $openingToken = $token;
  497. $openingTokenIndex = $index - $i;
  498. $newlineInOpening = false !== strpos($token->getContent(), "\n");
  499. if ($newlineInOpening) {
  500. ++$precedingNewlines;
  501. }
  502. break;
  503. }
  504. if (false === $token->isGivenKind(T_WHITESPACE)) {
  505. break;
  506. }
  507. $precedingNewlines += substr_count($token->getContent(), "\n");
  508. }
  509. }
  510. if ($precedingNewlines >= $expectedMin && $precedingNewlines <= $expectedMax) {
  511. return;
  512. }
  513. $previousIndex = $index - 1;
  514. $previous = $tokens[$previousIndex];
  515. if (0 === $expectedMax) {
  516. if ($previous->isWhitespace()) {
  517. $tokens->clearAt($previousIndex);
  518. }
  519. if ($newlineInOpening) {
  520. $tokens[$openingTokenIndex] = new Token([T_OPEN_TAG, rtrim($openingToken->getContent()).' ']);
  521. }
  522. return;
  523. }
  524. $lineEnding = $this->whitespacesConfig->getLineEnding();
  525. $newlinesForWhitespaceToken = $expectedMax;
  526. if (null !== $openingToken) {
  527. $content = rtrim($openingToken->getContent());
  528. $newContent = $content.$lineEnding;
  529. $tokens[$openingTokenIndex] = new Token([T_OPEN_TAG, $newContent]);
  530. --$newlinesForWhitespaceToken;
  531. }
  532. if (0 === $newlinesForWhitespaceToken) {
  533. if ($previous->isWhitespace()) {
  534. $tokens->clearAt($previousIndex);
  535. }
  536. return;
  537. }
  538. $newWhitespaceToken = new Token([T_WHITESPACE, str_repeat($lineEnding, $newlinesForWhitespaceToken)]);
  539. if ($previous->isWhitespace()) {
  540. $tokens[$previousIndex] = $newWhitespaceToken;
  541. } else {
  542. $tokens->insertAt($index, $newWhitespaceToken);
  543. }
  544. }
  545. }
  546. <?php
  547. namespace PhpCsFixer;
  548. use PhpCsFixer\Tokenizer\Token;
  549. use PhpCsFixer\Tokenizer\Tokens;
  550. abstract class AbstractNoUselessElseFixer extends AbstractFixer
  551. {
  552. public function getPriority()
  553. {
  554. return 25;
  555. }
  556. protected function isSuperfluousElse(Tokens $tokens, $index)
  557. {
  558. $previousBlockStart = $index;
  559. do {
  560. list($previousBlockStart, $previousBlockEnd) = $this->getPreviousBlock($tokens, $previousBlockStart);
  561. $previous = $previousBlockEnd;
  562. if ($tokens[$previous]->equals('}')) {
  563. $previous = $tokens->getPrevMeaningfulToken($previous);
  564. }
  565. if (
  566. !$tokens[$previous]->equals(';') ||
  567. $tokens[$tokens->getPrevMeaningfulToken($previous)]->equals('{')
  568. ) {
  569. return false;
  570. }
  571. $candidateIndex = $tokens->getPrevTokenOfKind(
  572. $previous,
  573. [
  574. ';',
  575. [T_BREAK],
  576. [T_CLOSE_TAG],
  577. [T_CONTINUE],
  578. [T_EXIT],
  579. [T_GOTO],
  580. [T_IF],
  581. [T_RETURN],
  582. [T_THROW],
  583. ]
  584. );
  585. if (
  586. null === $candidateIndex
  587. || $tokens[$candidateIndex]->equalsAny([';', [T_CLOSE_TAG], [T_IF]])
  588. || $this->isInConditional($tokens, $candidateIndex, $previousBlockStart)
  589. || $this->isInConditionWithoutBraces($tokens, $candidateIndex, $previousBlockStart)
  590. ) {
  591. return false;
  592. }
  593. } while (!$tokens[$previousBlockStart]->isGivenKind(T_IF));
  594. return true;
  595. }
  596. private function getPreviousBlock(Tokens $tokens, $index)
  597. {
  598. $close = $previous = $tokens->getPrevMeaningfulToken($index);
  599. if ($tokens[$close]->equals('}')) {
  600. $previous = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $close, false);
  601. }
  602. $open = $tokens->getPrevTokenOfKind($previous, [[T_IF], [T_ELSE], [T_ELSEIF]]);
  603. if ($tokens[$open]->isGivenKind(T_IF)) {
  604. $elseCandidate = $tokens->getPrevMeaningfulToken($open);
  605. if ($tokens[$elseCandidate]->isGivenKind(T_ELSE)) {
  606. $open = $elseCandidate;
  607. }
  608. }
  609. return [$open, $close];
  610. }
  611. private function isInConditional(Tokens $tokens, $index, $lowerLimitIndex)
  612. {
  613. $candidateIndex = $tokens->getPrevTokenOfKind($index, [')', ';', ':']);
  614. if ($tokens[$candidateIndex]->equals(':')) {
  615. return true;
  616. }
  617. if (!$tokens[$candidateIndex]->equals(')')) {
  618. return false;
  619. }
  620. $open = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $candidateIndex, false);
  621. return $tokens->getPrevMeaningfulToken($open) > $lowerLimitIndex;
  622. }
  623. private function isInConditionWithoutBraces(Tokens $tokens, $index, $lowerLimitIndex)
  624. {
  625. do {
  626. if ($tokens[$index]->isComment() || $tokens[$index]->isWhitespace()) {
  627. $index = $tokens->getPrevMeaningfulToken($index);
  628. }
  629. $token = $tokens[$index];
  630. if ($token->isGivenKind([T_IF, T_ELSEIF, T_ELSE])) {
  631. return true;
  632. }
  633. if ($token->equals(';', '}')) {
  634. return false;
  635. }
  636. if ($token->equals('{')) {
  637. $index = $tokens->getPrevMeaningfulToken($index);
  638. if ($tokens[$index]->isGivenKind(T_DO)) {
  639. --$index;
  640. continue;
  641. }
  642. if (!$tokens[$index]->equals(')')) {
  643. return false;
  644. }
  645. $index = $tokens->findBlockEnd(
  646. Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
  647. $index,
  648. false
  649. );
  650. $index = $tokens->getPrevMeaningfulToken($index);
  651. if ($tokens[$index]->isGivenKind([T_IF, T_ELSEIF])) {
  652. return false;
  653. }
  654. } elseif ($token->equals(')')) {
  655. $type = Tokens::detectBlockType($token);
  656. $index = $tokens->findBlockEnd(
  657. $type['type'],
  658. $index,
  659. false
  660. );
  661. $index = $tokens->getPrevMeaningfulToken($index);
  662. } else {
  663. --$index;
  664. }
  665. } while ($index > $lowerLimitIndex);
  666. return false;
  667. }
  668. }
  669. <?php
  670. namespace PhpCsFixer;
  671. use PhpCsFixer\DocBlock\Annotation;
  672. use PhpCsFixer\DocBlock\DocBlock;
  673. use PhpCsFixer\Tokenizer\Token;
  674. use PhpCsFixer\Tokenizer\Tokens;
  675. abstract class AbstractPhpdocTypesFixer extends AbstractFixer
  676. {
  677. protected $tags;
  678. public function __construct()
  679. {
  680. parent::__construct();
  681. $this->tags = Annotation::getTagsWithTypes();
  682. }
  683. public function isCandidate(Tokens $tokens)
  684. {
  685. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  686. }
  687. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  688. {
  689. foreach ($tokens as $index => $token) {
  690. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  691. continue;
  692. }
  693. $doc = new DocBlock($token->getContent());
  694. $annotations = $doc->getAnnotationsOfType($this->tags);
  695. if (empty($annotations)) {
  696. continue;
  697. }
  698. foreach ($annotations as $annotation) {
  699. $this->fixTypes($annotation);
  700. }
  701. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  702. }
  703. }
  704. abstract protected function normalize($type);
  705. private function fixTypes(Annotation $annotation)
  706. {
  707. $types = $annotation->getTypes();
  708. $new = $this->normalizeTypes($types);
  709. if ($types !== $new) {
  710. $annotation->setTypes($new);
  711. }
  712. }
  713. private function normalizeTypes(array $types)
  714. {
  715. foreach ($types as $index => $type) {
  716. $types[$index] = $this->normalizeType($type);
  717. }
  718. return $types;
  719. }
  720. private function normalizeType($type)
  721. {
  722. if ('[]' === substr($type, -2)) {
  723. return $this->normalize(substr($type, 0, -2)).'[]';
  724. }
  725. return $this->normalize($type);
  726. }
  727. }
  728. <?php
  729. namespace PhpCsFixer;
  730. use PhpCsFixer\Fixer\FixerInterface;
  731. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  732. use PhpCsFixer\Tokenizer\Tokens;
  733. abstract class AbstractProxyFixer extends AbstractFixer
  734. {
  735. protected $proxyFixers;
  736. public function __construct()
  737. {
  738. foreach (Utils::sortFixers($this->createProxyFixers()) as $proxyFixer) {
  739. $this->proxyFixers[$proxyFixer->getName()] = $proxyFixer;
  740. }
  741. parent::__construct();
  742. }
  743. public function isCandidate(Tokens $tokens)
  744. {
  745. foreach ($this->proxyFixers as $fixer) {
  746. if ($fixer->isCandidate($tokens)) {
  747. return true;
  748. }
  749. }
  750. return false;
  751. }
  752. public function isRisky()
  753. {
  754. foreach ($this->proxyFixers as $fixer) {
  755. if ($fixer->isRisky()) {
  756. return true;
  757. }
  758. }
  759. return false;
  760. }
  761. public function getPriority()
  762. {
  763. if (count($this->proxyFixers) > 1) {
  764. throw new \LogicException('You need to override this method to provide the priority of combined fixers.');
  765. }
  766. return reset($this->proxyFixers)->getPriority();
  767. }
  768. public function supports(\SplFileInfo $file)
  769. {
  770. foreach ($this->proxyFixers as $fixer) {
  771. if ($fixer->supports($file)) {
  772. return true;
  773. }
  774. }
  775. return false;
  776. }
  777. public function setWhitespacesConfig(WhitespacesFixerConfig $config)
  778. {
  779. parent::setWhitespacesConfig($config);
  780. foreach ($this->proxyFixers as $fixer) {
  781. if ($fixer instanceof WhitespacesAwareFixerInterface) {
  782. $fixer->setWhitespacesConfig($config);
  783. }
  784. }
  785. }
  786. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  787. {
  788. foreach ($this->proxyFixers as $fixer) {
  789. $fixer->fix($file, $tokens);
  790. }
  791. }
  792. abstract protected function createProxyFixers();
  793. }
  794. <?php
  795. namespace PhpCsFixer;
  796. use PhpCsFixer\Tokenizer\Token;
  797. use PhpCsFixer\Tokenizer\Tokens;
  798. abstract class AbstractPsrAutoloadingFixer extends AbstractFixer
  799. {
  800. public function isCandidate(Tokens $tokens)
  801. {
  802. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  803. }
  804. public function isRisky()
  805. {
  806. return true;
  807. }
  808. public function getPriority()
  809. {
  810. return -10;
  811. }
  812. public function supports(\SplFileInfo $file)
  813. {
  814. if ($file instanceof StdinFileInfo) {
  815. return false;
  816. }
  817. $filenameParts = explode('.', $file->getBasename(), 2);
  818. if (
  819. (!isset($filenameParts[1]) || 'php' !== $filenameParts[1])
  820. || 0 === preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $filenameParts[0])
  821. ) {
  822. return false;
  823. }
  824. try {
  825. $tokens = Tokens::fromCode(sprintf('<?php class %s {}', $filenameParts[0]));
  826. if ($tokens[3]->isKeyword() || $tokens[3]->isMagicConstant()) {
  827. return false;
  828. }
  829. } catch (\ParseError $e) {
  830. return false;
  831. }
  832. return !preg_match('{[/\\\\](stub|fixture)s?[/\\\\]}i', $file->getRealPath());
  833. }
  834. }
  835. <?php
  836. namespace PhpCsFixer\Cache;
  837. final class Cache implements CacheInterface
  838. {
  839. private $signature;
  840. private $hashes = [];
  841. public function __construct(SignatureInterface $signature)
  842. {
  843. $this->signature = $signature;
  844. }
  845. public function getSignature()
  846. {
  847. return $this->signature;
  848. }
  849. public function has($file)
  850. {
  851. return array_key_exists($file, $this->hashes);
  852. }
  853. public function get($file)
  854. {
  855. if (!$this->has($file)) {
  856. return;
  857. }
  858. return $this->hashes[$file];
  859. }
  860. public function set($file, $hash)
  861. {
  862. if (!is_int($hash)) {
  863. throw new \InvalidArgumentException(sprintf(
  864. 'Value needs to be an integer, got "%s".',
  865. is_object($hash) ? get_class($hash) : gettype($hash)
  866. ));
  867. }
  868. $this->hashes[$file] = $hash;
  869. }
  870. public function clear($file)
  871. {
  872. unset($this->hashes[$file]);
  873. }
  874. public function toJson()
  875. {
  876. $json = json_encode([
  877. 'php' => $this->getSignature()->getPhpVersion(),
  878. 'version' => $this->getSignature()->getFixerVersion(),
  879. 'rules' => $this->getSignature()->getRules(),
  880. 'hashes' => $this->hashes,
  881. ]);
  882. if (false === $json) {
  883. throw new \UnexpectedValueException(sprintf(
  884. 'Can not encode cache signature to JSON, error: "%s". If you have non-UTF8 chars in your signature, like in license for `header_comment`, consider enabling `ext-mbstring` or install `symfony/polyfill-mbstring`.',
  885. json_last_error_msg()
  886. ));
  887. }
  888. return $json;
  889. }
  890. public static function fromJson($json)
  891. {
  892. $data = json_decode($json, true);
  893. if (null === $data && JSON_ERROR_NONE !== json_last_error()) {
  894. throw new \InvalidArgumentException(sprintf(
  895. 'Value needs to be a valid JSON string, got "%s", error: "%s".',
  896. is_object($json) ? get_class($json) : gettype($json),
  897. json_last_error_msg()
  898. ));
  899. }
  900. $requiredKeys = [
  901. 'php',
  902. 'version',
  903. 'rules',
  904. 'hashes',
  905. ];
  906. $missingKeys = array_diff_key(array_flip($requiredKeys), $data);
  907. if (count($missingKeys)) {
  908. throw new \InvalidArgumentException(sprintf(
  909. 'JSON data is missing keys "%s"',
  910. implode('", "', $missingKeys)
  911. ));
  912. }
  913. $signature = new Signature(
  914. $data['php'],
  915. $data['version'],
  916. $data['rules']
  917. );
  918. $cache = new self($signature);
  919. $cache->hashes = $data['hashes'];
  920. return $cache;
  921. }
  922. }
  923. <?php
  924. namespace PhpCsFixer\Cache;
  925. interface CacheInterface
  926. {
  927. public function getSignature();
  928. public function has($file);
  929. public function get($file);
  930. public function set($file, $hash);
  931. public function clear($file);
  932. public function toJson();
  933. }
  934. <?php
  935. namespace PhpCsFixer\Cache;
  936. interface CacheManagerInterface
  937. {
  938. public function needFixing($file, $fileContent);
  939. public function setFile($file, $fileContent);
  940. }
  941. <?php
  942. namespace PhpCsFixer\Cache;
  943. final class Directory implements DirectoryInterface
  944. {
  945. private $directoryName;
  946. public function __construct($directoryName)
  947. {
  948. $this->directoryName = $directoryName;
  949. }
  950. public function getRelativePathTo($file)
  951. {
  952. $file = $this->normalizePath($file);
  953. if (
  954. '' === $this->directoryName
  955. || 0 !== stripos($file, $this->directoryName.DIRECTORY_SEPARATOR)
  956. ) {
  957. return $file;
  958. }
  959. return substr($file, strlen($this->directoryName) + 1);
  960. }
  961. private function normalizePath($path)
  962. {
  963. return str_replace(['\\', '/'], DIRECTORY_SEPARATOR, $path);
  964. }
  965. }
  966. <?php
  967. namespace PhpCsFixer\Cache;
  968. interface DirectoryInterface
  969. {
  970. public function getRelativePathTo($file);
  971. }
  972. <?php
  973. namespace PhpCsFixer\Cache;
  974. final class FileCacheManager implements CacheManagerInterface
  975. {
  976. private $handler;
  977. private $signature;
  978. private $cache;
  979. private $isDryRun;
  980. private $cacheDirectory;
  981. public function __construct(
  982. FileHandlerInterface $handler,
  983. SignatureInterface $signature,
  984. $isDryRun = false,
  985. DirectoryInterface $cacheDirectory = null
  986. ) {
  987. $this->handler = $handler;
  988. $this->signature = $signature;
  989. $this->isDryRun = $isDryRun;
  990. $this->cacheDirectory = $cacheDirectory ?: new Directory('');
  991. $this->readCache();
  992. }
  993. public function __destruct()
  994. {
  995. $this->writeCache();
  996. }
  997. public function needFixing($file, $fileContent)
  998. {
  999. $file = $this->cacheDirectory->getRelativePathTo($file);
  1000. return !$this->cache->has($file) || $this->cache->get($file) !== $this->calcHash($fileContent);
  1001. }
  1002. public function setFile($file, $fileContent)
  1003. {
  1004. $file = $this->cacheDirectory->getRelativePathTo($file);
  1005. $hash = $this->calcHash($fileContent);
  1006. if ($this->isDryRun && $this->cache->has($file) && $this->cache->get($file) !== $hash) {
  1007. $this->cache->clear($file);
  1008. return;
  1009. }
  1010. $this->cache->set($file, $hash);
  1011. }
  1012. private function readCache()
  1013. {
  1014. $cache = $this->handler->read();
  1015. if (!$cache || !$this->signature->equals($cache->getSignature())) {
  1016. $cache = new Cache($this->signature);
  1017. }
  1018. $this->cache = $cache;
  1019. }
  1020. private function writeCache()
  1021. {
  1022. $this->handler->write($this->cache);
  1023. }
  1024. private function calcHash($content)
  1025. {
  1026. return crc32($content);
  1027. }
  1028. }
  1029. <?php
  1030. namespace PhpCsFixer\Cache;
  1031. use Symfony\Component\Filesystem\Exception\IOException;
  1032. final class FileHandler implements FileHandlerInterface
  1033. {
  1034. private $file;
  1035. public function __construct($file)
  1036. {
  1037. $this->file = $file;
  1038. }
  1039. public function getFile()
  1040. {
  1041. return $this->file;
  1042. }
  1043. public function read()
  1044. {
  1045. if (!file_exists($this->file)) {
  1046. return;
  1047. }
  1048. $content = file_get_contents($this->file);
  1049. try {
  1050. $cache = Cache::fromJson($content);
  1051. } catch (\InvalidArgumentException $exception) {
  1052. return;
  1053. }
  1054. return $cache;
  1055. }
  1056. public function write(CacheInterface $cache)
  1057. {
  1058. $content = $cache->toJson();
  1059. if (file_exists($this->file)) {
  1060. if (is_dir($this->file)) {
  1061. throw new IOException(
  1062. sprintf('Cannot write cache file "%s" as the location exists as directory.', realpath($this->file)),
  1063. 0,
  1064. null,
  1065. $this->file
  1066. );
  1067. }
  1068. if (!is_writable($this->file)) {
  1069. throw new IOException(
  1070. sprintf('Cannot write to file "%s" as it is not writable.', realpath($this->file)),
  1071. 0,
  1072. null,
  1073. $this->file
  1074. );
  1075. }
  1076. } else {
  1077. @touch($this->file);
  1078. @chmod($this->file, 0666);
  1079. }
  1080. $bytesWritten = @file_put_contents($this->file, $content, LOCK_EX);
  1081. if (false === $bytesWritten) {
  1082. $error = error_get_last();
  1083. throw new IOException(
  1084. sprintf('Failed to write file "%s", "%s".', $this->file, isset($error['message']) ? $error['message'] : 'no reason available'),
  1085. 0,
  1086. null,
  1087. $this->file
  1088. );
  1089. }
  1090. }
  1091. }
  1092. <?php
  1093. namespace PhpCsFixer\Cache;
  1094. interface FileHandlerInterface
  1095. {
  1096. public function getFile();
  1097. public function read();
  1098. public function write(CacheInterface $cache);
  1099. }
  1100. <?php
  1101. namespace PhpCsFixer\Cache;
  1102. final class NullCacheManager implements CacheManagerInterface
  1103. {
  1104. public function needFixing($file, $fileContent)
  1105. {
  1106. return true;
  1107. }
  1108. public function setFile($file, $fileContent)
  1109. {
  1110. }
  1111. }
  1112. <?php
  1113. namespace PhpCsFixer\Cache;
  1114. final class Signature implements SignatureInterface
  1115. {
  1116. private $phpVersion;
  1117. private $fixerVersion;
  1118. private $rules;
  1119. public function __construct($phpVersion, $fixerVersion, array $rules)
  1120. {
  1121. $this->phpVersion = $phpVersion;
  1122. $this->fixerVersion = $fixerVersion;
  1123. $this->rules = self::utf8Encode($rules);
  1124. }
  1125. public function getPhpVersion()
  1126. {
  1127. return $this->phpVersion;
  1128. }
  1129. public function getFixerVersion()
  1130. {
  1131. return $this->fixerVersion;
  1132. }
  1133. public function getRules()
  1134. {
  1135. return $this->rules;
  1136. }
  1137. public function equals(SignatureInterface $signature)
  1138. {
  1139. return $this->phpVersion === $signature->getPhpVersion()
  1140. && $this->fixerVersion === $signature->getFixerVersion()
  1141. && $this->rules === $signature->getRules();
  1142. }
  1143. private static function utf8Encode(array $data)
  1144. {
  1145. if (!function_exists('mb_detect_encoding')) {
  1146. return $data;
  1147. }
  1148. array_walk_recursive($data, static function (&$item) {
  1149. if (is_string($item) && !mb_detect_encoding($item, 'utf-8', true)) {
  1150. $item = utf8_encode($item);
  1151. }
  1152. });
  1153. return $data;
  1154. }
  1155. }
  1156. <?php
  1157. namespace PhpCsFixer\Cache;
  1158. interface SignatureInterface
  1159. {
  1160. public function getPhpVersion();
  1161. public function getFixerVersion();
  1162. public function getRules();
  1163. public function equals(self $signature);
  1164. }
  1165. <?php
  1166. namespace PhpCsFixer;
  1167. use PhpCsFixer\Fixer\FixerInterface;
  1168. class Config implements ConfigInterface
  1169. {
  1170. private $cacheFile = '.php_cs.cache';
  1171. private $customFixers = [];
  1172. private $finder;
  1173. private $format = 'txt';
  1174. private $hideProgress = false;
  1175. private $indent = ' ';
  1176. private $isRiskyAllowed = false;
  1177. private $lineEnding = "\n";
  1178. private $name;
  1179. private $phpExecutable;
  1180. private $rules = ['@PSR2' => true];
  1181. private $usingCache = true;
  1182. public function __construct($name = 'default')
  1183. {
  1184. $this->name = $name;
  1185. }
  1186. public static function create()
  1187. {
  1188. return new static();
  1189. }
  1190. public function getCacheFile()
  1191. {
  1192. return $this->cacheFile;
  1193. }
  1194. public function getCustomFixers()
  1195. {
  1196. return $this->customFixers;
  1197. }
  1198. public function getFinder()
  1199. {
  1200. if (null === $this->finder) {
  1201. $this->finder = new Finder();
  1202. }
  1203. return $this->finder;
  1204. }
  1205. public function getFormat()
  1206. {
  1207. return $this->format;
  1208. }
  1209. public function getHideProgress()
  1210. {
  1211. return $this->hideProgress;
  1212. }
  1213. public function getIndent()
  1214. {
  1215. return $this->indent;
  1216. }
  1217. public function getLineEnding()
  1218. {
  1219. return $this->lineEnding;
  1220. }
  1221. public function getName()
  1222. {
  1223. return $this->name;
  1224. }
  1225. public function getPhpExecutable()
  1226. {
  1227. return $this->phpExecutable;
  1228. }
  1229. public function getRiskyAllowed()
  1230. {
  1231. return $this->isRiskyAllowed;
  1232. }
  1233. public function getRules()
  1234. {
  1235. return $this->rules;
  1236. }
  1237. public function getUsingCache()
  1238. {
  1239. return $this->usingCache;
  1240. }
  1241. public function registerCustomFixers($fixers)
  1242. {
  1243. if (false === is_array($fixers) && false === $fixers instanceof \Traversable) {
  1244. throw new \InvalidArgumentException(sprintf(
  1245. 'Argument must be an array or a Traversable, got "%s".',
  1246. is_object($fixers) ? get_class($fixers) : gettype($fixers)
  1247. ));
  1248. }
  1249. foreach ($fixers as $fixer) {
  1250. $this->addCustomFixer($fixer);
  1251. }
  1252. return $this;
  1253. }
  1254. public function setCacheFile($cacheFile)
  1255. {
  1256. $this->cacheFile = $cacheFile;
  1257. return $this;
  1258. }
  1259. public function setFinder($finder)
  1260. {
  1261. if (false === is_array($finder) && false === $finder instanceof \Traversable) {
  1262. throw new \InvalidArgumentException(sprintf(
  1263. 'Argument must be an array or a Traversable, got "%s".',
  1264. is_object($finder) ? get_class($finder) : gettype($finder)
  1265. ));
  1266. }
  1267. $this->finder = $finder;
  1268. return $this;
  1269. }
  1270. public function setFormat($format)
  1271. {
  1272. $this->format = $format;
  1273. return $this;
  1274. }
  1275. public function setHideProgress($hideProgress)
  1276. {
  1277. $this->hideProgress = $hideProgress;
  1278. return $this;
  1279. }
  1280. public function setIndent($indent)
  1281. {
  1282. $this->indent = $indent;
  1283. return $this;
  1284. }
  1285. public function setLineEnding($lineEnding)
  1286. {
  1287. $this->lineEnding = $lineEnding;
  1288. return $this;
  1289. }
  1290. public function setPhpExecutable($phpExecutable)
  1291. {
  1292. $this->phpExecutable = $phpExecutable;
  1293. return $this;
  1294. }
  1295. public function setRiskyAllowed($isRiskyAllowed)
  1296. {
  1297. $this->isRiskyAllowed = $isRiskyAllowed;
  1298. return $this;
  1299. }
  1300. public function setRules(array $rules)
  1301. {
  1302. $this->rules = $rules;
  1303. return $this;
  1304. }
  1305. public function setUsingCache($usingCache)
  1306. {
  1307. $this->usingCache = $usingCache;
  1308. return $this;
  1309. }
  1310. private function addCustomFixer(FixerInterface $fixer)
  1311. {
  1312. $this->customFixers[] = $fixer;
  1313. }
  1314. }
  1315. <?php
  1316. namespace PhpCsFixer;
  1317. use PhpCsFixer\Fixer\FixerInterface;
  1318. interface ConfigInterface
  1319. {
  1320. public function getCacheFile();
  1321. public function getCustomFixers();
  1322. public function getFinder();
  1323. public function getFormat();
  1324. public function getHideProgress();
  1325. public function getIndent();
  1326. public function getLineEnding();
  1327. public function getName();
  1328. public function getPhpExecutable();
  1329. public function getRiskyAllowed();
  1330. public function getRules();
  1331. public function getUsingCache();
  1332. public function registerCustomFixers($fixers);
  1333. public function setCacheFile($cacheFile);
  1334. public function setFinder($finder);
  1335. public function setFormat($format);
  1336. public function setHideProgress($hideProgress);
  1337. public function setIndent($indent);
  1338. public function setLineEnding($lineEnding);
  1339. public function setPhpExecutable($phpExecutable);
  1340. public function setRiskyAllowed($isRiskyAllowed);
  1341. public function setRules(array $rules);
  1342. public function setUsingCache($usingCache);
  1343. }
  1344. <?php
  1345. namespace PhpCsFixer\ConfigurationException;
  1346. use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator;
  1347. class InvalidConfigurationException extends \InvalidArgumentException
  1348. {
  1349. public function __construct($message, $code = null, \Exception $previous = null)
  1350. {
  1351. parent::__construct(
  1352. $message,
  1353. null === $code ? FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_CONFIG : $code,
  1354. $previous
  1355. );
  1356. }
  1357. }
  1358. <?php
  1359. namespace PhpCsFixer\ConfigurationException;
  1360. use PhpCsFixer\Console\Command\FixCommandExitStatusCalculator;
  1361. class InvalidFixerConfigurationException extends InvalidConfigurationException
  1362. {
  1363. private $fixerName;
  1364. public function __construct($fixerName, $message, \Exception $previous = null)
  1365. {
  1366. parent::__construct(
  1367. sprintf('[%s] %s', $fixerName, $message),
  1368. FixCommandExitStatusCalculator::EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG,
  1369. $previous
  1370. );
  1371. $this->fixerName = $fixerName;
  1372. }
  1373. public function getFixerName()
  1374. {
  1375. return $this->fixerName;
  1376. }
  1377. }
  1378. <?php
  1379. namespace PhpCsFixer\ConfigurationException;
  1380. final class InvalidForEnvFixerConfigurationException extends InvalidFixerConfigurationException
  1381. {
  1382. }
  1383. <?php
  1384. namespace PhpCsFixer\ConfigurationException;
  1385. final class RequiredFixerConfigurationException extends InvalidFixerConfigurationException
  1386. {
  1387. }
  1388. <?php
  1389. namespace PhpCsFixer\Console;
  1390. use PhpCsFixer\Console\Command\DescribeCommand;
  1391. use PhpCsFixer\Console\Command\FixCommand;
  1392. use PhpCsFixer\Console\Command\HelpCommand;
  1393. use PhpCsFixer\Console\Command\ReadmeCommand;
  1394. use PhpCsFixer\Console\Command\SelfUpdateCommand;
  1395. use PhpCsFixer\Console\SelfUpdate\GithubClient;
  1396. use PhpCsFixer\Console\SelfUpdate\NewVersionChecker;
  1397. use PhpCsFixer\PharChecker;
  1398. use PhpCsFixer\ToolInfo;
  1399. use Symfony\Component\Console\Application as BaseApplication;
  1400. use Symfony\Component\Console\Command\ListCommand;
  1401. use Symfony\Component\Console\Input\InputInterface;
  1402. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  1403. use Symfony\Component\Console\Output\OutputInterface;
  1404. final class Application extends BaseApplication
  1405. {
  1406. const VERSION = '2.10.0';
  1407. const VERSION_CODENAME = 'Bowling Bear';
  1408. private $toolInfo;
  1409. public function __construct()
  1410. {
  1411. error_reporting(-1);
  1412. parent::__construct('PHP CS Fixer', self::VERSION);
  1413. $this->toolInfo = new ToolInfo();
  1414. $this->add(new DescribeCommand());
  1415. $this->add(new FixCommand($this->toolInfo));
  1416. $this->add(new ReadmeCommand());
  1417. $this->add(new SelfUpdateCommand(
  1418. new NewVersionChecker(new GithubClient()),
  1419. $this->toolInfo,
  1420. new PharChecker()
  1421. ));
  1422. }
  1423. public function doRun(InputInterface $input, OutputInterface $output)
  1424. {
  1425. $stdErr = $output instanceof ConsoleOutputInterface
  1426. ? $output->getErrorOutput()
  1427. : ($input->hasParameterOption('--format', true) && 'txt' !== $input->getParameterOption('--format', null, true) ? null : $output)
  1428. ;
  1429. if (null !== $stdErr) {
  1430. $warningsDetector = new WarningsDetector($this->toolInfo);
  1431. $warningsDetector->detectOldVendor();
  1432. $warningsDetector->detectOldMajor();
  1433. if (FixCommand::COMMAND_NAME === $this->getCommandName($input)) {
  1434. $warningsDetector->detectXdebug();
  1435. }
  1436. foreach ($warningsDetector->getWarnings() as $warning) {
  1437. $stdErr->writeln(sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', $warning));
  1438. }
  1439. }
  1440. return parent::doRun($input, $output);
  1441. }
  1442. public function getLongVersion()
  1443. {
  1444. $version = parent::getLongVersion();
  1445. if (self::VERSION_CODENAME) {
  1446. $version .= ' <info>'.self::VERSION_CODENAME.'</info>';
  1447. }
  1448. $version .= ' by <comment>Fabien Potencier</comment> and <comment>Dariusz Ruminski</comment>';
  1449. $commit = '513a3765b56dd029175f9f32995566657ee89dda';
  1450. if ('@'.'git-commit@' !== $commit) {
  1451. $version .= ' ('.substr($commit, 0, 7).')';
  1452. }
  1453. return $version;
  1454. }
  1455. protected function getDefaultCommands()
  1456. {
  1457. return [new HelpCommand(), new ListCommand()];
  1458. }
  1459. }
  1460. <?php
  1461. namespace PhpCsFixer\Console\Command;
  1462. use PhpCsFixer\Diff\GeckoPackages\DiffOutputBuilder\UnifiedDiffOutputBuilder;
  1463. use PhpCsFixer\Diff\v2_0\Differ;
  1464. use PhpCsFixer\Differ\DiffConsoleFormatter;
  1465. use PhpCsFixer\Fixer\ConfigurableFixerInterface;
  1466. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  1467. use PhpCsFixer\Fixer\DefinedFixerInterface;
  1468. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  1469. use PhpCsFixer\Fixer\FixerInterface;
  1470. use PhpCsFixer\FixerDefinition\CodeSampleInterface;
  1471. use PhpCsFixer\FixerDefinition\FileSpecificCodeSampleInterface;
  1472. use PhpCsFixer\FixerDefinition\FixerDefinition;
  1473. use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
  1474. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSampleInterface;
  1475. use PhpCsFixer\FixerFactory;
  1476. use PhpCsFixer\RuleSet;
  1477. use PhpCsFixer\StdinFileInfo;
  1478. use PhpCsFixer\Tokenizer\Tokens;
  1479. use PhpCsFixer\Utils;
  1480. use PhpCsFixer\WordMatcher;
  1481. use Symfony\Component\Console\Command\Command;
  1482. use Symfony\Component\Console\Formatter\OutputFormatter;
  1483. use Symfony\Component\Console\Input\InputArgument;
  1484. use Symfony\Component\Console\Input\InputInterface;
  1485. use Symfony\Component\Console\Output\OutputInterface;
  1486. final class DescribeCommand extends Command
  1487. {
  1488. const COMMAND_NAME = 'describe';
  1489. private $setNames;
  1490. private $fixerFactory;
  1491. private $fixers;
  1492. public function __construct(FixerFactory $fixerFactory = null)
  1493. {
  1494. parent::__construct();
  1495. if (null === $fixerFactory) {
  1496. $fixerFactory = new FixerFactory();
  1497. $fixerFactory->registerBuiltInFixers();
  1498. }
  1499. $this->fixerFactory = $fixerFactory;
  1500. }
  1501. protected function configure()
  1502. {
  1503. $this
  1504. ->setName(self::COMMAND_NAME)
  1505. ->setDefinition(
  1506. [
  1507. new InputArgument('name', InputArgument::REQUIRED, 'Name of rule / set.'),
  1508. ]
  1509. )
  1510. ->setDescription('Describe rule / ruleset.')
  1511. ;
  1512. }
  1513. protected function execute(InputInterface $input, OutputInterface $output)
  1514. {
  1515. $name = $input->getArgument('name');
  1516. try {
  1517. if ('@' === $name[0]) {
  1518. $this->describeSet($output, $name);
  1519. return;
  1520. }
  1521. $this->describeRule($output, $name);
  1522. } catch (DescribeNameNotFoundException $e) {
  1523. $matcher = new WordMatcher(
  1524. 'set' === $e->getType() ? $this->getSetNames() : array_keys($this->getFixers())
  1525. );
  1526. $alternative = $matcher->match($name);
  1527. $this->describeList($output, $e->getType());
  1528. throw new \InvalidArgumentException(sprintf(
  1529. '%s "%s" not found.%s',
  1530. ucfirst($e->getType()),
  1531. $name,
  1532. null === $alternative ? '' : ' Did you mean "'.$alternative.'"?'
  1533. ));
  1534. }
  1535. }
  1536. private function describeRule(OutputInterface $output, $name)
  1537. {
  1538. $fixers = $this->getFixers();
  1539. if (!isset($fixers[$name])) {
  1540. throw new DescribeNameNotFoundException($name, 'rule');
  1541. }
  1542. $fixer = $fixers[$name];
  1543. if ($fixer instanceof DefinedFixerInterface) {
  1544. $definition = $fixer->getDefinition();
  1545. } else {
  1546. $definition = new FixerDefinition('Description is not available.', []);
  1547. }
  1548. $description = $definition->getSummary();
  1549. if ($fixer instanceof DeprecatedFixerInterface) {
  1550. $successors = $fixer->getSuccessorsNames();
  1551. $message = [] === $successors
  1552. ? 'will be removed on next major version'
  1553. : sprintf('use %s instead', Utils::naturalLanguageJoinWithBackticks($successors));
  1554. $message = preg_replace('/(`.+?`)/', '<info>$1</info>', $message);
  1555. $description .= sprintf(' <error>DEPRECATED</error>: %s.', $message);
  1556. }
  1557. $output->writeln(sprintf('<info>Description of</info> %s <info>rule</info>.', $name));
  1558. $output->writeln($description);
  1559. if ($definition->getDescription()) {
  1560. $output->writeln($definition->getDescription());
  1561. }
  1562. $output->writeln('');
  1563. if ($fixer->isRisky()) {
  1564. $output->writeln('<error>Fixer applying this rule is risky.</error>');
  1565. if ($definition->getRiskyDescription()) {
  1566. $output->writeln($definition->getRiskyDescription());
  1567. }
  1568. $output->writeln('');
  1569. }
  1570. if ($fixer instanceof ConfigurationDefinitionFixerInterface) {
  1571. $configurationDefinition = $fixer->getConfigurationDefinition();
  1572. $options = $configurationDefinition->getOptions();
  1573. $output->writeln(sprintf('Fixer is configurable using following option%s:', 1 === count($options) ? '' : 's'));
  1574. foreach ($options as $option) {
  1575. $line = '* <info>'.OutputFormatter::escape($option->getName()).'</info>';
  1576. $allowed = HelpCommand::getDisplayableAllowedValues($option);
  1577. if (null !== $allowed) {
  1578. foreach ($allowed as &$value) {
  1579. $value = HelpCommand::toString($value);
  1580. }
  1581. } else {
  1582. $allowed = $option->getAllowedTypes();
  1583. }
  1584. if (null !== $allowed) {
  1585. $line .= ' (<comment>'.implode('</comment>, <comment>', $allowed).'</comment>)';
  1586. }
  1587. $description = preg_replace('/(`.+?`)/', '<info>$1</info>', OutputFormatter::escape($option->getDescription()));
  1588. $line .= ': '.lcfirst(preg_replace('/\.$/', '', $description)).'; ';
  1589. if ($option->hasDefault()) {
  1590. $line .= sprintf(
  1591. 'defaults to <comment>%s</comment>',
  1592. HelpCommand::toString($option->getDefault())
  1593. );
  1594. } else {
  1595. $line .= '<comment>required</comment>';
  1596. }
  1597. $output->writeln($line);
  1598. }
  1599. $output->writeln('');
  1600. } elseif ($fixer instanceof ConfigurableFixerInterface) {
  1601. $output->writeln('<comment>Fixer is configurable.</comment>');
  1602. if ($definition->getConfigurationDescription()) {
  1603. $output->writeln($definition->getConfigurationDescription());
  1604. }
  1605. if ($definition->getDefaultConfiguration()) {
  1606. $output->writeln(sprintf('Default configuration: <comment>%s</comment>.', HelpCommand::toString($definition->getDefaultConfiguration())));
  1607. }
  1608. $output->writeln('');
  1609. }
  1610. $codeSamples = array_filter($definition->getCodeSamples(), static function (CodeSampleInterface $codeSample) {
  1611. if ($codeSample instanceof VersionSpecificCodeSampleInterface) {
  1612. return $codeSample->isSuitableFor(PHP_VERSION_ID);
  1613. }
  1614. return true;
  1615. });
  1616. if (!count($codeSamples)) {
  1617. $output->writeln([
  1618. 'Fixing examples can not be demonstrated on the current PHP version.',
  1619. '',
  1620. ]);
  1621. } else {
  1622. $output->writeln('Fixing examples:');
  1623. $differ = new Differ(new UnifiedDiffOutputBuilder([
  1624. 'fromFile' => 'Original',
  1625. 'toFile' => 'New',
  1626. ]));
  1627. $diffFormatter = new DiffConsoleFormatter($output->isDecorated(), sprintf(
  1628. '<comment> ---------- begin diff ----------</comment>%s%%s%s<comment> ----------- end diff -----------</comment>',
  1629. PHP_EOL,
  1630. PHP_EOL
  1631. ));
  1632. foreach ($codeSamples as $index => $codeSample) {
  1633. $old = $codeSample->getCode();
  1634. $tokens = Tokens::fromCode($old);
  1635. if ($fixer instanceof ConfigurableFixerInterface) {
  1636. $configuration = $codeSample->getConfiguration();
  1637. $fixer->configure(null === $configuration ? [] : $configuration);
  1638. }
  1639. $file = $codeSample instanceof FileSpecificCodeSampleInterface
  1640. ? $codeSample->getSplFileInfo()
  1641. : new StdinFileInfo();
  1642. $fixer->fix($file, $tokens);
  1643. $diff = $differ->diff($old, $tokens->generateCode());
  1644. if ($fixer instanceof ConfigurableFixerInterface) {
  1645. if (null === $configuration) {
  1646. $output->writeln(sprintf(' * Example #%d. Fixing with the <comment>default</comment> configuration.', $index + 1));
  1647. } else {
  1648. $output->writeln(sprintf(' * Example #%d. Fixing with configuration: <comment>%s</comment>.', $index + 1, HelpCommand::toString($codeSample->getConfiguration())));
  1649. }
  1650. } else {
  1651. $output->writeln(sprintf(' * Example #%d.', $index + 1));
  1652. }
  1653. $output->writeln($diffFormatter->format($diff, ' %s'));
  1654. $output->writeln('');
  1655. }
  1656. }
  1657. }
  1658. private function describeSet(OutputInterface $output, $name)
  1659. {
  1660. if (!in_array($name, $this->getSetNames(), true)) {
  1661. throw new DescribeNameNotFoundException($name, 'set');
  1662. }
  1663. $ruleSet = new RuleSet([$name => true]);
  1664. $rules = $ruleSet->getRules();
  1665. ksort($rules);
  1666. $fixers = $this->getFixers();
  1667. $output->writeln(sprintf('<info>Description of</info> %s <info>set.</info>', $name));
  1668. $output->writeln('');
  1669. $help = '';
  1670. foreach ($rules as $rule => $config) {
  1671. $definition = $fixers[$rule]->getDefinition();
  1672. $help .= sprintf(
  1673. " * <info>%s</info>%s\n | %s\n%s\n",
  1674. $rule,
  1675. $fixers[$rule]->isRisky() ? ' <error>risky</error>' : '',
  1676. $definition->getSummary(),
  1677. true !== $config ? sprintf(" <comment>| Configuration: %s</comment>\n", HelpCommand::toString($config)) : ''
  1678. );
  1679. }
  1680. $output->write($help);
  1681. }
  1682. private function getFixers()
  1683. {
  1684. if (null !== $this->fixers) {
  1685. return $this->fixers;
  1686. }
  1687. $fixers = [];
  1688. foreach ($this->fixerFactory->getFixers() as $fixer) {
  1689. $fixers[$fixer->getName()] = $fixer;
  1690. }
  1691. $this->fixers = $fixers;
  1692. ksort($this->fixers);
  1693. return $this->fixers;
  1694. }
  1695. private function getSetNames()
  1696. {
  1697. if (null !== $this->setNames) {
  1698. return $this->setNames;
  1699. }
  1700. $set = new RuleSet();
  1701. $this->setNames = $set->getSetDefinitionNames();
  1702. sort($this->setNames);
  1703. return $this->setNames;
  1704. }
  1705. private function describeList(OutputInterface $output, $type)
  1706. {
  1707. if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
  1708. $describe = [
  1709. 'set' => $this->getSetNames(),
  1710. 'rules' => $this->getFixers(),
  1711. ];
  1712. } elseif ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERBOSE) {
  1713. $describe = 'set' === $type ? ['set' => $this->getSetNames()] : ['rules' => $this->getFixers()];
  1714. } else {
  1715. return;
  1716. }
  1717. foreach ($describe as $list => $items) {
  1718. $output->writeln(sprintf('<comment>Defined %s:</comment>', $list));
  1719. foreach ($items as $name => $item) {
  1720. $output->writeln(sprintf('* <info>%s</info>', is_string($name) ? $name : $item));
  1721. }
  1722. }
  1723. }
  1724. }
  1725. <?php
  1726. namespace PhpCsFixer\Console\Command;
  1727. final class DescribeNameNotFoundException extends \InvalidArgumentException
  1728. {
  1729. private $name;
  1730. private $type;
  1731. public function __construct($name, $type)
  1732. {
  1733. $this->name = $name;
  1734. $this->type = $type;
  1735. }
  1736. public function getName()
  1737. {
  1738. return $this->name;
  1739. }
  1740. public function getType()
  1741. {
  1742. return $this->type;
  1743. }
  1744. }
  1745. <?php
  1746. namespace PhpCsFixer\Console\Command;
  1747. use PhpCsFixer\Config;
  1748. use PhpCsFixer\ConfigInterface;
  1749. use PhpCsFixer\Console\ConfigurationResolver;
  1750. use PhpCsFixer\Console\Output\ErrorOutput;
  1751. use PhpCsFixer\Console\Output\NullOutput;
  1752. use PhpCsFixer\Console\Output\ProcessOutput;
  1753. use PhpCsFixer\Error\ErrorsManager;
  1754. use PhpCsFixer\Report\ReportSummary;
  1755. use PhpCsFixer\Runner\Runner;
  1756. use PhpCsFixer\ToolInfoInterface;
  1757. use Symfony\Component\Console\Command\Command;
  1758. use Symfony\Component\Console\Input\InputArgument;
  1759. use Symfony\Component\Console\Input\InputInterface;
  1760. use Symfony\Component\Console\Input\InputOption;
  1761. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  1762. use Symfony\Component\Console\Output\OutputInterface;
  1763. use Symfony\Component\Console\Terminal;
  1764. use Symfony\Component\EventDispatcher\EventDispatcher;
  1765. use Symfony\Component\Stopwatch\Stopwatch;
  1766. final class FixCommand extends Command
  1767. {
  1768. const COMMAND_NAME = 'fix';
  1769. private $eventDispatcher;
  1770. private $errorsManager;
  1771. private $stopwatch;
  1772. private $defaultConfig;
  1773. private $toolInfo;
  1774. public function __construct(ToolInfoInterface $toolInfo)
  1775. {
  1776. parent::__construct();
  1777. $this->defaultConfig = new Config();
  1778. $this->errorsManager = new ErrorsManager();
  1779. $this->eventDispatcher = new EventDispatcher();
  1780. $this->stopwatch = new Stopwatch();
  1781. $this->toolInfo = $toolInfo;
  1782. }
  1783. public function getHelp()
  1784. {
  1785. return HelpCommand::getHelpCopy();
  1786. }
  1787. protected function configure()
  1788. {
  1789. $this
  1790. ->setName(self::COMMAND_NAME)
  1791. ->setDefinition(
  1792. [
  1793. new InputArgument('path', InputArgument::IS_ARRAY, 'The path.'),
  1794. new InputOption('path-mode', '', InputOption::VALUE_REQUIRED, 'Specify path mode (can be override or intersection).', 'override'),
  1795. new InputOption('allow-risky', '', InputOption::VALUE_REQUIRED, 'Are risky fixers allowed (can be yes or no).'),
  1796. new InputOption('config', '', InputOption::VALUE_REQUIRED, 'The path to a .php_cs file.'),
  1797. new InputOption('dry-run', '', InputOption::VALUE_NONE, 'Only shows which files would have been modified.'),
  1798. new InputOption('rules', '', InputOption::VALUE_REQUIRED, 'The rules.'),
  1799. new InputOption('using-cache', '', InputOption::VALUE_REQUIRED, 'Does cache should be used (can be yes or no).'),
  1800. new InputOption('cache-file', '', InputOption::VALUE_REQUIRED, 'The path to the cache file.'),
  1801. new InputOption('diff', '', InputOption::VALUE_NONE, 'Also produce diff for each file.'),
  1802. new InputOption('diff-format', '', InputOption::VALUE_REQUIRED, 'Specify diff format.'),
  1803. new InputOption('format', '', InputOption::VALUE_REQUIRED, 'To output results in other formats.'),
  1804. new InputOption('stop-on-violation', '', InputOption::VALUE_NONE, 'Stop execution on first violation.'),
  1805. new InputOption('show-progress', '', InputOption::VALUE_REQUIRED, 'Type of progress indicator (none, run-in, estimating, estimating-max or dots).'),
  1806. ]
  1807. )
  1808. ->setDescription('Fixes a directory or a file.')
  1809. ;
  1810. }
  1811. protected function execute(InputInterface $input, OutputInterface $output)
  1812. {
  1813. $verbosity = $output->getVerbosity();
  1814. $passedConfig = $input->getOption('config');
  1815. $passedRules = $input->getOption('rules');
  1816. $resolver = new ConfigurationResolver(
  1817. $this->defaultConfig,
  1818. [
  1819. 'allow-risky' => $input->getOption('allow-risky'),
  1820. 'config' => $passedConfig,
  1821. 'dry-run' => $input->getOption('dry-run'),
  1822. 'rules' => $passedRules,
  1823. 'path' => $input->getArgument('path'),
  1824. 'path-mode' => $input->getOption('path-mode'),
  1825. 'using-cache' => $input->getOption('using-cache'),
  1826. 'cache-file' => $input->getOption('cache-file'),
  1827. 'format' => $input->getOption('format'),
  1828. 'diff' => $input->getOption('diff'),
  1829. 'diff-format' => $input->getOption('diff-format'),
  1830. 'stop-on-violation' => $input->getOption('stop-on-violation'),
  1831. 'verbosity' => $verbosity,
  1832. 'show-progress' => $input->getOption('show-progress'),
  1833. ],
  1834. getcwd(),
  1835. $this->toolInfo
  1836. );
  1837. $reporter = $resolver->getReporter();
  1838. $stdErr = $output instanceof ConsoleOutputInterface
  1839. ? $output->getErrorOutput()
  1840. : ('txt' === $reporter->getFormat() ? $output : null)
  1841. ;
  1842. if (null !== $stdErr) {
  1843. if (null !== $passedConfig && null !== $passedRules) {
  1844. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  1845. throw new \RuntimeException('Passing both `config` and `rules` options is not possible. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
  1846. }
  1847. $stdErr->writeln([
  1848. sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'When passing both "--config" and "--rules" the rules within the configuration file are not used.'),
  1849. sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'Passing both options is deprecated; version v3.0 PHP-CS-Fixer will exit with a configuration error code.'),
  1850. ]);
  1851. }
  1852. $configFile = $resolver->getConfigFile();
  1853. $stdErr->writeln(sprintf('Loaded config <comment>%s</comment>%s.', $resolver->getConfig()->getName(), null === $configFile ? '' : ' from "'.$configFile.'"'));
  1854. if ($resolver->getUsingCache()) {
  1855. $cacheFile = $resolver->getCacheFile();
  1856. if (is_file($cacheFile)) {
  1857. $stdErr->writeln(sprintf('Using cache file "%s".', $cacheFile));
  1858. }
  1859. }
  1860. }
  1861. $progressType = $resolver->getProgress();
  1862. $finder = $resolver->getFinder();
  1863. if (null !== $stdErr && $resolver->configFinderIsOverridden()) {
  1864. $stdErr->writeln(
  1865. sprintf($stdErr->isDecorated() ? '<bg=yellow;fg=black;>%s</>' : '%s', 'Paths from configuration file have been overridden by paths provided as command arguments.')
  1866. );
  1867. }
  1868. if ('none' === $progressType || null === $stdErr) {
  1869. $progressOutput = new NullOutput();
  1870. } elseif ('run-in' === $progressType) {
  1871. $progressOutput = new ProcessOutput($stdErr, $this->eventDispatcher, null, null);
  1872. } else {
  1873. $finder = new \ArrayIterator(iterator_to_array($finder));
  1874. $progressOutput = new ProcessOutput(
  1875. $stdErr,
  1876. $this->eventDispatcher,
  1877. 'estimating' !== $progressType ? (new Terminal())->getWidth() : null,
  1878. count($finder)
  1879. );
  1880. }
  1881. $runner = new Runner(
  1882. $finder,
  1883. $resolver->getFixers(),
  1884. $resolver->getDiffer(),
  1885. 'none' !== $progressType ? $this->eventDispatcher : null,
  1886. $this->errorsManager,
  1887. $resolver->getLinter(),
  1888. $resolver->isDryRun(),
  1889. $resolver->getCacheManager(),
  1890. $resolver->getDirectory(),
  1891. $resolver->shouldStopOnViolation()
  1892. );
  1893. $this->stopwatch->start('fixFiles');
  1894. $changed = $runner->fix();
  1895. $this->stopwatch->stop('fixFiles');
  1896. $progressOutput->printLegend();
  1897. $fixEvent = $this->stopwatch->getEvent('fixFiles');
  1898. $reportSummary = new ReportSummary(
  1899. $changed,
  1900. $fixEvent->getDuration(),
  1901. $fixEvent->getMemory(),
  1902. OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity(),
  1903. $resolver->isDryRun(),
  1904. $output->isDecorated()
  1905. );
  1906. $output->isDecorated()
  1907. ? $output->write($reporter->generate($reportSummary))
  1908. : $output->write($reporter->generate($reportSummary), false, OutputInterface::OUTPUT_RAW)
  1909. ;
  1910. $invalidErrors = $this->errorsManager->getInvalidErrors();
  1911. $exceptionErrors = $this->errorsManager->getExceptionErrors();
  1912. $lintErrors = $this->errorsManager->getLintErrors();
  1913. if (null !== $stdErr) {
  1914. $errorOutput = new ErrorOutput($stdErr);
  1915. if (count($invalidErrors) > 0) {
  1916. $errorOutput->listErrors('linting before fixing', $invalidErrors);
  1917. }
  1918. if (count($exceptionErrors) > 0) {
  1919. $errorOutput->listErrors('fixing', $exceptionErrors);
  1920. }
  1921. if (count($lintErrors) > 0) {
  1922. $errorOutput->listErrors('linting after fixing', $lintErrors);
  1923. }
  1924. }
  1925. $exitStatusCalculator = new FixCommandExitStatusCalculator();
  1926. return $exitStatusCalculator->calculate(
  1927. $resolver->isDryRun(),
  1928. count($changed) > 0,
  1929. count($invalidErrors) > 0,
  1930. count($exceptionErrors) > 0
  1931. );
  1932. }
  1933. }
  1934. <?php
  1935. namespace PhpCsFixer\Console\Command;
  1936. final class FixCommandExitStatusCalculator
  1937. {
  1938. const EXIT_STATUS_FLAG_HAS_INVALID_FILES = 4;
  1939. const EXIT_STATUS_FLAG_HAS_CHANGED_FILES = 8;
  1940. const EXIT_STATUS_FLAG_HAS_INVALID_CONFIG = 16;
  1941. const EXIT_STATUS_FLAG_HAS_INVALID_FIXER_CONFIG = 32;
  1942. const EXIT_STATUS_FLAG_EXCEPTION_IN_APP = 64;
  1943. public function calculate($isDryRun, $hasChangedFiles, $hasInvalidErrors, $hasExceptionErrors)
  1944. {
  1945. $exitStatus = 0;
  1946. if ($isDryRun) {
  1947. if ($hasChangedFiles) {
  1948. $exitStatus |= self::EXIT_STATUS_FLAG_HAS_CHANGED_FILES;
  1949. }
  1950. if ($hasInvalidErrors) {
  1951. $exitStatus |= self::EXIT_STATUS_FLAG_HAS_INVALID_FILES;
  1952. }
  1953. }
  1954. if ($hasExceptionErrors) {
  1955. $exitStatus |= self::EXIT_STATUS_FLAG_EXCEPTION_IN_APP;
  1956. }
  1957. return $exitStatus;
  1958. }
  1959. }
  1960. <?php
  1961. namespace PhpCsFixer\Console\Command;
  1962. use PhpCsFixer\Console\Application;
  1963. use PhpCsFixer\Fixer\ConfigurableFixerInterface;
  1964. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  1965. use PhpCsFixer\Fixer\DefinedFixerInterface;
  1966. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  1967. use PhpCsFixer\Fixer\FixerInterface;
  1968. use PhpCsFixer\FixerConfiguration\FixerOptionInterface;
  1969. use PhpCsFixer\FixerFactory;
  1970. use PhpCsFixer\RuleSet;
  1971. use PhpCsFixer\Utils;
  1972. use Symfony\Component\Console\Command\HelpCommand as BaseHelpCommand;
  1973. use Symfony\Component\Console\Formatter\OutputFormatter;
  1974. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  1975. use Symfony\Component\Console\Input\InputInterface;
  1976. use Symfony\Component\Console\Output\OutputInterface;
  1977. final class HelpCommand extends BaseHelpCommand
  1978. {
  1979. const COMMAND_NAME = 'help';
  1980. public static function getHelpCopy()
  1981. {
  1982. $template =
  1983. <<<'EOF'
  1984. The <info>%command.name%</info> command tries to fix as much coding standards
  1985. problems as possible on a given file or files in a given directory and its subdirectories:
  1986. <info>$ php %command.full_name% /path/to/dir</info>
  1987. <info>$ php %command.full_name% /path/to/file</info>
  1988. By default <comment>--path-mode</comment> is set to ``override``, which means, that if you specify the path to a file or a directory via
  1989. command arguments, then the paths provided to a ``Finder`` in config file will be ignored. You can use <comment>--path-mode=intersection</comment>
  1990. to merge paths from the config file and from the argument:
  1991. <info>$ php %command.full_name% --path-mode=intersection /path/to/dir</info>
  1992. The <comment>--format</comment> option for the output format. Supported formats are ``txt`` (default one), ``json``, ``xml``, ``checkstyle`` and ``junit``.
  1993. NOTE: the output for the following formats are generated in accordance with XML schemas
  1994. * ``junit`` follows the `JUnit xml schema from Jenkins </doc/junit-10.xsd>`_
  1995. * ``checkstyle`` follows the common `"checkstyle" xml schema </doc/checkstyle.xsd>`_
  1996. The <comment>--verbose</comment> option will show the applied rules. When using the ``txt`` format it will also displays progress notifications.
  1997. The <comment>--rules</comment> option limits the rules to apply on the
  1998. project:
  1999. <info>$ php %command.full_name% /path/to/project --rules=@PSR2</info>
  2000. By default the PSR1 and PSR2 rules are used.
  2001. The <comment>--rules</comment> option lets you choose the exact rules to
  2002. apply (the rule names must be separated by a comma):
  2003. <info>$ php %command.full_name% /path/to/dir --rules=line_ending,full_opening_tag,indentation_type</info>
  2004. You can also blacklist the rules you don't want by placing a dash in front of the rule name, if this is more convenient,
  2005. using <comment>-name_of_fixer</comment>:
  2006. <info>$ php %command.full_name% /path/to/dir --rules=-full_opening_tag,-indentation_type</info>
  2007. When using combinations of exact and blacklist rules, applying exact rules along with above blacklisted results:
  2008. <info>$ php %command.full_name% /path/to/project --rules=@Symfony,-@PSR1,-blank_line_before_statement,strict_comparison</info>
  2009. Complete configuration for rules can be supplied using a ``json`` formatted string.
  2010. <info>$ php %command.full_name% /path/to/project --rules='{"concat_space": {"spacing": "none"}}'</info>
  2011. The <comment>--dry-run</comment> flag will run the fixer without making changes to your files.
  2012. The <comment>--diff</comment> flag can be used to let the fixer output all the changes it makes.
  2013. The <comment>--diff-format</comment> option allows to specify in which format the fixer should output the changes it makes:
  2014. * <comment>udiff</comment>: unified diff format;
  2015. * <comment>sbd</comment>: Sebastianbergmann/diff format (default when using `--diff` without specifying `diff-format`).
  2016. The <comment>--allow-risky</comment> option (pass ``yes`` or ``no``) allows you to set whether risky rules may run. Default value is taken from config file.
  2017. Risky rule is a rule, which could change code behaviour. By default no risky rules are run.
  2018. The <comment>--stop-on-violation</comment> flag stops the execution upon first file that needs to be fixed.
  2019. The <comment>--show-progress</comment> option allows you to choose the way process progress is rendered:
  2020. * <comment>none</comment>: disables progress output;
  2021. * <comment>run-in</comment>: [deprecated] simple single-line progress output;
  2022. * <comment>estimating</comment>: [deprecated] multiline progress output with number of files and percentage on each line. Note that with this option, the files list is evaluated before processing to get the total number of files and then kept in memory to avoid using the file iterator twice. This has an impact on memory usage so using this option is not recommended on very large projects;
  2023. * <comment>estimating-max</comment>: [deprecated] same as <comment>dots</comment>;
  2024. * <comment>dots</comment>: same as <comment>estimating</comment> but using all terminal columns instead of default 80.
  2025. If the option is not provided, it defaults to <comment>run-in</comment> unless a config file that disables output is used, in which case it defaults to <comment>none</comment>. This option has no effect if the verbosity of the command is less than <comment>verbose</comment>.
  2026. <info>$ php %command.full_name% --verbose --show-progress=estimating</info>
  2027. The command can also read from standard input, in which case it won't
  2028. automatically fix anything:
  2029. <info>$ cat foo.php | php %command.full_name% --diff -</info>
  2030. Finally, if you don't need BC kept on CLI level, you might use `PHP_CS_FIXER_FUTURE_MODE` to start using options that
  2031. would be default in next MAJOR release (unified differ, estimating, full-width progress indicator):
  2032. <info>$ PHP_CS_FIXER_FUTURE_MODE=1 php %command.full_name% -v --diff</info>
  2033. Choose from the list of available rules:
  2034. %%%FIXERS_DETAILS%%%
  2035. The <comment>--dry-run</comment> option displays the files that need to be
  2036. fixed but without actually modifying them:
  2037. <info>$ php %command.full_name% /path/to/code --dry-run</info>
  2038. Config file
  2039. -----------
  2040. Instead of using command line options to customize the rule, you can save the
  2041. project configuration in a <comment>.php_cs.dist</comment> file in the root directory of your project.
  2042. The file must return an instance of `PhpCsFixer\ConfigInterface` (<url>%%%CONFIG_INTERFACE_URL%%%</url>)
  2043. which lets you configure the rules, the files and directories that
  2044. need to be analyzed. You may also create <comment>.php_cs</comment> file, which is
  2045. the local configuration that will be used instead of the project configuration. It
  2046. is a good practice to add that file into your <comment>.gitignore</comment> file.
  2047. With the <comment>--config</comment> option you can specify the path to the
  2048. <comment>.php_cs</comment> file.
  2049. The example below will add two rules to the default list of PSR2 set rules:
  2050. <?php
  2051. $finder = PhpCsFixer\Finder::create()
  2052. ->exclude('somedir')
  2053. ->notPath('src/Symfony/Component/Translation/Tests/fixtures/resources.php')
  2054. ->in(__DIR__)
  2055. ;
  2056. return PhpCsFixer\Config::create()
  2057. ->setRules([
  2058. '@PSR2' => true,
  2059. 'strict_param' => true,
  2060. 'array_syntax' => ['syntax' => 'short'],
  2061. ])
  2062. ->setFinder($finder)
  2063. ;
  2064. ?>
  2065. **NOTE**: ``exclude`` will work only for directories, so if you need to exclude file, try ``notPath``.
  2066. See `Symfony\Finder` (<url>http://symfony.com/doc/current/components/finder.html</url>)
  2067. online documentation for other `Finder` methods.
  2068. You may also use a blacklist for the rules instead of the above shown whitelist approach.
  2069. The following example shows how to use all ``Symfony`` rules but the ``full_opening_tag`` rule.
  2070. <?php
  2071. $finder = PhpCsFixer\Finder::create()
  2072. ->exclude('somedir')
  2073. ->in(__DIR__)
  2074. ;
  2075. return PhpCsFixer\Config::create()
  2076. ->setRules([
  2077. '@Symfony' => true,
  2078. 'full_opening_tag' => false,
  2079. ])
  2080. ->setFinder($finder)
  2081. ;
  2082. ?>
  2083. You may want to use non-linux whitespaces in your project. Then you need to
  2084. configure them in your config file.
  2085. <?php
  2086. return PhpCsFixer\Config::create()
  2087. ->setIndent("\t")
  2088. ->setLineEnding("\r\n")
  2089. ;
  2090. ?>
  2091. By using ``--using-cache`` option with ``yes`` or ``no`` you can set if the caching
  2092. mechanism should be used.
  2093. Caching
  2094. -------
  2095. The caching mechanism is enabled by default. This will speed up further runs by
  2096. fixing only files that were modified since the last run. The tool will fix all
  2097. files if the tool version has changed or the list of rules has changed.
  2098. Cache is supported only for tool downloaded as phar file or installed via
  2099. composer.
  2100. Cache can be disabled via ``--using-cache`` option or config file:
  2101. <?php
  2102. return PhpCsFixer\Config::create()
  2103. ->setUsingCache(false)
  2104. ;
  2105. ?>
  2106. Cache file can be specified via ``--cache-file`` option or config file:
  2107. <?php
  2108. return PhpCsFixer\Config::create()
  2109. ->setCacheFile(__DIR__.'/.php_cs.cache')
  2110. ;
  2111. ?>
  2112. Using PHP CS Fixer on CI
  2113. ------------------------
  2114. Require ``friendsofphp/php-cs-fixer`` as a ``dev`` dependency:
  2115. $ ./composer.phar require --dev friendsofphp/php-cs-fixer
  2116. Then, add the following command to your CI:
  2117. %%%CI_INTEGRATION%%%
  2118. Where ``$COMMIT_RANGE`` is your range of commits, eg ``$TRAVIS_COMMIT_RANGE`` or ``HEAD~..HEAD``.
  2119. Exit codes
  2120. ----------
  2121. Exit code is built using following bit flags:
  2122. * 0 OK.
  2123. * 1 General error (or PHP minimal requirement not matched).
  2124. * 4 Some files have invalid syntax (only in dry-run mode).
  2125. * 8 Some files need fixing (only in dry-run mode).
  2126. * 16 Configuration error of the application.
  2127. * 32 Configuration error of a Fixer.
  2128. * 64 Exception raised within the application.
  2129. (applies to exit codes of the `fix` command only)
  2130. EOF
  2131. ;
  2132. return strtr($template, [
  2133. '%%%CONFIG_INTERFACE_URL%%%' => sprintf(
  2134. 'https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/v%s/src/ConfigInterface.php',
  2135. self::getLatestReleaseVersionFromChangeLog()
  2136. ),
  2137. '%%%CI_INTEGRATION%%%' => implode("\n", array_map(
  2138. static function ($line) { return ' $ '.$line; },
  2139. array_slice(file(__DIR__.'/../../../dev-tools/ci-integration.sh', FILE_IGNORE_NEW_LINES), 3)
  2140. )),
  2141. '%%%FIXERS_DETAILS%%%' => self::getFixersHelp(),
  2142. ]);
  2143. }
  2144. public static function toString($value)
  2145. {
  2146. if (is_array($value)) {
  2147. static $replaces = [
  2148. ['#\r|\n#', '#\s{1,}#', '#array\s*\((.*)\)#s', '#\[\s+#', '#,\s*\]#', '#\d+\s*=>\s*#'],
  2149. ['', ' ', '[$1]', '[', ']', ''],
  2150. ];
  2151. $str = var_export($value, true);
  2152. do {
  2153. $strNew = preg_replace(
  2154. $replaces[0],
  2155. $replaces[1],
  2156. $str
  2157. );
  2158. if ($strNew === $str) {
  2159. break;
  2160. }
  2161. $str = $strNew;
  2162. } while (true);
  2163. } else {
  2164. $str = var_export($value, true);
  2165. }
  2166. return preg_replace('/\bNULL\b/', 'null', $str);
  2167. }
  2168. public static function getDisplayableAllowedValues(FixerOptionInterface $option)
  2169. {
  2170. $allowed = $option->getAllowedValues();
  2171. if (null !== $allowed) {
  2172. $allowed = array_filter($allowed, static function ($value) {
  2173. return !($value instanceof \Closure);
  2174. });
  2175. usort($allowed, static function ($valueA, $valueB) {
  2176. return strcasecmp(
  2177. self::toString($valueA),
  2178. self::toString($valueB)
  2179. );
  2180. });
  2181. if (0 === count($allowed)) {
  2182. $allowed = null;
  2183. }
  2184. }
  2185. return $allowed;
  2186. }
  2187. public static function getLatestReleaseVersionFromChangeLog()
  2188. {
  2189. static $version = null;
  2190. if (null !== $version) {
  2191. return $version;
  2192. }
  2193. $changelogFile = self::getChangeLogFile();
  2194. if (null === $changelogFile) {
  2195. $version = Application::VERSION;
  2196. return $version;
  2197. }
  2198. $changelog = @file_get_contents($changelogFile);
  2199. if (false === $changelog) {
  2200. $error = error_get_last();
  2201. throw new \RuntimeException(sprintf(
  2202. 'Failed to read content of the changelog file "%s".%s',
  2203. $changelogFile,
  2204. $error ? ' '.$error['message'] : ''
  2205. ));
  2206. }
  2207. for ($i = (int) Application::VERSION; $i > 0; --$i) {
  2208. if (1 === preg_match('/Changelog for v('.$i.'.\d+.\d+)/', $changelog, $matches)) {
  2209. $version = $matches[1];
  2210. break;
  2211. }
  2212. }
  2213. if (null === $version) {
  2214. throw new \RuntimeException(sprintf('Failed to parse changelog data of "%s".', $changelogFile));
  2215. }
  2216. return $version;
  2217. }
  2218. protected function initialize(InputInterface $input, OutputInterface $output)
  2219. {
  2220. $output->getFormatter()->setStyle('url', new OutputFormatterStyle('blue'));
  2221. }
  2222. private static function getChangeLogFile()
  2223. {
  2224. $changelogFile = __DIR__.'/../../../CHANGELOG.md';
  2225. return is_file($changelogFile) ? $changelogFile : null;
  2226. }
  2227. private static function getFixersHelp()
  2228. {
  2229. $help = '';
  2230. $fixerFactory = new FixerFactory();
  2231. $fixers = $fixerFactory->registerBuiltInFixers()->getFixers();
  2232. usort(
  2233. $fixers,
  2234. static function (FixerInterface $a, FixerInterface $b) {
  2235. return strcmp($a->getName(), $b->getName());
  2236. }
  2237. );
  2238. $ruleSets = [];
  2239. foreach (RuleSet::create()->getSetDefinitionNames() as $setName) {
  2240. $ruleSets[$setName] = new RuleSet([$setName => true]);
  2241. }
  2242. $getSetsWithRule = static function ($rule) use ($ruleSets) {
  2243. $sets = [];
  2244. foreach ($ruleSets as $setName => $ruleSet) {
  2245. if ($ruleSet->hasRule($rule)) {
  2246. $sets[] = $setName;
  2247. }
  2248. }
  2249. return $sets;
  2250. };
  2251. $count = count($fixers) - 1;
  2252. foreach ($fixers as $i => $fixer) {
  2253. $sets = $getSetsWithRule($fixer->getName());
  2254. if ($fixer instanceof DefinedFixerInterface) {
  2255. $description = $fixer->getDefinition()->getSummary();
  2256. } else {
  2257. $description = '[n/a]';
  2258. }
  2259. if ($fixer instanceof DeprecatedFixerInterface) {
  2260. $successors = $fixer->getSuccessorsNames();
  2261. $message = [] === $successors
  2262. ? 'will be removed on next major version'
  2263. : sprintf('use %s instead', Utils::naturalLanguageJoinWithBackticks($successors));
  2264. $description .= sprintf(' DEPRECATED: %s.', $message);
  2265. }
  2266. $description = implode("\n | ", self::wordwrap(
  2267. preg_replace('/(`.+?`)/', '<info>$1</info>', $description),
  2268. 72
  2269. ));
  2270. if (!empty($sets)) {
  2271. $help .= sprintf(" * <comment>%s</comment> [%s]\n | %s\n", $fixer->getName(), implode(', ', $sets), $description);
  2272. } else {
  2273. $help .= sprintf(" * <comment>%s</comment>\n | %s\n", $fixer->getName(), $description);
  2274. }
  2275. if ($fixer->isRisky()) {
  2276. $help .= sprintf(
  2277. " | *Risky rule: %s.*\n",
  2278. preg_replace(
  2279. '/(`.+?`)/',
  2280. '<info>$1</info>',
  2281. lcfirst(preg_replace('/\.$/', '', $fixer->getDefinition()->getRiskyDescription()))
  2282. )
  2283. );
  2284. }
  2285. if ($fixer instanceof ConfigurationDefinitionFixerInterface) {
  2286. $configurationDefinition = $fixer->getConfigurationDefinition();
  2287. $configurationDefinitionOptions = $configurationDefinition->getOptions();
  2288. if (count($configurationDefinitionOptions)) {
  2289. $help .= " |\n | Configuration options:\n";
  2290. usort(
  2291. $configurationDefinitionOptions,
  2292. static function (FixerOptionInterface $optionA, FixerOptionInterface $optionB) {
  2293. return strcmp($optionA->getName(), $optionB->getName());
  2294. }
  2295. );
  2296. foreach ($configurationDefinitionOptions as $option) {
  2297. $line = '<info>'.OutputFormatter::escape($option->getName()).'</info>';
  2298. $allowed = self::getDisplayableAllowedValues($option);
  2299. if (null !== $allowed) {
  2300. foreach ($allowed as &$value) {
  2301. $value = self::toString($value);
  2302. }
  2303. } else {
  2304. $allowed = $option->getAllowedTypes();
  2305. }
  2306. if (null !== $allowed) {
  2307. $line .= ' (<comment>'.implode('</comment>, <comment>', $allowed).'</comment>)';
  2308. }
  2309. $line .= ': '.preg_replace(
  2310. '/(`.+?`)/',
  2311. '<info>$1</info>',
  2312. lcfirst(preg_replace('/\.$/', '', OutputFormatter::escape($option->getDescription())))
  2313. ).'; ';
  2314. if ($option->hasDefault()) {
  2315. $line .= 'defaults to <comment>'.self::toString($option->getDefault()).'</comment>';
  2316. } else {
  2317. $line .= 'required';
  2318. }
  2319. foreach (self::wordwrap($line, 72) as $index => $line) {
  2320. $help .= (0 === $index ? ' | - ' : ' | ').$line."\n";
  2321. }
  2322. }
  2323. }
  2324. } elseif ($fixer instanceof ConfigurableFixerInterface) {
  2325. $help .= " | *Configurable rule.*\n";
  2326. }
  2327. if ($count !== $i) {
  2328. $help .= "\n";
  2329. }
  2330. }
  2331. return preg_replace('#\\\\(</.*?>)#', '<<$1', $help);
  2332. }
  2333. private static function wordwrap($string, $width)
  2334. {
  2335. $result = [];
  2336. $currentLine = 0;
  2337. $lineLength = 0;
  2338. foreach (explode(' ', $string) as $word) {
  2339. $wordLength = strlen(preg_replace('~</?(\w+)>~', '', $word));
  2340. if (0 !== $lineLength) {
  2341. ++$wordLength;
  2342. }
  2343. if ($lineLength + $wordLength > $width) {
  2344. ++$currentLine;
  2345. $lineLength = 0;
  2346. }
  2347. $result[$currentLine][] = $word;
  2348. $lineLength += $wordLength;
  2349. }
  2350. return array_map(static function ($line) {
  2351. return implode(' ', $line);
  2352. }, $result);
  2353. }
  2354. }
  2355. <?php
  2356. namespace PhpCsFixer\Console\Command;
  2357. use Symfony\Component\Console\Command\Command;
  2358. use Symfony\Component\Console\Input\InputInterface;
  2359. use Symfony\Component\Console\Output\OutputInterface;
  2360. final class ReadmeCommand extends Command
  2361. {
  2362. const COMMAND_NAME = 'readme';
  2363. protected function configure()
  2364. {
  2365. $this
  2366. ->setName(self::COMMAND_NAME)
  2367. ->setDescription('Generates the README content, based on the fix command help.')
  2368. ;
  2369. }
  2370. protected function execute(InputInterface $input, OutputInterface $output)
  2371. {
  2372. $header = <<<'EOF'
  2373. PHP Coding Standards Fixer
  2374. ==========================
  2375. The PHP Coding Standards Fixer (PHP CS Fixer) tool fixes your code to follow standards;
  2376. whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc.,
  2377. or other community driven ones like the Symfony one.
  2378. You can **also** define your (teams) style through configuration.
  2379. It can modernize your code (like converting the `pow` function to the `**` operator on PHP 5.6)
  2380. and (micro) optimize it.
  2381. If you are already using a linter to identify coding standards problems in your
  2382. code, you know that fixing them by hand is tedious, especially on large
  2383. projects. This tool does not only detect them, but also fixes them for you.
  2384. The PHP CS Fixer is maintained on GitHub at https://github.com/FriendsOfPHP/PHP-CS-Fixer
  2385. bug reports and ideas about new features are welcome there.
  2386. You can talk to us at https://gitter.im/PHP-CS-Fixer/Lobby about the project,
  2387. configuration, possible improvements, ideas and questions, please visit us!
  2388. Requirements
  2389. ------------
  2390. PHP needs to be a minimum version of PHP 5.6.0.
  2391. Installation
  2392. ------------
  2393. Locally
  2394. ~~~~~~~
  2395. Download the `php-cs-fixer.phar`_ file and store it somewhere on your computer.
  2396. Globally (manual)
  2397. ~~~~~~~~~~~~~~~~~
  2398. You can run these commands to easily access latest ``php-cs-fixer`` from anywhere on
  2399. your system:
  2400. .. code-block:: bash
  2401. $ wget %download.url% -O php-cs-fixer
  2402. or with specified version:
  2403. .. code-block:: bash
  2404. $ wget %download.version_url% -O php-cs-fixer
  2405. or with curl:
  2406. .. code-block:: bash
  2407. $ curl -L %download.url% -o php-cs-fixer
  2408. then:
  2409. .. code-block:: bash
  2410. $ sudo chmod a+x php-cs-fixer
  2411. $ sudo mv php-cs-fixer /usr/local/bin/php-cs-fixer
  2412. Then, just run ``php-cs-fixer``.
  2413. Globally (Composer)
  2414. ~~~~~~~~~~~~~~~~~~~
  2415. To install PHP CS Fixer, `install Composer <https://getcomposer.org/download/>`_ and issue the following command:
  2416. .. code-block:: bash
  2417. $ composer global require friendsofphp/php-cs-fixer
  2418. Then make sure you have the global Composer binaries directory in your ``PATH``. This directory is platform-dependent, see `Composer documentation <https://getcomposer.org/doc/03-cli.md#composer-home>`_ for details. Example for some Unix systems:
  2419. .. code-block:: bash
  2420. $ export PATH="$PATH:$HOME/.composer/vendor/bin"
  2421. Globally (homebrew)
  2422. ~~~~~~~~~~~~~~~~~~~
  2423. PHP-CS-Fixer is part of the homebrew-php project. Follow the installation
  2424. instructions at https://github.com/homebrew/homebrew-php if you don't
  2425. already have it.
  2426. .. code-block:: bash
  2427. $ brew install homebrew/php/php-cs-fixer
  2428. Update
  2429. ------
  2430. Locally
  2431. ~~~~~~~
  2432. The ``self-update`` command tries to update ``php-cs-fixer`` itself:
  2433. .. code-block:: bash
  2434. $ php php-cs-fixer.phar self-update
  2435. Globally (manual)
  2436. ~~~~~~~~~~~~~~~~~
  2437. You can update ``php-cs-fixer`` through this command:
  2438. .. code-block:: bash
  2439. $ sudo php-cs-fixer self-update
  2440. Globally (Composer)
  2441. ~~~~~~~~~~~~~~~~~~~
  2442. You can update ``php-cs-fixer`` through this command:
  2443. .. code-block:: bash
  2444. $ ./composer.phar global update friendsofphp/php-cs-fixer
  2445. Globally (homebrew)
  2446. ~~~~~~~~~~~~~~~~~~~
  2447. You can update ``php-cs-fixer`` through this command:
  2448. .. code-block:: bash
  2449. $ brew upgrade php-cs-fixer
  2450. Usage
  2451. -----
  2452. EOF;
  2453. $footer = <<<'EOF'
  2454. Helpers
  2455. -------
  2456. Dedicated plugins exist for:
  2457. * `Atom`_
  2458. * `NetBeans`_
  2459. * `PhpStorm`_
  2460. * `Sublime Text`_
  2461. * `Vim`_
  2462. Contribute
  2463. ----------
  2464. The tool comes with quite a few built-in fixers, but everyone is more than
  2465. welcome to `contribute`_ more of them.
  2466. Fixers
  2467. ~~~~~~
  2468. A *fixer* is a class that tries to fix one CS issue (a ``Fixer`` class must
  2469. implement ``FixerInterface``).
  2470. Configs
  2471. ~~~~~~~
  2472. A *config* knows about the CS rules and the files and directories that must be
  2473. scanned by the tool when run in the directory of your project. It is useful for
  2474. projects that follow a well-known directory structures (like for Symfony
  2475. projects for instance).
  2476. .. _php-cs-fixer.phar: %download.url%
  2477. .. _Atom: https://github.com/Glavin001/atom-beautify
  2478. .. _NetBeans: http://plugins.netbeans.org/plugin/49042/php-cs-fixer
  2479. .. _PhpStorm: https://medium.com/@valeryan/how-to-configure-phpstorm-to-use-php-cs-fixer-1844991e521f
  2480. .. _Sublime Text: https://github.com/benmatselby/sublime-phpcs
  2481. .. _Vim: https://github.com/stephpy/vim-php-cs-fixer
  2482. .. _contribute: https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/CONTRIBUTING.md
  2483. EOF;
  2484. $command = $this->getApplication()->get('fix');
  2485. $help = $command->getHelp();
  2486. $help = str_replace('%command.full_name%', 'php-cs-fixer.phar '.$command->getName(), $help);
  2487. $help = str_replace('%command.name%', $command->getName(), $help);
  2488. $help = preg_replace('#</?(comment|info)>#', '``', $help);
  2489. $help = preg_replace('#`(``.+?``)`#', '$1', $help);
  2490. $help = preg_replace('#^(\s+)``(.+)``$#m', '$1$2', $help);
  2491. $help = preg_replace('#^ \* ``(.+)``(.*?\n)#m', "* **$1**$2\n", $help);
  2492. $help = preg_replace('#^ \\| #m', ' ', $help);
  2493. $help = preg_replace('#^ \\|#m', '', $help);
  2494. $help = preg_replace('#^(?= \\*Risky rule: )#m', "\n", $help);
  2495. $help = preg_replace("#^( Configuration options:\n)( - )#m", "$1\n$2", $help);
  2496. $help = preg_replace("#^\n( +\\$ )#m", "\n.. code-block:: bash\n\n$1", $help);
  2497. $help = preg_replace("#^\n( +<\\?php)#m", "\n.. code-block:: php\n\n$1", $help);
  2498. $help = preg_replace_callback(
  2499. '#^\s*<\?(\w+).*?\?>#ms',
  2500. static function ($matches) {
  2501. $result = preg_replace("#^\\.\\. code-block:: bash\n\n#m", '', $matches[0]);
  2502. if ('php' !== $matches[1]) {
  2503. $result = preg_replace("#<\\?{$matches[1]}\\s*#", '', $result);
  2504. }
  2505. $result = preg_replace("#\n\n +\\?>#", '', $result);
  2506. return $result;
  2507. },
  2508. $help
  2509. );
  2510. $help = preg_replace_callback(
  2511. '#`(.+)`\s?\(<url>(.+)<\/url>\)#',
  2512. static function (array $matches) {
  2513. return sprintf('`%s <%s>`_', str_replace('\\', '\\\\', $matches[1]), $matches[2]);
  2514. },
  2515. $help
  2516. );
  2517. $help = preg_replace('#^ #m', ' ', $help);
  2518. $help = preg_replace('#\*\* +\[#', '** [', $help);
  2519. $downloadLatestUrl = sprintf('https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/v%s/php-cs-fixer.phar', HelpCommand::getLatestReleaseVersionFromChangeLog());
  2520. $downloadUrl = 'http://cs.sensiolabs.org/download/php-cs-fixer-v2.phar';
  2521. $header = str_replace('%download.version_url%', $downloadLatestUrl, $header);
  2522. $header = str_replace('%download.url%', $downloadUrl, $header);
  2523. $footer = str_replace('%download.version_url%', $downloadLatestUrl, $footer);
  2524. $footer = str_replace('%download.url%', $downloadUrl, $footer);
  2525. $output->write($header."\n".$help."\n".$footer);
  2526. }
  2527. }
  2528. <?php
  2529. namespace PhpCsFixer\Console\Command;
  2530. use PhpCsFixer\Console\SelfUpdate\NewVersionCheckerInterface;
  2531. use PhpCsFixer\PharCheckerInterface;
  2532. use PhpCsFixer\ToolInfoInterface;
  2533. use Symfony\Component\Console\Command\Command;
  2534. use Symfony\Component\Console\Input\InputInterface;
  2535. use Symfony\Component\Console\Input\InputOption;
  2536. use Symfony\Component\Console\Output\OutputInterface;
  2537. final class SelfUpdateCommand extends Command
  2538. {
  2539. const COMMAND_NAME = 'self-update';
  2540. private $versionChecker;
  2541. private $toolInfo;
  2542. private $pharChecker;
  2543. public function __construct(
  2544. NewVersionCheckerInterface $versionChecker,
  2545. ToolInfoInterface $toolInfo,
  2546. PharCheckerInterface $pharChecker
  2547. ) {
  2548. parent::__construct();
  2549. $this->versionChecker = $versionChecker;
  2550. $this->toolInfo = $toolInfo;
  2551. $this->pharChecker = $pharChecker;
  2552. }
  2553. protected function configure()
  2554. {
  2555. $this
  2556. ->setName(self::COMMAND_NAME)
  2557. ->setAliases(['selfupdate'])
  2558. ->setDefinition(
  2559. [
  2560. new InputOption('--force', '-f', InputOption::VALUE_NONE, 'Force update to next major version if available.'),
  2561. ]
  2562. )
  2563. ->setDescription('Update php-cs-fixer.phar to the latest stable version.')
  2564. ->setHelp(
  2565. <<<'EOT'
  2566. The <info>%command.name%</info> command replace your php-cs-fixer.phar by the
  2567. latest version released on:
  2568. <comment>https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases</comment>
  2569. <info>$ php php-cs-fixer.phar %command.name%</info>
  2570. EOT
  2571. )
  2572. ;
  2573. }
  2574. protected function execute(InputInterface $input, OutputInterface $output)
  2575. {
  2576. if (!$this->toolInfo->isInstalledAsPhar()) {
  2577. $output->writeln('<error>Self-update is available only for PHAR version.</error>');
  2578. return 1;
  2579. }
  2580. $currentVersion = $this->getApplication()->getVersion();
  2581. preg_match('/^v?(?<major>\d+)\./', $currentVersion, $matches);
  2582. $currentMajor = (int) $matches['major'];
  2583. try {
  2584. $latestVersion = $this->versionChecker->getLatestVersion();
  2585. $latestVersionOfCurrentMajor = $this->versionChecker->getLatestVersionOfMajor($currentMajor);
  2586. } catch (\Exception $exception) {
  2587. $output->writeln(sprintf(
  2588. '<error>Unable to determine newest version: %s</error>',
  2589. $exception->getMessage()
  2590. ));
  2591. return 1;
  2592. }
  2593. if (1 !== $this->versionChecker->compareVersions($latestVersion, $currentVersion)) {
  2594. $output->writeln('<info>php-cs-fixer is already up to date.</info>');
  2595. return 0;
  2596. }
  2597. $remoteTag = $latestVersion;
  2598. if (
  2599. 0 !== $this->versionChecker->compareVersions($latestVersionOfCurrentMajor, $latestVersion)
  2600. && true !== $input->getOption('force')
  2601. ) {
  2602. $output->writeln(sprintf('<info>A new major version of php-cs-fixer is available</info> (<comment>%s</comment>)', $latestVersion));
  2603. $output->writeln(sprintf('<info>Before upgrading please read</info> https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/%s/UPGRADE.md', $latestVersion));
  2604. $output->writeln('<info>If you are ready to upgrade run this command with</info> <comment>-f</comment>');
  2605. $output->writeln('<info>Checking for new minor/patch version...</info>');
  2606. if (1 !== $this->versionChecker->compareVersions($latestVersionOfCurrentMajor, $currentVersion)) {
  2607. $output->writeln('<info>No minor update for php-cs-fixer.</info>');
  2608. return 0;
  2609. }
  2610. $remoteTag = $latestVersionOfCurrentMajor;
  2611. }
  2612. $localFilename = realpath($_SERVER['argv'][0]) ?: $_SERVER['argv'][0];
  2613. if (!is_writable($localFilename)) {
  2614. $output->writeln(sprintf('<error>No permission to update %s file.</error>', $localFilename));
  2615. return 1;
  2616. }
  2617. $tempFilename = dirname($localFilename).'/'.basename($localFilename, '.phar').'-tmp.phar';
  2618. $remoteFilename = $this->toolInfo->getPharDownloadUri($remoteTag);
  2619. if (false === @copy($remoteFilename, $tempFilename)) {
  2620. $output->writeln(sprintf('<error>Unable to download new version %s from the server.</error>', $remoteTag));
  2621. return 1;
  2622. }
  2623. chmod($tempFilename, 0777 & ~umask());
  2624. $pharInvalidityReason = $this->pharChecker->checkFileValidity($tempFilename);
  2625. if (null !== $pharInvalidityReason) {
  2626. unlink($tempFilename);
  2627. $output->writeln(sprintf('<error>The download of %s is corrupt (%s).</error>', $remoteTag, $pharInvalidityReason));
  2628. $output->writeln('<error>Please re-run the self-update command to try again.</error>');
  2629. return 1;
  2630. }
  2631. rename($tempFilename, $localFilename);
  2632. $output->writeln(sprintf('<info>php-cs-fixer updated</info> (<comment>%s</comment>)', $remoteTag));
  2633. }
  2634. }
  2635. <?php
  2636. namespace PhpCsFixer\Console;
  2637. use PhpCsFixer\Cache\CacheManagerInterface;
  2638. use PhpCsFixer\Cache\Directory;
  2639. use PhpCsFixer\Cache\DirectoryInterface;
  2640. use PhpCsFixer\Cache\FileCacheManager;
  2641. use PhpCsFixer\Cache\FileHandler;
  2642. use PhpCsFixer\Cache\NullCacheManager;
  2643. use PhpCsFixer\Cache\Signature;
  2644. use PhpCsFixer\ConfigInterface;
  2645. use PhpCsFixer\ConfigurationException\InvalidConfigurationException;
  2646. use PhpCsFixer\Differ\DifferInterface;
  2647. use PhpCsFixer\Differ\NullDiffer;
  2648. use PhpCsFixer\Differ\SebastianBergmannDiffer;
  2649. use PhpCsFixer\Differ\UnifiedDiffer;
  2650. use PhpCsFixer\Finder;
  2651. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  2652. use PhpCsFixer\Fixer\FixerInterface;
  2653. use PhpCsFixer\FixerFactory;
  2654. use PhpCsFixer\Linter\Linter;
  2655. use PhpCsFixer\Linter\LinterInterface;
  2656. use PhpCsFixer\Report\ReporterFactory;
  2657. use PhpCsFixer\Report\ReporterInterface;
  2658. use PhpCsFixer\RuleSet;
  2659. use PhpCsFixer\StdinFileInfo;
  2660. use PhpCsFixer\ToolInfoInterface;
  2661. use PhpCsFixer\Utils;
  2662. use PhpCsFixer\WhitespacesFixerConfig;
  2663. use PhpCsFixer\WordMatcher;
  2664. use Symfony\Component\Console\Output\OutputInterface;
  2665. use Symfony\Component\Filesystem\Filesystem;
  2666. use Symfony\Component\Finder\Finder as SymfonyFinder;
  2667. final class ConfigurationResolver
  2668. {
  2669. const PATH_MODE_OVERRIDE = 'override';
  2670. const PATH_MODE_INTERSECTION = 'intersection';
  2671. private $allowRisky;
  2672. private $config;
  2673. private $configFile;
  2674. private $cwd;
  2675. private $defaultConfig;
  2676. private $reporter;
  2677. private $isStdIn;
  2678. private $isDryRun;
  2679. private $fixers;
  2680. private $configFinderIsOverridden;
  2681. private $toolInfo;
  2682. private $options = [
  2683. 'allow-risky' => null,
  2684. 'cache-file' => null,
  2685. 'config' => null,
  2686. 'diff' => null,
  2687. 'diff-format' => null,
  2688. 'dry-run' => null,
  2689. 'format' => null,
  2690. 'path' => [],
  2691. 'path-mode' => self::PATH_MODE_OVERRIDE,
  2692. 'rules' => null,
  2693. 'show-progress' => null,
  2694. 'stop-on-violation' => null,
  2695. 'using-cache' => null,
  2696. 'verbosity' => null,
  2697. ];
  2698. private $cacheFile;
  2699. private $cacheManager;
  2700. private $differ;
  2701. private $directory;
  2702. private $finder;
  2703. private $format;
  2704. private $linter;
  2705. private $path;
  2706. private $progress;
  2707. private $ruleSet;
  2708. private $usingCache;
  2709. private $fixerFactory;
  2710. public function __construct(
  2711. ConfigInterface $config,
  2712. array $options,
  2713. $cwd,
  2714. ToolInfoInterface $toolInfo
  2715. ) {
  2716. $this->cwd = $cwd;
  2717. $this->defaultConfig = $config;
  2718. $this->toolInfo = $toolInfo;
  2719. foreach ($options as $name => $value) {
  2720. $this->setOption($name, $value);
  2721. }
  2722. }
  2723. public function getCacheFile()
  2724. {
  2725. if (!$this->getUsingCache()) {
  2726. return null;
  2727. }
  2728. if (null === $this->cacheFile) {
  2729. if (null === $this->options['cache-file']) {
  2730. $this->cacheFile = $this->getConfig()->getCacheFile();
  2731. } else {
  2732. $this->cacheFile = $this->options['cache-file'];
  2733. }
  2734. }
  2735. return $this->cacheFile;
  2736. }
  2737. public function getCacheManager()
  2738. {
  2739. if (null === $this->cacheManager) {
  2740. if ($this->getUsingCache() && ($this->toolInfo->isInstalledAsPhar() || $this->toolInfo->isInstalledByComposer())) {
  2741. $this->cacheManager = new FileCacheManager(
  2742. new FileHandler($this->getCacheFile()),
  2743. new Signature(
  2744. PHP_VERSION,
  2745. $this->toolInfo->getVersion(),
  2746. $this->getRules()
  2747. ),
  2748. $this->isDryRun(),
  2749. $this->getDirectory()
  2750. );
  2751. } else {
  2752. $this->cacheManager = new NullCacheManager();
  2753. }
  2754. }
  2755. return $this->cacheManager;
  2756. }
  2757. public function getConfig()
  2758. {
  2759. if (null === $this->config) {
  2760. foreach ($this->computeConfigFiles() as $configFile) {
  2761. if (!file_exists($configFile)) {
  2762. continue;
  2763. }
  2764. $config = self::separatedContextLessInclude($configFile);
  2765. if (!$config instanceof ConfigInterface) {
  2766. throw new InvalidConfigurationException(sprintf('The config file: "%s" does not return a "PhpCsFixer\ConfigInterface" instance. Got: "%s".', $configFile, is_object($config) ? get_class($config) : gettype($config)));
  2767. }
  2768. $this->config = $config;
  2769. $this->configFile = $configFile;
  2770. break;
  2771. }
  2772. if (null === $this->config) {
  2773. $this->config = $this->defaultConfig;
  2774. }
  2775. }
  2776. return $this->config;
  2777. }
  2778. public function getConfigFile()
  2779. {
  2780. if (null === $this->configFile) {
  2781. $this->getConfig();
  2782. }
  2783. return $this->configFile;
  2784. }
  2785. public function getDiffer()
  2786. {
  2787. if (null === $this->differ) {
  2788. $mapper = [
  2789. 'null' => static function () { return new NullDiffer(); },
  2790. 'sbd' => static function () { return new SebastianBergmannDiffer(); },
  2791. 'udiff' => static function () { return new UnifiedDiffer(); },
  2792. ];
  2793. if ($this->options['diff-format']) {
  2794. $option = $this->options['diff-format'];
  2795. if (!isset($mapper[$option])) {
  2796. throw new InvalidConfigurationException(sprintf(
  2797. '"diff-format" must be any of "%s", got "%s".',
  2798. implode('", "', array_keys($mapper)),
  2799. $option
  2800. ));
  2801. }
  2802. } else {
  2803. $default = 'sbd';
  2804. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  2805. $default = 'udiff';
  2806. }
  2807. $option = $this->options['diff'] ? $default : 'null';
  2808. }
  2809. $this->differ = $mapper[$option]();
  2810. }
  2811. return $this->differ;
  2812. }
  2813. public function getDirectory()
  2814. {
  2815. if (null === $this->directory) {
  2816. $path = $this->getCacheFile();
  2817. $filesystem = new Filesystem();
  2818. $absolutePath = $filesystem->isAbsolutePath($path)
  2819. ? $path
  2820. : $this->cwd.DIRECTORY_SEPARATOR.$path;
  2821. $this->directory = new Directory(dirname($absolutePath));
  2822. }
  2823. return $this->directory;
  2824. }
  2825. public function getFixers()
  2826. {
  2827. if (null === $this->fixers) {
  2828. $this->fixers = $this->createFixerFactory()
  2829. ->useRuleSet($this->getRuleSet())
  2830. ->setWhitespacesConfig(new WhitespacesFixerConfig($this->config->getIndent(), $this->config->getLineEnding()))
  2831. ->getFixers();
  2832. if (false === $this->getRiskyAllowed()) {
  2833. $riskyFixers = array_map(
  2834. static function (FixerInterface $fixer) {
  2835. return $fixer->getName();
  2836. },
  2837. array_filter(
  2838. $this->fixers,
  2839. static function (FixerInterface $fixer) {
  2840. return $fixer->isRisky();
  2841. }
  2842. )
  2843. );
  2844. if (count($riskyFixers)) {
  2845. throw new InvalidConfigurationException(sprintf('The rules contain risky fixers (%s), but they are not allowed to run. Perhaps you forget to use --allow-risky option?', implode(', ', $riskyFixers)));
  2846. }
  2847. }
  2848. foreach ($this->fixers as $fixer) {
  2849. if ($fixer instanceof DeprecatedFixerInterface) {
  2850. $successors = $fixer->getSuccessorsNames();
  2851. $message = sprintf(
  2852. 'Fixer `%s` is deprecated%s',
  2853. $fixer->getName(),
  2854. [] === $successors
  2855. ? ' and will be removed on next major version.'
  2856. : sprintf(', use %s instead.', Utils::naturalLanguageJoinWithBackticks($successors))
  2857. );
  2858. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  2859. throw new \RuntimeException($message.' This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
  2860. }
  2861. @trigger_error($message, E_USER_DEPRECATED);
  2862. }
  2863. }
  2864. }
  2865. return $this->fixers;
  2866. }
  2867. public function getLinter()
  2868. {
  2869. if (null === $this->linter) {
  2870. $this->linter = new Linter($this->getConfig()->getPhpExecutable());
  2871. }
  2872. return $this->linter;
  2873. }
  2874. public function getPath()
  2875. {
  2876. if (null === $this->path) {
  2877. $filesystem = new Filesystem();
  2878. $cwd = $this->cwd;
  2879. if (1 === count($this->options['path']) && '-' === $this->options['path'][0]) {
  2880. $this->path = $this->options['path'];
  2881. } else {
  2882. $this->path = array_map(
  2883. static function ($path) use ($cwd, $filesystem) {
  2884. $absolutePath = $filesystem->isAbsolutePath($path)
  2885. ? $path
  2886. : $cwd.DIRECTORY_SEPARATOR.$path;
  2887. if (!file_exists($absolutePath)) {
  2888. throw new InvalidConfigurationException(sprintf(
  2889. 'The path "%s" is not readable.',
  2890. $path
  2891. ));
  2892. }
  2893. return $absolutePath;
  2894. },
  2895. $this->options['path']
  2896. );
  2897. }
  2898. }
  2899. return $this->path;
  2900. }
  2901. public function getProgress()
  2902. {
  2903. if (null === $this->progress) {
  2904. if (OutputInterface::VERBOSITY_VERBOSE <= $this->options['verbosity'] && 'txt' === $this->getFormat()) {
  2905. $progressType = $this->options['show-progress'];
  2906. $progressTypes = ['none', 'run-in', 'estimating', 'estimating-max', 'dots'];
  2907. if (null === $progressType) {
  2908. $default = 'run-in';
  2909. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  2910. $default = 'dots';
  2911. }
  2912. $progressType = $this->getConfig()->getHideProgress() ? 'none' : $default;
  2913. } elseif (!in_array($progressType, $progressTypes, true)) {
  2914. throw new InvalidConfigurationException(sprintf(
  2915. 'The progress type "%s" is not defined, supported are "%s".',
  2916. $progressType,
  2917. implode('", "', $progressTypes)
  2918. ));
  2919. } elseif (in_array($progressType, ['estimating', 'estimating-max', 'run-in'], true)) {
  2920. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  2921. throw new \InvalidArgumentException('Passing `estimating`, `estimating-max` or `run-in` is deprecated and will not be supported in 3.0, use `none` or `dots` instead. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
  2922. }
  2923. @trigger_error(
  2924. 'Passing `estimating`, `estimating-max` or `run-in` is deprecated and will not be supported in 3.0, use `none` or `dots` instead.',
  2925. E_USER_DEPRECATED
  2926. );
  2927. }
  2928. $this->progress = $progressType;
  2929. } else {
  2930. $this->progress = 'none';
  2931. }
  2932. }
  2933. return $this->progress;
  2934. }
  2935. public function getReporter()
  2936. {
  2937. if (null === $this->reporter) {
  2938. $reporterFactory = ReporterFactory::create();
  2939. $reporterFactory->registerBuiltInReporters();
  2940. $format = $this->getFormat();
  2941. try {
  2942. $this->reporter = $reporterFactory->getReporter($format);
  2943. } catch (\UnexpectedValueException $e) {
  2944. $formats = $reporterFactory->getFormats();
  2945. sort($formats);
  2946. throw new InvalidConfigurationException(sprintf('The format "%s" is not defined, supported are "%s".', $format, implode('", "', $formats)));
  2947. }
  2948. }
  2949. return $this->reporter;
  2950. }
  2951. public function getRiskyAllowed()
  2952. {
  2953. if (null === $this->allowRisky) {
  2954. if (null === $this->options['allow-risky']) {
  2955. $this->allowRisky = $this->getConfig()->getRiskyAllowed();
  2956. } else {
  2957. $this->allowRisky = $this->resolveOptionBooleanValue('allow-risky');
  2958. }
  2959. }
  2960. return $this->allowRisky;
  2961. }
  2962. public function getRules()
  2963. {
  2964. return $this->getRuleSet()->getRules();
  2965. }
  2966. public function getUsingCache()
  2967. {
  2968. if (null === $this->usingCache) {
  2969. if (null === $this->options['using-cache']) {
  2970. $this->usingCache = $this->getConfig()->getUsingCache();
  2971. } else {
  2972. $this->usingCache = $this->resolveOptionBooleanValue('using-cache');
  2973. }
  2974. }
  2975. return $this->usingCache;
  2976. }
  2977. public function getFinder()
  2978. {
  2979. if (null === $this->finder) {
  2980. $this->finder = $this->resolveFinder();
  2981. }
  2982. return $this->finder;
  2983. }
  2984. public function isDryRun()
  2985. {
  2986. if (null === $this->isDryRun) {
  2987. if ($this->isStdIn()) {
  2988. $this->isDryRun = true;
  2989. } else {
  2990. $this->isDryRun = $this->options['dry-run'];
  2991. }
  2992. }
  2993. return $this->isDryRun;
  2994. }
  2995. public function shouldStopOnViolation()
  2996. {
  2997. return $this->options['stop-on-violation'];
  2998. }
  2999. public function configFinderIsOverridden()
  3000. {
  3001. if (null === $this->configFinderIsOverridden) {
  3002. $this->resolveFinder();
  3003. }
  3004. return $this->configFinderIsOverridden;
  3005. }
  3006. private function computeConfigFiles()
  3007. {
  3008. $configFile = $this->options['config'];
  3009. if (null !== $configFile) {
  3010. if (false === file_exists($configFile) || false === is_readable($configFile)) {
  3011. throw new InvalidConfigurationException(sprintf('Cannot read config file "%s".', $configFile));
  3012. }
  3013. return [$configFile];
  3014. }
  3015. $path = $this->getPath();
  3016. if ($this->isStdIn() || 0 === count($path)) {
  3017. $configDir = $this->cwd;
  3018. } elseif (1 < count($path)) {
  3019. throw new InvalidConfigurationException('For multiple paths config parameter is required.');
  3020. } elseif (is_file($path[0]) && $dirName = pathinfo($path[0], PATHINFO_DIRNAME)) {
  3021. $configDir = $dirName;
  3022. } else {
  3023. $configDir = $path[0];
  3024. }
  3025. $candidates = [
  3026. $configDir.DIRECTORY_SEPARATOR.'.php_cs',
  3027. $configDir.DIRECTORY_SEPARATOR.'.php_cs.dist',
  3028. ];
  3029. if ($configDir !== $this->cwd) {
  3030. $candidates[] = $this->cwd.DIRECTORY_SEPARATOR.'.php_cs';
  3031. $candidates[] = $this->cwd.DIRECTORY_SEPARATOR.'.php_cs.dist';
  3032. }
  3033. return $candidates;
  3034. }
  3035. private function createFixerFactory()
  3036. {
  3037. if (null === $this->fixerFactory) {
  3038. $fixerFactory = new FixerFactory();
  3039. $fixerFactory->registerBuiltInFixers();
  3040. $fixerFactory->registerCustomFixers($this->getConfig()->getCustomFixers());
  3041. $this->fixerFactory = $fixerFactory;
  3042. }
  3043. return $this->fixerFactory;
  3044. }
  3045. private function getFormat()
  3046. {
  3047. if (null === $this->format) {
  3048. $this->format = null === $this->options['format']
  3049. ? $this->getConfig()->getFormat()
  3050. : $this->options['format'];
  3051. }
  3052. return $this->format;
  3053. }
  3054. private function getRuleSet()
  3055. {
  3056. if (null === $this->ruleSet) {
  3057. $rules = $this->parseRules();
  3058. $this->validateRules($rules);
  3059. $this->ruleSet = new RuleSet($rules);
  3060. }
  3061. return $this->ruleSet;
  3062. }
  3063. private function isStdIn()
  3064. {
  3065. if (null === $this->isStdIn) {
  3066. $this->isStdIn = 1 === count($this->options['path']) && '-' === $this->options['path'][0];
  3067. }
  3068. return $this->isStdIn;
  3069. }
  3070. private function iterableToTraversable($iterable)
  3071. {
  3072. return is_array($iterable) ? new \ArrayIterator($iterable) : $iterable;
  3073. }
  3074. private function parseRules()
  3075. {
  3076. if (null === $this->options['rules']) {
  3077. return $this->getConfig()->getRules();
  3078. }
  3079. $rules = trim($this->options['rules']);
  3080. if ('' === $rules) {
  3081. throw new InvalidConfigurationException('Empty rules value is not allowed.');
  3082. }
  3083. if ('{' === $rules[0]) {
  3084. $rules = json_decode($rules, true);
  3085. if (JSON_ERROR_NONE !== json_last_error()) {
  3086. throw new InvalidConfigurationException(sprintf('Invalid JSON rules input: %s.', json_last_error_msg()));
  3087. }
  3088. return $rules;
  3089. }
  3090. $rules = [];
  3091. foreach (explode(',', $this->options['rules']) as $rule) {
  3092. $rule = trim($rule);
  3093. if ('' === $rule) {
  3094. throw new InvalidConfigurationException('Empty rule name is not allowed.');
  3095. }
  3096. if ('-' === $rule[0]) {
  3097. $rules[substr($rule, 1)] = false;
  3098. } else {
  3099. $rules[$rule] = true;
  3100. }
  3101. }
  3102. return $rules;
  3103. }
  3104. private function validateRules(array $rules)
  3105. {
  3106. $ruleSet = [];
  3107. foreach ($rules as $key => $value) {
  3108. if (is_int($key)) {
  3109. throw new InvalidConfigurationException(sprintf('Missing value for "%s" rule/set.', $value));
  3110. }
  3111. $ruleSet[$key] = true;
  3112. }
  3113. $ruleSet = new RuleSet($ruleSet);
  3114. $configuredFixers = array_keys($ruleSet->getRules());
  3115. $availableFixers = array_map(static function (FixerInterface $fixer) {
  3116. return $fixer->getName();
  3117. }, $this->createFixerFactory()->getFixers());
  3118. $unknownFixers = array_diff(
  3119. $configuredFixers,
  3120. $availableFixers
  3121. );
  3122. if (count($unknownFixers)) {
  3123. $matcher = new WordMatcher($availableFixers);
  3124. $message = 'The rules contain unknown fixers: ';
  3125. foreach ($unknownFixers as $unknownFixer) {
  3126. $alternative = $matcher->match($unknownFixer);
  3127. $message .= sprintf(
  3128. '"%s"%s, ',
  3129. $unknownFixer,
  3130. null === $alternative ? '' : ' (did you mean "'.$alternative.'"?)'
  3131. );
  3132. }
  3133. throw new InvalidConfigurationException(substr($message, 0, -2).'.');
  3134. }
  3135. }
  3136. private function resolveFinder()
  3137. {
  3138. $this->configFinderIsOverridden = false;
  3139. if ($this->isStdIn()) {
  3140. return new \ArrayIterator([new StdinFileInfo()]);
  3141. }
  3142. $modes = [self::PATH_MODE_OVERRIDE, self::PATH_MODE_INTERSECTION];
  3143. if (!in_array(
  3144. $this->options['path-mode'],
  3145. $modes,
  3146. true
  3147. )) {
  3148. throw new InvalidConfigurationException(sprintf(
  3149. 'The path-mode "%s" is not defined, supported are "%s".',
  3150. $this->options['path-mode'],
  3151. implode('", "', $modes)
  3152. ));
  3153. }
  3154. $isIntersectionPathMode = self::PATH_MODE_INTERSECTION === $this->options['path-mode'];
  3155. $paths = array_filter(array_map(
  3156. static function ($path) {
  3157. return realpath($path);
  3158. },
  3159. $this->getPath()
  3160. ));
  3161. if (!count($paths)) {
  3162. if ($isIntersectionPathMode) {
  3163. return new \ArrayIterator([]);
  3164. }
  3165. return $this->iterableToTraversable($this->getConfig()->getFinder());
  3166. }
  3167. $pathsByType = [
  3168. 'file' => [],
  3169. 'dir' => [],
  3170. ];
  3171. foreach ($paths as $path) {
  3172. if (is_file($path)) {
  3173. $pathsByType['file'][] = $path;
  3174. } else {
  3175. $pathsByType['dir'][] = $path.DIRECTORY_SEPARATOR;
  3176. }
  3177. }
  3178. $nestedFinder = null;
  3179. $currentFinder = $this->iterableToTraversable($this->getConfig()->getFinder());
  3180. try {
  3181. $nestedFinder = $currentFinder instanceof \IteratorAggregate ? $currentFinder->getIterator() : $currentFinder;
  3182. } catch (\Exception $e) {
  3183. }
  3184. if ($isIntersectionPathMode) {
  3185. if (null === $nestedFinder) {
  3186. throw new InvalidConfigurationException(
  3187. 'Cannot create intersection with not-fully defined Finder in configuration file.'
  3188. );
  3189. }
  3190. return new \CallbackFilterIterator(
  3191. $nestedFinder,
  3192. static function (\SplFileInfo $current) use ($pathsByType) {
  3193. $currentRealPath = $current->getRealPath();
  3194. if (in_array($currentRealPath, $pathsByType['file'], true)) {
  3195. return true;
  3196. }
  3197. foreach ($pathsByType['dir'] as $path) {
  3198. if (0 === strpos($currentRealPath, $path)) {
  3199. return true;
  3200. }
  3201. }
  3202. return false;
  3203. }
  3204. );
  3205. }
  3206. if (null !== $this->getConfigFile() && null !== $nestedFinder) {
  3207. $this->configFinderIsOverridden = true;
  3208. }
  3209. if ($currentFinder instanceof SymfonyFinder && null === $nestedFinder) {
  3210. return $currentFinder->in($pathsByType['dir'])->append($pathsByType['file']);
  3211. }
  3212. return Finder::create()->in($pathsByType['dir'])->append($pathsByType['file']);
  3213. }
  3214. private function setOption($name, $value)
  3215. {
  3216. if (!array_key_exists($name, $this->options)) {
  3217. throw new InvalidConfigurationException(sprintf('Unknown option name: "%s".', $name));
  3218. }
  3219. $this->options[$name] = $value;
  3220. }
  3221. private function resolveOptionBooleanValue($optionName)
  3222. {
  3223. $value = $this->options[$optionName];
  3224. if (is_bool($value)) {
  3225. return $value;
  3226. }
  3227. if (!is_string($value)) {
  3228. throw new InvalidConfigurationException(sprintf('Expected boolean or string value for option "%s".', $optionName));
  3229. }
  3230. if ('yes' === $value) {
  3231. return true;
  3232. }
  3233. if ('no' === $value) {
  3234. return false;
  3235. }
  3236. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  3237. throw new InvalidConfigurationException(sprintf('Expected "yes" or "no" for option "%s", got "%s". This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.', $optionName, $value));
  3238. }
  3239. @trigger_error(
  3240. sprintf('Expected "yes" or "no" for option "%s", other values are deprecated and support will be removed in 3.0. Got "%s", this implicitly set the option to "false".', $optionName, $value),
  3241. E_USER_DEPRECATED
  3242. );
  3243. return false;
  3244. }
  3245. private static function separatedContextLessInclude($path)
  3246. {
  3247. return include $path;
  3248. }
  3249. }
  3250. <?php
  3251. namespace PhpCsFixer\Console\Output;
  3252. use PhpCsFixer\Error\Error;
  3253. use PhpCsFixer\Linter\LintingException;
  3254. use Symfony\Component\Console\Formatter\OutputFormatter;
  3255. use Symfony\Component\Console\Output\OutputInterface;
  3256. final class ErrorOutput
  3257. {
  3258. private $output;
  3259. private $isDecorated;
  3260. public function __construct(OutputInterface $output)
  3261. {
  3262. $this->output = $output;
  3263. $this->isDecorated = $output->isDecorated();
  3264. }
  3265. public function listErrors($process, array $errors)
  3266. {
  3267. $this->output->writeln(['', sprintf(
  3268. 'Files that were not fixed due to errors reported during %s:',
  3269. $process
  3270. )]);
  3271. $showDetails = $this->output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE;
  3272. $showTrace = $this->output->getVerbosity() >= OutputInterface::VERBOSITY_DEBUG;
  3273. foreach ($errors as $i => $error) {
  3274. $this->output->writeln(sprintf('%4d) %s', $i + 1, $error->getFilePath()));
  3275. if ($showDetails) {
  3276. $e = $error->getSource();
  3277. if (null !== $e) {
  3278. $class = sprintf('[%s]', get_class($e));
  3279. $message = $e->getMessage();
  3280. $code = $e->getCode();
  3281. if (0 !== $code) {
  3282. $message .= " (${code})";
  3283. }
  3284. $length = max(strlen($class), strlen($message));
  3285. $lines = [
  3286. '',
  3287. $class,
  3288. $message,
  3289. '',
  3290. ];
  3291. $this->output->writeln('');
  3292. foreach ($lines as $line) {
  3293. if (strlen($line) < $length) {
  3294. $line .= str_repeat(' ', $length - strlen($line));
  3295. }
  3296. $this->output->writeln(sprintf(' <error> %s </error>', $this->prepareOutput($line)));
  3297. }
  3298. if ($showTrace && !$e instanceof LintingException) {
  3299. $this->output->writeln('');
  3300. $stackTrace = $e->getTrace();
  3301. foreach ($stackTrace as $trace) {
  3302. if (isset($trace['class'], $trace['function']) && \Symfony\Component\Console\Command\Command::class === $trace['class'] && 'run' === $trace['function']) {
  3303. $this->output->writeln(' [ ... ]');
  3304. break;
  3305. }
  3306. $this->outputTrace($trace);
  3307. }
  3308. }
  3309. }
  3310. }
  3311. }
  3312. }
  3313. private function outputTrace(array $trace)
  3314. {
  3315. if (isset($trace['class'], $trace['type'], $trace['function'])) {
  3316. $this->output->writeln(sprintf(
  3317. ' <comment>%s</comment>%s<comment>%s()</comment>',
  3318. $this->prepareOutput($trace['class']),
  3319. $this->prepareOutput($trace['type']),
  3320. $this->prepareOutput($trace['function'])
  3321. ));
  3322. } elseif (isset($trace['function'])) {
  3323. $this->output->writeln(sprintf(' <comment>%s()</comment>', $this->prepareOutput($trace['function'])));
  3324. }
  3325. if (isset($trace['file'])) {
  3326. $this->output->writeln(sprintf(' in <info>%s</info> at line <info>%d</info>', $this->prepareOutput($trace['file']), $trace['line']));
  3327. }
  3328. }
  3329. private function prepareOutput($string)
  3330. {
  3331. return $this->isDecorated
  3332. ? OutputFormatter::escape($string)
  3333. : $string
  3334. ;
  3335. }
  3336. }
  3337. <?php
  3338. namespace PhpCsFixer\Console\Output;
  3339. final class NullOutput implements ProcessOutputInterface
  3340. {
  3341. public function printLegend()
  3342. {
  3343. }
  3344. }
  3345. <?php
  3346. namespace PhpCsFixer\Console\Output;
  3347. use PhpCsFixer\FixerFileProcessedEvent;
  3348. use Symfony\Component\Console\Output\OutputInterface;
  3349. use Symfony\Component\EventDispatcher\EventDispatcher;
  3350. final class ProcessOutput implements ProcessOutputInterface
  3351. {
  3352. private static $eventStatusMap = [
  3353. FixerFileProcessedEvent::STATUS_UNKNOWN => ['symbol' => '?', 'format' => '%s', 'description' => 'unknown'],
  3354. FixerFileProcessedEvent::STATUS_INVALID => ['symbol' => 'I', 'format' => '<bg=red>%s</bg=red>', 'description' => 'invalid file syntax, file ignored'],
  3355. FixerFileProcessedEvent::STATUS_SKIPPED => ['symbol' => 'S', 'format' => '<fg=cyan>%s</fg=cyan>', 'description' => 'Skipped'],
  3356. FixerFileProcessedEvent::STATUS_NO_CHANGES => ['symbol' => '.', 'format' => '%s', 'description' => 'no changes'],
  3357. FixerFileProcessedEvent::STATUS_FIXED => ['symbol' => 'F', 'format' => '<fg=green>%s</fg=green>', 'description' => 'fixed'],
  3358. FixerFileProcessedEvent::STATUS_EXCEPTION => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
  3359. FixerFileProcessedEvent::STATUS_LINT => ['symbol' => 'E', 'format' => '<bg=red>%s</bg=red>', 'description' => 'error'],
  3360. ];
  3361. private $eventDispatcher;
  3362. private $output;
  3363. private $files;
  3364. private $processedFiles = 0;
  3365. private $symbolsPerLine;
  3366. public function __construct(OutputInterface $output, EventDispatcher $dispatcher, $width, $nbFiles)
  3367. {
  3368. $this->output = $output;
  3369. $this->eventDispatcher = $dispatcher;
  3370. $this->eventDispatcher->addListener(FixerFileProcessedEvent::NAME, [$this, 'onFixerFileProcessed']);
  3371. $this->symbolsPerLine = $width;
  3372. if (null !== $nbFiles) {
  3373. $this->files = $nbFiles;
  3374. $this->symbolsPerLine = max(1, ($width ?: 80) - strlen((string) $this->files) * 2 - 11);
  3375. }
  3376. }
  3377. public function __destruct()
  3378. {
  3379. $this->eventDispatcher->removeListener(FixerFileProcessedEvent::NAME, [$this, 'onFixerFileProcessed']);
  3380. }
  3381. public function onFixerFileProcessed(FixerFileProcessedEvent $event)
  3382. {
  3383. if (
  3384. null === $this->files
  3385. && null !== $this->symbolsPerLine
  3386. && 0 === $this->processedFiles % $this->symbolsPerLine
  3387. && 0 !== $this->processedFiles
  3388. ) {
  3389. $this->output->writeln('');
  3390. }
  3391. $status = self::$eventStatusMap[$event->getStatus()];
  3392. $this->output->write($this->output->isDecorated() ? sprintf($status['format'], $status['symbol']) : $status['symbol']);
  3393. ++$this->processedFiles;
  3394. if (null !== $this->files) {
  3395. $symbolsOnCurrentLine = $this->processedFiles % $this->symbolsPerLine;
  3396. $isLast = $this->processedFiles === $this->files;
  3397. if (0 === $symbolsOnCurrentLine || $isLast) {
  3398. $this->output->write(sprintf(
  3399. '%s %'.strlen((string) $this->files).'d / %d (%3d%%)',
  3400. $isLast && 0 !== $symbolsOnCurrentLine ? str_repeat(' ', $this->symbolsPerLine - $symbolsOnCurrentLine) : '',
  3401. $this->processedFiles,
  3402. $this->files,
  3403. round($this->processedFiles / $this->files * 100)
  3404. ));
  3405. if (!$isLast) {
  3406. $this->output->writeln('');
  3407. }
  3408. }
  3409. }
  3410. }
  3411. public function printLegend()
  3412. {
  3413. $symbols = [];
  3414. foreach (self::$eventStatusMap as $status) {
  3415. $symbol = $status['symbol'];
  3416. if ('' === $symbol || isset($symbols[$symbol])) {
  3417. continue;
  3418. }
  3419. $symbols[$symbol] = sprintf('%s-%s', $this->output->isDecorated() ? sprintf($status['format'], $symbol) : $symbol, $status['description']);
  3420. }
  3421. $this->output->write(sprintf("\nLegend: %s\n", implode(', ', $symbols)));
  3422. }
  3423. }
  3424. <?php
  3425. namespace PhpCsFixer\Console\Output;
  3426. interface ProcessOutputInterface
  3427. {
  3428. public function printLegend();
  3429. }
  3430. <?php
  3431. namespace PhpCsFixer\Console\SelfUpdate;
  3432. final class GithubClient implements GithubClientInterface
  3433. {
  3434. public function getTags()
  3435. {
  3436. $url = 'https://api.github.com/repos/FriendsOfPHP/PHP-CS-Fixer/tags';
  3437. $result = @file_get_contents(
  3438. $url,
  3439. false,
  3440. stream_context_create([
  3441. 'http' => [
  3442. 'header' => 'User-Agent: FriendsOfPHP/PHP-CS-Fixer',
  3443. ],
  3444. ])
  3445. );
  3446. if (false === $result) {
  3447. throw new \RuntimeException(sprintf('Failed to load tags at "%s".', $url));
  3448. }
  3449. $result = json_decode($result, true);
  3450. if (JSON_ERROR_NONE !== json_last_error()) {
  3451. throw new \RuntimeException(sprintf(
  3452. 'Failed to read response from "%s" as JSON: %s.',
  3453. $url,
  3454. json_last_error_msg()
  3455. ));
  3456. }
  3457. return $result;
  3458. }
  3459. }
  3460. <?php
  3461. namespace PhpCsFixer\Console\SelfUpdate;
  3462. interface GithubClientInterface
  3463. {
  3464. public function getTags();
  3465. }
  3466. <?php
  3467. namespace PhpCsFixer\Console\SelfUpdate;
  3468. use Composer\Semver\Comparator;
  3469. use Composer\Semver\Semver;
  3470. use Composer\Semver\VersionParser;
  3471. final class NewVersionChecker implements NewVersionCheckerInterface
  3472. {
  3473. private $githubClient;
  3474. private $versionParser;
  3475. private $availableVersions;
  3476. public function __construct(GithubClientInterface $githubClient)
  3477. {
  3478. $this->githubClient = $githubClient;
  3479. $this->versionParser = new VersionParser();
  3480. }
  3481. public function getLatestVersion()
  3482. {
  3483. $this->retrieveAvailableVersions();
  3484. return $this->availableVersions[0];
  3485. }
  3486. public function getLatestVersionOfMajor($majorVersion)
  3487. {
  3488. $this->retrieveAvailableVersions();
  3489. $semverConstraint = '^'.$majorVersion;
  3490. foreach ($this->availableVersions as $availableVersion) {
  3491. if (Semver::satisfies($availableVersion, $semverConstraint)) {
  3492. return $availableVersion;
  3493. }
  3494. }
  3495. return null;
  3496. }
  3497. public function compareVersions($versionA, $versionB)
  3498. {
  3499. $versionA = $this->versionParser->normalize($versionA);
  3500. $versionB = $this->versionParser->normalize($versionB);
  3501. if (Comparator::lessThan($versionA, $versionB)) {
  3502. return -1;
  3503. }
  3504. if (Comparator::greaterThan($versionA, $versionB)) {
  3505. return 1;
  3506. }
  3507. return 0;
  3508. }
  3509. private function retrieveAvailableVersions()
  3510. {
  3511. if (null !== $this->availableVersions) {
  3512. return;
  3513. }
  3514. foreach ($this->githubClient->getTags() as $tag) {
  3515. $version = $tag['name'];
  3516. try {
  3517. $this->versionParser->normalize($version);
  3518. if ('stable' === VersionParser::parseStability($version)) {
  3519. $this->availableVersions[] = $version;
  3520. }
  3521. } catch (\UnexpectedValueException $exception) {
  3522. }
  3523. }
  3524. $this->availableVersions = Semver::rsort($this->availableVersions);
  3525. }
  3526. }
  3527. <?php
  3528. namespace PhpCsFixer\Console\SelfUpdate;
  3529. interface NewVersionCheckerInterface
  3530. {
  3531. public function getLatestVersion();
  3532. public function getLatestVersionOfMajor($majorVersion);
  3533. public function compareVersions($versionA, $versionB);
  3534. }
  3535. <?php
  3536. namespace PhpCsFixer\Console;
  3537. use PhpCsFixer\ToolInfo;
  3538. use PhpCsFixer\ToolInfoInterface;
  3539. final class WarningsDetector
  3540. {
  3541. private $toolInfo;
  3542. private $warnings = [];
  3543. public function __construct(ToolInfoInterface $toolInfo)
  3544. {
  3545. $this->toolInfo = $toolInfo;
  3546. }
  3547. public function detectOldMajor()
  3548. {
  3549. }
  3550. public function detectOldVendor()
  3551. {
  3552. if ($this->toolInfo->isInstalledByComposer()) {
  3553. $details = $this->toolInfo->getComposerInstallationDetails();
  3554. if (ToolInfo::COMPOSER_LEGACY_PACKAGE_NAME === $details['name']) {
  3555. $this->warnings[] = sprintf(
  3556. 'You are running PHP CS Fixer installed with old vendor `%s`. Please update to `%s`.',
  3557. ToolInfo::COMPOSER_LEGACY_PACKAGE_NAME,
  3558. ToolInfo::COMPOSER_PACKAGE_NAME
  3559. );
  3560. }
  3561. }
  3562. }
  3563. public function detectXdebug()
  3564. {
  3565. if (extension_loaded('xdebug')) {
  3566. $this->warnings[] = 'You are running PHP CS Fixer with xdebug enabled. This has a major impact on runtime performance.';
  3567. }
  3568. }
  3569. public function getWarnings()
  3570. {
  3571. if (!count($this->warnings)) {
  3572. return [];
  3573. }
  3574. return array_unique(array_merge(
  3575. $this->warnings,
  3576. ['If you need help while solving warnings, ask at https://gitter.im/PHP-CS-Fixer, we will help you!']
  3577. ));
  3578. }
  3579. }
  3580. <?php
  3581. namespace PhpCsFixer\Differ;
  3582. use Symfony\Component\Console\Formatter\OutputFormatter;
  3583. final class DiffConsoleFormatter
  3584. {
  3585. private $isDecoratedOutput;
  3586. private $template;
  3587. public function __construct($isDecoratedOutput, $template = '%s')
  3588. {
  3589. $this->isDecoratedOutput = $isDecoratedOutput;
  3590. $this->template = $template;
  3591. }
  3592. public function format($diff, $lineTemplate = '%s')
  3593. {
  3594. $isDecorated = $this->isDecoratedOutput;
  3595. $template = $isDecorated
  3596. ? $this->template
  3597. : preg_replace('/<[^<>]+>/', '', $this->template)
  3598. ;
  3599. return sprintf(
  3600. $template,
  3601. implode(
  3602. PHP_EOL,
  3603. array_map(
  3604. function ($string) use ($isDecorated, $lineTemplate) {
  3605. if ($isDecorated) {
  3606. $string = preg_replace_callback(
  3607. [
  3608. '/^(\+.*)/',
  3609. '/^(\-.*)/',
  3610. '/^(@.*)/',
  3611. ],
  3612. function ($matches) {
  3613. if ('+' === $matches[0][0]) {
  3614. $colour = 'green';
  3615. } elseif ('-' === $matches[0][0]) {
  3616. $colour = 'red';
  3617. } else {
  3618. $colour = 'cyan';
  3619. }
  3620. return sprintf('<fg=%s>%s</fg=%s>', $colour, OutputFormatter::escape($matches[0]), $colour);
  3621. },
  3622. $string
  3623. );
  3624. }
  3625. return sprintf($lineTemplate, $string);
  3626. },
  3627. preg_split('#\R#u', $diff)
  3628. )
  3629. )
  3630. );
  3631. }
  3632. }
  3633. <?php
  3634. namespace PhpCsFixer\Differ;
  3635. interface DifferInterface
  3636. {
  3637. public function diff($old, $new);
  3638. }
  3639. <?php
  3640. namespace PhpCsFixer\Differ;
  3641. final class NullDiffer implements DifferInterface
  3642. {
  3643. public function diff($old, $new)
  3644. {
  3645. return '';
  3646. }
  3647. }
  3648. <?php
  3649. namespace PhpCsFixer\Differ;
  3650. use PhpCsFixer\Diff\v1_4\Differ;
  3651. final class SebastianBergmannDiffer implements DifferInterface
  3652. {
  3653. private $differ;
  3654. public function __construct()
  3655. {
  3656. $this->differ = new Differ();
  3657. }
  3658. public function diff($old, $new)
  3659. {
  3660. return $this->differ->diff($old, $new);
  3661. }
  3662. }
  3663. <?php
  3664. namespace PhpCsFixer\Differ;
  3665. use PhpCsFixer\Diff\v1_4\Differ;
  3666. final class SebastianBergmannShortDiffer implements DifferInterface
  3667. {
  3668. private $differ;
  3669. public function __construct()
  3670. {
  3671. $this->differ = new Differ("--- Original\n+++ New\n", false);
  3672. }
  3673. public function diff($old, $new)
  3674. {
  3675. return $this->differ->diff($old, $new);
  3676. }
  3677. }
  3678. <?php
  3679. namespace PhpCsFixer\Differ;
  3680. use PhpCsFixer\Diff\GeckoPackages\DiffOutputBuilder\UnifiedDiffOutputBuilder;
  3681. use PhpCsFixer\Diff\v2_0\Differ;
  3682. final class UnifiedDiffer implements DifferInterface
  3683. {
  3684. private $differ;
  3685. public function __construct()
  3686. {
  3687. $this->differ = new Differ(new UnifiedDiffOutputBuilder([
  3688. 'fromFile' => 'Original',
  3689. 'toFile' => 'New',
  3690. ]));
  3691. }
  3692. public function diff($old, $new)
  3693. {
  3694. return $this->differ->diff($old, $new);
  3695. }
  3696. }
  3697. <?php
  3698. namespace PhpCsFixer\DocBlock;
  3699. class Annotation
  3700. {
  3701. const REGEX_TYPES = '
  3702. # <simple> is any non-array, non-generic, non-alternated type, eg `int` or `\Foo`
  3703. # <array> is array of <simple>, eg `int[]` or `\Foo[]`
  3704. # <generic> is generic collection type, like `array<string, int>`, `Collection<Item>` and more complex like `Collection<int, \null|SubCollection<string>>`
  3705. # <type> is <simple>, <array> or <generic> type, like `int`, `bool[]` or `Collection<ItemKey, ItemVal>`
  3706. # <types> is one or more types alternated via `|`, like `int|bool[]|Collection<ItemKey, ItemVal>`
  3707. (?<types>
  3708. (?<type>
  3709. (?<array>
  3710. (?&simple)\[\]
  3711. )
  3712. |
  3713. (?<simple>
  3714. [@$?]?[\\\\\w]+
  3715. )
  3716. |
  3717. (?<generic>
  3718. (?&simple)
  3719. <
  3720. (?:(?&types),\s*)?(?:(?&types)|(?&generic))
  3721. >
  3722. )
  3723. )
  3724. (?:
  3725. \|
  3726. (?:(?&simple)|(?&array)|(?&generic))
  3727. )*
  3728. )
  3729. ';
  3730. private static $tags = [
  3731. 'method',
  3732. 'param',
  3733. 'property',
  3734. 'property-read',
  3735. 'property-write',
  3736. 'return',
  3737. 'throws',
  3738. 'type',
  3739. 'var',
  3740. ];
  3741. private $lines;
  3742. private $start;
  3743. private $end;
  3744. private $tag;
  3745. private $typesContent;
  3746. private $types;
  3747. public function __construct(array $lines)
  3748. {
  3749. $this->lines = array_values($lines);
  3750. $keys = array_keys($lines);
  3751. $this->start = $keys[0];
  3752. $this->end = end($keys);
  3753. }
  3754. public function __toString()
  3755. {
  3756. return $this->getContent();
  3757. }
  3758. public static function getTagsWithTypes()
  3759. {
  3760. return self::$tags;
  3761. }
  3762. public function getStart()
  3763. {
  3764. return $this->start;
  3765. }
  3766. public function getEnd()
  3767. {
  3768. return $this->end;
  3769. }
  3770. public function getTag()
  3771. {
  3772. if (null === $this->tag) {
  3773. $this->tag = new Tag($this->lines[0]);
  3774. }
  3775. return $this->tag;
  3776. }
  3777. public function getTypes()
  3778. {
  3779. if (null === $this->types) {
  3780. $this->types = [];
  3781. $content = $this->getTypesContent();
  3782. while ('' !== $content && false !== $content) {
  3783. preg_match(
  3784. '{^'.self::REGEX_TYPES.'$}x',
  3785. $content,
  3786. $matches
  3787. );
  3788. $this->types[] = $matches['type'];
  3789. $content = substr($content, strlen($matches['type']) + 1);
  3790. }
  3791. }
  3792. return $this->types;
  3793. }
  3794. public function setTypes(array $types)
  3795. {
  3796. $pattern = '/'.preg_quote($this->getTypesContent(), '/').'/';
  3797. $this->lines[0]->setContent(preg_replace($pattern, implode('|', $types), $this->lines[0]->getContent(), 1));
  3798. $this->clearCache();
  3799. }
  3800. public function remove()
  3801. {
  3802. foreach ($this->lines as $line) {
  3803. $line->remove();
  3804. }
  3805. $this->clearCache();
  3806. }
  3807. public function getContent()
  3808. {
  3809. return implode($this->lines);
  3810. }
  3811. public function supportTypes()
  3812. {
  3813. return in_array($this->getTag()->getName(), self::$tags, true);
  3814. }
  3815. private function getTypesContent()
  3816. {
  3817. if (null === $this->typesContent) {
  3818. $name = $this->getTag()->getName();
  3819. if (!$this->supportTypes()) {
  3820. throw new \RuntimeException('This tag does not support types.');
  3821. }
  3822. $matchingResult = preg_match(
  3823. '{^(?:\s*\*|/\*\*)\s*@'.$name.'\s+'.self::REGEX_TYPES.'(?:[ \t].*)?$}sx',
  3824. $this->lines[0]->getContent(),
  3825. $matches
  3826. );
  3827. $this->typesContent = 1 === $matchingResult
  3828. ? $matches['types']
  3829. : '';
  3830. }
  3831. return $this->typesContent;
  3832. }
  3833. private function clearCache()
  3834. {
  3835. $this->types = null;
  3836. $this->typesContent = null;
  3837. }
  3838. }
  3839. <?php
  3840. namespace PhpCsFixer\DocBlock;
  3841. use PhpCsFixer\Utils;
  3842. class DocBlock
  3843. {
  3844. private $lines = [];
  3845. private $annotations;
  3846. public function __construct($content)
  3847. {
  3848. foreach (Utils::splitLines($content) as $line) {
  3849. $this->lines[] = new Line($line);
  3850. }
  3851. }
  3852. public function __toString()
  3853. {
  3854. return $this->getContent();
  3855. }
  3856. public function getLines()
  3857. {
  3858. return $this->lines;
  3859. }
  3860. public function getLine($pos)
  3861. {
  3862. if (isset($this->lines[$pos])) {
  3863. return $this->lines[$pos];
  3864. }
  3865. }
  3866. public function getAnnotations()
  3867. {
  3868. if (null === $this->annotations) {
  3869. $this->annotations = [];
  3870. $total = count($this->lines);
  3871. for ($index = 0; $index < $total; ++$index) {
  3872. if ($this->lines[$index]->containsATag()) {
  3873. $lines = array_slice($this->lines, $index, $this->findAnnotationLength($index), true);
  3874. $annotation = new Annotation($lines);
  3875. $index = $annotation->getEnd();
  3876. $this->annotations[] = $annotation;
  3877. }
  3878. }
  3879. }
  3880. return $this->annotations;
  3881. }
  3882. public function getAnnotation($pos)
  3883. {
  3884. $annotations = $this->getAnnotations();
  3885. if (isset($annotations[$pos])) {
  3886. return $annotations[$pos];
  3887. }
  3888. }
  3889. public function getAnnotationsOfType($types)
  3890. {
  3891. $annotations = [];
  3892. $types = (array) $types;
  3893. foreach ($this->getAnnotations() as $annotation) {
  3894. $tag = $annotation->getTag()->getName();
  3895. foreach ($types as $type) {
  3896. if ($type === $tag) {
  3897. $annotations[] = $annotation;
  3898. }
  3899. }
  3900. }
  3901. return $annotations;
  3902. }
  3903. public function getContent()
  3904. {
  3905. return implode($this->lines);
  3906. }
  3907. private function findAnnotationLength($start)
  3908. {
  3909. $index = $start;
  3910. while ($line = $this->getLine(++$index)) {
  3911. if ($line->containsATag()) {
  3912. break;
  3913. }
  3914. if (!$line->containsUsefulContent()) {
  3915. $next = $this->getLine($index + 1);
  3916. if (null === $next || !$next->containsUsefulContent() || $next->containsATag()) {
  3917. break;
  3918. }
  3919. }
  3920. }
  3921. return $index - $start;
  3922. }
  3923. }
  3924. <?php
  3925. namespace PhpCsFixer\DocBlock;
  3926. class Line
  3927. {
  3928. private $content;
  3929. public function __construct($content)
  3930. {
  3931. $this->content = $content;
  3932. }
  3933. public function __toString()
  3934. {
  3935. return $this->content;
  3936. }
  3937. public function getContent()
  3938. {
  3939. return $this->content;
  3940. }
  3941. public function containsUsefulContent()
  3942. {
  3943. return 0 !== preg_match('/\\*\s*\S+/', $this->content) && !$this->isTheStart() && !$this->isTheEnd();
  3944. }
  3945. public function containsATag()
  3946. {
  3947. return 0 !== preg_match('/\\*\s*@/', $this->content);
  3948. }
  3949. public function isTheStart()
  3950. {
  3951. return false !== strpos($this->content, '/**');
  3952. }
  3953. public function isTheEnd()
  3954. {
  3955. return false !== strpos($this->content, '*/');
  3956. }
  3957. public function setContent($content)
  3958. {
  3959. $this->content = $content;
  3960. }
  3961. public function remove()
  3962. {
  3963. $this->content = '';
  3964. }
  3965. public function addBlank()
  3966. {
  3967. $matched = preg_match('/^([ \t]*\*)[^\r\n]*(\r?\n)$/', $this->content, $matches);
  3968. if (1 !== $matched) {
  3969. return;
  3970. }
  3971. $this->content .= $matches[1].$matches[2];
  3972. }
  3973. }
  3974. <?php
  3975. namespace PhpCsFixer\DocBlock;
  3976. class Tag
  3977. {
  3978. private static $tags = [
  3979. 'api', 'author', 'category', 'copyright', 'deprecated', 'example',
  3980. 'global', 'internal', 'license', 'link', 'method', 'package', 'param',
  3981. 'property', 'property-read', 'property-write', 'return', 'see',
  3982. 'since', 'subpackage', 'throws', 'todo', 'uses', 'var', 'version',
  3983. ];
  3984. private $line;
  3985. private $name;
  3986. public function __construct(Line $line)
  3987. {
  3988. $this->line = $line;
  3989. }
  3990. public function getName()
  3991. {
  3992. if (null === $this->name) {
  3993. preg_match_all('/@[a-zA-Z0-9_-]+(?=\s|$)/', $this->line->getContent(), $matches);
  3994. if (isset($matches[0][0])) {
  3995. $this->name = ltrim($matches[0][0], '@');
  3996. } else {
  3997. $this->name = 'other';
  3998. }
  3999. }
  4000. return $this->name;
  4001. }
  4002. public function setName($name)
  4003. {
  4004. $current = $this->getName();
  4005. if ('other' === $current) {
  4006. throw new \RuntimeException('Cannot set name on unknown tag.');
  4007. }
  4008. $this->line->setContent(preg_replace("/@${current}/", "@${name}", $this->line->getContent(), 1));
  4009. $this->name = $name;
  4010. }
  4011. public function valid()
  4012. {
  4013. return in_array($this->getName(), self::$tags, true);
  4014. }
  4015. }
  4016. <?php
  4017. namespace PhpCsFixer\DocBlock;
  4018. class TagComparator
  4019. {
  4020. private static $groups = [
  4021. ['deprecated', 'link', 'see', 'since'],
  4022. ['author', 'copyright', 'license'],
  4023. ['category', 'package', 'subpackage'],
  4024. ['property', 'property-read', 'property-write'],
  4025. ];
  4026. public static function shouldBeTogether(Tag $first, Tag $second)
  4027. {
  4028. $firstName = $first->getName();
  4029. $secondName = $second->getName();
  4030. if ($firstName === $secondName) {
  4031. return true;
  4032. }
  4033. foreach (self::$groups as $group) {
  4034. if (in_array($firstName, $group, true) && in_array($secondName, $group, true)) {
  4035. return true;
  4036. }
  4037. }
  4038. return false;
  4039. }
  4040. }
  4041. <?php
  4042. namespace PhpCsFixer\Doctrine\Annotation;
  4043. use Doctrine\Common\Annotations\DocLexer;
  4044. final class Token
  4045. {
  4046. private $type;
  4047. private $content;
  4048. public function __construct($type = DocLexer::T_NONE, $content = '')
  4049. {
  4050. $this->type = $type;
  4051. $this->content = $content;
  4052. }
  4053. public function getType()
  4054. {
  4055. return $this->type;
  4056. }
  4057. public function setType($type)
  4058. {
  4059. $this->type = $type;
  4060. }
  4061. public function getContent()
  4062. {
  4063. return $this->content;
  4064. }
  4065. public function setContent($content)
  4066. {
  4067. $this->content = $content;
  4068. }
  4069. public function isType($types)
  4070. {
  4071. if (!is_array($types)) {
  4072. $types = [$types];
  4073. }
  4074. return in_array($this->getType(), $types, true);
  4075. }
  4076. public function clear()
  4077. {
  4078. $this->setContent('');
  4079. }
  4080. }
  4081. <?php
  4082. namespace PhpCsFixer\Doctrine\Annotation;
  4083. use Doctrine\Common\Annotations\DocLexer;
  4084. use PhpCsFixer\Tokenizer\Token as PhpToken;
  4085. final class Tokens extends \SplFixedArray
  4086. {
  4087. public static function createFromDocComment(PhpToken $input, array $ignoredTags = [])
  4088. {
  4089. if (!$input->isGivenKind(T_DOC_COMMENT)) {
  4090. throw new \InvalidArgumentException('Input must be a T_DOC_COMMENT token.');
  4091. }
  4092. $tokens = new self();
  4093. $content = $input->getContent();
  4094. $ignoredTextPosition = 0;
  4095. $currentPosition = 0;
  4096. while (false !== $nextAtPosition = strpos($content, '@', $currentPosition)) {
  4097. if (0 !== $nextAtPosition && !preg_match('/\s/', $content[$nextAtPosition - 1])) {
  4098. $currentPosition = $nextAtPosition + 1;
  4099. continue;
  4100. }
  4101. $lexer = new DocLexer();
  4102. $lexer->setInput(substr($content, $nextAtPosition));
  4103. $scannedTokens = [];
  4104. $index = 0;
  4105. $nbScannedTokensToUse = 0;
  4106. $nbScopes = 0;
  4107. while (null !== $token = $lexer->peek()) {
  4108. if (0 === $index && DocLexer::T_AT !== $token['type']) {
  4109. break;
  4110. }
  4111. if (1 === $index) {
  4112. if (DocLexer::T_IDENTIFIER !== $token['type'] || in_array($token['value'], $ignoredTags, true)) {
  4113. break;
  4114. }
  4115. $nbScannedTokensToUse = 2;
  4116. }
  4117. if ($index >= 2 && 0 === $nbScopes && !in_array($token['type'], [DocLexer::T_NONE, DocLexer::T_OPEN_PARENTHESIS], true)) {
  4118. break;
  4119. }
  4120. $scannedTokens[] = $token;
  4121. if (DocLexer::T_OPEN_PARENTHESIS === $token['type']) {
  4122. ++$nbScopes;
  4123. } elseif (DocLexer::T_CLOSE_PARENTHESIS === $token['type']) {
  4124. if (0 === --$nbScopes) {
  4125. $nbScannedTokensToUse = count($scannedTokens);
  4126. break;
  4127. }
  4128. }
  4129. ++$index;
  4130. }
  4131. if (0 !== $nbScopes) {
  4132. break;
  4133. }
  4134. if (0 !== $nbScannedTokensToUse) {
  4135. $ignoredTextLength = $nextAtPosition - $ignoredTextPosition;
  4136. if (0 !== $ignoredTextLength) {
  4137. $tokens[] = new Token(DocLexer::T_NONE, substr($content, $ignoredTextPosition, $ignoredTextLength));
  4138. }
  4139. $lastTokenEndIndex = 0;
  4140. foreach (array_slice($scannedTokens, 0, $nbScannedTokensToUse) as $token) {
  4141. if (DocLexer::T_STRING === $token['type']) {
  4142. $token['value'] = '"'.str_replace('"', '""', $token['value']).'"';
  4143. }
  4144. $missingTextLength = $token['position'] - $lastTokenEndIndex;
  4145. if ($missingTextLength > 0) {
  4146. $tokens[] = new Token(DocLexer::T_NONE, substr(
  4147. $content,
  4148. $nextAtPosition + $lastTokenEndIndex,
  4149. $missingTextLength
  4150. ));
  4151. }
  4152. $tokens[] = new Token($token['type'], $token['value']);
  4153. $lastTokenEndIndex = $token['position'] + strlen($token['value']);
  4154. }
  4155. $currentPosition = $ignoredTextPosition = $nextAtPosition + $token['position'] + strlen($token['value']);
  4156. } else {
  4157. $currentPosition = $nextAtPosition + 1;
  4158. }
  4159. }
  4160. if ($ignoredTextPosition < strlen($content)) {
  4161. $tokens[] = new Token(DocLexer::T_NONE, substr($content, $ignoredTextPosition));
  4162. }
  4163. return $tokens;
  4164. }
  4165. public function getNextMeaningfulToken($index)
  4166. {
  4167. return $this->getMeaningfulTokenSibling($index, 1);
  4168. }
  4169. public function getPreviousMeaningfulToken($index)
  4170. {
  4171. return $this->getMeaningfulTokenSibling($index, -1);
  4172. }
  4173. public function getNextTokenOfType($type, $index)
  4174. {
  4175. return $this->getTokenOfTypeSibling($index, $type, 1);
  4176. }
  4177. public function getPreviousTokenOfType($type, $index)
  4178. {
  4179. return $this->getTokenOfTypeSibling($index, $type, -1);
  4180. }
  4181. public function getAnnotationEnd($index)
  4182. {
  4183. $currentIndex = null;
  4184. if (isset($this[$index + 2])) {
  4185. if ($this[$index + 2]->isType(DocLexer::T_OPEN_PARENTHESIS)) {
  4186. $currentIndex = $index + 2;
  4187. } elseif (
  4188. isset($this[$index + 3])
  4189. && $this[$index + 2]->isType(DocLexer::T_NONE)
  4190. && $this[$index + 3]->isType(DocLexer::T_OPEN_PARENTHESIS)
  4191. && preg_match('/^(\R\s*\*\s*)*\s*$/', $this[$index + 2]->getContent())
  4192. ) {
  4193. $currentIndex = $index + 3;
  4194. }
  4195. }
  4196. if (null !== $currentIndex) {
  4197. $level = 0;
  4198. for ($max = count($this); $currentIndex < $max; ++$currentIndex) {
  4199. if ($this[$currentIndex]->isType(DocLexer::T_OPEN_PARENTHESIS)) {
  4200. ++$level;
  4201. } elseif ($this[$currentIndex]->isType(DocLexer::T_CLOSE_PARENTHESIS)) {
  4202. --$level;
  4203. }
  4204. if (0 === $level) {
  4205. return $currentIndex;
  4206. }
  4207. }
  4208. return null;
  4209. }
  4210. return $index + 1;
  4211. }
  4212. public function getArrayEnd($index)
  4213. {
  4214. $level = 1;
  4215. for (++$index, $max = count($this); $index < $max; ++$index) {
  4216. if ($this[$index]->isType(DocLexer::T_OPEN_CURLY_BRACES)) {
  4217. ++$level;
  4218. } elseif ($this[$index]->isType($index, DocLexer::T_CLOSE_CURLY_BRACES)) {
  4219. --$level;
  4220. }
  4221. if (0 === $level) {
  4222. return $index;
  4223. }
  4224. }
  4225. return null;
  4226. }
  4227. public function getCode()
  4228. {
  4229. $code = '';
  4230. foreach ($this as $token) {
  4231. $code .= $token->getContent();
  4232. }
  4233. return $code;
  4234. }
  4235. public function insertAt($index, Token $token)
  4236. {
  4237. $this->setSize($this->getSize() + 1);
  4238. for ($i = $this->getSize() - 1; $i > $index; --$i) {
  4239. $this[$i] = isset($this[$i - 1]) ? $this[$i - 1] : new Token();
  4240. }
  4241. $this[$index] = $token;
  4242. }
  4243. public function offsetSet($index, $token)
  4244. {
  4245. if (!$token instanceof Token) {
  4246. $type = gettype($token);
  4247. if ('object' === $type) {
  4248. $type = get_class($token);
  4249. }
  4250. throw new \InvalidArgumentException(sprintf(
  4251. 'Token must be an instance of Symfony\\CS\\Doctrine\\Annotation\\Token, %s given.',
  4252. $type
  4253. ));
  4254. }
  4255. if (null === $index) {
  4256. $index = count($this);
  4257. $this->setSize($this->getSize() + 1);
  4258. }
  4259. parent::offsetSet($index, $token);
  4260. }
  4261. public function offsetUnset($index)
  4262. {
  4263. if (!isset($this[$index])) {
  4264. throw new \OutOfBoundsException(sprintf('Index %s is invalid or does not exist.', $index));
  4265. }
  4266. $max = count($this) - 1;
  4267. while ($index < $max) {
  4268. $this[$index] = $this[$index + 1];
  4269. ++$index;
  4270. }
  4271. parent::offsetUnset($index);
  4272. $this->setSize($max);
  4273. }
  4274. private function getMeaningfulTokenSibling($index, $direction)
  4275. {
  4276. while (true) {
  4277. $index += $direction;
  4278. if (!$this->offsetExists($index)) {
  4279. break;
  4280. }
  4281. if (!$this[$index]->isType(DocLexer::T_NONE)) {
  4282. return $index;
  4283. }
  4284. }
  4285. return null;
  4286. }
  4287. private function getTokenOfTypeSibling($index, $type, $direction)
  4288. {
  4289. while (true) {
  4290. $index += $direction;
  4291. if (!$this->offsetExists($index)) {
  4292. break;
  4293. }
  4294. if ($this[$index]->isType($type)) {
  4295. return $index;
  4296. }
  4297. }
  4298. return null;
  4299. }
  4300. }
  4301. <?php
  4302. namespace PhpCsFixer\Error;
  4303. final class Error
  4304. {
  4305. const TYPE_INVALID = 1;
  4306. const TYPE_EXCEPTION = 2;
  4307. const TYPE_LINT = 3;
  4308. private $type;
  4309. private $filePath;
  4310. private $source;
  4311. public function __construct($type, $filePath, $source = null)
  4312. {
  4313. $this->type = $type;
  4314. $this->filePath = $filePath;
  4315. $this->source = $source;
  4316. }
  4317. public function getFilePath()
  4318. {
  4319. return $this->filePath;
  4320. }
  4321. public function getSource()
  4322. {
  4323. return $this->source;
  4324. }
  4325. public function getType()
  4326. {
  4327. return $this->type;
  4328. }
  4329. }
  4330. <?php
  4331. namespace PhpCsFixer\Error;
  4332. final class ErrorsManager
  4333. {
  4334. private $errors = [];
  4335. public function getInvalidErrors()
  4336. {
  4337. return array_filter($this->errors, static function (Error $error) {
  4338. return Error::TYPE_INVALID === $error->getType();
  4339. });
  4340. }
  4341. public function getExceptionErrors()
  4342. {
  4343. return array_filter($this->errors, static function (Error $error) {
  4344. return Error::TYPE_EXCEPTION === $error->getType();
  4345. });
  4346. }
  4347. public function getLintErrors()
  4348. {
  4349. return array_filter($this->errors, static function (Error $error) {
  4350. return Error::TYPE_LINT === $error->getType();
  4351. });
  4352. }
  4353. public function isEmpty()
  4354. {
  4355. return empty($this->errors);
  4356. }
  4357. public function report(Error $error)
  4358. {
  4359. $this->errors[] = $error;
  4360. }
  4361. }
  4362. <?php
  4363. namespace PhpCsFixer;
  4364. final class FileReader
  4365. {
  4366. private static $instance;
  4367. private $stdinContent;
  4368. public static function createSingleton()
  4369. {
  4370. if (null === self::$instance) {
  4371. self::$instance = new self();
  4372. }
  4373. return self::$instance;
  4374. }
  4375. public function read($filePath)
  4376. {
  4377. if ('php://stdin' === $filePath) {
  4378. if (null === $this->stdinContent) {
  4379. $this->stdinContent = $this->readRaw($filePath);
  4380. }
  4381. return $this->stdinContent;
  4382. }
  4383. return $this->readRaw($filePath);
  4384. }
  4385. private function readRaw($realPath)
  4386. {
  4387. return file_get_contents($realPath);
  4388. }
  4389. }
  4390. <?php
  4391. namespace PhpCsFixer;
  4392. final class FileRemoval
  4393. {
  4394. private $files = [];
  4395. public function __construct()
  4396. {
  4397. register_shutdown_function([$this, 'clean']);
  4398. }
  4399. public function __destruct()
  4400. {
  4401. $this->clean();
  4402. }
  4403. public function observe($path)
  4404. {
  4405. $this->files[$path] = true;
  4406. }
  4407. public function delete($path)
  4408. {
  4409. if (isset($this->files[$path])) {
  4410. unset($this->files[$path]);
  4411. }
  4412. $this->unlink($path);
  4413. }
  4414. public function clean()
  4415. {
  4416. foreach ($this->files as $file => $value) {
  4417. $this->unlink($file);
  4418. }
  4419. $this->files = [];
  4420. }
  4421. private function unlink($path)
  4422. {
  4423. @unlink($path);
  4424. }
  4425. }
  4426. <?php
  4427. namespace PhpCsFixer;
  4428. use Symfony\Component\Finder\Finder as BaseFinder;
  4429. class Finder extends BaseFinder
  4430. {
  4431. public function __construct()
  4432. {
  4433. parent::__construct();
  4434. $this
  4435. ->files()
  4436. ->name('*.php')
  4437. ->name('*.phpt')
  4438. ->ignoreDotFiles(true)
  4439. ->ignoreVCS(true)
  4440. ->exclude('vendor')
  4441. ;
  4442. }
  4443. }
  4444. <?php
  4445. namespace PhpCsFixer\Fixer\Alias;
  4446. use PhpCsFixer\AbstractFixer;
  4447. use PhpCsFixer\FixerDefinition\CodeSample;
  4448. use PhpCsFixer\FixerDefinition\FixerDefinition;
  4449. use PhpCsFixer\Tokenizer\Token;
  4450. use PhpCsFixer\Tokenizer\Tokens;
  4451. final class BacktickToShellExecFixer extends AbstractFixer
  4452. {
  4453. public function isCandidate(Tokens $tokens)
  4454. {
  4455. return $tokens->isTokenKindFound('`');
  4456. }
  4457. public function getDefinition()
  4458. {
  4459. return new FixerDefinition(
  4460. 'Converts backtick operators to shell_exec calls.',
  4461. [
  4462. new CodeSample(
  4463. <<<'EOT'
  4464. <?php
  4465. $plain = `ls -lah`;
  4466. $withVar = `ls -lah $var1 ${var2} {$var3} {$var4[0]} {$var5->call()}`;
  4467. EOT
  4468. ),
  4469. ],
  4470. 'Convertion is done only when it is non risky, so when special chars like single-quotes, double-quotes and backticks are not used inside the command.'
  4471. );
  4472. }
  4473. public function getPriority()
  4474. {
  4475. return 2;
  4476. }
  4477. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  4478. {
  4479. $backtickStarted = false;
  4480. $backtickTokens = [];
  4481. for ($index = $tokens->count() - 1; $index > 0; --$index) {
  4482. $token = $tokens[$index];
  4483. if (!$token->equals('`')) {
  4484. if ($backtickStarted) {
  4485. $backtickTokens[$index] = $token;
  4486. }
  4487. continue;
  4488. }
  4489. $backtickTokens[$index] = $token;
  4490. if ($backtickStarted) {
  4491. $this->fixBackticks($tokens, $backtickTokens);
  4492. $backtickTokens = [];
  4493. }
  4494. $backtickStarted = !$backtickStarted;
  4495. }
  4496. }
  4497. private function fixBackticks(Tokens $tokens, array $backtickTokens)
  4498. {
  4499. ksort($backtickTokens);
  4500. $openingBacktickIndex = key($backtickTokens);
  4501. end($backtickTokens);
  4502. $closingBacktickIndex = key($backtickTokens);
  4503. array_shift($backtickTokens);
  4504. array_pop($backtickTokens);
  4505. $count = count($backtickTokens);
  4506. $newTokens = [
  4507. new Token([T_STRING, 'shell_exec']),
  4508. new Token('('),
  4509. ];
  4510. if (1 !== $count) {
  4511. $newTokens[] = new Token('"');
  4512. }
  4513. foreach ($backtickTokens as $token) {
  4514. if (!$token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) {
  4515. $newTokens[] = $token;
  4516. continue;
  4517. }
  4518. $content = $token->getContent();
  4519. if (preg_match('/[`"\']/u', $content)) {
  4520. return;
  4521. }
  4522. $kind = T_ENCAPSED_AND_WHITESPACE;
  4523. if (1 === $count) {
  4524. $content = '"'.$content.'"';
  4525. $kind = T_CONSTANT_ENCAPSED_STRING;
  4526. }
  4527. $newTokens[] = new Token([$kind, $content]);
  4528. }
  4529. if (1 !== $count) {
  4530. $newTokens[] = new Token('"');
  4531. }
  4532. $newTokens[] = new Token(')');
  4533. $tokens->overrideRange($openingBacktickIndex, $closingBacktickIndex, $newTokens);
  4534. }
  4535. }
  4536. <?php
  4537. namespace PhpCsFixer\Fixer\Alias;
  4538. use PhpCsFixer\AbstractFixer;
  4539. use PhpCsFixer\FixerDefinition\CodeSample;
  4540. use PhpCsFixer\FixerDefinition\FixerDefinition;
  4541. use PhpCsFixer\Tokenizer\Token;
  4542. use PhpCsFixer\Tokenizer\Tokens;
  4543. use PhpCsFixer\Utils;
  4544. final class EregToPregFixer extends AbstractFixer
  4545. {
  4546. private static $functions = [
  4547. ['ereg', 'preg_match', ''],
  4548. ['eregi', 'preg_match', 'i'],
  4549. ['ereg_replace', 'preg_replace', ''],
  4550. ['eregi_replace', 'preg_replace', 'i'],
  4551. ['split', 'preg_split', ''],
  4552. ['spliti', 'preg_split', 'i'],
  4553. ];
  4554. private static $delimiters = ['/', '#', '!'];
  4555. public function getDefinition()
  4556. {
  4557. return new FixerDefinition(
  4558. 'Replace deprecated `ereg` regular expression functions with preg.',
  4559. [new CodeSample("<?php \$x = ereg('[A-Z]');\n")],
  4560. null,
  4561. 'Risky if the `ereg` function is overridden.'
  4562. );
  4563. }
  4564. public function isCandidate(Tokens $tokens)
  4565. {
  4566. return $tokens->isTokenKindFound(T_STRING);
  4567. }
  4568. public function isRisky()
  4569. {
  4570. return true;
  4571. }
  4572. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  4573. {
  4574. $end = $tokens->count() - 1;
  4575. foreach (self::$functions as $map) {
  4576. $seq = [[T_STRING, $map[0]], '(', [T_CONSTANT_ENCAPSED_STRING]];
  4577. $currIndex = 0;
  4578. while (null !== $currIndex) {
  4579. $match = $tokens->findSequence($seq, $currIndex, $end, false);
  4580. if (null === $match) {
  4581. break;
  4582. }
  4583. $match = array_keys($match);
  4584. $currIndex = $match[2];
  4585. $prev = $tokens->getPrevMeaningfulToken($match[0]);
  4586. if (null === $prev || $tokens[$prev]->isGivenKind([T_OBJECT_OPERATOR, T_DOUBLE_COLON])) {
  4587. continue;
  4588. }
  4589. $next = $tokens->getNextMeaningfulToken($match[2]);
  4590. if (null === $next || !$tokens[$next]->equalsAny([',', ')'])) {
  4591. continue;
  4592. }
  4593. $regexTokenContent = $tokens[$match[2]]->getContent();
  4594. $string = substr($regexTokenContent, 1, -1);
  4595. $quote = $regexTokenContent[0];
  4596. $delim = $this->getBestDelimiter($string);
  4597. $preg = $delim.addcslashes($string, $delim).$delim.'D'.$map[2];
  4598. if (!$this->checkPreg($preg)) {
  4599. continue;
  4600. }
  4601. $tokens[$match[0]] = new Token([T_STRING, $map[1]]);
  4602. $tokens[$match[2]] = new Token([T_CONSTANT_ENCAPSED_STRING, $quote.$preg.$quote]);
  4603. }
  4604. }
  4605. }
  4606. private function checkPreg($pattern)
  4607. {
  4608. return false !== @preg_match($pattern, '');
  4609. }
  4610. private function getBestDelimiter($pattern)
  4611. {
  4612. $delimiters = [];
  4613. foreach (self::$delimiters as $k => $d) {
  4614. if (false === strpos($pattern, $d)) {
  4615. return $d;
  4616. }
  4617. $delimiters[$d] = [substr_count($pattern, $d), $k];
  4618. }
  4619. uasort($delimiters, static function ($a, $b) {
  4620. if ($a[0] === $b[0]) {
  4621. return Utils::cmpInt($a, $b);
  4622. }
  4623. return $a[0] < $b[0] ? -1 : 1;
  4624. });
  4625. return key($delimiters);
  4626. }
  4627. }
  4628. <?php
  4629. namespace PhpCsFixer\Fixer\Alias;
  4630. use PhpCsFixer\AbstractFunctionReferenceFixer;
  4631. use PhpCsFixer\FixerDefinition\CodeSample;
  4632. use PhpCsFixer\FixerDefinition\FixerDefinition;
  4633. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  4634. use PhpCsFixer\Tokenizer\Token;
  4635. use PhpCsFixer\Tokenizer\Tokens;
  4636. final class MbStrFunctionsFixer extends AbstractFunctionReferenceFixer
  4637. {
  4638. private static $functions = [
  4639. 'strlen' => ['alternativeName' => 'mb_strlen', 'argumentCount' => [1]],
  4640. 'strpos' => ['alternativeName' => 'mb_strpos', 'argumentCount' => [2, 3]],
  4641. 'strrpos' => ['alternativeName' => 'mb_strrpos', 'argumentCount' => [2, 3]],
  4642. 'substr' => ['alternativeName' => 'mb_substr', 'argumentCount' => [2, 3]],
  4643. 'strtolower' => ['alternativeName' => 'mb_strtolower', 'argumentCount' => [1]],
  4644. 'strtoupper' => ['alternativeName' => 'mb_strtoupper', 'argumentCount' => [1]],
  4645. 'stripos' => ['alternativeName' => 'mb_stripos', 'argumentCount' => [2, 3]],
  4646. 'strripos' => ['alternativeName' => 'mb_strripos', 'argumentCount' => [2, 3]],
  4647. 'strstr' => ['alternativeName' => 'mb_strstr', 'argumentCount' => [2, 3]],
  4648. 'stristr' => ['alternativeName' => 'mb_stristr', 'argumentCount' => [2, 3]],
  4649. 'strrchr' => ['alternativeName' => 'mb_strrchr', 'argumentCount' => [2]],
  4650. 'substr_count' => ['alternativeName' => 'mb_substr_count', 'argumentCount' => [2, 3, 4]],
  4651. ];
  4652. public function getDefinition()
  4653. {
  4654. return new FixerDefinition(
  4655. 'Replace non multibyte-safe functions with corresponding mb function.',
  4656. [
  4657. new CodeSample(
  4658. '<?php
  4659. $a = strlen($a);
  4660. $a = strpos($a, $b);
  4661. $a = strrpos($a, $b);
  4662. $a = substr($a, $b);
  4663. $a = strtolower($a);
  4664. $a = strtoupper($a);
  4665. $a = stripos($a, $b);
  4666. $a = strripos($a, $b);
  4667. $a = strstr($a, $b);
  4668. $a = stristr($a, $b);
  4669. $a = strrchr($a, $b);
  4670. $a = substr_count($a, $b);
  4671. '
  4672. ),
  4673. ],
  4674. null,
  4675. 'Risky when any of the functions are overridden.'
  4676. );
  4677. }
  4678. public function isCandidate(Tokens $tokens)
  4679. {
  4680. return $tokens->isTokenKindFound(T_STRING);
  4681. }
  4682. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  4683. {
  4684. $argumentsAnalyzer = new ArgumentsAnalyzer();
  4685. foreach (self::$functions as $functionIdentity => $functionReplacement) {
  4686. $currIndex = 0;
  4687. while (null !== $currIndex) {
  4688. $boundaries = $this->find($functionIdentity, $tokens, $currIndex, $tokens->count() - 1);
  4689. if (null === $boundaries) {
  4690. continue 2;
  4691. }
  4692. list($functionName, $openParenthesis, $closeParenthesis) = $boundaries;
  4693. $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis);
  4694. if (!in_array($count, $functionReplacement['argumentCount'], true)) {
  4695. continue 2;
  4696. }
  4697. $currIndex = $openParenthesis;
  4698. $tokens[$functionName] = new Token([T_STRING, $functionReplacement['alternativeName']]);
  4699. }
  4700. }
  4701. }
  4702. }
  4703. <?php
  4704. namespace PhpCsFixer\Fixer\Alias;
  4705. use PhpCsFixer\AbstractFixer;
  4706. use PhpCsFixer\FixerDefinition\CodeSample;
  4707. use PhpCsFixer\FixerDefinition\FixerDefinition;
  4708. use PhpCsFixer\Tokenizer\CT;
  4709. use PhpCsFixer\Tokenizer\Token;
  4710. use PhpCsFixer\Tokenizer\Tokens;
  4711. final class NoAliasFunctionsFixer extends AbstractFixer
  4712. {
  4713. private static $aliases = [
  4714. 'chop' => 'rtrim',
  4715. 'close' => 'closedir',
  4716. 'doubleval' => 'floatval',
  4717. 'fputs' => 'fwrite',
  4718. 'imap_create' => 'imap_createmailbox',
  4719. 'imap_fetchtext' => 'imap_body',
  4720. 'imap_header' => 'imap_headerinfo',
  4721. 'imap_listmailbox' => 'imap_list',
  4722. 'imap_listsubscribed' => 'imap_lsub',
  4723. 'imap_rename' => 'imap_renamemailbox',
  4724. 'imap_scan' => 'imap_listscan',
  4725. 'imap_scanmailbox' => 'imap_listscan',
  4726. 'ini_alter' => 'ini_set',
  4727. 'is_double' => 'is_float',
  4728. 'is_integer' => 'is_int',
  4729. 'is_long' => 'is_int',
  4730. 'is_real' => 'is_float',
  4731. 'is_writeable' => 'is_writable',
  4732. 'join' => 'implode',
  4733. 'key_exists' => 'array_key_exists',
  4734. 'magic_quotes_runtime' => 'set_magic_quotes_runtime',
  4735. 'pos' => 'current',
  4736. 'show_source' => 'highlight_file',
  4737. 'sizeof' => 'count',
  4738. 'strchr' => 'strstr',
  4739. ];
  4740. public function getDefinition()
  4741. {
  4742. return new FixerDefinition(
  4743. 'Master functions shall be used instead of aliases.',
  4744. [
  4745. new CodeSample(
  4746. '<?php
  4747. $a = chop($b);
  4748. close($b);
  4749. $a = doubleval($b);
  4750. $a = fputs($b, $c);
  4751. ini_alter($b, $c);
  4752. $a = is_double($b);
  4753. $a = is_integer($b);
  4754. $a = is_long($b);
  4755. $a = is_real($b);
  4756. $a = is_writeable($b);
  4757. $a = join($glue, $pieces);
  4758. $a = key_exists($key, $array);
  4759. magic_quotes_runtime($new_setting);
  4760. $a = pos($array);
  4761. $a = show_source($filename, true);
  4762. $a = sizeof($b);
  4763. $a = strchr($haystack, $needle);
  4764. '
  4765. ),
  4766. ],
  4767. null,
  4768. 'Risky when any of the alias functions are overridden.'
  4769. );
  4770. }
  4771. public function isCandidate(Tokens $tokens)
  4772. {
  4773. return $tokens->isTokenKindFound(T_STRING);
  4774. }
  4775. public function isRisky()
  4776. {
  4777. return true;
  4778. }
  4779. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  4780. {
  4781. foreach ($tokens->findGivenKind(T_STRING) as $index => $token) {
  4782. $tokenContent = strtolower($token->getContent());
  4783. if (!isset(self::$aliases[$tokenContent])) {
  4784. continue;
  4785. }
  4786. $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
  4787. if (!$nextToken->equals('(')) {
  4788. continue;
  4789. }
  4790. $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
  4791. $prevToken = $tokens[$prevTokenIndex];
  4792. if ($prevToken->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, CT::T_RETURN_REF])) {
  4793. continue;
  4794. }
  4795. if ($prevToken->isGivenKind([T_NS_SEPARATOR])) {
  4796. $twicePrevTokenIndex = $tokens->getPrevMeaningfulToken($prevTokenIndex);
  4797. $twicePrevToken = $tokens[$twicePrevTokenIndex];
  4798. if ($twicePrevToken->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, T_STRING, CT::T_NAMESPACE_OPERATOR])) {
  4799. continue;
  4800. }
  4801. }
  4802. $tokens[$index] = new Token([T_STRING, self::$aliases[$tokenContent]]);
  4803. }
  4804. }
  4805. }
  4806. <?php
  4807. namespace PhpCsFixer\Fixer\Alias;
  4808. use PhpCsFixer\AbstractFixer;
  4809. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  4810. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  4811. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  4812. use PhpCsFixer\FixerDefinition\CodeSample;
  4813. use PhpCsFixer\FixerDefinition\FixerDefinition;
  4814. use PhpCsFixer\Tokenizer\CT;
  4815. use PhpCsFixer\Tokenizer\Token;
  4816. use PhpCsFixer\Tokenizer\Tokens;
  4817. final class NoMixedEchoPrintFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  4818. {
  4819. public static $defaultConfig = ['use' => 'echo'];
  4820. private $callBack;
  4821. private $candidateTokenType;
  4822. public function configure(array $configuration = null)
  4823. {
  4824. parent::configure($configuration);
  4825. if ('echo' === $this->configuration['use']) {
  4826. $this->candidateTokenType = T_PRINT;
  4827. $this->callBack = 'fixPrintToEcho';
  4828. } else {
  4829. $this->candidateTokenType = T_ECHO;
  4830. $this->callBack = 'fixEchoToPrint';
  4831. }
  4832. }
  4833. public function getDefinition()
  4834. {
  4835. return new FixerDefinition(
  4836. 'Either language construct `print` or `echo` should be used.',
  4837. [
  4838. new CodeSample("<?php print 'example';\n"),
  4839. new CodeSample("<?php echo('example');\n", ['use' => 'print']),
  4840. ]
  4841. );
  4842. }
  4843. public function getPriority()
  4844. {
  4845. return -10;
  4846. }
  4847. public function isCandidate(Tokens $tokens)
  4848. {
  4849. return $tokens->isTokenKindFound($this->candidateTokenType);
  4850. }
  4851. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  4852. {
  4853. $callBack = $this->callBack;
  4854. foreach ($tokens as $index => $token) {
  4855. if ($token->isGivenKind($this->candidateTokenType)) {
  4856. $this->{$callBack}($tokens, $index);
  4857. }
  4858. }
  4859. }
  4860. protected function createConfigurationDefinition()
  4861. {
  4862. return new FixerConfigurationResolver([
  4863. (new FixerOptionBuilder('use', 'The desired language construct.'))
  4864. ->setAllowedValues(['print', 'echo'])
  4865. ->setDefault('echo')
  4866. ->getOption(),
  4867. ]);
  4868. }
  4869. private function fixEchoToPrint(Tokens $tokens, $index)
  4870. {
  4871. $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
  4872. $endTokenIndex = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]);
  4873. $canBeConverted = true;
  4874. for ($i = $nextTokenIndex; $i < $endTokenIndex; ++$i) {
  4875. if ($tokens[$i]->equalsAny(['(', [CT::T_ARRAY_SQUARE_BRACE_OPEN]])) {
  4876. $blockType = Tokens::detectBlockType($tokens[$i]);
  4877. $i = $tokens->findBlockEnd($blockType['type'], $i);
  4878. }
  4879. if ($tokens[$i]->equals(',')) {
  4880. $canBeConverted = false;
  4881. break;
  4882. }
  4883. }
  4884. if (false === $canBeConverted) {
  4885. return;
  4886. }
  4887. $tokens[$index] = new Token([T_PRINT, 'print']);
  4888. }
  4889. private function fixPrintToEcho(Tokens $tokens, $index)
  4890. {
  4891. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  4892. if (!$prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
  4893. return;
  4894. }
  4895. $tokens[$index] = new Token([T_ECHO, 'echo']);
  4896. }
  4897. }
  4898. <?php
  4899. namespace PhpCsFixer\Fixer\Alias;
  4900. use PhpCsFixer\AbstractFunctionReferenceFixer;
  4901. use PhpCsFixer\FixerDefinition\CodeSample;
  4902. use PhpCsFixer\FixerDefinition\FixerDefinition;
  4903. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  4904. use PhpCsFixer\Tokenizer\CT;
  4905. use PhpCsFixer\Tokenizer\Token;
  4906. use PhpCsFixer\Tokenizer\Tokens;
  4907. final class PowToExponentiationFixer extends AbstractFunctionReferenceFixer
  4908. {
  4909. public function isCandidate(Tokens $tokens)
  4910. {
  4911. return $tokens->count() > 7 && $tokens->isTokenKindFound(T_STRING);
  4912. }
  4913. public function getDefinition()
  4914. {
  4915. return new FixerDefinition(
  4916. 'Converts `pow` to the `**` operator.',
  4917. [
  4918. new CodeSample(
  4919. "<?php\n pow(\$a, 1);\n"
  4920. ),
  4921. ],
  4922. null,
  4923. 'Risky when the function `pow` is overridden.'
  4924. );
  4925. }
  4926. public function getPriority()
  4927. {
  4928. return 3;
  4929. }
  4930. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  4931. {
  4932. $candidates = $this->findPowCalls($tokens);
  4933. $argumentsAnalyzer = new ArgumentsAnalyzer();
  4934. $numberOfTokensAdded = 0;
  4935. $previousCloseParenthesisIndex = count($tokens);
  4936. foreach (array_reverse($candidates) as $candidate) {
  4937. if ($previousCloseParenthesisIndex < $candidate[2]) {
  4938. $previousCloseParenthesisIndex = $candidate[2];
  4939. $candidate[2] += $numberOfTokensAdded;
  4940. } else {
  4941. $previousCloseParenthesisIndex = $candidate[2];
  4942. $numberOfTokensAdded = 0;
  4943. }
  4944. $arguments = $argumentsAnalyzer->getArguments($tokens, $candidate[1], $candidate[2]);
  4945. if (2 !== count($arguments)) {
  4946. continue;
  4947. }
  4948. $numberOfTokensAdded += $this->fixPowToExponentiation(
  4949. $tokens,
  4950. $candidate[0],
  4951. $candidate[1],
  4952. $candidate[2],
  4953. $arguments
  4954. );
  4955. }
  4956. }
  4957. private function findPowCalls(Tokens $tokens)
  4958. {
  4959. $candidates = [];
  4960. $end = count($tokens) - 6;
  4961. for ($i = 1; $i < $end; ++$i) {
  4962. $candidate = $this->find('pow', $tokens, $i, $end);
  4963. if (null === $candidate) {
  4964. break;
  4965. }
  4966. $i = $candidate[1];
  4967. $candidates[] = $candidate;
  4968. }
  4969. return $candidates;
  4970. }
  4971. private function fixPowToExponentiation(Tokens $tokens, $functionNameIndex, $openParenthesisIndex, $closeParenthesisIndex, array $arguments)
  4972. {
  4973. $tokens[$tokens->getNextTokenOfKind(reset($arguments), [','])] = new Token([T_POW, '**']);
  4974. $tokens->clearAt($closeParenthesisIndex);
  4975. $added = 0;
  4976. foreach (array_reverse($arguments, true) as $argumentStartIndex => $argumentEndIndex) {
  4977. if ($this->isParenthesisNeeded($tokens, $argumentStartIndex, $argumentEndIndex)) {
  4978. $tokens->insertAt($argumentEndIndex + 1, new Token(')'));
  4979. $tokens->insertAt($argumentStartIndex, new Token('('));
  4980. $added += 2;
  4981. }
  4982. }
  4983. $tokens->clearAt($openParenthesisIndex);
  4984. $tokens->clearAt($functionNameIndex);
  4985. $prev = $tokens->getPrevMeaningfulToken($functionNameIndex);
  4986. if ($tokens[$prev]->isGivenKind(T_NS_SEPARATOR)) {
  4987. $tokens->clearAt($prev);
  4988. }
  4989. return $added;
  4990. }
  4991. private function isParenthesisNeeded(Tokens $tokens, $argumentStartIndex, $argumentEndIndex)
  4992. {
  4993. static $allowedKinds = [
  4994. T_DNUMBER, T_LNUMBER, T_VARIABLE, T_STRING, T_OBJECT_OPERATOR, T_CONSTANT_ENCAPSED_STRING, T_DOUBLE_CAST,
  4995. T_INT_CAST, T_INC, T_DEC, T_NS_SEPARATOR, T_WHITESPACE, T_DOUBLE_COLON, T_LINE, T_COMMENT, T_DOC_COMMENT,
  4996. CT::T_NAMESPACE_OPERATOR,
  4997. ];
  4998. for ($i = $argumentStartIndex; $i <= $argumentEndIndex; ++$i) {
  4999. if ($tokens[$i]->isGivenKind($allowedKinds) || $tokens->isEmptyAt($i)) {
  5000. continue;
  5001. }
  5002. if (null !== $blockType = Tokens::detectBlockType($tokens[$i])) {
  5003. $i = $tokens->findBlockEnd($blockType['type'], $i);
  5004. continue;
  5005. }
  5006. if ($tokens[$i]->equals('$')) {
  5007. $i = $tokens->getNextMeaningfulToken($i);
  5008. if ($tokens[$i]->isGivenKind(CT::T_DYNAMIC_VAR_BRACE_OPEN)) {
  5009. $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE, $i);
  5010. continue;
  5011. }
  5012. }
  5013. if ($tokens[$i]->equals('+') && $tokens->getPrevMeaningfulToken($i) < $argumentStartIndex) {
  5014. continue;
  5015. }
  5016. return true;
  5017. }
  5018. return false;
  5019. }
  5020. }
  5021. <?php
  5022. namespace PhpCsFixer\Fixer\Alias;
  5023. use PhpCsFixer\AbstractFunctionReferenceFixer;
  5024. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  5025. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  5026. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  5027. use PhpCsFixer\FixerDefinition\CodeSample;
  5028. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5029. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  5030. use PhpCsFixer\Tokenizer\Token;
  5031. use PhpCsFixer\Tokenizer\Tokens;
  5032. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  5033. final class RandomApiMigrationFixer extends AbstractFunctionReferenceFixer implements ConfigurationDefinitionFixerInterface
  5034. {
  5035. private static $argumentCounts = [
  5036. 'getrandmax' => [0],
  5037. 'mt_rand' => [1, 2],
  5038. 'rand' => [0, 2],
  5039. 'srand' => [0, 1],
  5040. ];
  5041. public function configure(array $configuration = null)
  5042. {
  5043. parent::configure($configuration);
  5044. foreach ($this->configuration['replacements'] as $functionName => $replacement) {
  5045. $this->configuration['replacements'][$functionName] = [
  5046. 'alternativeName' => $replacement,
  5047. 'argumentCount' => self::$argumentCounts[$functionName],
  5048. ];
  5049. }
  5050. }
  5051. public function getDefinition()
  5052. {
  5053. return new FixerDefinition(
  5054. 'Replaces `rand`, `srand`, `getrandmax` functions calls with their `mt_*` analogs.',
  5055. [
  5056. new CodeSample("<?php\n\$a = getrandmax();\n\$a = rand(\$b, \$c);\n\$a = srand();\n"),
  5057. new CodeSample(
  5058. "<?php\n\$a = getrandmax();\n\$a = rand(\$b, \$c);\n\$a = srand();\n",
  5059. ['replacements' => ['getrandmax' => 'mt_getrandmax']]
  5060. ),
  5061. ],
  5062. null,
  5063. 'Risky when the configured functions are overridden.'
  5064. );
  5065. }
  5066. public function isCandidate(Tokens $tokens)
  5067. {
  5068. return $tokens->isTokenKindFound(T_STRING);
  5069. }
  5070. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5071. {
  5072. $argumentsAnalyzer = new ArgumentsAnalyzer();
  5073. foreach ($this->configuration['replacements'] as $functionIdentity => $functionReplacement) {
  5074. if ($functionIdentity === $functionReplacement['alternativeName']) {
  5075. continue;
  5076. }
  5077. $currIndex = 0;
  5078. while (null !== $currIndex) {
  5079. $boundaries = $this->find($functionIdentity, $tokens, $currIndex, $tokens->count() - 1);
  5080. if (null === $boundaries) {
  5081. continue 2;
  5082. }
  5083. list($functionName, $openParenthesis, $closeParenthesis) = $boundaries;
  5084. $count = $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis);
  5085. if (!in_array($count, $functionReplacement['argumentCount'], true)) {
  5086. continue 2;
  5087. }
  5088. $currIndex = $openParenthesis;
  5089. $tokens[$functionName] = new Token([T_STRING, $functionReplacement['alternativeName']]);
  5090. if (0 === $count && 'random_int' === $functionReplacement['alternativeName']) {
  5091. $tokens->insertAt($currIndex + 1, [
  5092. new Token([T_LNUMBER, '0']),
  5093. new Token(','),
  5094. new Token([T_WHITESPACE, ' ']),
  5095. new Token([T_STRING, 'getrandmax']),
  5096. new Token('('),
  5097. new Token(')'),
  5098. ]);
  5099. $currIndex += 6;
  5100. }
  5101. }
  5102. }
  5103. }
  5104. protected function createConfigurationDefinition()
  5105. {
  5106. return new FixerConfigurationResolverRootless('replacements', [
  5107. (new FixerOptionBuilder('replacements', 'Mapping between replaced functions with the new ones.'))
  5108. ->setAllowedTypes(['array'])
  5109. ->setAllowedValues([static function ($value) {
  5110. foreach ($value as $functionName => $replacement) {
  5111. if (!array_key_exists($functionName, self::$argumentCounts)) {
  5112. throw new InvalidOptionsException(sprintf(
  5113. 'Function "%s" is not handled by the fixer.',
  5114. $functionName
  5115. ));
  5116. }
  5117. if (!is_string($replacement)) {
  5118. throw new InvalidOptionsException(sprintf(
  5119. 'Replacement for function "%s" must be a string, "%s" given.',
  5120. $functionName,
  5121. is_object($replacement) ? get_class($replacement) : gettype($replacement)
  5122. ));
  5123. }
  5124. }
  5125. return true;
  5126. }])
  5127. ->setDefault([
  5128. 'getrandmax' => 'mt_getrandmax',
  5129. 'rand' => 'mt_rand',
  5130. 'srand' => 'mt_srand',
  5131. ])
  5132. ->getOption(),
  5133. ]);
  5134. }
  5135. }
  5136. <?php
  5137. namespace PhpCsFixer\Fixer\ArrayNotation;
  5138. use PhpCsFixer\AbstractFixer;
  5139. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  5140. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  5141. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  5142. use PhpCsFixer\FixerDefinition\CodeSample;
  5143. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5144. use PhpCsFixer\FixerDefinition\VersionSpecification;
  5145. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  5146. use PhpCsFixer\Tokenizer\CT;
  5147. use PhpCsFixer\Tokenizer\Token;
  5148. use PhpCsFixer\Tokenizer\Tokens;
  5149. final class ArraySyntaxFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  5150. {
  5151. private $candidateTokenKind;
  5152. private $fixCallback;
  5153. public function configure(array $configuration = null)
  5154. {
  5155. parent::configure($configuration);
  5156. $this->resolveCandidateTokenKind();
  5157. $this->resolveFixCallback();
  5158. }
  5159. public function getDefinition()
  5160. {
  5161. return new FixerDefinition(
  5162. 'PHP arrays should be declared using the configured syntax.',
  5163. [
  5164. new CodeSample(
  5165. "<?php\n[1,2];\n"
  5166. ),
  5167. new VersionSpecificCodeSample(
  5168. "<?php\narray(1,2);\n",
  5169. new VersionSpecification(50400),
  5170. ['syntax' => 'short']
  5171. ),
  5172. ]
  5173. );
  5174. }
  5175. public function getPriority()
  5176. {
  5177. return 1;
  5178. }
  5179. public function isCandidate(Tokens $tokens)
  5180. {
  5181. return $tokens->isTokenKindFound($this->candidateTokenKind);
  5182. }
  5183. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5184. {
  5185. $callback = $this->fixCallback;
  5186. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  5187. if ($tokens[$index]->isGivenKind($this->candidateTokenKind)) {
  5188. $this->{$callback}($tokens, $index);
  5189. }
  5190. }
  5191. }
  5192. protected function createConfigurationDefinition()
  5193. {
  5194. return new FixerConfigurationResolver([
  5195. (new FixerOptionBuilder('syntax', 'Whether to use the `long` or `short` array syntax.'))
  5196. ->setAllowedValues(['long', 'short'])
  5197. ->setDefault('long')
  5198. ->getOption(),
  5199. ]);
  5200. }
  5201. private function fixToLongArraySyntax(Tokens $tokens, $index)
  5202. {
  5203. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index);
  5204. $tokens[$index] = new Token('(');
  5205. $tokens[$closeIndex] = new Token(')');
  5206. $tokens->insertAt($index, new Token([T_ARRAY, 'array']));
  5207. }
  5208. private function fixToShortArraySyntax(Tokens $tokens, $index)
  5209. {
  5210. $openIndex = $tokens->getNextTokenOfKind($index, ['(']);
  5211. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
  5212. $tokens[$openIndex] = new Token([CT::T_ARRAY_SQUARE_BRACE_OPEN, '[']);
  5213. $tokens[$closeIndex] = new Token([CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']']);
  5214. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  5215. }
  5216. private function resolveFixCallback()
  5217. {
  5218. $this->fixCallback = sprintf('fixTo%sArraySyntax', ucfirst($this->configuration['syntax']));
  5219. }
  5220. private function resolveCandidateTokenKind()
  5221. {
  5222. $this->candidateTokenKind = 'long' === $this->configuration['syntax'] ? CT::T_ARRAY_SQUARE_BRACE_OPEN : T_ARRAY;
  5223. }
  5224. }
  5225. <?php
  5226. namespace PhpCsFixer\Fixer\ArrayNotation;
  5227. use PhpCsFixer\AbstractFixer;
  5228. use PhpCsFixer\FixerDefinition\CodeSample;
  5229. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5230. use PhpCsFixer\Tokenizer\Token;
  5231. use PhpCsFixer\Tokenizer\Tokens;
  5232. final class NoMultilineWhitespaceAroundDoubleArrowFixer extends AbstractFixer
  5233. {
  5234. public function getDefinition()
  5235. {
  5236. return new FixerDefinition(
  5237. 'Operator `=>` should not be surrounded by multi-line whitespaces.',
  5238. [new CodeSample("<?php\n\$a = array(1\n\n=> 2);\n")]
  5239. );
  5240. }
  5241. public function getPriority()
  5242. {
  5243. return 1;
  5244. }
  5245. public function isCandidate(Tokens $tokens)
  5246. {
  5247. return $tokens->isTokenKindFound(T_DOUBLE_ARROW);
  5248. }
  5249. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5250. {
  5251. foreach ($tokens as $index => $token) {
  5252. if (!$token->isGivenKind(T_DOUBLE_ARROW)) {
  5253. continue;
  5254. }
  5255. $this->fixWhitespace($tokens, $index - 1);
  5256. if (!$tokens[$index + 2]->isComment()) {
  5257. $this->fixWhitespace($tokens, $index + 1);
  5258. }
  5259. }
  5260. }
  5261. private function fixWhitespace(Tokens $tokens, $index)
  5262. {
  5263. $token = $tokens[$index];
  5264. if ($token->isWhitespace() && !$token->isWhitespace(" \t")) {
  5265. $tokens[$index] = new Token([T_WHITESPACE, rtrim($token->getContent()).' ']);
  5266. }
  5267. }
  5268. }
  5269. <?php
  5270. namespace PhpCsFixer\Fixer\ArrayNotation;
  5271. use PhpCsFixer\AbstractFixer;
  5272. use PhpCsFixer\FixerDefinition\CodeSample;
  5273. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5274. use PhpCsFixer\Tokenizer\CT;
  5275. use PhpCsFixer\Tokenizer\Tokens;
  5276. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  5277. final class NoTrailingCommaInSinglelineArrayFixer extends AbstractFixer
  5278. {
  5279. public function getDefinition()
  5280. {
  5281. return new FixerDefinition(
  5282. 'PHP single-line arrays should not have trailing comma.',
  5283. [new CodeSample("<?php\n\$a = array('sample', );\n")]
  5284. );
  5285. }
  5286. public function isCandidate(Tokens $tokens)
  5287. {
  5288. return $tokens->isAnyTokenKindsFound([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]);
  5289. }
  5290. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5291. {
  5292. $tokensAnalyzer = new TokensAnalyzer($tokens);
  5293. for ($index = 0, $c = $tokens->count(); $index < $c; ++$index) {
  5294. if ($tokensAnalyzer->isArray($index)) {
  5295. $this->fixArray($tokens, $index);
  5296. }
  5297. }
  5298. }
  5299. private function fixArray(Tokens $tokens, $index)
  5300. {
  5301. $tokensAnalyzer = new TokensAnalyzer($tokens);
  5302. if ($tokensAnalyzer->isArrayMultiLine($index)) {
  5303. return;
  5304. }
  5305. $startIndex = $index;
  5306. if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
  5307. $startIndex = $tokens->getNextTokenOfKind($startIndex, ['(']);
  5308. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
  5309. } else {
  5310. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
  5311. }
  5312. $beforeEndIndex = $tokens->getPrevMeaningfulToken($endIndex);
  5313. $beforeEndToken = $tokens[$beforeEndIndex];
  5314. if ($beforeEndToken->equals(',')) {
  5315. $tokens->removeTrailingWhitespace($beforeEndIndex);
  5316. $tokens->clearAt($beforeEndIndex);
  5317. }
  5318. }
  5319. }
  5320. <?php
  5321. namespace PhpCsFixer\Fixer\ArrayNotation;
  5322. use PhpCsFixer\AbstractFixer;
  5323. use PhpCsFixer\FixerDefinition\CodeSample;
  5324. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5325. use PhpCsFixer\Tokenizer\CT;
  5326. use PhpCsFixer\Tokenizer\Tokens;
  5327. final class NoWhitespaceBeforeCommaInArrayFixer extends AbstractFixer
  5328. {
  5329. public function getDefinition()
  5330. {
  5331. return new FixerDefinition(
  5332. 'In array declaration, there MUST NOT be a whitespace before each comma.',
  5333. [new CodeSample("<?php \$x = array(1 , \"2\");\n")]
  5334. );
  5335. }
  5336. public function isCandidate(Tokens $tokens)
  5337. {
  5338. return $tokens->isAnyTokenKindsFound([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]);
  5339. }
  5340. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5341. {
  5342. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  5343. if ($tokens[$index]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  5344. $this->fixSpacing($index, $tokens);
  5345. }
  5346. }
  5347. }
  5348. private function fixSpacing($index, Tokens $tokens)
  5349. {
  5350. if ($tokens[$index]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  5351. $startIndex = $index;
  5352. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
  5353. } else {
  5354. $startIndex = $tokens->getNextTokenOfKind($index, ['(']);
  5355. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
  5356. }
  5357. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  5358. $i = $this->skipNonArrayElements($i, $tokens);
  5359. $currentToken = $tokens[$i];
  5360. $prevIndex = $tokens->getPrevNonWhitespace($i - 1);
  5361. if ($currentToken->equals(',') && !$tokens[$prevIndex]->equals([T_END_HEREDOC]) && !$tokens[$prevIndex]->isComment()) {
  5362. $tokens->removeLeadingWhitespace($i);
  5363. }
  5364. }
  5365. }
  5366. private function skipNonArrayElements($index, Tokens $tokens)
  5367. {
  5368. if ($tokens[$index]->equals('}')) {
  5369. return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index, false);
  5370. }
  5371. if ($tokens[$index]->equals(')')) {
  5372. $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index, false);
  5373. $startIndex = $tokens->getPrevMeaningfulToken($startIndex);
  5374. if (!$tokens[$startIndex]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  5375. return $startIndex;
  5376. }
  5377. }
  5378. return $index;
  5379. }
  5380. }
  5381. <?php
  5382. namespace PhpCsFixer\Fixer\ArrayNotation;
  5383. use PhpCsFixer\AbstractFixer;
  5384. use PhpCsFixer\FixerDefinition\CodeSample;
  5385. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5386. use PhpCsFixer\Tokenizer\CT;
  5387. use PhpCsFixer\Tokenizer\Token;
  5388. use PhpCsFixer\Tokenizer\Tokens;
  5389. final class NormalizeIndexBraceFixer extends AbstractFixer
  5390. {
  5391. public function getDefinition()
  5392. {
  5393. return new FixerDefinition(
  5394. 'Array index should always be written by using square braces.',
  5395. [new CodeSample("<?php\necho \$sample{\$index};\n")]
  5396. );
  5397. }
  5398. public function isCandidate(Tokens $tokens)
  5399. {
  5400. return $tokens->isTokenKindFound(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN);
  5401. }
  5402. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5403. {
  5404. foreach ($tokens as $index => $token) {
  5405. if ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN)) {
  5406. $tokens[$index] = new Token('[');
  5407. } elseif ($token->isGivenKind(CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE)) {
  5408. $tokens[$index] = new Token(']');
  5409. }
  5410. }
  5411. }
  5412. }
  5413. <?php
  5414. namespace PhpCsFixer\Fixer\ArrayNotation;
  5415. use PhpCsFixer\AbstractFixer;
  5416. use PhpCsFixer\FixerDefinition\CodeSample;
  5417. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5418. use PhpCsFixer\Tokenizer\CT;
  5419. use PhpCsFixer\Tokenizer\Token;
  5420. use PhpCsFixer\Tokenizer\Tokens;
  5421. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  5422. final class TrailingCommaInMultilineArrayFixer extends AbstractFixer
  5423. {
  5424. public function getDefinition()
  5425. {
  5426. return new FixerDefinition(
  5427. 'PHP multi-line arrays should have a trailing comma.',
  5428. [new CodeSample("<?php\narray(\n 1,\n 2\n);\n")]
  5429. );
  5430. }
  5431. public function isCandidate(Tokens $tokens)
  5432. {
  5433. return $tokens->isAnyTokenKindsFound([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]);
  5434. }
  5435. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5436. {
  5437. $tokensAnalyzer = new TokensAnalyzer($tokens);
  5438. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  5439. if ($tokensAnalyzer->isArray($index) && $tokensAnalyzer->isArrayMultiLine($index)) {
  5440. $this->fixArray($tokens, $index);
  5441. }
  5442. }
  5443. }
  5444. private function fixArray(Tokens $tokens, $index)
  5445. {
  5446. $startIndex = $index;
  5447. if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
  5448. $startIndex = $tokens->getNextTokenOfKind($startIndex, ['(']);
  5449. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
  5450. } else {
  5451. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
  5452. }
  5453. $beforeEndIndex = $tokens->getPrevMeaningfulToken($endIndex);
  5454. $beforeEndToken = $tokens[$beforeEndIndex];
  5455. if ($startIndex !== $beforeEndIndex && !$beforeEndToken->equalsAny([',', [T_END_HEREDOC]])) {
  5456. $tokens->insertAt($beforeEndIndex + 1, new Token(','));
  5457. $endToken = $tokens[$endIndex];
  5458. if (!$endToken->isComment() && !$endToken->isWhitespace()) {
  5459. $tokens->ensureWhitespaceAtIndex($endIndex, 1, ' ');
  5460. }
  5461. }
  5462. }
  5463. }
  5464. <?php
  5465. namespace PhpCsFixer\Fixer\ArrayNotation;
  5466. use PhpCsFixer\AbstractFixer;
  5467. use PhpCsFixer\FixerDefinition\CodeSample;
  5468. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5469. use PhpCsFixer\Tokenizer\CT;
  5470. use PhpCsFixer\Tokenizer\Tokens;
  5471. final class TrimArraySpacesFixer extends AbstractFixer
  5472. {
  5473. public function getDefinition()
  5474. {
  5475. return new FixerDefinition(
  5476. 'Arrays should be formatted like function/method arguments, without leading or trailing single line space.',
  5477. [new CodeSample("<?php\n\$sample = array( );\n\$sample = array( 'a', 'b' );\n")]
  5478. );
  5479. }
  5480. public function isCandidate(Tokens $tokens)
  5481. {
  5482. return $tokens->isAnyTokenKindsFound([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]);
  5483. }
  5484. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5485. {
  5486. for ($index = 0, $c = $tokens->count(); $index < $c; ++$index) {
  5487. if ($tokens[$index]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  5488. self::fixArray($tokens, $index);
  5489. }
  5490. }
  5491. }
  5492. private static function fixArray(Tokens $tokens, $index)
  5493. {
  5494. $startIndex = $index;
  5495. if ($tokens[$startIndex]->isGivenKind(T_ARRAY)) {
  5496. $startIndex = $tokens->getNextMeaningfulToken($startIndex);
  5497. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
  5498. } else {
  5499. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
  5500. }
  5501. $nextIndex = $startIndex + 1;
  5502. $nextToken = $tokens[$nextIndex];
  5503. $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($startIndex);
  5504. $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];
  5505. $tokenAfterNextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex + 1];
  5506. $prevIndex = $endIndex - 1;
  5507. $prevToken = $tokens[$prevIndex];
  5508. $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($endIndex);
  5509. $prevNonWhitespaceToken = $tokens[$prevNonWhitespaceIndex];
  5510. if (
  5511. $nextToken->isWhitespace(" \t")
  5512. && (
  5513. !$nextNonWhitespaceToken->isComment()
  5514. || $nextNonWhitespaceIndex === $prevNonWhitespaceIndex
  5515. || $tokenAfterNextNonWhitespaceToken->isWhitespace(" \t")
  5516. || '/*' === substr($nextNonWhitespaceToken->getContent(), 0, 2)
  5517. )
  5518. ) {
  5519. $tokens->clearAt($nextIndex);
  5520. }
  5521. if (
  5522. $prevToken->isWhitespace(" \t")
  5523. && !$prevNonWhitespaceToken->equals(',')
  5524. ) {
  5525. $tokens->clearAt($prevIndex);
  5526. }
  5527. }
  5528. }
  5529. <?php
  5530. namespace PhpCsFixer\Fixer\ArrayNotation;
  5531. use PhpCsFixer\AbstractFixer;
  5532. use PhpCsFixer\FixerDefinition\CodeSample;
  5533. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5534. use PhpCsFixer\Tokenizer\CT;
  5535. use PhpCsFixer\Tokenizer\Token;
  5536. use PhpCsFixer\Tokenizer\Tokens;
  5537. final class WhitespaceAfterCommaInArrayFixer extends AbstractFixer
  5538. {
  5539. public function getDefinition()
  5540. {
  5541. return new FixerDefinition(
  5542. 'In array declaration, there MUST be a whitespace after each comma.',
  5543. [new CodeSample("<?php\n\$sample = array(1,'a',\$b,);\n")]
  5544. );
  5545. }
  5546. public function isCandidate(Tokens $tokens)
  5547. {
  5548. return $tokens->isAnyTokenKindsFound([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]);
  5549. }
  5550. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5551. {
  5552. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  5553. if ($tokens[$index]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  5554. $this->fixSpacing($index, $tokens);
  5555. }
  5556. }
  5557. }
  5558. private function fixSpacing($index, Tokens $tokens)
  5559. {
  5560. if ($tokens[$index]->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  5561. $startIndex = $index;
  5562. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $startIndex);
  5563. } else {
  5564. $startIndex = $tokens->getNextTokenOfKind($index, ['(']);
  5565. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
  5566. }
  5567. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  5568. $i = $this->skipNonArrayElements($i, $tokens);
  5569. if ($tokens[$i]->equals(',') && !$tokens[$i + 1]->isWhitespace()) {
  5570. $tokens->insertAt($i + 1, new Token([T_WHITESPACE, ' ']));
  5571. }
  5572. }
  5573. }
  5574. private function skipNonArrayElements($index, Tokens $tokens)
  5575. {
  5576. if ($tokens[$index]->equals('}')) {
  5577. return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index, false);
  5578. }
  5579. if ($tokens[$index]->equals(')')) {
  5580. $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index, false);
  5581. $startIndex = $tokens->getPrevMeaningfulToken($startIndex);
  5582. if (!$tokens[$startIndex]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  5583. return $startIndex;
  5584. }
  5585. }
  5586. return $index;
  5587. }
  5588. }
  5589. <?php
  5590. namespace PhpCsFixer\Fixer\Basic;
  5591. use PhpCsFixer\AbstractFixer;
  5592. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  5593. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  5594. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  5595. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  5596. use PhpCsFixer\FixerDefinition\CodeSample;
  5597. use PhpCsFixer\FixerDefinition\FixerDefinition;
  5598. use PhpCsFixer\Tokenizer\CT;
  5599. use PhpCsFixer\Tokenizer\Token;
  5600. use PhpCsFixer\Tokenizer\Tokens;
  5601. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  5602. final class BracesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  5603. {
  5604. const LINE_NEXT = 'next';
  5605. const LINE_SAME = 'same';
  5606. public function getDefinition()
  5607. {
  5608. return new FixerDefinition(
  5609. 'The body of each structure MUST be enclosed by braces. Braces should be properly placed. Body of braces should be properly indented.',
  5610. [
  5611. new CodeSample(
  5612. '<?php
  5613. class Foo {
  5614. public function bar($baz) {
  5615. if ($baz = 900) echo "Hello!";
  5616. if ($baz = 9000)
  5617. echo "Wait!";
  5618. if ($baz == true)
  5619. {
  5620. echo "Why?";
  5621. }
  5622. else
  5623. {
  5624. echo "Ha?";
  5625. }
  5626. if (is_array($baz))
  5627. foreach ($baz as $b)
  5628. {
  5629. echo $b;
  5630. }
  5631. }
  5632. }
  5633. '
  5634. ),
  5635. new CodeSample(
  5636. '<?php
  5637. $positive = function ($item) { return $item >= 0; };
  5638. $negative = function ($item) {
  5639. return $item < 0; };
  5640. ',
  5641. ['allow_single_line_closure' => true]
  5642. ),
  5643. new CodeSample(
  5644. '<?php
  5645. class Foo
  5646. {
  5647. public function bar($baz)
  5648. {
  5649. if ($baz = 900) echo "Hello!";
  5650. if ($baz = 9000)
  5651. echo "Wait!";
  5652. if ($baz == true)
  5653. {
  5654. echo "Why?";
  5655. }
  5656. else
  5657. {
  5658. echo "Ha?";
  5659. }
  5660. if (is_array($baz))
  5661. foreach ($baz as $b)
  5662. {
  5663. echo $b;
  5664. }
  5665. }
  5666. }
  5667. ',
  5668. ['position_after_functions_and_oop_constructs' => self::LINE_SAME]
  5669. ),
  5670. ]
  5671. );
  5672. }
  5673. public function getPriority()
  5674. {
  5675. return -25;
  5676. }
  5677. public function isCandidate(Tokens $tokens)
  5678. {
  5679. return true;
  5680. }
  5681. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  5682. {
  5683. $this->fixCommentBeforeBrace($tokens);
  5684. $this->fixMissingControlBraces($tokens);
  5685. $this->fixIndents($tokens);
  5686. $this->fixControlContinuationBraces($tokens);
  5687. $this->fixSpaceAroundToken($tokens);
  5688. $this->fixDoWhile($tokens);
  5689. }
  5690. protected function createConfigurationDefinition()
  5691. {
  5692. return new FixerConfigurationResolver([
  5693. (new FixerOptionBuilder('allow_single_line_closure', 'Whether single line lambda notation should be allowed.'))
  5694. ->setAllowedTypes(['bool'])
  5695. ->setDefault(false)
  5696. ->getOption(),
  5697. (new FixerOptionBuilder('position_after_functions_and_oop_constructs', 'whether the opening brace should be placed on "next" or "same" line after classy constructs (non-anonymous classes, interfaces, traits, methods and non-lambda functions).'))
  5698. ->setAllowedValues([self::LINE_NEXT, self::LINE_SAME])
  5699. ->setDefault(self::LINE_NEXT)
  5700. ->getOption(),
  5701. (new FixerOptionBuilder('position_after_control_structures', 'whether the opening brace should be placed on "next" or "same" line after control structures.'))
  5702. ->setAllowedValues([self::LINE_NEXT, self::LINE_SAME])
  5703. ->setDefault(self::LINE_SAME)
  5704. ->getOption(),
  5705. (new FixerOptionBuilder('position_after_anonymous_constructs', 'whether the opening brace should be placed on "next" or "same" line after anonymous constructs (anonymous classes and lambda functions).'))
  5706. ->setAllowedValues([self::LINE_NEXT, self::LINE_SAME])
  5707. ->setDefault(self::LINE_SAME)
  5708. ->getOption(),
  5709. ]);
  5710. }
  5711. private function fixCommentBeforeBrace(Tokens $tokens)
  5712. {
  5713. $tokensAnalyzer = new TokensAnalyzer($tokens);
  5714. $controlTokens = $this->getControlTokens();
  5715. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  5716. $token = $tokens[$index];
  5717. if ($token->isGivenKind($controlTokens)) {
  5718. $prevIndex = $this->findParenthesisEnd($tokens, $index);
  5719. } elseif (
  5720. ($token->isGivenKind(T_FUNCTION) && $tokensAnalyzer->isLambda($index)) ||
  5721. ($token->isGivenKind(T_CLASS) && $tokensAnalyzer->isAnonymousClass($index))
  5722. ) {
  5723. $prevIndex = $tokens->getNextTokenOfKind($index, ['{']);
  5724. $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
  5725. } else {
  5726. continue;
  5727. }
  5728. $commentIndex = $tokens->getNextNonWhitespace($prevIndex);
  5729. $commentToken = $tokens[$commentIndex];
  5730. if (!$commentToken->isGivenKind(T_COMMENT) || 0 === strpos($commentToken->getContent(), '/*')) {
  5731. continue;
  5732. }
  5733. $braceIndex = $tokens->getNextMeaningfulToken($commentIndex);
  5734. $braceToken = $tokens[$braceIndex];
  5735. if (!$braceToken->equals('{')) {
  5736. continue;
  5737. }
  5738. $tokenTmp = $tokens[$braceIndex];
  5739. $newBraceIndex = $prevIndex + 1;
  5740. for ($i = $braceIndex; $i > $newBraceIndex; --$i) {
  5741. $tokens[$i] = $tokens[$i - 1];
  5742. if ($tokens[$i]->isWhitespace() && $tokens[$i + 1]->isWhitespace()) {
  5743. $tokens[$i] = new Token([T_WHITESPACE, $tokens[$i]->getContent().$tokens[$i + 1]->getContent()]);
  5744. $tokens->clearAt($i + 1);
  5745. }
  5746. }
  5747. $tokens[$newBraceIndex] = $tokenTmp;
  5748. $c = $tokens[$braceIndex]->getContent();
  5749. if (substr_count($c, "\n") > 1) {
  5750. $tokens[$braceIndex] = new Token([T_WHITESPACE, substr($c, strrpos($c, "\n"))]);
  5751. }
  5752. }
  5753. }
  5754. private function fixControlContinuationBraces(Tokens $tokens)
  5755. {
  5756. $controlContinuationTokens = $this->getControlContinuationTokens();
  5757. for ($index = count($tokens) - 1; 0 <= $index; --$index) {
  5758. $token = $tokens[$index];
  5759. if (!$token->isGivenKind($controlContinuationTokens)) {
  5760. continue;
  5761. }
  5762. $prevIndex = $tokens->getPrevNonWhitespace($index);
  5763. $prevToken = $tokens[$prevIndex];
  5764. if (!$prevToken->equals('}')) {
  5765. continue;
  5766. }
  5767. $tokens->ensureWhitespaceAtIndex(
  5768. $index - 1,
  5769. 1,
  5770. self::LINE_NEXT === $this->configuration['position_after_control_structures'] ?
  5771. $this->whitespacesConfig->getLineEnding().$this->detectIndent($tokens, $index)
  5772. : ' '
  5773. );
  5774. }
  5775. }
  5776. private function fixDoWhile(Tokens $tokens)
  5777. {
  5778. for ($index = count($tokens) - 1; 0 <= $index; --$index) {
  5779. $token = $tokens[$index];
  5780. if (!$token->isGivenKind(T_DO)) {
  5781. continue;
  5782. }
  5783. $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $index);
  5784. $startBraceIndex = $tokens->getNextNonWhitespace($parenthesisEndIndex);
  5785. $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startBraceIndex);
  5786. $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($endBraceIndex);
  5787. $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];
  5788. if (!$nextNonWhitespaceToken->isGivenKind(T_WHILE)) {
  5789. continue;
  5790. }
  5791. $tokens->ensureWhitespaceAtIndex($nextNonWhitespaceIndex - 1, 1, ' ');
  5792. }
  5793. }
  5794. private function fixIndents(Tokens $tokens)
  5795. {
  5796. $classyTokens = Token::getClassyTokenKinds();
  5797. $classyAndFunctionTokens = array_merge([T_FUNCTION], $classyTokens);
  5798. $controlTokens = $this->getControlTokens();
  5799. $indentTokens = array_filter(
  5800. array_merge($classyAndFunctionTokens, $controlTokens),
  5801. static function ($item) {
  5802. return T_SWITCH !== $item;
  5803. }
  5804. );
  5805. $tokensAnalyzer = new TokensAnalyzer($tokens);
  5806. for ($index = 0, $limit = count($tokens); $index < $limit; ++$index) {
  5807. $token = $tokens[$index];
  5808. if (!$token->isGivenKind($indentTokens)) {
  5809. continue;
  5810. }
  5811. if (
  5812. $token->isGivenKind(T_WHILE)
  5813. && $tokensAnalyzer->isWhilePartOfDoWhile($index)
  5814. ) {
  5815. continue;
  5816. }
  5817. if (
  5818. $this->configuration['allow_single_line_closure']
  5819. && $token->isGivenKind(T_FUNCTION)
  5820. && $tokensAnalyzer->isLambda($index)
  5821. ) {
  5822. $braceEndIndex = $tokens->findBlockEnd(
  5823. Tokens::BLOCK_TYPE_CURLY_BRACE,
  5824. $tokens->getNextTokenOfKind($index, ['{'])
  5825. );
  5826. if (!$this->isMultilined($tokens, $index, $braceEndIndex)) {
  5827. $index = $braceEndIndex;
  5828. continue;
  5829. }
  5830. }
  5831. if ($token->isGivenKind($classyAndFunctionTokens)) {
  5832. $startBraceIndex = $tokens->getNextTokenOfKind($index, [';', '{']);
  5833. $startBraceToken = $tokens[$startBraceIndex];
  5834. } else {
  5835. $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $index);
  5836. $startBraceIndex = $tokens->getNextNonWhitespace($parenthesisEndIndex);
  5837. $startBraceToken = $tokens[$startBraceIndex];
  5838. }
  5839. if (!$startBraceToken->equals('{')) {
  5840. continue;
  5841. }
  5842. $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startBraceIndex);
  5843. $indent = $this->detectIndent($tokens, $index);
  5844. $tokens->ensureWhitespaceAtIndex($endBraceIndex - 1, 1, $this->whitespacesConfig->getLineEnding().$indent);
  5845. $lastCommaIndex = $tokens->getPrevTokenOfKind($endBraceIndex - 1, [';', '}']);
  5846. $nestLevel = 1;
  5847. for ($nestIndex = $lastCommaIndex; $nestIndex >= $startBraceIndex; --$nestIndex) {
  5848. $nestToken = $tokens[$nestIndex];
  5849. if ($nestToken->equalsAny([')', [CT::T_BRACE_CLASS_INSTANTIATION_CLOSE]])) {
  5850. $nestIndex = $tokens->findBlockEnd(
  5851. $nestToken->equals(')') ? Tokens::BLOCK_TYPE_PARENTHESIS_BRACE : Tokens::BLOCK_TYPE_BRACE_CLASS_INSTANTIATION,
  5852. $nestIndex,
  5853. false
  5854. );
  5855. continue;
  5856. }
  5857. if (1 === $nestLevel) {
  5858. $nextLineCanBeIndented = false;
  5859. if ($nestToken->equalsAny([';', '}'])) {
  5860. $nextLineCanBeIndented = true;
  5861. } elseif ($this->isCommentWithFixableIndentation($tokens, $nestIndex)) {
  5862. for ($i = $nestIndex; $i > $startBraceIndex; --$i) {
  5863. if ($tokens[$i]->equalsAny([';', '}'])) {
  5864. $nextLineCanBeIndented = true;
  5865. break;
  5866. }
  5867. if (!$tokens[$i]->isWhitespace() && !$tokens[$i]->isComment()) {
  5868. break;
  5869. }
  5870. }
  5871. if ($nextLineCanBeIndented || $i === $startBraceIndex) {
  5872. $nextToken = $tokens[$nestIndex + 1];
  5873. $nextLineCanBeIndented = $nextToken->isWhitespace() && 1 === preg_match('/\R/', $nextToken->getContent());
  5874. }
  5875. }
  5876. if (!$nextLineCanBeIndented) {
  5877. continue;
  5878. }
  5879. $nextNonWhitespaceNestIndex = $tokens->getNextNonWhitespace($nestIndex);
  5880. $nextNonWhitespaceNestToken = $tokens[$nextNonWhitespaceNestIndex];
  5881. if (
  5882. !($nextNonWhitespaceNestToken->isComment() && (
  5883. !$tokens[$nextNonWhitespaceNestIndex - 1]->isWhitespace()
  5884. || !preg_match('/\R/', $tokens[$nextNonWhitespaceNestIndex - 1]->getContent())
  5885. )) &&
  5886. !($nestToken->equals('}') && $nextNonWhitespaceNestToken->equalsAny([';', ',', ']', [CT::T_ARRAY_SQUARE_BRACE_CLOSE]])) &&
  5887. !($nestToken->equals('}') && $nextNonWhitespaceNestToken->equals('(')) &&
  5888. !($nestToken->equals('}') && $tokens[$nestIndex - 1]->equalsAny(['"', "'", [T_CONSTANT_ENCAPSED_STRING]])) &&
  5889. !($tokens[$nestIndex - 1]->isGivenKind(T_END_HEREDOC) && $nextNonWhitespaceNestToken->isGivenKind(T_CLOSE_TAG))
  5890. ) {
  5891. if (
  5892. (
  5893. self::LINE_NEXT !== $this->configuration['position_after_control_structures']
  5894. && $nextNonWhitespaceNestToken->isGivenKind($this->getControlContinuationTokens())
  5895. && !$tokens[$tokens->getPrevNonWhitespace($nextNonWhitespaceNestIndex)]->isComment()
  5896. )
  5897. || $nextNonWhitespaceNestToken->isGivenKind(T_CLOSE_TAG)
  5898. || (
  5899. self::LINE_NEXT !== $this->configuration['position_after_control_structures']
  5900. && $nextNonWhitespaceNestToken->isGivenKind(T_WHILE)
  5901. && $tokensAnalyzer->isWhilePartOfDoWhile($nextNonWhitespaceNestIndex)
  5902. )
  5903. ) {
  5904. $whitespace = ' ';
  5905. } else {
  5906. $nextToken = $tokens[$nestIndex + 1];
  5907. $nextWhitespace = '';
  5908. if ($nextToken->isWhitespace()) {
  5909. $nextWhitespace = rtrim($nextToken->getContent(), " \t");
  5910. if ('' !== $nextWhitespace) {
  5911. $nextWhitespace = preg_replace(
  5912. sprintf('/%s$/', $this->whitespacesConfig->getLineEnding()),
  5913. '',
  5914. $nextWhitespace,
  5915. 1
  5916. );
  5917. }
  5918. }
  5919. $whitespace = $nextWhitespace.$this->whitespacesConfig->getLineEnding().$indent;
  5920. if (!$nextNonWhitespaceNestToken->equals('}')) {
  5921. $determineIsIndentableBlockContent = function ($contentIndex) use ($tokens) {
  5922. if (!$tokens[$contentIndex]->isComment()) {
  5923. return true;
  5924. }
  5925. if (!$tokens[$tokens->getPrevMeaningfulToken($contentIndex)]->equals(';')) {
  5926. return true;
  5927. }
  5928. $nextIndex = $tokens->getNextMeaningfulToken($contentIndex);
  5929. if (!$tokens[$nextIndex]->equals('}')) {
  5930. return true;
  5931. }
  5932. $nextNextIndex = $tokens->getNextMeaningfulToken($nextIndex);
  5933. if (null === $nextNextIndex) {
  5934. return true;
  5935. }
  5936. if ($tokens[$nextNextIndex]->equalsAny([
  5937. [T_ELSE],
  5938. [T_ELSEIF],
  5939. ',',
  5940. ])) {
  5941. return false;
  5942. }
  5943. return true;
  5944. };
  5945. if ($determineIsIndentableBlockContent($nestIndex + 2)) {
  5946. $whitespace .= $this->whitespacesConfig->getIndent();
  5947. }
  5948. }
  5949. }
  5950. $this->ensureWhitespaceAtIndexAndIndentMultilineComment($tokens, $nestIndex + 1, $whitespace);
  5951. }
  5952. }
  5953. if ($nestToken->equals('}')) {
  5954. ++$nestLevel;
  5955. continue;
  5956. }
  5957. if ($nestToken->equals('{')) {
  5958. --$nestLevel;
  5959. continue;
  5960. }
  5961. }
  5962. if (isset($tokens[$startBraceIndex + 2]) && $tokens[$startBraceIndex + 2]->equals('}')) {
  5963. $tokens->ensureWhitespaceAtIndex($startBraceIndex + 1, 0, $this->whitespacesConfig->getLineEnding().$indent);
  5964. } else {
  5965. $nextToken = $tokens[$startBraceIndex + 1];
  5966. $nextNonWhitespaceToken = $tokens[$tokens->getNextNonWhitespace($startBraceIndex)];
  5967. if (
  5968. !$nextNonWhitespaceToken->isComment()
  5969. || ($nextToken->isWhitespace() && 1 === substr_count($nextToken->getContent(), "\n"))
  5970. ) {
  5971. $this->ensureWhitespaceAtIndexAndIndentMultilineComment(
  5972. $tokens,
  5973. $startBraceIndex + 1,
  5974. $this->whitespacesConfig->getLineEnding().$indent.$this->whitespacesConfig->getIndent()
  5975. );
  5976. }
  5977. }
  5978. if ($token->isGivenKind($classyTokens) && !$tokensAnalyzer->isAnonymousClass($index)) {
  5979. if (self::LINE_SAME === $this->configuration['position_after_functions_and_oop_constructs'] && !$tokens[$tokens->getPrevNonWhitespace($startBraceIndex)]->isComment()) {
  5980. $ensuredWhitespace = ' ';
  5981. } else {
  5982. $ensuredWhitespace = $this->whitespacesConfig->getLineEnding().$indent;
  5983. }
  5984. $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, $ensuredWhitespace);
  5985. } elseif (
  5986. $token->isGivenKind(T_FUNCTION) && !$tokensAnalyzer->isLambda($index)
  5987. || (
  5988. self::LINE_NEXT === $this->configuration['position_after_control_structures'] && $token->isGivenKind($controlTokens)
  5989. || (
  5990. self::LINE_NEXT === $this->configuration['position_after_anonymous_constructs']
  5991. && (
  5992. $token->isGivenKind(T_FUNCTION) && $tokensAnalyzer->isLambda($index)
  5993. || $token->isGivenKind(T_CLASS) && $tokensAnalyzer->isAnonymousClass($index)
  5994. )
  5995. )
  5996. )
  5997. ) {
  5998. $isAnonymousClass = $token->isGivenKind($classyTokens) && $tokensAnalyzer->isAnonymousClass($index);
  5999. $closingParenthesisIndex = $tokens->getPrevTokenOfKind($startBraceIndex, [')']);
  6000. if (null === $closingParenthesisIndex && !$isAnonymousClass) {
  6001. continue;
  6002. }
  6003. if (!$isAnonymousClass) {
  6004. $prevToken = $tokens[$closingParenthesisIndex - 1];
  6005. }
  6006. if (!$isAnonymousClass && $prevToken->isWhitespace() && false !== strpos($prevToken->getContent(), "\n")) {
  6007. if (!$tokens[$startBraceIndex - 2]->isComment()) {
  6008. $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' ');
  6009. }
  6010. } else {
  6011. if (
  6012. self::LINE_SAME === $this->configuration['position_after_functions_and_oop_constructs']
  6013. && (
  6014. $token->isGivenKind([T_FUNCTION]) && !$tokensAnalyzer->isLambda($index)
  6015. || $token->isGivenKind($classyTokens) && !$tokensAnalyzer->isAnonymousClass($index)
  6016. )
  6017. && !$tokens[$tokens->getPrevNonWhitespace($startBraceIndex)]->isComment()
  6018. ) {
  6019. $ensuredWhitespace = ' ';
  6020. } else {
  6021. $ensuredWhitespace = $this->whitespacesConfig->getLineEnding().$indent;
  6022. }
  6023. $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, $ensuredWhitespace);
  6024. }
  6025. } else {
  6026. $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' ');
  6027. }
  6028. $limit = count($tokens);
  6029. }
  6030. }
  6031. private function fixMissingControlBraces(Tokens $tokens)
  6032. {
  6033. $controlTokens = $this->getControlTokens();
  6034. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  6035. $token = $tokens[$index];
  6036. if (!$token->isGivenKind($controlTokens)) {
  6037. continue;
  6038. }
  6039. $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $index);
  6040. $tokenAfterParenthesis = $tokens[$tokens->getNextMeaningfulToken($parenthesisEndIndex)];
  6041. if ($tokenAfterParenthesis->equals('{') && self::LINE_SAME === $this->configuration['position_after_control_structures']) {
  6042. $tokens->ensureWhitespaceAtIndex($parenthesisEndIndex + 1, 0, ' ');
  6043. continue;
  6044. }
  6045. if ($tokenAfterParenthesis->equalsAny([';', '{', ':'])) {
  6046. continue;
  6047. }
  6048. $statementEndIndex = $this->findStatementEnd($tokens, $parenthesisEndIndex);
  6049. $tokens->insertAt($statementEndIndex + 1, [new Token([T_WHITESPACE, ' ']), new Token('}')]);
  6050. if (!$tokens[$statementEndIndex]->equalsAny([';', '}'])) {
  6051. $tokens->insertAt($statementEndIndex + 1, new Token(';'));
  6052. }
  6053. $tokens->insertAt($parenthesisEndIndex + 1, new Token('{'));
  6054. $tokens->ensureWhitespaceAtIndex($parenthesisEndIndex + 1, 0, ' ');
  6055. }
  6056. }
  6057. private function fixSpaceAroundToken(Tokens $tokens)
  6058. {
  6059. $controlTokens = $this->getControlTokens();
  6060. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  6061. $token = $tokens[$index];
  6062. if ($token->isGivenKind(T_DECLARE)) {
  6063. $this->fixDeclareStatement($tokens, $index);
  6064. } elseif ($token->isGivenKind($controlTokens) || $token->isGivenKind(CT::T_USE_LAMBDA)) {
  6065. $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($index);
  6066. if (!$tokens[$nextNonWhitespaceIndex]->equals(':')) {
  6067. $tokens->ensureWhitespaceAtIndex(
  6068. $index + 1,
  6069. 0,
  6070. self::LINE_NEXT === $this->configuration['position_after_control_structures'] && !$tokens[$nextNonWhitespaceIndex]->equals('(') ?
  6071. $this->whitespacesConfig->getLineEnding().$this->detectIndent($tokens, $index)
  6072. : ' '
  6073. );
  6074. }
  6075. $prevToken = $tokens[$index - 1];
  6076. if (!$prevToken->isWhitespace() && !$prevToken->isComment() && !$prevToken->isGivenKind(T_OPEN_TAG)) {
  6077. $tokens->ensureWhitespaceAtIndex($index - 1, 1, ' ');
  6078. }
  6079. }
  6080. }
  6081. }
  6082. private function detectIndent(Tokens $tokens, $index)
  6083. {
  6084. while (true) {
  6085. $whitespaceIndex = $tokens->getPrevTokenOfKind($index, [[T_WHITESPACE]]);
  6086. if (null === $whitespaceIndex) {
  6087. return '';
  6088. }
  6089. $whitespaceToken = $tokens[$whitespaceIndex];
  6090. if (false !== strpos($whitespaceToken->getContent(), "\n")) {
  6091. break;
  6092. }
  6093. $prevToken = $tokens[$whitespaceIndex - 1];
  6094. if ($prevToken->isGivenKind([T_OPEN_TAG, T_COMMENT]) && "\n" === substr($prevToken->getContent(), -1)) {
  6095. break;
  6096. }
  6097. $index = $whitespaceIndex;
  6098. }
  6099. $explodedContent = explode("\n", $whitespaceToken->getContent());
  6100. return end($explodedContent);
  6101. }
  6102. private function findParenthesisEnd(Tokens $tokens, $structureTokenIndex)
  6103. {
  6104. $nextIndex = $tokens->getNextMeaningfulToken($structureTokenIndex);
  6105. $nextToken = $tokens[$nextIndex];
  6106. if (!$nextToken->equals('(')) {
  6107. return $structureTokenIndex;
  6108. }
  6109. return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextIndex);
  6110. }
  6111. private function findStatementEnd(Tokens $tokens, $parenthesisEndIndex)
  6112. {
  6113. $nextIndex = $tokens->getNextMeaningfulToken($parenthesisEndIndex);
  6114. $nextToken = $tokens[$nextIndex];
  6115. if (!$nextToken) {
  6116. return $parenthesisEndIndex;
  6117. }
  6118. if ($nextToken->equals('{')) {
  6119. return $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nextIndex);
  6120. }
  6121. if ($nextToken->isGivenKind($this->getControlTokens())) {
  6122. $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $nextIndex);
  6123. $endIndex = $this->findStatementEnd($tokens, $parenthesisEndIndex);
  6124. if ($nextToken->isGivenKind([T_IF, T_TRY, T_DO])) {
  6125. $openingTokenKind = $nextToken->getId();
  6126. while (true) {
  6127. $nextIndex = $tokens->getNextMeaningfulToken($endIndex);
  6128. $nextToken = isset($nextIndex) ? $tokens[$nextIndex] : null;
  6129. if ($nextToken && $nextToken->isGivenKind($this->getControlContinuationTokensForOpeningToken($openingTokenKind))) {
  6130. $parenthesisEndIndex = $this->findParenthesisEnd($tokens, $nextIndex);
  6131. $endIndex = $this->findStatementEnd($tokens, $parenthesisEndIndex);
  6132. if ($nextToken->isGivenKind($this->getFinalControlContinuationTokensForOpeningToken($openingTokenKind))) {
  6133. return $endIndex;
  6134. }
  6135. } else {
  6136. break;
  6137. }
  6138. }
  6139. }
  6140. return $endIndex;
  6141. }
  6142. $index = $parenthesisEndIndex;
  6143. while (true) {
  6144. $token = $tokens[++$index];
  6145. if ($token->equals('{')) {
  6146. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  6147. continue;
  6148. }
  6149. if ($token->equals(';')) {
  6150. return $index;
  6151. }
  6152. if ($token->isGivenKind(T_CLOSE_TAG)) {
  6153. return $tokens->getPrevNonWhitespace($index);
  6154. }
  6155. }
  6156. throw new \RuntimeException('Statement end not found.');
  6157. }
  6158. private function getControlTokens()
  6159. {
  6160. static $tokens = [
  6161. T_DECLARE,
  6162. T_DO,
  6163. T_ELSE,
  6164. T_ELSEIF,
  6165. T_FINALLY,
  6166. T_FOR,
  6167. T_FOREACH,
  6168. T_IF,
  6169. T_WHILE,
  6170. T_TRY,
  6171. T_CATCH,
  6172. T_SWITCH,
  6173. ];
  6174. return $tokens;
  6175. }
  6176. private function getControlContinuationTokens()
  6177. {
  6178. static $tokens = [
  6179. T_CATCH,
  6180. T_ELSE,
  6181. T_ELSEIF,
  6182. T_FINALLY,
  6183. ];
  6184. return $tokens;
  6185. }
  6186. private function getControlContinuationTokensForOpeningToken($openingTokenKind)
  6187. {
  6188. if (T_IF === $openingTokenKind) {
  6189. return [
  6190. T_ELSE,
  6191. T_ELSEIF,
  6192. ];
  6193. }
  6194. if (T_DO === $openingTokenKind) {
  6195. return [T_WHILE];
  6196. }
  6197. if (T_TRY === $openingTokenKind) {
  6198. return [
  6199. T_CATCH,
  6200. T_FINALLY,
  6201. ];
  6202. }
  6203. return [];
  6204. }
  6205. private function getFinalControlContinuationTokensForOpeningToken($openingTokenKind)
  6206. {
  6207. if (T_IF === $openingTokenKind) {
  6208. return [T_ELSE];
  6209. }
  6210. if (T_TRY === $openingTokenKind) {
  6211. return [T_FINALLY];
  6212. }
  6213. return [];
  6214. }
  6215. private function fixDeclareStatement(Tokens $tokens, $index)
  6216. {
  6217. $tokens->removeTrailingWhitespace($index);
  6218. $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(']);
  6219. $tokens->removeTrailingWhitespace($startParenthesisIndex);
  6220. $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex);
  6221. $tokens->removeLeadingWhitespace($endParenthesisIndex);
  6222. $startBraceIndex = $tokens->getNextTokenOfKind($endParenthesisIndex, [';', '{']);
  6223. $startBraceToken = $tokens[$startBraceIndex];
  6224. if ($startBraceToken->equals('{')) {
  6225. $this->fixSingleLineWhitespaceForDeclare($tokens, $startBraceIndex);
  6226. }
  6227. }
  6228. private function fixSingleLineWhitespaceForDeclare(Tokens $tokens, $startBraceIndex)
  6229. {
  6230. if (
  6231. !$tokens[$startBraceIndex - 1]->isWhitespace() ||
  6232. $tokens[$startBraceIndex - 1]->isWhitespace(" \t")
  6233. ) {
  6234. $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' ');
  6235. }
  6236. }
  6237. private function ensureWhitespaceAtIndexAndIndentMultilineComment(Tokens $tokens, $index, $whitespace)
  6238. {
  6239. if ($tokens[$index]->isWhitespace()) {
  6240. $nextTokenIndex = $tokens->getNextNonWhitespace($index);
  6241. } else {
  6242. $nextTokenIndex = $index;
  6243. }
  6244. $nextToken = $tokens[$nextTokenIndex];
  6245. if ($nextToken->isComment()) {
  6246. $previousToken = $tokens[$nextTokenIndex - 1];
  6247. if (
  6248. (0 === strpos($nextToken->getContent(), '//'.$this->whitespacesConfig->getIndent()) || '//' === $nextToken->getContent())
  6249. && $previousToken->isWhitespace() && 1 === preg_match('/\R$/', $previousToken->getContent())
  6250. ) {
  6251. return;
  6252. }
  6253. $tokens[$nextTokenIndex] = new Token([
  6254. $nextToken->getId(),
  6255. preg_replace(
  6256. '/(\R)'.$this->detectIndent($tokens, $nextTokenIndex).'/',
  6257. '$1'.preg_replace('/^.*\R([ \t]*)$/s', '$1', $whitespace),
  6258. $nextToken->getContent()
  6259. ),
  6260. ]);
  6261. }
  6262. $tokens->ensureWhitespaceAtIndex($index, 0, $whitespace);
  6263. }
  6264. private function isMultilined(Tokens $tokens, $startParenthesisIndex, $endParenthesisIndex)
  6265. {
  6266. for ($i = $startParenthesisIndex; $i < $endParenthesisIndex; ++$i) {
  6267. if (false !== strpos($tokens[$i]->getContent(), "\n")) {
  6268. return true;
  6269. }
  6270. }
  6271. return false;
  6272. }
  6273. private function isCommentWithFixableIndentation(Tokens $tokens, $index)
  6274. {
  6275. if (!$tokens[$index]->isComment()) {
  6276. return false;
  6277. }
  6278. if (0 === strpos($tokens[$index]->getContent(), '/*')) {
  6279. return true;
  6280. }
  6281. $firstCommentIndex = $index;
  6282. while (true) {
  6283. $i = $this->getSiblingContinuousSingleLineComment($tokens, $firstCommentIndex, false);
  6284. if (null === $i) {
  6285. break;
  6286. }
  6287. $firstCommentIndex = $i;
  6288. }
  6289. $lastCommentIndex = $index;
  6290. while (true) {
  6291. $i = $this->getSiblingContinuousSingleLineComment($tokens, $lastCommentIndex, true);
  6292. if (null === $i) {
  6293. break;
  6294. }
  6295. $lastCommentIndex = $i;
  6296. }
  6297. if ($firstCommentIndex === $lastCommentIndex) {
  6298. return true;
  6299. }
  6300. for ($i = $firstCommentIndex + 1; $i < $lastCommentIndex; ++$i) {
  6301. if (!$tokens[$i]->isWhitespace() && !$tokens[$i]->isComment()) {
  6302. return false;
  6303. }
  6304. }
  6305. return true;
  6306. }
  6307. private function getSiblingContinuousSingleLineComment(Tokens $tokens, $index, $after)
  6308. {
  6309. $siblingIndex = $index;
  6310. do {
  6311. if ($after) {
  6312. $siblingIndex = $tokens->getNextTokenOfKind($siblingIndex, [[T_COMMENT]]);
  6313. } else {
  6314. $siblingIndex = $tokens->getPrevTokenOfKind($siblingIndex, [[T_COMMENT]]);
  6315. }
  6316. if (null === $siblingIndex) {
  6317. return null;
  6318. }
  6319. } while (0 === strpos($tokens[$siblingIndex]->getContent(), '/*'));
  6320. $newLines = 0;
  6321. for ($i = min($siblingIndex, $index) + 1, $max = max($siblingIndex, $index); $i < $max; ++$i) {
  6322. if ($tokens[$i]->isWhitespace() && preg_match('/\R/', $tokens[$i]->getContent())) {
  6323. if (1 === $newLines || preg_match('/\R.*\R/', $tokens[$i]->getContent())) {
  6324. return null;
  6325. }
  6326. ++$newLines;
  6327. }
  6328. }
  6329. return $siblingIndex;
  6330. }
  6331. }
  6332. <?php
  6333. namespace PhpCsFixer\Fixer\Basic;
  6334. use PhpCsFixer\AbstractFixer;
  6335. use PhpCsFixer\FixerDefinition\CodeSample;
  6336. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6337. use PhpCsFixer\Tokenizer\Token;
  6338. use PhpCsFixer\Tokenizer\Tokens;
  6339. final class EncodingFixer extends AbstractFixer
  6340. {
  6341. private $BOM;
  6342. public function __construct()
  6343. {
  6344. parent::__construct();
  6345. $this->BOM = pack('CCC', 0xef, 0xbb, 0xbf);
  6346. }
  6347. public function getDefinition()
  6348. {
  6349. return new FixerDefinition(
  6350. 'PHP code MUST use only UTF-8 without BOM (remove BOM).',
  6351. [
  6352. new CodeSample(
  6353. $this->BOM.'<?php
  6354. echo "Hello!";
  6355. '
  6356. ),
  6357. ]
  6358. );
  6359. }
  6360. public function getPriority()
  6361. {
  6362. return 100;
  6363. }
  6364. public function isCandidate(Tokens $tokens)
  6365. {
  6366. return true;
  6367. }
  6368. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6369. {
  6370. $content = $tokens[0]->getContent();
  6371. if (0 === strncmp($content, $this->BOM, 3)) {
  6372. $newContent = substr($content, 3);
  6373. if (false === $newContent) {
  6374. $newContent = '';
  6375. }
  6376. if ('' === $newContent) {
  6377. $tokens->clearAt(0);
  6378. } else {
  6379. $tokens[0] = new Token([$tokens[0]->getId(), $newContent]);
  6380. }
  6381. }
  6382. }
  6383. }
  6384. <?php
  6385. namespace PhpCsFixer\Fixer\Basic;
  6386. use PhpCsFixer\AbstractFixer;
  6387. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  6388. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  6389. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  6390. use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException;
  6391. use PhpCsFixer\FixerDefinition\CodeSample;
  6392. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6393. use PhpCsFixer\FixerDefinition\VersionSpecification;
  6394. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  6395. use PhpCsFixer\Tokenizer\Token;
  6396. use PhpCsFixer\Tokenizer\Tokens;
  6397. use Symfony\Component\OptionsResolver\Options;
  6398. final class NonPrintableCharacterFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  6399. {
  6400. private $symbolsReplace;
  6401. private static $tokens = [
  6402. T_STRING_VARNAME,
  6403. T_INLINE_HTML,
  6404. T_VARIABLE,
  6405. T_COMMENT,
  6406. T_ENCAPSED_AND_WHITESPACE,
  6407. T_CONSTANT_ENCAPSED_STRING,
  6408. T_DOC_COMMENT,
  6409. ];
  6410. public function __construct()
  6411. {
  6412. parent::__construct();
  6413. $this->symbolsReplace = [
  6414. pack('H*', 'e2808b') => ['', '200b'],
  6415. pack('H*', 'e28087') => [' ', '2007'],
  6416. pack('H*', 'e280af') => [' ', '202f'],
  6417. pack('H*', 'e281a0') => ['', '2060'],
  6418. pack('H*', 'c2a0') => [' ', 'a0'],
  6419. ];
  6420. }
  6421. public function getDefinition()
  6422. {
  6423. return new FixerDefinition(
  6424. 'Remove Zero-width space (ZWSP), Non-breaking space (NBSP) and other invisible unicode symbols.',
  6425. [
  6426. new CodeSample(
  6427. '<?php echo "'.pack('H*', 'e2808b').'Hello'.pack('H*', 'e28087').'World'.pack('H*', 'c2a0')."!\";\n"
  6428. ),
  6429. new VersionSpecificCodeSample(
  6430. '<?php echo "'.pack('H*', 'e2808b').'Hello'.pack('H*', 'e28087').'World'.pack('H*', 'c2a0')."!\";\n",
  6431. new VersionSpecification(70000),
  6432. ['use_escape_sequences_in_strings' => true]
  6433. ),
  6434. ],
  6435. null,
  6436. 'Risky when strings contain intended invisible characters.'
  6437. );
  6438. }
  6439. public function isRisky()
  6440. {
  6441. return true;
  6442. }
  6443. public function isCandidate(Tokens $tokens)
  6444. {
  6445. return count($tokens) > 1 && $tokens->isAnyTokenKindsFound(self::$tokens);
  6446. }
  6447. protected function createConfigurationDefinition()
  6448. {
  6449. return new FixerConfigurationResolver([
  6450. (new FixerOptionBuilder('use_escape_sequences_in_strings', 'Whether characters should be replaced with escape sequences in strings.'))
  6451. ->setAllowedTypes(['bool'])
  6452. ->setDefault(false)
  6453. ->setNormalizer(static function (Options $options, $value) {
  6454. if (PHP_VERSION_ID < 70000 && $value) {
  6455. throw new InvalidOptionsForEnvException('Escape sequences require PHP 7.0+.');
  6456. }
  6457. return $value;
  6458. })
  6459. ->getOption(),
  6460. ]);
  6461. }
  6462. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6463. {
  6464. $replacements = [];
  6465. $escapeSequences = [];
  6466. foreach ($this->symbolsReplace as $character => list($replacement, $codepoint)) {
  6467. $replacements[$character] = $replacement;
  6468. $escapeSequences[$character] = '\u{'.$codepoint.'}';
  6469. }
  6470. foreach ($tokens as $index => $token) {
  6471. $content = $token->getContent();
  6472. if (
  6473. $this->configuration['use_escape_sequences_in_strings']
  6474. && $token->isGivenKind([T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE])
  6475. ) {
  6476. if (!preg_match('/'.implode('|', array_keys($escapeSequences)).'/', $content)) {
  6477. continue;
  6478. }
  6479. $previousToken = $tokens[$index - 1];
  6480. $stringTypeChanged = false;
  6481. if ($previousToken->isGivenKind(T_START_HEREDOC)) {
  6482. $previousTokenContent = $previousToken->getContent();
  6483. if (false !== strpos($previousTokenContent, '\'')) {
  6484. $tokens[$index - 1] = new Token([T_START_HEREDOC, str_replace('\'', '', $previousTokenContent)]);
  6485. $stringTypeChanged = true;
  6486. }
  6487. } elseif ("'" === $content[0]) {
  6488. $content = preg_replace('/^\'(.*)\'$/', '"$1"', $content);
  6489. $stringTypeChanged = true;
  6490. }
  6491. if ($stringTypeChanged) {
  6492. $content = preg_replace('/([\\\\$])/', '\\\\$1', $content);
  6493. }
  6494. $tokens[$index] = new Token([$token->getId(), strtr($content, $escapeSequences)]);
  6495. continue;
  6496. }
  6497. if ($token->isGivenKind(self::$tokens)) {
  6498. $tokens[$index] = new Token([$token->getId(), strtr($content, $replacements)]);
  6499. }
  6500. }
  6501. }
  6502. }
  6503. <?php
  6504. namespace PhpCsFixer\Fixer\Basic;
  6505. use PhpCsFixer\AbstractPsrAutoloadingFixer;
  6506. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  6507. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  6508. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  6509. use PhpCsFixer\FixerDefinition\FileSpecificCodeSample;
  6510. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6511. use PhpCsFixer\Tokenizer\Token;
  6512. use PhpCsFixer\Tokenizer\Tokens;
  6513. final class Psr0Fixer extends AbstractPsrAutoloadingFixer implements ConfigurationDefinitionFixerInterface
  6514. {
  6515. public function getDefinition()
  6516. {
  6517. return new FixerDefinition(
  6518. 'Classes must be in a path that matches their namespace, be at least one namespace deep and the class name should match the file name.',
  6519. [
  6520. new FileSpecificCodeSample(
  6521. '<?php
  6522. namespace PhpCsFixer\FIXER\Basic;
  6523. class InvalidName {}
  6524. ',
  6525. new \SplFileInfo(__FILE__)
  6526. ),
  6527. new FileSpecificCodeSample(
  6528. '<?php
  6529. namespace PhpCsFixer\FIXER\Basic;
  6530. class InvalidName {}
  6531. ',
  6532. new \SplFileInfo(__FILE__),
  6533. ['dir' => realpath(__DIR__.'/../..')]
  6534. ),
  6535. ],
  6536. null,
  6537. 'This fixer may change your class name, which will break the code that is depended on old name.'
  6538. );
  6539. }
  6540. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6541. {
  6542. $namespace = false;
  6543. $namespaceIndex = 0;
  6544. $namespaceEndIndex = 0;
  6545. $classyName = null;
  6546. $classyIndex = 0;
  6547. foreach ($tokens as $index => $token) {
  6548. if ($token->isGivenKind(T_NAMESPACE)) {
  6549. if (false !== $namespace) {
  6550. return;
  6551. }
  6552. $namespaceIndex = $tokens->getNextMeaningfulToken($index);
  6553. $namespaceEndIndex = $tokens->getNextTokenOfKind($index, [';']);
  6554. $namespace = trim($tokens->generatePartialCode($namespaceIndex, $namespaceEndIndex - 1));
  6555. } elseif ($token->isClassy()) {
  6556. if (null !== $classyName) {
  6557. return;
  6558. }
  6559. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  6560. if ($prevToken->isGivenKind(T_NEW)) {
  6561. return;
  6562. }
  6563. $classyIndex = $tokens->getNextMeaningfulToken($index);
  6564. $classyName = $tokens[$classyIndex]->getContent();
  6565. }
  6566. }
  6567. if (null === $classyName) {
  6568. return;
  6569. }
  6570. if (false !== $namespace) {
  6571. $normNamespace = str_replace('\\', '/', $namespace);
  6572. $path = str_replace('\\', '/', $file->getRealPath());
  6573. $dir = dirname($path);
  6574. if ('' !== $this->configuration['dir']) {
  6575. $dir = substr($dir, strlen(realpath($this->configuration['dir'])) + 1);
  6576. if (false === $dir) {
  6577. $dir = '';
  6578. }
  6579. if (strlen($normNamespace) > strlen($dir)) {
  6580. if ('' !== $dir) {
  6581. $normNamespace = substr($normNamespace, -strlen($dir));
  6582. } else {
  6583. $normNamespace = '';
  6584. }
  6585. }
  6586. }
  6587. $dir = substr($dir, -strlen($normNamespace));
  6588. if (false === $dir) {
  6589. $dir = '';
  6590. }
  6591. $filename = basename($path, '.php');
  6592. if ($classyName !== $filename) {
  6593. $tokens[$classyIndex] = new Token([T_STRING, $filename]);
  6594. }
  6595. if ($normNamespace !== $dir && strtolower($normNamespace) === strtolower($dir)) {
  6596. for ($i = $namespaceIndex; $i <= $namespaceEndIndex; ++$i) {
  6597. $tokens->clearAt($i);
  6598. }
  6599. $namespace = substr($namespace, 0, -strlen($dir)).str_replace('/', '\\', $dir);
  6600. $newNamespace = Tokens::fromCode('<?php namespace '.$namespace.';');
  6601. $newNamespace->clearRange(0, 2);
  6602. $newNamespace->clearEmptyTokens();
  6603. $tokens->insertAt($namespaceIndex, $newNamespace);
  6604. }
  6605. } else {
  6606. $normClass = str_replace('_', '/', $classyName);
  6607. $path = str_replace('\\', '/', $file->getRealPath());
  6608. $filename = substr($path, -strlen($normClass) - 4, -4);
  6609. if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
  6610. $tokens[$classyIndex] = new Token([T_STRING, str_replace('/', '_', $filename)]);
  6611. }
  6612. }
  6613. }
  6614. protected function createConfigurationDefinition()
  6615. {
  6616. return new FixerConfigurationResolver([
  6617. (new FixerOptionBuilder('dir', 'The directory where the project code is placed.'))
  6618. ->setAllowedTypes(['string'])
  6619. ->setDefault('')
  6620. ->getOption(),
  6621. ]);
  6622. }
  6623. }
  6624. <?php
  6625. namespace PhpCsFixer\Fixer\Basic;
  6626. use PhpCsFixer\AbstractPsrAutoloadingFixer;
  6627. use PhpCsFixer\FixerDefinition\FileSpecificCodeSample;
  6628. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6629. use PhpCsFixer\Tokenizer\Token;
  6630. use PhpCsFixer\Tokenizer\Tokens;
  6631. final class Psr4Fixer extends AbstractPsrAutoloadingFixer
  6632. {
  6633. public function getDefinition()
  6634. {
  6635. return new FixerDefinition(
  6636. 'Class names should match the file name.',
  6637. [
  6638. new FileSpecificCodeSample(
  6639. '<?php
  6640. namespace PhpCsFixer\FIXER\Basic;
  6641. class InvalidName {}
  6642. ',
  6643. new \SplFileInfo(__FILE__)
  6644. ),
  6645. ],
  6646. null,
  6647. 'This fixer may change your class name, which will break the code that is depended on old name.'
  6648. );
  6649. }
  6650. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6651. {
  6652. $namespace = false;
  6653. $classyName = null;
  6654. $classyIndex = 0;
  6655. foreach ($tokens as $index => $token) {
  6656. if ($token->isGivenKind(T_NAMESPACE)) {
  6657. if (false !== $namespace) {
  6658. return;
  6659. }
  6660. $namespace = true;
  6661. } elseif ($token->isClassy()) {
  6662. if (null !== $classyName) {
  6663. return;
  6664. }
  6665. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  6666. if ($prevToken->isGivenKind(T_NEW)) {
  6667. return;
  6668. }
  6669. $classyIndex = $tokens->getNextMeaningfulToken($index);
  6670. $classyName = $tokens[$classyIndex]->getContent();
  6671. }
  6672. }
  6673. if (null === $classyName) {
  6674. return;
  6675. }
  6676. if (false !== $namespace) {
  6677. $filename = basename(str_replace('\\', '/', $file->getRealPath()), '.php');
  6678. if ($classyName !== $filename) {
  6679. $tokens[$classyIndex] = new Token([T_STRING, $filename]);
  6680. }
  6681. } else {
  6682. $normClass = str_replace('_', '/', $classyName);
  6683. $filename = substr(str_replace('\\', '/', $file->getRealPath()), -strlen($normClass) - 4, -4);
  6684. if ($normClass !== $filename && strtolower($normClass) === strtolower($filename)) {
  6685. $tokens[$classyIndex] = new Token([T_STRING, str_replace('/', '_', $filename)]);
  6686. }
  6687. }
  6688. }
  6689. }
  6690. <?php
  6691. namespace PhpCsFixer\Fixer\Casing;
  6692. use PhpCsFixer\AbstractFixer;
  6693. use PhpCsFixer\FixerDefinition\CodeSample;
  6694. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6695. use PhpCsFixer\Tokenizer\CT;
  6696. use PhpCsFixer\Tokenizer\Token;
  6697. use PhpCsFixer\Tokenizer\Tokens;
  6698. final class LowercaseConstantsFixer extends AbstractFixer
  6699. {
  6700. public function getDefinition()
  6701. {
  6702. return new FixerDefinition(
  6703. 'The PHP constants `true`, `false`, and `null` MUST be in lower case.',
  6704. [new CodeSample("<?php\n\$a = FALSE;\n\$b = True;\n\$c = nuLL;\n")]
  6705. );
  6706. }
  6707. public function isCandidate(Tokens $tokens)
  6708. {
  6709. return $tokens->isTokenKindFound(T_STRING);
  6710. }
  6711. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6712. {
  6713. foreach ($tokens as $index => $token) {
  6714. if (!$token->isNativeConstant()) {
  6715. continue;
  6716. }
  6717. if (
  6718. $this->isNeighbourAccepted($tokens, $tokens->getPrevMeaningfulToken($index)) &&
  6719. $this->isNeighbourAccepted($tokens, $tokens->getNextMeaningfulToken($index))
  6720. ) {
  6721. $tokens[$index] = new Token([$token->getId(), strtolower($token->getContent())]);
  6722. }
  6723. }
  6724. }
  6725. private function isNeighbourAccepted(Tokens $tokens, $index)
  6726. {
  6727. static $forbiddenTokens = [
  6728. T_AS,
  6729. T_CLASS,
  6730. T_CONST,
  6731. T_EXTENDS,
  6732. T_IMPLEMENTS,
  6733. T_INSTANCEOF,
  6734. T_INSTEADOF,
  6735. T_INTERFACE,
  6736. T_NEW,
  6737. T_NS_SEPARATOR,
  6738. T_PAAMAYIM_NEKUDOTAYIM,
  6739. T_TRAIT,
  6740. T_USE,
  6741. CT::T_USE_TRAIT,
  6742. CT::T_USE_LAMBDA,
  6743. ];
  6744. $token = $tokens[$index];
  6745. if ($token->equalsAny(['{', '}'])) {
  6746. return false;
  6747. }
  6748. return !$token->isGivenKind($forbiddenTokens);
  6749. }
  6750. }
  6751. <?php
  6752. namespace PhpCsFixer\Fixer\Casing;
  6753. use PhpCsFixer\AbstractFixer;
  6754. use PhpCsFixer\FixerDefinition\CodeSample;
  6755. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6756. use PhpCsFixer\Tokenizer\Token;
  6757. use PhpCsFixer\Tokenizer\Tokens;
  6758. final class LowercaseKeywordsFixer extends AbstractFixer
  6759. {
  6760. private static $excludedTokens = [T_HALT_COMPILER];
  6761. public function getDefinition()
  6762. {
  6763. return new FixerDefinition(
  6764. 'PHP keywords MUST be in lower case.',
  6765. [
  6766. new CodeSample(
  6767. '<?php
  6768. FOREACH($a AS $B) {
  6769. TRY {
  6770. NEW $C($a, ISSET($B));
  6771. WHILE($B) {
  6772. INCLUDE "test.php";
  6773. }
  6774. } CATCH(\Exception $e) {
  6775. EXIT(1);
  6776. }
  6777. }
  6778. '
  6779. ),
  6780. ]
  6781. );
  6782. }
  6783. public function isCandidate(Tokens $tokens)
  6784. {
  6785. return $tokens->isAnyTokenKindsFound(Token::getKeywords());
  6786. }
  6787. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6788. {
  6789. foreach ($tokens as $index => $token) {
  6790. if ($token->isKeyword() && !$token->isGivenKind(self::$excludedTokens)) {
  6791. $tokens[$index] = new Token([$token->getId(), strtolower($token->getContent())]);
  6792. }
  6793. }
  6794. }
  6795. }
  6796. <?php
  6797. namespace PhpCsFixer\Fixer\Casing;
  6798. use PhpCsFixer\AbstractFixer;
  6799. use PhpCsFixer\FixerDefinition\CodeSample;
  6800. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6801. use PhpCsFixer\Tokenizer\CT;
  6802. use PhpCsFixer\Tokenizer\Token;
  6803. use PhpCsFixer\Tokenizer\Tokens;
  6804. final class MagicConstantCasingFixer extends AbstractFixer
  6805. {
  6806. public function getDefinition()
  6807. {
  6808. return new FixerDefinition(
  6809. 'Magic constants should be referred to using the correct casing.',
  6810. [new CodeSample("<?php\necho __dir__;\n")]
  6811. );
  6812. }
  6813. public function isCandidate(Tokens $tokens)
  6814. {
  6815. return $tokens->isAnyTokenKindsFound($this->getMagicConstantTokens());
  6816. }
  6817. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6818. {
  6819. $magicConstants = $this->getMagicConstants();
  6820. $magicConstantTokens = $this->getMagicConstantTokens();
  6821. foreach ($tokens as $index => $token) {
  6822. if ($token->isGivenKind($magicConstantTokens)) {
  6823. $tokens[$index] = new Token([$token->getId(), $magicConstants[$token->getId()]]);
  6824. }
  6825. }
  6826. }
  6827. private function getMagicConstants()
  6828. {
  6829. static $magicConstants = null;
  6830. if (null === $magicConstants) {
  6831. $magicConstants = [
  6832. T_LINE => '__LINE__',
  6833. T_FILE => '__FILE__',
  6834. T_DIR => '__DIR__',
  6835. T_FUNC_C => '__FUNCTION__',
  6836. T_CLASS_C => '__CLASS__',
  6837. T_METHOD_C => '__METHOD__',
  6838. T_NS_C => '__NAMESPACE__',
  6839. CT::T_CLASS_CONSTANT => 'class',
  6840. T_TRAIT_C => '__TRAIT__',
  6841. ];
  6842. }
  6843. return $magicConstants;
  6844. }
  6845. private function getMagicConstantTokens()
  6846. {
  6847. static $magicConstantTokens = null;
  6848. if (null === $magicConstantTokens) {
  6849. $magicConstantTokens = array_keys($this->getMagicConstants());
  6850. }
  6851. return $magicConstantTokens;
  6852. }
  6853. }
  6854. <?php
  6855. namespace PhpCsFixer\Fixer\Casing;
  6856. use PhpCsFixer\AbstractFixer;
  6857. use PhpCsFixer\FixerDefinition\CodeSample;
  6858. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6859. use PhpCsFixer\Tokenizer\Token;
  6860. use PhpCsFixer\Tokenizer\Tokens;
  6861. final class NativeFunctionCasingFixer extends AbstractFixer
  6862. {
  6863. public function getDefinition()
  6864. {
  6865. return new FixerDefinition(
  6866. 'Function defined by PHP should be called using the correct casing.',
  6867. [new CodeSample("<?php\nSTRLEN(\$str);\n")]
  6868. );
  6869. }
  6870. public function isCandidate(Tokens $tokens)
  6871. {
  6872. return $tokens->isTokenKindFound(T_STRING);
  6873. }
  6874. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6875. {
  6876. static $nativeFunctionNames = null;
  6877. if (null === $nativeFunctionNames) {
  6878. $nativeFunctionNames = $this->getNativeFunctionNames();
  6879. }
  6880. for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
  6881. if (!$tokens[$index]->isGivenKind(T_STRING)) {
  6882. continue;
  6883. }
  6884. $next = $tokens->getNextMeaningfulToken($index);
  6885. if (!$tokens[$next]->equals('(')) {
  6886. $index = $next;
  6887. continue;
  6888. }
  6889. $functionNamePrefix = $tokens->getPrevMeaningfulToken($index);
  6890. if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION])) {
  6891. continue;
  6892. }
  6893. if ($tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)) {
  6894. $prev = $tokens->getPrevMeaningfulToken($functionNamePrefix);
  6895. if ($tokens[$prev]->isGivenKind([T_STRING, T_NEW])) {
  6896. continue;
  6897. }
  6898. }
  6899. $lower = strtolower($tokens[$index]->getContent());
  6900. if (!array_key_exists($lower, $nativeFunctionNames)) {
  6901. continue;
  6902. }
  6903. $tokens[$index] = new Token([T_STRING, $nativeFunctionNames[$lower]]);
  6904. $index = $next;
  6905. }
  6906. }
  6907. private function getNativeFunctionNames()
  6908. {
  6909. $allFunctions = get_defined_functions();
  6910. $functions = [];
  6911. foreach ($allFunctions['internal'] as $function) {
  6912. $functions[strtolower($function)] = $function;
  6913. }
  6914. return $functions;
  6915. }
  6916. }
  6917. <?php
  6918. namespace PhpCsFixer\Fixer\CastNotation;
  6919. use PhpCsFixer\AbstractFixer;
  6920. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  6921. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  6922. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  6923. use PhpCsFixer\FixerDefinition\CodeSample;
  6924. use PhpCsFixer\FixerDefinition\FixerDefinition;
  6925. use PhpCsFixer\Tokenizer\Token;
  6926. use PhpCsFixer\Tokenizer\Tokens;
  6927. final class CastSpacesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  6928. {
  6929. const INSIDE_CAST_SPACE_REPLACE_MAP = [
  6930. ' ' => '',
  6931. "\t" => '',
  6932. "\n" => '',
  6933. "\r" => '',
  6934. "\0" => '',
  6935. "\x0B" => '',
  6936. ];
  6937. public function getDefinition()
  6938. {
  6939. return new FixerDefinition(
  6940. 'A single space or none should be between cast and variable.',
  6941. [
  6942. new CodeSample(
  6943. "<?php\n\$bar = ( string ) \$a;\n\$foo = (int)\$b;\n"
  6944. ),
  6945. new CodeSample(
  6946. "<?php\n\$bar = ( string ) \$a;\n\$foo = (int)\$b;\n",
  6947. ['space' => 'single']
  6948. ),
  6949. new CodeSample(
  6950. "<?php\n\$bar = ( string ) \$a;\n\$foo = (int) \$b;\n",
  6951. ['space' => 'none']
  6952. ),
  6953. ]
  6954. );
  6955. }
  6956. public function getPriority()
  6957. {
  6958. return -10;
  6959. }
  6960. public function isCandidate(Tokens $tokens)
  6961. {
  6962. return $tokens->isAnyTokenKindsFound(Token::getCastTokenKinds());
  6963. }
  6964. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  6965. {
  6966. foreach ($tokens as $index => $token) {
  6967. if (!$token->isCast()) {
  6968. continue;
  6969. }
  6970. $tokens[$index] = new Token([
  6971. $token->getId(),
  6972. strtr($token->getContent(), self::INSIDE_CAST_SPACE_REPLACE_MAP),
  6973. ]);
  6974. if ('single' === $this->configuration['space']) {
  6975. if ($tokens[$index + 1]->isWhitespace(" \t")) {
  6976. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  6977. } elseif (!$tokens[$index + 1]->isWhitespace()) {
  6978. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  6979. }
  6980. continue;
  6981. }
  6982. if ($tokens[$index + 1]->isWhitespace()) {
  6983. $tokens->clearAt($index + 1);
  6984. }
  6985. }
  6986. }
  6987. protected function createConfigurationDefinition()
  6988. {
  6989. return new FixerConfigurationResolver([
  6990. (new FixerOptionBuilder('space', 'spacing to apply between cast and variable.'))
  6991. ->setAllowedValues(['none', 'single'])
  6992. ->setDefault('single')
  6993. ->getOption(),
  6994. ]);
  6995. }
  6996. }
  6997. <?php
  6998. namespace PhpCsFixer\Fixer\CastNotation;
  6999. use PhpCsFixer\AbstractFixer;
  7000. use PhpCsFixer\FixerDefinition\CodeSample;
  7001. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7002. use PhpCsFixer\Tokenizer\Token;
  7003. use PhpCsFixer\Tokenizer\Tokens;
  7004. final class LowercaseCastFixer extends AbstractFixer
  7005. {
  7006. public function getDefinition()
  7007. {
  7008. return new FixerDefinition(
  7009. 'Cast should be written in lower case.',
  7010. [
  7011. new CodeSample(
  7012. '<?php
  7013. $a = (BOOLEAN) $b;
  7014. $a = (BOOL) $b;
  7015. $a = (INTEGER) $b;
  7016. $a = (INT) $b;
  7017. $a = (DOUBLE) $b;
  7018. $a = (FLoaT) $b;
  7019. $a = (reaL) $b;
  7020. $a = (flOAT) $b;
  7021. $a = (sTRING) $b;
  7022. $a = (ARRAy) $b;
  7023. $a = (OBJect) $b;
  7024. $a = (UNset) $b;
  7025. $a = (Binary) $b;
  7026. '
  7027. ),
  7028. ]
  7029. );
  7030. }
  7031. public function isCandidate(Tokens $tokens)
  7032. {
  7033. return $tokens->isAnyTokenKindsFound(Token::getCastTokenKinds());
  7034. }
  7035. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7036. {
  7037. for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
  7038. if (!$tokens[$index]->isCast()) {
  7039. continue;
  7040. }
  7041. $tokens[$index] = new Token([$tokens[$index]->getId(), strtolower($tokens[$index]->getContent())]);
  7042. }
  7043. }
  7044. }
  7045. <?php
  7046. namespace PhpCsFixer\Fixer\CastNotation;
  7047. use PhpCsFixer\AbstractFunctionReferenceFixer;
  7048. use PhpCsFixer\FixerDefinition\CodeSample;
  7049. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7050. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  7051. use PhpCsFixer\Tokenizer\Token;
  7052. use PhpCsFixer\Tokenizer\Tokens;
  7053. final class ModernizeTypesCastingFixer extends AbstractFunctionReferenceFixer
  7054. {
  7055. public function getDefinition()
  7056. {
  7057. return new FixerDefinition(
  7058. 'Replaces `intval`, `floatval`, `doubleval`, `strval` and `boolval` function calls with according type casting operator.',
  7059. [
  7060. new CodeSample(
  7061. '<?php
  7062. $a = intval($b);
  7063. $a = floatval($b);
  7064. $a = doubleval($b);
  7065. $a = strval ($b);
  7066. $a = boolval($b);
  7067. '
  7068. ),
  7069. ],
  7070. null,
  7071. 'Risky if any of the functions `intval`, `floatval`, `doubleval`, `strval` or `boolval` are overridden.'
  7072. );
  7073. }
  7074. public function isCandidate(Tokens $tokens)
  7075. {
  7076. return $tokens->isTokenKindFound(T_STRING);
  7077. }
  7078. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7079. {
  7080. static $replacement = [
  7081. 'intval' => [T_INT_CAST, '(int)'],
  7082. 'floatval' => [T_DOUBLE_CAST, '(float)'],
  7083. 'doubleval' => [T_DOUBLE_CAST, '(float)'],
  7084. 'strval' => [T_STRING_CAST, '(string)'],
  7085. 'boolval' => [T_BOOL_CAST, '(bool)'],
  7086. ];
  7087. $argumentsAnalyzer = new ArgumentsAnalyzer();
  7088. foreach ($replacement as $functionIdentity => $newToken) {
  7089. $currIndex = 0;
  7090. while (null !== $currIndex) {
  7091. $boundaries = $this->find($functionIdentity, $tokens, $currIndex, $tokens->count() - 1);
  7092. if (null === $boundaries) {
  7093. continue 2;
  7094. }
  7095. list($functionName, $openParenthesis, $closeParenthesis) = $boundaries;
  7096. $currIndex = $openParenthesis;
  7097. if (1 !== $argumentsAnalyzer->countArguments($tokens, $openParenthesis, $closeParenthesis)) {
  7098. continue;
  7099. }
  7100. $countParamTokens = 0;
  7101. for ($paramContentIndex = $openParenthesis + 1; $paramContentIndex < $closeParenthesis; ++$paramContentIndex) {
  7102. if (!$tokens[$paramContentIndex]->isGivenKind(T_WHITESPACE)) {
  7103. ++$countParamTokens;
  7104. }
  7105. }
  7106. $preserveParenthesises = $countParamTokens > 1;
  7107. $prevTokenIndex = $tokens->getPrevMeaningfulToken($functionName);
  7108. if ($tokens[$prevTokenIndex]->isGivenKind(T_NS_SEPARATOR)) {
  7109. $tokens->removeTrailingWhitespace($prevTokenIndex);
  7110. $tokens->clearAt($prevTokenIndex);
  7111. }
  7112. $replacementSequence = [
  7113. new Token($newToken),
  7114. new Token([T_WHITESPACE, ' ']),
  7115. ];
  7116. if (!$preserveParenthesises) {
  7117. $tokens->removeLeadingWhitespace($closeParenthesis);
  7118. $tokens->clearAt($closeParenthesis);
  7119. $tokens->removeLeadingWhitespace($openParenthesis);
  7120. $tokens->removeTrailingWhitespace($openParenthesis);
  7121. $tokens->clearAt($openParenthesis);
  7122. } else {
  7123. $tokens->removeTrailingWhitespace($functionName);
  7124. }
  7125. $tokens->overrideRange($functionName, $functionName, $replacementSequence);
  7126. $currIndex = $functionName;
  7127. }
  7128. }
  7129. }
  7130. }
  7131. <?php
  7132. namespace PhpCsFixer\Fixer\CastNotation;
  7133. use PhpCsFixer\AbstractFixer;
  7134. use PhpCsFixer\FixerDefinition\CodeSample;
  7135. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7136. use PhpCsFixer\Tokenizer\Token;
  7137. use PhpCsFixer\Tokenizer\Tokens;
  7138. final class NoShortBoolCastFixer extends AbstractFixer
  7139. {
  7140. public function getPriority()
  7141. {
  7142. return -9;
  7143. }
  7144. public function getDefinition()
  7145. {
  7146. return new FixerDefinition(
  7147. 'Short cast `bool` using double exclamation mark should not be used.',
  7148. [new CodeSample("<?php\n\$a = !!\$b;\n")]
  7149. );
  7150. }
  7151. public function isCandidate(Tokens $tokens)
  7152. {
  7153. return $tokens->isTokenKindFound('!');
  7154. }
  7155. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7156. {
  7157. for ($index = count($tokens) - 1; $index > 1; --$index) {
  7158. if ($tokens[$index]->equals('!')) {
  7159. $index = $this->fixShortCast($tokens, $index);
  7160. }
  7161. }
  7162. }
  7163. private function fixShortCast(Tokens $tokens, $index)
  7164. {
  7165. for ($i = $index - 1; $i > 1; --$i) {
  7166. if ($tokens[$i]->equals('!')) {
  7167. $this->fixShortCastToBoolCast($tokens, $i, $index);
  7168. break;
  7169. }
  7170. if (!$tokens[$i]->isComment() && !$tokens[$i]->isWhitespace()) {
  7171. break;
  7172. }
  7173. }
  7174. return $i;
  7175. }
  7176. private function fixShortCastToBoolCast(Tokens $tokens, $start, $end)
  7177. {
  7178. for (; $start <= $end; ++$start) {
  7179. if (
  7180. !$tokens[$start]->isComment()
  7181. && !($tokens[$start]->isWhitespace() && $tokens[$start - 1]->isComment())
  7182. ) {
  7183. $tokens->clearAt($start);
  7184. }
  7185. }
  7186. $tokens->insertAt($start, new Token([T_BOOL_CAST, '(bool)']));
  7187. }
  7188. }
  7189. <?php
  7190. namespace PhpCsFixer\Fixer\CastNotation;
  7191. use PhpCsFixer\AbstractFixer;
  7192. use PhpCsFixer\FixerDefinition\CodeSample;
  7193. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7194. use PhpCsFixer\Tokenizer\Token;
  7195. use PhpCsFixer\Tokenizer\Tokens;
  7196. final class ShortScalarCastFixer extends AbstractFixer
  7197. {
  7198. public function getDefinition()
  7199. {
  7200. return new FixerDefinition(
  7201. 'Cast `(boolean)` and `(integer)` should be written as `(bool)` and `(int)`, `(double)` and `(real)` as `(float)`.',
  7202. [new CodeSample("<?php\n\$a = (boolean) \$b;\n\$a = (integer) \$b;\n\$a = (double) \$b;\n\$a = (real) \$b;\n")]
  7203. );
  7204. }
  7205. public function isCandidate(Tokens $tokens)
  7206. {
  7207. return $tokens->isAnyTokenKindsFound(Token::getCastTokenKinds());
  7208. }
  7209. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7210. {
  7211. static $castMap = [
  7212. 'boolean' => 'bool',
  7213. 'integer' => 'int',
  7214. 'double' => 'float',
  7215. 'real' => 'float',
  7216. ];
  7217. for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
  7218. if (!$tokens[$index]->isCast()) {
  7219. continue;
  7220. }
  7221. $castFrom = trim(substr($tokens[$index]->getContent(), 1, -1));
  7222. $castFromLowered = strtolower($castFrom);
  7223. if (!array_key_exists($castFromLowered, $castMap)) {
  7224. continue;
  7225. }
  7226. $tokens[$index] = new Token([
  7227. $tokens[$index]->getId(),
  7228. str_replace($castFrom, $castMap[$castFromLowered], $tokens[$index]->getContent()),
  7229. ]);
  7230. }
  7231. }
  7232. }
  7233. <?php
  7234. namespace PhpCsFixer\Fixer\ClassNotation;
  7235. use PhpCsFixer\AbstractFixer;
  7236. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  7237. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  7238. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  7239. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  7240. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  7241. use PhpCsFixer\FixerDefinition\CodeSample;
  7242. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7243. use PhpCsFixer\Tokenizer\Token;
  7244. use PhpCsFixer\Tokenizer\Tokens;
  7245. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  7246. use SplFileInfo;
  7247. final class ClassAttributesSeparationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  7248. {
  7249. private $classElementTypes = [];
  7250. public function configure(array $configuration = null)
  7251. {
  7252. parent::configure($configuration);
  7253. $this->classElementTypes = [];
  7254. foreach ($this->configuration['elements'] as $element) {
  7255. $this->classElementTypes[$element] = true;
  7256. }
  7257. }
  7258. public function getDefinition()
  7259. {
  7260. return new FixerDefinition(
  7261. 'Class, trait and interface elements must be separated with one blank line.',
  7262. [
  7263. new CodeSample(
  7264. '<?php
  7265. final class Sample
  7266. {
  7267. protected function foo()
  7268. {
  7269. }
  7270. protected function bar()
  7271. {
  7272. }
  7273. }
  7274. '
  7275. ),
  7276. new CodeSample(
  7277. '<?php
  7278. class Sample
  7279. {private $a; // a is awesome
  7280. /** second in a hour */
  7281. private $b;
  7282. }
  7283. ',
  7284. ['elements' => ['property']]
  7285. ),
  7286. new CodeSample(
  7287. '<?php
  7288. class Sample
  7289. {
  7290. const A = 1;
  7291. /** seconds in some hours */
  7292. const B = 3600;
  7293. }
  7294. ',
  7295. ['elements' => ['const']]
  7296. ),
  7297. ]
  7298. );
  7299. }
  7300. public function getPriority()
  7301. {
  7302. return 55;
  7303. }
  7304. public function isCandidate(Tokens $tokens)
  7305. {
  7306. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  7307. }
  7308. protected function applyFix(SplFileInfo $file, Tokens $tokens)
  7309. {
  7310. $tokensAnalyzer = new TokensAnalyzer($tokens);
  7311. $class = $classStart = $classEnd = false;
  7312. foreach (array_reverse($tokensAnalyzer->getClassyElements(), true) as $index => $element) {
  7313. if (!isset($this->classElementTypes[$element['type']])) {
  7314. continue;
  7315. }
  7316. if ($element['classIndex'] !== $class) {
  7317. $class = $element['classIndex'];
  7318. $classStart = $tokens->getNextTokenOfKind($class, ['{']);
  7319. $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classStart);
  7320. }
  7321. if ('method' === $element['type'] && !$tokens[$class]->isGivenKind(T_INTERFACE)) {
  7322. $attributes = $tokensAnalyzer->getMethodAttributes($index);
  7323. $methodEnd = true === $attributes['abstract']
  7324. ? $tokens->getNextTokenOfKind($index, [';'])
  7325. : $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $tokens->getNextTokenOfKind($index, ['{']))
  7326. ;
  7327. $this->fixSpaceBelowClassMethod($tokens, $classEnd, $methodEnd);
  7328. $this->fixSpaceAboveClassElement($tokens, $classStart, $index);
  7329. continue;
  7330. }
  7331. $this->fixSpaceBelowClassElement($tokens, $classEnd, $tokens->getNextTokenOfKind($index, [';']));
  7332. $this->fixSpaceAboveClassElement($tokens, $classStart, $index);
  7333. }
  7334. }
  7335. protected function createConfigurationDefinition()
  7336. {
  7337. $types = ['const', 'method', 'property'];
  7338. return new FixerConfigurationResolver([
  7339. (new FixerOptionBuilder('elements', sprintf('List of classy elements; \'%s\'.', implode("', '", $types))))
  7340. ->setAllowedTypes(['array'])
  7341. ->setAllowedValues([
  7342. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf($types),
  7343. ])
  7344. ->setDefault(['const', 'method', 'property'])
  7345. ->getOption(),
  7346. ]);
  7347. }
  7348. private function fixSpaceBelowClassElement(Tokens $tokens, $classEndIndex, $elementEndIndex)
  7349. {
  7350. for ($nextNotWhite = $elementEndIndex + 1;; ++$nextNotWhite) {
  7351. if (($tokens[$nextNotWhite]->isComment() || $tokens[$nextNotWhite]->isWhitespace()) && false === strpos($tokens[$nextNotWhite]->getContent(), "\n")) {
  7352. continue;
  7353. }
  7354. break;
  7355. }
  7356. if ($tokens[$nextNotWhite]->isWhitespace()) {
  7357. $nextNotWhite = $tokens->getNextNonWhitespace($nextNotWhite);
  7358. }
  7359. $this->correctLineBreaks($tokens, $elementEndIndex, $nextNotWhite, $nextNotWhite === $classEndIndex ? 1 : 2);
  7360. }
  7361. private function fixSpaceBelowClassMethod(Tokens $tokens, $classEndIndex, $elementEndIndex)
  7362. {
  7363. $nextNotWhite = $tokens->getNextNonWhitespace($elementEndIndex);
  7364. $this->correctLineBreaks($tokens, $elementEndIndex, $nextNotWhite, $nextNotWhite === $classEndIndex ? 1 : 2);
  7365. }
  7366. private function fixSpaceAboveClassElement(Tokens $tokens, $classStartIndex, $elementIndex)
  7367. {
  7368. static $methodAttr = [T_PRIVATE, T_PROTECTED, T_PUBLIC, T_ABSTRACT, T_FINAL, T_STATIC];
  7369. $firstElementAttributeIndex = $elementIndex;
  7370. for ($i = $elementIndex; $i > $classStartIndex; --$i) {
  7371. $nonWhiteAbove = $tokens->getNonWhitespaceSibling($i, -1);
  7372. if (null !== $nonWhiteAbove && $tokens[$nonWhiteAbove]->isGivenKind($methodAttr)) {
  7373. $firstElementAttributeIndex = $nonWhiteAbove;
  7374. } else {
  7375. break;
  7376. }
  7377. }
  7378. if ($tokens[$nonWhiteAbove]->isGivenKind(T_COMMENT)) {
  7379. if (1 === $firstElementAttributeIndex - $nonWhiteAbove) {
  7380. $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1);
  7381. return;
  7382. }
  7383. if (substr_count($tokens[$nonWhiteAbove + 1]->getContent(), "\n") > 1) {
  7384. $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 2);
  7385. return;
  7386. }
  7387. if ($tokens[$nonWhiteAbove - 1]->isWhitespace() && substr_count($tokens[$nonWhiteAbove - 1]->getContent(), "\n") > 0) {
  7388. $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1);
  7389. $nonWhiteAbove = $this->findCommentBlockStart($tokens, $nonWhiteAbove);
  7390. $nonWhiteAboveComment = $tokens->getNonWhitespaceSibling($nonWhiteAbove, -1);
  7391. $this->correctLineBreaks($tokens, $nonWhiteAboveComment, $nonWhiteAbove, $nonWhiteAboveComment === $classStartIndex ? 1 : 2);
  7392. } else {
  7393. $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 2);
  7394. }
  7395. return;
  7396. }
  7397. if (false === $tokens[$nonWhiteAbove]->isGivenKind(T_DOC_COMMENT)) {
  7398. $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, $nonWhiteAbove === $classStartIndex ? 1 : 2);
  7399. return;
  7400. }
  7401. $this->correctLineBreaks($tokens, $nonWhiteAbove, $firstElementAttributeIndex, 1);
  7402. $nonWhiteAbovePHPDoc = $tokens->getNonWhitespaceSibling($nonWhiteAbove, -1);
  7403. $this->correctLineBreaks($tokens, $nonWhiteAbovePHPDoc, $nonWhiteAbove, $nonWhiteAbovePHPDoc === $classStartIndex ? 1 : 2);
  7404. }
  7405. private function correctLineBreaks(Tokens $tokens, $startIndex, $endIndex, $reqLineCount = 2)
  7406. {
  7407. $lineEnding = $this->whitespacesConfig->getLineEnding();
  7408. ++$startIndex;
  7409. $numbOfWhiteTokens = $endIndex - $startIndex;
  7410. if (0 === $numbOfWhiteTokens) {
  7411. $tokens->insertAt($startIndex, new Token([T_WHITESPACE, str_repeat($lineEnding, $reqLineCount)]));
  7412. return;
  7413. }
  7414. $lineBreakCount = $this->getLineBreakCount($tokens, $startIndex, $endIndex);
  7415. if ($reqLineCount === $lineBreakCount) {
  7416. return;
  7417. }
  7418. if ($lineBreakCount < $reqLineCount) {
  7419. $tokens[$startIndex] = new Token([
  7420. T_WHITESPACE,
  7421. str_repeat($lineEnding, $reqLineCount - $lineBreakCount).$tokens[$startIndex]->getContent(),
  7422. ]);
  7423. return;
  7424. }
  7425. if (1 === $numbOfWhiteTokens) {
  7426. $tokens[$startIndex] = new Token([
  7427. T_WHITESPACE,
  7428. preg_replace('/\r\n|\n/', '', $tokens[$startIndex]->getContent(), $lineBreakCount - $reqLineCount),
  7429. ]);
  7430. return;
  7431. }
  7432. $toReplaceCount = $lineBreakCount - $reqLineCount;
  7433. for ($i = $startIndex; $i < $endIndex && $toReplaceCount > 0; ++$i) {
  7434. $tokenLineCount = substr_count($tokens[$i]->getContent(), "\n");
  7435. if ($tokenLineCount > 0) {
  7436. $tokens[$i] = new Token([
  7437. T_WHITESPACE,
  7438. preg_replace('/\r\n|\n/', '', $tokens[$i]->getContent(), min($toReplaceCount, $tokenLineCount)),
  7439. ]);
  7440. $toReplaceCount -= $tokenLineCount;
  7441. }
  7442. }
  7443. }
  7444. private function getLineBreakCount(Tokens $tokens, $whiteSpaceStartIndex, $whiteSpaceEndIndex)
  7445. {
  7446. $lineCount = 0;
  7447. for ($i = $whiteSpaceStartIndex; $i < $whiteSpaceEndIndex; ++$i) {
  7448. $lineCount += substr_count($tokens[$i]->getContent(), "\n");
  7449. }
  7450. return $lineCount;
  7451. }
  7452. private function findCommentBlockStart(Tokens $tokens, $commentIndex)
  7453. {
  7454. $start = $commentIndex;
  7455. for ($i = $commentIndex - 1; $i > 0; --$i) {
  7456. if ($tokens[$i]->isComment()) {
  7457. $start = $i;
  7458. continue;
  7459. }
  7460. if (!$tokens[$i]->isWhitespace() || $this->getLineBreakCount($tokens, $i, $i + 1) > 1) {
  7461. break;
  7462. }
  7463. }
  7464. return $start;
  7465. }
  7466. }
  7467. <?php
  7468. namespace PhpCsFixer\Fixer\ClassNotation;
  7469. use PhpCsFixer\AbstractFixer;
  7470. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  7471. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  7472. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  7473. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  7474. use PhpCsFixer\FixerDefinition\CodeSample;
  7475. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7476. use PhpCsFixer\FixerDefinition\VersionSpecification;
  7477. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  7478. use PhpCsFixer\Tokenizer\Token;
  7479. use PhpCsFixer\Tokenizer\Tokens;
  7480. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  7481. final class ClassDefinitionFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  7482. {
  7483. public function getDefinition()
  7484. {
  7485. return new FixerDefinition(
  7486. 'Whitespace around the keywords of a class, trait or interfaces definition should be one space.',
  7487. [
  7488. new CodeSample(
  7489. '<?php
  7490. class Foo extends Bar implements Baz, BarBaz
  7491. {
  7492. }
  7493. final class Foo extends Bar implements Baz, BarBaz
  7494. {
  7495. }
  7496. trait Foo
  7497. {
  7498. }
  7499. '
  7500. ),
  7501. new VersionSpecificCodeSample(
  7502. '<?php
  7503. $foo = new class extends Bar implements Baz, BarBaz {};
  7504. ',
  7505. new VersionSpecification(70100)
  7506. ),
  7507. new CodeSample(
  7508. '<?php
  7509. class Foo
  7510. extends Bar
  7511. implements Baz, BarBaz
  7512. {}
  7513. ',
  7514. ['singleLine' => true]
  7515. ),
  7516. new CodeSample(
  7517. '<?php
  7518. class Foo
  7519. extends Bar
  7520. implements Baz
  7521. {}
  7522. ',
  7523. ['singleItemSingleLine' => true]
  7524. ),
  7525. new CodeSample(
  7526. '<?php
  7527. interface Bar extends
  7528. Bar, BarBaz, FooBarBaz
  7529. {}
  7530. ',
  7531. ['multiLineExtendsEachSingleLine' => true]
  7532. ),
  7533. ]
  7534. );
  7535. }
  7536. public function isCandidate(Tokens $tokens)
  7537. {
  7538. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  7539. }
  7540. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7541. {
  7542. for ($index = $tokens->getSize() - 4; $index > 0; --$index) {
  7543. if ($tokens[$index]->isClassy()) {
  7544. $this->fixClassyDefinition($tokens, $index);
  7545. }
  7546. }
  7547. }
  7548. protected function createConfigurationDefinition()
  7549. {
  7550. return new FixerConfigurationResolver([
  7551. (new FixerOptionBuilder('multiLineExtendsEachSingleLine', 'Whether definitions should be multiline.'))
  7552. ->setAllowedTypes(['bool'])
  7553. ->setDefault(false)
  7554. ->getOption(),
  7555. (new FixerOptionBuilder('singleItemSingleLine', 'Whether definitions should be single line when including a single item.'))
  7556. ->setAllowedTypes(['bool'])
  7557. ->setDefault(false)
  7558. ->getOption(),
  7559. (new FixerOptionBuilder('singleLine', 'Whether definitions should be single line.'))
  7560. ->setAllowedTypes(['bool'])
  7561. ->setDefault(false)
  7562. ->getOption(),
  7563. ]);
  7564. }
  7565. private function fixClassyDefinition(Tokens $tokens, $classyIndex)
  7566. {
  7567. $classDefInfo = $this->getClassyDefinitionInfo($tokens, $classyIndex);
  7568. if (false !== $classDefInfo['implements']) {
  7569. $classDefInfo['implements'] = $this->fixClassyDefinitionImplements(
  7570. $tokens,
  7571. $classDefInfo['open'],
  7572. $classDefInfo['implements']
  7573. );
  7574. }
  7575. if (false !== $classDefInfo['extends']) {
  7576. $classDefInfo['extends'] = $this->fixClassyDefinitionExtends(
  7577. $tokens,
  7578. false === $classDefInfo['implements'] ? $classDefInfo['open'] : $classDefInfo['implements']['start'],
  7579. $classDefInfo['extends']
  7580. );
  7581. }
  7582. $classDefInfo['open'] = $this->fixClassyDefinitionOpenSpacing($tokens, $classDefInfo);
  7583. if ($classDefInfo['implements']) {
  7584. $end = $classDefInfo['implements']['start'];
  7585. } elseif ($classDefInfo['extends']) {
  7586. $end = $classDefInfo['extends']['start'];
  7587. } else {
  7588. $end = $tokens->getPrevNonWhitespace($classDefInfo['open']);
  7589. }
  7590. $this->makeClassyDefinitionSingleLine(
  7591. $tokens,
  7592. $classDefInfo['anonymousClass'] ? $tokens->getPrevMeaningfulToken($classyIndex) : $classDefInfo['start'],
  7593. $end
  7594. );
  7595. }
  7596. private function fixClassyDefinitionExtends(Tokens $tokens, $classOpenIndex, $classExtendsInfo)
  7597. {
  7598. $endIndex = $tokens->getPrevNonWhitespace($classOpenIndex);
  7599. if ($this->configuration['singleLine'] || false === $classExtendsInfo['multiLine']) {
  7600. $this->makeClassyDefinitionSingleLine($tokens, $classExtendsInfo['start'], $endIndex);
  7601. $classExtendsInfo['multiLine'] = false;
  7602. } elseif ($this->configuration['singleItemSingleLine'] && 1 === $classExtendsInfo['numberOfExtends']) {
  7603. $this->makeClassyDefinitionSingleLine($tokens, $classExtendsInfo['start'], $endIndex);
  7604. $classExtendsInfo['multiLine'] = false;
  7605. } elseif ($this->configuration['multiLineExtendsEachSingleLine'] && $classExtendsInfo['multiLine']) {
  7606. $this->makeClassyInheritancePartMultiLine($tokens, $classExtendsInfo['start'], $endIndex);
  7607. $classExtendsInfo['multiLine'] = true;
  7608. }
  7609. return $classExtendsInfo;
  7610. }
  7611. private function fixClassyDefinitionImplements(Tokens $tokens, $classOpenIndex, array $classImplementsInfo)
  7612. {
  7613. $endIndex = $tokens->getPrevNonWhitespace($classOpenIndex);
  7614. if ($this->configuration['singleLine'] || false === $classImplementsInfo['multiLine']) {
  7615. $this->makeClassyDefinitionSingleLine($tokens, $classImplementsInfo['start'], $endIndex);
  7616. $classImplementsInfo['multiLine'] = false;
  7617. } elseif ($this->configuration['singleItemSingleLine'] && 1 === $classImplementsInfo['numberOfImplements']) {
  7618. $this->makeClassyDefinitionSingleLine($tokens, $classImplementsInfo['start'], $endIndex);
  7619. $classImplementsInfo['multiLine'] = false;
  7620. } else {
  7621. $this->makeClassyInheritancePartMultiLine($tokens, $classImplementsInfo['start'], $endIndex);
  7622. $classImplementsInfo['multiLine'] = true;
  7623. }
  7624. return $classImplementsInfo;
  7625. }
  7626. private function fixClassyDefinitionOpenSpacing(Tokens $tokens, $classDefInfo)
  7627. {
  7628. if ($classDefInfo['anonymousClass']) {
  7629. if (false !== $classDefInfo['implements']) {
  7630. $spacing = $classDefInfo['implements']['multiLine'] ? $spacing = $this->whitespacesConfig->getLineEnding() : ' ';
  7631. } elseif (false !== $classDefInfo['extends']) {
  7632. $spacing = $classDefInfo['extends']['multiLine'] ? $spacing = $this->whitespacesConfig->getLineEnding() : ' ';
  7633. } else {
  7634. $spacing = ' ';
  7635. }
  7636. } else {
  7637. $spacing = $this->whitespacesConfig->getLineEnding();
  7638. }
  7639. $openIndex = $tokens->getNextTokenOfKind($classDefInfo['classy'], ['{']);
  7640. if (' ' !== $spacing && false !== strpos($tokens[$openIndex - 1]->getContent(), "\n")) {
  7641. return $openIndex;
  7642. }
  7643. if ($tokens[$openIndex - 1]->isWhitespace()) {
  7644. if (' ' !== $spacing || !$tokens[$tokens->getPrevNonWhitespace($openIndex - 1)]->isComment()) {
  7645. $tokens[$openIndex - 1] = new Token([T_WHITESPACE, $spacing]);
  7646. }
  7647. return $openIndex;
  7648. }
  7649. $tokens->insertAt($openIndex, new Token([T_WHITESPACE, $spacing]));
  7650. return $openIndex + 1;
  7651. }
  7652. private function getClassyDefinitionInfo(Tokens $tokens, $classyIndex)
  7653. {
  7654. $openIndex = $tokens->getNextTokenOfKind($classyIndex, ['{']);
  7655. $prev = $tokens->getPrevMeaningfulToken($classyIndex);
  7656. $startIndex = $tokens[$prev]->isGivenKind([T_FINAL, T_ABSTRACT]) ? $prev : $classyIndex;
  7657. $extends = false;
  7658. $implements = false;
  7659. $anonymousClass = false;
  7660. if (!$tokens[$classyIndex]->isGivenKind(T_TRAIT)) {
  7661. $extends = $tokens->findGivenKind(T_EXTENDS, $classyIndex, $openIndex);
  7662. $extends = count($extends) ? $this->getClassyInheritanceInfo($tokens, key($extends), 'numberOfExtends') : false;
  7663. if (!$tokens[$classyIndex]->isGivenKind(T_INTERFACE)) {
  7664. $implements = $tokens->findGivenKind(T_IMPLEMENTS, $classyIndex, $openIndex);
  7665. $implements = count($implements) ? $this->getClassyInheritanceInfo($tokens, key($implements), 'numberOfImplements') : false;
  7666. $tokensAnalyzer = new TokensAnalyzer($tokens);
  7667. $anonymousClass = $tokensAnalyzer->isAnonymousClass($classyIndex);
  7668. }
  7669. }
  7670. return [
  7671. 'start' => $startIndex,
  7672. 'classy' => $classyIndex,
  7673. 'open' => $openIndex,
  7674. 'extends' => $extends,
  7675. 'implements' => $implements,
  7676. 'anonymousClass' => $anonymousClass,
  7677. ];
  7678. }
  7679. private function getClassyInheritanceInfo(Tokens $tokens, $startIndex, $label)
  7680. {
  7681. $implementsInfo = ['start' => $startIndex, $label => 1, 'multiLine' => false];
  7682. ++$startIndex;
  7683. $endIndex = $tokens->getNextTokenOfKind($startIndex, ['{', [T_IMPLEMENTS], [T_EXTENDS]]);
  7684. $endIndex = $tokens[$endIndex]->equals('{') ? $tokens->getPrevNonWhitespace($endIndex) : $endIndex;
  7685. for ($i = $startIndex; $i < $endIndex; ++$i) {
  7686. if ($tokens[$i]->equals(',')) {
  7687. ++$implementsInfo[$label];
  7688. continue;
  7689. }
  7690. if (!$implementsInfo['multiLine'] && false !== strpos($tokens[$i]->getContent(), "\n")) {
  7691. $implementsInfo['multiLine'] = true;
  7692. }
  7693. }
  7694. return $implementsInfo;
  7695. }
  7696. private function makeClassyDefinitionSingleLine(Tokens $tokens, $startIndex, $endIndex)
  7697. {
  7698. for ($i = $endIndex; $i >= $startIndex; --$i) {
  7699. if ($tokens[$i]->isWhitespace()) {
  7700. $prevNonWhite = $tokens->getPrevNonWhitespace($i);
  7701. $nextNonWhite = $tokens->getNextNonWhitespace($i);
  7702. if ($tokens[$prevNonWhite]->isComment() || $tokens[$nextNonWhite]->isComment()) {
  7703. $content = $tokens[$prevNonWhite]->getContent();
  7704. if (!('#' === $content || '//' === substr($content, 0, 2))) {
  7705. $content = $tokens[$nextNonWhite]->getContent();
  7706. if (!('#' === $content || '//' === substr($content, 0, 2))) {
  7707. $tokens[$i] = new Token([T_WHITESPACE, ' ']);
  7708. }
  7709. }
  7710. continue;
  7711. }
  7712. if ($tokens[$i + 1]->equalsAny([',', '(', ')']) || $tokens[$i - 1]->equals('(')) {
  7713. $tokens->clearAt($i);
  7714. continue;
  7715. }
  7716. $tokens[$i] = new Token([T_WHITESPACE, ' ']);
  7717. continue;
  7718. }
  7719. if ($tokens[$i]->equals(',') && !$tokens[$i + 1]->isWhitespace()) {
  7720. $tokens->insertAt($i + 1, new Token([T_WHITESPACE, ' ']));
  7721. continue;
  7722. }
  7723. if (!$tokens[$i]->isComment()) {
  7724. continue;
  7725. }
  7726. if (!$tokens[$i + 1]->isWhitespace() && !$tokens[$i + 1]->isComment() && false === strpos($tokens[$i]->getContent(), "\n")) {
  7727. $tokens->insertAt($i + 1, new Token([T_WHITESPACE, ' ']));
  7728. }
  7729. if (!$tokens[$i - 1]->isWhitespace() && !$tokens[$i - 1]->isComment()) {
  7730. $tokens->insertAt($i, new Token([T_WHITESPACE, ' ']));
  7731. }
  7732. }
  7733. }
  7734. private function makeClassyInheritancePartMultiLine(Tokens $tokens, $startIndex, $endIndex)
  7735. {
  7736. for ($i = $endIndex; $i > $startIndex; --$i) {
  7737. $previousInterfaceImplementingIndex = $tokens->getPrevTokenOfKind($i, [',', [T_IMPLEMENTS], [T_EXTENDS]]);
  7738. $breakAtIndex = $tokens->getNextMeaningfulToken($previousInterfaceImplementingIndex);
  7739. $this->makeClassyDefinitionSingleLine(
  7740. $tokens,
  7741. $breakAtIndex,
  7742. $i
  7743. );
  7744. $isOnOwnLine = false;
  7745. for ($j = $breakAtIndex; $j > $previousInterfaceImplementingIndex; --$j) {
  7746. if (false !== strpos($tokens[$j]->getContent(), "\n")) {
  7747. $isOnOwnLine = true;
  7748. break;
  7749. }
  7750. }
  7751. if (!$isOnOwnLine) {
  7752. if ($tokens[$breakAtIndex - 1]->isWhitespace()) {
  7753. $tokens[$breakAtIndex - 1] = new Token([
  7754. T_WHITESPACE,
  7755. $this->whitespacesConfig->getLineEnding().$this->whitespacesConfig->getIndent(),
  7756. ]);
  7757. } else {
  7758. $tokens->insertAt($breakAtIndex, new Token([T_WHITESPACE, $this->whitespacesConfig->getLineEnding().$this->whitespacesConfig->getIndent()]));
  7759. }
  7760. }
  7761. $i = $previousInterfaceImplementingIndex + 1;
  7762. }
  7763. }
  7764. }
  7765. <?php
  7766. namespace PhpCsFixer\Fixer\ClassNotation;
  7767. use PhpCsFixer\AbstractFixer;
  7768. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  7769. use PhpCsFixer\DocBlock\DocBlock;
  7770. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  7771. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  7772. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  7773. use PhpCsFixer\FixerDefinition\CodeSample;
  7774. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7775. use PhpCsFixer\Tokenizer\Token;
  7776. use PhpCsFixer\Tokenizer\Tokens;
  7777. use Symfony\Component\OptionsResolver\Options;
  7778. final class FinalInternalClassFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  7779. {
  7780. public function configure(array $configuration = null)
  7781. {
  7782. parent::configure($configuration);
  7783. $intersect = array_intersect_assoc(
  7784. $this->configuration['annotation-white-list'],
  7785. $this->configuration['annotation-black-list']
  7786. );
  7787. if (count($intersect)) {
  7788. throw new InvalidFixerConfigurationException($this->getName(), sprintf('Annotation cannot be used in both the white- and black list, got duplicates: "%s".', implode('", "', array_keys($intersect))));
  7789. }
  7790. }
  7791. public function getDefinition()
  7792. {
  7793. return new FixerDefinition(
  7794. 'Internal classes should be `final`.',
  7795. [
  7796. new CodeSample("<?php\n/**\n * @internal\n */\nclass Sample\n{\n}\n"),
  7797. new CodeSample(
  7798. "<?php\n/** @CUSTOM */class A{}\n",
  7799. [
  7800. 'annotation-white-list' => ['@Custom'],
  7801. ]
  7802. ),
  7803. ],
  7804. null,
  7805. 'Changing classes to `final` might cause code execution to break.'
  7806. );
  7807. }
  7808. public function isCandidate(Tokens $tokens)
  7809. {
  7810. return $tokens->isAllTokenKindsFound([T_CLASS, T_DOC_COMMENT]);
  7811. }
  7812. public function isRisky()
  7813. {
  7814. return true;
  7815. }
  7816. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7817. {
  7818. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  7819. if (!$tokens[$index]->isGivenKind(T_CLASS) || !$this->isClassCandidate($tokens, $index)) {
  7820. continue;
  7821. }
  7822. $tokens->insertAt(
  7823. $index,
  7824. [
  7825. new Token([T_FINAL, 'final']),
  7826. new Token([T_WHITESPACE, ' ']),
  7827. ]
  7828. );
  7829. }
  7830. }
  7831. protected function createConfigurationDefinition()
  7832. {
  7833. $annotationsAsserts = [static function (array $values) {
  7834. foreach ($values as $value) {
  7835. if (!is_string($value) || '' === $value) {
  7836. return false;
  7837. }
  7838. }
  7839. return true;
  7840. }];
  7841. $annotationsNormalizer = static function (Options $options, array $value) {
  7842. $newValue = [];
  7843. foreach ($value as $key) {
  7844. if ('@' === $key[0]) {
  7845. $key = substr($key, 1);
  7846. }
  7847. $newValue[strtolower($key)] = true;
  7848. }
  7849. return $newValue;
  7850. };
  7851. return new FixerConfigurationResolver([
  7852. (new FixerOptionBuilder('annotation-white-list', 'Class level annotations tags that must be set in order to fix the class. (case insensitive)'))
  7853. ->setAllowedTypes(['array'])
  7854. ->setAllowedValues($annotationsAsserts)
  7855. ->setDefault(['@internal'])
  7856. ->setNormalizer($annotationsNormalizer)
  7857. ->getOption(),
  7858. (new FixerOptionBuilder('annotation-black-list', 'Class level annotations tags that must be omitted to fix the class, even if all of the white list ones are used as well. (case insensitive)'))
  7859. ->setAllowedTypes(['array'])
  7860. ->setAllowedValues($annotationsAsserts)
  7861. ->setDefault(['@final', '@Entity', '@ORM'])
  7862. ->setNormalizer($annotationsNormalizer)
  7863. ->getOption(),
  7864. ]);
  7865. }
  7866. private function isClassCandidate(Tokens $tokens, $index)
  7867. {
  7868. if ($tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind([T_ABSTRACT, T_FINAL])) {
  7869. return false;
  7870. }
  7871. $docToken = $tokens[$tokens->getPrevNonWhitespace($index)];
  7872. if (!$docToken->isGivenKind(T_DOC_COMMENT)) {
  7873. return false;
  7874. }
  7875. $doc = new DocBlock($docToken->getContent());
  7876. $tags = [];
  7877. foreach ($doc->getAnnotations() as $annotation) {
  7878. $tag = strtolower($annotation->getTag()->getName());
  7879. if (isset($this->configuration['annotation-black-list'][$tag])) {
  7880. return false;
  7881. }
  7882. $tags[$tag] = true;
  7883. }
  7884. foreach ($this->configuration['annotation-white-list'] as $tag => $true) {
  7885. if (!isset($tags[$tag])) {
  7886. return false;
  7887. }
  7888. }
  7889. return true;
  7890. }
  7891. }
  7892. <?php
  7893. namespace PhpCsFixer\Fixer\ClassNotation;
  7894. use PhpCsFixer\AbstractProxyFixer;
  7895. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  7896. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  7897. use PhpCsFixer\FixerDefinition\CodeSample;
  7898. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7899. final class MethodSeparationFixer extends AbstractProxyFixer implements DeprecatedFixerInterface, WhitespacesAwareFixerInterface
  7900. {
  7901. public function getDefinition()
  7902. {
  7903. return new FixerDefinition(
  7904. 'Methods must be separated with one blank line.',
  7905. [
  7906. new CodeSample(
  7907. '<?php
  7908. final class Sample
  7909. {
  7910. protected function foo()
  7911. {
  7912. }
  7913. protected function bar()
  7914. {
  7915. }
  7916. }
  7917. '
  7918. ),
  7919. ]
  7920. );
  7921. }
  7922. public function getSuccessorsNames()
  7923. {
  7924. return array_keys($this->proxyFixers);
  7925. }
  7926. protected function createProxyFixers()
  7927. {
  7928. $fixer = new ClassAttributesSeparationFixer();
  7929. $fixer->configure(['elements' => ['method']]);
  7930. return [$fixer];
  7931. }
  7932. }
  7933. <?php
  7934. namespace PhpCsFixer\Fixer\ClassNotation;
  7935. use PhpCsFixer\AbstractFixer;
  7936. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  7937. use PhpCsFixer\FixerDefinition\CodeSample;
  7938. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7939. use PhpCsFixer\Tokenizer\Token;
  7940. use PhpCsFixer\Tokenizer\Tokens;
  7941. use PhpCsFixer\Utils;
  7942. final class NoBlankLinesAfterClassOpeningFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  7943. {
  7944. public function isCandidate(Tokens $tokens)
  7945. {
  7946. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  7947. }
  7948. public function getDefinition()
  7949. {
  7950. return new FixerDefinition(
  7951. 'There should be no empty lines after class opening brace.',
  7952. [
  7953. new CodeSample(
  7954. '<?php
  7955. final class Sample
  7956. {
  7957. protected function foo()
  7958. {
  7959. }
  7960. }
  7961. '
  7962. ),
  7963. ]
  7964. );
  7965. }
  7966. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  7967. {
  7968. foreach ($tokens as $index => $token) {
  7969. if (!$token->isClassy()) {
  7970. continue;
  7971. }
  7972. $startBraceIndex = $tokens->getNextTokenOfKind($index, ['{']);
  7973. if (!$tokens[$startBraceIndex + 1]->isWhitespace()) {
  7974. continue;
  7975. }
  7976. $this->fixWhitespace($tokens, $startBraceIndex + 1);
  7977. }
  7978. }
  7979. private function fixWhitespace(Tokens $tokens, $index)
  7980. {
  7981. $content = $tokens[$index]->getContent();
  7982. if (substr_count($content, "\n") > 1) {
  7983. $lines = Utils::splitLines($content);
  7984. $tokens[$index] = new Token([T_WHITESPACE, $this->whitespacesConfig->getLineEnding().end($lines)]);
  7985. }
  7986. }
  7987. }
  7988. <?php
  7989. namespace PhpCsFixer\Fixer\ClassNotation;
  7990. use PhpCsFixer\AbstractFixer;
  7991. use PhpCsFixer\FixerDefinition\CodeSample;
  7992. use PhpCsFixer\FixerDefinition\FixerDefinition;
  7993. use PhpCsFixer\Tokenizer\Tokens;
  7994. final class NoNullPropertyInitializationFixer extends AbstractFixer
  7995. {
  7996. public function getDefinition()
  7997. {
  7998. return new FixerDefinition(
  7999. 'Properties MUST not be explicitly initialized with `null`.',
  8000. [
  8001. new CodeSample(
  8002. '<?php
  8003. class Foo {
  8004. public $foo = null;
  8005. }
  8006. '
  8007. ),
  8008. ]
  8009. );
  8010. }
  8011. public function isCandidate(Tokens $tokens)
  8012. {
  8013. return $tokens->isAnyTokenKindsFound([T_CLASS, T_TRAIT]) && $tokens->isAnyTokenKindsFound([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_VAR]);
  8014. }
  8015. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8016. {
  8017. for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
  8018. if (!$tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_VAR])) {
  8019. continue;
  8020. }
  8021. while (true) {
  8022. $varTokenIndex = $index = $tokens->getNextMeaningfulToken($index);
  8023. if (!$tokens[$index]->isGivenKind(T_VARIABLE)) {
  8024. break;
  8025. }
  8026. $index = $tokens->getNextMeaningfulToken($index);
  8027. if ($tokens[$index]->equals('=')) {
  8028. $index = $tokens->getNextMeaningfulToken($index);
  8029. if ($tokens[$index]->isGivenKind(T_NS_SEPARATOR)) {
  8030. $index = $tokens->getNextMeaningfulToken($index);
  8031. }
  8032. if ($tokens[$index]->equals([T_STRING, 'null'], false)) {
  8033. for ($i = $varTokenIndex + 1; $i <= $index; ++$i) {
  8034. if (
  8035. !($tokens[$i]->isWhitespace() && false !== strpos($tokens[$i]->getContent(), "\n"))
  8036. && !$tokens[$i]->isComment()
  8037. ) {
  8038. $tokens->clearAt($i);
  8039. }
  8040. }
  8041. }
  8042. ++$index;
  8043. }
  8044. if (!$tokens[$index]->equals(',')) {
  8045. break;
  8046. }
  8047. }
  8048. }
  8049. }
  8050. }
  8051. <?php
  8052. namespace PhpCsFixer\Fixer\ClassNotation;
  8053. use PhpCsFixer\AbstractFixer;
  8054. use PhpCsFixer\FixerDefinition\CodeSample;
  8055. use PhpCsFixer\FixerDefinition\FixerDefinition;
  8056. use PhpCsFixer\Tokenizer\Token;
  8057. use PhpCsFixer\Tokenizer\Tokens;
  8058. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  8059. final class NoPhp4ConstructorFixer extends AbstractFixer
  8060. {
  8061. public function getDefinition()
  8062. {
  8063. return new FixerDefinition(
  8064. 'Convert PHP4-style constructors to `__construct`.',
  8065. [
  8066. new CodeSample('<?php
  8067. class Foo
  8068. {
  8069. public function Foo($bar)
  8070. {
  8071. }
  8072. }
  8073. '),
  8074. ],
  8075. null,
  8076. 'Risky when old style constructor being fixed is overridden or overrides parent one.'
  8077. );
  8078. }
  8079. public function getPriority()
  8080. {
  8081. return 75;
  8082. }
  8083. public function isCandidate(Tokens $tokens)
  8084. {
  8085. return $tokens->isTokenKindFound(T_CLASS);
  8086. }
  8087. public function isRisky()
  8088. {
  8089. return true;
  8090. }
  8091. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8092. {
  8093. $tokensAnalyzer = new TokensAnalyzer($tokens);
  8094. $classes = array_keys($tokens->findGivenKind(T_CLASS));
  8095. $numClasses = count($classes);
  8096. for ($i = 0; $i < $numClasses; ++$i) {
  8097. $index = $classes[$i];
  8098. if ($tokensAnalyzer->isAnonymousClass($index)) {
  8099. continue;
  8100. }
  8101. $nspIndex = $tokens->getPrevTokenOfKind($index, [[T_NAMESPACE, 'namespace']]);
  8102. if (null !== $nspIndex) {
  8103. $nspIndex = $tokens->getNextMeaningfulToken($nspIndex);
  8104. if (!$tokens[$nspIndex]->equals('{')) {
  8105. $nspIndex = $tokens->getNextTokenOfKind($nspIndex, [';', '{']);
  8106. if ($tokens[$nspIndex]->equals(';')) {
  8107. break;
  8108. }
  8109. $nspEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $nspIndex);
  8110. if ($index < $nspEnd) {
  8111. for ($j = $i + 1; $j < $numClasses; ++$j) {
  8112. if ($classes[$j] < $nspEnd) {
  8113. ++$i;
  8114. }
  8115. }
  8116. continue;
  8117. }
  8118. }
  8119. }
  8120. $classNameIndex = $tokens->getNextMeaningfulToken($index);
  8121. $className = $tokens[$classNameIndex]->getContent();
  8122. $classStart = $tokens->getNextTokenOfKind($classNameIndex, ['{']);
  8123. $classEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classStart);
  8124. $this->fixConstructor($tokens, $className, $classStart, $classEnd);
  8125. $this->fixParent($tokens, $classStart, $classEnd);
  8126. }
  8127. }
  8128. private function fixConstructor(Tokens $tokens, $className, $classStart, $classEnd)
  8129. {
  8130. $php4 = $this->findFunction($tokens, $className, $classStart, $classEnd);
  8131. if (null === $php4) {
  8132. return;
  8133. }
  8134. if (!empty($php4['modifiers'][T_ABSTRACT]) || !empty($php4['modifiers'][T_STATIC])) {
  8135. return;
  8136. }
  8137. $php5 = $this->findFunction($tokens, '__construct', $classStart, $classEnd);
  8138. if (null === $php5) {
  8139. $tokens[$php4['nameIndex']] = new Token([T_STRING, '__construct']);
  8140. $this->fixInfiniteRecursion($tokens, $php4['bodyIndex'], $php4['endIndex']);
  8141. return;
  8142. }
  8143. list($seq, $case) = $this->getWrapperMethodSequence($tokens, '__construct', $php4['startIndex'], $php4['bodyIndex']);
  8144. if (null !== $tokens->findSequence($seq, $php4['bodyIndex'] - 1, $php4['endIndex'], $case)) {
  8145. for ($i = $php4['startIndex']; $i <= $php4['endIndex']; ++$i) {
  8146. $tokens->clearAt($i);
  8147. }
  8148. return;
  8149. }
  8150. list($seq, $case) = $this->getWrapperMethodSequence($tokens, $className, $php4['startIndex'], $php4['bodyIndex']);
  8151. if (null !== $tokens->findSequence($seq, $php5['bodyIndex'] - 1, $php5['endIndex'], $case)) {
  8152. for ($i = $php5['startIndex']; $i <= $php5['endIndex']; ++$i) {
  8153. $tokens->clearAt($i);
  8154. }
  8155. $tokens[$php4['nameIndex']] = new Token([T_STRING, '__construct']);
  8156. }
  8157. }
  8158. private function fixParent(Tokens $tokens, $classStart, $classEnd)
  8159. {
  8160. foreach ($tokens->findGivenKind(T_EXTENDS) as $index => $token) {
  8161. $parentIndex = $tokens->getNextMeaningfulToken($index);
  8162. $parentClass = $tokens[$parentIndex]->getContent();
  8163. $parentSeq = $tokens->findSequence([
  8164. [T_STRING],
  8165. [T_DOUBLE_COLON],
  8166. [T_STRING, $parentClass],
  8167. '(',
  8168. ], $classStart, $classEnd, [2 => false]);
  8169. if (null !== $parentSeq) {
  8170. $parentSeq = array_keys($parentSeq);
  8171. if ($tokens[$parentSeq[0]]->equalsAny([[T_STRING, 'parent'], [T_STRING, $parentClass]], false)) {
  8172. $tokens[$parentSeq[0]] = new Token([T_STRING, 'parent']);
  8173. $tokens[$parentSeq[2]] = new Token([T_STRING, '__construct']);
  8174. }
  8175. }
  8176. $parentSeq = $tokens->findSequence([
  8177. [T_VARIABLE, '$this'],
  8178. [T_OBJECT_OPERATOR],
  8179. [T_STRING, $parentClass],
  8180. '(',
  8181. ], $classStart, $classEnd, [2 => false]);
  8182. if (null !== $parentSeq) {
  8183. $parentSeq = array_keys($parentSeq);
  8184. $tokens[$parentSeq[0]] = new Token([
  8185. T_STRING,
  8186. 'parent',
  8187. ]);
  8188. $tokens[$parentSeq[1]] = new Token([
  8189. T_DOUBLE_COLON,
  8190. '::',
  8191. ]);
  8192. $tokens[$parentSeq[2]] = new Token([T_STRING, '__construct']);
  8193. }
  8194. }
  8195. }
  8196. private function fixInfiniteRecursion(Tokens $tokens, $start, $end)
  8197. {
  8198. $seq = [
  8199. [T_VARIABLE, '$this'],
  8200. [T_OBJECT_OPERATOR],
  8201. [T_STRING, '__construct'],
  8202. ];
  8203. while (true) {
  8204. $callSeq = $tokens->findSequence($seq, $start, $end, [2 => false]);
  8205. if (null === $callSeq) {
  8206. return;
  8207. }
  8208. $callSeq = array_keys($callSeq);
  8209. $tokens[$callSeq[0]] = new Token([T_STRING, 'parent']);
  8210. $tokens[$callSeq[1]] = new Token([T_DOUBLE_COLON, '::']);
  8211. }
  8212. }
  8213. private function getWrapperMethodSequence(Tokens $tokens, $method, $startIndex, $bodyIndex)
  8214. {
  8215. $seq = [
  8216. '{',
  8217. [T_VARIABLE, '$this'],
  8218. [T_OBJECT_OPERATOR],
  8219. [T_STRING, $method],
  8220. '(',
  8221. ];
  8222. $case = [3 => false];
  8223. $index = $startIndex;
  8224. while (true) {
  8225. $index = $tokens->getNextTokenOfKind($index, [[T_VARIABLE]]);
  8226. if (null === $index || $index >= $bodyIndex) {
  8227. break;
  8228. }
  8229. if (count($seq) > 5) {
  8230. $seq[] = ',';
  8231. }
  8232. $seq[] = [T_VARIABLE, $tokens[$index]->getContent()];
  8233. }
  8234. $seq[] = ')';
  8235. $seq[] = ';';
  8236. $seq[] = '}';
  8237. return [$seq, $case];
  8238. }
  8239. private function findFunction(Tokens $tokens, $name, $startIndex, $endIndex)
  8240. {
  8241. $function = $tokens->findSequence([
  8242. [T_FUNCTION],
  8243. [T_STRING, $name],
  8244. '(',
  8245. ], $startIndex, $endIndex, false);
  8246. if (null === $function) {
  8247. return null;
  8248. }
  8249. $function = array_keys($function);
  8250. $possibleModifiers = [T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_ABSTRACT, T_FINAL];
  8251. $modifiers = [];
  8252. $prevBlock = $tokens->getPrevMeaningfulToken($function[0]);
  8253. while (null !== $prevBlock && $tokens[$prevBlock]->isGivenKind($possibleModifiers)) {
  8254. $modifiers[$tokens[$prevBlock]->getId()] = $prevBlock;
  8255. $prevBlock = $tokens->getPrevMeaningfulToken($prevBlock);
  8256. }
  8257. if (isset($modifiers[T_ABSTRACT])) {
  8258. $bodyStart = null;
  8259. $funcEnd = $tokens->getNextTokenOfKind($function[2], [';']);
  8260. } else {
  8261. $bodyStart = $tokens->getNextTokenOfKind($function[2], ['{']);
  8262. $funcEnd = null !== $bodyStart ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $bodyStart) : null;
  8263. }
  8264. return [
  8265. 'nameIndex' => $function[1],
  8266. 'startIndex' => $prevBlock + 1,
  8267. 'endIndex' => $funcEnd,
  8268. 'bodyIndex' => $bodyStart,
  8269. 'modifiers' => $modifiers,
  8270. ];
  8271. }
  8272. }
  8273. <?php
  8274. namespace PhpCsFixer\Fixer\ClassNotation;
  8275. use PhpCsFixer\AbstractFixer;
  8276. use PhpCsFixer\FixerDefinition\CodeSample;
  8277. use PhpCsFixer\FixerDefinition\FixerDefinition;
  8278. use PhpCsFixer\Tokenizer\Tokens;
  8279. final class NoUnneededFinalMethodFixer extends AbstractFixer
  8280. {
  8281. public function getDefinition()
  8282. {
  8283. return new FixerDefinition(
  8284. 'A final class must not have final methods.',
  8285. [
  8286. new CodeSample(
  8287. '<?php
  8288. final class Foo {
  8289. final public function foo() {}
  8290. final protected function bar() {}
  8291. final private function baz() {}
  8292. }
  8293. '
  8294. ),
  8295. new CodeSample(
  8296. '<?php
  8297. class Foo {
  8298. final private function bar() {}
  8299. }
  8300. '
  8301. ),
  8302. ]
  8303. );
  8304. }
  8305. public function isCandidate(Tokens $tokens)
  8306. {
  8307. return $tokens->isAllTokenKindsFound([T_CLASS, T_FINAL]);
  8308. }
  8309. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8310. {
  8311. $tokensCount = count($tokens);
  8312. for ($index = 0; $index < $tokensCount; ++$index) {
  8313. if (!$tokens[$index]->isGivenKind(T_CLASS)) {
  8314. continue;
  8315. }
  8316. $classOpen = $tokens->getNextTokenOfKind($index, ['{']);
  8317. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  8318. $classIsFinal = $prevToken->isGivenKind(T_FINAL);
  8319. $this->fixClass($tokens, $classOpen, $classIsFinal);
  8320. }
  8321. }
  8322. private function fixClass(Tokens $tokens, $classOpenIndex, $classIsFinal)
  8323. {
  8324. $tokensCount = count($tokens);
  8325. for ($index = $classOpenIndex + 1; $index < $tokensCount; ++$index) {
  8326. if ($tokens[$index]->equals('}')) {
  8327. return;
  8328. }
  8329. if ($tokens[$index]->equals('{')) {
  8330. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  8331. continue;
  8332. }
  8333. if (!$tokens[$index]->isGivenKind(T_FINAL)) {
  8334. continue;
  8335. }
  8336. if (!$classIsFinal && !$this->isPrivateMethod($tokens, $index, $classOpenIndex)) {
  8337. continue;
  8338. }
  8339. $tokens->clearAt($index);
  8340. $nextTokenIndex = $index + 1;
  8341. if ($tokens[$nextTokenIndex]->isWhitespace()) {
  8342. $tokens->clearAt($nextTokenIndex);
  8343. }
  8344. }
  8345. }
  8346. private function isPrivateMethod(Tokens $tokens, $index, $classOpenIndex)
  8347. {
  8348. $index = max($classOpenIndex + 1, $tokens->getPrevTokenOfKind($index, [';', '{', '}']));
  8349. while (!$tokens[$index]->isGivenKind(T_FUNCTION)) {
  8350. if ($tokens[$index]->isGivenKind(T_PRIVATE)) {
  8351. return true;
  8352. }
  8353. ++$index;
  8354. }
  8355. return false;
  8356. }
  8357. }
  8358. <?php
  8359. namespace PhpCsFixer\Fixer\ClassNotation;
  8360. use PhpCsFixer\AbstractFixer;
  8361. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  8362. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  8363. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  8364. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  8365. use PhpCsFixer\FixerDefinition\CodeSample;
  8366. use PhpCsFixer\FixerDefinition\FixerDefinition;
  8367. use PhpCsFixer\Tokenizer\CT;
  8368. use PhpCsFixer\Tokenizer\Token;
  8369. use PhpCsFixer\Tokenizer\Tokens;
  8370. final class OrderedClassElementsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  8371. {
  8372. private static $typeHierarchy = [
  8373. 'use_trait' => null,
  8374. 'public' => null,
  8375. 'protected' => null,
  8376. 'private' => null,
  8377. 'constant' => null,
  8378. 'constant_public' => ['constant', 'public'],
  8379. 'constant_protected' => ['constant', 'protected'],
  8380. 'constant_private' => ['constant', 'private'],
  8381. 'property' => null,
  8382. 'property_static' => ['property'],
  8383. 'property_public' => ['property', 'public'],
  8384. 'property_protected' => ['property', 'protected'],
  8385. 'property_private' => ['property', 'private'],
  8386. 'property_public_static' => ['property_static', 'property_public'],
  8387. 'property_protected_static' => ['property_static', 'property_protected'],
  8388. 'property_private_static' => ['property_static', 'property_private'],
  8389. 'method' => null,
  8390. 'method_static' => ['method'],
  8391. 'method_public' => ['method', 'public'],
  8392. 'method_protected' => ['method', 'protected'],
  8393. 'method_private' => ['method', 'private'],
  8394. 'method_public_static' => ['method_static', 'method_public'],
  8395. 'method_protected_static' => ['method_static', 'method_protected'],
  8396. 'method_private_static' => ['method_static', 'method_private'],
  8397. ];
  8398. private static $specialTypes = [
  8399. 'construct' => null,
  8400. 'destruct' => null,
  8401. 'magic' => null,
  8402. 'phpunit' => null,
  8403. ];
  8404. private $typePosition;
  8405. public function configure(array $configuration = null)
  8406. {
  8407. parent::configure($configuration);
  8408. $this->typePosition = [];
  8409. $pos = 0;
  8410. foreach ($this->configuration['order'] as $type) {
  8411. $this->typePosition[$type] = $pos++;
  8412. }
  8413. foreach (self::$typeHierarchy as $type => $parents) {
  8414. if (isset($this->typePosition[$type])) {
  8415. continue;
  8416. }
  8417. if (!$parents) {
  8418. $this->typePosition[$type] = null;
  8419. continue;
  8420. }
  8421. foreach ($parents as $parent) {
  8422. if (isset($this->typePosition[$parent])) {
  8423. $this->typePosition[$type] = $this->typePosition[$parent];
  8424. continue 2;
  8425. }
  8426. }
  8427. $this->typePosition[$type] = null;
  8428. }
  8429. $lastPosition = count($this->configuration['order']);
  8430. foreach ($this->typePosition as &$pos) {
  8431. if (null === $pos) {
  8432. $pos = $lastPosition;
  8433. }
  8434. $pos *= 10;
  8435. }
  8436. }
  8437. public function isCandidate(Tokens $tokens)
  8438. {
  8439. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  8440. }
  8441. public function getDefinition()
  8442. {
  8443. return new FixerDefinition(
  8444. 'Orders the elements of classes/interfaces/traits.',
  8445. [
  8446. new CodeSample(
  8447. '<?php
  8448. final class Example
  8449. {
  8450. use BarTrait;
  8451. use BazTrait;
  8452. const C1 = 1;
  8453. const C2 = 2;
  8454. protected static $protStatProp;
  8455. public static $pubStatProp1;
  8456. public $pubProp1;
  8457. protected $protProp;
  8458. var $pubProp2;
  8459. private static $privStatProp;
  8460. private $privProp;
  8461. public static $pubStatProp2;
  8462. public $pubProp3;
  8463. protected function __construct() {}
  8464. private static function privStatFunc() {}
  8465. public function pubFunc1() {}
  8466. public function __toString() {}
  8467. protected function protFunc() {}
  8468. function pubFunc2() {}
  8469. public static function pubStatFunc1() {}
  8470. public function pubFunc3() {}
  8471. static function pubStatFunc2() {}
  8472. private function privFunc() {}
  8473. public static function pubStatFunc3() {}
  8474. protected static function protStatFunc() {}
  8475. public function __destruct() {}
  8476. }
  8477. '
  8478. ),
  8479. new CodeSample(
  8480. '<?php
  8481. class Example
  8482. {
  8483. public function A(){}
  8484. private function B(){}
  8485. }
  8486. ',
  8487. ['order' => ['method_private', 'method_public']]
  8488. ),
  8489. ]
  8490. );
  8491. }
  8492. public function getPriority()
  8493. {
  8494. return 65;
  8495. }
  8496. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8497. {
  8498. for ($i = 1, $count = $tokens->count(); $i < $count; ++$i) {
  8499. if (!$tokens[$i]->isClassy()) {
  8500. continue;
  8501. }
  8502. $i = $tokens->getNextTokenOfKind($i, ['{']);
  8503. $elements = $this->getElements($tokens, $i);
  8504. if (!$elements) {
  8505. continue;
  8506. }
  8507. $sorted = $this->sortElements($elements);
  8508. $endIndex = $elements[count($elements) - 1]['end'];
  8509. if ($sorted !== $elements) {
  8510. $this->sortTokens($tokens, $i, $endIndex, $sorted);
  8511. }
  8512. $i = $endIndex;
  8513. }
  8514. }
  8515. protected function createConfigurationDefinition()
  8516. {
  8517. return new FixerConfigurationResolverRootless('order', [
  8518. (new FixerOptionBuilder('order', 'List of strings defining order of elements.'))
  8519. ->setAllowedTypes(['array'])
  8520. ->setAllowedValues([
  8521. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(array_keys(array_merge(self::$typeHierarchy, self::$specialTypes))),
  8522. ])
  8523. ->setDefault([
  8524. 'use_trait',
  8525. 'constant_public',
  8526. 'constant_protected',
  8527. 'constant_private',
  8528. 'property_public',
  8529. 'property_protected',
  8530. 'property_private',
  8531. 'construct',
  8532. 'destruct',
  8533. 'magic',
  8534. 'phpunit',
  8535. 'method_public',
  8536. 'method_protected',
  8537. 'method_private',
  8538. ])
  8539. ->getOption(),
  8540. ]);
  8541. }
  8542. private function getElements(Tokens $tokens, $startIndex)
  8543. {
  8544. static $elementTokenKinds = [CT::T_USE_TRAIT, T_CONST, T_VARIABLE, T_FUNCTION];
  8545. ++$startIndex;
  8546. $elements = [];
  8547. while (true) {
  8548. $element = [
  8549. 'start' => $startIndex,
  8550. 'visibility' => 'public',
  8551. 'static' => false,
  8552. ];
  8553. for ($i = $startIndex;; ++$i) {
  8554. $token = $tokens[$i];
  8555. if ($token->equals('}')) {
  8556. return $elements;
  8557. }
  8558. if ($token->isGivenKind(T_STATIC)) {
  8559. $element['static'] = true;
  8560. continue;
  8561. }
  8562. if ($token->isGivenKind([T_PROTECTED, T_PRIVATE])) {
  8563. $element['visibility'] = strtolower($token->getContent());
  8564. continue;
  8565. }
  8566. if (!$token->isGivenKind($elementTokenKinds)) {
  8567. continue;
  8568. }
  8569. $type = $this->detectElementType($tokens, $i);
  8570. if (is_array($type)) {
  8571. $element['type'] = $type[0];
  8572. $element['name'] = $type[1];
  8573. } else {
  8574. $element['type'] = $type;
  8575. }
  8576. $element['end'] = $this->findElementEnd($tokens, $i);
  8577. break;
  8578. }
  8579. $elements[] = $element;
  8580. $startIndex = $element['end'] + 1;
  8581. }
  8582. }
  8583. private function detectElementType(Tokens $tokens, $index)
  8584. {
  8585. $token = $tokens[$index];
  8586. if ($token->isGivenKind(CT::T_USE_TRAIT)) {
  8587. return 'use_trait';
  8588. }
  8589. if ($token->isGivenKind(T_CONST)) {
  8590. return 'constant';
  8591. }
  8592. if ($token->isGivenKind(T_VARIABLE)) {
  8593. return 'property';
  8594. }
  8595. $nameToken = $tokens[$tokens->getNextMeaningfulToken($index)];
  8596. if ($nameToken->equals([T_STRING, '__construct'], false)) {
  8597. return 'construct';
  8598. }
  8599. if ($nameToken->equals([T_STRING, '__destruct'], false)) {
  8600. return 'destruct';
  8601. }
  8602. if (
  8603. $nameToken->equalsAny([
  8604. [T_STRING, 'setUpBeforeClass'],
  8605. [T_STRING, 'tearDownAfterClass'],
  8606. [T_STRING, 'setUp'],
  8607. [T_STRING, 'tearDown'],
  8608. ], false)
  8609. ) {
  8610. return ['phpunit', strtolower($nameToken->getContent())];
  8611. }
  8612. if ('__' === substr($nameToken->getContent(), 0, 2)) {
  8613. return 'magic';
  8614. }
  8615. return 'method';
  8616. }
  8617. private function findElementEnd(Tokens $tokens, $index)
  8618. {
  8619. $index = $tokens->getNextTokenOfKind($index, ['{', ';']);
  8620. if ($tokens[$index]->equals('{')) {
  8621. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  8622. }
  8623. for (++$index; $tokens[$index]->isWhitespace(" \t") || $tokens[$index]->isComment(); ++$index);
  8624. --$index;
  8625. return $tokens[$index]->isWhitespace() ? $index - 1 : $index;
  8626. }
  8627. private function sortElements(array $elements)
  8628. {
  8629. static $phpunitPositions = [
  8630. 'setupbeforeclass' => 1,
  8631. 'teardownafterclass' => 2,
  8632. 'setup' => 3,
  8633. 'teardown' => 4,
  8634. ];
  8635. foreach ($elements as &$element) {
  8636. $type = $element['type'];
  8637. if (array_key_exists($type, self::$specialTypes)) {
  8638. if (isset($this->typePosition[$type])) {
  8639. $element['position'] = $this->typePosition[$type];
  8640. if ('phpunit' === $type) {
  8641. $element['position'] += $phpunitPositions[$element['name']];
  8642. }
  8643. continue;
  8644. }
  8645. $type = 'method';
  8646. }
  8647. if (in_array($type, ['constant', 'property', 'method'], true)) {
  8648. $type .= '_'.$element['visibility'];
  8649. if ($element['static']) {
  8650. $type .= '_static';
  8651. }
  8652. }
  8653. $element['position'] = $this->typePosition[$type];
  8654. }
  8655. unset($element);
  8656. usort($elements, static function (array $a, array $b) {
  8657. if ($a['position'] === $b['position']) {
  8658. return $a['start'] > $b['start'] ? 1 : -1;
  8659. }
  8660. return $a['position'] > $b['position'] ? 1 : -1;
  8661. });
  8662. return $elements;
  8663. }
  8664. private function sortTokens(Tokens $tokens, $startIndex, $endIndex, array $elements)
  8665. {
  8666. $replaceTokens = [];
  8667. foreach ($elements as $element) {
  8668. for ($i = $element['start']; $i <= $element['end']; ++$i) {
  8669. $replaceTokens[] = clone $tokens[$i];
  8670. }
  8671. }
  8672. $tokens->overrideRange($startIndex + 1, $endIndex, $replaceTokens);
  8673. }
  8674. }
  8675. <?php
  8676. namespace PhpCsFixer\Fixer\ClassNotation;
  8677. use PhpCsFixer\AbstractFixer;
  8678. use PhpCsFixer\FixerDefinition\CodeSample;
  8679. use PhpCsFixer\FixerDefinition\FixerDefinition;
  8680. use PhpCsFixer\Tokenizer\CT;
  8681. use PhpCsFixer\Tokenizer\Token;
  8682. use PhpCsFixer\Tokenizer\Tokens;
  8683. final class ProtectedToPrivateFixer extends AbstractFixer
  8684. {
  8685. public function getDefinition()
  8686. {
  8687. return new FixerDefinition(
  8688. 'Converts `protected` variables and methods to `private` where possible.',
  8689. [
  8690. new CodeSample(
  8691. '<?php
  8692. final class Sample
  8693. {
  8694. protected $a;
  8695. protected function test()
  8696. {
  8697. }
  8698. }
  8699. '
  8700. ),
  8701. ]
  8702. );
  8703. }
  8704. public function getPriority()
  8705. {
  8706. return 66;
  8707. }
  8708. public function isCandidate(Tokens $tokens)
  8709. {
  8710. return $tokens->isAllTokenKindsFound([T_CLASS, T_FINAL, T_PROTECTED]);
  8711. }
  8712. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8713. {
  8714. $end = count($tokens) - 3;
  8715. for ($index = 0; $index < $end; ++$index) {
  8716. if (!$tokens[$index]->isGivenKind(T_CLASS)) {
  8717. continue;
  8718. }
  8719. $classOpen = $tokens->getNextTokenOfKind($index, ['{']);
  8720. $classClose = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpen);
  8721. if (!$this->skipClass($tokens, $index, $classOpen, $classClose)) {
  8722. $this->fixClass($tokens, $classOpen, $classClose);
  8723. }
  8724. $index = $classClose;
  8725. }
  8726. }
  8727. private function fixClass(Tokens $tokens, $classOpenIndex, $classCloseIndex)
  8728. {
  8729. for ($index = $classOpenIndex + 1; $index < $classCloseIndex; ++$index) {
  8730. if ($tokens[$index]->equals('{')) {
  8731. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  8732. continue;
  8733. }
  8734. if (!$tokens[$index]->isGivenKind(T_PROTECTED)) {
  8735. continue;
  8736. }
  8737. $tokens[$index] = new Token([T_PRIVATE, 'private']);
  8738. }
  8739. }
  8740. private function skipClass(Tokens $tokens, $classIndex, $classOpenIndex, $classCloseIndex)
  8741. {
  8742. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($classIndex)];
  8743. if (!$prevToken->isGivenKind(T_FINAL)) {
  8744. return true;
  8745. }
  8746. for ($index = $classIndex; $index < $classOpenIndex; ++$index) {
  8747. if ($tokens[$index]->isGivenKind(T_EXTENDS)) {
  8748. return true;
  8749. }
  8750. }
  8751. $useIndex = $tokens->getNextTokenOfKind($classIndex, [[CT::T_USE_TRAIT]]);
  8752. return $useIndex && $useIndex < $classCloseIndex;
  8753. }
  8754. }
  8755. <?php
  8756. namespace PhpCsFixer\Fixer\ClassNotation;
  8757. use PhpCsFixer\AbstractFixer;
  8758. use PhpCsFixer\FixerDefinition\CodeSample;
  8759. use PhpCsFixer\FixerDefinition\FixerDefinition;
  8760. use PhpCsFixer\Tokenizer\CT;
  8761. use PhpCsFixer\Tokenizer\Token;
  8762. use PhpCsFixer\Tokenizer\Tokens;
  8763. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  8764. final class SelfAccessorFixer extends AbstractFixer
  8765. {
  8766. public function getDefinition()
  8767. {
  8768. return new FixerDefinition(
  8769. 'Inside class or interface element "self" should be preferred to the class name itself.',
  8770. [
  8771. new CodeSample(
  8772. '<?php
  8773. class Sample
  8774. {
  8775. const BAZ = 1;
  8776. const BAR = Sample::BAZ;
  8777. public function getBar()
  8778. {
  8779. return Sample::BAR;
  8780. }
  8781. }
  8782. '
  8783. ),
  8784. ]
  8785. );
  8786. }
  8787. public function isCandidate(Tokens $tokens)
  8788. {
  8789. return $tokens->isAnyTokenKindsFound([T_CLASS, T_INTERFACE]);
  8790. }
  8791. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8792. {
  8793. $tokensAnalyzer = new TokensAnalyzer($tokens);
  8794. for ($i = 0, $c = $tokens->count(); $i < $c; ++$i) {
  8795. if (!$tokens[$i]->isGivenKind([T_CLASS, T_INTERFACE]) || $tokensAnalyzer->isAnonymousClass($i)) {
  8796. continue;
  8797. }
  8798. $nameIndex = $tokens->getNextTokenOfKind($i, [[T_STRING]]);
  8799. $startIndex = $tokens->getNextTokenOfKind($nameIndex, ['{']);
  8800. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex);
  8801. $name = $tokens[$nameIndex]->getContent();
  8802. $this->replaceNameOccurrences($tokens, $name, $startIndex, $endIndex);
  8803. $i = $endIndex;
  8804. }
  8805. }
  8806. private function replaceNameOccurrences(Tokens $tokens, $name, $startIndex, $endIndex)
  8807. {
  8808. $tokensAnalyzer = new TokensAnalyzer($tokens);
  8809. $insideMethodSignatureUntil = null;
  8810. for ($i = $startIndex; $i < $endIndex; ++$i) {
  8811. if ($i === $insideMethodSignatureUntil) {
  8812. $insideMethodSignatureUntil = null;
  8813. }
  8814. $token = $tokens[$i];
  8815. if (
  8816. ($token->isGivenKind(T_CLASS) && $tokensAnalyzer->isAnonymousClass($i)) ||
  8817. ($token->isGivenKind(T_FUNCTION) && $tokensAnalyzer->isLambda($i))
  8818. ) {
  8819. $i = $tokens->getNextTokenOfKind($i, ['{']);
  8820. $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i);
  8821. continue;
  8822. }
  8823. if ($token->isGivenKind(T_FUNCTION)) {
  8824. $i = $tokens->getNextTokenOfKind($i, ['(']);
  8825. $insideMethodSignatureUntil = $tokens->getNextTokenOfKind($i, ['{', ';']);
  8826. continue;
  8827. }
  8828. if (!$token->equals([T_STRING, $name], false)) {
  8829. continue;
  8830. }
  8831. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($i)];
  8832. $nextToken = $tokens[$tokens->getNextMeaningfulToken($i)];
  8833. if ($prevToken->isGivenKind([T_NS_SEPARATOR, T_OBJECT_OPERATOR]) || $nextToken->isGivenKind(T_NS_SEPARATOR)) {
  8834. continue;
  8835. }
  8836. if (
  8837. $prevToken->isGivenKind([T_INSTANCEOF, T_NEW])
  8838. || $nextToken->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM)
  8839. || (
  8840. null !== $insideMethodSignatureUntil
  8841. && $i < $insideMethodSignatureUntil
  8842. && $prevToken->equalsAny(['(', ',', [CT::T_TYPE_COLON], [CT::T_NULLABLE_TYPE]])
  8843. )
  8844. ) {
  8845. $tokens[$i] = new Token([T_STRING, 'self']);
  8846. }
  8847. }
  8848. }
  8849. }
  8850. <?php
  8851. namespace PhpCsFixer\Fixer\ClassNotation;
  8852. use PhpCsFixer\AbstractFixer;
  8853. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  8854. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  8855. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  8856. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  8857. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  8858. use PhpCsFixer\FixerDefinition\CodeSample;
  8859. use PhpCsFixer\FixerDefinition\FixerDefinition;
  8860. use PhpCsFixer\Tokenizer\CT;
  8861. use PhpCsFixer\Tokenizer\Token;
  8862. use PhpCsFixer\Tokenizer\Tokens;
  8863. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  8864. final class SingleClassElementPerStatementFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  8865. {
  8866. public function isCandidate(Tokens $tokens)
  8867. {
  8868. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  8869. }
  8870. public function getDefinition()
  8871. {
  8872. return new FixerDefinition(
  8873. 'There MUST NOT be more than one property or constant declared per statement.',
  8874. [
  8875. new CodeSample(
  8876. '<?php
  8877. final class Example
  8878. {
  8879. const FOO_1 = 1, FOO_2 = 2;
  8880. private static $bar1 = array(1,2,3), $bar2 = [1,2,3];
  8881. }
  8882. '
  8883. ),
  8884. new CodeSample(
  8885. '<?php
  8886. final class Example
  8887. {
  8888. const FOO_1 = 1, FOO_2 = 2;
  8889. private static $bar1 = array(1,2,3), $bar2 = [1,2,3];
  8890. }
  8891. ',
  8892. ['elements' => ['property']]
  8893. ),
  8894. ]
  8895. );
  8896. }
  8897. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  8898. {
  8899. $analyzer = new TokensAnalyzer($tokens);
  8900. $elements = array_reverse($analyzer->getClassyElements(), true);
  8901. foreach ($elements as $index => $element) {
  8902. if (!in_array($element['type'], $this->configuration['elements'], true)) {
  8903. continue;
  8904. }
  8905. $this->fixElement($tokens, $index);
  8906. }
  8907. }
  8908. protected function createConfigurationDefinition()
  8909. {
  8910. $values = ['const', 'property'];
  8911. return new FixerConfigurationResolverRootless('elements', [
  8912. (new FixerOptionBuilder('elements', 'List of strings which element should be modified.'))
  8913. ->setDefault($values)
  8914. ->setAllowedTypes(['array'])
  8915. ->setAllowedValues([
  8916. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf($values),
  8917. ])
  8918. ->getOption(),
  8919. ]);
  8920. }
  8921. private function fixElement(Tokens $tokens, $index)
  8922. {
  8923. $tokensAnalyzer = new TokensAnalyzer($tokens);
  8924. $repeatIndex = $index;
  8925. while (true) {
  8926. $repeatIndex = $tokens->getNextMeaningfulToken($repeatIndex);
  8927. $repeatToken = $tokens[$repeatIndex];
  8928. if ($tokensAnalyzer->isArray($repeatIndex)) {
  8929. if ($repeatToken->isGivenKind(T_ARRAY)) {
  8930. $repeatIndex = $tokens->getNextTokenOfKind($repeatIndex, ['(']);
  8931. $repeatIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $repeatIndex);
  8932. } else {
  8933. $repeatIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $repeatIndex);
  8934. }
  8935. continue;
  8936. }
  8937. if ($repeatToken->equals(';')) {
  8938. return;
  8939. }
  8940. if ($repeatToken->equals(',')) {
  8941. break;
  8942. }
  8943. }
  8944. $start = $tokens->getPrevTokenOfKind($index, [';', '{', '}']);
  8945. $this->expandElement(
  8946. $tokens,
  8947. $tokens->getNextMeaningfulToken($start),
  8948. $tokens->getNextTokenOfKind($index, [';'])
  8949. );
  8950. }
  8951. private function expandElement(Tokens $tokens, $startIndex, $endIndex)
  8952. {
  8953. $divisionContent = null;
  8954. if ($tokens[$startIndex - 1]->isWhitespace()) {
  8955. $divisionContent = $tokens[$startIndex - 1]->getContent();
  8956. if (preg_match('#(\n|\r\n)#', $divisionContent, $matches)) {
  8957. $divisionContent = $matches[0].trim($divisionContent, "\r\n");
  8958. }
  8959. }
  8960. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  8961. $token = $tokens[$i];
  8962. if ($token->equals(')')) {
  8963. $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $i, false);
  8964. continue;
  8965. }
  8966. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) {
  8967. $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $i, false);
  8968. continue;
  8969. }
  8970. if (!$tokens[$i]->equals(',')) {
  8971. continue;
  8972. }
  8973. $tokens[$i] = new Token(';');
  8974. if ($tokens[$i + 1]->isWhitespace()) {
  8975. $tokens->clearAt($i + 1);
  8976. }
  8977. if (null !== $divisionContent && '' !== $divisionContent) {
  8978. $tokens->insertAt($i + 1, new Token([T_WHITESPACE, $divisionContent]));
  8979. }
  8980. $sequence = $this->getModifiersSequences($tokens, $startIndex, $endIndex);
  8981. $tokens->insertAt($i + 2, $sequence);
  8982. }
  8983. }
  8984. private function getModifiersSequences(Tokens $tokens, $startIndex, $endIndex)
  8985. {
  8986. $sequence = [];
  8987. for ($i = $startIndex; $i < $endIndex - 1; ++$i) {
  8988. if ($tokens[$i]->isWhitespace() || $tokens[$i]->isComment()) {
  8989. continue;
  8990. }
  8991. if (!$tokens[$i]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_STATIC, T_CONST, T_VAR])) {
  8992. break;
  8993. }
  8994. $sequence[] = clone $tokens[$i];
  8995. $sequence[] = new Token([T_WHITESPACE, ' ']);
  8996. }
  8997. return $sequence;
  8998. }
  8999. }
  9000. <?php
  9001. namespace PhpCsFixer\Fixer\ClassNotation;
  9002. use PhpCsFixer\AbstractFixer;
  9003. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  9004. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  9005. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  9006. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  9007. use PhpCsFixer\FixerConfiguration\InvalidOptionsForEnvException;
  9008. use PhpCsFixer\FixerDefinition\CodeSample;
  9009. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9010. use PhpCsFixer\FixerDefinition\VersionSpecification;
  9011. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  9012. use PhpCsFixer\Tokenizer\Token;
  9013. use PhpCsFixer\Tokenizer\Tokens;
  9014. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  9015. use Symfony\Component\OptionsResolver\Options;
  9016. final class VisibilityRequiredFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  9017. {
  9018. public function getDefinition()
  9019. {
  9020. return new FixerDefinition(
  9021. 'Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility.',
  9022. [
  9023. new CodeSample(
  9024. '<?php
  9025. class Sample
  9026. {
  9027. var $a;
  9028. static protected $var_foo2;
  9029. function A()
  9030. {
  9031. }
  9032. }
  9033. '
  9034. ),
  9035. new VersionSpecificCodeSample(
  9036. '<?php
  9037. class Sample
  9038. {
  9039. const SAMPLE = 1;
  9040. }
  9041. ',
  9042. new VersionSpecification(70100),
  9043. ['elements' => ['const']]
  9044. ),
  9045. ]
  9046. );
  9047. }
  9048. public function isCandidate(Tokens $tokens)
  9049. {
  9050. return $tokens->isAnyTokenKindsFound(Token::getClassyTokenKinds());
  9051. }
  9052. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9053. {
  9054. $tokensAnalyzer = new TokensAnalyzer($tokens);
  9055. $elements = $tokensAnalyzer->getClassyElements();
  9056. foreach (array_reverse($elements, true) as $index => $element) {
  9057. if (!in_array($element['type'], $this->configuration['elements'], true)) {
  9058. continue;
  9059. }
  9060. if ('method' === $element['type']) {
  9061. $this->fixMethodVisibility($tokens, $index);
  9062. } elseif ('property' === $element['type']) {
  9063. $this->fixPropertyVisibility($tokens, $index);
  9064. } elseif ('const' === $element['type']) {
  9065. $this->fixConstVisibility($tokens, $index);
  9066. }
  9067. }
  9068. }
  9069. protected function createConfigurationDefinition()
  9070. {
  9071. return new FixerConfigurationResolverRootless('elements', [
  9072. (new FixerOptionBuilder('elements', 'The structural elements to fix (PHP >= 7.1 required for `const`).'))
  9073. ->setAllowedTypes(['array'])
  9074. ->setAllowedValues([
  9075. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(['property', 'method', 'const']),
  9076. ])
  9077. ->setNormalizer(static function (Options $options, $value) {
  9078. if (PHP_VERSION_ID < 70100 && in_array('const', $value, true)) {
  9079. throw new InvalidOptionsForEnvException('"const" option can only be enabled with PHP 7.1+.');
  9080. }
  9081. return $value;
  9082. })
  9083. ->setDefault(['property', 'method'])
  9084. ->getOption(),
  9085. ]);
  9086. }
  9087. private function fixMethodVisibility(Tokens $tokens, $index)
  9088. {
  9089. $this->overrideAttribs($tokens, $index, $this->grabAttribsBeforeMethodToken($tokens, $index));
  9090. if ($tokens[$index + 1]->isWhitespace()) {
  9091. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  9092. }
  9093. }
  9094. private function fixPropertyVisibility(Tokens $tokens, $index)
  9095. {
  9096. $prevIndex = $tokens->getPrevTokenOfKind($index, [';', ',', '{']);
  9097. if (null === $prevIndex || !$tokens[$prevIndex]->equals(',')) {
  9098. $this->overrideAttribs($tokens, $index, $this->grabAttribsBeforePropertyToken($tokens, $index));
  9099. }
  9100. }
  9101. private function fixConstVisibility(Tokens $tokens, $index)
  9102. {
  9103. $prev = $tokens->getPrevMeaningfulToken($index);
  9104. if ($tokens[$prev]->isGivenKind([T_PRIVATE, T_PROTECTED, T_PUBLIC])) {
  9105. return;
  9106. }
  9107. $tokens->insertAt($index, new Token([T_WHITESPACE, ' ']));
  9108. $tokens->insertAt($index, new Token([T_PUBLIC, 'public']));
  9109. }
  9110. private function grabAttribsBeforeMethodToken(Tokens $tokens, $index)
  9111. {
  9112. static $tokenAttribsMap = [
  9113. T_PRIVATE => 'visibility',
  9114. T_PROTECTED => 'visibility',
  9115. T_PUBLIC => 'visibility',
  9116. T_ABSTRACT => 'abstract',
  9117. T_FINAL => 'final',
  9118. T_STATIC => 'static',
  9119. ];
  9120. return $this->grabAttribsBeforeToken(
  9121. $tokens,
  9122. $index,
  9123. $tokenAttribsMap,
  9124. [
  9125. 'abstract' => null,
  9126. 'final' => null,
  9127. 'visibility' => ['index' => null, 'token' => new Token([T_PUBLIC, 'public'])],
  9128. 'static' => null,
  9129. ]
  9130. );
  9131. }
  9132. private function overrideAttribs(Tokens $tokens, $memberIndex, array $attribs)
  9133. {
  9134. $toOverride = [];
  9135. $firstAttribIndex = $memberIndex;
  9136. foreach ($attribs as $attrib) {
  9137. if (null === $attrib) {
  9138. continue;
  9139. }
  9140. if (null !== $attrib['index']) {
  9141. $firstAttribIndex = min($firstAttribIndex, $attrib['index']);
  9142. }
  9143. if (!$attrib['token']->isGivenKind(T_VAR) && '' !== $attrib['token']->getContent()) {
  9144. $toOverride[] = $attrib['token'];
  9145. $toOverride[] = new Token([T_WHITESPACE, ' ']);
  9146. }
  9147. }
  9148. if (!empty($toOverride)) {
  9149. $tokens->overrideRange($firstAttribIndex, $memberIndex - 1, $toOverride);
  9150. }
  9151. }
  9152. private function grabAttribsBeforePropertyToken(Tokens $tokens, $index)
  9153. {
  9154. static $tokenAttribsMap = [
  9155. T_VAR => 'var',
  9156. T_PRIVATE => 'visibility',
  9157. T_PROTECTED => 'visibility',
  9158. T_PUBLIC => 'visibility',
  9159. T_STATIC => 'static',
  9160. ];
  9161. return $this->grabAttribsBeforeToken(
  9162. $tokens,
  9163. $index,
  9164. $tokenAttribsMap,
  9165. [
  9166. 'visibility' => ['index' => null, 'token' => new Token([T_PUBLIC, 'public'])],
  9167. 'static' => null,
  9168. ]
  9169. );
  9170. }
  9171. private function grabAttribsBeforeToken(Tokens $tokens, $index, array $tokenAttribsMap, array $attribs)
  9172. {
  9173. while (true) {
  9174. $token = $tokens[--$index];
  9175. if (!$token->isArray()) {
  9176. if ($token->equalsAny(['{', '}', '(', ')'])) {
  9177. break;
  9178. }
  9179. continue;
  9180. }
  9181. if (isset($tokenAttribsMap[$token->getId()])) {
  9182. $attribs[$tokenAttribsMap[$token->getId()]] = [
  9183. 'token' => clone $token,
  9184. 'index' => $index,
  9185. ];
  9186. continue;
  9187. }
  9188. if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
  9189. continue;
  9190. }
  9191. break;
  9192. }
  9193. return $attribs;
  9194. }
  9195. }
  9196. <?php
  9197. namespace PhpCsFixer\Fixer\Comment;
  9198. use PhpCsFixer\AbstractProxyFixer;
  9199. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  9200. use PhpCsFixer\FixerDefinition\CodeSample;
  9201. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9202. final class HashToSlashCommentFixer extends AbstractProxyFixer implements DeprecatedFixerInterface
  9203. {
  9204. public function getDefinition()
  9205. {
  9206. return new FixerDefinition(
  9207. 'Single line comments should use double slashes `//` and not hash `#`.',
  9208. [new CodeSample("<?php # comment\n")]
  9209. );
  9210. }
  9211. public function getSuccessorsNames()
  9212. {
  9213. return array_keys($this->proxyFixers);
  9214. }
  9215. protected function createProxyFixers()
  9216. {
  9217. $fixer = new SingleLineCommentStyleFixer();
  9218. $fixer->configure(['comment_types' => ['hash']]);
  9219. return [$fixer];
  9220. }
  9221. }
  9222. <?php
  9223. namespace PhpCsFixer\Fixer\Comment;
  9224. use PhpCsFixer\AbstractFixer;
  9225. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  9226. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  9227. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  9228. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  9229. use PhpCsFixer\FixerDefinition\CodeSample;
  9230. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9231. use PhpCsFixer\Tokenizer\Token;
  9232. use PhpCsFixer\Tokenizer\Tokens;
  9233. use Symfony\Component\OptionsResolver\Options;
  9234. final class HeaderCommentFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  9235. {
  9236. const HEADER_PHPDOC = 'PHPDoc';
  9237. const HEADER_COMMENT = 'comment';
  9238. const HEADER_LOCATION_AFTER_OPEN = 1;
  9239. const HEADER_LOCATION_AFTER_DECLARE_STRICT = 2;
  9240. const HEADER_LINE_SEPARATION_BOTH = 1;
  9241. const HEADER_LINE_SEPARATION_TOP = 2;
  9242. const HEADER_LINE_SEPARATION_BOTTOM = 3;
  9243. const HEADER_LINE_SEPARATION_NONE = 4;
  9244. public function getDefinition()
  9245. {
  9246. return new FixerDefinition(
  9247. 'Add, replace or remove header comment.',
  9248. [
  9249. new CodeSample(
  9250. '<?php
  9251. declare(strict_types=1);
  9252. namespace A\B;
  9253. echo 1;
  9254. ',
  9255. [
  9256. 'header' => 'Made with love.',
  9257. ]
  9258. ),
  9259. new CodeSample(
  9260. '<?php
  9261. declare(strict_types=1);
  9262. namespace A\B;
  9263. echo 1;
  9264. ',
  9265. [
  9266. 'header' => 'Made with love.',
  9267. 'commentType' => 'PHPDoc',
  9268. 'location' => 'after_open',
  9269. 'separate' => 'bottom',
  9270. ]
  9271. ),
  9272. new CodeSample(
  9273. '<?php
  9274. declare(strict_types=1);
  9275. namespace A\B;
  9276. echo 1;
  9277. ',
  9278. [
  9279. 'header' => 'Made with love.',
  9280. 'commentType' => 'comment',
  9281. 'location' => 'after_declare_strict',
  9282. ]
  9283. ),
  9284. ]
  9285. );
  9286. }
  9287. public function isCandidate(Tokens $tokens)
  9288. {
  9289. return $tokens[0]->isGivenKind(T_OPEN_TAG) && $tokens->isMonolithicPhp();
  9290. }
  9291. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9292. {
  9293. $headerNewIndex = $this->findHeaderCommentInsertionIndex($tokens);
  9294. $headerCurrentIndex = $this->findHeaderCommentCurrentIndex($tokens, $headerNewIndex - 1);
  9295. if (null === $headerCurrentIndex) {
  9296. if ('' === $this->configuration['header']) {
  9297. return;
  9298. }
  9299. $this->insertHeader($tokens, $headerNewIndex);
  9300. } elseif ($this->getHeaderAsComment() !== $tokens[$headerCurrentIndex]->getContent()) {
  9301. $tokens->clearTokenAndMergeSurroundingWhitespace($headerCurrentIndex);
  9302. if ('' === $this->configuration['header']) {
  9303. return;
  9304. }
  9305. $this->insertHeader($tokens, $headerNewIndex);
  9306. } else {
  9307. $headerNewIndex = $headerCurrentIndex;
  9308. }
  9309. $this->fixWhiteSpaceAroundHeader($tokens, $headerNewIndex);
  9310. }
  9311. protected function createConfigurationDefinition()
  9312. {
  9313. return new FixerConfigurationResolver([
  9314. (new FixerOptionBuilder('header', 'Proper header content.'))
  9315. ->setAllowedTypes(['string'])
  9316. ->setNormalizer(static function (Options $options, $value) {
  9317. if ('' === trim($value)) {
  9318. return '';
  9319. }
  9320. return $value;
  9321. })
  9322. ->getOption(),
  9323. (new FixerOptionBuilder('commentType', 'Comment syntax type.'))
  9324. ->setAllowedValues([self::HEADER_PHPDOC, self::HEADER_COMMENT])
  9325. ->setDefault(self::HEADER_COMMENT)
  9326. ->getOption(),
  9327. (new FixerOptionBuilder('location', 'The location of the inserted header.'))
  9328. ->setAllowedValues(['after_open', 'after_declare_strict'])
  9329. ->setDefault('after_declare_strict')
  9330. ->getOption(),
  9331. (new FixerOptionBuilder('separate', 'Whether the header should be separated from the file content with a new line.'))
  9332. ->setAllowedValues(['both', 'top', 'bottom', 'none'])
  9333. ->setDefault('both')
  9334. ->getOption(),
  9335. ]);
  9336. }
  9337. private function getHeaderAsComment()
  9338. {
  9339. $lineEnding = $this->whitespacesConfig->getLineEnding();
  9340. $comment = (self::HEADER_COMMENT === $this->configuration['commentType'] ? '/*' : '/**').$lineEnding;
  9341. $lines = explode("\n", str_replace("\r", '', $this->configuration['header']));
  9342. foreach ($lines as $line) {
  9343. $comment .= rtrim(' * '.$line).$lineEnding;
  9344. }
  9345. return $comment.' */';
  9346. }
  9347. private function findHeaderCommentCurrentIndex(Tokens $tokens, $headerNewIndex)
  9348. {
  9349. $index = $tokens->getNextNonWhitespace($headerNewIndex);
  9350. return null === $index || !$tokens[$index]->isComment() ? null : $index;
  9351. }
  9352. private function findHeaderCommentInsertionIndex(Tokens $tokens)
  9353. {
  9354. if ('after_open' === $this->configuration['location']) {
  9355. return 1;
  9356. }
  9357. $index = $tokens->getNextMeaningfulToken(0);
  9358. if (null === $index) {
  9359. return 1;
  9360. }
  9361. if (!$tokens[$index]->isGivenKind(T_DECLARE)) {
  9362. return 1;
  9363. }
  9364. $next = $tokens->getNextMeaningfulToken($index);
  9365. if (null === $next || !$tokens[$next]->equals('(')) {
  9366. return 1;
  9367. }
  9368. $next = $tokens->getNextMeaningfulToken($next);
  9369. if (null === $next || !$tokens[$next]->equals([T_STRING, 'strict_types'], false)) {
  9370. return 1;
  9371. }
  9372. $next = $tokens->getNextMeaningfulToken($next);
  9373. if (null === $next || !$tokens[$next]->equals('=')) {
  9374. return 1;
  9375. }
  9376. $next = $tokens->getNextMeaningfulToken($next);
  9377. if (null === $next || !$tokens[$next]->isGivenKind(T_LNUMBER)) {
  9378. return 1;
  9379. }
  9380. $next = $tokens->getNextMeaningfulToken($next);
  9381. if (null === $next || !$tokens[$next]->equals(')')) {
  9382. return 1;
  9383. }
  9384. $next = $tokens->getNextMeaningfulToken($next);
  9385. if (null === $next || !$tokens[$next]->equals(';')) {
  9386. return 1;
  9387. }
  9388. return $next + 1;
  9389. }
  9390. private function fixWhiteSpaceAroundHeader(Tokens $tokens, $headerIndex)
  9391. {
  9392. $lineEnding = $this->whitespacesConfig->getLineEnding();
  9393. $expectedLineCount = 'both' === $this->configuration['separate'] || 'bottom' === $this->configuration['separate'] ? 2 : 1;
  9394. if ($headerIndex === count($tokens) - 1) {
  9395. $tokens->insertAt($headerIndex + 1, new Token([T_WHITESPACE, str_repeat($lineEnding, $expectedLineCount)]));
  9396. } else {
  9397. $afterCommentIndex = $tokens->getNextNonWhitespace($headerIndex);
  9398. $lineBreakCount = $this->getLineBreakCount($tokens, $headerIndex + 1, null === $afterCommentIndex ? count($tokens) : $afterCommentIndex);
  9399. if ($lineBreakCount < $expectedLineCount) {
  9400. $missing = str_repeat($lineEnding, $expectedLineCount - $lineBreakCount);
  9401. if ($tokens[$headerIndex + 1]->isWhitespace()) {
  9402. $tokens[$headerIndex + 1] = new Token([T_WHITESPACE, $missing.$tokens[$headerIndex + 1]->getContent()]);
  9403. } else {
  9404. $tokens->insertAt($headerIndex + 1, new Token([T_WHITESPACE, $missing]));
  9405. }
  9406. } elseif ($lineBreakCount > 2) {
  9407. if ($tokens[$headerIndex + 1]->isWhitespace()) {
  9408. $tokens[$headerIndex + 1] = new Token([T_WHITESPACE, $lineEnding.$lineEnding]);
  9409. }
  9410. }
  9411. }
  9412. $expectedLineCount = 'both' === $this->configuration['separate'] || 'top' === $this->configuration['separate'] ? 2 : 1;
  9413. $prev = $tokens->getPrevNonWhitespace($headerIndex);
  9414. $regex = '/[\t ]$/';
  9415. if ($tokens[$prev]->isGivenKind(T_OPEN_TAG) && preg_match($regex, $tokens[$prev]->getContent())) {
  9416. $tokens[$prev] = new Token([T_OPEN_TAG, preg_replace($regex, $lineEnding, $tokens[$prev]->getContent())]);
  9417. }
  9418. $lineBreakCount = $this->getLineBreakCount($tokens, $prev, $headerIndex);
  9419. if ($lineBreakCount < $expectedLineCount) {
  9420. $tokens->insertAt($headerIndex, new Token([T_WHITESPACE, str_repeat($lineEnding, $expectedLineCount - $lineBreakCount)]));
  9421. }
  9422. }
  9423. private function getLineBreakCount(Tokens $tokens, $indexStart, $indexEnd)
  9424. {
  9425. $lineCount = 0;
  9426. for ($i = $indexStart; $i < $indexEnd; ++$i) {
  9427. $lineCount += substr_count($tokens[$i]->getContent(), "\n");
  9428. }
  9429. return $lineCount;
  9430. }
  9431. private function insertHeader(Tokens $tokens, $index)
  9432. {
  9433. $tokens->insertAt($index, new Token([self::HEADER_COMMENT === $this->configuration['commentType'] ? T_COMMENT : T_DOC_COMMENT, $this->getHeaderAsComment()]));
  9434. }
  9435. }
  9436. <?php
  9437. namespace PhpCsFixer\Fixer\Comment;
  9438. use PhpCsFixer\AbstractFixer;
  9439. use PhpCsFixer\FixerDefinition\CodeSample;
  9440. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9441. use PhpCsFixer\Tokenizer\Token;
  9442. use PhpCsFixer\Tokenizer\Tokens;
  9443. final class MultilineCommentOpeningClosingFixer extends AbstractFixer
  9444. {
  9445. public function getDefinition()
  9446. {
  9447. return new FixerDefinition(
  9448. 'DocBlocks must start with two asterisks, multiline comments must start with a single asterisk, after the opening slash. Both must end with a single asterisk before the closing slash.',
  9449. [
  9450. new CodeSample(
  9451. <<<'EOT'
  9452. <?php
  9453. /******
  9454. * Multiline comment with arbitrary asterisks count
  9455. ******/
  9456. /**\
  9457. * Multiline comment that seems a DocBlock
  9458. */
  9459. /**
  9460. * DocBlock with arbitrary asterisk count at the end
  9461. **/
  9462. EOT
  9463. ),
  9464. ]
  9465. );
  9466. }
  9467. public function isCandidate(Tokens $tokens)
  9468. {
  9469. return $tokens->isAnyTokenKindsFound([T_COMMENT, T_DOC_COMMENT]);
  9470. }
  9471. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9472. {
  9473. foreach ($tokens as $index => $token) {
  9474. $originalContent = $token->getContent();
  9475. if (
  9476. !$token->isGivenKind(T_DOC_COMMENT)
  9477. && !($token->isGivenKind(T_COMMENT) && 0 === strpos($originalContent, '/*'))
  9478. ) {
  9479. continue;
  9480. }
  9481. $newContent = $originalContent;
  9482. if ($token->isGivenKind(T_COMMENT)) {
  9483. $newContent = preg_replace('/^\\/\\*\\*+/', '/*', $newContent);
  9484. }
  9485. $newContent = preg_replace('/\\*+\\*\\/$/', '*/', $newContent);
  9486. if ($newContent !== $originalContent) {
  9487. $tokens[$index] = new Token([$token->getId(), $newContent]);
  9488. }
  9489. }
  9490. }
  9491. }
  9492. <?php
  9493. namespace PhpCsFixer\Fixer\Comment;
  9494. use PhpCsFixer\AbstractFixer;
  9495. use PhpCsFixer\FixerDefinition\CodeSample;
  9496. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9497. use PhpCsFixer\Tokenizer\Tokens;
  9498. final class NoEmptyCommentFixer extends AbstractFixer
  9499. {
  9500. const TYPE_HASH = 1;
  9501. const TYPE_DOUBLE_SLASH = 2;
  9502. const TYPE_SLASH_ASTERISK = 3;
  9503. public function getPriority()
  9504. {
  9505. return 2;
  9506. }
  9507. public function getDefinition()
  9508. {
  9509. return new FixerDefinition(
  9510. 'There should not be any empty comments.',
  9511. [new CodeSample("<?php\n//\n#\n/* */\n")]
  9512. );
  9513. }
  9514. public function isCandidate(Tokens $tokens)
  9515. {
  9516. return $tokens->isTokenKindFound(T_COMMENT);
  9517. }
  9518. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9519. {
  9520. for ($index = 1, $count = count($tokens); $index < $count; ++$index) {
  9521. if (!$tokens[$index]->isGivenKind(T_COMMENT)) {
  9522. continue;
  9523. }
  9524. list($blockStart, $index, $isEmpty) = $this->getCommentBlock($tokens, $index);
  9525. if (false === $isEmpty) {
  9526. continue;
  9527. }
  9528. for ($i = $blockStart; $i <= $index; ++$i) {
  9529. $tokens->clearTokenAndMergeSurroundingWhitespace($i);
  9530. }
  9531. }
  9532. }
  9533. private function getCommentBlock(Tokens $tokens, $index)
  9534. {
  9535. $commentType = $this->getCommentType($tokens[$index]->getContent());
  9536. $empty = $this->isEmptyComment($tokens[$index]->getContent());
  9537. $start = $index;
  9538. $count = count($tokens);
  9539. ++$index;
  9540. for (; $index < $count; ++$index) {
  9541. if ($tokens[$index]->isComment()) {
  9542. if ($commentType !== $this->getCommentType($tokens[$index]->getContent())) {
  9543. break;
  9544. }
  9545. if ($empty) {
  9546. $empty = $this->isEmptyComment($tokens[$index]->getContent());
  9547. }
  9548. continue;
  9549. }
  9550. if (!$tokens[$index]->isWhitespace() || $this->getLineBreakCount($tokens, $index, $index + 1) > 1) {
  9551. break;
  9552. }
  9553. }
  9554. return [$start, $index - 1, $empty];
  9555. }
  9556. private function getCommentType($content)
  9557. {
  9558. if ('#' === $content[0]) {
  9559. return self::TYPE_HASH;
  9560. }
  9561. if ('*' === $content[1]) {
  9562. return self::TYPE_SLASH_ASTERISK;
  9563. }
  9564. return self::TYPE_DOUBLE_SLASH;
  9565. }
  9566. private function getLineBreakCount(Tokens $tokens, $whiteStart, $whiteEnd)
  9567. {
  9568. $lineCount = 0;
  9569. for ($i = $whiteStart; $i < $whiteEnd; ++$i) {
  9570. $lineCount += substr_count($tokens[$i]->getContent(), "\n");
  9571. }
  9572. return $lineCount;
  9573. }
  9574. private function isEmptyComment($content)
  9575. {
  9576. static $mapper = [
  9577. self::TYPE_HASH => '|^#\s*$|',
  9578. self::TYPE_SLASH_ASTERISK => '|^/\*\s*\*/$|',
  9579. self::TYPE_DOUBLE_SLASH => '|^//\s*$|',
  9580. ];
  9581. $type = $this->getCommentType($content);
  9582. return 1 === preg_match($mapper[$type], $content);
  9583. }
  9584. }
  9585. <?php
  9586. namespace PhpCsFixer\Fixer\Comment;
  9587. use PhpCsFixer\AbstractFixer;
  9588. use PhpCsFixer\FixerDefinition\CodeSample;
  9589. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9590. use PhpCsFixer\Tokenizer\Token;
  9591. use PhpCsFixer\Tokenizer\Tokens;
  9592. final class NoTrailingWhitespaceInCommentFixer extends AbstractFixer
  9593. {
  9594. public function getDefinition()
  9595. {
  9596. return new FixerDefinition(
  9597. 'There MUST be no trailing spaces inside comments and phpdocs.',
  9598. [new CodeSample('<?php
  9599. // This is '.'
  9600. // a comment. '.'
  9601. ')]
  9602. );
  9603. }
  9604. public function isCandidate(Tokens $tokens)
  9605. {
  9606. return $tokens->isAnyTokenKindsFound([T_COMMENT, T_DOC_COMMENT]);
  9607. }
  9608. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9609. {
  9610. foreach ($tokens as $index => $token) {
  9611. if ($token->isGivenKind(T_DOC_COMMENT)) {
  9612. $tokens[$index] = new Token([T_DOC_COMMENT, preg_replace('/[ \t]+$/m', '', $token->getContent())]);
  9613. continue;
  9614. }
  9615. if ($token->isGivenKind(T_COMMENT)) {
  9616. if ('/*' === substr($token->getContent(), 0, 2)) {
  9617. $tokens[$index] = new Token([T_COMMENT, preg_replace('/[ \t]+$/m', '', $token->getContent())]);
  9618. } elseif (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) {
  9619. $trimmedContent = ltrim($tokens[$index + 1]->getContent(), " \t");
  9620. if ('' !== $trimmedContent) {
  9621. $tokens[$index + 1] = new Token([T_WHITESPACE, $trimmedContent]);
  9622. } else {
  9623. $tokens->clearAt($index + 1);
  9624. }
  9625. }
  9626. }
  9627. }
  9628. }
  9629. }
  9630. <?php
  9631. namespace PhpCsFixer\Fixer\Comment;
  9632. use PhpCsFixer\AbstractFixer;
  9633. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  9634. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  9635. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  9636. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  9637. use PhpCsFixer\FixerDefinition\CodeSample;
  9638. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9639. use PhpCsFixer\Tokenizer\Token;
  9640. use PhpCsFixer\Tokenizer\Tokens;
  9641. final class SingleLineCommentStyleFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  9642. {
  9643. private $asteriskEnabled;
  9644. private $hashEnabled;
  9645. public function configure(array $configuration = null)
  9646. {
  9647. parent::configure($configuration);
  9648. $this->asteriskEnabled = in_array('asterisk', $this->configuration['comment_types'], true);
  9649. $this->hashEnabled = in_array('hash', $this->configuration['comment_types'], true);
  9650. }
  9651. public function getDefinition()
  9652. {
  9653. return new FixerDefinition(
  9654. 'Single-line comments and multi-line comments with only one line of actual content should use the `//` syntax.',
  9655. [
  9656. new CodeSample(
  9657. '<?php
  9658. /* asterisk comment */
  9659. $a = 1;
  9660. # hash comment
  9661. $b = 2;
  9662. /*
  9663. * multi-line
  9664. * comment
  9665. */
  9666. $c = 3;
  9667. '
  9668. ),
  9669. new CodeSample(
  9670. '<?php
  9671. /* first comment */
  9672. $a = 1;
  9673. /*
  9674. * second comment
  9675. */
  9676. $b = 2;
  9677. /*
  9678. * third
  9679. * comment
  9680. */
  9681. $c = 3;
  9682. ',
  9683. ['comment_types' => ['asterisk']]
  9684. ),
  9685. new CodeSample(
  9686. "<?php # comment\n",
  9687. ['comment_types' => ['hash']]
  9688. ),
  9689. ]
  9690. );
  9691. }
  9692. public function isCandidate(Tokens $tokens)
  9693. {
  9694. return $tokens->isTokenKindFound(T_COMMENT);
  9695. }
  9696. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9697. {
  9698. foreach ($tokens as $index => $token) {
  9699. if (!$token->isGivenKind(T_COMMENT)) {
  9700. continue;
  9701. }
  9702. $content = $token->getContent();
  9703. $commentContent = substr($content, 2, -2) ?: '';
  9704. if ($this->hashEnabled && '#' === $content[0]) {
  9705. $tokens[$index] = new Token([$token->getId(), '//'.substr($content, 1)]);
  9706. continue;
  9707. }
  9708. if (
  9709. !$this->asteriskEnabled
  9710. || false !== strpos($commentContent, '?>')
  9711. || '/*' !== substr($content, 0, 2)
  9712. || 1 === preg_match('/[^\s\*].*\R.*[^\s\*]/s', $commentContent)
  9713. ) {
  9714. continue;
  9715. }
  9716. $nextTokenIndex = $index + 1;
  9717. if (isset($tokens[$nextTokenIndex])) {
  9718. $nextToken = $tokens[$nextTokenIndex];
  9719. if (!$nextToken->isWhitespace() || 1 !== preg_match('/\R/', $nextToken->getContent())) {
  9720. continue;
  9721. }
  9722. $tokens[$nextTokenIndex] = new Token([$nextToken->getId(), ltrim($nextToken->getContent(), " \t")]);
  9723. }
  9724. $content = '//';
  9725. if (1 === preg_match('/[^\s\*]/', $commentContent)) {
  9726. $content = '// '.preg_replace('/[\s\*]*([^\s\*](?:.+[^\s\*])?)[\s\*]*/', '\1', $commentContent);
  9727. }
  9728. $tokens[$index] = new Token([$token->getId(), $content]);
  9729. }
  9730. }
  9731. protected function createConfigurationDefinition()
  9732. {
  9733. return new FixerConfigurationResolver([
  9734. (new FixerOptionBuilder('comment_types', 'List of comment types to fix'))
  9735. ->setAllowedTypes(['array'])
  9736. ->setAllowedValues([
  9737. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(['asterisk', 'hash']),
  9738. ])
  9739. ->setDefault(['asterisk', 'hash'])
  9740. ->getOption(),
  9741. ]);
  9742. }
  9743. }
  9744. <?php
  9745. namespace PhpCsFixer\Fixer;
  9746. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  9747. interface ConfigurableFixerInterface extends FixerInterface
  9748. {
  9749. public function configure(array $configuration = null);
  9750. }
  9751. <?php
  9752. namespace PhpCsFixer\Fixer;
  9753. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverInterface;
  9754. interface ConfigurationDefinitionFixerInterface extends ConfigurableFixerInterface
  9755. {
  9756. public function getConfigurationDefinition();
  9757. }
  9758. <?php
  9759. namespace PhpCsFixer\Fixer\ControlStructure;
  9760. use PhpCsFixer\AbstractFixer;
  9761. use PhpCsFixer\FixerDefinition\CodeSample;
  9762. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9763. use PhpCsFixer\Tokenizer\Token;
  9764. use PhpCsFixer\Tokenizer\Tokens;
  9765. final class ElseifFixer extends AbstractFixer
  9766. {
  9767. public function getDefinition()
  9768. {
  9769. return new FixerDefinition(
  9770. 'The keyword `elseif` should be used instead of `else if` so that all control keywords look like single words.',
  9771. [new CodeSample("<?php\nif (\$a) {\n} else if (\$b) {\n}\n")]
  9772. );
  9773. }
  9774. public function isCandidate(Tokens $tokens)
  9775. {
  9776. return $tokens->isAllTokenKindsFound([T_IF, T_ELSE]);
  9777. }
  9778. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9779. {
  9780. foreach ($tokens as $index => $token) {
  9781. if (!$token->isGivenKind(T_ELSE)) {
  9782. continue;
  9783. }
  9784. $ifTokenIndex = $tokens->getNextMeaningfulToken($index);
  9785. if (!$tokens[$ifTokenIndex]->isGivenKind(T_IF)) {
  9786. continue;
  9787. }
  9788. $tokens->clearAt($index + 1);
  9789. $tokens[$index] = new Token([T_ELSEIF, 'elseif']);
  9790. $tokens->clearAt($ifTokenIndex);
  9791. $beforeIfTokenIndex = $tokens->getPrevNonWhitespace($ifTokenIndex);
  9792. if ($tokens[$beforeIfTokenIndex]->isComment() && $tokens[$ifTokenIndex + 1]->isWhitespace()) {
  9793. $tokens->clearAt($ifTokenIndex + 1);
  9794. }
  9795. }
  9796. }
  9797. }
  9798. <?php
  9799. namespace PhpCsFixer\Fixer\ControlStructure;
  9800. use PhpCsFixer\AbstractFixer;
  9801. use PhpCsFixer\FixerDefinition\CodeSample;
  9802. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9803. use PhpCsFixer\Tokenizer\Token;
  9804. use PhpCsFixer\Tokenizer\Tokens;
  9805. final class IncludeFixer extends AbstractFixer
  9806. {
  9807. public function getDefinition()
  9808. {
  9809. return new FixerDefinition(
  9810. 'Include/Require and file path should be divided with a single space. File path should not be placed under brackets.',
  9811. [
  9812. new CodeSample(
  9813. '<?php
  9814. require ("sample1.php");
  9815. require_once "sample2.php";
  9816. include "sample3.php";
  9817. include_once("sample4.php");
  9818. '
  9819. ),
  9820. ]
  9821. );
  9822. }
  9823. public function isCandidate(Tokens $tokens)
  9824. {
  9825. return $tokens->isAnyTokenKindsFound([T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE]);
  9826. }
  9827. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9828. {
  9829. $this->clearIncludies($tokens, $this->findIncludies($tokens));
  9830. }
  9831. private function clearIncludies(Tokens $tokens, array $includies)
  9832. {
  9833. foreach (array_reverse($includies) as $includy) {
  9834. if ($includy['end'] && !$tokens[$includy['end']]->isGivenKind(T_CLOSE_TAG)) {
  9835. $afterEndIndex = $tokens->getNextNonWhitespace($includy['end']);
  9836. if (null === $afterEndIndex || !$tokens[$afterEndIndex]->isComment()) {
  9837. $tokens->removeLeadingWhitespace($includy['end']);
  9838. }
  9839. }
  9840. $braces = $includy['braces'];
  9841. if ($braces) {
  9842. $nextToken = $tokens[$tokens->getNextMeaningfulToken($braces['close'])];
  9843. if ($nextToken->equalsAny([';', [T_CLOSE_TAG]])) {
  9844. $this->removeWhitespaceAroundIfPossible($tokens, $braces['open']);
  9845. $this->removeWhitespaceAroundIfPossible($tokens, $braces['close']);
  9846. $tokens->clearTokenAndMergeSurroundingWhitespace($braces['open']);
  9847. $tokens->clearTokenAndMergeSurroundingWhitespace($braces['close']);
  9848. $nextSiblingIndex = $tokens->getNonEmptySibling($includy['begin'], 1);
  9849. if (!$tokens[$nextSiblingIndex]->isWhitespace()) {
  9850. $tokens->insertAt($nextSiblingIndex, new Token([T_WHITESPACE, ' ']));
  9851. }
  9852. }
  9853. }
  9854. $nextIndex = $includy['begin'] + 1;
  9855. while ($tokens->isEmptyAt($nextIndex)) {
  9856. ++$nextIndex;
  9857. }
  9858. if ($tokens[$nextIndex]->isWhitespace()) {
  9859. $tokens[$nextIndex] = new Token([T_WHITESPACE, ' ']);
  9860. } elseif ($braces || $tokens[$nextIndex]->isGivenKind([T_VARIABLE, T_CONSTANT_ENCAPSED_STRING, T_COMMENT])) {
  9861. $tokens->insertAt($includy['begin'] + 1, new Token([T_WHITESPACE, ' ']));
  9862. }
  9863. }
  9864. }
  9865. private function findIncludies(Tokens $tokens)
  9866. {
  9867. static $includyTokenKinds = [T_REQUIRE, T_REQUIRE_ONCE, T_INCLUDE, T_INCLUDE_ONCE];
  9868. $includies = [];
  9869. foreach ($tokens->findGivenKind($includyTokenKinds) as $includyTokens) {
  9870. foreach ($includyTokens as $index => $token) {
  9871. $includy = [
  9872. 'begin' => $index,
  9873. 'braces' => null,
  9874. 'end' => $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]),
  9875. ];
  9876. $nextTokenIndex = $tokens->getNextMeaningfulToken($index);
  9877. $nextToken = $tokens[$nextTokenIndex];
  9878. if ($nextToken->equals('(')) {
  9879. $braceCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextTokenIndex);
  9880. if ($tokens[$tokens->getNextMeaningfulToken($braceCloseIndex)]->equalsAny([';', [T_CLOSE_TAG]])) {
  9881. $includy['braces'] = [
  9882. 'open' => $nextTokenIndex,
  9883. 'close' => $braceCloseIndex,
  9884. ];
  9885. }
  9886. }
  9887. $includies[] = $includy;
  9888. }
  9889. }
  9890. return $includies;
  9891. }
  9892. private function removeWhitespaceAroundIfPossible(Tokens $tokens, $index)
  9893. {
  9894. $nextIndex = $tokens->getNextNonWhitespace($index);
  9895. if (null === $nextIndex || !$tokens[$nextIndex]->isComment()) {
  9896. $tokens->removeLeadingWhitespace($index);
  9897. }
  9898. $prevIndex = $tokens->getPrevNonWhitespace($index);
  9899. if (null === $prevIndex || !$tokens[$prevIndex]->isComment()) {
  9900. $tokens->removeTrailingWhitespace($index);
  9901. }
  9902. }
  9903. }
  9904. <?php
  9905. namespace PhpCsFixer\Fixer\ControlStructure;
  9906. use PhpCsFixer\AbstractFixer;
  9907. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  9908. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  9909. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  9910. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  9911. use PhpCsFixer\FixerDefinition\CodeSample;
  9912. use PhpCsFixer\FixerDefinition\FixerDefinition;
  9913. use PhpCsFixer\Tokenizer\Token;
  9914. use PhpCsFixer\Tokenizer\Tokens;
  9915. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  9916. use Symfony\Component\OptionsResolver\Options;
  9917. final class NoBreakCommentFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  9918. {
  9919. public function getDefinition()
  9920. {
  9921. return new FixerDefinition(
  9922. 'There must be a comment when fall-through is intentional in a non-empty case body.',
  9923. [
  9924. new CodeSample(
  9925. '<?php
  9926. switch ($foo) {
  9927. case 1:
  9928. foo();
  9929. case 2:
  9930. bar();
  9931. // no break
  9932. break;
  9933. case 3:
  9934. baz();
  9935. }
  9936. '
  9937. ),
  9938. ],
  9939. 'Adds a "no break" comment before fall-through cases, and removes it if there is no fall-through.'
  9940. );
  9941. }
  9942. public function isCandidate(Tokens $tokens)
  9943. {
  9944. return $tokens->isAnyTokenKindsFound([T_CASE, T_DEFAULT]);
  9945. }
  9946. protected function createConfigurationDefinition()
  9947. {
  9948. return new FixerConfigurationResolver([
  9949. (new FixerOptionBuilder('comment_text', 'The text to use in the added comment and to detect it.'))
  9950. ->setAllowedTypes(['string'])
  9951. ->setAllowedValues([
  9952. function ($value) {
  9953. if (is_string($value) && preg_match('/\R/', $value)) {
  9954. throw new InvalidOptionsException('The comment text must not contain new lines.');
  9955. }
  9956. return true;
  9957. },
  9958. ])
  9959. ->setNormalizer(function (Options $options, $value) {
  9960. return rtrim($value);
  9961. })
  9962. ->setDefault('no break')
  9963. ->getOption(),
  9964. ]);
  9965. }
  9966. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  9967. {
  9968. for ($position = count($tokens) - 1; $position >= 0; --$position) {
  9969. if ($tokens[$position]->isGivenKind([T_CASE, T_DEFAULT])) {
  9970. $this->fixCase($tokens, $position);
  9971. }
  9972. }
  9973. }
  9974. private function fixCase(Tokens $tokens, $casePosition)
  9975. {
  9976. $empty = true;
  9977. $fallThrough = true;
  9978. $commentPosition = null;
  9979. for ($i = $tokens->getNextTokenOfKind($casePosition, [':', ';']) + 1, $max = count($tokens); $i < $max; ++$i) {
  9980. if ($tokens[$i]->isGivenKind([T_SWITCH, T_IF, T_ELSE, T_ELSEIF, T_FOR, T_FOREACH, T_WHILE, T_DO, T_FUNCTION, T_CLASS])) {
  9981. $empty = false;
  9982. $i = $this->getStructureEnd($tokens, $i);
  9983. continue;
  9984. }
  9985. if ($tokens[$i]->isGivenKind([T_BREAK, T_CONTINUE, T_RETURN, T_EXIT, T_THROW, T_GOTO])) {
  9986. $fallThrough = false;
  9987. continue;
  9988. }
  9989. if ($tokens[$i]->equals('}') || $tokens[$i]->isGivenKind(T_ENDSWITCH)) {
  9990. if (null !== $commentPosition) {
  9991. $this->removeComment($tokens, $commentPosition);
  9992. }
  9993. break;
  9994. }
  9995. if ($this->isNoBreakComment($tokens[$i])) {
  9996. $commentPosition = $i;
  9997. continue;
  9998. }
  9999. if ($tokens[$i]->isGivenKind([T_CASE, T_DEFAULT])) {
  10000. if (!$empty && $fallThrough) {
  10001. if (null !== $commentPosition && $tokens->getPrevNonWhitespace($i) !== $commentPosition) {
  10002. $this->removeComment($tokens, $commentPosition);
  10003. $commentPosition = null;
  10004. }
  10005. if (null === $commentPosition) {
  10006. $this->insertCommentAt($tokens, $i);
  10007. } else {
  10008. $text = $this->configuration['comment_text'];
  10009. $tokens[$commentPosition] = new Token([
  10010. $tokens[$commentPosition]->getId(),
  10011. str_ireplace($text, $text, $tokens[$commentPosition]->getContent()),
  10012. ]);
  10013. $this->ensureNewLineAt($tokens, $commentPosition);
  10014. }
  10015. } elseif (null !== $commentPosition) {
  10016. $this->removeComment($tokens, $commentPosition);
  10017. }
  10018. break;
  10019. }
  10020. if (!$tokens[$i]->isGivenKind([T_COMMENT, T_WHITESPACE])) {
  10021. $empty = false;
  10022. }
  10023. }
  10024. }
  10025. private function isNoBreakComment(Token $token)
  10026. {
  10027. if (!$token->isComment()) {
  10028. return false;
  10029. }
  10030. $text = preg_quote($this->configuration['comment_text'], '~');
  10031. return preg_match("~^((//|#)\\s*${text}\\s*)|(/\\*\\*?\\s*${text}\\s*\\*/)$~i", $token->getContent());
  10032. }
  10033. private function insertCommentAt(Tokens $tokens, $casePosition)
  10034. {
  10035. $lineEnding = $this->whitespacesConfig->getLineEnding();
  10036. $newlinePosition = $this->ensureNewLineAt($tokens, $casePosition);
  10037. $newlineToken = $tokens[$newlinePosition];
  10038. $nbNewlines = substr_count($newlineToken->getContent(), $lineEnding);
  10039. if ($newlineToken->isGivenKind(T_OPEN_TAG) && preg_match('/\R/', $newlineToken->getContent())) {
  10040. ++$nbNewlines;
  10041. } elseif ($tokens[$newlinePosition - 1]->isGivenKind(T_OPEN_TAG) && preg_match('/\R/', $tokens[$newlinePosition - 1]->getContent())) {
  10042. ++$nbNewlines;
  10043. if (!preg_match('/\R/', $newlineToken->getContent())) {
  10044. $tokens[$newlinePosition] = new Token([$newlineToken->getId(), $lineEnding.$newlineToken->getContent()]);
  10045. }
  10046. }
  10047. if ($nbNewlines > 1) {
  10048. preg_match('/^(.*?)(\R[ \t]*)$/s', $newlineToken->getContent(), $matches);
  10049. $indent = $this->getIndentAt($tokens, $newlinePosition - 1);
  10050. $tokens[$newlinePosition] = new Token([$newlineToken->getId(), $matches[1].$lineEnding.$indent]);
  10051. $tokens->insertAt(++$newlinePosition, new Token([T_WHITESPACE, $matches[2]]));
  10052. }
  10053. $tokens->insertAt($newlinePosition, new Token([T_COMMENT, '// '.$this->configuration['comment_text']]));
  10054. $this->ensureNewLineAt($tokens, $newlinePosition);
  10055. }
  10056. private function ensureNewLineAt(Tokens $tokens, $position)
  10057. {
  10058. $lineEnding = $this->whitespacesConfig->getLineEnding();
  10059. $content = $lineEnding.$this->getIndentAt($tokens, $position);
  10060. $whitespaceToken = $tokens[$position - 1];
  10061. if (!$whitespaceToken->isGivenKind(T_WHITESPACE)) {
  10062. if ($whitespaceToken->isGivenKind(T_OPEN_TAG)) {
  10063. $content = preg_replace('/\R/', '', $content);
  10064. if (!preg_match('/\R/', $whitespaceToken->getContent())) {
  10065. $tokens[$position - 1] = new Token([T_OPEN_TAG, preg_replace('/\s+$/', $lineEnding, $whitespaceToken->getContent())]);
  10066. }
  10067. }
  10068. if ('' !== $content) {
  10069. $tokens->insertAt($position, new Token([T_WHITESPACE, $content]));
  10070. return $position;
  10071. }
  10072. return $position - 1;
  10073. }
  10074. if ($tokens[$position - 2]->isGivenKind(T_OPEN_TAG) && preg_match('/\R/', $tokens[$position - 2]->getContent())) {
  10075. $content = preg_replace('/^\R/', '', $content);
  10076. }
  10077. if (!preg_match('/\R/', $whitespaceToken->getContent())) {
  10078. $tokens[$position - 1] = new Token([T_WHITESPACE, $content]);
  10079. }
  10080. return $position - 1;
  10081. }
  10082. private function removeComment(Tokens $tokens, $commentPosition)
  10083. {
  10084. if ($tokens[$tokens->getPrevNonWhitespace($commentPosition)]->isGivenKind(T_OPEN_TAG)) {
  10085. $whitespacePosition = $commentPosition + 1;
  10086. $regex = '/^\R[ \t]*/';
  10087. } else {
  10088. $whitespacePosition = $commentPosition - 1;
  10089. $regex = '/\R[ \t]*$/';
  10090. }
  10091. $whitespaceToken = $tokens[$whitespacePosition];
  10092. if ($whitespaceToken->isGivenKind(T_WHITESPACE)) {
  10093. $content = preg_replace($regex, '', $whitespaceToken->getContent());
  10094. if ('' !== $content) {
  10095. $tokens[$whitespacePosition] = new Token([T_WHITESPACE, $content]);
  10096. } else {
  10097. $tokens->clearAt($whitespacePosition);
  10098. }
  10099. }
  10100. $tokens->clearTokenAndMergeSurroundingWhitespace($commentPosition);
  10101. }
  10102. private function getIndentAt(Tokens $tokens, $position)
  10103. {
  10104. while (true) {
  10105. $position = $tokens->getPrevTokenOfKind($position, [[T_WHITESPACE]]);
  10106. if (null === $position) {
  10107. break;
  10108. }
  10109. $content = $tokens[$position]->getContent();
  10110. $prevToken = $tokens[$position - 1];
  10111. if ($prevToken->isGivenKind(T_OPEN_TAG) && preg_match('/\R$/', $prevToken->getContent())) {
  10112. $content = $this->whitespacesConfig->getLineEnding().$content;
  10113. }
  10114. if (preg_match('/\R([ \t]*)$/', $content, $matches)) {
  10115. return $matches[1];
  10116. }
  10117. }
  10118. return '';
  10119. }
  10120. private function getStructureEnd(Tokens $tokens, $position)
  10121. {
  10122. $initialToken = $tokens[$position];
  10123. if ($initialToken->isGivenKind([T_FOR, T_FOREACH, T_WHILE, T_IF, T_ELSEIF, T_SWITCH, T_FUNCTION])) {
  10124. $position = $tokens->findBlockEnd(
  10125. Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
  10126. $tokens->getNextTokenOfKind($position, ['('])
  10127. );
  10128. } elseif ($initialToken->isGivenKind([T_CLASS])) {
  10129. $openParenthesisPosition = $tokens->getNextMeaningfulToken($position);
  10130. if ('(' === $tokens[$openParenthesisPosition]->getContent()) {
  10131. $position = $tokens->findBlockEnd(
  10132. Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
  10133. $openParenthesisPosition
  10134. );
  10135. }
  10136. }
  10137. $position = $tokens->getNextMeaningfulToken($position);
  10138. if ('{' !== $tokens[$position]->getContent()) {
  10139. return $tokens->getNextTokenOfKind($position, [';']);
  10140. }
  10141. $position = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $position);
  10142. if ($initialToken->isGivenKind([T_DO])) {
  10143. $position = $tokens->findBlockEnd(
  10144. Tokens::BLOCK_TYPE_PARENTHESIS_BRACE,
  10145. $tokens->getNextTokenOfKind($position, ['('])
  10146. );
  10147. return $tokens->getNextTokenOfKind($position, [';']);
  10148. }
  10149. return $position;
  10150. }
  10151. }
  10152. <?php
  10153. namespace PhpCsFixer\Fixer\ControlStructure;
  10154. use PhpCsFixer\AbstractNoUselessElseFixer;
  10155. use PhpCsFixer\FixerDefinition\CodeSample;
  10156. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10157. use PhpCsFixer\Tokenizer\Token;
  10158. use PhpCsFixer\Tokenizer\Tokens;
  10159. final class NoSuperfluousElseifFixer extends AbstractNoUselessElseFixer
  10160. {
  10161. public function isCandidate(Tokens $tokens)
  10162. {
  10163. return $tokens->isAnyTokenKindsFound([T_ELSE, T_ELSEIF]);
  10164. }
  10165. public function getDefinition()
  10166. {
  10167. return new FixerDefinition(
  10168. 'Replaces superfluous `elseif` with `if`.',
  10169. [
  10170. new CodeSample("<?php\nif (\$a) {\n return 1;\n} elseif (\$b) {\n return 2;\n}\n"),
  10171. ]
  10172. );
  10173. }
  10174. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10175. {
  10176. foreach ($tokens as $index => $token) {
  10177. if ($this->isElseif($tokens, $index) && $this->isSuperfluousElse($tokens, $index)) {
  10178. $this->convertElseifToIf($tokens, $index);
  10179. }
  10180. }
  10181. }
  10182. private function isElseif(Tokens $tokens, $index)
  10183. {
  10184. if ($tokens[$index]->isGivenKind(T_ELSEIF)) {
  10185. return true;
  10186. }
  10187. return $tokens[$index]->isGivenKind(T_ELSE) && $tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind(T_IF);
  10188. }
  10189. private function convertElseifToIf(Tokens $tokens, $index)
  10190. {
  10191. if ($tokens[$index]->isGivenKind(T_ELSE)) {
  10192. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  10193. } else {
  10194. $tokens[$index] = new Token([T_IF, 'if']);
  10195. }
  10196. $whitespace = '';
  10197. for ($previous = $index - 1; $previous > 0; --$previous) {
  10198. $token = $tokens[$previous];
  10199. if ($token->isWhitespace() && preg_match('/(\R[^\R]*)$/', $token->getContent(), $matches)) {
  10200. $whitespace = $matches[1];
  10201. break;
  10202. }
  10203. }
  10204. $previousToken = $tokens[$index - 1];
  10205. if (!$previousToken->isWhitespace()) {
  10206. $tokens->insertAt($index, new Token([T_WHITESPACE, $whitespace]));
  10207. } elseif (!preg_match('/\R/', $previousToken->getContent())) {
  10208. $tokens[$index - 1] = new Token([T_WHITESPACE, $whitespace]);
  10209. }
  10210. }
  10211. }
  10212. <?php
  10213. namespace PhpCsFixer\Fixer\ControlStructure;
  10214. use PhpCsFixer\AbstractFixer;
  10215. use PhpCsFixer\FixerDefinition\CodeSample;
  10216. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10217. use PhpCsFixer\Tokenizer\Tokens;
  10218. final class NoTrailingCommaInListCallFixer extends AbstractFixer
  10219. {
  10220. public function getDefinition()
  10221. {
  10222. return new FixerDefinition(
  10223. 'Remove trailing commas in list function calls.',
  10224. [new CodeSample("<?php\nlist(\$a, \$b,) = foo();\n")]
  10225. );
  10226. }
  10227. public function isCandidate(Tokens $tokens)
  10228. {
  10229. return $tokens->isTokenKindFound(T_LIST);
  10230. }
  10231. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10232. {
  10233. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  10234. $token = $tokens[$index];
  10235. if (!$token->isGivenKind(T_LIST)) {
  10236. continue;
  10237. }
  10238. $openIndex = $tokens->getNextMeaningfulToken($index);
  10239. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
  10240. $markIndex = null;
  10241. $prevIndex = $tokens->getPrevNonWhitespace($closeIndex);
  10242. while ($tokens[$prevIndex]->equals(',')) {
  10243. $markIndex = $prevIndex;
  10244. $prevIndex = $tokens->getPrevNonWhitespace($prevIndex);
  10245. }
  10246. if (null !== $markIndex) {
  10247. $tokens->clearRange(
  10248. $tokens->getPrevNonWhitespace($markIndex) + 1,
  10249. $closeIndex - 1
  10250. );
  10251. }
  10252. }
  10253. }
  10254. }
  10255. <?php
  10256. namespace PhpCsFixer\Fixer\ControlStructure;
  10257. use PhpCsFixer\AbstractFixer;
  10258. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  10259. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  10260. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  10261. use PhpCsFixer\FixerDefinition\CodeSample;
  10262. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10263. use PhpCsFixer\Tokenizer\CT;
  10264. use PhpCsFixer\Tokenizer\Token;
  10265. use PhpCsFixer\Tokenizer\Tokens;
  10266. final class NoUnneededControlParenthesesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  10267. {
  10268. private static $loops = [
  10269. 'break' => ['lookupTokens' => T_BREAK, 'neededSuccessors' => [';']],
  10270. 'clone' => ['lookupTokens' => T_CLONE, 'neededSuccessors' => [';', ':', ',', ')'], 'forbiddenContents' => ['?', ':']],
  10271. 'continue' => ['lookupTokens' => T_CONTINUE, 'neededSuccessors' => [';']],
  10272. 'echo_print' => ['lookupTokens' => [T_ECHO, T_PRINT], 'neededSuccessors' => [';', [T_CLOSE_TAG]]],
  10273. 'return' => ['lookupTokens' => T_RETURN, 'neededSuccessors' => [';', [T_CLOSE_TAG]]],
  10274. 'switch_case' => ['lookupTokens' => T_CASE, 'neededSuccessors' => [';', ':']],
  10275. 'yield' => ['lookupTokens' => T_YIELD, 'neededSuccessors' => [';', ')']],
  10276. ];
  10277. public function __construct()
  10278. {
  10279. parent::__construct();
  10280. if (defined('T_COALESCE')) {
  10281. self::$loops['clone']['forbiddenContents'][] = [T_COALESCE, '??'];
  10282. }
  10283. }
  10284. public function isCandidate(Tokens $tokens)
  10285. {
  10286. $types = [];
  10287. foreach (self::$loops as $loop) {
  10288. $types[] = (array) $loop['lookupTokens'];
  10289. }
  10290. $types = array_merge(...$types);
  10291. return $tokens->isAnyTokenKindsFound($types);
  10292. }
  10293. public function getDefinition()
  10294. {
  10295. return new FixerDefinition(
  10296. 'Removes unneeded parentheses around control statements.',
  10297. [
  10298. new CodeSample(
  10299. '<?php
  10300. while ($x) { while ($y) { break (2); } }
  10301. clone($a);
  10302. while ($y) { continue (2); }
  10303. echo("foo");
  10304. print("foo");
  10305. return (1 + 2);
  10306. switch ($a) { case($x); }
  10307. yield(2);
  10308. '
  10309. ),
  10310. new CodeSample(
  10311. '<?php
  10312. while ($x) { while ($y) { break (2); } }
  10313. clone($a);
  10314. while ($y) { continue (2); }
  10315. echo("foo");
  10316. print("foo");
  10317. return (1 + 2);
  10318. switch ($a) { case($x); }
  10319. yield(2);
  10320. ',
  10321. ['statements' => ['break', 'continue']]
  10322. ),
  10323. ]
  10324. );
  10325. }
  10326. public function getPriority()
  10327. {
  10328. return 30;
  10329. }
  10330. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10331. {
  10332. $loops = array_intersect_key(self::$loops, array_flip($this->configuration['statements']));
  10333. foreach ($tokens as $index => $token) {
  10334. if (!$token->equalsAny(['(', [CT::T_BRACE_CLASS_INSTANTIATION_OPEN]])) {
  10335. continue;
  10336. }
  10337. $blockStartIndex = $index;
  10338. $index = $tokens->getPrevMeaningfulToken($index);
  10339. $prevToken = $tokens[$index];
  10340. foreach ($loops as $loop) {
  10341. if (!$prevToken->isGivenKind($loop['lookupTokens'])) {
  10342. continue;
  10343. }
  10344. $blockEndIndex = $tokens->findBlockEnd(
  10345. $token->equals('(') ? Tokens::BLOCK_TYPE_PARENTHESIS_BRACE : Tokens::BLOCK_TYPE_BRACE_CLASS_INSTANTIATION,
  10346. $blockStartIndex
  10347. );
  10348. $blockEndNextIndex = $tokens->getNextMeaningfulToken($blockEndIndex);
  10349. if (!$tokens[$blockEndNextIndex]->equalsAny($loop['neededSuccessors'])) {
  10350. continue;
  10351. }
  10352. if (array_key_exists('forbiddenContents', $loop)) {
  10353. $forbiddenTokenIndex = $tokens->getNextTokenOfKind($blockStartIndex, $loop['forbiddenContents']);
  10354. if (null !== $forbiddenTokenIndex && $forbiddenTokenIndex < $blockEndIndex) {
  10355. continue;
  10356. }
  10357. }
  10358. if ($tokens[$blockStartIndex - 1]->isWhitespace() || $tokens[$blockStartIndex - 1]->isComment()) {
  10359. $tokens->clearTokenAndMergeSurroundingWhitespace($blockStartIndex);
  10360. } else {
  10361. $tokens[$blockStartIndex] = new Token([T_WHITESPACE, ' ']);
  10362. }
  10363. $tokens->clearTokenAndMergeSurroundingWhitespace($blockEndIndex);
  10364. }
  10365. }
  10366. }
  10367. protected function createConfigurationDefinition()
  10368. {
  10369. return new FixerConfigurationResolverRootless('statements', [
  10370. (new FixerOptionBuilder('statements', 'List of control statements to fix.'))
  10371. ->setAllowedTypes(['array'])
  10372. ->setDefault([
  10373. 'break',
  10374. 'clone',
  10375. 'continue',
  10376. 'echo_print',
  10377. 'return',
  10378. 'switch_case',
  10379. 'yield',
  10380. ])
  10381. ->getOption(),
  10382. ]);
  10383. }
  10384. }
  10385. <?php
  10386. namespace PhpCsFixer\Fixer\ControlStructure;
  10387. use PhpCsFixer\AbstractFixer;
  10388. use PhpCsFixer\FixerDefinition\CodeSample;
  10389. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10390. use PhpCsFixer\Tokenizer\Tokens;
  10391. final class NoUnneededCurlyBracesFixer extends AbstractFixer
  10392. {
  10393. public function getDefinition()
  10394. {
  10395. return new FixerDefinition(
  10396. 'Removes unneeded curly braces that are superfluous and aren\'t part of a control structure\'s body.',
  10397. [
  10398. new CodeSample(
  10399. '<?php {
  10400. echo 1;
  10401. }
  10402. switch ($b) {
  10403. case 1: {
  10404. break;
  10405. }
  10406. }
  10407. '
  10408. ),
  10409. ]
  10410. );
  10411. }
  10412. public function getPriority()
  10413. {
  10414. return 26;
  10415. }
  10416. public function isCandidate(Tokens $tokens)
  10417. {
  10418. return $tokens->isTokenKindFound('}');
  10419. }
  10420. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10421. {
  10422. foreach ($this->findCurlyBraceOpen($tokens) as $index) {
  10423. if ($this->isOverComplete($tokens, $index)) {
  10424. $this->clearOverCompleteBraces($tokens, $index, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index));
  10425. }
  10426. }
  10427. }
  10428. private function clearOverCompleteBraces(Tokens $tokens, $openIndex, $closeIndex)
  10429. {
  10430. $tokens->clearTokenAndMergeSurroundingWhitespace($closeIndex);
  10431. $tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
  10432. }
  10433. private function findCurlyBraceOpen(Tokens $tokens)
  10434. {
  10435. for ($i = count($tokens) - 1; $i > 0; --$i) {
  10436. if ($tokens[$i]->equals('{')) {
  10437. yield $i;
  10438. }
  10439. }
  10440. }
  10441. private function isOverComplete(Tokens $tokens, $index)
  10442. {
  10443. static $whiteList = ['{', '}', [T_OPEN_TAG], ':', ';'];
  10444. return $tokens[$tokens->getPrevMeaningfulToken($index)]->equalsAny($whiteList);
  10445. }
  10446. }
  10447. <?php
  10448. namespace PhpCsFixer\Fixer\ControlStructure;
  10449. use PhpCsFixer\AbstractNoUselessElseFixer;
  10450. use PhpCsFixer\FixerDefinition\CodeSample;
  10451. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10452. use PhpCsFixer\Tokenizer\Tokens;
  10453. final class NoUselessElseFixer extends AbstractNoUselessElseFixer
  10454. {
  10455. public function isCandidate(Tokens $tokens)
  10456. {
  10457. return $tokens->isTokenKindFound(T_ELSE);
  10458. }
  10459. public function getDefinition()
  10460. {
  10461. return new FixerDefinition(
  10462. 'There should not be useless `else` cases.',
  10463. [
  10464. new CodeSample("<?php\nif (\$a) {\n return 1;\n} else {\n return 2;\n}\n"),
  10465. ]
  10466. );
  10467. }
  10468. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10469. {
  10470. foreach ($tokens as $index => $token) {
  10471. if (!$token->isGivenKind(T_ELSE)) {
  10472. continue;
  10473. }
  10474. if ($tokens[$tokens->getNextMeaningfulToken($index)]->equalsAny([':', [T_IF]])) {
  10475. continue;
  10476. }
  10477. $this->fixEmptyElse($tokens, $index);
  10478. if ($tokens->isEmptyAt($index)) {
  10479. continue;
  10480. }
  10481. if ($this->isSuperfluousElse($tokens, $index)) {
  10482. $this->clearElse($tokens, $index);
  10483. }
  10484. }
  10485. }
  10486. private function fixEmptyElse(Tokens $tokens, $index)
  10487. {
  10488. $next = $tokens->getNextMeaningfulToken($index);
  10489. if ($tokens[$next]->equals('{')) {
  10490. $close = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $next);
  10491. if (1 === $close - $next) {
  10492. $this->clearElse($tokens, $index);
  10493. } elseif ($tokens->getNextMeaningfulToken($next) === $close) {
  10494. $this->clearElse($tokens, $index);
  10495. }
  10496. return;
  10497. }
  10498. $end = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]);
  10499. if ($next === $end) {
  10500. $this->clearElse($tokens, $index);
  10501. }
  10502. }
  10503. private function clearElse(Tokens $tokens, $index)
  10504. {
  10505. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  10506. $next = $tokens->getNextMeaningfulToken($index);
  10507. if (!$tokens[$next]->equals('{')) {
  10508. return;
  10509. }
  10510. $tokens->clearTokenAndMergeSurroundingWhitespace($tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $next));
  10511. $tokens->clearTokenAndMergeSurroundingWhitespace($next);
  10512. }
  10513. }
  10514. <?php
  10515. namespace PhpCsFixer\Fixer\ControlStructure;
  10516. use PhpCsFixer\AbstractFixer;
  10517. use PhpCsFixer\FixerDefinition\CodeSample;
  10518. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10519. use PhpCsFixer\Tokenizer\Token;
  10520. use PhpCsFixer\Tokenizer\Tokens;
  10521. final class SwitchCaseSemicolonToColonFixer extends AbstractFixer
  10522. {
  10523. public function getDefinition()
  10524. {
  10525. return new FixerDefinition(
  10526. 'A case should be followed by a colon and not a semicolon.',
  10527. [
  10528. new CodeSample(
  10529. '<?php
  10530. switch ($a) {
  10531. case 1;
  10532. break;
  10533. default;
  10534. break;
  10535. }
  10536. '
  10537. ),
  10538. ]
  10539. );
  10540. }
  10541. public function isCandidate(Tokens $tokens)
  10542. {
  10543. return $tokens->isAnyTokenKindsFound([T_CASE, T_DEFAULT]);
  10544. }
  10545. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10546. {
  10547. foreach ($tokens as $index => $token) {
  10548. if ($token->isGivenKind([T_CASE, T_DEFAULT])) {
  10549. $this->fixSwitchCase($tokens, $index);
  10550. }
  10551. }
  10552. }
  10553. protected function fixSwitchCase(Tokens $tokens, $index)
  10554. {
  10555. $ternariesCount = 0;
  10556. do {
  10557. if ($tokens[$index]->equalsAny(['(', '{'])) {
  10558. $type = Tokens::detectBlockType($tokens[$index]);
  10559. $index = $tokens->findBlockEnd($type['type'], $index);
  10560. continue;
  10561. }
  10562. if ($tokens[$index]->equals('?')) {
  10563. ++$ternariesCount;
  10564. continue;
  10565. }
  10566. if ($tokens[$index]->equalsAny([':', ';'])) {
  10567. if (0 === $ternariesCount) {
  10568. break;
  10569. }
  10570. --$ternariesCount;
  10571. }
  10572. } while (++$index);
  10573. if ($tokens[$index]->equals(';')) {
  10574. $tokens[$index] = new Token(':');
  10575. }
  10576. }
  10577. }
  10578. <?php
  10579. namespace PhpCsFixer\Fixer\ControlStructure;
  10580. use PhpCsFixer\AbstractFixer;
  10581. use PhpCsFixer\FixerDefinition\CodeSample;
  10582. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10583. use PhpCsFixer\Tokenizer\Tokens;
  10584. final class SwitchCaseSpaceFixer extends AbstractFixer
  10585. {
  10586. public function getDefinition()
  10587. {
  10588. return new FixerDefinition(
  10589. 'Removes extra spaces between colon and case value.',
  10590. [
  10591. new CodeSample(
  10592. '<?php
  10593. switch($a) {
  10594. case 1 :
  10595. break;
  10596. default :
  10597. return 2;
  10598. }
  10599. '
  10600. ),
  10601. ]
  10602. );
  10603. }
  10604. public function isCandidate(Tokens $tokens)
  10605. {
  10606. return $tokens->isAnyTokenKindsFound([T_CASE, T_DEFAULT]);
  10607. }
  10608. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10609. {
  10610. foreach ($tokens as $index => $token) {
  10611. if (!$token->isGivenKind([T_CASE, T_DEFAULT])) {
  10612. continue;
  10613. }
  10614. $ternariesCount = 0;
  10615. for ($colonIndex = $index + 1;; ++$colonIndex) {
  10616. if ($tokens[$colonIndex]->equals('?')) {
  10617. ++$ternariesCount;
  10618. }
  10619. if ($tokens[$colonIndex]->equalsAny([':', ';'])) {
  10620. if (0 === $ternariesCount) {
  10621. break;
  10622. }
  10623. --$ternariesCount;
  10624. }
  10625. }
  10626. $valueIndex = $tokens->getPrevNonWhitespace($colonIndex);
  10627. if ($valueIndex === $colonIndex - 1 || $tokens[$valueIndex]->isComment()) {
  10628. continue;
  10629. }
  10630. $tokens->clearAt($valueIndex + 1);
  10631. }
  10632. }
  10633. }
  10634. <?php
  10635. namespace PhpCsFixer\Fixer\ControlStructure;
  10636. use PhpCsFixer\AbstractFixer;
  10637. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  10638. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  10639. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  10640. use PhpCsFixer\FixerDefinition\CodeSample;
  10641. use PhpCsFixer\FixerDefinition\FixerDefinition;
  10642. use PhpCsFixer\Tokenizer\CT;
  10643. use PhpCsFixer\Tokenizer\Token;
  10644. use PhpCsFixer\Tokenizer\Tokens;
  10645. final class YodaStyleFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  10646. {
  10647. private $candidatesMap;
  10648. private $candidateTypes;
  10649. public function configure(array $configuration = null)
  10650. {
  10651. parent::configure($configuration);
  10652. $this->resolveConfiguration();
  10653. }
  10654. public function getDefinition()
  10655. {
  10656. return new FixerDefinition(
  10657. 'Write conditions in Yoda style (`true`), non-Yoda style (`false`) or ignore those conditions (`null`) based on configuration.',
  10658. [
  10659. new CodeSample(
  10660. '<?php
  10661. if ($a === null) {
  10662. echo "null";
  10663. }
  10664. '
  10665. ),
  10666. new CodeSample(
  10667. '<?php
  10668. $b = $c != 1; // equal
  10669. $a = 1 === $b; // identical
  10670. $c = $c > 3; // less than
  10671. ',
  10672. [
  10673. 'equal' => true,
  10674. 'identical' => false,
  10675. 'less_and_greater' => null,
  10676. ]
  10677. ),
  10678. ]
  10679. );
  10680. }
  10681. public function isCandidate(Tokens $tokens)
  10682. {
  10683. return $tokens->isAnyTokenKindsFound($this->candidateTypes);
  10684. }
  10685. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  10686. {
  10687. $this->fixTokens($tokens);
  10688. }
  10689. protected function createConfigurationDefinition()
  10690. {
  10691. return new FixerConfigurationResolver([
  10692. (new FixerOptionBuilder('equal', 'Style for equal (`==`, `!=`) statements.'))
  10693. ->setAllowedTypes(['bool', 'null'])
  10694. ->setDefault(true)
  10695. ->getOption(),
  10696. (new FixerOptionBuilder('identical', 'Style for identical (`===`, `!==`) statements.'))
  10697. ->setAllowedTypes(['bool', 'null'])
  10698. ->setDefault(true)
  10699. ->getOption(),
  10700. (new FixerOptionBuilder('less_and_greater', 'Style for less and greater than (`<`, `<=`, `>`, `>=`) statements.'))
  10701. ->setAllowedTypes(['bool', 'null'])
  10702. ->setDefault(null)
  10703. ->getOption(),
  10704. ]);
  10705. }
  10706. private function findComparisonEnd(Tokens $tokens, $index)
  10707. {
  10708. ++$index;
  10709. $count = count($tokens);
  10710. while ($index < $count) {
  10711. $token = $tokens[$index];
  10712. if ($this->isOfLowerPrecedence($token)) {
  10713. break;
  10714. }
  10715. $block = Tokens::detectBlockType($token);
  10716. if (null === $block) {
  10717. ++$index;
  10718. continue;
  10719. }
  10720. if (!$block['isStart']) {
  10721. break;
  10722. }
  10723. $index = $tokens->findBlockEnd($block['type'], $index) + 1;
  10724. }
  10725. $prev = $tokens->getPrevMeaningfulToken($index);
  10726. return $tokens[$prev]->isGivenKind(T_CLOSE_TAG) ? $tokens->getPrevMeaningfulToken($prev) : $prev;
  10727. }
  10728. private function findComparisonStart(Tokens $tokens, $index)
  10729. {
  10730. --$index;
  10731. while (0 <= $index) {
  10732. $token = $tokens[$index];
  10733. if ($this->isOfLowerPrecedence($token)) {
  10734. break;
  10735. }
  10736. $block = Tokens::detectBlockType($token);
  10737. if (null === $block) {
  10738. --$index;
  10739. continue;
  10740. }
  10741. if ($block['isStart']) {
  10742. break;
  10743. }
  10744. $index = $tokens->findBlockEnd($block['type'], $index, false) - 1;
  10745. }
  10746. return $tokens->getNextMeaningfulToken($index);
  10747. }
  10748. private function fixTokens(Tokens $tokens)
  10749. {
  10750. for ($i = count($tokens) - 1; $i > 1; --$i) {
  10751. if ($tokens[$i]->isGivenKind($this->candidateTypes)) {
  10752. $yoda = $this->configuration[$tokens[$i]->getId()];
  10753. } elseif (
  10754. ($tokens[$i]->equals('<') && in_array('<', $this->candidateTypes, true))
  10755. || ($tokens[$i]->equals('>') && in_array('>', $this->candidateTypes, true))
  10756. ) {
  10757. $yoda = $this->configuration[$tokens[$i]->getContent()];
  10758. } else {
  10759. continue;
  10760. }
  10761. $fixableCompareInfo = $this->getCompareFixableInfo($tokens, $i, $yoda);
  10762. if (null === $fixableCompareInfo) {
  10763. continue;
  10764. }
  10765. $i = $this->fixTokensCompare(
  10766. $tokens,
  10767. $fixableCompareInfo['left']['start'],
  10768. $fixableCompareInfo['left']['end'],
  10769. $i,
  10770. $fixableCompareInfo['right']['start'],
  10771. $fixableCompareInfo['right']['end']
  10772. );
  10773. }
  10774. return $tokens;
  10775. }
  10776. private function fixTokensCompare(
  10777. Tokens $tokens,
  10778. $startLeft,
  10779. $endLeft,
  10780. $compareOperatorIndex,
  10781. $startRight,
  10782. $endRight
  10783. ) {
  10784. $type = $tokens[$compareOperatorIndex]->getId();
  10785. $content = $tokens[$compareOperatorIndex]->getContent();
  10786. if (array_key_exists($type, $this->candidatesMap)) {
  10787. $tokens[$compareOperatorIndex] = clone $this->candidatesMap[$type];
  10788. } elseif (array_key_exists($content, $this->candidatesMap)) {
  10789. $tokens[$compareOperatorIndex] = clone $this->candidatesMap[$content];
  10790. }
  10791. $right = $this->fixTokensComparePart($tokens, $startRight, $endRight);
  10792. $left = $this->fixTokensComparePart($tokens, $startLeft, $endLeft);
  10793. for ($i = $startRight; $i <= $endRight; ++$i) {
  10794. $tokens->clearAt($i);
  10795. }
  10796. for ($i = $startLeft; $i <= $endLeft; ++$i) {
  10797. $tokens->clearAt($i);
  10798. }
  10799. $tokens->insertAt($startRight, $left);
  10800. $tokens->insertAt($startLeft, $right);
  10801. return $startLeft;
  10802. }
  10803. private function fixTokensComparePart(Tokens $tokens, $start, $end)
  10804. {
  10805. $newTokens = $tokens->generatePartialCode($start, $end);
  10806. $newTokens = $this->fixTokens(Tokens::fromCode(sprintf('<?php %s;', $newTokens)));
  10807. $newTokens->clearAt(count($newTokens) - 1);
  10808. $newTokens->clearAt(0);
  10809. $newTokens->clearEmptyTokens();
  10810. return $newTokens;
  10811. }
  10812. private function getCompareFixableInfo(Tokens $tokens, $index, $yoda)
  10813. {
  10814. if ($yoda) {
  10815. $right = $this->getRightSideCompareFixableInfo($tokens, $index);
  10816. if ($this->isVariable($tokens, $right['start'], $right['end']) || $this->isListStatement($tokens, $right['start'], $right['end'])) {
  10817. return null;
  10818. }
  10819. $left = $this->getLeftSideCompareFixableInfo($tokens, $index);
  10820. $otherIsVar = $this->isVariable($tokens, $left['start'], $left['end']);
  10821. } else {
  10822. $left = $this->getLeftSideCompareFixableInfo($tokens, $index);
  10823. if ($this->isVariable($tokens, $left['start'], $left['end']) || $this->isListStatement($tokens, $left['start'], $left['end'])) {
  10824. return null;
  10825. }
  10826. $right = $this->getRightSideCompareFixableInfo($tokens, $index);
  10827. $otherIsVar = $this->isVariable($tokens, $right['start'], $right['end']);
  10828. }
  10829. if (!$otherIsVar) {
  10830. return null;
  10831. }
  10832. return [
  10833. 'left' => $left,
  10834. 'right' => $right,
  10835. ];
  10836. }
  10837. private function getLeftSideCompareFixableInfo(Tokens $tokens, $index)
  10838. {
  10839. return [
  10840. 'start' => $this->findComparisonStart($tokens, $index),
  10841. 'end' => $tokens->getPrevMeaningfulToken($index),
  10842. ];
  10843. }
  10844. private function getRightSideCompareFixableInfo(Tokens $tokens, $index)
  10845. {
  10846. return [
  10847. 'start' => $tokens->getNextMeaningfulToken($index),
  10848. 'end' => $this->findComparisonEnd($tokens, $index),
  10849. ];
  10850. }
  10851. private function isListStatement(Tokens $tokens, $index, $end)
  10852. {
  10853. for ($i = $index; $i <= $end; ++$i) {
  10854. if ($tokens[$i]->isGivenKind([T_LIST, CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE])) {
  10855. return true;
  10856. }
  10857. }
  10858. return false;
  10859. }
  10860. private function isOfLowerPrecedence(Token $token)
  10861. {
  10862. if ($token->isGivenKind([T_WHITESPACE, T_COMMENT, T_DOC_COMMENT])) {
  10863. return false;
  10864. }
  10865. static $tokens;
  10866. if (null === $tokens) {
  10867. $tokens = [
  10868. T_AND_EQUAL,
  10869. T_BOOLEAN_AND,
  10870. T_BOOLEAN_OR,
  10871. T_CASE,
  10872. T_CONCAT_EQUAL,
  10873. T_DIV_EQUAL,
  10874. T_DOUBLE_ARROW,
  10875. T_GOTO,
  10876. T_LOGICAL_AND,
  10877. T_LOGICAL_OR,
  10878. T_LOGICAL_XOR,
  10879. T_MINUS_EQUAL,
  10880. T_MUL_EQUAL,
  10881. T_OR_EQUAL,
  10882. T_PLUS_EQUAL,
  10883. T_RETURN,
  10884. T_SL_EQUAL,
  10885. T_SR_EQUAL,
  10886. T_THROW,
  10887. T_XOR_EQUAL,
  10888. T_ECHO,
  10889. T_PRINT,
  10890. T_OPEN_TAG,
  10891. T_OPEN_TAG_WITH_ECHO,
  10892. ];
  10893. if (defined('T_POW_EQUAL')) {
  10894. $tokens[] = T_POW_EQUAL;
  10895. }
  10896. if (defined('T_COALESCE')) {
  10897. $tokens[] = T_COALESCE;
  10898. }
  10899. }
  10900. static $otherTokens = [
  10901. '&', '|', '^',
  10902. '?', ':',
  10903. '=',
  10904. ',', ';',
  10905. ];
  10906. return $token->isGivenKind($tokens) || $token->equalsAny($otherTokens);
  10907. }
  10908. private function isVariable(Tokens $tokens, $index, $end)
  10909. {
  10910. if ($end === $index) {
  10911. return $tokens[$index]->isGivenKind(T_VARIABLE);
  10912. }
  10913. while (
  10914. $tokens[$index]->equals('(')
  10915. && $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index) === $end
  10916. ) {
  10917. $index = $tokens->getNextMeaningfulToken($index);
  10918. $end = $tokens->getPrevMeaningfulToken($end);
  10919. }
  10920. $expectString = false;
  10921. while ($index <= $end) {
  10922. $current = $tokens[$index];
  10923. if ($current->isComment() || $current->isWhitespace() || $tokens->isEmptyAt($index)) {
  10924. ++$index;
  10925. continue;
  10926. }
  10927. if ($index === $end) {
  10928. return $current->isGivenKind($expectString ? T_STRING : T_VARIABLE);
  10929. }
  10930. if ($current->isGivenKind([T_LIST, CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE])) {
  10931. return false;
  10932. }
  10933. $nextIndex = $tokens->getNextMeaningfulToken($index);
  10934. $next = $tokens[$nextIndex];
  10935. if ($current->isGivenKind(T_STRING) && $next->isGivenKind(T_DOUBLE_COLON)) {
  10936. $index = $tokens->getNextMeaningfulToken($nextIndex);
  10937. continue;
  10938. }
  10939. if ($current->isGivenKind(T_NS_SEPARATOR) && $next->isGivenKind(T_STRING)) {
  10940. $index = $nextIndex;
  10941. continue;
  10942. }
  10943. if ($current->isGivenKind(T_STRING) && $next->isGivenKind(T_NS_SEPARATOR)) {
  10944. $index = $nextIndex;
  10945. continue;
  10946. }
  10947. if ($current->isGivenKind($expectString ? T_STRING : T_VARIABLE) && $next->isGivenKind(T_OBJECT_OPERATOR)) {
  10948. $index = $tokens->getNextMeaningfulToken($nextIndex);
  10949. $expectString = true;
  10950. continue;
  10951. }
  10952. if ($current->isGivenKind($expectString ? T_STRING : T_VARIABLE) && $next->equals('[')) {
  10953. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index + 1);
  10954. if ($index === $end) {
  10955. return true;
  10956. }
  10957. $index = $tokens->getNextMeaningfulToken($index);
  10958. if (!$tokens[$index]->isGivenKind(T_OBJECT_OPERATOR)) {
  10959. return false;
  10960. }
  10961. $index = $tokens->getNextMeaningfulToken($index);
  10962. $expectString = true;
  10963. continue;
  10964. }
  10965. if ($expectString && $current->isGivenKind(CT::T_DYNAMIC_PROP_BRACE_OPEN)) {
  10966. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_DYNAMIC_PROP_BRACE, $index);
  10967. if ($index === $end) {
  10968. return true;
  10969. }
  10970. $index = $tokens->getNextMeaningfulToken($index);
  10971. if (!$tokens[$index]->isGivenKind(T_OBJECT_OPERATOR)) {
  10972. return false;
  10973. }
  10974. $index = $tokens->getNextMeaningfulToken($index);
  10975. $expectString = true;
  10976. continue;
  10977. }
  10978. break;
  10979. }
  10980. return true;
  10981. }
  10982. private function resolveConfiguration()
  10983. {
  10984. $candidateTypes = [];
  10985. $this->candidatesMap = [];
  10986. if (null !== $this->configuration['equal']) {
  10987. $candidateTypes[T_IS_EQUAL] = $this->configuration['equal'];
  10988. $candidateTypes[T_IS_NOT_EQUAL] = $this->configuration['equal'];
  10989. }
  10990. if (null !== $this->configuration['identical']) {
  10991. $candidateTypes[T_IS_IDENTICAL] = $this->configuration['identical'];
  10992. $candidateTypes[T_IS_NOT_IDENTICAL] = $this->configuration['identical'];
  10993. }
  10994. if (null !== $this->configuration['less_and_greater']) {
  10995. $candidateTypes[T_IS_SMALLER_OR_EQUAL] = $this->configuration['less_and_greater'];
  10996. $this->candidatesMap[T_IS_SMALLER_OR_EQUAL] = new Token([T_IS_GREATER_OR_EQUAL, '>=']);
  10997. $candidateTypes[T_IS_GREATER_OR_EQUAL] = $this->configuration['less_and_greater'];
  10998. $this->candidatesMap[T_IS_GREATER_OR_EQUAL] = new Token([T_IS_SMALLER_OR_EQUAL, '<=']);
  10999. $candidateTypes['<'] = $this->configuration['less_and_greater'];
  11000. $this->candidatesMap['<'] = new Token('>');
  11001. $candidateTypes['>'] = $this->configuration['less_and_greater'];
  11002. $this->candidatesMap['>'] = new Token('<');
  11003. }
  11004. $this->configuration = $candidateTypes;
  11005. $this->candidateTypes = array_keys($candidateTypes);
  11006. }
  11007. }
  11008. <?php
  11009. namespace PhpCsFixer\Fixer;
  11010. use PhpCsFixer\FixerDefinition\FixerDefinitionInterface;
  11011. interface DefinedFixerInterface extends FixerInterface
  11012. {
  11013. public function getDefinition();
  11014. }
  11015. <?php
  11016. namespace PhpCsFixer\Fixer;
  11017. interface DeprecatedFixerInterface extends FixerInterface
  11018. {
  11019. public function getSuccessorsNames();
  11020. }
  11021. <?php
  11022. namespace PhpCsFixer\Fixer\DoctrineAnnotation;
  11023. use Doctrine\Common\Annotations\DocLexer;
  11024. use PhpCsFixer\AbstractDoctrineAnnotationFixer;
  11025. use PhpCsFixer\Doctrine\Annotation\Tokens;
  11026. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11027. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11028. use PhpCsFixer\FixerDefinition\CodeSample;
  11029. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11030. final class DoctrineAnnotationArrayAssignmentFixer extends AbstractDoctrineAnnotationFixer
  11031. {
  11032. public function getDefinition()
  11033. {
  11034. return new FixerDefinition(
  11035. 'Doctrine annotations must use configured operator for assignment in arrays.',
  11036. [
  11037. new CodeSample(
  11038. "<?php\n/**\n * @Foo({bar : \"baz\"})\n */\nclass Bar {}\n"
  11039. ),
  11040. new CodeSample(
  11041. "<?php\n/**\n * @Foo({bar = \"baz\"})\n */\nclass Bar {}\n",
  11042. ['operator' => ':']
  11043. ),
  11044. ]
  11045. );
  11046. }
  11047. public function getPriority()
  11048. {
  11049. return 1;
  11050. }
  11051. protected function createConfigurationDefinition()
  11052. {
  11053. $options = parent::createConfigurationDefinition()->getOptions();
  11054. $operator = new FixerOptionBuilder('operator', 'The operator to use.');
  11055. $options[] = $operator
  11056. ->setAllowedValues(['=', ':'])
  11057. ->setDefault('=')
  11058. ->getOption()
  11059. ;
  11060. return new FixerConfigurationResolver($options);
  11061. }
  11062. protected function fixAnnotations(Tokens $tokens)
  11063. {
  11064. $scopes = [];
  11065. foreach ($tokens as $index => $token) {
  11066. if ($token->isType(DocLexer::T_OPEN_PARENTHESIS)) {
  11067. $scopes[] = 'annotation';
  11068. continue;
  11069. }
  11070. if ($token->isType(DocLexer::T_OPEN_CURLY_BRACES)) {
  11071. $scopes[] = 'array';
  11072. continue;
  11073. }
  11074. if ($token->isType([DocLexer::T_CLOSE_PARENTHESIS, DocLexer::T_CLOSE_CURLY_BRACES])) {
  11075. array_pop($scopes);
  11076. continue;
  11077. }
  11078. if ('array' === end($scopes) && $token->isType([DocLexer::T_EQUALS, DocLexer::T_COLON])) {
  11079. $token->setContent($this->configuration['operator']);
  11080. }
  11081. }
  11082. }
  11083. }
  11084. <?php
  11085. namespace PhpCsFixer\Fixer\DoctrineAnnotation;
  11086. use Doctrine\Common\Annotations\DocLexer;
  11087. use PhpCsFixer\AbstractDoctrineAnnotationFixer;
  11088. use PhpCsFixer\Doctrine\Annotation\Token;
  11089. use PhpCsFixer\Doctrine\Annotation\Tokens;
  11090. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11091. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11092. use PhpCsFixer\FixerDefinition\CodeSample;
  11093. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11094. final class DoctrineAnnotationBracesFixer extends AbstractDoctrineAnnotationFixer
  11095. {
  11096. public function getDefinition()
  11097. {
  11098. return new FixerDefinition(
  11099. 'Doctrine annotations without arguments must use the configured syntax.',
  11100. [
  11101. new CodeSample(
  11102. "<?php\n/**\n * @Foo()\n */\nclass Bar {}\n"
  11103. ),
  11104. new CodeSample(
  11105. "<?php\n/**\n * @Foo\n */\nclass Bar {}\n",
  11106. ['syntax' => 'with_braces']
  11107. ),
  11108. ]
  11109. );
  11110. }
  11111. protected function createConfigurationDefinition()
  11112. {
  11113. return new FixerConfigurationResolver(array_merge(
  11114. parent::createConfigurationDefinition()->getOptions(),
  11115. [
  11116. (new FixerOptionBuilder('syntax', 'Whether to add or remove braces.'))
  11117. ->setAllowedValues(['with_braces', 'without_braces'])
  11118. ->setDefault('without_braces')
  11119. ->getOption(),
  11120. ]
  11121. ));
  11122. }
  11123. protected function fixAnnotations(Tokens $tokens)
  11124. {
  11125. if ('without_braces' === $this->configuration['syntax']) {
  11126. $this->removesBracesFromAnnotations($tokens);
  11127. } else {
  11128. $this->addBracesToAnnotations($tokens);
  11129. }
  11130. }
  11131. private function addBracesToAnnotations(Tokens $tokens)
  11132. {
  11133. foreach ($tokens as $index => $token) {
  11134. if (!$tokens[$index]->isType(DocLexer::T_AT)) {
  11135. continue;
  11136. }
  11137. $braceIndex = $tokens->getNextMeaningfulToken($index + 1);
  11138. if (null !== $braceIndex && $tokens[$braceIndex]->isType(DocLexer::T_OPEN_PARENTHESIS)) {
  11139. continue;
  11140. }
  11141. $tokens->insertAt($index + 2, new Token(DocLexer::T_OPEN_PARENTHESIS, '('));
  11142. $tokens->insertAt($index + 3, new Token(DocLexer::T_CLOSE_PARENTHESIS, ')'));
  11143. }
  11144. }
  11145. private function removesBracesFromAnnotations(Tokens $tokens)
  11146. {
  11147. for ($index = 0, $max = count($tokens); $index < $max; ++$index) {
  11148. if (!$tokens[$index]->isType(DocLexer::T_AT)) {
  11149. continue;
  11150. }
  11151. $openBraceIndex = $tokens->getNextMeaningfulToken($index + 1);
  11152. if (null === $openBraceIndex) {
  11153. continue;
  11154. }
  11155. if (!$tokens[$openBraceIndex]->isType(DocLexer::T_OPEN_PARENTHESIS)) {
  11156. continue;
  11157. }
  11158. $closeBraceIndex = $tokens->getNextMeaningfulToken($openBraceIndex);
  11159. if (null === $closeBraceIndex) {
  11160. continue;
  11161. }
  11162. if (!$tokens[$closeBraceIndex]->isType(DocLexer::T_CLOSE_PARENTHESIS)) {
  11163. continue;
  11164. }
  11165. for ($currentIndex = $index + 2; $currentIndex <= $closeBraceIndex; ++$currentIndex) {
  11166. $tokens[$currentIndex]->clear();
  11167. }
  11168. }
  11169. }
  11170. }
  11171. <?php
  11172. namespace PhpCsFixer\Fixer\DoctrineAnnotation;
  11173. use Doctrine\Common\Annotations\DocLexer;
  11174. use PhpCsFixer\AbstractDoctrineAnnotationFixer;
  11175. use PhpCsFixer\Doctrine\Annotation\Tokens;
  11176. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11177. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11178. use PhpCsFixer\FixerDefinition\CodeSample;
  11179. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11180. final class DoctrineAnnotationIndentationFixer extends AbstractDoctrineAnnotationFixer
  11181. {
  11182. public function getDefinition()
  11183. {
  11184. return new FixerDefinition(
  11185. 'Doctrine annotations must be indented with four spaces.',
  11186. [
  11187. new CodeSample("<?php\n/**\n * @Foo(\n * foo=\"foo\"\n * )\n */\nclass Bar {}\n"),
  11188. new CodeSample(
  11189. "<?php\n/**\n * @Foo({@Bar,\n * @Baz})\n */\nclass Bar {}\n",
  11190. ['indent_mixed_lines' => true]
  11191. ),
  11192. ]
  11193. );
  11194. }
  11195. protected function createConfigurationDefinition()
  11196. {
  11197. return new FixerConfigurationResolver(array_merge(
  11198. parent::createConfigurationDefinition()->getOptions(),
  11199. [
  11200. (new FixerOptionBuilder('indent_mixed_lines', 'Whether to indent lines that have content before closing parenthesis.'))
  11201. ->setAllowedTypes(['bool'])
  11202. ->setDefault(false)
  11203. ->getOption(),
  11204. ]
  11205. ));
  11206. }
  11207. protected function fixAnnotations(Tokens $tokens)
  11208. {
  11209. $annotationPositions = [];
  11210. for ($index = 0, $max = count($tokens); $index < $max; ++$index) {
  11211. if (!$tokens[$index]->isType(DocLexer::T_AT)) {
  11212. continue;
  11213. }
  11214. $annotationEndIndex = $tokens->getAnnotationEnd($index);
  11215. if (null === $annotationEndIndex) {
  11216. return;
  11217. }
  11218. $annotationPositions[] = [$index, $annotationEndIndex];
  11219. $index = $annotationEndIndex;
  11220. }
  11221. $previousLineBracesDelta = 0;
  11222. $indentLevel = 0;
  11223. foreach ($tokens as $index => $token) {
  11224. if (!$token->isType(DocLexer::T_NONE) || false === strpos($token->getContent(), "\n")) {
  11225. continue;
  11226. }
  11227. if (!$this->indentationCanBeFixed($tokens, $index, $annotationPositions)) {
  11228. continue;
  11229. }
  11230. $currentLineDelta = $this->getLineBracesDelta($tokens, $index);
  11231. $extraIndentLevel = 0;
  11232. if ($previousLineBracesDelta > 0) {
  11233. ++$indentLevel;
  11234. }
  11235. if ($currentLineDelta < 0 && $indentLevel > 0) {
  11236. --$indentLevel;
  11237. if ($this->configuration['indent_mixed_lines'] && $this->isClosingLineWithMeaningfulContent($tokens, $index)) {
  11238. $extraIndentLevel = 1;
  11239. }
  11240. }
  11241. $previousLineBracesDelta = $currentLineDelta;
  11242. $token->setContent(preg_replace(
  11243. '/(\n( +\*)?) *$/',
  11244. '$1'.str_repeat(' ', 4 * ($indentLevel + $extraIndentLevel) + 1),
  11245. $token->getContent()
  11246. ));
  11247. }
  11248. }
  11249. private function getLineBracesDelta(Tokens $tokens, $index)
  11250. {
  11251. $lineBracesDelta = 0;
  11252. while (isset($tokens[++$index])) {
  11253. $token = $tokens[$index];
  11254. if ($token->isType(DocLexer::T_NONE) && false !== strpos($token->getContent(), "\n")) {
  11255. break;
  11256. }
  11257. if ($token->isType([DocLexer::T_OPEN_PARENTHESIS, DocLexer::T_OPEN_CURLY_BRACES])) {
  11258. ++$lineBracesDelta;
  11259. continue;
  11260. }
  11261. if ($token->isType([DocLexer::T_CLOSE_PARENTHESIS, DocLexer::T_CLOSE_CURLY_BRACES])) {
  11262. --$lineBracesDelta;
  11263. continue;
  11264. }
  11265. }
  11266. return $lineBracesDelta;
  11267. }
  11268. private function isClosingLineWithMeaningfulContent(Tokens $tokens, $index)
  11269. {
  11270. while (isset($tokens[++$index])) {
  11271. $token = $tokens[$index];
  11272. if ($token->isType(DocLexer::T_NONE)) {
  11273. if (false !== strpos($token->getContent(), "\n")) {
  11274. return false;
  11275. }
  11276. continue;
  11277. }
  11278. return !$token->isType([DocLexer::T_CLOSE_PARENTHESIS, DocLexer::T_CLOSE_CURLY_BRACES]);
  11279. }
  11280. return false;
  11281. }
  11282. private function indentationCanBeFixed(Tokens $tokens, $newLineTokenIndex, array $annotationPositions)
  11283. {
  11284. foreach ($annotationPositions as $position) {
  11285. if ($newLineTokenIndex >= $position[0] && $newLineTokenIndex <= $position[1]) {
  11286. return true;
  11287. }
  11288. }
  11289. for ($index = $newLineTokenIndex + 1, $max = count($tokens); $index < $max; ++$index) {
  11290. $token = $tokens[$index];
  11291. if (false !== strpos($token->getContent(), "\n")) {
  11292. return false;
  11293. }
  11294. return $tokens[$index]->isType(DocLexer::T_AT);
  11295. }
  11296. return false;
  11297. }
  11298. }
  11299. <?php
  11300. namespace PhpCsFixer\Fixer\DoctrineAnnotation;
  11301. use Doctrine\Common\Annotations\DocLexer;
  11302. use PhpCsFixer\AbstractDoctrineAnnotationFixer;
  11303. use PhpCsFixer\Doctrine\Annotation\Token;
  11304. use PhpCsFixer\Doctrine\Annotation\Tokens;
  11305. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11306. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11307. use PhpCsFixer\FixerDefinition\CodeSample;
  11308. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11309. final class DoctrineAnnotationSpacesFixer extends AbstractDoctrineAnnotationFixer
  11310. {
  11311. public function getDefinition()
  11312. {
  11313. return new FixerDefinition(
  11314. 'Fixes spaces in Doctrine annotations.',
  11315. [
  11316. new CodeSample(
  11317. "<?php\n/**\n * @Foo ( )\n */\nclass Bar {}\n\n/**\n * @Foo(\"bar\" ,\"baz\")\n */\nclass Bar2 {}\n\n/**\n * @Foo(foo = \"foo\", bar = {\"foo\":\"foo\", \"bar\"=\"bar\"})\n */\nclass Bar3 {}\n"
  11318. ),
  11319. ],
  11320. 'There must not be any space around parentheses; commas must be preceded by no space and followed by one space; there must be no space around named arguments assignment operator; there must be one space around array assignment operator.'
  11321. );
  11322. }
  11323. public function configure(array $configuration = null)
  11324. {
  11325. parent::configure($configuration);
  11326. if (null !== $configuration) {
  11327. if (array_key_exists('around_argument_assignments', $configuration)) {
  11328. @trigger_error('Option "around_argument_assignments" is deprecated and will be removed in 3.0, use options "before_argument_assignments" and "after_argument_assignments" instead.', E_USER_DEPRECATED);
  11329. }
  11330. if (array_key_exists('around_array_assignments', $configuration)) {
  11331. @trigger_error('Option "around_array_assignments" is deprecated and will be removed in 3.0, use options "before_array_assignments_equals", "after_array_assignments_equals", "before_array_assignments_colon" and "after_array_assignments_colon" instead.', E_USER_DEPRECATED);
  11332. }
  11333. }
  11334. if (!$this->configuration['around_argument_assignments']) {
  11335. foreach ([
  11336. 'before_argument_assignments',
  11337. 'after_argument_assignments',
  11338. ] as $newOption) {
  11339. if (!array_key_exists($newOption, $configuration)) {
  11340. $this->configuration[$newOption] = null;
  11341. }
  11342. }
  11343. }
  11344. if (!$this->configuration['around_array_assignments']) {
  11345. foreach ([
  11346. 'before_array_assignments_equals',
  11347. 'after_array_assignments_equals',
  11348. 'before_array_assignments_colon',
  11349. 'after_array_assignments_colon',
  11350. ] as $newOption) {
  11351. if (!array_key_exists($newOption, $configuration)) {
  11352. $this->configuration[$newOption] = null;
  11353. }
  11354. }
  11355. }
  11356. }
  11357. protected function createConfigurationDefinition()
  11358. {
  11359. return new FixerConfigurationResolver(array_merge(
  11360. parent::createConfigurationDefinition()->getOptions(),
  11361. [
  11362. (new FixerOptionBuilder('around_parentheses', 'Whether to fix spaces around parentheses.'))
  11363. ->setAllowedTypes(['bool'])
  11364. ->setDefault(true)
  11365. ->getOption(),
  11366. (new FixerOptionBuilder('around_commas', 'Whether to fix spaces around commas.'))
  11367. ->setAllowedTypes(['bool'])
  11368. ->setDefault(true)
  11369. ->getOption(),
  11370. (new FixerOptionBuilder('around_argument_assignments', 'Whether to fix spaces around argument assignment operator (deprecated, use `before_argument_assignments` and `after_argument_assignments` options instead).'))
  11371. ->setAllowedTypes(['bool'])
  11372. ->setDefault(true)
  11373. ->getOption(),
  11374. (new FixerOptionBuilder('before_argument_assignments', 'Whether to add, remove or ignore spaces before argument assignment operator.'))
  11375. ->setAllowedTypes(['null', 'bool'])
  11376. ->setDefault(false)
  11377. ->getOption(),
  11378. (new FixerOptionBuilder('after_argument_assignments', 'Whether to add, remove or ignore spaces after argument assignment operator.'))
  11379. ->setAllowedTypes(['null', 'bool'])
  11380. ->setDefault(false)
  11381. ->getOption(),
  11382. (new FixerOptionBuilder('around_array_assignments', 'Whether to fix spaces around array assignment operators (deprecated, use `before_array_assignments_*` and `after_array_assignments_*` options instead).'))
  11383. ->setAllowedTypes(['bool'])
  11384. ->setDefault(true)
  11385. ->getOption(),
  11386. (new FixerOptionBuilder('before_array_assignments_equals', 'Whether to add, remove or ignore spaces before array `=` assignment operator.'))
  11387. ->setAllowedTypes(['null', 'bool'])
  11388. ->setDefault(true)
  11389. ->getOption(),
  11390. (new FixerOptionBuilder('after_array_assignments_equals', 'Whether to add, remove or ignore spaces after array assignment `=` operator.'))
  11391. ->setAllowedTypes(['null', 'bool'])
  11392. ->setDefault(true)
  11393. ->getOption(),
  11394. (new FixerOptionBuilder('before_array_assignments_colon', 'Whether to add, remove or ignore spaces before array `:` assignment operator.'))
  11395. ->setAllowedTypes(['null', 'bool'])
  11396. ->setDefault(true)
  11397. ->getOption(),
  11398. (new FixerOptionBuilder('after_array_assignments_colon', 'Whether to add, remove or ignore spaces after array assignment `:` operator.'))
  11399. ->setAllowedTypes(['null', 'bool'])
  11400. ->setDefault(true)
  11401. ->getOption(),
  11402. ]
  11403. ));
  11404. }
  11405. protected function fixAnnotations(Tokens $tokens)
  11406. {
  11407. if ($this->configuration['around_parentheses']) {
  11408. $this->fixSpacesAroundParentheses($tokens);
  11409. }
  11410. if ($this->configuration['around_commas']) {
  11411. $this->fixSpacesAroundCommas($tokens);
  11412. }
  11413. if (
  11414. null !== $this->configuration['before_argument_assignments']
  11415. || null !== $this->configuration['after_argument_assignments']
  11416. || null !== $this->configuration['before_array_assignments_equals']
  11417. || null !== $this->configuration['after_array_assignments_equals']
  11418. || null !== $this->configuration['before_array_assignments_colon']
  11419. || null !== $this->configuration['after_array_assignments_colon']
  11420. ) {
  11421. $this->fixAroundAssignments($tokens);
  11422. }
  11423. }
  11424. private function fixSpacesAroundParentheses(Tokens $tokens)
  11425. {
  11426. $inAnnotationUntilIndex = null;
  11427. foreach ($tokens as $index => $token) {
  11428. if (null !== $inAnnotationUntilIndex) {
  11429. if ($index === $inAnnotationUntilIndex) {
  11430. $inAnnotationUntilIndex = null;
  11431. continue;
  11432. }
  11433. } elseif ($tokens[$index]->isType(DocLexer::T_AT)) {
  11434. $endIndex = $tokens->getAnnotationEnd($index);
  11435. if (null !== $endIndex) {
  11436. $inAnnotationUntilIndex = $endIndex + 1;
  11437. }
  11438. continue;
  11439. }
  11440. if (null === $inAnnotationUntilIndex) {
  11441. continue;
  11442. }
  11443. if (!$token->isType([DocLexer::T_OPEN_PARENTHESIS, DocLexer::T_CLOSE_PARENTHESIS])) {
  11444. continue;
  11445. }
  11446. if ($token->isType(DocLexer::T_OPEN_PARENTHESIS)) {
  11447. $token = $tokens[$index - 1];
  11448. if ($token->isType(DocLexer::T_NONE)) {
  11449. $token->clear();
  11450. }
  11451. $token = $tokens[$index + 1];
  11452. } else {
  11453. $token = $tokens[$index - 1];
  11454. }
  11455. if ($token->isType(DocLexer::T_NONE)) {
  11456. if (false !== strpos($token->getContent(), "\n")) {
  11457. continue;
  11458. }
  11459. $token->clear();
  11460. }
  11461. }
  11462. }
  11463. private function fixSpacesAroundCommas(Tokens $tokens)
  11464. {
  11465. $inAnnotationUntilIndex = null;
  11466. foreach ($tokens as $index => $token) {
  11467. if (null !== $inAnnotationUntilIndex) {
  11468. if ($index === $inAnnotationUntilIndex) {
  11469. $inAnnotationUntilIndex = null;
  11470. continue;
  11471. }
  11472. } elseif ($tokens[$index]->isType(DocLexer::T_AT)) {
  11473. $endIndex = $tokens->getAnnotationEnd($index);
  11474. if (null !== $endIndex) {
  11475. $inAnnotationUntilIndex = $endIndex;
  11476. }
  11477. continue;
  11478. }
  11479. if (null === $inAnnotationUntilIndex) {
  11480. continue;
  11481. }
  11482. if (!$token->isType(DocLexer::T_COMMA)) {
  11483. continue;
  11484. }
  11485. $token = $tokens[$index - 1];
  11486. if ($token->isType(DocLexer::T_NONE)) {
  11487. $token->clear();
  11488. }
  11489. if ($index < count($tokens) - 1 && !preg_match('/^\s/', $tokens[$index + 1]->getContent())) {
  11490. $tokens->insertAt($index + 1, new Token(DocLexer::T_NONE, ' '));
  11491. }
  11492. }
  11493. }
  11494. private function fixAroundAssignments(Tokens $tokens)
  11495. {
  11496. $beforeArguments = $this->configuration['before_argument_assignments'];
  11497. $afterArguments = $this->configuration['after_argument_assignments'];
  11498. $beforeArraysEquals = $this->configuration['before_array_assignments_equals'];
  11499. $afterArraysEquals = $this->configuration['after_array_assignments_equals'];
  11500. $beforeArraysColon = $this->configuration['before_array_assignments_colon'];
  11501. $afterArraysColon = $this->configuration['after_array_assignments_colon'];
  11502. $scopes = [];
  11503. foreach ($tokens as $index => $token) {
  11504. $endScopeType = end($scopes);
  11505. if (false !== $endScopeType && $token->isType($endScopeType)) {
  11506. array_pop($scopes);
  11507. continue;
  11508. }
  11509. if ($tokens[$index]->isType(DocLexer::T_AT)) {
  11510. $scopes[] = DocLexer::T_CLOSE_PARENTHESIS;
  11511. continue;
  11512. }
  11513. if ($tokens[$index]->isType(DocLexer::T_OPEN_CURLY_BRACES)) {
  11514. $scopes[] = DocLexer::T_CLOSE_CURLY_BRACES;
  11515. continue;
  11516. }
  11517. if (DocLexer::T_CLOSE_PARENTHESIS === $endScopeType && $token->isType(DocLexer::T_EQUALS)) {
  11518. $this->updateSpacesAfter($tokens, $index, $afterArguments);
  11519. $this->updateSpacesBefore($tokens, $index, $beforeArguments);
  11520. continue;
  11521. }
  11522. if (DocLexer::T_CLOSE_CURLY_BRACES === $endScopeType) {
  11523. if ($token->isType(DocLexer::T_EQUALS)) {
  11524. $this->updateSpacesAfter($tokens, $index, $afterArraysEquals);
  11525. $this->updateSpacesBefore($tokens, $index, $beforeArraysEquals);
  11526. continue;
  11527. }
  11528. if ($token->isType(DocLexer::T_COLON)) {
  11529. $this->updateSpacesAfter($tokens, $index, $afterArraysColon);
  11530. $this->updateSpacesBefore($tokens, $index, $beforeArraysColon);
  11531. }
  11532. }
  11533. }
  11534. }
  11535. private function updateSpacesAfter(Tokens $tokens, $index, $insert)
  11536. {
  11537. $this->updateSpacesAt($tokens, $index + 1, $index + 1, $insert);
  11538. }
  11539. private function updateSpacesBefore(Tokens $tokens, $index, $insert)
  11540. {
  11541. $this->updateSpacesAt($tokens, $index - 1, $index, $insert);
  11542. }
  11543. private function updateSpacesAt(Tokens $tokens, $index, $insertIndex, $insert)
  11544. {
  11545. if (null === $insert) {
  11546. return;
  11547. }
  11548. $token = $tokens[$index];
  11549. if ($insert) {
  11550. if (!$token->isType(DocLexer::T_NONE)) {
  11551. $tokens->insertAt($insertIndex, $token = new Token());
  11552. }
  11553. $token->setContent(' ');
  11554. } elseif ($token->isType(DocLexer::T_NONE)) {
  11555. $token->clear();
  11556. }
  11557. }
  11558. }
  11559. <?php
  11560. namespace PhpCsFixer\Fixer;
  11561. use PhpCsFixer\Tokenizer\Tokens;
  11562. interface FixerInterface
  11563. {
  11564. public function isCandidate(Tokens $tokens);
  11565. public function isRisky();
  11566. public function fix(\SplFileInfo $file, Tokens $tokens);
  11567. public function getName();
  11568. public function getPriority();
  11569. public function supports(\SplFileInfo $file);
  11570. }
  11571. <?php
  11572. namespace PhpCsFixer\Fixer\FunctionNotation;
  11573. use PhpCsFixer\AbstractFixer;
  11574. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  11575. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11576. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11577. use PhpCsFixer\FixerDefinition\CodeSample;
  11578. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11579. use PhpCsFixer\Tokenizer\CT;
  11580. use PhpCsFixer\Tokenizer\Tokens;
  11581. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  11582. final class FunctionDeclarationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  11583. {
  11584. const SPACING_NONE = 'none';
  11585. const SPACING_ONE = 'one';
  11586. private $supportedSpacings = [self::SPACING_NONE, self::SPACING_ONE];
  11587. private $singleLineWhitespaceOptions = " \t";
  11588. public function isCandidate(Tokens $tokens)
  11589. {
  11590. return $tokens->isTokenKindFound(T_FUNCTION);
  11591. }
  11592. public function getDefinition()
  11593. {
  11594. return new FixerDefinition(
  11595. 'Spaces should be properly placed in a function declaration.',
  11596. [
  11597. new CodeSample(
  11598. '<?php
  11599. class Foo
  11600. {
  11601. public static function bar ( $baz , $foo )
  11602. {
  11603. return false;
  11604. }
  11605. }
  11606. function foo ($bar, $baz)
  11607. {
  11608. return false;
  11609. }
  11610. '
  11611. ),
  11612. new CodeSample(
  11613. '<?php
  11614. $f = function () {};
  11615. ',
  11616. ['closure_function_spacing' => self::SPACING_NONE]
  11617. ),
  11618. ]
  11619. );
  11620. }
  11621. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  11622. {
  11623. $tokensAnalyzer = new TokensAnalyzer($tokens);
  11624. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  11625. $token = $tokens[$index];
  11626. if (!$token->isGivenKind(T_FUNCTION)) {
  11627. continue;
  11628. }
  11629. $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(', ';', [T_CLOSE_TAG]]);
  11630. if (!$tokens[$startParenthesisIndex]->equals('(')) {
  11631. continue;
  11632. }
  11633. $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex);
  11634. $startBraceIndex = $tokens->getNextTokenOfKind($endParenthesisIndex, [';', '{']);
  11635. if (
  11636. $tokens[$startBraceIndex]->equals('{') &&
  11637. (
  11638. !$tokens[$startBraceIndex - 1]->isWhitespace() ||
  11639. $tokens[$startBraceIndex - 1]->isWhitespace($this->singleLineWhitespaceOptions)
  11640. )
  11641. ) {
  11642. $tokens->ensureWhitespaceAtIndex($startBraceIndex - 1, 1, ' ');
  11643. }
  11644. $afterParenthesisIndex = $tokens->getNextNonWhitespace($endParenthesisIndex);
  11645. $afterParenthesisToken = $tokens[$afterParenthesisIndex];
  11646. if ($afterParenthesisToken->isGivenKind(CT::T_USE_LAMBDA)) {
  11647. $tokens->ensureWhitespaceAtIndex($afterParenthesisIndex + 1, 0, ' ');
  11648. $useStartParenthesisIndex = $tokens->getNextTokenOfKind($afterParenthesisIndex, ['(']);
  11649. $useEndParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $useStartParenthesisIndex);
  11650. $this->fixParenthesisInnerEdge($tokens, $useStartParenthesisIndex, $useEndParenthesisIndex);
  11651. $tokens->ensureWhitespaceAtIndex($afterParenthesisIndex - 1, 1, ' ');
  11652. }
  11653. $this->fixParenthesisInnerEdge($tokens, $startParenthesisIndex, $endParenthesisIndex);
  11654. $isLambda = $tokensAnalyzer->isLambda($index);
  11655. if (!$isLambda && $tokens[$startParenthesisIndex - 1]->isWhitespace() && !$tokens[$tokens->getPrevNonWhitespace($startParenthesisIndex - 1)]->isComment()) {
  11656. $tokens->clearAt($startParenthesisIndex - 1);
  11657. }
  11658. if ($isLambda && self::SPACING_NONE === $this->configuration['closure_function_spacing']) {
  11659. if ($tokens[$index + 1]->isWhitespace()) {
  11660. $tokens->clearAt($index + 1);
  11661. }
  11662. } else {
  11663. $tokens->ensureWhitespaceAtIndex($index + 1, 0, ' ');
  11664. }
  11665. if ($isLambda) {
  11666. $prev = $tokens->getPrevMeaningfulToken($index);
  11667. if ($tokens[$prev]->isGivenKind(T_STATIC)) {
  11668. $tokens->ensureWhitespaceAtIndex($prev + 1, 0, ' ');
  11669. }
  11670. }
  11671. }
  11672. }
  11673. protected function createConfigurationDefinition()
  11674. {
  11675. return new FixerConfigurationResolver([
  11676. (new FixerOptionBuilder('closure_function_spacing', 'Spacing to use before open parenthesis for closures.'))
  11677. ->setDefault(self::SPACING_ONE)
  11678. ->setAllowedValues($this->supportedSpacings)
  11679. ->getOption(),
  11680. ]);
  11681. }
  11682. private function fixParenthesisInnerEdge(Tokens $tokens, $start, $end)
  11683. {
  11684. if ($tokens[$end - 1]->isWhitespace($this->singleLineWhitespaceOptions)) {
  11685. $tokens->clearAt($end - 1);
  11686. }
  11687. if ($tokens[$start + 1]->isWhitespace($this->singleLineWhitespaceOptions)) {
  11688. $tokens->clearAt($start + 1);
  11689. }
  11690. }
  11691. }
  11692. <?php
  11693. namespace PhpCsFixer\Fixer\FunctionNotation;
  11694. use PhpCsFixer\AbstractFixer;
  11695. use PhpCsFixer\FixerDefinition\CodeSample;
  11696. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11697. use PhpCsFixer\Tokenizer\Token;
  11698. use PhpCsFixer\Tokenizer\Tokens;
  11699. final class FunctionTypehintSpaceFixer extends AbstractFixer
  11700. {
  11701. public function getDefinition()
  11702. {
  11703. return new FixerDefinition(
  11704. 'Add missing space between function\'s argument and its typehint.',
  11705. [new CodeSample("<?php\nfunction sample(array\$a)\n{}\n")]
  11706. );
  11707. }
  11708. public function isCandidate(Tokens $tokens)
  11709. {
  11710. return $tokens->isTokenKindFound(T_FUNCTION);
  11711. }
  11712. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  11713. {
  11714. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  11715. $token = $tokens[$index];
  11716. if (!$token->isGivenKind(T_FUNCTION)) {
  11717. continue;
  11718. }
  11719. $startParenthesisIndex = $tokens->getNextTokenOfKind($index, ['(', ';', [T_CLOSE_TAG]]);
  11720. if (!$tokens[$startParenthesisIndex]->equals('(')) {
  11721. continue;
  11722. }
  11723. $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startParenthesisIndex);
  11724. for ($iter = $endParenthesisIndex - 1; $iter > $startParenthesisIndex; --$iter) {
  11725. if (!$tokens[$iter]->isGivenKind(T_VARIABLE)) {
  11726. continue;
  11727. }
  11728. $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($iter);
  11729. if ($tokens[$prevNonWhitespaceIndex]->isGivenKind(T_ELLIPSIS)) {
  11730. $iter = $prevNonWhitespaceIndex;
  11731. }
  11732. $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($iter);
  11733. if ($tokens[$prevNonWhitespaceIndex]->equals('&')) {
  11734. $iter = $prevNonWhitespaceIndex;
  11735. }
  11736. if (!$tokens[$iter - 1]->equalsAny([[T_WHITESPACE], [T_COMMENT], [T_DOC_COMMENT], '(', ','])) {
  11737. $tokens->insertAt($iter, new Token([T_WHITESPACE, ' ']));
  11738. }
  11739. }
  11740. }
  11741. }
  11742. }
  11743. <?php
  11744. namespace PhpCsFixer\Fixer\FunctionNotation;
  11745. use PhpCsFixer\AbstractFixer;
  11746. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  11747. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  11748. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11749. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11750. use PhpCsFixer\FixerDefinition\CodeSample;
  11751. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11752. use PhpCsFixer\Tokenizer\CT;
  11753. use PhpCsFixer\Tokenizer\Token;
  11754. use PhpCsFixer\Tokenizer\Tokens;
  11755. final class MethodArgumentSpaceFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  11756. {
  11757. public function fixSpace(Tokens $tokens, $index)
  11758. {
  11759. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  11760. $this->fixSpace2($tokens, $index);
  11761. }
  11762. public function getDefinition()
  11763. {
  11764. return new FixerDefinition(
  11765. 'In method arguments and method call, there MUST NOT be a space before each comma and there MUST be one space after each comma. Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line.',
  11766. [
  11767. new CodeSample(
  11768. "<?php\nfunction sample(\$a=10,\$b=20,\$c=30) {}\nsample(1, 2);\n",
  11769. null
  11770. ),
  11771. new CodeSample(
  11772. "<?php\nfunction sample(\$a=10,\$b=20,\$c=30) {}\nsample(1, 2);\n",
  11773. ['keep_multiple_spaces_after_comma' => false]
  11774. ),
  11775. new CodeSample(
  11776. "<?php\nfunction sample(\$a=10,\$b=20,\$c=30) {}\nsample(1, 2);\n",
  11777. ['keep_multiple_spaces_after_comma' => true]
  11778. ),
  11779. new CodeSample(
  11780. "<?php\nfunction sample(\$a=10,\n \$b=20,\$c=30) {}\nsample(1,\n 2);\n",
  11781. ['ensure_fully_multiline' => true]
  11782. ),
  11783. new CodeSample(
  11784. "<?php\nfunction sample(\$a=10,\n \$b=20,\$c=30) {}\nsample(1, \n 2);\nsample('foo', 'foobarbaz', 'baz');\nsample('foobar', 'bar', 'baz');\n",
  11785. [
  11786. 'ensure_fully_multiline' => true,
  11787. 'keep_multiple_spaces_after_comma' => true,
  11788. ]
  11789. ),
  11790. new CodeSample(
  11791. "<?php\nfunction sample(\$a=10,\n \$b=20,\$c=30) {}\nsample(1, \n 2);\nsample('foo', 'foobarbaz', 'baz');\nsample('foobar', 'bar', 'baz');\n",
  11792. [
  11793. 'ensure_fully_multiline' => true,
  11794. 'keep_multiple_spaces_after_comma' => false,
  11795. ]
  11796. ),
  11797. ]
  11798. );
  11799. }
  11800. public function isCandidate(Tokens $tokens)
  11801. {
  11802. return $tokens->isTokenKindFound('(');
  11803. }
  11804. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  11805. {
  11806. for ($index = $tokens->count() - 1; $index > 0; --$index) {
  11807. $token = $tokens[$index];
  11808. if ($token->equals('(')) {
  11809. $meaningfulTokenBeforeParenthesis = $tokens[$tokens->getPrevMeaningfulToken($index)];
  11810. if (!$meaningfulTokenBeforeParenthesis->isKeyword()
  11811. || $meaningfulTokenBeforeParenthesis->isGivenKind([T_LIST, T_FUNCTION])) {
  11812. if ($this->fixFunction($tokens, $index) && $this->configuration['ensure_fully_multiline']) {
  11813. if (!$meaningfulTokenBeforeParenthesis->isGivenKind(T_LIST)) {
  11814. $this->ensureFunctionFullyMultiline($tokens, $index);
  11815. }
  11816. }
  11817. }
  11818. }
  11819. }
  11820. }
  11821. protected function createConfigurationDefinition()
  11822. {
  11823. return new FixerConfigurationResolver([
  11824. (new FixerOptionBuilder('keep_multiple_spaces_after_comma', 'Whether keep multiple spaces after comma.'))
  11825. ->setAllowedTypes(['bool'])
  11826. ->setDefault(false)
  11827. ->getOption(),
  11828. (new FixerOptionBuilder(
  11829. 'ensure_fully_multiline',
  11830. 'Ensure every argument of a multiline argument list is on its own line'
  11831. ))
  11832. ->setAllowedTypes(['bool'])
  11833. ->setDefault(false)
  11834. ->getOption(),
  11835. ]);
  11836. }
  11837. private function fixFunction(Tokens $tokens, $startFunctionIndex)
  11838. {
  11839. $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex);
  11840. $isMultiline = $this->isNewline($tokens[$startFunctionIndex + 1])
  11841. || $this->isNewline($tokens[$endFunctionIndex - 1]);
  11842. for ($index = $endFunctionIndex - 1; $index > $startFunctionIndex; --$index) {
  11843. $token = $tokens[$index];
  11844. if ($token->equals(')')) {
  11845. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index, false);
  11846. continue;
  11847. }
  11848. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) {
  11849. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index, false);
  11850. continue;
  11851. }
  11852. if ($token->equals('}')) {
  11853. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index, false);
  11854. continue;
  11855. }
  11856. if ($token->equals(',')) {
  11857. $this->fixSpace2($tokens, $index);
  11858. if (!$isMultiline && $this->isNewline($tokens[$index + 1])) {
  11859. $isMultiline = true;
  11860. break;
  11861. }
  11862. }
  11863. }
  11864. return $isMultiline;
  11865. }
  11866. private function ensureFunctionFullyMultiline(Tokens $tokens, $startFunctionIndex)
  11867. {
  11868. $searchIndex = $startFunctionIndex;
  11869. do {
  11870. $prevWhitespaceTokenIndex = $tokens->getPrevTokenOfKind(
  11871. $searchIndex,
  11872. [[T_WHITESPACE]]
  11873. );
  11874. $searchIndex = $prevWhitespaceTokenIndex;
  11875. } while ($prevWhitespaceTokenIndex
  11876. && false === strpos($tokens[$prevWhitespaceTokenIndex]->getContent(), "\n")
  11877. );
  11878. $existingIndentation = $prevWhitespaceTokenIndex
  11879. ? ltrim($tokens[$prevWhitespaceTokenIndex]->getContent(), "\n\r")
  11880. : '';
  11881. $indentation = $existingIndentation.$this->whitespacesConfig->getIndent();
  11882. $endFunctionIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startFunctionIndex);
  11883. if (!$this->isNewline($tokens[$endFunctionIndex - 1])) {
  11884. $tokens->ensureWhitespaceAtIndex($endFunctionIndex, 0, $this->whitespacesConfig->getLineEnding().$existingIndentation);
  11885. ++$endFunctionIndex;
  11886. }
  11887. for ($index = $endFunctionIndex - 1; $index > $startFunctionIndex; --$index) {
  11888. $token = $tokens[$index];
  11889. if ($token->equals(')')) {
  11890. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index, false);
  11891. continue;
  11892. }
  11893. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_CLOSE)) {
  11894. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index, false);
  11895. continue;
  11896. }
  11897. if ($token->equals('}')) {
  11898. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index, false);
  11899. continue;
  11900. }
  11901. if ($token->equals(',')) {
  11902. $this->fixNewline($tokens, $index, $indentation);
  11903. }
  11904. }
  11905. $this->fixNewline($tokens, $startFunctionIndex, $indentation, false);
  11906. }
  11907. private function fixNewline(Tokens $tokens, $index, $indentation, $override = true)
  11908. {
  11909. if ($this->isNewline($tokens[$index + 1]) || $tokens[$index + 1]->isComment()) {
  11910. return;
  11911. }
  11912. if ($tokens[$index + 2]->isComment()) {
  11913. $nextMeaningfulTokenIndex = $tokens->getNextMeaningfulToken($index + 2);
  11914. if (!$this->isNewline($tokens[$nextMeaningfulTokenIndex - 1])) {
  11915. $tokens->ensureWhitespaceAtIndex($nextMeaningfulTokenIndex, 0, $this->whitespacesConfig->getLineEnding().$indentation);
  11916. }
  11917. return;
  11918. }
  11919. $tokens->ensureWhitespaceAtIndex($index + 1, 0, $this->whitespacesConfig->getLineEnding().$indentation);
  11920. }
  11921. private function fixSpace2(Tokens $tokens, $index)
  11922. {
  11923. if ($tokens[$index - 1]->isWhitespace()) {
  11924. $prevIndex = $tokens->getPrevNonWhitespace($index - 1);
  11925. if (!$tokens[$prevIndex]->equalsAny([',', [T_END_HEREDOC]]) && !$tokens[$prevIndex]->isComment()) {
  11926. $tokens->clearAt($index - 1);
  11927. }
  11928. }
  11929. $nextIndex = $index + 1;
  11930. $nextToken = $tokens[$nextIndex];
  11931. if ($nextToken->isWhitespace()) {
  11932. if (
  11933. ($this->configuration['keep_multiple_spaces_after_comma'] && !preg_match('/\R/', $nextToken->getContent()))
  11934. || $this->isCommentLastLineToken($tokens, $index + 2)
  11935. ) {
  11936. return;
  11937. }
  11938. $newContent = ltrim($nextToken->getContent(), " \t");
  11939. $tokens[$nextIndex] = new Token([T_WHITESPACE, '' === $newContent ? ' ' : $newContent]);
  11940. return;
  11941. }
  11942. if (!$this->isCommentLastLineToken($tokens, $index + 1)) {
  11943. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  11944. }
  11945. }
  11946. private function isCommentLastLineToken(Tokens $tokens, $index)
  11947. {
  11948. if (!$tokens[$index]->isComment() || !$tokens[$index + 1]->isWhitespace()) {
  11949. return false;
  11950. }
  11951. $content = $tokens[$index + 1]->getContent();
  11952. return $content !== ltrim($content, "\r\n");
  11953. }
  11954. private function isNewline(Token $token)
  11955. {
  11956. return $token->isWhitespace() && false !== strpos($token->getContent(), "\n");
  11957. }
  11958. }
  11959. <?php
  11960. namespace PhpCsFixer\Fixer\FunctionNotation;
  11961. use PhpCsFixer\AbstractFixer;
  11962. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  11963. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  11964. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  11965. use PhpCsFixer\FixerDefinition\CodeSample;
  11966. use PhpCsFixer\FixerDefinition\FixerDefinition;
  11967. use PhpCsFixer\Tokenizer\Token;
  11968. use PhpCsFixer\Tokenizer\Tokens;
  11969. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  11970. final class NativeFunctionInvocationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  11971. {
  11972. public function getDefinition()
  11973. {
  11974. return new FixerDefinition(
  11975. 'Add leading `\` before function invocation of internal function to speed up resolving.',
  11976. [
  11977. new CodeSample(
  11978. '<?php
  11979. function baz($options)
  11980. {
  11981. if (!array_key_exists("foo", $options)) {
  11982. throw new \InvalidArgumentException();
  11983. }
  11984. return json_encode($options);
  11985. }
  11986. '
  11987. ),
  11988. new CodeSample(
  11989. '<?php
  11990. function baz($options)
  11991. {
  11992. if (!array_key_exists("foo", $options)) {
  11993. throw new \InvalidArgumentException();
  11994. }
  11995. return json_encode($options);
  11996. }
  11997. ',
  11998. [
  11999. 'exclude' => [
  12000. 'json_encode',
  12001. ],
  12002. ]
  12003. ),
  12004. ],
  12005. null,
  12006. 'Risky when any of the functions are overridden.'
  12007. );
  12008. }
  12009. public function isCandidate(Tokens $tokens)
  12010. {
  12011. return $tokens->isTokenKindFound(T_STRING);
  12012. }
  12013. public function isRisky()
  12014. {
  12015. return true;
  12016. }
  12017. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12018. {
  12019. $functionNames = $this->getFunctionNames();
  12020. $indexes = [];
  12021. for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
  12022. $token = $tokens[$index];
  12023. $tokenContent = $token->getContent();
  12024. if (!$token->isGivenKind(T_STRING)) {
  12025. continue;
  12026. }
  12027. $next = $tokens->getNextMeaningfulToken($index);
  12028. if (!$tokens[$next]->equals('(')) {
  12029. continue;
  12030. }
  12031. $functionNamePrefix = $tokens->getPrevMeaningfulToken($index);
  12032. if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION])) {
  12033. continue;
  12034. }
  12035. if ($tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)) {
  12036. $prev = $tokens->getPrevMeaningfulToken($functionNamePrefix);
  12037. if ($tokens[$prev]->isGivenKind([T_STRING, T_NEW])) {
  12038. continue;
  12039. }
  12040. }
  12041. $lowerFunctionName = \strtolower($tokenContent);
  12042. if (!\in_array($lowerFunctionName, $functionNames, true)) {
  12043. continue;
  12044. }
  12045. if ($tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_NS_SEPARATOR)) {
  12046. continue;
  12047. }
  12048. $indexes[] = $index;
  12049. }
  12050. $indexes = \array_reverse($indexes);
  12051. foreach ($indexes as $index) {
  12052. $tokens->insertAt($index, new Token([T_NS_SEPARATOR, '\\']));
  12053. }
  12054. }
  12055. protected function createConfigurationDefinition()
  12056. {
  12057. return new FixerConfigurationResolver([
  12058. (new FixerOptionBuilder('exclude', 'List of functions to ignore.'))
  12059. ->setAllowedTypes(['array'])
  12060. ->setAllowedValues([static function ($value) {
  12061. foreach ($value as $functionName) {
  12062. if (!\is_string($functionName) || '' === \trim($functionName) || \trim($functionName) !== $functionName) {
  12063. throw new InvalidOptionsException(\sprintf(
  12064. 'Each element must be a non-empty, trimmed string, got "%s" instead.',
  12065. \is_object($functionName) ? \get_class($functionName) : \gettype($functionName)
  12066. ));
  12067. }
  12068. }
  12069. return true;
  12070. }])
  12071. ->setDefault([])
  12072. ->getOption(),
  12073. ]);
  12074. }
  12075. private function getFunctionNames()
  12076. {
  12077. $definedFunctions = \get_defined_functions();
  12078. return \array_diff(
  12079. $this->normalizeFunctionNames($definedFunctions['internal']),
  12080. \array_unique($this->normalizeFunctionNames($this->configuration['exclude']))
  12081. );
  12082. }
  12083. private function normalizeFunctionNames(array $functionNames)
  12084. {
  12085. return \array_map(static function ($functionName) {
  12086. return \strtolower($functionName);
  12087. }, $functionNames);
  12088. }
  12089. }
  12090. <?php
  12091. namespace PhpCsFixer\Fixer\FunctionNotation;
  12092. use PhpCsFixer\AbstractFixer;
  12093. use PhpCsFixer\FixerDefinition\CodeSample;
  12094. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12095. use PhpCsFixer\Tokenizer\CT;
  12096. use PhpCsFixer\Tokenizer\Tokens;
  12097. final class NoSpacesAfterFunctionNameFixer extends AbstractFixer
  12098. {
  12099. public function getDefinition()
  12100. {
  12101. return new FixerDefinition(
  12102. 'When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis.',
  12103. [new CodeSample("<?php\nrequire ('sample.php');\necho (test (3));\nexit (1);\n\$func ();\n")]
  12104. );
  12105. }
  12106. public function getPriority()
  12107. {
  12108. return 2;
  12109. }
  12110. public function isCandidate(Tokens $tokens)
  12111. {
  12112. return $tokens->isAnyTokenKindsFound(array_merge($this->getFunctionyTokenKinds(), [T_STRING]));
  12113. }
  12114. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12115. {
  12116. $functionyTokens = $this->getFunctionyTokenKinds();
  12117. $languageConstructionTokens = $this->getLanguageConstructionTokenKinds();
  12118. $braceTypes = $this->getBraceAfterVariableKinds();
  12119. foreach ($tokens as $index => $token) {
  12120. if (!$token->equals('(')) {
  12121. continue;
  12122. }
  12123. $lastTokenIndex = $tokens->getPrevNonWhitespace($index);
  12124. $endParenthesisIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  12125. $nextNonWhiteSpace = $tokens->getNextMeaningfulToken($endParenthesisIndex);
  12126. if (
  12127. null !== $nextNonWhiteSpace
  12128. && $tokens[$nextNonWhiteSpace]->equals('?')
  12129. && $tokens[$lastTokenIndex]->isGivenKind($languageConstructionTokens)
  12130. ) {
  12131. continue;
  12132. }
  12133. if ($tokens[$lastTokenIndex]->isGivenKind($functionyTokens)) {
  12134. $this->fixFunctionCall($tokens, $index);
  12135. } elseif ($tokens[$lastTokenIndex]->isGivenKind(T_STRING)) {
  12136. $possibleDefinitionIndex = $tokens->getPrevMeaningfulToken($lastTokenIndex);
  12137. if (!$tokens[$possibleDefinitionIndex]->isGivenKind(T_FUNCTION)) {
  12138. $this->fixFunctionCall($tokens, $index);
  12139. }
  12140. } elseif ($tokens[$lastTokenIndex]->equalsAny($braceTypes)) {
  12141. $block = Tokens::detectBlockType($tokens[$lastTokenIndex]);
  12142. if (
  12143. Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE === $block['type']
  12144. || Tokens::BLOCK_TYPE_DYNAMIC_VAR_BRACE === $block['type']
  12145. || Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE === $block['type']
  12146. || Tokens::BLOCK_TYPE_PARENTHESIS_BRACE === $block['type']
  12147. ) {
  12148. $this->fixFunctionCall($tokens, $index);
  12149. }
  12150. }
  12151. }
  12152. }
  12153. private function fixFunctionCall(Tokens $tokens, $index)
  12154. {
  12155. if ($tokens[$index - 1]->isWhitespace()) {
  12156. $tokens->clearAt($index - 1);
  12157. }
  12158. }
  12159. private function getBraceAfterVariableKinds()
  12160. {
  12161. static $tokens = [
  12162. ')',
  12163. ']',
  12164. [CT::T_DYNAMIC_VAR_BRACE_CLOSE],
  12165. [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE],
  12166. ];
  12167. return $tokens;
  12168. }
  12169. private function getFunctionyTokenKinds()
  12170. {
  12171. static $tokens = [
  12172. T_ARRAY,
  12173. T_ECHO,
  12174. T_EMPTY,
  12175. T_EVAL,
  12176. T_EXIT,
  12177. T_INCLUDE,
  12178. T_INCLUDE_ONCE,
  12179. T_ISSET,
  12180. T_LIST,
  12181. T_PRINT,
  12182. T_REQUIRE,
  12183. T_REQUIRE_ONCE,
  12184. T_UNSET,
  12185. T_VARIABLE,
  12186. ];
  12187. return $tokens;
  12188. }
  12189. private function getLanguageConstructionTokenKinds()
  12190. {
  12191. static $languageConstructionTokens = [
  12192. T_ECHO,
  12193. T_PRINT,
  12194. T_INCLUDE,
  12195. T_INCLUDE_ONCE,
  12196. T_REQUIRE,
  12197. T_REQUIRE_ONCE,
  12198. ];
  12199. return $languageConstructionTokens;
  12200. }
  12201. }
  12202. <?php
  12203. namespace PhpCsFixer\Fixer\FunctionNotation;
  12204. use PhpCsFixer\AbstractFixer;
  12205. use PhpCsFixer\FixerDefinition\CodeSample;
  12206. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12207. use PhpCsFixer\Tokenizer\CT;
  12208. use PhpCsFixer\Tokenizer\Tokens;
  12209. final class NoUnreachableDefaultArgumentValueFixer extends AbstractFixer
  12210. {
  12211. public function getDefinition()
  12212. {
  12213. return new FixerDefinition(
  12214. 'In function arguments there must not be arguments with default values before non-default ones.',
  12215. [
  12216. new CodeSample(
  12217. '<?php
  12218. function example($foo = "two words", $bar) {}
  12219. '
  12220. ),
  12221. ],
  12222. null,
  12223. 'Modifies the signature of functions; therefore risky when using systems (such as some Symfony components) that rely on those (for example through reflection).'
  12224. );
  12225. }
  12226. public function isCandidate(Tokens $tokens)
  12227. {
  12228. return $tokens->isTokenKindFound(T_FUNCTION);
  12229. }
  12230. public function isRisky()
  12231. {
  12232. return true;
  12233. }
  12234. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12235. {
  12236. for ($i = 0, $l = $tokens->count(); $i < $l; ++$i) {
  12237. if (!$tokens[$i]->isGivenKind(T_FUNCTION)) {
  12238. continue;
  12239. }
  12240. $startIndex = $tokens->getNextTokenOfKind($i, ['(']);
  12241. $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startIndex);
  12242. $this->fixFunctionDefinition($tokens, $startIndex, $i);
  12243. }
  12244. }
  12245. private function fixFunctionDefinition(Tokens $tokens, $startIndex, $endIndex)
  12246. {
  12247. $lastArgumentIndex = $this->getLastNonDefaultArgumentIndex($tokens, $startIndex, $endIndex);
  12248. if (!$lastArgumentIndex) {
  12249. return;
  12250. }
  12251. for ($i = $lastArgumentIndex; $i > $startIndex; --$i) {
  12252. $token = $tokens[$i];
  12253. if ($token->isGivenKind(T_VARIABLE)) {
  12254. $lastArgumentIndex = $i;
  12255. continue;
  12256. }
  12257. if (!$token->equals('=') || $this->isTypehintedNullableVariable($tokens, $i)) {
  12258. continue;
  12259. }
  12260. $endIndex = $tokens->getPrevTokenOfKind($lastArgumentIndex, [',']);
  12261. $endIndex = $tokens->getPrevMeaningfulToken($endIndex);
  12262. $this->removeDefaultArgument($tokens, $i, $endIndex);
  12263. }
  12264. }
  12265. private function getLastNonDefaultArgumentIndex(Tokens $tokens, $startIndex, $endIndex)
  12266. {
  12267. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  12268. $token = $tokens[$i];
  12269. if ($token->equals('=')) {
  12270. $i = $tokens->getPrevMeaningfulToken($i);
  12271. continue;
  12272. }
  12273. if ($token->isGivenKind(T_VARIABLE) && !$this->isEllipsis($tokens, $i)) {
  12274. return $i;
  12275. }
  12276. }
  12277. }
  12278. private function isEllipsis(Tokens $tokens, $variableIndex)
  12279. {
  12280. return $tokens[$tokens->getPrevMeaningfulToken($variableIndex)]->isGivenKind(T_ELLIPSIS);
  12281. }
  12282. private function removeDefaultArgument(Tokens $tokens, $startIndex, $endIndex)
  12283. {
  12284. for ($i = $startIndex; $i <= $endIndex;) {
  12285. $tokens->clearTokenAndMergeSurroundingWhitespace($i);
  12286. $this->clearWhitespacesBeforeIndex($tokens, $i);
  12287. $i = $tokens->getNextMeaningfulToken($i);
  12288. }
  12289. }
  12290. private function isTypehintedNullableVariable(Tokens $tokens, $index)
  12291. {
  12292. $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
  12293. if (!$nextToken->equals([T_STRING, 'null'], false)) {
  12294. return false;
  12295. }
  12296. $variableIndex = $tokens->getPrevMeaningfulToken($index);
  12297. $searchTokens = [',', '(', [T_STRING], [CT::T_ARRAY_TYPEHINT], [T_CALLABLE]];
  12298. $typehintKinds = [T_STRING, CT::T_ARRAY_TYPEHINT, T_CALLABLE];
  12299. $prevIndex = $tokens->getPrevTokenOfKind($variableIndex, $searchTokens);
  12300. return $tokens[$prevIndex]->isGivenKind($typehintKinds);
  12301. }
  12302. private function clearWhitespacesBeforeIndex(Tokens $tokens, $index)
  12303. {
  12304. $prevIndex = $tokens->getNonEmptySibling($index, -1);
  12305. if (!$tokens[$prevIndex]->isWhitespace()) {
  12306. return;
  12307. }
  12308. $prevNonWhiteIndex = $tokens->getPrevNonWhitespace($prevIndex);
  12309. if (null === $prevNonWhiteIndex || !$tokens[$prevNonWhiteIndex]->isComment()) {
  12310. $tokens->clearTokenAndMergeSurroundingWhitespace($prevIndex);
  12311. }
  12312. }
  12313. }
  12314. <?php
  12315. namespace PhpCsFixer\Fixer\FunctionNotation;
  12316. use PhpCsFixer\AbstractFixer;
  12317. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  12318. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  12319. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  12320. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12321. use PhpCsFixer\FixerDefinition\VersionSpecification;
  12322. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  12323. use PhpCsFixer\Tokenizer\CT;
  12324. use PhpCsFixer\Tokenizer\Token;
  12325. use PhpCsFixer\Tokenizer\Tokens;
  12326. final class ReturnTypeDeclarationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  12327. {
  12328. public function getDefinition()
  12329. {
  12330. $versionSpecification = new VersionSpecification(70000);
  12331. return new FixerDefinition(
  12332. 'There should be one or no space before colon, and one space after it in return type declarations, according to configuration.',
  12333. [
  12334. new VersionSpecificCodeSample(
  12335. "<?php\nfunction foo(int \$a):string {};\n",
  12336. $versionSpecification
  12337. ),
  12338. new VersionSpecificCodeSample(
  12339. "<?php\nfunction foo(int \$a):string {};\n",
  12340. $versionSpecification,
  12341. ['space_before' => 'none']
  12342. ),
  12343. new VersionSpecificCodeSample(
  12344. "<?php\nfunction foo(int \$a):string {};\n",
  12345. $versionSpecification,
  12346. ['space_before' => 'one']
  12347. ),
  12348. ],
  12349. 'Rule is applied only in a PHP 7+ environment.'
  12350. );
  12351. }
  12352. public function isCandidate(Tokens $tokens)
  12353. {
  12354. return PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(CT::T_TYPE_COLON);
  12355. }
  12356. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12357. {
  12358. $oneSpaceBefore = 'one' === $this->configuration['space_before'];
  12359. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  12360. if (!$tokens[$index]->isGivenKind(CT::T_TYPE_COLON)) {
  12361. continue;
  12362. }
  12363. $previousIndex = $index - 1;
  12364. $previousToken = $tokens[$previousIndex];
  12365. if ($previousToken->isWhitespace()) {
  12366. if (!$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
  12367. if ($oneSpaceBefore) {
  12368. $tokens[$previousIndex] = new Token([T_WHITESPACE, ' ']);
  12369. } else {
  12370. $tokens->clearAt($previousIndex);
  12371. }
  12372. }
  12373. } elseif ($oneSpaceBefore) {
  12374. $tokenWasAdded = $tokens->ensureWhitespaceAtIndex($index, 0, ' ');
  12375. if ($tokenWasAdded) {
  12376. ++$limit;
  12377. }
  12378. ++$index;
  12379. }
  12380. ++$index;
  12381. $tokenWasAdded = $tokens->ensureWhitespaceAtIndex($index, 0, ' ');
  12382. if ($tokenWasAdded) {
  12383. ++$limit;
  12384. }
  12385. }
  12386. }
  12387. protected function createConfigurationDefinition()
  12388. {
  12389. return new FixerConfigurationResolver([
  12390. (new FixerOptionBuilder('space_before', 'Spacing to apply before colon.'))
  12391. ->setAllowedValues(['one', 'none'])
  12392. ->setDefault('none')
  12393. ->getOption(),
  12394. ]);
  12395. }
  12396. }
  12397. <?php
  12398. namespace PhpCsFixer\Fixer\FunctionNotation;
  12399. use PhpCsFixer\AbstractFixer;
  12400. use PhpCsFixer\FixerDefinition\CodeSample;
  12401. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12402. use PhpCsFixer\Tokenizer\CT;
  12403. use PhpCsFixer\Tokenizer\Token;
  12404. use PhpCsFixer\Tokenizer\Tokens;
  12405. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  12406. final class StaticLambdaFixer extends AbstractFixer
  12407. {
  12408. public function getDefinition()
  12409. {
  12410. return new FixerDefinition(
  12411. 'Lambdas not (indirect) referencing `$this` must be declared `static`.',
  12412. [new CodeSample("<?php\n\$a = function () use (\$b)\n{ echo \$b;\n};\n")],
  12413. null,
  12414. 'Risky when using "->bindTo" on lambdas without referencing to `$this`.'
  12415. );
  12416. }
  12417. public function isCandidate(Tokens $tokens)
  12418. {
  12419. return $tokens->isTokenKindFound(T_FUNCTION);
  12420. }
  12421. public function isRisky()
  12422. {
  12423. return true;
  12424. }
  12425. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12426. {
  12427. $analyzer = new TokensAnalyzer($tokens);
  12428. for ($index = $tokens->count() - 4; $index > 0; --$index) {
  12429. if (!$tokens[$index]->isGivenKind(T_FUNCTION) || !$analyzer->isLambda($index)) {
  12430. continue;
  12431. }
  12432. $prev = $tokens->getPrevMeaningfulToken($index);
  12433. if ($tokens[$prev]->isGivenKind(T_STATIC)) {
  12434. continue;
  12435. }
  12436. $lambdaOpenIndex = $tokens->getNextTokenOfKind($index, ['{']);
  12437. $lambdaEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $lambdaOpenIndex);
  12438. if ($this->hasPossibleReferenceToThis($tokens, $lambdaOpenIndex, $lambdaEndIndex)) {
  12439. continue;
  12440. }
  12441. $tokens->insertAt(
  12442. $index,
  12443. [
  12444. new Token([T_STATIC, 'static']),
  12445. new Token([T_WHITESPACE, ' ']),
  12446. ]
  12447. );
  12448. $index -= 4;
  12449. }
  12450. }
  12451. private function hasPossibleReferenceToThis(Tokens $tokens, $startIndex, $endIndex)
  12452. {
  12453. for ($i = $startIndex; $i < $endIndex; ++$i) {
  12454. if ($tokens[$i]->isGivenKind(T_VARIABLE) && '$this' === strtolower($tokens[$i]->getContent())) {
  12455. return true;
  12456. }
  12457. if ($tokens[$i]->isGivenKind([
  12458. T_INCLUDE,
  12459. T_INCLUDE_ONCE,
  12460. T_REQUIRE,
  12461. T_REQUIRE_ONCE,
  12462. CT::T_DYNAMIC_VAR_BRACE_OPEN,
  12463. T_EVAL,
  12464. ])) {
  12465. return true;
  12466. }
  12467. if ($tokens[$i]->equals('$')) {
  12468. $nextIndex = $tokens->getNextMeaningfulToken($i);
  12469. if ($tokens[$nextIndex]->isGivenKind(T_VARIABLE)) {
  12470. return true;
  12471. }
  12472. }
  12473. }
  12474. return false;
  12475. }
  12476. }
  12477. <?php
  12478. namespace PhpCsFixer\Fixer\FunctionNotation;
  12479. use PhpCsFixer\AbstractFixer;
  12480. use PhpCsFixer\DocBlock\Annotation;
  12481. use PhpCsFixer\DocBlock\DocBlock;
  12482. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12483. use PhpCsFixer\FixerDefinition\VersionSpecification;
  12484. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  12485. use PhpCsFixer\Tokenizer\CT;
  12486. use PhpCsFixer\Tokenizer\Token;
  12487. use PhpCsFixer\Tokenizer\Tokens;
  12488. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  12489. final class VoidReturnFixer extends AbstractFixer
  12490. {
  12491. public function getDefinition()
  12492. {
  12493. return new FixerDefinition(
  12494. 'Add void return type to functions with missing or empty return statements, but priority is given to `@return` annotations. Requires PHP >= 7.1.',
  12495. [
  12496. new VersionSpecificCodeSample(
  12497. "<?php\nfunction foo(\$a) {};\n",
  12498. new VersionSpecification(70100)
  12499. ),
  12500. ],
  12501. null,
  12502. 'Modifies the signature of functions.'
  12503. );
  12504. }
  12505. public function getPriority()
  12506. {
  12507. return 15;
  12508. }
  12509. public function isCandidate(Tokens $tokens)
  12510. {
  12511. return PHP_VERSION_ID >= 70100 && $tokens->isTokenKindFound(T_FUNCTION);
  12512. }
  12513. public function isRisky()
  12514. {
  12515. return true;
  12516. }
  12517. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12518. {
  12519. static $blacklistFuncNames = [
  12520. [T_STRING, '__construct'],
  12521. [T_STRING, '__destruct'],
  12522. [T_STRING, '__clone'],
  12523. ];
  12524. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  12525. if (!$tokens[$index]->isGivenKind(T_FUNCTION)) {
  12526. continue;
  12527. }
  12528. $funcName = $tokens->getNextMeaningfulToken($index);
  12529. if ($tokens[$funcName]->equalsAny($blacklistFuncNames, false)) {
  12530. continue;
  12531. }
  12532. $startIndex = $tokens->getNextTokenOfKind($index, ['{', ';']);
  12533. if ($this->hasReturnTypeHint($tokens, $startIndex)) {
  12534. continue;
  12535. }
  12536. if ($tokens[$startIndex]->equals(';')) {
  12537. if ($this->hasVoidReturnAnnotation($tokens, $index)) {
  12538. $this->fixFunctionDefinition($tokens, $startIndex);
  12539. }
  12540. continue;
  12541. }
  12542. if ($this->hasReturnAnnotation($tokens, $index)) {
  12543. continue;
  12544. }
  12545. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $startIndex);
  12546. if ($this->hasVoidReturn($tokens, $startIndex, $endIndex)) {
  12547. $this->fixFunctionDefinition($tokens, $startIndex);
  12548. }
  12549. }
  12550. }
  12551. private function hasReturnAnnotation(Tokens $tokens, $index)
  12552. {
  12553. foreach ($this->findReturnAnnotations($tokens, $index) as $return) {
  12554. if (['void'] !== $return->getTypes()) {
  12555. return true;
  12556. }
  12557. }
  12558. return false;
  12559. }
  12560. private function hasVoidReturnAnnotation(Tokens $tokens, $index)
  12561. {
  12562. foreach ($this->findReturnAnnotations($tokens, $index) as $return) {
  12563. if (['void'] === $return->getTypes()) {
  12564. return true;
  12565. }
  12566. }
  12567. return false;
  12568. }
  12569. private function hasReturnTypeHint(Tokens $tokens, $index)
  12570. {
  12571. $endFuncIndex = $tokens->getPrevTokenOfKind($index, [')']);
  12572. $nextIndex = $tokens->getNextMeaningfulToken($endFuncIndex);
  12573. return $tokens[$nextIndex]->isGivenKind(CT::T_TYPE_COLON);
  12574. }
  12575. private function hasVoidReturn(Tokens $tokens, $startIndex, $endIndex)
  12576. {
  12577. $tokensAnalyzer = new TokensAnalyzer($tokens);
  12578. for ($i = $startIndex; $i < $endIndex; ++$i) {
  12579. if (
  12580. ($tokens[$i]->isGivenKind(T_CLASS) && $tokensAnalyzer->isAnonymousClass($i)) ||
  12581. ($tokens[$i]->isGivenKind(T_FUNCTION) && $tokensAnalyzer->isLambda($i))
  12582. ) {
  12583. $i = $tokens->getNextTokenOfKind($i, ['{']);
  12584. $i = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $i);
  12585. continue;
  12586. }
  12587. if ($tokens[$i]->isGivenKind(T_YIELD)) {
  12588. return false;
  12589. }
  12590. if (!$tokens[$i]->isGivenKind(T_RETURN)) {
  12591. continue;
  12592. }
  12593. $i = $tokens->getNextMeaningfulToken($i);
  12594. if (!$tokens[$i]->equals(';')) {
  12595. return false;
  12596. }
  12597. }
  12598. return true;
  12599. }
  12600. private function fixFunctionDefinition(Tokens $tokens, $index)
  12601. {
  12602. $endFuncIndex = $tokens->getPrevTokenOfKind($index, [')']);
  12603. $tokens->insertAt($endFuncIndex + 1, [
  12604. new Token([CT::T_TYPE_COLON, ':']),
  12605. new Token([T_WHITESPACE, ' ']),
  12606. new Token([T_STRING, 'void']),
  12607. ]);
  12608. }
  12609. private function findReturnAnnotations(Tokens $tokens, $index)
  12610. {
  12611. do {
  12612. $index = $tokens->getPrevNonWhitespace($index);
  12613. } while ($tokens[$index]->isGivenKind([
  12614. T_ABSTRACT,
  12615. T_FINAL,
  12616. T_PRIVATE,
  12617. T_PROTECTED,
  12618. T_PUBLIC,
  12619. T_STATIC,
  12620. ]));
  12621. if (!$tokens[$index]->isGivenKind(T_DOC_COMMENT)) {
  12622. return [];
  12623. }
  12624. $doc = new DocBlock($tokens[$index]->getContent());
  12625. return $doc->getAnnotationsOfType('return');
  12626. }
  12627. }
  12628. <?php
  12629. namespace PhpCsFixer\Fixer\Import;
  12630. use PhpCsFixer\AbstractFixer;
  12631. use PhpCsFixer\FixerDefinition\CodeSample;
  12632. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12633. use PhpCsFixer\Tokenizer\CT;
  12634. use PhpCsFixer\Tokenizer\Tokens;
  12635. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  12636. final class NoLeadingImportSlashFixer extends AbstractFixer
  12637. {
  12638. public function getDefinition()
  12639. {
  12640. return new FixerDefinition(
  12641. 'Remove leading slashes in use clauses.',
  12642. [new CodeSample("<?php\nnamespace Foo;\nuse \\Bar;\n")]
  12643. );
  12644. }
  12645. public function getPriority()
  12646. {
  12647. return -20;
  12648. }
  12649. public function isCandidate(Tokens $tokens)
  12650. {
  12651. return $tokens->isTokenKindFound(T_USE);
  12652. }
  12653. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12654. {
  12655. $tokensAnalyzer = new TokensAnalyzer($tokens);
  12656. $usesIndexes = $tokensAnalyzer->getImportUseIndexes();
  12657. foreach ($usesIndexes as $idx) {
  12658. $nextTokenIdx = $tokens->getNextMeaningfulToken($idx);
  12659. $nextToken = $tokens[$nextTokenIdx];
  12660. if ($nextToken->isGivenKind(T_NS_SEPARATOR)) {
  12661. $tokens->clearAt($nextTokenIdx);
  12662. } elseif ($nextToken->isGivenKind([CT::T_FUNCTION_IMPORT, CT::T_CONST_IMPORT])) {
  12663. $nextTokenIdx = $tokens->getNextMeaningfulToken($nextTokenIdx);
  12664. if ($tokens[$nextTokenIdx]->isGivenKind(T_NS_SEPARATOR)) {
  12665. $tokens->clearAt($nextTokenIdx);
  12666. }
  12667. }
  12668. }
  12669. }
  12670. }
  12671. <?php
  12672. namespace PhpCsFixer\Fixer\Import;
  12673. use PhpCsFixer\AbstractFixer;
  12674. use PhpCsFixer\FixerDefinition\CodeSample;
  12675. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12676. use PhpCsFixer\Tokenizer\Token;
  12677. use PhpCsFixer\Tokenizer\Tokens;
  12678. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  12679. final class NoUnusedImportsFixer extends AbstractFixer
  12680. {
  12681. public function getDefinition()
  12682. {
  12683. return new FixerDefinition(
  12684. 'Unused use statements must be removed.',
  12685. [new CodeSample("<?php\nuse \\DateTime;\nuse \\Exception;\n\nnew DateTime();\n")]
  12686. );
  12687. }
  12688. public function getPriority()
  12689. {
  12690. return -10;
  12691. }
  12692. public function isCandidate(Tokens $tokens)
  12693. {
  12694. return $tokens->isTokenKindFound(T_USE);
  12695. }
  12696. public function supports(\SplFileInfo $file)
  12697. {
  12698. $path = $file->getPathname();
  12699. if (false !== strpos($path, DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR) &&
  12700. false === strpos($path, DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'Fixtures'.DIRECTORY_SEPARATOR)
  12701. ) {
  12702. return false;
  12703. }
  12704. return true;
  12705. }
  12706. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12707. {
  12708. $tokensAnalyzer = new TokensAnalyzer($tokens);
  12709. $useDeclarationsIndexes = $tokensAnalyzer->getImportUseIndexes();
  12710. if (0 === count($useDeclarationsIndexes)) {
  12711. return;
  12712. }
  12713. $useDeclarations = $this->getNamespaceUseDeclarations($tokens, $useDeclarationsIndexes);
  12714. $namespaceDeclarations = $this->getNamespaceDeclarations($tokens);
  12715. $contentWithoutUseDeclarations = $this->generateCodeWithoutPartials($tokens, array_merge($namespaceDeclarations, $useDeclarations));
  12716. $useUsages = $this->detectUseUsages($contentWithoutUseDeclarations, $useDeclarations);
  12717. $this->removeUnusedUseDeclarations($tokens, $useDeclarations, $useUsages);
  12718. $this->removeUsesInSameNamespace($tokens, $useDeclarations, $namespaceDeclarations);
  12719. }
  12720. private function detectUseUsages($content, array $useDeclarations)
  12721. {
  12722. $usages = [];
  12723. foreach ($useDeclarations as $shortName => $useDeclaration) {
  12724. $usages[$shortName] = (bool) preg_match('/(?<![\$\\\\])(?<!->)\b'.preg_quote($shortName, '/').'\b/i', $content);
  12725. }
  12726. return $usages;
  12727. }
  12728. private function generateCodeWithoutPartials(Tokens $tokens, array $partials)
  12729. {
  12730. $content = '';
  12731. foreach ($tokens as $index => $token) {
  12732. $allowToAppend = true;
  12733. foreach ($partials as $partial) {
  12734. if ($partial['start'] <= $index && $index <= $partial['end']) {
  12735. $allowToAppend = false;
  12736. break;
  12737. }
  12738. }
  12739. if ($allowToAppend) {
  12740. $content .= $token->getContent();
  12741. }
  12742. }
  12743. return $content;
  12744. }
  12745. private function getNamespaceDeclarations(Tokens $tokens)
  12746. {
  12747. $namespaces = [];
  12748. foreach ($tokens as $index => $token) {
  12749. if (!$token->isGivenKind(T_NAMESPACE)) {
  12750. continue;
  12751. }
  12752. $declarationEndIndex = $tokens->getNextTokenOfKind($index, [';', '{']);
  12753. $namespaces[] = [
  12754. 'name' => trim($tokens->generatePartialCode($index + 1, $declarationEndIndex - 1)),
  12755. 'start' => $index,
  12756. 'end' => $declarationEndIndex,
  12757. ];
  12758. }
  12759. return $namespaces;
  12760. }
  12761. private function getNamespaceUseDeclarations(Tokens $tokens, array $useIndexes)
  12762. {
  12763. $uses = [];
  12764. foreach ($useIndexes as $index) {
  12765. $declarationEndIndex = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]);
  12766. $declarationContent = $tokens->generatePartialCode($index + 1, $declarationEndIndex - 1);
  12767. if (
  12768. false !== strpos($declarationContent, ',')
  12769. || false !== strpos($declarationContent, '{')
  12770. ) {
  12771. continue;
  12772. }
  12773. $declarationParts = preg_split('/\s+as\s+/i', $declarationContent);
  12774. if (1 === count($declarationParts)) {
  12775. $fullName = $declarationContent;
  12776. $declarationParts = explode('\\', $fullName);
  12777. $shortName = end($declarationParts);
  12778. $aliased = false;
  12779. } else {
  12780. list($fullName, $shortName) = $declarationParts;
  12781. $declarationParts = explode('\\', $fullName);
  12782. $aliased = $shortName !== end($declarationParts);
  12783. }
  12784. $shortName = trim($shortName);
  12785. $uses[$shortName] = [
  12786. 'fullName' => trim($fullName),
  12787. 'shortName' => $shortName,
  12788. 'aliased' => $aliased,
  12789. 'start' => $index,
  12790. 'end' => $declarationEndIndex,
  12791. ];
  12792. }
  12793. return $uses;
  12794. }
  12795. private function removeUnusedUseDeclarations(Tokens $tokens, array $useDeclarations, array $useUsages)
  12796. {
  12797. foreach ($useDeclarations as $shortName => $useDeclaration) {
  12798. if (!$useUsages[$shortName]) {
  12799. $this->removeUseDeclaration($tokens, $useDeclaration);
  12800. }
  12801. }
  12802. }
  12803. private function removeUseDeclaration(Tokens $tokens, array $useDeclaration)
  12804. {
  12805. for ($index = $useDeclaration['end'] - 1; $index >= $useDeclaration['start']; --$index) {
  12806. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  12807. }
  12808. if ($tokens[$useDeclaration['end']]->equals(';')) {
  12809. $tokens->clearAt($useDeclaration['end']);
  12810. }
  12811. $prevIndex = $useDeclaration['start'] - 1;
  12812. $prevToken = $tokens[$prevIndex];
  12813. if ($prevToken->isWhitespace()) {
  12814. $content = rtrim($prevToken->getContent(), " \t");
  12815. if ('' !== $content) {
  12816. $tokens[$prevIndex] = new Token([T_WHITESPACE, $content]);
  12817. } else {
  12818. $tokens->clearAt($prevIndex);
  12819. }
  12820. $prevToken = $tokens[$prevIndex];
  12821. }
  12822. if (!isset($tokens[$useDeclaration['end'] + 1])) {
  12823. return;
  12824. }
  12825. $nextIndex = $tokens->getNonEmptySibling($useDeclaration['end'], 1);
  12826. if (null === $nextIndex) {
  12827. return;
  12828. }
  12829. $nextToken = $tokens[$nextIndex];
  12830. if ($nextToken->isWhitespace()) {
  12831. $content = ltrim($nextToken->getContent(), " \t");
  12832. $content = preg_replace(
  12833. "#^\r\n|^\n#",
  12834. '',
  12835. $content,
  12836. 1
  12837. );
  12838. if ('' !== $content) {
  12839. $tokens[$nextIndex] = new Token([T_WHITESPACE, $content]);
  12840. } else {
  12841. $tokens->clearAt($nextIndex);
  12842. }
  12843. $nextToken = $tokens[$nextIndex];
  12844. }
  12845. if ($prevToken->isWhitespace() && $nextToken->isWhitespace()) {
  12846. $content = $prevToken->getContent().$nextToken->getContent();
  12847. if ('' !== $content) {
  12848. $tokens[$nextIndex] = new Token([T_WHITESPACE, $content]);
  12849. } else {
  12850. $tokens->clearAt($nextIndex);
  12851. }
  12852. $tokens->clearAt($prevIndex);
  12853. }
  12854. }
  12855. private function removeUsesInSameNamespace(Tokens $tokens, array $useDeclarations, array $namespaceDeclarations)
  12856. {
  12857. if (1 !== count($namespaceDeclarations)) {
  12858. return;
  12859. }
  12860. $namespace = $namespaceDeclarations[0]['name'];
  12861. $nsLength = strlen($namespace.'\\');
  12862. foreach ($useDeclarations as $useDeclaration) {
  12863. if ($useDeclaration['aliased']) {
  12864. continue;
  12865. }
  12866. $useDeclarationFullName = ltrim($useDeclaration['fullName'], '\\');
  12867. if (0 !== strpos($useDeclarationFullName, $namespace.'\\')) {
  12868. continue;
  12869. }
  12870. $partName = substr($useDeclarationFullName, $nsLength);
  12871. if (false === strpos($partName, '\\')) {
  12872. $this->removeUseDeclaration($tokens, $useDeclaration);
  12873. }
  12874. }
  12875. }
  12876. }
  12877. <?php
  12878. namespace PhpCsFixer\Fixer\Import;
  12879. use PhpCsFixer\AbstractFixer;
  12880. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  12881. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  12882. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  12883. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  12884. use PhpCsFixer\FixerDefinition\CodeSample;
  12885. use PhpCsFixer\FixerDefinition\FixerDefinition;
  12886. use PhpCsFixer\FixerDefinition\VersionSpecification;
  12887. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  12888. use PhpCsFixer\Tokenizer\CT;
  12889. use PhpCsFixer\Tokenizer\Token;
  12890. use PhpCsFixer\Tokenizer\Tokens;
  12891. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  12892. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  12893. final class OrderedImportsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  12894. {
  12895. const IMPORT_TYPE_CLASS = 'class';
  12896. const IMPORT_TYPE_CONST = 'const';
  12897. const IMPORT_TYPE_FUNCTION = 'function';
  12898. const SORT_ALPHA = 'alpha';
  12899. const SORT_LENGTH = 'length';
  12900. private $supportedSortTypes = [self::IMPORT_TYPE_CLASS, self::IMPORT_TYPE_CONST, self::IMPORT_TYPE_FUNCTION];
  12901. private $supportedSortAlgorithms = [self::SORT_ALPHA, self::SORT_LENGTH];
  12902. public function getDefinition()
  12903. {
  12904. return new FixerDefinition(
  12905. 'Ordering use statements.',
  12906. [
  12907. new CodeSample("<?php\nuse Z; use A;\n"),
  12908. new CodeSample(
  12909. '<?php
  12910. use Bar1;
  12911. use Acme;
  12912. use Barr;
  12913. use Acme\Bar;
  12914. ',
  12915. ['sortAlgorithm' => self::SORT_LENGTH]
  12916. ),
  12917. new VersionSpecificCodeSample(
  12918. "<?php\nuse function AAA;\nuse const AAB;\nuse AAC;\n",
  12919. new VersionSpecification(70000)
  12920. ),
  12921. new VersionSpecificCodeSample(
  12922. '<?php
  12923. use const AAAA;
  12924. use const BBB;
  12925. use Bar;
  12926. use AAC;
  12927. use Acme;
  12928. use function CCC\AA;
  12929. use function DDD;
  12930. ',
  12931. new VersionSpecification(70000),
  12932. [
  12933. 'sortAlgorithm' => self::SORT_LENGTH,
  12934. 'importsOrder' => [
  12935. self::IMPORT_TYPE_CONST,
  12936. self::IMPORT_TYPE_CLASS,
  12937. self::IMPORT_TYPE_FUNCTION,
  12938. ],
  12939. ]
  12940. ),
  12941. new VersionSpecificCodeSample(
  12942. '<?php
  12943. use const BBB;
  12944. use const AAAA;
  12945. use Acme;
  12946. use AAC;
  12947. use Bar;
  12948. use function DDD;
  12949. use function CCC\AA;
  12950. ',
  12951. new VersionSpecification(70000),
  12952. [
  12953. 'sortAlgorithm' => self::SORT_ALPHA,
  12954. 'importsOrder' => [
  12955. self::IMPORT_TYPE_CONST,
  12956. self::IMPORT_TYPE_CLASS,
  12957. self::IMPORT_TYPE_FUNCTION,
  12958. ],
  12959. ]
  12960. ),
  12961. ]
  12962. );
  12963. }
  12964. public function getPriority()
  12965. {
  12966. return -30;
  12967. }
  12968. public function isCandidate(Tokens $tokens)
  12969. {
  12970. return $tokens->isTokenKindFound(T_USE);
  12971. }
  12972. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  12973. {
  12974. $tokensAnalyzer = new TokensAnalyzer($tokens);
  12975. $namespacesImports = $tokensAnalyzer->getImportUseIndexes(true);
  12976. if (0 === count($namespacesImports)) {
  12977. return;
  12978. }
  12979. $usesOrder = [];
  12980. foreach ($namespacesImports as $uses) {
  12981. $usesOrder[] = $this->getNewOrder(array_reverse($uses), $tokens);
  12982. }
  12983. $usesOrder = array_replace(...$usesOrder);
  12984. $usesOrder = array_reverse($usesOrder, true);
  12985. $mapStartToEnd = [];
  12986. foreach ($usesOrder as $use) {
  12987. $mapStartToEnd[$use['startIndex']] = $use['endIndex'];
  12988. }
  12989. foreach ($usesOrder as $index => $use) {
  12990. $declarationTokens = Tokens::fromCode('<?php use '.$use['namespace'].';');
  12991. $declarationTokens->clearRange(0, 2);
  12992. $declarationTokens->clearAt(count($declarationTokens) - 1);
  12993. $declarationTokens->clearEmptyTokens();
  12994. $tokens->overrideRange($index, $mapStartToEnd[$index], $declarationTokens);
  12995. if ($use['group']) {
  12996. $prev = $tokens->getPrevMeaningfulToken($index);
  12997. if ($tokens[$prev]->equals(',')) {
  12998. $tokens[$prev] = new Token(';');
  12999. $tokens->insertAt($prev + 1, new Token([T_USE, 'use']));
  13000. if (!$tokens[$prev + 2]->isWhitespace()) {
  13001. $tokens->insertAt($prev + 2, new Token([T_WHITESPACE, ' ']));
  13002. }
  13003. }
  13004. }
  13005. }
  13006. }
  13007. protected function createConfigurationDefinition()
  13008. {
  13009. $supportedSortTypes = $this->supportedSortTypes;
  13010. return new FixerConfigurationResolver([
  13011. (new FixerOptionBuilder('sortAlgorithm', 'whether the statements should be sorted alphabetically or by length'))
  13012. ->setAllowedValues($this->supportedSortAlgorithms)
  13013. ->setDefault(self::SORT_ALPHA)
  13014. ->getOption(),
  13015. (new FixerOptionBuilder('importsOrder', 'Defines the order of import types.'))
  13016. ->setAllowedTypes(['array', 'null'])
  13017. ->setAllowedValues([static function ($value) use ($supportedSortTypes) {
  13018. if (null !== $value) {
  13019. $missing = array_diff($supportedSortTypes, $value);
  13020. if (count($missing)) {
  13021. throw new InvalidOptionsException(sprintf(
  13022. 'Missing sort %s "%s".',
  13023. 1 === count($missing) ? 'type' : 'types',
  13024. implode('", "', $missing)
  13025. ));
  13026. }
  13027. $unknown = array_diff($value, $supportedSortTypes);
  13028. if (count($unknown)) {
  13029. throw new InvalidOptionsException(sprintf(
  13030. 'Unknown sort %s "%s".',
  13031. 1 === count($unknown) ? 'type' : 'types',
  13032. implode('", "', $unknown)
  13033. ));
  13034. }
  13035. }
  13036. return true;
  13037. }])
  13038. ->setDefault(null)
  13039. ->getOption(),
  13040. ]);
  13041. }
  13042. private function sortAlphabetically(array $first, array $second)
  13043. {
  13044. if ($first['importType'] !== $second['importType']) {
  13045. return $first['importType'] > $second['importType'] ? 1 : -1;
  13046. }
  13047. $firstNamespace = str_replace('\\', ' ', $this->prepareNamespace($first['namespace']));
  13048. $secondNamespace = str_replace('\\', ' ', $this->prepareNamespace($second['namespace']));
  13049. return strcasecmp($firstNamespace, $secondNamespace);
  13050. }
  13051. private function sortByLength(array $first, array $second)
  13052. {
  13053. $firstNamespace = $this->prepareNamespace($first['namespace']);
  13054. $secondNamespace = $this->prepareNamespace($second['namespace']);
  13055. $firstNamespaceLength = strlen($firstNamespace);
  13056. $secondNamespaceLength = strlen($secondNamespace);
  13057. if ($firstNamespaceLength === $secondNamespaceLength) {
  13058. $sortResult = strcasecmp($firstNamespace, $secondNamespace);
  13059. } else {
  13060. $sortResult = $firstNamespaceLength > $secondNamespaceLength ? 1 : -1;
  13061. }
  13062. return $sortResult;
  13063. }
  13064. private function prepareNamespace($namespace)
  13065. {
  13066. return trim(preg_replace('%/\*(.*)\*/%s', '', $namespace));
  13067. }
  13068. private function getNewOrder(array $uses, Tokens $tokens)
  13069. {
  13070. $indexes = [];
  13071. $originalIndexes = [];
  13072. $lineEnding = $this->whitespacesConfig->getLineEnding();
  13073. for ($i = count($uses) - 1; $i >= 0; --$i) {
  13074. $index = $uses[$i];
  13075. $startIndex = $tokens->getTokenNotOfKindSibling($index + 1, 1, [[T_WHITESPACE]]);
  13076. $endIndex = $tokens->getNextTokenOfKind($startIndex, [';', [T_CLOSE_TAG]]);
  13077. $previous = $tokens->getPrevMeaningfulToken($endIndex);
  13078. $group = $tokens[$previous]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_CLOSE);
  13079. if ($tokens[$startIndex]->isGivenKind([CT::T_CONST_IMPORT])) {
  13080. $type = self::IMPORT_TYPE_CONST;
  13081. } elseif ($tokens[$startIndex]->isGivenKind([CT::T_FUNCTION_IMPORT])) {
  13082. $type = self::IMPORT_TYPE_FUNCTION;
  13083. } else {
  13084. $type = self::IMPORT_TYPE_CLASS;
  13085. }
  13086. $namespaceTokens = [];
  13087. $index = $startIndex;
  13088. while ($index <= $endIndex) {
  13089. $token = $tokens[$index];
  13090. if ($index === $endIndex || (!$group && $token->equals(','))) {
  13091. if ($group) {
  13092. $namespaceTokensCount = count($namespaceTokens) - 1;
  13093. $namespace = '';
  13094. for ($k = 0; $k < $namespaceTokensCount; ++$k) {
  13095. if ($namespaceTokens[$k]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_OPEN)) {
  13096. $namespace .= '{';
  13097. break;
  13098. }
  13099. $namespace .= $namespaceTokens[$k]->getContent();
  13100. }
  13101. $parts = [];
  13102. $firstIndent = '';
  13103. $separator = ', ';
  13104. $lastIndent = '';
  13105. for ($k1 = $k + 1; $k1 < $namespaceTokensCount; ++$k1) {
  13106. $comment = '';
  13107. $namespacePart = '';
  13108. for ($k2 = $k1;; ++$k2) {
  13109. if ($namespaceTokens[$k2]->equalsAny([',', [CT::T_GROUP_IMPORT_BRACE_CLOSE]])) {
  13110. break;
  13111. }
  13112. if ($namespaceTokens[$k2]->isComment()) {
  13113. $comment .= $namespaceTokens[$k2]->getContent();
  13114. continue;
  13115. }
  13116. if (
  13117. '' === $firstIndent &&
  13118. $namespaceTokens[$k2]->isWhitespace() &&
  13119. false !== strpos($namespaceTokens[$k2]->getContent(), $lineEnding)
  13120. ) {
  13121. $lastIndent = $lineEnding;
  13122. $firstIndent = $lineEnding.$this->whitespacesConfig->getIndent();
  13123. $separator = ','.$firstIndent;
  13124. }
  13125. $namespacePart .= $namespaceTokens[$k2]->getContent();
  13126. }
  13127. $namespacePart = trim($namespacePart);
  13128. $comment = trim($comment);
  13129. if ('' !== $comment) {
  13130. $namespacePart .= ' '.$comment;
  13131. }
  13132. $parts[] = $namespacePart;
  13133. $k1 = $k2;
  13134. }
  13135. $sortedParts = $parts;
  13136. sort($parts);
  13137. if ($sortedParts === $parts) {
  13138. $namespace = Tokens::fromArray($namespaceTokens)->generateCode();
  13139. } else {
  13140. $namespace .= $firstIndent.implode($separator, $parts).$lastIndent.'}';
  13141. }
  13142. } else {
  13143. $namespace = Tokens::fromArray($namespaceTokens)->generateCode();
  13144. }
  13145. $indexes[$startIndex] = [
  13146. 'namespace' => $namespace,
  13147. 'startIndex' => $startIndex,
  13148. 'endIndex' => $index - 1,
  13149. 'importType' => $type,
  13150. 'group' => $group,
  13151. ];
  13152. $originalIndexes[] = $startIndex;
  13153. if ($index === $endIndex) {
  13154. break;
  13155. }
  13156. $namespaceTokens = [];
  13157. $nextPartIndex = $tokens->getTokenNotOfKindSibling($index, 1, [[','], [T_WHITESPACE]]);
  13158. $startIndex = $nextPartIndex;
  13159. $index = $nextPartIndex;
  13160. continue;
  13161. }
  13162. $namespaceTokens[] = $token;
  13163. ++$index;
  13164. }
  13165. }
  13166. if ($this->configuration['importsOrder']) {
  13167. $groupedByTypes = [];
  13168. foreach ($indexes as $startIndex => $item) {
  13169. $groupedByTypes[$item['importType']][$startIndex] = $item;
  13170. }
  13171. foreach ($groupedByTypes as $type => $indexes) {
  13172. $groupedByTypes[$type] = $this->sortByAlgorithm($indexes);
  13173. }
  13174. $sortedGroups = [];
  13175. foreach ($this->configuration['importsOrder'] as $type) {
  13176. if (isset($groupedByTypes[$type]) && !empty($groupedByTypes[$type])) {
  13177. foreach ($groupedByTypes[$type] as $startIndex => $item) {
  13178. $sortedGroups[$startIndex] = $item;
  13179. }
  13180. }
  13181. }
  13182. $indexes = $sortedGroups;
  13183. } else {
  13184. $indexes = $this->sortByAlgorithm($indexes);
  13185. }
  13186. $index = -1;
  13187. $usesOrder = [];
  13188. foreach ($indexes as $v) {
  13189. $usesOrder[$originalIndexes[++$index]] = $v;
  13190. }
  13191. return $usesOrder;
  13192. }
  13193. private function sortByAlgorithm($indexes)
  13194. {
  13195. if (self::SORT_ALPHA === $this->configuration['sortAlgorithm']) {
  13196. uasort($indexes, [$this, 'sortAlphabetically']);
  13197. } elseif (self::SORT_LENGTH === $this->configuration['sortAlgorithm']) {
  13198. uasort($indexes, [$this, 'sortByLength']);
  13199. } else {
  13200. throw new \LogicException(sprintf('Sort algorithm "%s" is not supported.', $this->configuration['sortAlgorithm']));
  13201. }
  13202. return $indexes;
  13203. }
  13204. }
  13205. <?php
  13206. namespace PhpCsFixer\Fixer\Import;
  13207. use PhpCsFixer\AbstractFixer;
  13208. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  13209. use PhpCsFixer\FixerDefinition\CodeSample;
  13210. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13211. use PhpCsFixer\Tokenizer\CT;
  13212. use PhpCsFixer\Tokenizer\Token;
  13213. use PhpCsFixer\Tokenizer\Tokens;
  13214. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  13215. final class SingleImportPerStatementFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  13216. {
  13217. public function getDefinition()
  13218. {
  13219. return new FixerDefinition(
  13220. 'There MUST be one use keyword per declaration.',
  13221. [new CodeSample("<?php\nuse Foo, Sample, Sample\\Sample as Sample2;\n")]
  13222. );
  13223. }
  13224. public function getPriority()
  13225. {
  13226. return 1;
  13227. }
  13228. public function isCandidate(Tokens $tokens)
  13229. {
  13230. return $tokens->isTokenKindFound(T_USE);
  13231. }
  13232. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13233. {
  13234. $tokensAnalyzer = new TokensAnalyzer($tokens);
  13235. $uses = array_reverse($tokensAnalyzer->getImportUseIndexes());
  13236. foreach ($uses as $index) {
  13237. $endIndex = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]);
  13238. $groupClose = $tokens->getPrevMeaningfulToken($endIndex);
  13239. if ($tokens[$groupClose]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_CLOSE)) {
  13240. $this->fixGroupUse($tokens, $index, $endIndex);
  13241. } else {
  13242. $this->fixMultipleUse($tokens, $index, $endIndex);
  13243. }
  13244. }
  13245. }
  13246. private function detectIndent(Tokens $tokens, $index)
  13247. {
  13248. if (!$tokens[$index - 1]->isWhitespace()) {
  13249. return '';
  13250. }
  13251. $explodedContent = explode("\n", $tokens[$index - 1]->getContent());
  13252. return end($explodedContent);
  13253. }
  13254. private function getGroupDeclaration(Tokens $tokens, $index)
  13255. {
  13256. $groupPrefix = '';
  13257. $comment = '';
  13258. for ($i = $index + 1;; ++$i) {
  13259. if ($tokens[$i]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_OPEN)) {
  13260. $groupOpenIndex = $i;
  13261. break;
  13262. }
  13263. if ($tokens[$i]->isComment()) {
  13264. $comment .= $tokens[$i]->getContent();
  13265. if (!$tokens[$i - 1]->isWhitespace() && !$tokens[$i + 1]->isWhitespace()) {
  13266. $groupPrefix .= ' ';
  13267. }
  13268. continue;
  13269. }
  13270. if ($tokens[$i]->isWhitespace()) {
  13271. $groupPrefix .= ' ';
  13272. continue;
  13273. }
  13274. $groupPrefix .= $tokens[$i]->getContent();
  13275. }
  13276. return [
  13277. $groupPrefix,
  13278. $groupOpenIndex,
  13279. $tokens->findBlockEnd(Tokens::BLOCK_TYPE_GROUP_IMPORT_BRACE, $groupOpenIndex),
  13280. $comment,
  13281. ];
  13282. }
  13283. private function getGroupStatements(Tokens $tokens, $groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment)
  13284. {
  13285. $statements = [];
  13286. $statement = $groupPrefix;
  13287. for ($i = $groupOpenIndex + 1; $i <= $groupCloseIndex; ++$i) {
  13288. $token = $tokens[$i];
  13289. if ($token->equals(',') && $tokens[$tokens->getNextMeaningfulToken($i)]->equals([CT::T_GROUP_IMPORT_BRACE_CLOSE])) {
  13290. continue;
  13291. }
  13292. if ($token->equalsAny([',', [CT::T_GROUP_IMPORT_BRACE_CLOSE]])) {
  13293. $statements[] = 'use'.$statement.';';
  13294. $statement = $groupPrefix;
  13295. continue;
  13296. }
  13297. if ($token->isWhitespace()) {
  13298. $j = $tokens->getNextMeaningfulToken($i);
  13299. if ($tokens[$j]->equals([T_AS])) {
  13300. $statement .= ' as ';
  13301. $i += 2;
  13302. } elseif ($tokens[$j]->equals([T_FUNCTION])) {
  13303. $statement = ' function'.$statement;
  13304. $i += 2;
  13305. } elseif ($tokens[$j]->equals([T_CONST])) {
  13306. $statement = ' const'.$statement;
  13307. $i += 2;
  13308. }
  13309. if ($token->isWhitespace(" \t") || '//' !== substr($tokens[$i - 1]->getContent(), 0, 2)) {
  13310. continue;
  13311. }
  13312. }
  13313. $statement .= $token->getContent();
  13314. }
  13315. if ('' !== $comment) {
  13316. $statements[0] .= ' '.$comment;
  13317. }
  13318. return $statements;
  13319. }
  13320. private function fixGroupUse(Tokens $tokens, $index, $endIndex)
  13321. {
  13322. list($groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment) = $this->getGroupDeclaration($tokens, $index);
  13323. $statements = $this->getGroupStatements($tokens, $groupPrefix, $groupOpenIndex, $groupCloseIndex, $comment);
  13324. if (count($statements) < 2) {
  13325. return;
  13326. }
  13327. $tokens->clearRange($index, $groupCloseIndex);
  13328. if ($tokens[$endIndex]->equals(';')) {
  13329. $tokens->clearAt($endIndex);
  13330. }
  13331. $ending = $this->whitespacesConfig->getLineEnding();
  13332. $importTokens = Tokens::fromCode('<?php '.implode($ending, $statements));
  13333. $importTokens->clearAt(0);
  13334. $importTokens->clearEmptyTokens();
  13335. $tokens->insertAt($index, $importTokens);
  13336. }
  13337. private function fixMultipleUse(Tokens $tokens, $index, $endIndex)
  13338. {
  13339. $ending = $this->whitespacesConfig->getLineEnding();
  13340. for ($i = $endIndex - 1; $i > $index; --$i) {
  13341. if (!$tokens[$i]->equals(',')) {
  13342. continue;
  13343. }
  13344. $tokens[$i] = new Token(';');
  13345. $i = $tokens->getNextMeaningfulToken($i);
  13346. $tokens->insertAt($i, new Token([T_USE, 'use']));
  13347. $tokens->insertAt($i + 1, new Token([T_WHITESPACE, ' ']));
  13348. $indent = $this->detectIndent($tokens, $index);
  13349. if ($tokens[$i - 1]->isWhitespace()) {
  13350. $tokens[$i - 1] = new Token([T_WHITESPACE, $ending.$indent]);
  13351. continue;
  13352. }
  13353. if (false === strpos($tokens[$i - 1]->getContent(), "\n")) {
  13354. $tokens->insertAt($i, new Token([T_WHITESPACE, $ending.$indent]));
  13355. }
  13356. }
  13357. }
  13358. }
  13359. <?php
  13360. namespace PhpCsFixer\Fixer\Import;
  13361. use PhpCsFixer\AbstractFixer;
  13362. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  13363. use PhpCsFixer\FixerDefinition\CodeSample;
  13364. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13365. use PhpCsFixer\Tokenizer\Token;
  13366. use PhpCsFixer\Tokenizer\Tokens;
  13367. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  13368. use PhpCsFixer\Utils;
  13369. final class SingleLineAfterImportsFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  13370. {
  13371. public function isCandidate(Tokens $tokens)
  13372. {
  13373. return $tokens->isTokenKindFound(T_USE);
  13374. }
  13375. public function getDefinition()
  13376. {
  13377. return new FixerDefinition(
  13378. 'Each namespace use MUST go on its own line and there MUST be one blank line after the use statements block.',
  13379. [
  13380. new CodeSample(
  13381. '<?php
  13382. namespace Foo;
  13383. use Bar;
  13384. use Baz;
  13385. final class Example
  13386. {
  13387. }
  13388. '
  13389. ),
  13390. new CodeSample(
  13391. '<?php
  13392. namespace Foo;
  13393. use Bar;
  13394. use Baz;
  13395. final class Example
  13396. {
  13397. }
  13398. '
  13399. ),
  13400. ]
  13401. );
  13402. }
  13403. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13404. {
  13405. $ending = $this->whitespacesConfig->getLineEnding();
  13406. $tokensAnalyzer = new TokensAnalyzer($tokens);
  13407. $added = 0;
  13408. foreach ($tokensAnalyzer->getImportUseIndexes() as $index) {
  13409. $index += $added;
  13410. $indent = '';
  13411. if ($tokens[$index - 1]->isWhitespace(" \t") && $tokens[$index - 2]->isGivenKind(T_COMMENT)) {
  13412. $indent = $tokens[$index - 1]->getContent();
  13413. } elseif ($tokens[$index - 1]->isWhitespace()) {
  13414. $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$index - 1]);
  13415. }
  13416. $semicolonIndex = $tokens->getNextTokenOfKind($index, [';', [T_CLOSE_TAG]]);
  13417. $insertIndex = $semicolonIndex;
  13418. if ($tokens[$semicolonIndex]->isGivenKind(T_CLOSE_TAG)) {
  13419. if ($tokens[$insertIndex - 1]->isWhitespace()) {
  13420. --$insertIndex;
  13421. }
  13422. $tokens->insertAt($insertIndex, new Token(';'));
  13423. ++$added;
  13424. }
  13425. if ($semicolonIndex === count($tokens) - 1) {
  13426. $tokens->insertAt($insertIndex + 1, new Token([T_WHITESPACE, $ending.$ending.$indent]));
  13427. ++$added;
  13428. } else {
  13429. $newline = $ending;
  13430. $tokens[$semicolonIndex]->isGivenKind(T_CLOSE_TAG) ? --$insertIndex : ++$insertIndex;
  13431. if ($tokens[$insertIndex]->isWhitespace(" \t") && $tokens[$insertIndex + 1]->isComment()) {
  13432. ++$insertIndex;
  13433. }
  13434. if ($tokens[$insertIndex]->isComment()) {
  13435. ++$insertIndex;
  13436. }
  13437. $afterSemicolon = $tokens->getNextMeaningfulToken($semicolonIndex);
  13438. if (null === $afterSemicolon || !$tokens[$afterSemicolon]->isGivenKind(T_USE)) {
  13439. $newline .= $ending;
  13440. }
  13441. if ($tokens[$insertIndex]->isWhitespace()) {
  13442. $nextToken = $tokens[$insertIndex];
  13443. $nextMeaningfulAfterUseIndex = $tokens->getNextMeaningfulToken($insertIndex);
  13444. if (null !== $nextMeaningfulAfterUseIndex && $tokens[$nextMeaningfulAfterUseIndex]->isGivenKind(T_USE)) {
  13445. if (substr_count($nextToken->getContent(), "\n") < 2) {
  13446. $tokens[$insertIndex] = new Token([T_WHITESPACE, $newline.$indent.ltrim($nextToken->getContent())]);
  13447. }
  13448. } else {
  13449. $tokens[$insertIndex] = new Token([T_WHITESPACE, $newline.$indent.ltrim($nextToken->getContent())]);
  13450. }
  13451. } else {
  13452. $tokens->insertAt($insertIndex, new Token([T_WHITESPACE, $newline.$indent]));
  13453. ++$added;
  13454. }
  13455. }
  13456. }
  13457. }
  13458. }
  13459. <?php
  13460. namespace PhpCsFixer\Fixer\LanguageConstruct;
  13461. use PhpCsFixer\AbstractFixer;
  13462. use PhpCsFixer\FixerDefinition\CodeSample;
  13463. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13464. use PhpCsFixer\Tokenizer\CT;
  13465. use PhpCsFixer\Tokenizer\Token;
  13466. use PhpCsFixer\Tokenizer\Tokens;
  13467. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  13468. final class ClassKeywordRemoveFixer extends AbstractFixer
  13469. {
  13470. private $imports = [];
  13471. public function getDefinition()
  13472. {
  13473. return new FixerDefinition(
  13474. 'Converts `::class` keywords to FQCN strings.',
  13475. [
  13476. new CodeSample(
  13477. '<?php
  13478. use Foo\Bar\Baz;
  13479. $className = Baz::class;
  13480. '
  13481. ),
  13482. ]
  13483. );
  13484. }
  13485. public function isCandidate(Tokens $tokens)
  13486. {
  13487. return $tokens->isTokenKindFound(CT::T_CLASS_CONSTANT);
  13488. }
  13489. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13490. {
  13491. $this->replaceClassKeywords($tokens);
  13492. }
  13493. private function replaceClassKeywords(Tokens $tokens, $namespaceNumber = -1)
  13494. {
  13495. $namespaceIndexes = array_keys($tokens->findGivenKind(T_NAMESPACE));
  13496. if (count($namespaceIndexes) && isset($namespaceIndexes[$namespaceNumber])) {
  13497. $startIndex = $namespaceIndexes[$namespaceNumber];
  13498. $namespaceBlockStartIndex = $tokens->getNextTokenOfKind($startIndex, [';', '{']);
  13499. $endIndex = $tokens[$namespaceBlockStartIndex]->equals('{')
  13500. ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $namespaceBlockStartIndex)
  13501. : $tokens->getNextTokenOfKind($namespaceBlockStartIndex, [T_NAMESPACE]);
  13502. $endIndex = $endIndex ?: $tokens->count() - 1;
  13503. } elseif (-1 === $namespaceNumber) {
  13504. $startIndex = 0;
  13505. $endIndex = count($namespaceIndexes) ? $namespaceIndexes[0] : $tokens->count() - 1;
  13506. } else {
  13507. return;
  13508. }
  13509. $this->storeImports($tokens, $startIndex, $endIndex);
  13510. $tokens->rewind();
  13511. $this->replaceClassKeywordsSection($tokens, $startIndex, $endIndex);
  13512. $this->replaceClassKeywords($tokens, $namespaceNumber + 1);
  13513. }
  13514. private function storeImports(Tokens $tokens, $startIndex, $endIndex)
  13515. {
  13516. $tokensAnalyzer = new TokensAnalyzer($tokens);
  13517. $this->imports = [];
  13518. foreach ($tokensAnalyzer->getImportUseIndexes() as $index) {
  13519. if ($index < $startIndex || $index > $endIndex) {
  13520. continue;
  13521. }
  13522. $import = '';
  13523. while ($index = $tokens->getNextMeaningfulToken($index)) {
  13524. if ($tokens[$index]->equalsAny([';', [CT::T_GROUP_IMPORT_BRACE_OPEN]]) || $tokens[$index]->isGivenKind(T_AS)) {
  13525. break;
  13526. }
  13527. $import .= $tokens[$index]->getContent();
  13528. }
  13529. if ($tokens[$index]->isGivenKind(CT::T_GROUP_IMPORT_BRACE_OPEN)) {
  13530. $groupEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_GROUP_IMPORT_BRACE, $index);
  13531. $groupImports = array_map(
  13532. static function ($import) {
  13533. return trim($import);
  13534. },
  13535. explode(',', $tokens->generatePartialCode($index + 1, $groupEndIndex - 1))
  13536. );
  13537. foreach ($groupImports as $groupImport) {
  13538. $groupImportParts = array_map(static function ($import) {
  13539. return trim($import);
  13540. }, explode(' as ', $groupImport));
  13541. if (2 === count($groupImportParts)) {
  13542. $this->imports[$groupImportParts[1]] = $import.$groupImportParts[0];
  13543. } else {
  13544. $this->imports[] = $import.$groupImport;
  13545. }
  13546. }
  13547. } elseif ($tokens[$index]->isGivenKind(T_AS)) {
  13548. $aliasIndex = $tokens->getNextMeaningfulToken($index);
  13549. $alias = $tokens[$aliasIndex]->getContent();
  13550. $this->imports[$alias] = $import;
  13551. } else {
  13552. $this->imports[] = $import;
  13553. }
  13554. }
  13555. }
  13556. private function replaceClassKeywordsSection(Tokens $tokens, $startIndex, $endIndex)
  13557. {
  13558. $ctClassTokens = $tokens->findGivenKind(CT::T_CLASS_CONSTANT, $startIndex, $endIndex);
  13559. if (!empty($ctClassTokens)) {
  13560. $this->replaceClassKeyword($tokens, current(array_keys($ctClassTokens)));
  13561. $this->replaceClassKeywordsSection($tokens, $startIndex, $endIndex);
  13562. }
  13563. }
  13564. private function replaceClassKeyword(Tokens $tokens, $classIndex)
  13565. {
  13566. $classEndIndex = $tokens->getPrevMeaningfulToken($classIndex);
  13567. $classEndIndex = $tokens->getPrevMeaningfulToken($classEndIndex);
  13568. $classBeginIndex = $classEndIndex;
  13569. while (true) {
  13570. $prev = $tokens->getPrevMeaningfulToken($classBeginIndex);
  13571. if (!$tokens[$prev]->isGivenKind([T_NS_SEPARATOR, T_STRING])) {
  13572. break;
  13573. }
  13574. $classBeginIndex = $prev;
  13575. }
  13576. $classString = $tokens->generatePartialCode(
  13577. $tokens[$classBeginIndex]->isGivenKind(T_NS_SEPARATOR)
  13578. ? $tokens->getNextMeaningfulToken($classBeginIndex)
  13579. : $classBeginIndex,
  13580. $classEndIndex
  13581. );
  13582. $classImport = false;
  13583. foreach ($this->imports as $alias => $import) {
  13584. if ($classString === $alias) {
  13585. $classImport = $import;
  13586. break;
  13587. }
  13588. $classStringArray = explode('\\', $classString);
  13589. $namespaceToTest = $classStringArray[0];
  13590. if (0 === strcmp($namespaceToTest, substr($import, -strlen($namespaceToTest)))) {
  13591. $classImport = $import;
  13592. break;
  13593. }
  13594. }
  13595. for ($i = $classBeginIndex; $i <= $classIndex; ++$i) {
  13596. if (!$tokens[$i]->isComment() && !($tokens[$i]->isWhitespace() && false !== strpos($tokens[$i]->getContent(), "\n"))) {
  13597. $tokens->clearAt($i);
  13598. }
  13599. }
  13600. $tokens->insertAt($classBeginIndex, new Token([
  13601. T_CONSTANT_ENCAPSED_STRING,
  13602. "'".$this->makeClassFQN($classImport, $classString)."'",
  13603. ]));
  13604. }
  13605. private function makeClassFQN($classImport, $classString)
  13606. {
  13607. if (false === $classImport) {
  13608. return $classString;
  13609. }
  13610. $classStringArray = explode('\\', $classString);
  13611. $classStringLength = count($classStringArray);
  13612. $classImportArray = explode('\\', $classImport);
  13613. $classImportLength = count($classImportArray);
  13614. if (1 === $classStringLength) {
  13615. return $classImport;
  13616. }
  13617. return implode('\\', array_merge(
  13618. array_slice($classImportArray, 0, $classImportLength - $classStringLength + 1),
  13619. $classStringArray
  13620. ));
  13621. }
  13622. }
  13623. <?php
  13624. namespace PhpCsFixer\Fixer\LanguageConstruct;
  13625. use PhpCsFixer\AbstractFixer;
  13626. use PhpCsFixer\FixerDefinition\CodeSample;
  13627. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13628. use PhpCsFixer\Tokenizer\Token;
  13629. use PhpCsFixer\Tokenizer\Tokens;
  13630. final class CombineConsecutiveIssetsFixer extends AbstractFixer
  13631. {
  13632. public function getDefinition()
  13633. {
  13634. return new FixerDefinition(
  13635. 'Using `isset($var) &&` multiple times should be done in one call.',
  13636. [new CodeSample("<?php\n\$a = isset(\$a) && isset(\$b);\n")]
  13637. );
  13638. }
  13639. public function getPriority()
  13640. {
  13641. return 3;
  13642. }
  13643. public function isCandidate(Tokens $tokens)
  13644. {
  13645. return $tokens->isAllTokenKindsFound([T_ISSET, T_BOOLEAN_AND]);
  13646. }
  13647. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13648. {
  13649. $tokenCount = $tokens->count();
  13650. for ($index = 1; $index < $tokenCount; ++$index) {
  13651. if (!$tokens[$index]->isGivenKind(T_ISSET) || $tokens[$tokens->getPrevMeaningfulToken($index)]->equals('!')) {
  13652. continue;
  13653. }
  13654. $issetInfo = $this->getIssetInfo($tokens, $index);
  13655. $issetCloseBraceIndex = end($issetInfo);
  13656. $insertLocation = prev($issetInfo) + 1;
  13657. $booleanAndTokenIndex = $tokens->getNextMeaningfulToken($issetCloseBraceIndex);
  13658. while ($tokens[$booleanAndTokenIndex]->isGivenKind(T_BOOLEAN_AND)) {
  13659. $issetIndex = $tokens->getNextMeaningfulToken($booleanAndTokenIndex);
  13660. if (!$tokens[$issetIndex]->isGivenKind(T_ISSET)) {
  13661. $index = $issetIndex;
  13662. break;
  13663. }
  13664. $nextIssetInfo = $this->getIssetInfo($tokens, $issetIndex);
  13665. $clones = $this->getTokenClones($tokens, array_slice($nextIssetInfo, 1, -1));
  13666. $this->clearTokens($tokens, array_merge($nextIssetInfo, [$issetIndex, $booleanAndTokenIndex]));
  13667. array_unshift($clones, new Token(','), new Token([T_WHITESPACE, ' ']));
  13668. $tokens->insertAt($insertLocation, $clones);
  13669. $numberOfTokensInserted = count($clones);
  13670. $tokenCount += $numberOfTokensInserted;
  13671. $issetCloseBraceIndex += $numberOfTokensInserted;
  13672. $insertLocation += $numberOfTokensInserted;
  13673. $booleanAndTokenIndex = $tokens->getNextMeaningfulToken($issetCloseBraceIndex);
  13674. }
  13675. }
  13676. }
  13677. private function clearTokens(Tokens $tokens, array $indexes)
  13678. {
  13679. foreach ($indexes as $index) {
  13680. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  13681. }
  13682. }
  13683. private function getIssetInfo(Tokens $tokens, $index)
  13684. {
  13685. $openIndex = $tokens->getNextMeaningfulToken($index);
  13686. $braceOpenCount = 1;
  13687. $meaningfulTokenIndexes = [$openIndex];
  13688. for ($i = $openIndex + 1;; ++$i) {
  13689. if ($tokens[$i]->isWhitespace() || $tokens[$i]->isComment()) {
  13690. continue;
  13691. }
  13692. $meaningfulTokenIndexes[] = $i;
  13693. if ($tokens[$i]->equals(')')) {
  13694. --$braceOpenCount;
  13695. if (0 === $braceOpenCount) {
  13696. break;
  13697. }
  13698. } elseif ($tokens[$i]->equals('(')) {
  13699. ++$braceOpenCount;
  13700. }
  13701. }
  13702. return $meaningfulTokenIndexes;
  13703. }
  13704. private function getTokenClones(Tokens $tokens, array $indexes)
  13705. {
  13706. $clones = [];
  13707. foreach ($indexes as $i) {
  13708. $clones[] = clone $tokens[$i];
  13709. }
  13710. return $clones;
  13711. }
  13712. }
  13713. <?php
  13714. namespace PhpCsFixer\Fixer\LanguageConstruct;
  13715. use PhpCsFixer\AbstractFixer;
  13716. use PhpCsFixer\FixerDefinition\CodeSample;
  13717. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13718. use PhpCsFixer\Tokenizer\Token;
  13719. use PhpCsFixer\Tokenizer\Tokens;
  13720. final class CombineConsecutiveUnsetsFixer extends AbstractFixer
  13721. {
  13722. public function getDefinition()
  13723. {
  13724. return new FixerDefinition(
  13725. 'Calling `unset` on multiple items should be done in one call.',
  13726. [new CodeSample("<?php\nunset(\$a); unset(\$b);\n")]
  13727. );
  13728. }
  13729. public function getPriority()
  13730. {
  13731. return 24;
  13732. }
  13733. public function isCandidate(Tokens $tokens)
  13734. {
  13735. return $tokens->isTokenKindFound(T_UNSET);
  13736. }
  13737. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13738. {
  13739. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  13740. if (!$tokens[$index]->isGivenKind(T_UNSET)) {
  13741. continue;
  13742. }
  13743. $previousUnsetCall = $this->getPreviousUnsetCall($tokens, $index);
  13744. if (is_int($previousUnsetCall)) {
  13745. $index = $previousUnsetCall;
  13746. continue;
  13747. }
  13748. list($previousUnset, , $previousUnsetBraceEnd) = $previousUnsetCall;
  13749. $tokensAddCount = $this->moveTokens(
  13750. $tokens,
  13751. $nextUnsetContentStart = $tokens->getNextTokenOfKind($index, ['(']),
  13752. $nextUnsetContentEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $nextUnsetContentStart),
  13753. $previousUnsetBraceEnd - 1
  13754. );
  13755. if (!$tokens[$previousUnsetBraceEnd]->isWhitespace()) {
  13756. $tokens->insertAt($previousUnsetBraceEnd, new Token([T_WHITESPACE, ' ']));
  13757. ++$tokensAddCount;
  13758. }
  13759. $tokens->insertAt($previousUnsetBraceEnd, new Token(','));
  13760. ++$tokensAddCount;
  13761. $this->clearOffsetTokens($tokens, $tokensAddCount, [$index, $nextUnsetContentStart, $nextUnsetContentEnd]);
  13762. $nextUnsetSemicolon = $tokens->getNextMeaningfulToken($nextUnsetContentEnd);
  13763. if (null !== $nextUnsetSemicolon && $tokens[$nextUnsetSemicolon]->equals(';')) {
  13764. $tokens->clearTokenAndMergeSurroundingWhitespace($nextUnsetSemicolon);
  13765. }
  13766. $index = $previousUnset + 1;
  13767. }
  13768. }
  13769. private function clearOffsetTokens(Tokens $tokens, $offset, array $indices)
  13770. {
  13771. foreach ($indices as $index) {
  13772. $tokens->clearTokenAndMergeSurroundingWhitespace($index + $offset);
  13773. }
  13774. }
  13775. private function getPreviousUnsetCall(Tokens $tokens, $index)
  13776. {
  13777. $previousUnsetSemicolon = $tokens->getPrevMeaningfulToken($index);
  13778. if (null === $previousUnsetSemicolon) {
  13779. return $index;
  13780. }
  13781. if (!$tokens[$previousUnsetSemicolon]->equals(';')) {
  13782. return $previousUnsetSemicolon;
  13783. }
  13784. $previousUnsetBraceEnd = $tokens->getPrevMeaningfulToken($previousUnsetSemicolon);
  13785. if (null === $previousUnsetBraceEnd) {
  13786. return $index;
  13787. }
  13788. if (!$tokens[$previousUnsetBraceEnd]->equals(')')) {
  13789. return $previousUnsetBraceEnd;
  13790. }
  13791. $previousUnsetBraceStart = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $previousUnsetBraceEnd, false);
  13792. $previousUnset = $tokens->getPrevMeaningfulToken($previousUnsetBraceStart);
  13793. if (null === $previousUnset) {
  13794. return $index;
  13795. }
  13796. if (!$tokens[$previousUnset]->isGivenKind(T_UNSET)) {
  13797. return $previousUnset;
  13798. }
  13799. return [
  13800. $previousUnset,
  13801. $previousUnsetBraceStart,
  13802. $previousUnsetBraceEnd,
  13803. $previousUnsetSemicolon,
  13804. ];
  13805. }
  13806. private function moveTokens(Tokens $tokens, $start, $end, $to)
  13807. {
  13808. $added = 0;
  13809. for ($i = $start + 1; $i < $end; $i += 2) {
  13810. if ($tokens[$i]->isWhitespace() && $tokens[$to + 1]->isWhitespace()) {
  13811. $tokens[$to + 1] = new Token([T_WHITESPACE, $tokens[$to + 1]->getContent().$tokens[$i]->getContent()]);
  13812. } else {
  13813. $tokens->insertAt(++$to, clone $tokens[$i]);
  13814. ++$end;
  13815. ++$added;
  13816. }
  13817. $tokens->clearAt($i + 1);
  13818. }
  13819. return $added;
  13820. }
  13821. }
  13822. <?php
  13823. namespace PhpCsFixer\Fixer\LanguageConstruct;
  13824. use PhpCsFixer\AbstractFixer;
  13825. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  13826. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  13827. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  13828. use PhpCsFixer\FixerDefinition\CodeSample;
  13829. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13830. use PhpCsFixer\Tokenizer\Token;
  13831. use PhpCsFixer\Tokenizer\Tokens;
  13832. final class DeclareEqualNormalizeFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  13833. {
  13834. private $callback;
  13835. public function configure(array $configuration = null)
  13836. {
  13837. parent::configure($configuration);
  13838. $this->callback = 'none' === $this->configuration['space'] ? 'removeWhitespaceAroundToken' : 'ensureWhitespaceAroundToken';
  13839. }
  13840. public function getDefinition()
  13841. {
  13842. return new FixerDefinition(
  13843. 'Equal sign in declare statement should be surrounded by spaces or not following configuration.',
  13844. [
  13845. new CodeSample("<?php\ndeclare(ticks = 1);\n"),
  13846. new CodeSample("<?php\ndeclare(ticks=1);\n", ['space' => 'single']),
  13847. ]
  13848. );
  13849. }
  13850. public function isCandidate(Tokens $tokens)
  13851. {
  13852. return $tokens->isTokenKindFound(T_DECLARE);
  13853. }
  13854. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13855. {
  13856. $callback = $this->callback;
  13857. for ($index = 0, $count = $tokens->count(); $index < $count - 6; ++$index) {
  13858. if (!$tokens[$index]->isGivenKind(T_DECLARE)) {
  13859. continue;
  13860. }
  13861. while (!$tokens[++$index]->equals('='));
  13862. $this->{$callback}($tokens, $index);
  13863. }
  13864. }
  13865. protected function createConfigurationDefinition()
  13866. {
  13867. return new FixerConfigurationResolver([
  13868. (new FixerOptionBuilder('space', 'Spacing to apply around the equal sign.'))
  13869. ->setAllowedValues(['single', 'none'])
  13870. ->setDefault('none')
  13871. ->getOption(),
  13872. ]);
  13873. }
  13874. private function ensureWhitespaceAroundToken(Tokens $tokens, $index)
  13875. {
  13876. if ($tokens[$index + 1]->isWhitespace()) {
  13877. if (' ' !== $tokens[$index + 1]->getContent()) {
  13878. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  13879. }
  13880. } else {
  13881. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  13882. }
  13883. if ($tokens[$index - 1]->isWhitespace()) {
  13884. if (' ' !== $tokens[$index - 1]->getContent() && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
  13885. $tokens[$index - 1] = new Token([T_WHITESPACE, ' ']);
  13886. }
  13887. } else {
  13888. $tokens->insertAt($index, new Token([T_WHITESPACE, ' ']));
  13889. }
  13890. }
  13891. private function removeWhitespaceAroundToken(Tokens $tokens, $index)
  13892. {
  13893. if (!$tokens[$tokens->getPrevNonWhitespace($index)]->isComment()) {
  13894. $tokens->removeLeadingWhitespace($index);
  13895. }
  13896. $tokens->removeTrailingWhitespace($index);
  13897. }
  13898. }
  13899. <?php
  13900. namespace PhpCsFixer\Fixer\LanguageConstruct;
  13901. use PhpCsFixer\AbstractFunctionReferenceFixer;
  13902. use PhpCsFixer\FixerDefinition\CodeSample;
  13903. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13904. use PhpCsFixer\Tokenizer\Token;
  13905. use PhpCsFixer\Tokenizer\Tokens;
  13906. final class DirConstantFixer extends AbstractFunctionReferenceFixer
  13907. {
  13908. public function getDefinition()
  13909. {
  13910. return new FixerDefinition(
  13911. 'Replaces `dirname(__FILE__)` expression with equivalent `__DIR__` constant.',
  13912. [new CodeSample("<?php\n\$a = dirname(__FILE__);\n")],
  13913. null,
  13914. 'Risky when the function `dirname` is overridden.'
  13915. );
  13916. }
  13917. public function isCandidate(Tokens $tokens)
  13918. {
  13919. return $tokens->isTokenKindFound(T_FILE);
  13920. }
  13921. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13922. {
  13923. $currIndex = 0;
  13924. while (null !== $currIndex) {
  13925. $boundaries = $this->find('dirname', $tokens, $currIndex, $tokens->count() - 1);
  13926. if (null === $boundaries) {
  13927. return;
  13928. }
  13929. list($functionNameIndex, $openParenthesis, $closeParenthesis) = $boundaries;
  13930. $currIndex = $openParenthesis;
  13931. $fileCandidateRightIndex = $tokens->getPrevMeaningfulToken($closeParenthesis);
  13932. $fileCandidateRight = $tokens[$fileCandidateRightIndex];
  13933. $fileCandidateLeftIndex = $tokens->getNextMeaningfulToken($openParenthesis);
  13934. $fileCandidateLeft = $tokens[$fileCandidateLeftIndex];
  13935. if (!$fileCandidateRight->isGivenKind([T_FILE]) || !$fileCandidateLeft->isGivenKind([T_FILE])) {
  13936. continue;
  13937. }
  13938. $namespaceCandidateIndex = $tokens->getPrevMeaningfulToken($functionNameIndex);
  13939. $namespaceCandidate = $tokens[$namespaceCandidateIndex];
  13940. if ($namespaceCandidate->isGivenKind(T_NS_SEPARATOR)) {
  13941. $tokens->removeTrailingWhitespace($namespaceCandidateIndex);
  13942. $tokens->clearAt($namespaceCandidateIndex);
  13943. }
  13944. if (!$tokens[$tokens->getNextNonWhitespace($closeParenthesis)]->isComment()) {
  13945. $tokens->removeLeadingWhitespace($closeParenthesis);
  13946. }
  13947. $tokens->clearAt($closeParenthesis);
  13948. if (!$tokens[$tokens->getNextNonWhitespace($openParenthesis)]->isComment()) {
  13949. $tokens->removeLeadingWhitespace($openParenthesis);
  13950. }
  13951. $tokens->removeTrailingWhitespace($openParenthesis);
  13952. $tokens->clearAt($openParenthesis);
  13953. $tokens[$fileCandidateLeftIndex] = new Token([T_DIR, '__DIR__']);
  13954. $tokens->clearAt($functionNameIndex);
  13955. }
  13956. }
  13957. }
  13958. <?php
  13959. namespace PhpCsFixer\Fixer\LanguageConstruct;
  13960. use PhpCsFixer\AbstractFixer;
  13961. use PhpCsFixer\FixerDefinition\FixerDefinition;
  13962. use PhpCsFixer\FixerDefinition\VersionSpecification;
  13963. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  13964. use PhpCsFixer\Tokenizer\CT;
  13965. use PhpCsFixer\Tokenizer\Token;
  13966. use PhpCsFixer\Tokenizer\Tokens;
  13967. final class ExplicitIndirectVariableFixer extends AbstractFixer
  13968. {
  13969. public function getDefinition()
  13970. {
  13971. return new FixerDefinition(
  13972. 'Add curly braces to indirect variables to make them clear to understand. Requires PHP >= 7.0.',
  13973. [
  13974. new VersionSpecificCodeSample(
  13975. <<<'EOT'
  13976. <?php
  13977. echo $$foo;
  13978. echo $$foo['bar'];
  13979. echo $foo->$bar['baz'];
  13980. echo $foo->$callback($baz);
  13981. EOT
  13982. ,
  13983. new VersionSpecification(70000)
  13984. ),
  13985. ]
  13986. );
  13987. }
  13988. public function isCandidate(Tokens $tokens)
  13989. {
  13990. return PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_VARIABLE);
  13991. }
  13992. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  13993. {
  13994. for ($index = $tokens->count() - 1; $index > 1; --$index) {
  13995. $token = $tokens[$index];
  13996. if (!$token->isGivenKind(T_VARIABLE)) {
  13997. continue;
  13998. }
  13999. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  14000. $prevToken = $tokens[$prevIndex];
  14001. if (!$prevToken->equals('$') && !$prevToken->isGivenKind(T_OBJECT_OPERATOR)) {
  14002. continue;
  14003. }
  14004. $openingBrace = CT::T_DYNAMIC_VAR_BRACE_OPEN;
  14005. $closingBrace = CT::T_DYNAMIC_VAR_BRACE_CLOSE;
  14006. if ($prevToken->isGivenKind(T_OBJECT_OPERATOR)) {
  14007. $openingBrace = CT::T_DYNAMIC_PROP_BRACE_OPEN;
  14008. $closingBrace = CT::T_DYNAMIC_PROP_BRACE_CLOSE;
  14009. }
  14010. $tokens->overrideRange($index, $index, [
  14011. new Token([$openingBrace, '{']),
  14012. new Token([T_VARIABLE, $token->getContent()]),
  14013. new Token([$closingBrace, '}']),
  14014. ]);
  14015. }
  14016. }
  14017. }
  14018. <?php
  14019. namespace PhpCsFixer\Fixer\LanguageConstruct;
  14020. use PhpCsFixer\AbstractFixer;
  14021. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  14022. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  14023. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  14024. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  14025. use PhpCsFixer\FixerDefinition\CodeSample;
  14026. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14027. use PhpCsFixer\Tokenizer\Token;
  14028. use PhpCsFixer\Tokenizer\Tokens;
  14029. final class FunctionToConstantFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  14030. {
  14031. private static $availableFunctions;
  14032. private $functionsFixMap;
  14033. public function __construct()
  14034. {
  14035. if (null === self::$availableFunctions) {
  14036. self::$availableFunctions = [
  14037. 'get_class' => new Token([T_CLASS_C, '__CLASS__']),
  14038. 'php_sapi_name' => new Token([T_STRING, 'PHP_SAPI']),
  14039. 'phpversion' => new Token([T_STRING, 'PHP_VERSION']),
  14040. 'pi' => new Token([T_STRING, 'M_PI']),
  14041. ];
  14042. }
  14043. parent::__construct();
  14044. }
  14045. public function configure(array $configuration = null)
  14046. {
  14047. parent::configure($configuration);
  14048. $this->functionsFixMap = [];
  14049. foreach ($this->configuration['functions'] as $key) {
  14050. $this->functionsFixMap[$key] = self::$availableFunctions[$key];
  14051. }
  14052. }
  14053. public function getDefinition()
  14054. {
  14055. return new FixerDefinition(
  14056. 'Replace core functions calls returning constants with the constants.',
  14057. [
  14058. new CodeSample("<?php\necho phpversion();\necho pi();\necho php_sapi_name();\n"),
  14059. new CodeSample("<?php\necho phpversion();\necho pi();\n", ['functions' => ['phpversion']]),
  14060. ],
  14061. null,
  14062. 'Risky when any of the configured functions to replace are overridden.'
  14063. );
  14064. }
  14065. public function getPriority()
  14066. {
  14067. return 1;
  14068. }
  14069. public function isCandidate(Tokens $tokens)
  14070. {
  14071. return $tokens->isTokenKindFound(T_STRING);
  14072. }
  14073. public function isRisky()
  14074. {
  14075. return true;
  14076. }
  14077. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14078. {
  14079. for ($index = $tokens->count() - 4; $index > 0; --$index) {
  14080. $candidate = $this->getReplaceCandidate($tokens, $index);
  14081. if (null === $candidate) {
  14082. continue;
  14083. }
  14084. $this->fixFunctionCallToConstant(
  14085. $tokens,
  14086. $index,
  14087. $candidate[0],
  14088. $candidate[1],
  14089. $candidate[2]
  14090. );
  14091. }
  14092. }
  14093. protected function createConfigurationDefinition()
  14094. {
  14095. $functionNames = array_keys(self::$availableFunctions);
  14096. return new FixerConfigurationResolver([
  14097. (new FixerOptionBuilder('functions', 'List of function names to fix.'))
  14098. ->setAllowedTypes(['array'])
  14099. ->setAllowedValues([
  14100. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf($functionNames),
  14101. ])
  14102. ->setDefault($functionNames)
  14103. ->getOption(),
  14104. ]);
  14105. }
  14106. private function fixFunctionCallToConstant(Tokens $tokens, $index, $braceOpenIndex, $braceCloseIndex, Token $replacementConst)
  14107. {
  14108. $tokens->clearTokenAndMergeSurroundingWhitespace($braceCloseIndex);
  14109. $tokens->clearTokenAndMergeSurroundingWhitespace($braceOpenIndex);
  14110. if ($replacementConst->isMagicConstant()) {
  14111. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  14112. $prevToken = $tokens[$prevIndex];
  14113. if ($prevToken->isGivenKind(T_NS_SEPARATOR)) {
  14114. $tokens->clearAt($prevIndex);
  14115. }
  14116. }
  14117. $tokens->clearAt($index);
  14118. $tokens->insertAt($index, $replacementConst);
  14119. }
  14120. private function getReplaceCandidate(Tokens $tokens, $index)
  14121. {
  14122. if (!$tokens[$index]->isGivenKind(T_STRING)) {
  14123. return null;
  14124. }
  14125. $braceOpenIndex = $tokens->getNextMeaningfulToken($index);
  14126. if (!$tokens[$braceOpenIndex]->equals('(')) {
  14127. return null;
  14128. }
  14129. $braceCloseIndex = $tokens->getNextMeaningfulToken($braceOpenIndex);
  14130. if (!$tokens[$braceCloseIndex]->equals(')')) {
  14131. return null;
  14132. }
  14133. $functionNamePrefix = $tokens->getPrevMeaningfulToken($index);
  14134. if ($tokens[$functionNamePrefix]->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION])) {
  14135. return null;
  14136. }
  14137. if ($tokens[$functionNamePrefix]->isGivenKind(T_NS_SEPARATOR)) {
  14138. $prevIndex = $tokens->getPrevMeaningfulToken($functionNamePrefix);
  14139. if ($tokens[$prevIndex]->isGivenKind([T_STRING, T_NEW])) {
  14140. return null;
  14141. }
  14142. }
  14143. $lowerContent = strtolower($tokens[$index]->getContent());
  14144. if (!array_key_exists($lowerContent, $this->functionsFixMap)) {
  14145. return null;
  14146. }
  14147. return [
  14148. $braceOpenIndex,
  14149. $braceCloseIndex,
  14150. clone $this->functionsFixMap[$lowerContent],
  14151. ];
  14152. }
  14153. }
  14154. <?php
  14155. namespace PhpCsFixer\Fixer\LanguageConstruct;
  14156. use PhpCsFixer\AbstractFixer;
  14157. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  14158. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  14159. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  14160. use PhpCsFixer\FixerDefinition\CodeSample;
  14161. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14162. use PhpCsFixer\Tokenizer\CT;
  14163. use PhpCsFixer\Tokenizer\Token;
  14164. use PhpCsFixer\Tokenizer\Tokens;
  14165. final class IsNullFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  14166. {
  14167. public function getDefinition()
  14168. {
  14169. return new FixerDefinition(
  14170. 'Replaces `is_null($var)` expression with `null === $var`.',
  14171. [
  14172. new CodeSample("<?php\n\$a = is_null(\$b);\n"),
  14173. ],
  14174. null,
  14175. 'Risky when the function `is_null` is overridden.'
  14176. );
  14177. }
  14178. public function getPriority()
  14179. {
  14180. return 1;
  14181. }
  14182. public function isCandidate(Tokens $tokens)
  14183. {
  14184. return $tokens->isTokenKindFound(T_STRING);
  14185. }
  14186. public function isRisky()
  14187. {
  14188. return true;
  14189. }
  14190. public function configure(array $configuration = null)
  14191. {
  14192. if (null !== $configuration && array_key_exists('use_yoda_style', $configuration)) {
  14193. @trigger_error(
  14194. 'Using "use_yoda_style" is deprecated and will be removed in 3.0. Use "yoda_style" fixer instead.',
  14195. E_USER_DEPRECATED
  14196. );
  14197. }
  14198. parent::configure($configuration);
  14199. }
  14200. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14201. {
  14202. static $sequenceNeeded = [[T_STRING, 'is_null'], '('];
  14203. $currIndex = 0;
  14204. while (null !== $currIndex) {
  14205. $matches = $tokens->findSequence($sequenceNeeded, $currIndex, $tokens->count() - 1, false);
  14206. if (null === $matches) {
  14207. break;
  14208. }
  14209. $matches = array_keys($matches);
  14210. list($isNullIndex, $currIndex) = $matches;
  14211. $next = $tokens->getNextMeaningfulToken($currIndex);
  14212. if ($tokens[$next]->equals(')')) {
  14213. continue;
  14214. }
  14215. $inversionCandidateIndex = $prevTokenIndex = $tokens->getPrevMeaningfulToken($matches[0]);
  14216. $prevToken = $tokens[$prevTokenIndex];
  14217. if ($prevToken->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION])) {
  14218. continue;
  14219. }
  14220. if ($prevToken->isGivenKind(T_NS_SEPARATOR)) {
  14221. $inversionCandidateIndex = $twicePrevTokenIndex = $tokens->getPrevMeaningfulToken($prevTokenIndex);
  14222. $twicePrevToken = $tokens[$twicePrevTokenIndex];
  14223. if ($twicePrevToken->isGivenKind([T_DOUBLE_COLON, T_NEW, T_OBJECT_OPERATOR, T_FUNCTION, T_STRING, CT::T_NAMESPACE_OPERATOR])) {
  14224. continue;
  14225. }
  14226. $tokens->removeTrailingWhitespace($prevTokenIndex);
  14227. $tokens->clearAt($prevTokenIndex);
  14228. }
  14229. $isInvertedNullCheck = false;
  14230. if ($tokens[$inversionCandidateIndex]->equals('!')) {
  14231. $isInvertedNullCheck = true;
  14232. $tokens->removeTrailingWhitespace($inversionCandidateIndex);
  14233. $tokens->clearAt($inversionCandidateIndex);
  14234. }
  14235. $referenceEnd = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $matches[1]);
  14236. $isContainingDangerousConstructs = false;
  14237. for ($paramTokenIndex = $matches[1]; $paramTokenIndex <= $referenceEnd; ++$paramTokenIndex) {
  14238. if (in_array($tokens[$paramTokenIndex]->getContent(), ['?', '?:', '='], true)) {
  14239. $isContainingDangerousConstructs = true;
  14240. break;
  14241. }
  14242. }
  14243. $parentLeftToken = $tokens[$tokens->getPrevMeaningfulToken($isNullIndex)];
  14244. $parentRightToken = $tokens[$tokens->getNextMeaningfulToken($referenceEnd)];
  14245. $parentOperations = [T_IS_EQUAL, T_IS_NOT_EQUAL, T_IS_IDENTICAL, T_IS_NOT_IDENTICAL];
  14246. $wrapIntoParentheses = $parentLeftToken->isGivenKind($parentOperations) || $parentRightToken->isGivenKind($parentOperations);
  14247. if (!$isContainingDangerousConstructs) {
  14248. if (!$wrapIntoParentheses) {
  14249. $tokens->removeLeadingWhitespace($referenceEnd);
  14250. $tokens->clearAt($referenceEnd);
  14251. }
  14252. $tokens->removeLeadingWhitespace($matches[1]);
  14253. $tokens->removeTrailingWhitespace($matches[1]);
  14254. $tokens->clearAt($matches[1]);
  14255. }
  14256. $replacement = [
  14257. new Token([T_STRING, 'null']),
  14258. new Token([T_WHITESPACE, ' ']),
  14259. new Token($isInvertedNullCheck ? [T_IS_NOT_IDENTICAL, '!=='] : [T_IS_IDENTICAL, '===']),
  14260. new Token([T_WHITESPACE, ' ']),
  14261. ];
  14262. if (true === $this->configuration['use_yoda_style']) {
  14263. if ($wrapIntoParentheses) {
  14264. array_unshift($replacement, new Token('('));
  14265. }
  14266. $tokens->overrideRange($isNullIndex, $isNullIndex, $replacement);
  14267. } else {
  14268. $replacement = array_reverse($replacement);
  14269. if ($isContainingDangerousConstructs) {
  14270. array_unshift($replacement, new Token(')'));
  14271. }
  14272. if ($wrapIntoParentheses) {
  14273. $replacement[] = new Token(')');
  14274. $tokens[$isNullIndex] = new Token('(');
  14275. } else {
  14276. $tokens->clearAt($isNullIndex);
  14277. }
  14278. $tokens->overrideRange($referenceEnd, $referenceEnd, $replacement);
  14279. }
  14280. $currIndex = $isNullIndex;
  14281. }
  14282. }
  14283. protected function createConfigurationDefinition()
  14284. {
  14285. return new FixerConfigurationResolver([
  14286. (new FixerOptionBuilder('use_yoda_style', '(deprecated) Whether Yoda style conditions should be used.'))
  14287. ->setAllowedTypes(['bool'])
  14288. ->setDefault(true)
  14289. ->getOption(),
  14290. ]);
  14291. }
  14292. }
  14293. <?php
  14294. namespace PhpCsFixer\Fixer\LanguageConstruct;
  14295. use PhpCsFixer\AbstractFixer;
  14296. use PhpCsFixer\FixerDefinition\CodeSample;
  14297. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14298. use PhpCsFixer\Tokenizer\Token;
  14299. use PhpCsFixer\Tokenizer\Tokens;
  14300. final class SilencedDeprecationErrorFixer extends AbstractFixer
  14301. {
  14302. public function getDefinition()
  14303. {
  14304. return new FixerDefinition(
  14305. 'Ensures deprecation notices are silenced.',
  14306. [new CodeSample("<?php\ntrigger_error('Warning.', E_USER_DEPRECATED);\n")],
  14307. null,
  14308. 'Silencing of deprecation errors might cause changes to code behaviour.'
  14309. );
  14310. }
  14311. public function isCandidate(Tokens $tokens)
  14312. {
  14313. return $tokens->isTokenKindFound(T_STRING);
  14314. }
  14315. public function isRisky()
  14316. {
  14317. return true;
  14318. }
  14319. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14320. {
  14321. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  14322. $token = $tokens[$index];
  14323. if (!$token->equals([T_STRING, 'trigger_error'], false)) {
  14324. continue;
  14325. }
  14326. $start = $index;
  14327. $prev = $tokens->getPrevMeaningfulToken($start);
  14328. if ($tokens[$prev]->isGivenKind(T_NS_SEPARATOR)) {
  14329. $start = $prev;
  14330. $prev = $tokens->getPrevMeaningfulToken($start);
  14331. }
  14332. if ($tokens[$prev]->isGivenKind(T_STRING) || $tokens[$prev]->equals('@')) {
  14333. continue;
  14334. }
  14335. $end = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextTokenOfKind($index, [T_STRING, '(']));
  14336. if ($tokens[$tokens->getPrevMeaningfulToken($end)]->equals([T_STRING, 'E_USER_DEPRECATED'])) {
  14337. $tokens->insertAt($start, new Token('@'));
  14338. }
  14339. }
  14340. }
  14341. }
  14342. <?php
  14343. namespace PhpCsFixer\Fixer\ListNotation;
  14344. use PhpCsFixer\AbstractFixer;
  14345. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  14346. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  14347. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  14348. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  14349. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14350. use PhpCsFixer\FixerDefinition\VersionSpecification;
  14351. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  14352. use PhpCsFixer\Tokenizer\CT;
  14353. use PhpCsFixer\Tokenizer\Token;
  14354. use PhpCsFixer\Tokenizer\Tokens;
  14355. final class ListSyntaxFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  14356. {
  14357. private $candidateTokenKind;
  14358. public function configure(array $configuration = null)
  14359. {
  14360. parent::configure($configuration);
  14361. $this->candidateTokenKind = 'long' === $this->configuration['syntax'] ? CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN : T_LIST;
  14362. }
  14363. public function getDefinition()
  14364. {
  14365. return new FixerDefinition(
  14366. 'List (`array` destructuring) assignment should be declared using the configured syntax. Requires PHP >= 7.1.',
  14367. [
  14368. new VersionSpecificCodeSample(
  14369. "<?php\n[\$sample] = \$array;\n",
  14370. new VersionSpecification(70100)
  14371. ),
  14372. new VersionSpecificCodeSample(
  14373. "<?php\nlist(\$sample) = \$array;\n",
  14374. new VersionSpecification(70100),
  14375. ['syntax' => 'short']
  14376. ),
  14377. ]
  14378. );
  14379. }
  14380. public function getPriority()
  14381. {
  14382. return 1;
  14383. }
  14384. public function isCandidate(Tokens $tokens)
  14385. {
  14386. return PHP_VERSION_ID >= 70100 && $tokens->isTokenKindFound($this->candidateTokenKind);
  14387. }
  14388. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14389. {
  14390. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  14391. if ($tokens[$index]->isGivenKind($this->candidateTokenKind)) {
  14392. if (T_LIST === $this->candidateTokenKind) {
  14393. $this->fixToShortSyntax($tokens, $index);
  14394. } else {
  14395. $this->fixToLongSyntax($tokens, $index);
  14396. }
  14397. }
  14398. }
  14399. }
  14400. protected function createConfigurationDefinition()
  14401. {
  14402. return new FixerConfigurationResolver([
  14403. (new FixerOptionBuilder('syntax', 'Whether to use the `long` or `short` `list` syntax.'))
  14404. ->setAllowedValues(['long', 'short'])
  14405. ->setDefault('long')
  14406. ->getOption(),
  14407. ]);
  14408. }
  14409. private function fixToLongSyntax(Tokens $tokens, $index)
  14410. {
  14411. static $typesOfInterest = [
  14412. [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE],
  14413. [CT::T_ARRAY_SQUARE_BRACE_OPEN],
  14414. ];
  14415. $closeIndex = $tokens->getNextTokenOfKind($index, $typesOfInterest);
  14416. if (!$tokens[$closeIndex]->isGivenKind(CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE)) {
  14417. return;
  14418. }
  14419. $tokens[$index] = new Token('(');
  14420. $tokens[$closeIndex] = new Token(')');
  14421. $tokens->insertAt($index, new Token([T_LIST, 'list']));
  14422. }
  14423. private function fixToShortSyntax(Tokens $tokens, $index)
  14424. {
  14425. $openIndex = $tokens->getNextTokenOfKind($index, ['(']);
  14426. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
  14427. $tokens[$openIndex] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '[']);
  14428. $tokens[$closeIndex] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']']);
  14429. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  14430. }
  14431. }
  14432. <?php
  14433. namespace PhpCsFixer\Fixer\NamespaceNotation;
  14434. use PhpCsFixer\AbstractFixer;
  14435. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  14436. use PhpCsFixer\FixerDefinition\CodeSample;
  14437. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14438. use PhpCsFixer\Tokenizer\Token;
  14439. use PhpCsFixer\Tokenizer\Tokens;
  14440. final class BlankLineAfterNamespaceFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  14441. {
  14442. public function getDefinition()
  14443. {
  14444. return new FixerDefinition(
  14445. 'There MUST be one blank line after the namespace declaration.',
  14446. [
  14447. new CodeSample("<?php\nnamespace Sample\\Sample;\n\n\n\$a;\n"),
  14448. new CodeSample("<?php\nnamespace Sample\\Sample;\nClass Test{}\n"),
  14449. ]
  14450. );
  14451. }
  14452. public function getPriority()
  14453. {
  14454. return -20;
  14455. }
  14456. public function isCandidate(Tokens $tokens)
  14457. {
  14458. return $tokens->isTokenKindFound(T_NAMESPACE);
  14459. }
  14460. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14461. {
  14462. $ending = $this->whitespacesConfig->getLineEnding();
  14463. $lastIndex = $tokens->count() - 1;
  14464. for ($index = $lastIndex; $index >= 0; --$index) {
  14465. $token = $tokens[$index];
  14466. if (!$token->isGivenKind(T_NAMESPACE)) {
  14467. continue;
  14468. }
  14469. $semicolonIndex = $tokens->getNextTokenOfKind($index, [';', '{', [T_CLOSE_TAG]]);
  14470. $semicolonToken = $tokens[$semicolonIndex];
  14471. if (!isset($tokens[$semicolonIndex + 1]) || !$semicolonToken->equals(';')) {
  14472. continue;
  14473. }
  14474. $nextIndex = $semicolonIndex + 1;
  14475. $nextToken = $tokens[$nextIndex];
  14476. if (!$nextToken->isWhitespace()) {
  14477. $tokens->insertAt($semicolonIndex + 1, new Token([T_WHITESPACE, $ending.$ending]));
  14478. } else {
  14479. $tokens[$nextIndex] = new Token([
  14480. T_WHITESPACE,
  14481. ($nextIndex === $lastIndex ? $ending : $ending.$ending).ltrim($nextToken->getContent()),
  14482. ]);
  14483. }
  14484. }
  14485. }
  14486. }
  14487. <?php
  14488. namespace PhpCsFixer\Fixer\NamespaceNotation;
  14489. use PhpCsFixer\AbstractLinesBeforeNamespaceFixer;
  14490. use PhpCsFixer\FixerDefinition\CodeSample;
  14491. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14492. use PhpCsFixer\Tokenizer\Tokens;
  14493. final class NoBlankLinesBeforeNamespaceFixer extends AbstractLinesBeforeNamespaceFixer
  14494. {
  14495. public function isCandidate(Tokens $tokens)
  14496. {
  14497. return $tokens->isTokenKindFound(T_NAMESPACE);
  14498. }
  14499. public function getDefinition()
  14500. {
  14501. return new FixerDefinition(
  14502. 'There should be no blank lines before a namespace declaration.',
  14503. [
  14504. new CodeSample(
  14505. "<?php\n\n\n\nnamespace Example;\n"
  14506. ),
  14507. ]
  14508. );
  14509. }
  14510. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14511. {
  14512. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  14513. $token = $tokens[$index];
  14514. if (!$token->isGivenKind(T_NAMESPACE)) {
  14515. continue;
  14516. }
  14517. $this->fixLinesBeforeNamespace($tokens, $index, 0, 1);
  14518. }
  14519. }
  14520. }
  14521. <?php
  14522. namespace PhpCsFixer\Fixer\NamespaceNotation;
  14523. use PhpCsFixer\AbstractFixer;
  14524. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  14525. use PhpCsFixer\FixerDefinition\CodeSample;
  14526. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14527. use PhpCsFixer\Tokenizer\Token;
  14528. use PhpCsFixer\Tokenizer\Tokens;
  14529. final class NoLeadingNamespaceWhitespaceFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  14530. {
  14531. public function isCandidate(Tokens $tokens)
  14532. {
  14533. return $tokens->isTokenKindFound(T_NAMESPACE);
  14534. }
  14535. public function getDefinition()
  14536. {
  14537. return new FixerDefinition(
  14538. 'The namespace declaration line shouldn\'t contain leading whitespace.',
  14539. [
  14540. new CodeSample(
  14541. '<?php
  14542. namespace Test8a;
  14543. namespace Test8b;
  14544. '
  14545. ),
  14546. ]
  14547. );
  14548. }
  14549. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14550. {
  14551. for ($index = count($tokens) - 1; 0 <= $index; --$index) {
  14552. $token = $tokens[$index];
  14553. if (!$token->isGivenKind(T_NAMESPACE)) {
  14554. continue;
  14555. }
  14556. $beforeNamespaceIndex = $index - 1;
  14557. $beforeNamespace = $tokens[$beforeNamespaceIndex];
  14558. if (!$beforeNamespace->isWhitespace()) {
  14559. if (!self::endsWithWhitespace($beforeNamespace->getContent())) {
  14560. $tokens->insertAt($index, new Token([T_WHITESPACE, $this->whitespacesConfig->getLineEnding()]));
  14561. }
  14562. continue;
  14563. }
  14564. $lastNewline = strrpos($beforeNamespace->getContent(), "\n");
  14565. if (false === $lastNewline) {
  14566. $beforeBeforeNamespace = $tokens[$index - 2];
  14567. if (self::endsWithWhitespace($beforeBeforeNamespace->getContent())) {
  14568. $tokens->clearAt($beforeNamespaceIndex);
  14569. } else {
  14570. $tokens[$beforeNamespaceIndex] = new Token([T_WHITESPACE, ' ']);
  14571. }
  14572. } else {
  14573. $tokens[$beforeNamespaceIndex] = new Token([T_WHITESPACE, substr($beforeNamespace->getContent(), 0, $lastNewline + 1)]);
  14574. }
  14575. }
  14576. }
  14577. private static function endsWithWhitespace($str)
  14578. {
  14579. if ('' === $str) {
  14580. return false;
  14581. }
  14582. return '' === trim(substr($str, -1));
  14583. }
  14584. }
  14585. <?php
  14586. namespace PhpCsFixer\Fixer\NamespaceNotation;
  14587. use PhpCsFixer\AbstractLinesBeforeNamespaceFixer;
  14588. use PhpCsFixer\FixerDefinition\CodeSample;
  14589. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14590. use PhpCsFixer\Tokenizer\Tokens;
  14591. final class SingleBlankLineBeforeNamespaceFixer extends AbstractLinesBeforeNamespaceFixer
  14592. {
  14593. public function getDefinition()
  14594. {
  14595. return new FixerDefinition(
  14596. 'There should be exactly one blank line before a namespace declaration.',
  14597. [
  14598. new CodeSample("<?php namespace A {}\n"),
  14599. new CodeSample("<?php\n\n\nnamespace A{}\n"),
  14600. ]
  14601. );
  14602. }
  14603. public function isCandidate(Tokens $tokens)
  14604. {
  14605. return $tokens->isTokenKindFound(T_NAMESPACE);
  14606. }
  14607. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14608. {
  14609. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  14610. $token = $tokens[$index];
  14611. if ($token->isGivenKind(T_NAMESPACE)) {
  14612. $this->fixLinesBeforeNamespace($tokens, $index, 2, 2);
  14613. }
  14614. }
  14615. }
  14616. }
  14617. <?php
  14618. namespace PhpCsFixer\Fixer\Naming;
  14619. use PhpCsFixer\AbstractFixer;
  14620. use PhpCsFixer\FixerDefinition\CodeSample;
  14621. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14622. use PhpCsFixer\Tokenizer\Token;
  14623. use PhpCsFixer\Tokenizer\Tokens;
  14624. final class NoHomoglyphNamesFixer extends AbstractFixer
  14625. {
  14626. private static $replacements = [
  14627. 'O' => '0',
  14628. '�' => '0',
  14629. 'I' => '1',
  14630. '1' => '1',
  14631. 'ï¼’' => '2',
  14632. '3' => '3',
  14633. 'ï¼”' => '4',
  14634. '5' => '5',
  14635. 'ï¼–' => '6',
  14636. 'ï¼—' => '7',
  14637. '8' => '8',
  14638. 'ï¼™' => '9',
  14639. 'Α' => 'A',
  14640. '�' => 'A',
  14641. 'A' => 'A',
  14642. 'Ê™' => 'B',
  14643. 'Î’' => 'B',
  14644. 'Ð’' => 'B',
  14645. 'ï¼¢' => 'B',
  14646. 'Ϲ' => 'C',
  14647. 'С' => 'C',
  14648. 'â…­' => 'C',
  14649. 'ï¼£' => 'C',
  14650. 'â…®' => 'D',
  14651. 'D' => 'D',
  14652. 'Ε' => 'E',
  14653. 'Е' => 'E',
  14654. 'ï¼¥' => 'E',
  14655. 'Ϝ' => 'F',
  14656. 'F' => 'F',
  14657. 'É¢' => 'G',
  14658. 'Ԍ' => 'G',
  14659. 'ï¼§' => 'G',
  14660. 'ʜ' => 'H',
  14661. 'Η' => 'H',
  14662. '�' => 'H',
  14663. 'H' => 'H',
  14664. 'l' => 'I',
  14665. 'Ι' => 'I',
  14666. 'І' => 'I',
  14667. 'â… ' => 'I',
  14668. 'I' => 'I',
  14669. 'Ј' => 'J',
  14670. 'J' => 'J',
  14671. 'Κ' => 'K',
  14672. 'К' => 'K',
  14673. 'K' => 'K',
  14674. 'K' => 'K',
  14675. 'ÊŸ' => 'L',
  14676. 'â…¬' => 'L',
  14677. 'L' => 'L',
  14678. 'Μ' => 'M',
  14679. 'М' => 'M',
  14680. 'â…¯' => 'M',
  14681. 'ï¼­' => 'M',
  14682. 'É´' => 'N',
  14683. '�' => 'N',
  14684. 'ï¼®' => 'N',
  14685. 'Ο' => 'O',
  14686. 'О' => 'O',
  14687. 'O' => 'O',
  14688. 'Ρ' => 'P',
  14689. 'Р' => 'P',
  14690. 'ï¼°' => 'P',
  14691. 'ï¼±' => 'Q',
  14692. 'Ê€' => 'R',
  14693. 'ï¼²' => 'R',
  14694. 'Ð…' => 'S',
  14695. 'ï¼³' => 'S',
  14696. 'Τ' => 'T',
  14697. 'Т' => 'T',
  14698. 'ï¼´' => 'T',
  14699. 'ï¼µ' => 'U',
  14700. 'Ñ´' => 'V',
  14701. 'â…¤' => 'V',
  14702. 'ï¼¶' => 'V',
  14703. 'ï¼·' => 'W',
  14704. 'Χ' => 'X',
  14705. 'Ð¥' => 'X',
  14706. 'â…©' => 'X',
  14707. 'X' => 'X',
  14708. '�' => 'Y',
  14709. 'Î¥' => 'Y',
  14710. 'Ò®' => 'Y',
  14711. 'ï¼¹' => 'Y',
  14712. 'Ζ' => 'Z',
  14713. 'Z' => 'Z',
  14714. '_' => '_',
  14715. 'É‘' => 'a',
  14716. 'а' => 'a',
  14717. '�' => 'a',
  14718. 'Ь' => 'b',
  14719. 'b' => 'b',
  14720. 'ϲ' => 'c',
  14721. '�' => 'c',
  14722. 'â…½' => 'c',
  14723. 'c' => 'c',
  14724. 'Ô�' => 'd',
  14725. 'â…¾' => 'd',
  14726. 'd' => 'd',
  14727. 'е' => 'e',
  14728. 'ï½…' => 'e',
  14729. 'f' => 'f',
  14730. 'É¡' => 'g',
  14731. 'g' => 'g',
  14732. 'Ò»' => 'h',
  14733. 'h' => 'h',
  14734. 'É©' => 'i',
  14735. 'Ñ–' => 'i',
  14736. 'â…°' => 'i',
  14737. 'i' => 'i',
  14738. 'ј' => 'j',
  14739. 'j' => 'j',
  14740. 'k' => 'k',
  14741. 'â…¼' => 'l',
  14742. 'l' => 'l',
  14743. 'â…¿' => 'm',
  14744. '�' => 'm',
  14745. 'n' => 'n',
  14746. 'ο' => 'o',
  14747. 'о' => 'o',
  14748. '�' => 'o',
  14749. 'Ñ€' => 'p',
  14750. '�' => 'p',
  14751. 'q' => 'q',
  14752. 'ï½’' => 'r',
  14753. 'Ñ•' => 's',
  14754. 's' => 's',
  14755. 'ï½”' => 't',
  14756. 'u' => 'u',
  14757. 'ν' => 'v',
  14758. 'ѵ' => 'v',
  14759. 'â…´' => 'v',
  14760. 'ï½–' => 'v',
  14761. 'Ñ¡' => 'w',
  14762. 'ï½—' => 'w',
  14763. 'Ñ…' => 'x',
  14764. 'â…¹' => 'x',
  14765. 'x' => 'x',
  14766. 'у' => 'y',
  14767. 'ï½™' => 'y',
  14768. 'z' => 'z',
  14769. ];
  14770. public function getDefinition()
  14771. {
  14772. return new FixerDefinition(
  14773. 'Replace accidental usage of homoglyphs (non ascii characters) in names.',
  14774. [new CodeSample("<?php \$nаmе = 'wrong \"a\" character';\n")],
  14775. null,
  14776. 'Renames classes and cannot rename the files. You might have string references to renamed code (`$$name`).'
  14777. );
  14778. }
  14779. public function isRisky()
  14780. {
  14781. return true;
  14782. }
  14783. public function isCandidate(Tokens $tokens)
  14784. {
  14785. return $tokens->isAnyTokenKindsFound([T_VARIABLE, T_STRING]);
  14786. }
  14787. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  14788. {
  14789. foreach ($tokens as $index => $token) {
  14790. if (!$token->isGivenKind([T_VARIABLE, T_STRING])) {
  14791. continue;
  14792. }
  14793. $replaced = preg_replace_callback('/[^[:ascii:]]/u', static function ($matches) {
  14794. return isset(self::$replacements[$matches[0]])
  14795. ? self::$replacements[$matches[0]]
  14796. : $matches[0]
  14797. ;
  14798. }, $token->getContent(), -1, $count);
  14799. if ($count) {
  14800. $tokens->offsetSet($index, new Token([$token->getId(), $replaced]));
  14801. }
  14802. }
  14803. }
  14804. }
  14805. <?php
  14806. namespace PhpCsFixer\Fixer\Operator;
  14807. use PhpCsFixer\AbstractAlignFixerHelper;
  14808. use PhpCsFixer\Tokenizer\CT;
  14809. use PhpCsFixer\Tokenizer\Token;
  14810. use PhpCsFixer\Tokenizer\Tokens;
  14811. final class AlignDoubleArrowFixerHelper extends AbstractAlignFixerHelper
  14812. {
  14813. private $currentLevel = 0;
  14814. public function __construct()
  14815. {
  14816. @trigger_error(
  14817. sprintf(
  14818. 'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
  14819. __CLASS__
  14820. ),
  14821. E_USER_DEPRECATED
  14822. );
  14823. }
  14824. protected function injectAlignmentPlaceholders(Tokens $tokens, $startAt, $endAt)
  14825. {
  14826. for ($index = $startAt; $index < $endAt; ++$index) {
  14827. $token = $tokens[$index];
  14828. if ($token->isGivenKind([T_FOREACH, T_FOR, T_WHILE, T_IF, T_SWITCH])) {
  14829. $index = $tokens->getNextMeaningfulToken($index);
  14830. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  14831. continue;
  14832. }
  14833. if ($token->isGivenKind(T_ARRAY)) {
  14834. $from = $tokens->getNextMeaningfulToken($index);
  14835. $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $from);
  14836. $index = $until;
  14837. $this->injectArrayAlignmentPlaceholders($tokens, $from, $until);
  14838. continue;
  14839. }
  14840. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  14841. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  14842. if ($prevToken->isGivenKind([T_STRING, T_VARIABLE])) {
  14843. continue;
  14844. }
  14845. $from = $index;
  14846. $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $from);
  14847. $index = $until;
  14848. $this->injectArrayAlignmentPlaceholders($tokens, $from + 1, $until - 1);
  14849. continue;
  14850. }
  14851. if ($token->isGivenKind(T_DOUBLE_ARROW)) {
  14852. $tokenContent = sprintf(self::ALIGNABLE_PLACEHOLDER, $this->currentLevel).$token->getContent();
  14853. $nextIndex = $index + 1;
  14854. $nextToken = $tokens[$nextIndex];
  14855. if (!$nextToken->isWhitespace()) {
  14856. $tokenContent .= ' ';
  14857. } elseif ($nextToken->isWhitespace(" \t")) {
  14858. $tokens[$nextIndex] = new Token([T_WHITESPACE, ' ']);
  14859. }
  14860. $tokens[$index] = new Token([T_DOUBLE_ARROW, $tokenContent]);
  14861. continue;
  14862. }
  14863. if ($token->equals(';')) {
  14864. ++$this->deepestLevel;
  14865. ++$this->currentLevel;
  14866. continue;
  14867. }
  14868. if ($token->equals(',')) {
  14869. for ($i = $index; $i < $endAt - 1; ++$i) {
  14870. if (false !== strpos($tokens[$i - 1]->getContent(), "\n")) {
  14871. break;
  14872. }
  14873. if ($tokens[$i + 1]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  14874. $arrayStartIndex = $tokens[$i + 1]->isGivenKind(T_ARRAY)
  14875. ? $tokens->getNextMeaningfulToken($i + 1)
  14876. : $i + 1
  14877. ;
  14878. $blockType = Tokens::detectBlockType($tokens[$arrayStartIndex]);
  14879. $arrayEndIndex = $tokens->findBlockEnd($blockType['type'], $arrayStartIndex);
  14880. if ($tokens->isPartialCodeMultiline($arrayStartIndex, $arrayEndIndex)) {
  14881. break;
  14882. }
  14883. }
  14884. ++$index;
  14885. }
  14886. }
  14887. }
  14888. }
  14889. private function injectArrayAlignmentPlaceholders(Tokens $tokens, $from, $until)
  14890. {
  14891. if ($tokens->isPartialCodeMultiline($from, $until)) {
  14892. ++$this->deepestLevel;
  14893. ++$this->currentLevel;
  14894. $this->injectAlignmentPlaceholders($tokens, $from, $until);
  14895. --$this->currentLevel;
  14896. }
  14897. }
  14898. }
  14899. <?php
  14900. namespace PhpCsFixer\Fixer\Operator;
  14901. use PhpCsFixer\AbstractAlignFixerHelper;
  14902. use PhpCsFixer\Tokenizer\CT;
  14903. use PhpCsFixer\Tokenizer\Token;
  14904. use PhpCsFixer\Tokenizer\Tokens;
  14905. final class AlignEqualsFixerHelper extends AbstractAlignFixerHelper
  14906. {
  14907. public function __construct()
  14908. {
  14909. @trigger_error(
  14910. sprintf(
  14911. 'The "%s" class is deprecated. You should stop using it, as it will be removed in 3.0 version.',
  14912. __CLASS__
  14913. ),
  14914. E_USER_DEPRECATED
  14915. );
  14916. }
  14917. protected function injectAlignmentPlaceholders(Tokens $tokens, $startAt, $endAt)
  14918. {
  14919. for ($index = $startAt; $index < $endAt; ++$index) {
  14920. $token = $tokens[$index];
  14921. if ($token->equals('=')) {
  14922. $tokens[$index] = new Token(sprintf(self::ALIGNABLE_PLACEHOLDER, $this->deepestLevel).$token->getContent());
  14923. continue;
  14924. }
  14925. if ($token->isGivenKind(T_FUNCTION)) {
  14926. ++$this->deepestLevel;
  14927. continue;
  14928. }
  14929. if ($token->equals('(')) {
  14930. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  14931. continue;
  14932. }
  14933. if ($token->equals('[')) {
  14934. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
  14935. continue;
  14936. }
  14937. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  14938. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index);
  14939. continue;
  14940. }
  14941. }
  14942. }
  14943. }
  14944. <?php
  14945. namespace PhpCsFixer\Fixer\Operator;
  14946. use PhpCsFixer\AbstractFixer;
  14947. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  14948. use PhpCsFixer\Console\Command\HelpCommand;
  14949. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  14950. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  14951. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  14952. use PhpCsFixer\FixerDefinition\CodeSample;
  14953. use PhpCsFixer\FixerDefinition\FixerDefinition;
  14954. use PhpCsFixer\Tokenizer\CT;
  14955. use PhpCsFixer\Tokenizer\Token;
  14956. use PhpCsFixer\Tokenizer\Tokens;
  14957. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  14958. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  14959. final class BinaryOperatorSpacesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  14960. {
  14961. const SINGLE_SPACE = 'single_space';
  14962. const ALIGN = 'align';
  14963. const ALIGN_SINGLE_SPACE = 'align_single_space';
  14964. const ALIGN_SINGLE_SPACE_MINIMAL = 'align_single_space_minimal';
  14965. const ALIGN_PLACEHOLDER = "\x2 ALIGNABLE%d \x3";
  14966. private $deepestLevel;
  14967. private $currentLevel;
  14968. private static $allowedValues = [
  14969. self::ALIGN,
  14970. self::ALIGN_SINGLE_SPACE,
  14971. self::ALIGN_SINGLE_SPACE_MINIMAL,
  14972. self::SINGLE_SPACE,
  14973. null,
  14974. ];
  14975. private static $supportedOperators = [
  14976. '=',
  14977. '*',
  14978. '/',
  14979. '%',
  14980. '<',
  14981. '>',
  14982. '|',
  14983. '^',
  14984. '+',
  14985. '-',
  14986. '&',
  14987. '&=',
  14988. '&&',
  14989. '||',
  14990. '.=',
  14991. '/=',
  14992. '=>',
  14993. '==',
  14994. '>=',
  14995. '===',
  14996. '!=',
  14997. '<>',
  14998. '!==',
  14999. '<=',
  15000. 'and',
  15001. 'or',
  15002. 'xor',
  15003. '-=',
  15004. '%=',
  15005. '*=',
  15006. '|=',
  15007. '+=',
  15008. '<<',
  15009. '<<=',
  15010. '>>',
  15011. '>>=',
  15012. '^=',
  15013. '**',
  15014. '**=',
  15015. '<=>',
  15016. '??',
  15017. ];
  15018. private $tokensAnalyzer;
  15019. private $alignOperatorTokens = [];
  15020. private $operators = [];
  15021. public function configure(array $configuration = null)
  15022. {
  15023. if (
  15024. null !== $configuration &&
  15025. (array_key_exists('align_equals', $configuration) || array_key_exists('align_double_arrow', $configuration))
  15026. ) {
  15027. $configuration = $this->resolveOldConfig($configuration);
  15028. }
  15029. parent::configure($configuration);
  15030. $this->operators = $this->resolveOperatorsFromConfig();
  15031. }
  15032. public function getDefinition()
  15033. {
  15034. return new FixerDefinition(
  15035. 'Binary operators should be surrounded by space as configured.',
  15036. [
  15037. new CodeSample(
  15038. "<?php\n\$a= 1 + \$b^ \$d !== \$e or \$f;\n"
  15039. ),
  15040. new CodeSample(
  15041. '<?php
  15042. $aa= 1;
  15043. $b=2;
  15044. $c = $d xor $e;
  15045. $f -= 1;
  15046. ',
  15047. ['operators' => ['=' => 'align', 'xor' => null]]
  15048. ),
  15049. new CodeSample(
  15050. '<?php
  15051. $a = $b +=$c;
  15052. $d = $ee+=$f;
  15053. $g = $b +=$c;
  15054. $h = $ee+=$f;
  15055. ',
  15056. ['operators' => ['+=' => 'align_single_space']]
  15057. ),
  15058. new CodeSample(
  15059. '<?php
  15060. $a = $b===$c;
  15061. $d = $f === $g;
  15062. $h = $i=== $j;
  15063. ',
  15064. ['operators' => ['===' => 'align_single_space_minimal']]
  15065. ),
  15066. ]
  15067. );
  15068. }
  15069. public function getPriority()
  15070. {
  15071. return -1;
  15072. }
  15073. public function isCandidate(Tokens $tokens)
  15074. {
  15075. return true;
  15076. }
  15077. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15078. {
  15079. $this->tokensAnalyzer = new TokensAnalyzer($tokens);
  15080. for ($index = $tokens->count() - 2; $index > 0; --$index) {
  15081. if (!$this->tokensAnalyzer->isBinaryOperator($index)) {
  15082. continue;
  15083. }
  15084. if ('=' === $tokens[$index]->getContent()) {
  15085. $isDeclare = $this->isEqualPartOfDeclareStatement($tokens, $index);
  15086. if (false === $isDeclare) {
  15087. $this->fixWhiteSpaceAroundOperator($tokens, $index);
  15088. } else {
  15089. $index = $isDeclare;
  15090. }
  15091. } else {
  15092. $this->fixWhiteSpaceAroundOperator($tokens, $index);
  15093. }
  15094. --$index;
  15095. }
  15096. if (count($this->alignOperatorTokens)) {
  15097. $this->fixAlignment($tokens, $this->alignOperatorTokens);
  15098. }
  15099. }
  15100. protected function createConfigurationDefinition()
  15101. {
  15102. return new FixerConfigurationResolver([
  15103. (new FixerOptionBuilder('default', 'Default fix strategy.'))
  15104. ->setDefault(self::SINGLE_SPACE)
  15105. ->setAllowedValues(self::$allowedValues)
  15106. ->getOption(),
  15107. (new FixerOptionBuilder('operators', 'Dictionary of `binary operator` => `fix strategy` values that differ from the default strategy.'))
  15108. ->setAllowedTypes(['array'])
  15109. ->setAllowedValues([static function ($option) {
  15110. foreach ($option as $operator => $value) {
  15111. if (!in_array($operator, self::$supportedOperators, true)) {
  15112. throw new InvalidOptionsException(
  15113. sprintf(
  15114. 'Unexpected "operators" key, expected any of "%s", got "%s".',
  15115. implode('", "', self::$supportedOperators),
  15116. is_object($operator) ? get_class($operator) : gettype($operator).'#'.$operator
  15117. )
  15118. );
  15119. }
  15120. if (!in_array($value, self::$allowedValues, true)) {
  15121. throw new InvalidOptionsException(
  15122. sprintf(
  15123. 'Unexpected value for operator "%s", expected any of "%s", got "%s".',
  15124. $operator,
  15125. implode('", "', self::$allowedValues),
  15126. is_object($value) ? get_class($value) : (null === $value ? 'null' : gettype($value).'#'.$value)
  15127. )
  15128. );
  15129. }
  15130. }
  15131. return true;
  15132. }])
  15133. ->setDefault([])
  15134. ->getOption(),
  15135. (new FixerOptionBuilder('align_double_arrow', '(deprecated) Whether to apply, remove or ignore double arrows alignment.'))
  15136. ->setDefault(false)
  15137. ->setAllowedValues([true, false, null])
  15138. ->getOption(),
  15139. (new FixerOptionBuilder('align_equals', '(deprecated) Whether to apply, remove or ignore equals alignment.'))
  15140. ->setDefault(false)
  15141. ->setAllowedValues([true, false, null])
  15142. ->getOption(),
  15143. ]);
  15144. }
  15145. private function fixWhiteSpaceAroundOperator(Tokens $tokens, $index)
  15146. {
  15147. $tokenContent = strtolower($tokens[$index]->getContent());
  15148. if (!array_key_exists($tokenContent, $this->operators)) {
  15149. return;
  15150. }
  15151. if (self::SINGLE_SPACE === $this->operators[$tokenContent]) {
  15152. $this->fixWhiteSpaceAroundOperatorToSingleSpace($tokens, $index);
  15153. return;
  15154. }
  15155. $this->alignOperatorTokens[$tokenContent] = $this->operators[$tokenContent];
  15156. if (self::ALIGN === $this->operators[$tokenContent]) {
  15157. return;
  15158. }
  15159. if ($tokens[$index + 1]->isWhitespace()) {
  15160. if (self::ALIGN_SINGLE_SPACE_MINIMAL === $this->operators[$tokenContent]) {
  15161. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  15162. }
  15163. return;
  15164. }
  15165. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  15166. }
  15167. private function fixWhiteSpaceAroundOperatorToSingleSpace(Tokens $tokens, $index)
  15168. {
  15169. if ($tokens[$index + 1]->isWhitespace()) {
  15170. $content = $tokens[$index + 1]->getContent();
  15171. if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getNextNonWhitespace($index + 1)]->isComment()) {
  15172. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  15173. }
  15174. } else {
  15175. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  15176. }
  15177. if ($tokens[$index - 1]->isWhitespace()) {
  15178. $content = $tokens[$index - 1]->getContent();
  15179. if (' ' !== $content && false === strpos($content, "\n") && !$tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
  15180. $tokens[$index - 1] = new Token([T_WHITESPACE, ' ']);
  15181. }
  15182. } else {
  15183. $tokens->insertAt($index, new Token([T_WHITESPACE, ' ']));
  15184. }
  15185. }
  15186. private function isEqualPartOfDeclareStatement(Tokens $tokens, $index)
  15187. {
  15188. $prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($index);
  15189. if ($tokens[$prevMeaningfulIndex]->isGivenKind(T_STRING)) {
  15190. $prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulIndex);
  15191. if ($tokens[$prevMeaningfulIndex]->equals('(')) {
  15192. $prevMeaningfulIndex = $tokens->getPrevMeaningfulToken($prevMeaningfulIndex);
  15193. if ($tokens[$prevMeaningfulIndex]->isGivenKind(T_DECLARE)) {
  15194. return $prevMeaningfulIndex;
  15195. }
  15196. }
  15197. }
  15198. return false;
  15199. }
  15200. private function resolveOperatorsFromConfig()
  15201. {
  15202. $operators = [];
  15203. if (null !== $this->configuration['default']) {
  15204. foreach (self::$supportedOperators as $operator) {
  15205. $operators[$operator] = $this->configuration['default'];
  15206. }
  15207. }
  15208. foreach ($this->configuration['operators'] as $operator => $value) {
  15209. if (null === $value) {
  15210. unset($operators[$operator]);
  15211. } else {
  15212. $operators[$operator] = $value;
  15213. }
  15214. }
  15215. if (!defined('T_SPACESHIP')) {
  15216. unset($operators['<=>']);
  15217. }
  15218. if (!defined('T_COALESCE')) {
  15219. unset($operators['??']);
  15220. }
  15221. return $operators;
  15222. }
  15223. private function resolveOldConfig(array $configuration)
  15224. {
  15225. $newConfig = [
  15226. 'operators' => [],
  15227. ];
  15228. foreach ($configuration as $name => $setting) {
  15229. if ('align_double_arrow' === $name) {
  15230. if (true === $configuration[$name]) {
  15231. $newConfig['operators']['=>'] = self::ALIGN;
  15232. } elseif (false === $configuration[$name]) {
  15233. $newConfig['operators']['=>'] = self::SINGLE_SPACE;
  15234. } elseif (null !== $configuration[$name]) {
  15235. throw new InvalidFixerConfigurationException(
  15236. $this->getName(),
  15237. sprintf(
  15238. 'Invalid configuration: The option "align_double_arrow" with value %s is invalid. Accepted values are: true, false, null.',
  15239. $configuration[$name]
  15240. )
  15241. );
  15242. }
  15243. } elseif ('align_equals' === $name) {
  15244. if (true === $configuration[$name]) {
  15245. $newConfig['operators']['='] = self::ALIGN;
  15246. } elseif (false === $configuration[$name]) {
  15247. $newConfig['operators']['='] = self::SINGLE_SPACE;
  15248. } elseif (null !== $configuration[$name]) {
  15249. throw new InvalidFixerConfigurationException(
  15250. $this->getName(),
  15251. sprintf(
  15252. 'Invalid configuration: The option "align_equals" with value %s is invalid. Accepted values are: true, false, null.',
  15253. $configuration[$name]
  15254. )
  15255. );
  15256. }
  15257. } else {
  15258. throw new InvalidFixerConfigurationException($this->getName(), 'Mixing old configuration with new configuration is not allowed.');
  15259. }
  15260. }
  15261. @trigger_error(sprintf(
  15262. 'Given configuration is deprecated and will be removed in 3.0. Use configuration %s as replacement for %s.',
  15263. HelpCommand::toString($newConfig),
  15264. HelpCommand::toString($configuration)
  15265. ), E_USER_DEPRECATED);
  15266. return $newConfig;
  15267. }
  15268. private function fixAlignment(Tokens $tokens, array $toAlign)
  15269. {
  15270. $this->deepestLevel = 0;
  15271. $this->currentLevel = 0;
  15272. foreach ($toAlign as $tokenContent => $alignStrategy) {
  15273. $tokensClone = clone $tokens;
  15274. if ('=>' === $tokenContent) {
  15275. $this->injectAlignmentPlaceholdersForArrow($tokensClone, 0, count($tokens));
  15276. } else {
  15277. $this->injectAlignmentPlaceholders($tokensClone, 0, count($tokens), $tokenContent);
  15278. }
  15279. if (self::ALIGN_SINGLE_SPACE === $alignStrategy || self::ALIGN_SINGLE_SPACE_MINIMAL === $alignStrategy) {
  15280. if ('=>' === $tokenContent) {
  15281. for ($index = $tokens->count() - 2; $index > 0; --$index) {
  15282. if ($tokens[$index]->isGivenKind(T_DOUBLE_ARROW)) {
  15283. $this->fixWhiteSpaceBeforeOperator($tokensClone, $index, $alignStrategy);
  15284. }
  15285. }
  15286. } elseif ('=' === $tokenContent) {
  15287. for ($index = $tokens->count() - 2; $index > 0; --$index) {
  15288. if ('=' === $tokens[$index]->getContent() && !$this->isEqualPartOfDeclareStatement($tokens, $index) && $this->tokensAnalyzer->isBinaryOperator($index)) {
  15289. $this->fixWhiteSpaceBeforeOperator($tokensClone, $index, $alignStrategy);
  15290. }
  15291. }
  15292. } else {
  15293. for ($index = $tokens->count() - 2; $index > 0; --$index) {
  15294. $content = $tokens[$index]->getContent();
  15295. if (strtolower($content) === $tokenContent && $this->tokensAnalyzer->isBinaryOperator($index)) {
  15296. $this->fixWhiteSpaceBeforeOperator($tokensClone, $index, $alignStrategy);
  15297. }
  15298. }
  15299. }
  15300. }
  15301. $tokens->setCode($this->replacePlaceholders($tokensClone, $alignStrategy));
  15302. }
  15303. }
  15304. private function injectAlignmentPlaceholders(Tokens $tokens, $startAt, $endAt, $tokenContent)
  15305. {
  15306. for ($index = $startAt; $index < $endAt; ++$index) {
  15307. $token = $tokens[$index];
  15308. $content = $token->getContent();
  15309. if (
  15310. strtolower($content) === $tokenContent
  15311. && $this->tokensAnalyzer->isBinaryOperator($index)
  15312. && ('=' !== $content || !$this->isEqualPartOfDeclareStatement($tokens, $index))
  15313. ) {
  15314. $tokens[$index] = new Token(sprintf(self::ALIGN_PLACEHOLDER, $this->deepestLevel).$content);
  15315. continue;
  15316. }
  15317. if ($token->isGivenKind(T_FUNCTION)) {
  15318. ++$this->deepestLevel;
  15319. continue;
  15320. }
  15321. if ($token->equals('(')) {
  15322. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  15323. continue;
  15324. }
  15325. if ($token->equals('[')) {
  15326. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
  15327. continue;
  15328. }
  15329. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  15330. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index);
  15331. continue;
  15332. }
  15333. }
  15334. }
  15335. private function injectAlignmentPlaceholdersForArrow(Tokens $tokens, $startAt, $endAt)
  15336. {
  15337. for ($index = $startAt; $index < $endAt; ++$index) {
  15338. $token = $tokens[$index];
  15339. if ($token->isGivenKind([T_FOREACH, T_FOR, T_WHILE, T_IF, T_SWITCH])) {
  15340. $index = $tokens->getNextMeaningfulToken($index);
  15341. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  15342. continue;
  15343. }
  15344. if ($token->isGivenKind(T_ARRAY)) {
  15345. $from = $tokens->getNextMeaningfulToken($index);
  15346. $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $from);
  15347. $index = $until;
  15348. $this->injectArrayAlignmentPlaceholders($tokens, $from + 1, $until - 1);
  15349. continue;
  15350. }
  15351. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  15352. $from = $index;
  15353. $until = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $from);
  15354. $index = $until;
  15355. $this->injectArrayAlignmentPlaceholders($tokens, $from + 1, $until - 1);
  15356. continue;
  15357. }
  15358. if ($token->isGivenKind(T_DOUBLE_ARROW)) {
  15359. $tokenContent = sprintf(self::ALIGN_PLACEHOLDER, $this->currentLevel).$token->getContent();
  15360. $nextToken = $tokens[$index + 1];
  15361. if (!$nextToken->isWhitespace()) {
  15362. $tokenContent .= ' ';
  15363. } elseif ($nextToken->isWhitespace(" \t")) {
  15364. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  15365. }
  15366. $tokens[$index] = new Token([T_DOUBLE_ARROW, $tokenContent]);
  15367. continue;
  15368. }
  15369. if ($token->equals(';')) {
  15370. ++$this->deepestLevel;
  15371. ++$this->currentLevel;
  15372. continue;
  15373. }
  15374. if ($token->equals(',')) {
  15375. for ($i = $index; $i < $endAt - 1; ++$i) {
  15376. if (false !== strpos($tokens[$i - 1]->getContent(), "\n")) {
  15377. break;
  15378. }
  15379. if ($tokens[$i + 1]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN])) {
  15380. $arrayStartIndex = $tokens[$i + 1]->isGivenKind(T_ARRAY)
  15381. ? $tokens->getNextMeaningfulToken($i + 1)
  15382. : $i + 1
  15383. ;
  15384. $blockType = Tokens::detectBlockType($tokens[$arrayStartIndex]);
  15385. $arrayEndIndex = $tokens->findBlockEnd($blockType['type'], $arrayStartIndex);
  15386. if ($tokens->isPartialCodeMultiline($arrayStartIndex, $arrayEndIndex)) {
  15387. break;
  15388. }
  15389. }
  15390. ++$index;
  15391. }
  15392. }
  15393. }
  15394. }
  15395. private function injectArrayAlignmentPlaceholders(Tokens $tokens, $from, $until)
  15396. {
  15397. if ($tokens->isPartialCodeMultiline($from, $until)) {
  15398. ++$this->deepestLevel;
  15399. ++$this->currentLevel;
  15400. $this->injectAlignmentPlaceholdersForArrow($tokens, $from, $until);
  15401. --$this->currentLevel;
  15402. }
  15403. }
  15404. private function fixWhiteSpaceBeforeOperator(Tokens $tokens, $index, $alignStrategy)
  15405. {
  15406. if (!$tokens[$index - 1]->isWhitespace()) {
  15407. $tokens->insertAt($index, new Token([T_WHITESPACE, ' ']));
  15408. return;
  15409. }
  15410. if (self::ALIGN_SINGLE_SPACE_MINIMAL !== $alignStrategy || $tokens[$tokens->getPrevNonWhitespace($index - 1)]->isComment()) {
  15411. return;
  15412. }
  15413. $content = $tokens[$index - 1]->getContent();
  15414. if (' ' !== $content && false === strpos($content, "\n")) {
  15415. $tokens[$index - 1] = new Token([T_WHITESPACE, ' ']);
  15416. }
  15417. }
  15418. private function replacePlaceholders(Tokens $tokens, $alignStrategy)
  15419. {
  15420. $tmpCode = $tokens->generateCode();
  15421. for ($j = 0; $j <= $this->deepestLevel; ++$j) {
  15422. $placeholder = sprintf(self::ALIGN_PLACEHOLDER, $j);
  15423. if (false === strpos($tmpCode, $placeholder)) {
  15424. continue;
  15425. }
  15426. $lines = explode("\n", $tmpCode);
  15427. $groups = [];
  15428. $groupIndex = 0;
  15429. $groups[$groupIndex] = [];
  15430. foreach ($lines as $index => $line) {
  15431. if (substr_count($line, $placeholder) > 0) {
  15432. $groups[$groupIndex][] = $index;
  15433. } else {
  15434. ++$groupIndex;
  15435. $groups[$groupIndex] = [];
  15436. }
  15437. }
  15438. foreach ($groups as $group) {
  15439. if (count($group) < 1) {
  15440. continue;
  15441. }
  15442. if (self::ALIGN !== $alignStrategy) {
  15443. foreach ($group as $index) {
  15444. $currentPosition = strpos($lines[$index], $placeholder);
  15445. $before = substr($lines[$index], 0, $currentPosition);
  15446. if (self::ALIGN_SINGLE_SPACE === $alignStrategy) {
  15447. if (1 > strlen($before) || ' ' !== substr($before, -1)) {
  15448. $before .= ' ';
  15449. }
  15450. } elseif (self::ALIGN_SINGLE_SPACE_MINIMAL === $alignStrategy) {
  15451. if (1 !== preg_match('/^\h+$/', $before)) {
  15452. $before = rtrim($before).' ';
  15453. }
  15454. }
  15455. $lines[$index] = $before.substr($lines[$index], $currentPosition);
  15456. }
  15457. }
  15458. $rightmostSymbol = 0;
  15459. foreach ($group as $index) {
  15460. $rightmostSymbol = max($rightmostSymbol, strpos(utf8_decode($lines[$index]), $placeholder));
  15461. }
  15462. foreach ($group as $index) {
  15463. $line = $lines[$index];
  15464. $currentSymbol = strpos(utf8_decode($line), $placeholder);
  15465. $delta = abs($rightmostSymbol - $currentSymbol);
  15466. if ($delta > 0) {
  15467. $line = str_replace($placeholder, str_repeat(' ', $delta).$placeholder, $line);
  15468. $lines[$index] = $line;
  15469. }
  15470. }
  15471. }
  15472. $tmpCode = str_replace($placeholder, '', implode("\n", $lines));
  15473. }
  15474. return $tmpCode;
  15475. }
  15476. }
  15477. <?php
  15478. namespace PhpCsFixer\Fixer\Operator;
  15479. use PhpCsFixer\AbstractFixer;
  15480. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  15481. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  15482. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  15483. use PhpCsFixer\FixerDefinition\CodeSample;
  15484. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15485. use PhpCsFixer\Tokenizer\Token;
  15486. use PhpCsFixer\Tokenizer\Tokens;
  15487. final class ConcatSpaceFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  15488. {
  15489. private $fixCallback;
  15490. public function configure(array $configuration = null)
  15491. {
  15492. parent::configure($configuration);
  15493. if ('one' === $this->configuration['spacing']) {
  15494. $this->fixCallback = 'fixConcatenationToSingleSpace';
  15495. } else {
  15496. $this->fixCallback = 'fixConcatenationToNoSpace';
  15497. }
  15498. }
  15499. public function getDefinition()
  15500. {
  15501. return new FixerDefinition(
  15502. 'Concatenation should be spaced according configuration.',
  15503. [
  15504. new CodeSample(
  15505. "<?php\n\$foo = 'bar' . 3 . 'baz'.'qux';\n"
  15506. ),
  15507. new CodeSample(
  15508. "<?php\n\$foo = 'bar' . 3 . 'baz'.'qux';\n",
  15509. ['spacing' => 'none']
  15510. ),
  15511. new CodeSample(
  15512. "<?php\n\$foo = 'bar' . 3 . 'baz'.'qux';\n",
  15513. ['spacing' => 'one']
  15514. ),
  15515. ]
  15516. );
  15517. }
  15518. public function isCandidate(Tokens $tokens)
  15519. {
  15520. return $tokens->isTokenKindFound('.');
  15521. }
  15522. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15523. {
  15524. $callBack = $this->fixCallback;
  15525. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  15526. if ($tokens[$index]->equals('.')) {
  15527. $this->{$callBack}($tokens, $index);
  15528. }
  15529. }
  15530. }
  15531. protected function createConfigurationDefinition()
  15532. {
  15533. return new FixerConfigurationResolver([
  15534. (new FixerOptionBuilder('spacing', 'Spacing to apply around concatenation operator.'))
  15535. ->setAllowedValues(['one', 'none'])
  15536. ->setDefault('none')
  15537. ->getOption(),
  15538. ]);
  15539. }
  15540. private function fixConcatenationToNoSpace(Tokens $tokens, $index)
  15541. {
  15542. if (!$tokens[$tokens->getPrevNonWhitespace($index)]->isGivenKind(T_LNUMBER)) {
  15543. $tokens->removeLeadingWhitespace($index, " \t");
  15544. }
  15545. if (!$tokens[$tokens->getNextNonWhitespace($index)]->isGivenKind([T_LNUMBER, T_COMMENT, T_DOC_COMMENT])) {
  15546. $tokens->removeTrailingWhitespace($index, " \t");
  15547. }
  15548. }
  15549. private function fixConcatenationToSingleSpace(Tokens $tokens, $index)
  15550. {
  15551. $this->fixWhiteSpaceAroundConcatToken($tokens, $index, 1);
  15552. $this->fixWhiteSpaceAroundConcatToken($tokens, $index, -1);
  15553. }
  15554. private function fixWhiteSpaceAroundConcatToken(Tokens $tokens, $index, $offset)
  15555. {
  15556. $offsetIndex = $index + $offset;
  15557. if (!$tokens[$offsetIndex]->isWhitespace()) {
  15558. $tokens->insertAt($index + (1 === $offset ?: 0), new Token([T_WHITESPACE, ' ']));
  15559. return;
  15560. }
  15561. if (false !== strpos($tokens[$offsetIndex]->getContent(), "\n")) {
  15562. return;
  15563. }
  15564. if ($tokens[$index + $offset * 2]->isComment()) {
  15565. return;
  15566. }
  15567. $tokens[$offsetIndex] = new Token([T_WHITESPACE, ' ']);
  15568. }
  15569. }
  15570. <?php
  15571. namespace PhpCsFixer\Fixer\Operator;
  15572. use PhpCsFixer\AbstractFixer;
  15573. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  15574. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  15575. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  15576. use PhpCsFixer\FixerDefinition\CodeSample;
  15577. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15578. use PhpCsFixer\Tokenizer\CT;
  15579. use PhpCsFixer\Tokenizer\Tokens;
  15580. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  15581. final class IncrementStyleFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  15582. {
  15583. const STYLE_PRE = 'pre';
  15584. const STYLE_POST = 'post';
  15585. public function getDefinition()
  15586. {
  15587. return new FixerDefinition(
  15588. 'Pre- or post-increment and decrement operators should be used if possible.',
  15589. [
  15590. new CodeSample("<?php\n\$a++;\n\$b--;\n"),
  15591. new CodeSample(
  15592. "<?php\n++\$a;\n--\$b;\n",
  15593. ['style' => self::STYLE_POST]
  15594. ),
  15595. ]
  15596. );
  15597. }
  15598. public function isCandidate(Tokens $tokens)
  15599. {
  15600. return $tokens->isAnyTokenKindsFound([T_INC, T_DEC]);
  15601. }
  15602. protected function createConfigurationDefinition()
  15603. {
  15604. return new FixerConfigurationResolver([
  15605. (new FixerOptionBuilder('style', 'Whether to use pre- or post-increment and decrement operators.'))
  15606. ->setAllowedValues([self::STYLE_PRE, self::STYLE_POST])
  15607. ->setDefault(self::STYLE_PRE)
  15608. ->getOption(),
  15609. ]);
  15610. }
  15611. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15612. {
  15613. $tokensAnalyzer = new TokensAnalyzer($tokens);
  15614. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  15615. $token = $tokens[$index];
  15616. if (!$token->isGivenKind([T_INC, T_DEC])) {
  15617. continue;
  15618. }
  15619. if (self::STYLE_PRE === $this->configuration['style'] && $tokensAnalyzer->isUnarySuccessorOperator($index)) {
  15620. $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
  15621. if (!$nextToken->equalsAny([';', ')'])) {
  15622. continue;
  15623. }
  15624. $startIndex = $this->findStart($tokens, $index);
  15625. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($startIndex)];
  15626. if ($prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
  15627. $tokens->clearAt($index);
  15628. $tokens->insertAt($startIndex, clone $token);
  15629. }
  15630. } elseif (self::STYLE_POST === $this->configuration['style'] && $tokensAnalyzer->isUnaryPredecessorOperator($index)) {
  15631. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  15632. if (!$prevToken->equalsAny([';', '{', '}', [T_OPEN_TAG]])) {
  15633. continue;
  15634. }
  15635. $endIndex = $this->findEnd($tokens, $index);
  15636. $nextToken = $tokens[$tokens->getNextMeaningfulToken($endIndex)];
  15637. if ($nextToken->equalsAny([';', ')'])) {
  15638. $tokens->clearAt($index);
  15639. $tokens->insertAt($tokens->getNextNonWhitespace($endIndex), clone $token);
  15640. }
  15641. }
  15642. }
  15643. }
  15644. private function findEnd(Tokens $tokens, $index)
  15645. {
  15646. $nextIndex = $tokens->getNextMeaningfulToken($index);
  15647. $nextToken = $tokens[$nextIndex];
  15648. while ($nextToken->equalsAny([
  15649. '$',
  15650. '[',
  15651. [CT::T_DYNAMIC_PROP_BRACE_OPEN],
  15652. [CT::T_DYNAMIC_VAR_BRACE_OPEN],
  15653. [T_NS_SEPARATOR],
  15654. [T_STRING],
  15655. [T_VARIABLE],
  15656. ])) {
  15657. $blockType = Tokens::detectBlockType($nextToken);
  15658. if (null !== $blockType) {
  15659. $nextIndex = $tokens->findBlockEnd($blockType['type'], $nextIndex);
  15660. }
  15661. $index = $nextIndex;
  15662. $nextIndex = $tokens->getNextMeaningfulToken($nextIndex);
  15663. $nextToken = $tokens[$nextIndex];
  15664. }
  15665. if ($nextToken->isGivenKind(T_OBJECT_OPERATOR)) {
  15666. return $this->findEnd($tokens, $nextIndex);
  15667. }
  15668. if ($nextToken->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM)) {
  15669. return $this->findEnd($tokens, $tokens->getNextMeaningfulToken($nextIndex));
  15670. }
  15671. return $index;
  15672. }
  15673. private function findStart(Tokens $tokens, $index)
  15674. {
  15675. do {
  15676. $index = $tokens->getPrevMeaningfulToken($index);
  15677. $token = $tokens[$index];
  15678. $blockType = Tokens::detectBlockType($token);
  15679. if (null !== $blockType && !$blockType['isStart']) {
  15680. $index = $tokens->findBlockEnd($blockType['type'], $index, false);
  15681. $token = $tokens[$index];
  15682. }
  15683. } while (!$token->equalsAny(['$', [T_VARIABLE]]));
  15684. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  15685. $prevToken = $tokens[$prevIndex];
  15686. if ($prevToken->equals('$')) {
  15687. $index = $prevIndex;
  15688. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  15689. $prevToken = $tokens[$prevIndex];
  15690. }
  15691. if ($prevToken->isGivenKind(T_OBJECT_OPERATOR)) {
  15692. return $this->findStart($tokens, $prevIndex);
  15693. }
  15694. if ($prevToken->isGivenKind(T_PAAMAYIM_NEKUDOTAYIM)) {
  15695. $prevPrevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
  15696. if (!$tokens[$prevPrevIndex]->isGivenKind(T_STRING)) {
  15697. return $this->findStart($tokens, $prevIndex);
  15698. }
  15699. $index = $tokens->getTokenNotOfKindSibling($prevIndex, -1, [[T_NS_SEPARATOR], [T_STRING]]);
  15700. $index = $tokens->getNextMeaningfulToken($index);
  15701. }
  15702. return $index;
  15703. }
  15704. }
  15705. <?php
  15706. namespace PhpCsFixer\Fixer\Operator;
  15707. use PhpCsFixer\AbstractFixer;
  15708. use PhpCsFixer\FixerDefinition\CodeSample;
  15709. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15710. use PhpCsFixer\Tokenizer\CT;
  15711. use PhpCsFixer\Tokenizer\Token;
  15712. use PhpCsFixer\Tokenizer\Tokens;
  15713. final class NewWithBracesFixer extends AbstractFixer
  15714. {
  15715. public function getDefinition()
  15716. {
  15717. return new FixerDefinition(
  15718. 'All instances created with new keyword must be followed by braces.',
  15719. [new CodeSample("<?php \$x = new X;\n")]
  15720. );
  15721. }
  15722. public function isCandidate(Tokens $tokens)
  15723. {
  15724. return $tokens->isTokenKindFound(T_NEW);
  15725. }
  15726. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15727. {
  15728. static $nextTokenKinds = null;
  15729. if (null === $nextTokenKinds) {
  15730. $nextTokenKinds = [
  15731. '?',
  15732. ';',
  15733. ',',
  15734. '(',
  15735. ')',
  15736. '[',
  15737. ']',
  15738. ':',
  15739. '<',
  15740. '>',
  15741. '+',
  15742. '-',
  15743. '*',
  15744. '/',
  15745. '%',
  15746. '&',
  15747. '^',
  15748. '|',
  15749. [T_CLASS],
  15750. [T_IS_SMALLER_OR_EQUAL],
  15751. [T_IS_GREATER_OR_EQUAL],
  15752. [T_IS_EQUAL],
  15753. [T_IS_NOT_EQUAL],
  15754. [T_IS_IDENTICAL],
  15755. [T_IS_NOT_IDENTICAL],
  15756. [T_CLOSE_TAG],
  15757. [T_LOGICAL_AND],
  15758. [T_LOGICAL_OR],
  15759. [T_LOGICAL_XOR],
  15760. [T_BOOLEAN_AND],
  15761. [T_BOOLEAN_OR],
  15762. [T_SL],
  15763. [T_SR],
  15764. [T_INSTANCEOF],
  15765. [T_AS],
  15766. [T_DOUBLE_ARROW],
  15767. [T_POW],
  15768. [CT::T_ARRAY_SQUARE_BRACE_OPEN],
  15769. [CT::T_ARRAY_SQUARE_BRACE_CLOSE],
  15770. [CT::T_BRACE_CLASS_INSTANTIATION_OPEN],
  15771. [CT::T_BRACE_CLASS_INSTANTIATION_CLOSE],
  15772. ];
  15773. if (defined('T_SPACESHIP')) {
  15774. $nextTokenKinds[] = [T_SPACESHIP];
  15775. }
  15776. }
  15777. for ($index = $tokens->count() - 3; $index > 0; --$index) {
  15778. $token = $tokens[$index];
  15779. if (!$token->isGivenKind(T_NEW)) {
  15780. continue;
  15781. }
  15782. $nextIndex = $tokens->getNextTokenOfKind($index, $nextTokenKinds);
  15783. $nextToken = $tokens[$nextIndex];
  15784. if ($nextToken->isGivenKind(T_CLASS)) {
  15785. if (!$tokens[$tokens->getNextMeaningfulToken($nextIndex)]->equals('(')) {
  15786. $this->insertBracesAfter($tokens, $nextIndex);
  15787. }
  15788. continue;
  15789. }
  15790. while ($nextToken->equals('[')) {
  15791. $nextIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $nextIndex) + 1;
  15792. $nextToken = $tokens[$nextIndex];
  15793. }
  15794. if ($nextToken->isWhitespace()) {
  15795. $nextIndex = $tokens->getNextNonWhitespace($nextIndex);
  15796. $nextToken = $tokens[$nextIndex];
  15797. }
  15798. if ($nextToken->equals('(')) {
  15799. continue;
  15800. }
  15801. $this->insertBracesAfter($tokens, $tokens->getPrevMeaningfulToken($nextIndex));
  15802. }
  15803. }
  15804. private function insertBracesAfter(Tokens $tokens, $index)
  15805. {
  15806. $tokens->insertAt(++$index, [new Token('('), new Token(')')]);
  15807. }
  15808. }
  15809. <?php
  15810. namespace PhpCsFixer\Fixer\Operator;
  15811. use PhpCsFixer\AbstractFixer;
  15812. use PhpCsFixer\FixerDefinition\CodeSample;
  15813. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15814. use PhpCsFixer\Tokenizer\Token;
  15815. use PhpCsFixer\Tokenizer\Tokens;
  15816. final class NotOperatorWithSpaceFixer extends AbstractFixer
  15817. {
  15818. public function getDefinition()
  15819. {
  15820. return new FixerDefinition(
  15821. 'Logical NOT operators (`!`) should have leading and trailing whitespaces.',
  15822. [new CodeSample(
  15823. '<?php
  15824. if (!$bar) {
  15825. echo "Help!";
  15826. }
  15827. '
  15828. )]
  15829. );
  15830. }
  15831. public function getPriority()
  15832. {
  15833. return -10;
  15834. }
  15835. public function isCandidate(Tokens $tokens)
  15836. {
  15837. return $tokens->isTokenKindFound('!');
  15838. }
  15839. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15840. {
  15841. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  15842. $token = $tokens[$index];
  15843. if ($token->equals('!')) {
  15844. if (!$tokens[$index + 1]->isWhitespace()) {
  15845. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  15846. }
  15847. if (!$tokens[$index - 1]->isWhitespace()) {
  15848. $tokens->insertAt($index, new Token([T_WHITESPACE, ' ']));
  15849. }
  15850. }
  15851. }
  15852. }
  15853. }
  15854. <?php
  15855. namespace PhpCsFixer\Fixer\Operator;
  15856. use PhpCsFixer\AbstractFixer;
  15857. use PhpCsFixer\FixerDefinition\CodeSample;
  15858. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15859. use PhpCsFixer\Tokenizer\Token;
  15860. use PhpCsFixer\Tokenizer\Tokens;
  15861. final class NotOperatorWithSuccessorSpaceFixer extends AbstractFixer
  15862. {
  15863. public function getDefinition()
  15864. {
  15865. return new FixerDefinition(
  15866. 'Logical NOT operators (`!`) should have one trailing whitespace.',
  15867. [new CodeSample(
  15868. '<?php
  15869. if (!$bar) {
  15870. echo "Help!";
  15871. }
  15872. '
  15873. )]
  15874. );
  15875. }
  15876. public function getPriority()
  15877. {
  15878. return -10;
  15879. }
  15880. public function isCandidate(Tokens $tokens)
  15881. {
  15882. return $tokens->isTokenKindFound('!');
  15883. }
  15884. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15885. {
  15886. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  15887. $token = $tokens[$index];
  15888. if ($token->equals('!')) {
  15889. if (!$tokens[$index + 1]->isWhitespace()) {
  15890. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  15891. } else {
  15892. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  15893. }
  15894. }
  15895. }
  15896. }
  15897. }
  15898. <?php
  15899. namespace PhpCsFixer\Fixer\Operator;
  15900. use PhpCsFixer\AbstractFixer;
  15901. use PhpCsFixer\FixerDefinition\CodeSample;
  15902. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15903. use PhpCsFixer\Tokenizer\Tokens;
  15904. final class ObjectOperatorWithoutWhitespaceFixer extends AbstractFixer
  15905. {
  15906. public function getDefinition()
  15907. {
  15908. return new FixerDefinition(
  15909. 'There should not be space before or after object `T_OBJECT_OPERATOR` `->`.',
  15910. [new CodeSample("<?php \$a -> b;\n")]
  15911. );
  15912. }
  15913. public function isCandidate(Tokens $tokens)
  15914. {
  15915. return $tokens->isTokenKindFound(T_OBJECT_OPERATOR);
  15916. }
  15917. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15918. {
  15919. foreach ($tokens as $index => $token) {
  15920. if (!$token->isGivenKind(T_OBJECT_OPERATOR)) {
  15921. continue;
  15922. }
  15923. if ($tokens[$index - 1]->isWhitespace(" \t") && !$tokens[$index - 2]->isComment()) {
  15924. $tokens->clearAt($index - 1);
  15925. }
  15926. if ($tokens[$index + 1]->isWhitespace(" \t") && !$tokens[$index + 2]->isComment()) {
  15927. $tokens->clearAt($index + 1);
  15928. }
  15929. }
  15930. }
  15931. }
  15932. <?php
  15933. namespace PhpCsFixer\Fixer\Operator;
  15934. use PhpCsFixer\AbstractProxyFixer;
  15935. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  15936. use PhpCsFixer\FixerDefinition\CodeSample;
  15937. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15938. final class PreIncrementFixer extends AbstractProxyFixer implements DeprecatedFixerInterface
  15939. {
  15940. public function getDefinition()
  15941. {
  15942. return new FixerDefinition(
  15943. 'Pre incrementation/decrementation should be used if possible.',
  15944. [new CodeSample("<?php\n\$a++;\n\$b--;\n")]
  15945. );
  15946. }
  15947. public function getSuccessorsNames()
  15948. {
  15949. return array_keys($this->proxyFixers);
  15950. }
  15951. protected function createProxyFixers()
  15952. {
  15953. $fixer = new IncrementStyleFixer();
  15954. $fixer->configure(['style' => 'pre']);
  15955. return [$fixer];
  15956. }
  15957. }
  15958. <?php
  15959. namespace PhpCsFixer\Fixer\Operator;
  15960. use PhpCsFixer\AbstractFixer;
  15961. use PhpCsFixer\FixerDefinition\CodeSample;
  15962. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15963. use PhpCsFixer\Tokenizer\Token;
  15964. use PhpCsFixer\Tokenizer\Tokens;
  15965. final class StandardizeNotEqualsFixer extends AbstractFixer
  15966. {
  15967. public function getDefinition()
  15968. {
  15969. return new FixerDefinition(
  15970. 'Replace all `<>` with `!=`.',
  15971. [new CodeSample("<?php\n\$a = \$b <> \$c;\n")]
  15972. );
  15973. }
  15974. public function isCandidate(Tokens $tokens)
  15975. {
  15976. return $tokens->isTokenKindFound(T_IS_NOT_EQUAL);
  15977. }
  15978. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  15979. {
  15980. foreach ($tokens as $index => $token) {
  15981. if ($token->isGivenKind(T_IS_NOT_EQUAL)) {
  15982. $tokens[$index] = new Token([T_IS_NOT_EQUAL, '!=']);
  15983. }
  15984. }
  15985. }
  15986. }
  15987. <?php
  15988. namespace PhpCsFixer\Fixer\Operator;
  15989. use PhpCsFixer\AbstractFixer;
  15990. use PhpCsFixer\FixerDefinition\CodeSample;
  15991. use PhpCsFixer\FixerDefinition\FixerDefinition;
  15992. use PhpCsFixer\Tokenizer\Token;
  15993. use PhpCsFixer\Tokenizer\Tokens;
  15994. final class TernaryOperatorSpacesFixer extends AbstractFixer
  15995. {
  15996. public function getDefinition()
  15997. {
  15998. return new FixerDefinition(
  15999. 'Standardize spaces around ternary operator.',
  16000. [new CodeSample("<?php \$a = \$a ?1 :0;\n")]
  16001. );
  16002. }
  16003. public function isCandidate(Tokens $tokens)
  16004. {
  16005. return $tokens->isAllTokenKindsFound(['?', ':']);
  16006. }
  16007. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16008. {
  16009. $ternaryLevel = 0;
  16010. foreach ($tokens as $index => $token) {
  16011. if ($token->equals('?')) {
  16012. ++$ternaryLevel;
  16013. $nextNonWhitespaceIndex = $tokens->getNextNonWhitespace($index);
  16014. $nextNonWhitespaceToken = $tokens[$nextNonWhitespaceIndex];
  16015. if ($nextNonWhitespaceToken->equals(':')) {
  16016. if ($tokens[$index + 1]->isWhitespace()) {
  16017. $tokens->clearAt($index + 1);
  16018. }
  16019. } else {
  16020. $this->ensureWhitespaceExistence($tokens, $index + 1, true);
  16021. }
  16022. $this->ensureWhitespaceExistence($tokens, $index - 1, false);
  16023. continue;
  16024. }
  16025. if ($ternaryLevel && $token->equals(':')) {
  16026. $this->ensureWhitespaceExistence($tokens, $index + 1, true);
  16027. $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)];
  16028. if (!$prevNonWhitespaceToken->equals('?')) {
  16029. $this->ensureWhitespaceExistence($tokens, $index - 1, false);
  16030. }
  16031. --$ternaryLevel;
  16032. }
  16033. }
  16034. }
  16035. private function ensureWhitespaceExistence(Tokens $tokens, $index, $after)
  16036. {
  16037. if ($tokens[$index]->isWhitespace()) {
  16038. if (
  16039. false === strpos($tokens[$index]->getContent(), "\n")
  16040. && !$tokens[$index - 1]->isComment()
  16041. ) {
  16042. $tokens[$index] = new Token([T_WHITESPACE, ' ']);
  16043. }
  16044. return;
  16045. }
  16046. $index += $after ? 0 : 1;
  16047. $tokens->insertAt($index, new Token([T_WHITESPACE, ' ']));
  16048. }
  16049. }
  16050. <?php
  16051. namespace PhpCsFixer\Fixer\Operator;
  16052. use PhpCsFixer\AbstractFixer;
  16053. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16054. use PhpCsFixer\FixerDefinition\VersionSpecification;
  16055. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  16056. use PhpCsFixer\Tokenizer\Token;
  16057. use PhpCsFixer\Tokenizer\Tokens;
  16058. final class TernaryToNullCoalescingFixer extends AbstractFixer
  16059. {
  16060. public function getDefinition()
  16061. {
  16062. return new FixerDefinition(
  16063. 'Use `null` coalescing operator `??` where possible. Requires PHP >= 7.0.',
  16064. [
  16065. new VersionSpecificCodeSample(
  16066. "<?php\n\$sample = isset(\$a) ? \$a : \$b;\n",
  16067. new VersionSpecification(70000)
  16068. ),
  16069. ]
  16070. );
  16071. }
  16072. public function isCandidate(Tokens $tokens)
  16073. {
  16074. return PHP_VERSION_ID >= 70000 && $tokens->isTokenKindFound(T_ISSET);
  16075. }
  16076. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16077. {
  16078. $issetIndexes = array_keys($tokens->findGivenKind(T_ISSET));
  16079. while ($issetIndex = array_pop($issetIndexes)) {
  16080. $this->fixIsset($tokens, $issetIndex);
  16081. }
  16082. }
  16083. private function fixIsset(Tokens $tokens, $index)
  16084. {
  16085. $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
  16086. if ($this->isHigherPrecedenceAssociativityOperator($tokens[$prevTokenIndex])) {
  16087. return;
  16088. }
  16089. $startBraceIndex = $tokens->getNextTokenOfKind($index, ['(']);
  16090. $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startBraceIndex);
  16091. $ternaryQuestionMarkIndex = $tokens->getNextMeaningfulToken($endBraceIndex);
  16092. if (!$tokens[$ternaryQuestionMarkIndex]->equals('?')) {
  16093. return;
  16094. }
  16095. $issetTokens = $this->getMeaningfulSequence($tokens, $startBraceIndex, $endBraceIndex);
  16096. if ($this->hasChangingContent($issetTokens)) {
  16097. return;
  16098. }
  16099. $ternaryColonIndex = $tokens->getNextTokenOfKind($ternaryQuestionMarkIndex, [':']);
  16100. $ternaryFirstOperandTokens = $this->getMeaningfulSequence($tokens, $ternaryQuestionMarkIndex, $ternaryColonIndex);
  16101. if ($issetTokens->generateCode() !== $ternaryFirstOperandTokens->generateCode()) {
  16102. return;
  16103. }
  16104. $ternaryFirstOperandIndex = $tokens->getNextMeaningfulToken($ternaryQuestionMarkIndex);
  16105. $comments = [];
  16106. $commentStarted = false;
  16107. for ($loopIndex = $index; $loopIndex < $ternaryFirstOperandIndex; ++$loopIndex) {
  16108. if ($tokens[$loopIndex]->isComment()) {
  16109. $comments[] = $tokens[$loopIndex];
  16110. $commentStarted = true;
  16111. } elseif ($commentStarted) {
  16112. if ($tokens[$loopIndex]->isWhitespace()) {
  16113. $comments[] = $tokens[$loopIndex];
  16114. }
  16115. $commentStarted = false;
  16116. }
  16117. }
  16118. $tokens[$ternaryColonIndex] = new Token([T_COALESCE, '??']);
  16119. $tokens->overrideRange($index, $ternaryFirstOperandIndex - 1, $comments);
  16120. }
  16121. private function getMeaningfulSequence(Tokens $tokens, $start, $end)
  16122. {
  16123. $sequence = [];
  16124. $index = $start;
  16125. while ($index < $end) {
  16126. $index = $tokens->getNextMeaningfulToken($index);
  16127. if ($index >= $end || null === $index) {
  16128. break;
  16129. }
  16130. $sequence[] = $tokens[$index];
  16131. }
  16132. return Tokens::fromArray($sequence);
  16133. }
  16134. private function isHigherPrecedenceAssociativityOperator(Token $token)
  16135. {
  16136. static $operatorsPerId = [
  16137. T_ARRAY_CAST => true,
  16138. T_BOOLEAN_AND => true,
  16139. T_BOOLEAN_OR => true,
  16140. T_BOOL_CAST => true,
  16141. T_COALESCE => true,
  16142. T_DEC => true,
  16143. T_DOUBLE_CAST => true,
  16144. T_INC => true,
  16145. T_INT_CAST => true,
  16146. T_IS_EQUAL => true,
  16147. T_IS_GREATER_OR_EQUAL => true,
  16148. T_IS_IDENTICAL => true,
  16149. T_IS_NOT_EQUAL => true,
  16150. T_IS_NOT_IDENTICAL => true,
  16151. T_IS_SMALLER_OR_EQUAL => true,
  16152. T_OBJECT_CAST => true,
  16153. T_POW => true,
  16154. T_SL => true,
  16155. T_SPACESHIP => true,
  16156. T_SR => true,
  16157. T_STRING_CAST => true,
  16158. T_UNSET_CAST => true,
  16159. ];
  16160. static $operatorsPerContent = [
  16161. '!',
  16162. '%',
  16163. '&',
  16164. '*',
  16165. '+',
  16166. '-',
  16167. '/',
  16168. ':',
  16169. '^',
  16170. '|',
  16171. '~',
  16172. ];
  16173. return isset($operatorsPerId[$token->getId()]) || $token->equalsAny($operatorsPerContent);
  16174. }
  16175. private function hasChangingContent(Tokens $tokens)
  16176. {
  16177. static $operatorsPerId = [
  16178. T_DEC,
  16179. T_INC,
  16180. T_STRING,
  16181. T_YIELD,
  16182. ];
  16183. foreach ($tokens as $token) {
  16184. if ($token->isGivenKind($operatorsPerId) || $token->equals('(')) {
  16185. return true;
  16186. }
  16187. }
  16188. return false;
  16189. }
  16190. }
  16191. <?php
  16192. namespace PhpCsFixer\Fixer\Operator;
  16193. use PhpCsFixer\AbstractFixer;
  16194. use PhpCsFixer\FixerDefinition\CodeSample;
  16195. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16196. use PhpCsFixer\Tokenizer\Tokens;
  16197. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  16198. final class UnaryOperatorSpacesFixer extends AbstractFixer
  16199. {
  16200. public function getDefinition()
  16201. {
  16202. return new FixerDefinition(
  16203. 'Unary operators should be placed adjacent to their operands.',
  16204. [new CodeSample("<?php\n\$sample ++;\n-- \$sample;\n\$sample = ! ! \$a;\n\$sample = ~ \$c;\nfunction & foo(){}\n")]
  16205. );
  16206. }
  16207. public function isCandidate(Tokens $tokens)
  16208. {
  16209. return true;
  16210. }
  16211. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16212. {
  16213. $tokensAnalyzer = new TokensAnalyzer($tokens);
  16214. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  16215. if ($tokensAnalyzer->isUnarySuccessorOperator($index)) {
  16216. if (!$tokens[$tokens->getPrevNonWhitespace($index)]->isComment()) {
  16217. $tokens->removeLeadingWhitespace($index);
  16218. }
  16219. continue;
  16220. }
  16221. if ($tokensAnalyzer->isUnaryPredecessorOperator($index)) {
  16222. $tokens->removeTrailingWhitespace($index);
  16223. continue;
  16224. }
  16225. }
  16226. }
  16227. }
  16228. <?php
  16229. namespace PhpCsFixer\Fixer\PhpTag;
  16230. use PhpCsFixer\AbstractFixer;
  16231. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  16232. use PhpCsFixer\FixerDefinition\CodeSample;
  16233. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16234. use PhpCsFixer\Tokenizer\Token;
  16235. use PhpCsFixer\Tokenizer\Tokens;
  16236. final class BlankLineAfterOpeningTagFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  16237. {
  16238. public function getDefinition()
  16239. {
  16240. return new FixerDefinition(
  16241. 'Ensure there is no code on the same line as the PHP open tag and it is followed by a blank line.',
  16242. [new CodeSample("<?php \$a = 1;\n\$b = 1;\n")]
  16243. );
  16244. }
  16245. public function getPriority()
  16246. {
  16247. return 1;
  16248. }
  16249. public function isCandidate(Tokens $tokens)
  16250. {
  16251. return $tokens->isTokenKindFound(T_OPEN_TAG);
  16252. }
  16253. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16254. {
  16255. $lineEnding = $this->whitespacesConfig->getLineEnding();
  16256. if (!$tokens[0]->isGivenKind(T_OPEN_TAG) || !$tokens->isMonolithicPhp()) {
  16257. return;
  16258. }
  16259. $newlineFound = false;
  16260. foreach ($tokens as $token) {
  16261. if ($token->isWhitespace() && false !== strpos($token->getContent(), "\n")) {
  16262. $newlineFound = true;
  16263. break;
  16264. }
  16265. }
  16266. if (!$newlineFound) {
  16267. return;
  16268. }
  16269. $token = $tokens[0];
  16270. if (false === strpos($token->getContent(), "\n")) {
  16271. $tokens[0] = new Token([$token->getId(), rtrim($token->getContent()).$lineEnding]);
  16272. }
  16273. if (!$tokens[1]->isWhitespace() && false === strpos($tokens[1]->getContent(), "\n")) {
  16274. $tokens->insertAt(1, new Token([T_WHITESPACE, $lineEnding]));
  16275. }
  16276. }
  16277. }
  16278. <?php
  16279. namespace PhpCsFixer\Fixer\PhpTag;
  16280. use PhpCsFixer\AbstractFixer;
  16281. use PhpCsFixer\FixerDefinition\CodeSample;
  16282. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16283. use PhpCsFixer\Tokenizer\Token;
  16284. use PhpCsFixer\Tokenizer\Tokens;
  16285. final class FullOpeningTagFixer extends AbstractFixer
  16286. {
  16287. public function getDefinition()
  16288. {
  16289. return new FixerDefinition(
  16290. 'PHP code must use the long `<?php` tags or short-echo `<?=` tags and not other tag variations.',
  16291. [
  16292. new CodeSample(
  16293. '<?
  16294. echo "Hello!";
  16295. '
  16296. ),
  16297. ]
  16298. );
  16299. }
  16300. public function getPriority()
  16301. {
  16302. return 98;
  16303. }
  16304. public function isCandidate(Tokens $tokens)
  16305. {
  16306. return true;
  16307. }
  16308. protected function applyFix(\SplFileInfo $file, Tokens $tokensOrg)
  16309. {
  16310. $content = $tokensOrg->generateCode();
  16311. $newContent = preg_replace('/<\?(?:phP|pHp|pHP|Php|PhP|PHp|PHP)?(\s|$)/', '<?php$1', $content, -1, $count);
  16312. if (!$count) {
  16313. return;
  16314. }
  16315. $tokens = Tokens::fromCode($newContent);
  16316. $tokensOldContent = '';
  16317. $tokensOldContentLength = 0;
  16318. foreach ($tokens as $index => $token) {
  16319. if ($token->isGivenKind(T_OPEN_TAG)) {
  16320. $tokenContent = $token->getContent();
  16321. if ('<?php' !== strtolower(substr($content, $tokensOldContentLength, 5))) {
  16322. $tokenContent = '<? ';
  16323. }
  16324. $tokensOldContent .= $tokenContent;
  16325. $tokensOldContentLength += strlen($tokenContent);
  16326. continue;
  16327. }
  16328. if ($token->isGivenKind([T_COMMENT, T_DOC_COMMENT, T_CONSTANT_ENCAPSED_STRING, T_ENCAPSED_AND_WHITESPACE, T_STRING])) {
  16329. $tokenContent = '';
  16330. $tokenContentLength = 0;
  16331. $parts = explode('<?php', $token->getContent());
  16332. $iLast = count($parts) - 1;
  16333. foreach ($parts as $i => $part) {
  16334. $tokenContent .= $part;
  16335. $tokenContentLength += strlen($part);
  16336. if ($i !== $iLast) {
  16337. $originalTokenContent = substr($content, $tokensOldContentLength + $tokenContentLength, 5);
  16338. if ('<?php' === strtolower($originalTokenContent)) {
  16339. $tokenContent .= $originalTokenContent;
  16340. $tokenContentLength += 5;
  16341. } else {
  16342. $tokenContent .= '<?';
  16343. $tokenContentLength += 2;
  16344. }
  16345. }
  16346. }
  16347. $tokens[$index] = new Token([$token->getId(), $tokenContent]);
  16348. $token = $tokens[$index];
  16349. }
  16350. $tokensOldContent .= $token->getContent();
  16351. $tokensOldContentLength += strlen($token->getContent());
  16352. }
  16353. $tokensOrg->overrideRange(0, $tokensOrg->count() - 1, $tokens);
  16354. }
  16355. }
  16356. <?php
  16357. namespace PhpCsFixer\Fixer\PhpTag;
  16358. use PhpCsFixer\AbstractFixer;
  16359. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  16360. use PhpCsFixer\FixerDefinition\CodeSample;
  16361. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16362. use PhpCsFixer\Tokenizer\Token;
  16363. use PhpCsFixer\Tokenizer\Tokens;
  16364. final class LinebreakAfterOpeningTagFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  16365. {
  16366. public function getDefinition()
  16367. {
  16368. return new FixerDefinition(
  16369. 'Ensure there is no code on the same line as the PHP open tag.',
  16370. [new CodeSample("<?php \$a = 1;\n\$b = 3;\n")]
  16371. );
  16372. }
  16373. public function isCandidate(Tokens $tokens)
  16374. {
  16375. return $tokens->isTokenKindFound(T_OPEN_TAG);
  16376. }
  16377. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16378. {
  16379. if (!$tokens[0]->isGivenKind(T_OPEN_TAG) || !$tokens->isMonolithicPhp()) {
  16380. return;
  16381. }
  16382. $newlineFound = false;
  16383. foreach ($tokens as $token) {
  16384. if ($token->isWhitespace() && false !== strpos($token->getContent(), "\n")) {
  16385. $newlineFound = true;
  16386. break;
  16387. }
  16388. }
  16389. if (!$newlineFound) {
  16390. return;
  16391. }
  16392. $token = $tokens[0];
  16393. $tokens[0] = new Token([$token->getId(), rtrim($token->getContent()).$this->whitespacesConfig->getLineEnding()]);
  16394. }
  16395. }
  16396. <?php
  16397. namespace PhpCsFixer\Fixer\PhpTag;
  16398. use PhpCsFixer\AbstractFixer;
  16399. use PhpCsFixer\FixerDefinition\CodeSample;
  16400. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16401. use PhpCsFixer\Tokenizer\Token;
  16402. use PhpCsFixer\Tokenizer\Tokens;
  16403. final class NoClosingTagFixer extends AbstractFixer
  16404. {
  16405. public function getDefinition()
  16406. {
  16407. return new FixerDefinition(
  16408. 'The closing `?>` tag MUST be omitted from files containing only PHP.',
  16409. [new CodeSample("<?php\nclass Sample\n{\n}\n?>\n")]
  16410. );
  16411. }
  16412. public function isCandidate(Tokens $tokens)
  16413. {
  16414. return $tokens->isTokenKindFound(T_CLOSE_TAG);
  16415. }
  16416. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16417. {
  16418. if (count($tokens) < 2 || !$tokens->isMonolithicPhp()) {
  16419. return;
  16420. }
  16421. if (!$tokens->isTokenKindFound(T_CLOSE_TAG)) {
  16422. return;
  16423. }
  16424. $closeTags = $tokens->findGivenKind(T_CLOSE_TAG);
  16425. $index = key($closeTags);
  16426. $tokens->removeLeadingWhitespace($index);
  16427. $tokens->clearAt($index);
  16428. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  16429. if (!$tokens[$prevIndex]->equalsAny([';', '}', [T_OPEN_TAG]])) {
  16430. $tokens->insertAt($prevIndex + 1, new Token(';'));
  16431. }
  16432. }
  16433. }
  16434. <?php
  16435. namespace PhpCsFixer\Fixer\PhpTag;
  16436. use PhpCsFixer\AbstractFixer;
  16437. use PhpCsFixer\FixerDefinition\CodeSample;
  16438. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16439. use PhpCsFixer\Tokenizer\Token;
  16440. use PhpCsFixer\Tokenizer\Tokens;
  16441. final class NoShortEchoTagFixer extends AbstractFixer
  16442. {
  16443. public function getDefinition()
  16444. {
  16445. return new FixerDefinition(
  16446. 'Replace short-echo `<?=` with long format `<?php echo` syntax.',
  16447. [new CodeSample("<?= \"foo\";\n")]
  16448. );
  16449. }
  16450. public function isCandidate(Tokens $tokens)
  16451. {
  16452. return $tokens->isTokenKindFound(T_OPEN_TAG_WITH_ECHO);
  16453. }
  16454. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16455. {
  16456. $i = count($tokens);
  16457. while ($i--) {
  16458. $token = $tokens[$i];
  16459. if (!$token->isGivenKind(T_OPEN_TAG_WITH_ECHO)) {
  16460. continue;
  16461. }
  16462. $nextIndex = $i + 1;
  16463. $tokens[$i] = new Token([T_OPEN_TAG, '<?php ']);
  16464. if (!$tokens[$nextIndex]->isWhitespace()) {
  16465. $tokens->insertAt($nextIndex, new Token([T_WHITESPACE, ' ']));
  16466. }
  16467. $tokens->insertAt($nextIndex, new Token([T_ECHO, 'echo']));
  16468. }
  16469. }
  16470. }
  16471. <?php
  16472. namespace PhpCsFixer\Fixer\PhpUnit;
  16473. use PhpCsFixer\AbstractFixer;
  16474. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  16475. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  16476. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  16477. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  16478. use PhpCsFixer\FixerDefinition\CodeSample;
  16479. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16480. use PhpCsFixer\Tokenizer\Token;
  16481. use PhpCsFixer\Tokenizer\Tokens;
  16482. final class PhpUnitConstructFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  16483. {
  16484. private static $assertionFixers = [
  16485. 'assertSame' => 'fixAssertPositive',
  16486. 'assertEquals' => 'fixAssertPositive',
  16487. 'assertNotEquals' => 'fixAssertNegative',
  16488. 'assertNotSame' => 'fixAssertNegative',
  16489. ];
  16490. public function isCandidate(Tokens $tokens)
  16491. {
  16492. return $tokens->isTokenKindFound(T_STRING);
  16493. }
  16494. public function isRisky()
  16495. {
  16496. return true;
  16497. }
  16498. public function getDefinition()
  16499. {
  16500. return new FixerDefinition(
  16501. 'PHPUnit assertion method calls like "->assertSame(true, $foo)" should be written with dedicated method like "->assertTrue($foo)".',
  16502. [
  16503. new CodeSample(
  16504. '<?php
  16505. $this->assertEquals(false, $b);
  16506. $this->assertSame(true, $a);
  16507. $this->assertNotEquals(null, $c);
  16508. $this->assertNotSame(null, $d);
  16509. '
  16510. ),
  16511. new CodeSample(
  16512. '<?php
  16513. $this->assertEquals(false, $b);
  16514. $this->assertSame(true, $a);
  16515. $this->assertNotEquals(null, $c);
  16516. $this->assertNotSame(null, $d);
  16517. ',
  16518. ['assertions' => ['assertSame', 'assertNotSame']]
  16519. ),
  16520. ],
  16521. null,
  16522. 'Fixer could be risky if one is overriding PHPUnit\'s native methods.'
  16523. );
  16524. }
  16525. public function getPriority()
  16526. {
  16527. return -10;
  16528. }
  16529. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16530. {
  16531. if (empty($this->configuration['assertions'])) {
  16532. return;
  16533. }
  16534. foreach ($this->configuration['assertions'] as $assertionMethod) {
  16535. $assertionFixer = self::$assertionFixers[$assertionMethod];
  16536. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  16537. $index = $this->{$assertionFixer}($tokens, $index, $assertionMethod);
  16538. if (null === $index) {
  16539. break;
  16540. }
  16541. }
  16542. }
  16543. }
  16544. protected function createConfigurationDefinition()
  16545. {
  16546. return new FixerConfigurationResolverRootless('assertions', [
  16547. (new FixerOptionBuilder('assertions', 'List of assertion methods to fix.'))
  16548. ->setAllowedTypes(['array'])
  16549. ->setAllowedValues([
  16550. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(array_keys(self::$assertionFixers)),
  16551. ])
  16552. ->setDefault([
  16553. 'assertEquals',
  16554. 'assertSame',
  16555. 'assertNotEquals',
  16556. 'assertNotSame',
  16557. ])
  16558. ->getOption(),
  16559. ]);
  16560. }
  16561. private function fixAssertNegative(Tokens $tokens, $index, $method)
  16562. {
  16563. static $map = [
  16564. 'false' => 'assertNotFalse',
  16565. 'null' => 'assertNotNull',
  16566. 'true' => 'assertNotTrue',
  16567. ];
  16568. return $this->fixAssert($map, $tokens, $index, $method);
  16569. }
  16570. private function fixAssertPositive(Tokens $tokens, $index, $method)
  16571. {
  16572. static $map = [
  16573. 'false' => 'assertFalse',
  16574. 'null' => 'assertNull',
  16575. 'true' => 'assertTrue',
  16576. ];
  16577. return $this->fixAssert($map, $tokens, $index, $method);
  16578. }
  16579. private function fixAssert(array $map, Tokens $tokens, $index, $method)
  16580. {
  16581. $sequence = $tokens->findSequence(
  16582. [
  16583. [T_VARIABLE, '$this'],
  16584. [T_OBJECT_OPERATOR, '->'],
  16585. [T_STRING, $method],
  16586. '(',
  16587. ],
  16588. $index
  16589. );
  16590. if (null === $sequence) {
  16591. return null;
  16592. }
  16593. $sequenceIndexes = array_keys($sequence);
  16594. $sequenceIndexes[4] = $tokens->getNextMeaningfulToken($sequenceIndexes[3]);
  16595. $firstParameterToken = $tokens[$sequenceIndexes[4]];
  16596. if (!$firstParameterToken->isNativeConstant()) {
  16597. return $sequenceIndexes[4];
  16598. }
  16599. $sequenceIndexes[5] = $tokens->getNextMeaningfulToken($sequenceIndexes[4]);
  16600. if (!$tokens[$sequenceIndexes[5]]->equals(',')) {
  16601. return $sequenceIndexes[5];
  16602. }
  16603. $tokens[$sequenceIndexes[2]] = new Token([T_STRING, $map[$firstParameterToken->getContent()]]);
  16604. $tokens->clearRange($sequenceIndexes[4], $tokens->getNextNonWhitespace($sequenceIndexes[5]) - 1);
  16605. return $sequenceIndexes[5];
  16606. }
  16607. }
  16608. <?php
  16609. namespace PhpCsFixer\Fixer\PhpUnit;
  16610. use PhpCsFixer\AbstractFixer;
  16611. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  16612. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  16613. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  16614. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  16615. use PhpCsFixer\FixerDefinition\CodeSample;
  16616. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16617. use PhpCsFixer\Tokenizer\Token;
  16618. use PhpCsFixer\Tokenizer\Tokens;
  16619. final class PhpUnitDedicateAssertFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  16620. {
  16621. private static $fixMap = [
  16622. 'array_key_exists' => ['assertArrayNotHasKey', 'assertArrayHasKey'],
  16623. 'empty' => ['assertNotEmpty', 'assertEmpty'],
  16624. 'file_exists' => ['assertFileNotExists', 'assertFileExists'],
  16625. 'is_array' => true,
  16626. 'is_bool' => true,
  16627. 'is_callable' => true,
  16628. 'is_dir' => ['assertDirectoryNotExists', 'assertDirectoryExists'],
  16629. 'is_double' => true,
  16630. 'is_float' => true,
  16631. 'is_infinite' => ['assertFinite', 'assertInfinite'],
  16632. 'is_int' => true,
  16633. 'is_integer' => true,
  16634. 'is_long' => true,
  16635. 'is_nan' => [false, 'assertNan'],
  16636. 'is_null' => ['assertNotNull', 'assertNull'],
  16637. 'is_numeric' => true,
  16638. 'is_object' => true,
  16639. 'is_readable' => ['assertNotIsReadable', 'assertIsReadable'],
  16640. 'is_real' => true,
  16641. 'is_resource' => true,
  16642. 'is_scalar' => true,
  16643. 'is_string' => true,
  16644. 'is_writable' => ['assertNotIsWritable', 'assertIsWritable'],
  16645. ];
  16646. private $functions = [];
  16647. public function configure(array $configuration = null)
  16648. {
  16649. parent::configure($configuration);
  16650. if (isset($this->configuration['functions'])) {
  16651. @trigger_error('Option "functions" is deprecated and will be removed in 3.0, use option "target" instead.', E_USER_DEPRECATED);
  16652. $this->functions = $this->configuration['functions'];
  16653. return;
  16654. }
  16655. $this->functions = [
  16656. 'array_key_exists',
  16657. 'file_exists',
  16658. 'is_null',
  16659. ];
  16660. if (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_3_5)) {
  16661. $this->functions = array_merge($this->functions, [
  16662. 'empty',
  16663. 'is_array',
  16664. 'is_bool',
  16665. 'is_boolean',
  16666. 'is_callable',
  16667. 'is_double',
  16668. 'is_float',
  16669. 'is_int',
  16670. 'is_integer',
  16671. 'is_long',
  16672. 'is_numeric',
  16673. 'is_object',
  16674. 'is_real',
  16675. 'is_resource',
  16676. 'is_scalar',
  16677. 'is_string',
  16678. ]);
  16679. }
  16680. if (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_5_0)) {
  16681. $this->functions = array_merge($this->functions, [
  16682. 'is_infinite',
  16683. 'is_nan',
  16684. ]);
  16685. }
  16686. if (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_5_6)) {
  16687. $this->functions = array_merge($this->functions, [
  16688. 'is_dir',
  16689. 'is_readable',
  16690. 'is_writable',
  16691. ]);
  16692. }
  16693. }
  16694. public function isCandidate(Tokens $tokens)
  16695. {
  16696. return $tokens->isTokenKindFound(T_STRING);
  16697. }
  16698. public function isRisky()
  16699. {
  16700. return true;
  16701. }
  16702. public function getDefinition()
  16703. {
  16704. return new FixerDefinition(
  16705. 'PHPUnit assertions like "assertInternalType", "assertFileExists", should be used over "assertTrue".',
  16706. [
  16707. new CodeSample(
  16708. '<?php
  16709. $this->assertTrue(is_float( $a), "my message");
  16710. $this->assertTrue(is_nan($a));
  16711. '
  16712. ),
  16713. new CodeSample(
  16714. '<?php
  16715. $this->assertTrue(is_dir($a));
  16716. $this->assertTrue(is_writable($a));
  16717. $this->assertTrue(is_readable($a));
  16718. ',
  16719. ['target' => PhpUnitTargetVersion::VERSION_5_6]
  16720. ),
  16721. ],
  16722. null,
  16723. 'Fixer could be risky if one is overriding PHPUnit\'s native methods.'
  16724. );
  16725. }
  16726. public function getPriority()
  16727. {
  16728. return -15;
  16729. }
  16730. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16731. {
  16732. static $searchSequence = [
  16733. [T_VARIABLE, '$this'],
  16734. [T_OBJECT_OPERATOR, '->'],
  16735. [T_STRING],
  16736. ];
  16737. $index = 1;
  16738. $candidate = $tokens->findSequence($searchSequence, $index);
  16739. while (null !== $candidate) {
  16740. end($candidate);
  16741. $index = $this->getAssertCandidate($tokens, key($candidate));
  16742. if (is_array($index)) {
  16743. $index = $this->fixAssert($tokens, $index);
  16744. }
  16745. ++$index;
  16746. $candidate = $tokens->findSequence($searchSequence, $index);
  16747. }
  16748. }
  16749. protected function createConfigurationDefinition()
  16750. {
  16751. $values = [
  16752. 'array_key_exists',
  16753. 'empty',
  16754. 'file_exists',
  16755. 'is_array',
  16756. 'is_bool',
  16757. 'is_callable',
  16758. 'is_double',
  16759. 'is_float',
  16760. 'is_infinite',
  16761. 'is_int',
  16762. 'is_integer',
  16763. 'is_long',
  16764. 'is_nan',
  16765. 'is_null',
  16766. 'is_numeric',
  16767. 'is_object',
  16768. 'is_real',
  16769. 'is_resource',
  16770. 'is_scalar',
  16771. 'is_string',
  16772. ];
  16773. sort($values);
  16774. return new FixerConfigurationResolverRootless('functions', [
  16775. (new FixerOptionBuilder('functions', '(deprecated, use `target` instead) List of assertions to fix (overrides `target`).'))
  16776. ->setAllowedTypes(['null', 'array'])
  16777. ->setAllowedValues([
  16778. null,
  16779. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf($values),
  16780. ])
  16781. ->setDefault(null)
  16782. ->getOption(),
  16783. (new FixerOptionBuilder('target', 'Target version of PHPUnit.'))
  16784. ->setAllowedTypes(['string'])
  16785. ->setAllowedValues([
  16786. PhpUnitTargetVersion::VERSION_3_0,
  16787. PhpUnitTargetVersion::VERSION_3_5,
  16788. PhpUnitTargetVersion::VERSION_5_0,
  16789. PhpUnitTargetVersion::VERSION_5_6,
  16790. PhpUnitTargetVersion::VERSION_NEWEST,
  16791. ])
  16792. ->setDefault(PhpUnitTargetVersion::VERSION_5_0)
  16793. ->getOption(),
  16794. ]);
  16795. }
  16796. private function getAssertCandidate(Tokens $tokens, $assertCallIndex)
  16797. {
  16798. $content = strtolower($tokens[$assertCallIndex]->getContent());
  16799. if ('asserttrue' === $content) {
  16800. $isPositive = 1;
  16801. } elseif ('assertfalse' === $content) {
  16802. $isPositive = 0;
  16803. } else {
  16804. return $assertCallIndex;
  16805. }
  16806. $assertCallOpenIndex = $tokens->getNextMeaningfulToken($assertCallIndex);
  16807. if (!$tokens[$assertCallOpenIndex]->equals('(')) {
  16808. return $assertCallIndex;
  16809. }
  16810. $testDefaultNamespaceTokenIndex = false;
  16811. $testIndex = $tokens->getNextMeaningfulToken($assertCallOpenIndex);
  16812. if (!$tokens[$testIndex]->isGivenKind([T_EMPTY, T_STRING])) {
  16813. if (!$tokens[$testIndex]->isGivenKind(T_NS_SEPARATOR)) {
  16814. return $testIndex;
  16815. }
  16816. $testDefaultNamespaceTokenIndex = $testIndex;
  16817. $testIndex = $tokens->getNextMeaningfulToken($testIndex);
  16818. }
  16819. $testOpenIndex = $tokens->getNextMeaningfulToken($testIndex);
  16820. if (!$tokens[$testOpenIndex]->equals('(')) {
  16821. return $testOpenIndex;
  16822. }
  16823. $testCloseIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $testOpenIndex);
  16824. $assertCallCloseIndex = $tokens->getNextMeaningfulToken($testCloseIndex);
  16825. if (!$tokens[$assertCallCloseIndex]->equalsAny([')', ','])) {
  16826. return $assertCallCloseIndex;
  16827. }
  16828. return [
  16829. $isPositive,
  16830. $assertCallIndex,
  16831. $assertCallOpenIndex,
  16832. $testDefaultNamespaceTokenIndex,
  16833. $testIndex,
  16834. $testOpenIndex,
  16835. $testCloseIndex,
  16836. $assertCallCloseIndex,
  16837. ];
  16838. }
  16839. private function fixAssert(Tokens $tokens, array $assertIndexes)
  16840. {
  16841. list(
  16842. $isPositive,
  16843. $assertCallIndex,
  16844. ,
  16845. $testDefaultNamespaceTokenIndex,
  16846. $testIndex,
  16847. $testOpenIndex,
  16848. $testCloseIndex,
  16849. $assertCallCloseIndex
  16850. ) = $assertIndexes;
  16851. $content = strtolower($tokens[$testIndex]->getContent());
  16852. if (!in_array($content, $this->functions, true)) {
  16853. return $assertCallCloseIndex;
  16854. }
  16855. if (is_array(self::$fixMap[$content])) {
  16856. if (false !== self::$fixMap[$content][$isPositive]) {
  16857. $tokens[$assertCallIndex] = new Token([T_STRING, self::$fixMap[$content][$isPositive]]);
  16858. $this->removeFunctionCall($tokens, $testDefaultNamespaceTokenIndex, $testIndex, $testOpenIndex, $testCloseIndex);
  16859. }
  16860. return $assertCallCloseIndex;
  16861. }
  16862. $type = substr($content, 3);
  16863. $tokens[$assertCallIndex] = new Token([T_STRING, $isPositive ? 'assertInternalType' : 'assertNotInternalType']);
  16864. $tokens[$testIndex] = new Token([T_CONSTANT_ENCAPSED_STRING, "'".$type."'"]);
  16865. $tokens[$testOpenIndex] = new Token(',');
  16866. $tokens->clearTokenAndMergeSurroundingWhitespace($testCloseIndex);
  16867. if (!$tokens[$testOpenIndex + 1]->isWhitespace()) {
  16868. $tokens->insertAt($testOpenIndex + 1, new Token([T_WHITESPACE, ' ']));
  16869. }
  16870. if (false !== $testDefaultNamespaceTokenIndex) {
  16871. $tokens->clearTokenAndMergeSurroundingWhitespace($testDefaultNamespaceTokenIndex);
  16872. }
  16873. return $assertCallCloseIndex;
  16874. }
  16875. private function removeFunctionCall(Tokens $tokens, $callNSIndex, $callIndex, $openIndex, $closeIndex)
  16876. {
  16877. $tokens->clearTokenAndMergeSurroundingWhitespace($callIndex);
  16878. if (false !== $callNSIndex) {
  16879. $tokens->clearTokenAndMergeSurroundingWhitespace($callNSIndex);
  16880. }
  16881. $tokens->clearTokenAndMergeSurroundingWhitespace($openIndex);
  16882. $tokens->clearTokenAndMergeSurroundingWhitespace($closeIndex);
  16883. }
  16884. }
  16885. <?php
  16886. namespace PhpCsFixer\Fixer\PhpUnit;
  16887. use PhpCsFixer\AbstractFunctionReferenceFixer;
  16888. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  16889. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  16890. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  16891. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  16892. use PhpCsFixer\FixerDefinition\CodeSample;
  16893. use PhpCsFixer\FixerDefinition\FixerDefinition;
  16894. use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator;
  16895. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  16896. use PhpCsFixer\Tokenizer\Token;
  16897. use PhpCsFixer\Tokenizer\Tokens;
  16898. final class PhpUnitExpectationFixer extends AbstractFunctionReferenceFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  16899. {
  16900. private $methodMap = [];
  16901. public function configure(array $configuration = null)
  16902. {
  16903. parent::configure($configuration);
  16904. $this->methodMap = [
  16905. 'setExpectedException' => 'expectExceptionMessage',
  16906. ];
  16907. if (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_5_6)) {
  16908. $this->methodMap['setExpectedExceptionRegExp'] = 'expectExceptionMessageRegExp';
  16909. }
  16910. }
  16911. public function getDefinition()
  16912. {
  16913. return new FixerDefinition(
  16914. 'Usages of `->setExpectedException*` methods MUST be replaced by `->expectException*` methods.',
  16915. [
  16916. new CodeSample(
  16917. '<?php
  16918. final class MyTest extends \PHPUnit_Framework_TestCase
  16919. {
  16920. public function testFoo()
  16921. {
  16922. $this->setExpectedException("RuntimeException", "Msg", 123);
  16923. foo();
  16924. }
  16925. public function testBar()
  16926. {
  16927. $this->setExpectedExceptionRegExp("RuntimeException", "/Msg.*/", 123);
  16928. bar();
  16929. }
  16930. }
  16931. '
  16932. ),
  16933. new CodeSample(
  16934. '<?php
  16935. final class MyTest extends \PHPUnit_Framework_TestCase
  16936. {
  16937. public function testFoo()
  16938. {
  16939. $this->setExpectedException("RuntimeException", null, 123);
  16940. foo();
  16941. }
  16942. public function testBar()
  16943. {
  16944. $this->setExpectedExceptionRegExp("RuntimeException", "/Msg.*/", 123);
  16945. bar();
  16946. }
  16947. }
  16948. ',
  16949. ['target' => PhpUnitTargetVersion::VERSION_5_6]
  16950. ),
  16951. new CodeSample(
  16952. '<?php
  16953. final class MyTest extends \PHPUnit_Framework_TestCase
  16954. {
  16955. public function testFoo()
  16956. {
  16957. $this->setExpectedException("RuntimeException", "Msg", 123);
  16958. foo();
  16959. }
  16960. public function testBar()
  16961. {
  16962. $this->setExpectedExceptionRegExp("RuntimeException", "/Msg.*/", 123);
  16963. bar();
  16964. }
  16965. }
  16966. ',
  16967. ['target' => PhpUnitTargetVersion::VERSION_5_2]
  16968. ),
  16969. ],
  16970. null,
  16971. 'Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.'
  16972. );
  16973. }
  16974. public function isCandidate(Tokens $tokens)
  16975. {
  16976. return $tokens->isTokenKindFound(T_CLASS);
  16977. }
  16978. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  16979. {
  16980. $argumentsAnalyzer = new ArgumentsAnalyzer();
  16981. $phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator();
  16982. $oldMethodSequence = [
  16983. new Token([T_VARIABLE, '$this']),
  16984. new Token([T_OBJECT_OPERATOR, '->']),
  16985. [T_STRING],
  16986. ];
  16987. $inPhpUnitClass = false;
  16988. for ($index = 0, $limit = $tokens->count() - 1; $index < $limit; ++$index) {
  16989. if (!$inPhpUnitClass && $tokens[$index]->isGivenKind(T_CLASS) && $phpUnitTestCaseIndicator->isPhpUnitClass($tokens, $index)) {
  16990. $inPhpUnitClass = true;
  16991. }
  16992. if (!$inPhpUnitClass) {
  16993. continue;
  16994. }
  16995. $match = $tokens->findSequence($oldMethodSequence, $index);
  16996. if (null === $match) {
  16997. return;
  16998. }
  16999. list($thisIndex, , $index) = array_keys($match);
  17000. if (!isset($this->methodMap[$tokens[$index]->getContent()])) {
  17001. continue;
  17002. }
  17003. $openIndex = $tokens->getNextTokenOfKind($index, ['(']);
  17004. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
  17005. $arguments = $argumentsAnalyzer->getArguments($tokens, $openIndex, $closeIndex);
  17006. $argumentsCnt = count($arguments);
  17007. $argumentsReplacements = ['expectException', $this->methodMap[$tokens[$index]->getContent()], 'expectExceptionCode'];
  17008. $indent = $this->whitespacesConfig->getLineEnding().$this->detectIndent($tokens, $thisIndex);
  17009. $isMultilineWhitespace = false;
  17010. for ($cnt = $argumentsCnt - 1; $cnt >= 1; --$cnt) {
  17011. $argStart = array_keys($arguments)[$cnt];
  17012. $argBefore = $tokens->getPrevMeaningfulToken($argStart);
  17013. if ('expectExceptionMessage' === $argumentsReplacements[$cnt]) {
  17014. $paramIndicatorIndex = $tokens->getNextMeaningfulToken($argBefore);
  17015. $afterParamIndicatorIndex = $tokens->getNextMeaningfulToken($paramIndicatorIndex);
  17016. if (
  17017. $tokens[$paramIndicatorIndex]->equals([T_STRING, 'null'], false) &&
  17018. $tokens[$afterParamIndicatorIndex]->equals(')')
  17019. ) {
  17020. if ($tokens[$argBefore + 1]->isWhitespace()) {
  17021. $tokens->clearTokenAndMergeSurroundingWhitespace($argBefore + 1);
  17022. }
  17023. $tokens->clearTokenAndMergeSurroundingWhitespace($argBefore);
  17024. $tokens->clearTokenAndMergeSurroundingWhitespace($paramIndicatorIndex);
  17025. continue;
  17026. }
  17027. }
  17028. $isMultilineWhitespace = $isMultilineWhitespace || ($tokens[$argStart]->isWhitespace() && !$tokens[$argStart]->isWhitespace(" \t"));
  17029. $tokensOverrideArgStart = [
  17030. new Token([T_WHITESPACE, $indent]),
  17031. new Token([T_VARIABLE, '$this']),
  17032. new Token([T_OBJECT_OPERATOR, '->']),
  17033. new Token([T_STRING, $argumentsReplacements[$cnt]]),
  17034. new Token('('),
  17035. ];
  17036. $tokensOverrideArgBefore = [
  17037. new Token(')'),
  17038. new Token(';'),
  17039. ];
  17040. if ($isMultilineWhitespace) {
  17041. array_push($tokensOverrideArgStart, new Token([T_WHITESPACE, $indent.$this->whitespacesConfig->getIndent()]));
  17042. array_unshift($tokensOverrideArgBefore, new Token([T_WHITESPACE, $indent]));
  17043. }
  17044. if ($tokens[$argStart]->isWhitespace()) {
  17045. $tokens->overrideRange($argStart, $argStart, $tokensOverrideArgStart);
  17046. } else {
  17047. $tokens->insertAt($argStart, $tokensOverrideArgStart);
  17048. }
  17049. $tokens->overrideRange($argBefore, $argBefore, $tokensOverrideArgBefore);
  17050. $limit = $tokens->count();
  17051. }
  17052. $tokens[$index] = new Token([T_STRING, 'expectException']);
  17053. }
  17054. }
  17055. protected function createConfigurationDefinition()
  17056. {
  17057. return new FixerConfigurationResolver([
  17058. (new FixerOptionBuilder('target', 'Target version of PHPUnit.'))
  17059. ->setAllowedTypes(['string'])
  17060. ->setAllowedValues([PhpUnitTargetVersion::VERSION_5_2, PhpUnitTargetVersion::VERSION_5_6, PhpUnitTargetVersion::VERSION_NEWEST])
  17061. ->setDefault(PhpUnitTargetVersion::VERSION_NEWEST)
  17062. ->getOption(),
  17063. ]);
  17064. }
  17065. private function detectIndent(Tokens $tokens, $index)
  17066. {
  17067. if (!$tokens[$index - 1]->isWhitespace()) {
  17068. return '';
  17069. }
  17070. $explodedContent = explode("\n", $tokens[$index - 1]->getContent());
  17071. return end($explodedContent);
  17072. }
  17073. }
  17074. <?php
  17075. namespace PhpCsFixer\Fixer\PhpUnit;
  17076. use PhpCsFixer\AbstractFixer;
  17077. use PhpCsFixer\FixerDefinition\CodeSample;
  17078. use PhpCsFixer\FixerDefinition\FixerDefinition;
  17079. use PhpCsFixer\Tokenizer\Token;
  17080. use PhpCsFixer\Tokenizer\Tokens;
  17081. final class PhpUnitFqcnAnnotationFixer extends AbstractFixer
  17082. {
  17083. public function getDefinition()
  17084. {
  17085. return new FixerDefinition(
  17086. 'PHPUnit annotations should be a FQCNs including a root namespace.',
  17087. [new CodeSample(
  17088. '<?php
  17089. final class MyTest extends \PHPUnit_Framework_TestCase
  17090. {
  17091. /**
  17092. * @expectedException InvalidArgumentException
  17093. * @covers Project\NameSpace\Something
  17094. * @coversDefaultClass Project\Default
  17095. * @uses Project\Test\Util
  17096. */
  17097. public function testSomeTest()
  17098. {
  17099. }
  17100. }
  17101. '
  17102. )]
  17103. );
  17104. }
  17105. public function getPriority()
  17106. {
  17107. return -9;
  17108. }
  17109. public function isCandidate(Tokens $tokens)
  17110. {
  17111. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  17112. }
  17113. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  17114. {
  17115. foreach ($tokens as $index => $token) {
  17116. if ($token->isGivenKind(T_DOC_COMMENT)) {
  17117. $tokens[$index] = new Token([T_DOC_COMMENT, preg_replace(
  17118. '~^(\s*\*\s*@(?:expectedException|covers|coversDefaultClass|uses)\h+)(\w.*)$~m',
  17119. '$1\\\\$2',
  17120. $token->getContent()
  17121. )]);
  17122. }
  17123. }
  17124. }
  17125. }
  17126. <?php
  17127. namespace PhpCsFixer\Fixer\PhpUnit;
  17128. use PhpCsFixer\AbstractFixer;
  17129. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  17130. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  17131. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  17132. use PhpCsFixer\FixerDefinition\CodeSample;
  17133. use PhpCsFixer\FixerDefinition\FixerDefinition;
  17134. use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator;
  17135. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  17136. use PhpCsFixer\Tokenizer\Token;
  17137. use PhpCsFixer\Tokenizer\Tokens;
  17138. final class PhpUnitMockFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  17139. {
  17140. private $fixCreatePartialMock;
  17141. public function getDefinition()
  17142. {
  17143. return new FixerDefinition(
  17144. 'Usages of `->getMock` and `->getMockWithoutInvokingTheOriginalConstructor` methods MUST be replaced by `->createMock` or `->createPartialMock` methods.',
  17145. [
  17146. new CodeSample(
  17147. '<?php
  17148. final class MyTest extends \PHPUnit_Framework_TestCase
  17149. {
  17150. public function testFoo()
  17151. {
  17152. $mock = $this->getMockWithoutInvokingTheOriginalConstructor("Foo");
  17153. $mock1 = $this->getMock("Foo");
  17154. $mock1 = $this->getMock("Bar", ["aaa"]);
  17155. $mock1 = $this->getMock("Baz", ["aaa"], ["argument"]); // version with more than 2 params is not supported
  17156. }
  17157. }
  17158. '
  17159. ),
  17160. new CodeSample(
  17161. '<?php
  17162. final class MyTest extends \PHPUnit_Framework_TestCase
  17163. {
  17164. public function testFoo()
  17165. {
  17166. $mock1 = $this->getMock("Foo");
  17167. $mock1 = $this->getMock("Bar", ["aaa"]); // version with multiple params is not supported
  17168. }
  17169. }
  17170. ',
  17171. ['target' => PhpUnitTargetVersion::VERSION_5_4]
  17172. ),
  17173. ],
  17174. null,
  17175. 'Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.'
  17176. );
  17177. }
  17178. public function isCandidate(Tokens $tokens)
  17179. {
  17180. return $tokens->isTokenKindFound(T_CLASS);
  17181. }
  17182. public function isRisky()
  17183. {
  17184. return true;
  17185. }
  17186. public function configure(array $configuration = null)
  17187. {
  17188. parent::configure($configuration);
  17189. $this->fixCreatePartialMock = PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_5_5);
  17190. }
  17191. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  17192. {
  17193. $phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator();
  17194. $argumentsAnalyzer = new ArgumentsAnalyzer();
  17195. $inPhpUnitClass = false;
  17196. for ($index = 0, $limit = $tokens->count() - 1; $index < $limit; ++$index) {
  17197. if (!$inPhpUnitClass && $tokens[$index]->isGivenKind(T_CLASS) && $phpUnitTestCaseIndicator->isPhpUnitClass($tokens, $index)) {
  17198. $inPhpUnitClass = true;
  17199. }
  17200. if (!$inPhpUnitClass) {
  17201. continue;
  17202. }
  17203. if (!$tokens[$index]->isGivenKind(T_OBJECT_OPERATOR)) {
  17204. continue;
  17205. }
  17206. $index = $tokens->getNextMeaningfulToken($index);
  17207. if ($tokens[$index]->equals([T_STRING, 'getMockWithoutInvokingTheOriginalConstructor'], false)) {
  17208. $tokens[$index] = new Token([T_STRING, 'createMock']);
  17209. } elseif ($tokens[$index]->equals([T_STRING, 'getMock'], false)) {
  17210. $openingParenthesis = $tokens->getNextMeaningfulToken($index);
  17211. $closingParenthesis = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openingParenthesis);
  17212. $argumentsCount = $argumentsAnalyzer->countArguments($tokens, $openingParenthesis, $closingParenthesis);
  17213. if (1 === $argumentsCount) {
  17214. $tokens[$index] = new Token([T_STRING, 'createMock']);
  17215. } elseif (2 === $argumentsCount && true === $this->fixCreatePartialMock) {
  17216. $tokens[$index] = new Token([T_STRING, 'createPartialMock']);
  17217. }
  17218. }
  17219. }
  17220. }
  17221. protected function createConfigurationDefinition()
  17222. {
  17223. return new FixerConfigurationResolver([
  17224. (new FixerOptionBuilder('target', 'Target version of PHPUnit.'))
  17225. ->setAllowedTypes(['string'])
  17226. ->setAllowedValues([PhpUnitTargetVersion::VERSION_5_4, PhpUnitTargetVersion::VERSION_5_5, PhpUnitTargetVersion::VERSION_NEWEST])
  17227. ->setDefault(PhpUnitTargetVersion::VERSION_NEWEST)
  17228. ->getOption(),
  17229. ]);
  17230. }
  17231. }
  17232. <?php
  17233. namespace PhpCsFixer\Fixer\PhpUnit;
  17234. use PhpCsFixer\AbstractFixer;
  17235. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  17236. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  17237. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  17238. use PhpCsFixer\FixerDefinition\CodeSample;
  17239. use PhpCsFixer\FixerDefinition\FixerDefinition;
  17240. use PhpCsFixer\Tokenizer\Token;
  17241. use PhpCsFixer\Tokenizer\Tokens;
  17242. final class PhpUnitNamespacedFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  17243. {
  17244. private $originalClassRegEx;
  17245. public function getDefinition()
  17246. {
  17247. return new FixerDefinition(
  17248. 'PHPUnit classes MUST be used in namespaced version, eg `\PHPUnit\Framework\TestCase` instead of `\PHPUnit_Framework_TestCase`.',
  17249. [
  17250. new CodeSample(
  17251. '<?php
  17252. final class MyTest extends \PHPUnit_Framework_TestCase
  17253. {
  17254. }
  17255. '
  17256. ),
  17257. ],
  17258. "PHPUnit v6 has finally fully switched to namespaces.\n"
  17259. ."You could start preparing the upgrade by switching from non-namespaced TestCase to namespaced one.\n"
  17260. .'Forward compatibility layer (`\PHPUnit\Framework\TestCase` class) was backported to PHPUnit v4.8.35 and PHPUnit v5.4.0.'."\n"
  17261. .'Extended forward compatibility layer (`PHPUnit\Framework\Assert`, `PHPUnit\Framework\BaseTestListener`, `PHPUnit\Framework\TestListener` classes) was introduced in v5.7.0.'."\n",
  17262. 'Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.'
  17263. );
  17264. }
  17265. public function isCandidate(Tokens $tokens)
  17266. {
  17267. return $tokens->isTokenKindFound(T_STRING);
  17268. }
  17269. public function isRisky()
  17270. {
  17271. return true;
  17272. }
  17273. public function configure(array $configuration = null)
  17274. {
  17275. parent::configure($configuration);
  17276. if (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_6_0)) {
  17277. $this->originalClassRegEx = '/^PHPUnit_\w+$/i';
  17278. } elseif (PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_5_7)) {
  17279. $this->originalClassRegEx = '/^PHPUnit_Framework_TestCase|PHPUnit_Framework_Assert|PHPUnit_Framework_BaseTestListener|PHPUnit_Framework_TestListener$/i';
  17280. } else {
  17281. $this->originalClassRegEx = '/^PHPUnit_Framework_TestCase$/i';
  17282. }
  17283. }
  17284. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  17285. {
  17286. $importedOriginalClassesMap = [];
  17287. $currIndex = 0;
  17288. while (null !== $currIndex) {
  17289. $currIndex = $tokens->getNextTokenOfKind($currIndex, [[T_STRING]]);
  17290. if (null === $currIndex) {
  17291. break;
  17292. }
  17293. $originalClass = $tokens[$currIndex]->getContent();
  17294. if (1 !== preg_match($this->originalClassRegEx, $originalClass)) {
  17295. ++$currIndex;
  17296. continue;
  17297. }
  17298. $substituteTokens = $this->generateReplacement($originalClass);
  17299. $tokens->clearAt($currIndex);
  17300. $tokens->insertAt(
  17301. $currIndex,
  17302. isset($importedOriginalClassesMap[$originalClass]) ? $substituteTokens[$substituteTokens->getSize() - 1] : $substituteTokens
  17303. );
  17304. $prevIndex = $tokens->getPrevMeaningfulToken($currIndex);
  17305. if ($tokens[$prevIndex]->isGivenKind(T_USE)) {
  17306. $importedOriginalClassesMap[$originalClass] = true;
  17307. } elseif ($tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
  17308. $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
  17309. if ($tokens[$prevIndex]->isGivenKind(T_USE)) {
  17310. $importedOriginalClassesMap[$originalClass] = true;
  17311. }
  17312. }
  17313. }
  17314. }
  17315. protected function createConfigurationDefinition()
  17316. {
  17317. return new FixerConfigurationResolver([
  17318. (new FixerOptionBuilder('target', 'Target version of PHPUnit.'))
  17319. ->setAllowedTypes(['string'])
  17320. ->setAllowedValues([PhpUnitTargetVersion::VERSION_4_8, PhpUnitTargetVersion::VERSION_5_7, PhpUnitTargetVersion::VERSION_6_0, PhpUnitTargetVersion::VERSION_NEWEST])
  17321. ->setDefault(PhpUnitTargetVersion::VERSION_NEWEST)
  17322. ->getOption(),
  17323. ]);
  17324. }
  17325. private function generateReplacement($originalClassName)
  17326. {
  17327. $parts = explode('_', $originalClassName);
  17328. $tokensArray = [];
  17329. while (!empty($parts)) {
  17330. $tokensArray[] = new Token([T_STRING, array_shift($parts)]);
  17331. if (!empty($parts)) {
  17332. $tokensArray[] = new Token([T_NS_SEPARATOR, '\\']);
  17333. }
  17334. }
  17335. return Tokens::fromArray($tokensArray);
  17336. }
  17337. }
  17338. <?php
  17339. namespace PhpCsFixer\Fixer\PhpUnit;
  17340. use PhpCsFixer\AbstractFixer;
  17341. use PhpCsFixer\DocBlock\Annotation;
  17342. use PhpCsFixer\DocBlock\DocBlock;
  17343. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  17344. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  17345. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  17346. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  17347. use PhpCsFixer\FixerDefinition\CodeSample;
  17348. use PhpCsFixer\FixerDefinition\FixerDefinition;
  17349. use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator;
  17350. use PhpCsFixer\Tokenizer\Token;
  17351. use PhpCsFixer\Tokenizer\Tokens;
  17352. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  17353. final class PhpUnitNoExpectationAnnotationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  17354. {
  17355. private $fixMessageRegExp;
  17356. public function configure(array $configuration = null)
  17357. {
  17358. parent::configure($configuration);
  17359. $this->fixMessageRegExp = PhpUnitTargetVersion::fulfills($this->configuration['target'], PhpUnitTargetVersion::VERSION_4_3);
  17360. }
  17361. public function getDefinition()
  17362. {
  17363. return new FixerDefinition(
  17364. 'Usages of `@expectedException*` annotations MUST be replaced by `->setExpectedException*` methods.',
  17365. [
  17366. new CodeSample(
  17367. '<?php
  17368. final class MyTest extends \PHPUnit_Framework_TestCase
  17369. {
  17370. /**
  17371. * @expectedException FooException
  17372. * @expectedExceptionMessageRegExp /foo.*$/
  17373. * @expectedExceptionCode 123
  17374. */
  17375. function testAaa()
  17376. {
  17377. aaa();
  17378. }
  17379. }
  17380. '
  17381. ),
  17382. new CodeSample(
  17383. '<?php
  17384. final class MyTest extends \PHPUnit_Framework_TestCase
  17385. {
  17386. /**
  17387. * @expectedException FooException
  17388. * @expectedExceptionCode 123
  17389. */
  17390. function testBbb()
  17391. {
  17392. bbb();
  17393. }
  17394. /**
  17395. * @expectedException FooException
  17396. * @expectedExceptionMessageRegExp /foo.*$/
  17397. */
  17398. function testCcc()
  17399. {
  17400. ccc();
  17401. }
  17402. }
  17403. ',
  17404. ['target' => PhpUnitTargetVersion::VERSION_3_2]
  17405. ),
  17406. ],
  17407. null,
  17408. 'Risky when PHPUnit classes are overridden or not accessible, or when project has PHPUnit incompatibilities.'
  17409. );
  17410. }
  17411. public function getPriority()
  17412. {
  17413. return 10;
  17414. }
  17415. public function isCandidate(Tokens $tokens)
  17416. {
  17417. return $tokens->isAllTokenKindsFound([T_CLASS, T_DOC_COMMENT]);
  17418. }
  17419. public function isRisky()
  17420. {
  17421. return true;
  17422. }
  17423. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  17424. {
  17425. foreach (array_reverse($this->findPhpUnitClasses($tokens)) as $indexes) {
  17426. $this->fixPhpUnitClass($tokens, $indexes[0], $indexes[1]);
  17427. }
  17428. }
  17429. protected function createConfigurationDefinition()
  17430. {
  17431. return new FixerConfigurationResolver([
  17432. (new FixerOptionBuilder('target', 'Target version of PHPUnit.'))
  17433. ->setAllowedTypes(['string'])
  17434. ->setAllowedValues([PhpUnitTargetVersion::VERSION_3_2, PhpUnitTargetVersion::VERSION_4_3, PhpUnitTargetVersion::VERSION_NEWEST])
  17435. ->setDefault(PhpUnitTargetVersion::VERSION_NEWEST)
  17436. ->getOption(),
  17437. (new FixerOptionBuilder('use_class_const', 'Use ::class notation.'))
  17438. ->setAllowedTypes(['bool'])
  17439. ->setDefault(true)
  17440. ->getOption(),
  17441. ]);
  17442. }
  17443. private function detectIndent(Tokens $tokens, $index)
  17444. {
  17445. if (!$tokens[$index - 1]->isWhitespace()) {
  17446. return '';
  17447. }
  17448. $explodedContent = explode("\n", $tokens[$index - 1]->getContent());
  17449. return end($explodedContent);
  17450. }
  17451. private function findPhpUnitClasses(Tokens $tokens)
  17452. {
  17453. $phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator();
  17454. $phpunitClasses = [];
  17455. for ($index = 0, $limit = $tokens->count() - 1; $index < $limit; ++$index) {
  17456. if ($tokens[$index]->isGivenKind(T_CLASS) && $phpUnitTestCaseIndicator->isPhpUnitClass($tokens, $index)) {
  17457. $index = $tokens->getNextTokenOfKind($index, ['{']);
  17458. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  17459. $phpunitClasses[] = [$index, $endIndex];
  17460. $index = $endIndex;
  17461. }
  17462. }
  17463. return $phpunitClasses;
  17464. }
  17465. private function fixPhpUnitClass(Tokens $tokens, $startIndex, $endIndex)
  17466. {
  17467. $tokensAnalyzer = new TokensAnalyzer($tokens);
  17468. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  17469. if (!$tokens[$i]->isGivenKind(T_FUNCTION) || $tokensAnalyzer->isLambda($i)) {
  17470. continue;
  17471. }
  17472. $functionIndex = $i;
  17473. $docBlockIndex = $i;
  17474. $braceIndex = $tokens->getNextTokenOfKind($functionIndex, [';', '{']);
  17475. if (!$tokens[$braceIndex]->equals('{')) {
  17476. continue;
  17477. }
  17478. do {
  17479. $docBlockIndex = $tokens->getPrevNonWhitespace($docBlockIndex);
  17480. } while ($tokens[$docBlockIndex]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_COMMENT]));
  17481. if (!$tokens[$docBlockIndex]->isGivenKind(T_DOC_COMMENT)) {
  17482. continue;
  17483. }
  17484. $doc = new DocBlock($tokens[$docBlockIndex]->getContent());
  17485. $annotations = [];
  17486. foreach ($doc->getAnnotationsOfType([
  17487. 'expectedException',
  17488. 'expectedExceptionCode',
  17489. 'expectedExceptionMessage',
  17490. 'expectedExceptionMessageRegExp',
  17491. ]) as $annotation) {
  17492. $tag = $annotation->getTag()->getName();
  17493. $content = $this->extractContentFromAnnotation($annotation);
  17494. $annotations[$tag] = $content;
  17495. $annotation->remove();
  17496. }
  17497. if (!isset($annotations['expectedException'])) {
  17498. continue;
  17499. }
  17500. if (!$this->fixMessageRegExp && isset($annotations['expectedExceptionMessageRegExp'])) {
  17501. continue;
  17502. }
  17503. $originalIndent = $this->detectIndent($tokens, $docBlockIndex);
  17504. $paramList = $this->annotationsToParamList($annotations);
  17505. $newMethodsCode = '<?php $this->'
  17506. .(isset($annotations['expectedExceptionMessageRegExp']) ? 'setExpectedExceptionRegExp' : 'setExpectedException')
  17507. .'('
  17508. .implode($paramList, ', ')
  17509. .');';
  17510. $newMethods = Tokens::fromCode($newMethodsCode);
  17511. $newMethods[0] = new Token([
  17512. T_WHITESPACE,
  17513. $this->whitespacesConfig->getLineEnding().$originalIndent.$this->whitespacesConfig->getIndent(),
  17514. ]);
  17515. $tokens[$docBlockIndex] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  17516. $tokens->insertAt($braceIndex + 1, $newMethods);
  17517. $tokens[$braceIndex + $newMethods->getSize() + 1] = new Token([
  17518. T_WHITESPACE,
  17519. $this->whitespacesConfig->getLineEnding().$tokens[$braceIndex + $newMethods->getSize() + 1]->getContent(),
  17520. ]);
  17521. $i = $docBlockIndex;
  17522. }
  17523. }
  17524. private function extractContentFromAnnotation(Annotation $annotation)
  17525. {
  17526. $tag = $annotation->getTag()->getName();
  17527. preg_match('/^\s*\*\s*@'.$tag.'\s+(.+)$/s', $annotation->getContent(), $matches);
  17528. $content = $matches[1];
  17529. if (preg_match('/\R/u', $content)) {
  17530. $content = preg_replace('/\s*\R+\s*\*\s*/u', ' ', $content);
  17531. }
  17532. return rtrim($content);
  17533. }
  17534. private function annotationsToParamList(array $annotations)
  17535. {
  17536. $params = [];
  17537. $exceptionClass = '\\'.ltrim($annotations['expectedException'], '\\');
  17538. if ($this->configuration['use_class_const']) {
  17539. $params[] = $exceptionClass.'::class';
  17540. } else {
  17541. $params[] = "'${exceptionClass}'";
  17542. }
  17543. if (isset($annotations['expectedExceptionMessage'])) {
  17544. $params[] = var_export($annotations['expectedExceptionMessage'], true);
  17545. } elseif (isset($annotations['expectedExceptionMessageRegExp'])) {
  17546. $params[] = var_export($annotations['expectedExceptionMessageRegExp'], true);
  17547. } elseif (isset($annotations['expectedExceptionCode'])) {
  17548. $params[] = 'null';
  17549. }
  17550. if (isset($annotations['expectedExceptionCode'])) {
  17551. $params[] = $annotations['expectedExceptionCode'];
  17552. }
  17553. return $params;
  17554. }
  17555. }
  17556. <?php
  17557. namespace PhpCsFixer\Fixer\PhpUnit;
  17558. use PhpCsFixer\AbstractFixer;
  17559. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  17560. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  17561. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  17562. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  17563. use PhpCsFixer\FixerDefinition\CodeSample;
  17564. use PhpCsFixer\FixerDefinition\FixerDefinition;
  17565. use PhpCsFixer\Tokenizer\Token;
  17566. use PhpCsFixer\Tokenizer\Tokens;
  17567. final class PhpUnitStrictFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  17568. {
  17569. private static $assertionMap = [
  17570. 'assertAttributeEquals' => 'assertAttributeSame',
  17571. 'assertAttributeNotEquals' => 'assertAttributeNotSame',
  17572. 'assertEquals' => 'assertSame',
  17573. 'assertNotEquals' => 'assertNotSame',
  17574. ];
  17575. public function getDefinition()
  17576. {
  17577. return new FixerDefinition(
  17578. 'PHPUnit methods like `assertSame` should be used instead of `assertEquals`.',
  17579. [
  17580. new CodeSample(
  17581. '<?php
  17582. final class MyTest extends \PHPUnit_Framework_TestCase
  17583. {
  17584. public function testSomeTest()
  17585. {
  17586. $this->assertAttributeEquals(a(), b());
  17587. $this->assertAttributeNotEquals(a(), b());
  17588. $this->assertEquals(a(), b());
  17589. $this->assertNotEquals(a(), b());
  17590. }
  17591. }
  17592. '
  17593. ),
  17594. new CodeSample(
  17595. '<?php
  17596. final class MyTest extends \PHPUnit_Framework_TestCase
  17597. {
  17598. public function testSomeTest()
  17599. {
  17600. $this->assertAttributeEquals(a(), b());
  17601. $this->assertAttributeNotEquals(a(), b());
  17602. $this->assertEquals(a(), b());
  17603. $this->assertNotEquals(a(), b());
  17604. }
  17605. }
  17606. ',
  17607. ['assertions' => ['assertEquals']]
  17608. ),
  17609. ],
  17610. null,
  17611. 'Risky when any of the functions are overridden.'
  17612. );
  17613. }
  17614. public function isCandidate(Tokens $tokens)
  17615. {
  17616. return $tokens->isTokenKindFound(T_STRING);
  17617. }
  17618. public function isRisky()
  17619. {
  17620. return true;
  17621. }
  17622. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  17623. {
  17624. foreach ($this->configuration['assertions'] as $methodBefore) {
  17625. $methodAfter = self::$assertionMap[$methodBefore];
  17626. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  17627. $sequence = $tokens->findSequence(
  17628. [
  17629. [T_VARIABLE, '$this'],
  17630. [T_OBJECT_OPERATOR, '->'],
  17631. [T_STRING, $methodBefore],
  17632. '(',
  17633. ],
  17634. $index
  17635. );
  17636. if (null === $sequence) {
  17637. break;
  17638. }
  17639. $sequenceIndexes = array_keys($sequence);
  17640. $tokens[$sequenceIndexes[2]] = new Token([T_STRING, $methodAfter]);
  17641. $index = $sequenceIndexes[3];
  17642. }
  17643. }
  17644. }
  17645. protected function createConfigurationDefinition()
  17646. {
  17647. return new FixerConfigurationResolverRootless('assertions', [
  17648. (new FixerOptionBuilder('assertions', 'List of assertion methods to fix.'))
  17649. ->setAllowedTypes(['array'])
  17650. ->setAllowedValues([
  17651. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(array_keys(self::$assertionMap)),
  17652. ])
  17653. ->setDefault([
  17654. 'assertAttributeEquals',
  17655. 'assertAttributeNotEquals',
  17656. 'assertEquals',
  17657. 'assertNotEquals',
  17658. ])
  17659. ->getOption(),
  17660. ]);
  17661. }
  17662. }
  17663. <?php
  17664. namespace PhpCsFixer\Fixer\PhpUnit;
  17665. use Composer\Semver\Comparator;
  17666. final class PhpUnitTargetVersion
  17667. {
  17668. const VERSION_3_0 = '3.0';
  17669. const VERSION_3_2 = '3.2';
  17670. const VERSION_3_5 = '3.5';
  17671. const VERSION_4_3 = '4.3';
  17672. const VERSION_4_8 = '4.8';
  17673. const VERSION_5_0 = '5.0';
  17674. const VERSION_5_2 = '5.2';
  17675. const VERSION_5_4 = '5.4';
  17676. const VERSION_5_5 = '5.5';
  17677. const VERSION_5_6 = '5.6';
  17678. const VERSION_5_7 = '5.7';
  17679. const VERSION_6_0 = '6.0';
  17680. const VERSION_NEWEST = 'newest';
  17681. private function __construct()
  17682. {
  17683. }
  17684. public static function fulfills($candidate, $target)
  17685. {
  17686. if (self::VERSION_NEWEST === $target) {
  17687. throw new \LogicException(sprintf('Parameter `target` shall not be provided as `%s`, determine proper target for tested PHPUnit feature instead.', self::VERSION_NEWEST));
  17688. }
  17689. if (self::VERSION_NEWEST === $candidate) {
  17690. return true;
  17691. }
  17692. return Comparator::greaterThanOrEqualTo($candidate, $target);
  17693. }
  17694. }
  17695. <?php
  17696. namespace PhpCsFixer\Fixer\PhpUnit;
  17697. use PhpCsFixer\AbstractFixer;
  17698. use PhpCsFixer\DocBlock\DocBlock;
  17699. use PhpCsFixer\DocBlock\Line;
  17700. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  17701. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  17702. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  17703. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  17704. use PhpCsFixer\FixerDefinition\CodeSample;
  17705. use PhpCsFixer\FixerDefinition\FixerDefinition;
  17706. use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator;
  17707. use PhpCsFixer\Tokenizer\Token;
  17708. use PhpCsFixer\Tokenizer\Tokens;
  17709. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  17710. final class PhpUnitTestAnnotationFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  17711. {
  17712. public function isRisky()
  17713. {
  17714. return true;
  17715. }
  17716. public function getDefinition()
  17717. {
  17718. return new FixerDefinition(
  17719. 'Adds or removes @test annotations from tests, following configuration.',
  17720. [
  17721. new CodeSample('<?php
  17722. class Test extends \\PhpUnit\\FrameWork\\TestCase
  17723. {
  17724. /**
  17725. * @test
  17726. */
  17727. public function itDoesSomething() {} }'.$this->whitespacesConfig->getLineEnding()),
  17728. new CodeSample('<?php
  17729. class Test extends \\PhpUnit\\FrameWork\\TestCase
  17730. {
  17731. public function testItDoesSomething() {}}'.$this->whitespacesConfig->getLineEnding(), ['style' => 'annotation']),
  17732. ],
  17733. null,
  17734. 'This fixer may change the name of your tests, and could cause incompatibility with'.
  17735. ' abstract classes or interfaces.'
  17736. );
  17737. }
  17738. public function getPriority()
  17739. {
  17740. return 10;
  17741. }
  17742. public function isCandidate(Tokens $tokens)
  17743. {
  17744. return $tokens->isAllTokenKindsFound([T_CLASS, T_FUNCTION]);
  17745. }
  17746. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  17747. {
  17748. foreach (array_reverse($this->findPhpUnitClasses($tokens)) as $indexes) {
  17749. if ('annotation' === $this->configuration['style']) {
  17750. $this->applyTestAnnotation($tokens, $indexes[0], $indexes[1]);
  17751. } else {
  17752. $this->applyTestPrefix($tokens, $indexes[0], $indexes[1]);
  17753. }
  17754. }
  17755. }
  17756. protected function createConfigurationDefinition()
  17757. {
  17758. return new FixerConfigurationResolver([
  17759. (new FixerOptionBuilder('style', 'Whether to use the @test annotation or not.'))
  17760. ->setAllowedValues(['prefix', 'annotation'])
  17761. ->setDefault('prefix')
  17762. ->getOption(),
  17763. (new FixerOptionBuilder('case', 'Whether to camel or snake case when adding the test prefix'))
  17764. ->setAllowedValues(['camel', 'snake'])
  17765. ->setDefault('camel')
  17766. ->getOption(),
  17767. ]);
  17768. }
  17769. private function findPhpUnitClasses(Tokens $tokens)
  17770. {
  17771. $phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator();
  17772. $phpunitClasses = [];
  17773. for ($index = 0, $limit = $tokens->count() - 1; $index < $limit; ++$index) {
  17774. if ($tokens[$index]->isGivenKind(T_CLASS) && $phpUnitTestCaseIndicator->isPhpUnitClass($tokens, $index)) {
  17775. $index = $tokens->getNextTokenOfKind($index, ['{']);
  17776. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  17777. $phpunitClasses[] = [$index, $endIndex];
  17778. $index = $endIndex;
  17779. }
  17780. }
  17781. return $phpunitClasses;
  17782. }
  17783. private function applyTestAnnotation(Tokens $tokens, $startIndex, $endIndex)
  17784. {
  17785. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  17786. if (!$this->isTestMethod($tokens, $i)) {
  17787. continue;
  17788. }
  17789. $functionNameIndex = $tokens->getNextMeaningfulToken($i);
  17790. $functionName = $tokens[$functionNameIndex]->getContent();
  17791. if ($this->hasTestPrefix($functionName)) {
  17792. $newFunctionName = $this->removeTestPrefix($functionName);
  17793. $tokens[$functionNameIndex] = new Token([T_STRING, $newFunctionName]);
  17794. }
  17795. $docBlockIndex = $this->getDocBlockIndex($tokens, $i);
  17796. if (!$this->hasDocBlock($tokens, $i)) {
  17797. $this->createDocBlock($tokens, $docBlockIndex);
  17798. continue;
  17799. }
  17800. $lines = $this->updateDocBlock($tokens, $docBlockIndex);
  17801. $lines = $this->addTestAnnotation($lines, $tokens, $docBlockIndex);
  17802. $lines = implode($lines);
  17803. $tokens[$docBlockIndex] = new Token([T_DOC_COMMENT, $lines]);
  17804. }
  17805. }
  17806. private function applyTestPrefix(Tokens $tokens, $startIndex, $endIndex)
  17807. {
  17808. for ($i = $endIndex - 1; $i > $startIndex; --$i) {
  17809. if (!$this->isTestMethod($tokens, $i) || !$this->hasDocBlock($tokens, $i)) {
  17810. continue;
  17811. }
  17812. $docBlockIndex = $this->getDocBlockIndex($tokens, $i);
  17813. $lines = $this->updateDocBlock($tokens, $docBlockIndex);
  17814. $lines = implode($lines);
  17815. $tokens[$docBlockIndex] = new Token([T_DOC_COMMENT, $lines]);
  17816. $functionNameIndex = $tokens->getNextMeaningfulToken($i);
  17817. $functionName = $tokens[$functionNameIndex]->getContent();
  17818. if ($this->hasTestPrefix($functionName)) {
  17819. continue;
  17820. }
  17821. $newFunctionName = $this->addTestPrefix($functionName);
  17822. $tokens[$functionNameIndex] = new Token([T_STRING, $newFunctionName]);
  17823. }
  17824. }
  17825. private function isTestMethod(Tokens $tokens, $index)
  17826. {
  17827. if (!$this->isMethod($tokens, $index)) {
  17828. return false;
  17829. }
  17830. $functionNameIndex = $tokens->getNextMeaningfulToken($index);
  17831. $functionName = $tokens[$functionNameIndex]->getContent();
  17832. if ($this->startsWith('test', $functionName)) {
  17833. return true;
  17834. }
  17835. if (!$this->hasDocBlock($tokens, $index)) {
  17836. return false;
  17837. }
  17838. $docBlockIndex = $this->getDocBlockIndex($tokens, $index);
  17839. $doc = $tokens[$docBlockIndex]->getContent();
  17840. if (false === strpos($doc, '@test')) {
  17841. return false;
  17842. }
  17843. return true;
  17844. }
  17845. private function isMethod(Tokens $tokens, $index)
  17846. {
  17847. $tokensAnalyzer = new TokensAnalyzer($tokens);
  17848. return $tokens[$index]->isGivenKind(T_FUNCTION) && !$tokensAnalyzer->isLambda($index);
  17849. }
  17850. private function startsWith($needle, $haystack)
  17851. {
  17852. $len = strlen($needle);
  17853. return substr($haystack, 0, $len) === $needle;
  17854. }
  17855. private function hasDocBlock(Tokens $tokens, $index)
  17856. {
  17857. $docBlockIndex = $this->getDocBlockIndex($tokens, $index);
  17858. return $tokens[$docBlockIndex]->isGivenKind(T_DOC_COMMENT);
  17859. }
  17860. private function getDocBlockIndex(Tokens $tokens, $index)
  17861. {
  17862. do {
  17863. $index = $tokens->getPrevNonWhitespace($index);
  17864. } while ($tokens[$index]->isGivenKind([T_PUBLIC, T_PROTECTED, T_PRIVATE, T_FINAL, T_ABSTRACT, T_COMMENT]));
  17865. return $index;
  17866. }
  17867. private function hasTestPrefix($functionName)
  17868. {
  17869. if (!$this->startsWith('test', $functionName) || strlen($functionName) < 5) {
  17870. return false;
  17871. }
  17872. $nextCharacter = $functionName[4];
  17873. return $nextCharacter === strtoupper($nextCharacter);
  17874. }
  17875. private function removeTestPrefix($functionName)
  17876. {
  17877. $remainder = preg_replace('/^test_?/', '', $functionName);
  17878. if ('' === $remainder || is_numeric($remainder[0])) {
  17879. return $functionName;
  17880. }
  17881. return lcfirst($remainder);
  17882. }
  17883. private function addTestPrefix($functionName)
  17884. {
  17885. if ('camel' !== $this->configuration['case']) {
  17886. return 'test_'.$functionName;
  17887. }
  17888. return'test'.ucfirst($functionName);
  17889. }
  17890. private function detectIndent(Tokens $tokens, $index)
  17891. {
  17892. if (!$tokens[$index - 1]->isWhitespace()) {
  17893. return '';
  17894. }
  17895. $explodedContent = explode($this->whitespacesConfig->getLineEnding(), $tokens[$index - 1]->getContent());
  17896. return end($explodedContent);
  17897. }
  17898. private function createDocBlock(Tokens $tokens, $docBlockIndex)
  17899. {
  17900. $lineEnd = $this->whitespacesConfig->getLineEnding();
  17901. $originalIndent = $this->detectIndent($tokens, $tokens->getNextNonWhitespace($docBlockIndex));
  17902. $toInsert = [
  17903. new Token([T_DOC_COMMENT, '/**'.$lineEnd."${originalIndent} * @test".$lineEnd."${originalIndent} */"]),
  17904. new Token([T_WHITESPACE, $lineEnd.$originalIndent]),
  17905. ];
  17906. $index = $tokens->getNextMeaningfulToken($docBlockIndex);
  17907. $tokens->insertAt($index, $toInsert);
  17908. }
  17909. private function updateDocBlock(Tokens $tokens, $docBlockIndex)
  17910. {
  17911. $doc = new DocBlock($tokens[$docBlockIndex]->getContent());
  17912. $lines = $doc->getLines();
  17913. return $this->updateLines($lines, $tokens, $docBlockIndex);
  17914. }
  17915. private function updateLines($lines, Tokens $tokens, $docBlockIndex)
  17916. {
  17917. $needsAnnotation = 'annotation' === $this->configuration['style'];
  17918. $doc = new DocBlock($tokens[$docBlockIndex]->getContent());
  17919. for ($i = 0; $i < \count($lines); ++$i) {
  17920. if ($needsAnnotation && ($lines[$i]->isTheStart() && $lines[$i]->isTheEnd())) {
  17921. if (!$this->doesDocBlockContainTest($doc)) {
  17922. $lines = $this->splitUpDocBlock($lines, $tokens, $docBlockIndex);
  17923. return $this->updateLines($lines, $tokens, $docBlockIndex);
  17924. }
  17925. }
  17926. if (!$needsAnnotation &&
  17927. false !== \strpos($lines[$i]->getContent(), ' @test') &&
  17928. false === \strpos($lines[$i]->getContent(), '@testWith') &&
  17929. false === \strpos($lines[$i]->getContent(), '@testdox')
  17930. ) {
  17931. $lines[$i] = new Line(str_replace(' @test', '', $lines[$i]->getContent()));
  17932. }
  17933. if (false === strpos($lines[$i]->getContent(), '@depends')) {
  17934. continue;
  17935. }
  17936. $lines[$i] = $this->updateDependsAnnotation($lines[$i]);
  17937. }
  17938. return $lines;
  17939. }
  17940. private function splitUpDocBlock($lines, Tokens $tokens, $docBlockIndex)
  17941. {
  17942. $lineContent = $this->getSingleLineDocBlockEntry($lines);
  17943. $lineEnd = $this->whitespacesConfig->getLineEnding();
  17944. $originalIndent = $this->detectIndent($tokens, $tokens->getNextNonWhitespace($docBlockIndex));
  17945. $lines = [
  17946. new Line('/**'.$lineEnd),
  17947. new Line($originalIndent.' * '.$lineContent.$lineEnd),
  17948. new Line($originalIndent.' */'),
  17949. ];
  17950. return $lines;
  17951. }
  17952. private function getSingleLineDocBlockEntry($line)
  17953. {
  17954. $line = $line[0];
  17955. $line = \str_replace('*/', '', $line);
  17956. $line = trim($line);
  17957. $line = \str_split($line);
  17958. $i = \count($line);
  17959. do {
  17960. --$i;
  17961. } while ('*' !== $line[$i] && '*' !== $line[$i - 1] && '/' !== $line[$i - 2]);
  17962. if (' ' === $line[$i]) {
  17963. ++$i;
  17964. }
  17965. $line = array_slice($line, $i);
  17966. $line = implode($line);
  17967. return $line;
  17968. }
  17969. private function updateDependsAnnotation(Line $line)
  17970. {
  17971. if ('annotation' === $this->configuration['style']) {
  17972. return $this->removeTestPrefixFromDependsAnnotation($line);
  17973. }
  17974. return $this->addTestPrefixToDependsAnnotation($line);
  17975. }
  17976. private function removeTestPrefixFromDependsAnnotation(Line $line)
  17977. {
  17978. $line = \str_split($line->getContent());
  17979. $dependsIndex = $this->findWhereDependsFunctionNameStarts($line);
  17980. $dependsFunctionName = implode(array_slice($line, $dependsIndex));
  17981. if ($this->startsWith('test', $dependsFunctionName)) {
  17982. $dependsFunctionName = $this->removeTestPrefix($dependsFunctionName);
  17983. }
  17984. array_splice($line, $dependsIndex);
  17985. return new Line(implode($line).$dependsFunctionName);
  17986. }
  17987. private function addTestPrefixToDependsAnnotation(Line $line)
  17988. {
  17989. $line = \str_split($line->getContent());
  17990. $dependsIndex = $this->findWhereDependsFunctionNameStarts($line);
  17991. $dependsFunctionName = implode(array_slice($line, $dependsIndex));
  17992. if (!$this->startsWith('test', $dependsFunctionName)) {
  17993. $dependsFunctionName = $this->addTestPrefix($dependsFunctionName);
  17994. }
  17995. array_splice($line, $dependsIndex);
  17996. return new Line(implode($line).$dependsFunctionName);
  17997. }
  17998. private function findWhereDependsFunctionNameStarts(array $line)
  17999. {
  18000. $counter = \count($line);
  18001. do {
  18002. --$counter;
  18003. } while (' ' !== $line[$counter]);
  18004. return $counter + 1;
  18005. }
  18006. private function addTestAnnotation($lines, Tokens $tokens, $docBlockIndex)
  18007. {
  18008. $doc = new DocBlock($tokens[$docBlockIndex]->getContent());
  18009. if (!$this->doesDocBlockContainTest($doc)) {
  18010. $originalIndent = $this->detectIndent($tokens, $docBlockIndex);
  18011. $lineEnd = $this->whitespacesConfig->getLineEnding();
  18012. array_splice($lines, -1, 0, $originalIndent.' *'.$lineEnd.$originalIndent.' * @test'.$lineEnd);
  18013. }
  18014. return $lines;
  18015. }
  18016. private function doesDocBlockContainTest(DocBlock $doc)
  18017. {
  18018. return !empty($doc->getAnnotationsOfType('test'));
  18019. }
  18020. }
  18021. <?php
  18022. namespace PhpCsFixer\Fixer\PhpUnit;
  18023. use PhpCsFixer\AbstractFixer;
  18024. use PhpCsFixer\DocBlock\DocBlock;
  18025. use PhpCsFixer\DocBlock\Line;
  18026. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  18027. use PhpCsFixer\FixerDefinition\CodeSample;
  18028. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18029. use PhpCsFixer\Indicator\PhpUnitTestCaseIndicator;
  18030. use PhpCsFixer\Tokenizer\Token;
  18031. use PhpCsFixer\Tokenizer\Tokens;
  18032. final class PhpUnitTestClassRequiresCoversFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  18033. {
  18034. public function getDefinition()
  18035. {
  18036. return new FixerDefinition(
  18037. 'Adds a default `@coversNothing` annotation to PHPUnit test classes that have no `@covers*` annotation.',
  18038. [
  18039. new CodeSample(
  18040. '<?php
  18041. final class MyTest extends \PHPUnit_Framework_TestCase
  18042. {
  18043. public function testSomeTest()
  18044. {
  18045. $this->assertSame(a(), b());
  18046. }
  18047. }
  18048. '
  18049. ),
  18050. ]
  18051. );
  18052. }
  18053. public function isCandidate(Tokens $tokens)
  18054. {
  18055. return $tokens->isTokenKindFound(T_CLASS);
  18056. }
  18057. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18058. {
  18059. $phpUnitTestCaseIndicator = new PhpUnitTestCaseIndicator();
  18060. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  18061. if (!$tokens[$index]->isGivenKind(T_CLASS)) {
  18062. continue;
  18063. }
  18064. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  18065. if ($tokens[$prevIndex]->isGivenKind(T_ABSTRACT)) {
  18066. continue;
  18067. }
  18068. if (!$phpUnitTestCaseIndicator->isPhpUnitClass($tokens, $index)) {
  18069. continue;
  18070. }
  18071. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  18072. $index = $tokens[$prevIndex]->isGivenKind(T_FINAL) ? $prevIndex : $index;
  18073. $indent = $tokens[$index - 1]->isGivenKind(T_WHITESPACE)
  18074. ? preg_replace('/^.*\R*/', '', $tokens[$index - 1]->getContent())
  18075. : '';
  18076. $prevIndex = $tokens->getPrevNonWhitespace($index);
  18077. $doc = null;
  18078. $docIndex = null;
  18079. if ($tokens[$prevIndex]->isGivenKind(T_DOC_COMMENT)) {
  18080. $docIndex = $prevIndex;
  18081. $docContent = $tokens[$docIndex]->getContent();
  18082. if (false === strpos($docContent, "\n")) {
  18083. continue;
  18084. }
  18085. $doc = new DocBlock($docContent);
  18086. if (!empty($doc->getAnnotationsOfType([
  18087. 'covers',
  18088. 'coversDefaultClass',
  18089. 'coversNothing',
  18090. ]))) {
  18091. continue;
  18092. }
  18093. } else {
  18094. $docIndex = $index;
  18095. $tokens->insertAt($docIndex, [
  18096. new Token([T_DOC_COMMENT, sprintf('/**%s%s */', $this->whitespacesConfig->getLineEnding(), $indent)]),
  18097. new Token([T_WHITESPACE, sprintf('%s%s', $this->whitespacesConfig->getLineEnding(), $indent)]),
  18098. ]);
  18099. if (!$tokens[$docIndex - 1]->isGivenKind(T_WHITESPACE)) {
  18100. $extraNewLines = $this->whitespacesConfig->getLineEnding();
  18101. if (!$tokens[$docIndex - 1]->isGivenKind(T_OPEN_TAG)) {
  18102. $extraNewLines .= $this->whitespacesConfig->getLineEnding();
  18103. }
  18104. $tokens->insertAt($docIndex, [
  18105. new Token([T_WHITESPACE, $extraNewLines.$indent]),
  18106. ]);
  18107. ++$docIndex;
  18108. }
  18109. $doc = new DocBlock($tokens[$docIndex]->getContent());
  18110. }
  18111. $lines = $doc->getLines();
  18112. array_splice(
  18113. $lines,
  18114. count($lines) - 1,
  18115. 0,
  18116. [
  18117. new Line(sprintf(
  18118. '%s * @coversNothing%s',
  18119. $indent,
  18120. $this->whitespacesConfig->getLineEnding()
  18121. )),
  18122. ]
  18123. );
  18124. $tokens[$docIndex] = new Token([T_DOC_COMMENT, implode('', $lines)]);
  18125. }
  18126. }
  18127. }
  18128. <?php
  18129. namespace PhpCsFixer\Fixer\Phpdoc;
  18130. use PhpCsFixer\AbstractFixer;
  18131. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  18132. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  18133. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  18134. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  18135. use PhpCsFixer\FixerDefinition\CodeSample;
  18136. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18137. use PhpCsFixer\Tokenizer\Token;
  18138. use PhpCsFixer\Tokenizer\Tokens;
  18139. final class AlignMultilineCommentFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  18140. {
  18141. private $tokenKinds;
  18142. public function configure(array $configuration = null)
  18143. {
  18144. parent::configure($configuration);
  18145. $this->tokenKinds = [T_DOC_COMMENT];
  18146. if ('phpdocs_only' !== $this->configuration['comment_type']) {
  18147. $this->tokenKinds[] = T_COMMENT;
  18148. }
  18149. }
  18150. public function getDefinition()
  18151. {
  18152. return new FixerDefinition(
  18153. 'Each line of multi-line DocComments must have an asterisk [PSR-5] and must be aligned with the first one.',
  18154. [
  18155. new CodeSample(
  18156. '<?php
  18157. /**
  18158. * This is a DOC Comment
  18159. with a line not prefixed with asterisk
  18160. */
  18161. '
  18162. ),
  18163. new CodeSample(
  18164. '<?php
  18165. /*
  18166. * This is a doc-like multiline comment
  18167. */
  18168. ',
  18169. ['comment_type' => 'phpdocs_like']
  18170. ),
  18171. new CodeSample(
  18172. '<?php
  18173. /*
  18174. * This is a doc-like multiline comment
  18175. with a line not prefixed with asterisk
  18176. */
  18177. ',
  18178. ['comment_type' => 'all_multiline']
  18179. ),
  18180. ]
  18181. );
  18182. }
  18183. public function isCandidate(Tokens $tokens)
  18184. {
  18185. return $tokens->isAnyTokenKindsFound($this->tokenKinds);
  18186. }
  18187. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18188. {
  18189. $lineEnding = $this->whitespacesConfig->getLineEnding();
  18190. foreach ($tokens as $index => $token) {
  18191. if (!$token->isGivenKind($this->tokenKinds)) {
  18192. continue;
  18193. }
  18194. $whitespace = '';
  18195. $previousIndex = $index - 1;
  18196. if ($tokens[$previousIndex]->isWhitespace()) {
  18197. $whitespace = $tokens[$previousIndex]->getContent();
  18198. --$previousIndex;
  18199. }
  18200. if ($tokens[$previousIndex]->isGivenKind(T_OPEN_TAG)) {
  18201. $whitespace = preg_replace('/\S/', '', $tokens[$previousIndex]->getContent()).$whitespace;
  18202. }
  18203. if (1 !== preg_match('/\R([ \t]*)$/', $whitespace, $matches)) {
  18204. continue;
  18205. }
  18206. if ($token->isGivenKind(T_COMMENT) && 'all_multiline' !== $this->configuration['comment_type'] && 1 === preg_match('/\R(?:\R|\s*[^\s\*])/', $token->getContent())) {
  18207. continue;
  18208. }
  18209. $indentation = $matches[1];
  18210. $lines = preg_split('/\R/u', $token->getContent());
  18211. foreach ($lines as $lineNumber => $line) {
  18212. if (0 === $lineNumber) {
  18213. continue;
  18214. }
  18215. $line = ltrim($line);
  18216. if ($token->isGivenKind(T_COMMENT) && (!isset($line[0]) || '*' !== $line[0])) {
  18217. continue;
  18218. }
  18219. if (!isset($line[0])) {
  18220. $line = '*';
  18221. } elseif ('*' !== $line[0]) {
  18222. $line = '* '.$line;
  18223. }
  18224. $lines[$lineNumber] = $indentation.' '.$line;
  18225. }
  18226. $tokens[$index] = new Token([$token->getId(), implode($lineEnding, $lines)]);
  18227. }
  18228. }
  18229. protected function createConfigurationDefinition()
  18230. {
  18231. return new FixerConfigurationResolver([
  18232. (new FixerOptionBuilder('comment_type', 'Whether to fix PHPDoc comments only (`phpdocs_only`), any multi-line comment whose lines all start with an asterisk (`phpdocs_like`) or any multi-line comment (`all_multiline`).'))
  18233. ->setAllowedValues(['phpdocs_only', 'phpdocs_like', 'all_multiline'])
  18234. ->setDefault('phpdocs_only')
  18235. ->getOption(),
  18236. ]);
  18237. }
  18238. }
  18239. <?php
  18240. namespace PhpCsFixer\Fixer\Phpdoc;
  18241. use PhpCsFixer\AbstractFixer;
  18242. use PhpCsFixer\DocBlock\DocBlock;
  18243. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  18244. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  18245. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  18246. use PhpCsFixer\FixerDefinition\CodeSample;
  18247. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18248. use PhpCsFixer\Tokenizer\Token;
  18249. use PhpCsFixer\Tokenizer\Tokens;
  18250. final class GeneralPhpdocAnnotationRemoveFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  18251. {
  18252. public function getDefinition()
  18253. {
  18254. return new FixerDefinition(
  18255. 'Configured annotations should be omitted from phpdocs.',
  18256. [
  18257. new CodeSample(
  18258. '<?php
  18259. /**
  18260. * @internal
  18261. * @author someone
  18262. */
  18263. function foo() {}
  18264. ',
  18265. ['annotations' => ['author']]
  18266. ),
  18267. ]
  18268. );
  18269. }
  18270. public function getPriority()
  18271. {
  18272. return 10;
  18273. }
  18274. public function isCandidate(Tokens $tokens)
  18275. {
  18276. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18277. }
  18278. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18279. {
  18280. if (!count($this->configuration['annotations'])) {
  18281. return;
  18282. }
  18283. foreach ($tokens as $index => $token) {
  18284. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18285. continue;
  18286. }
  18287. $doc = new DocBlock($token->getContent());
  18288. $annotations = $doc->getAnnotationsOfType($this->configuration['annotations']);
  18289. if (empty($annotations)) {
  18290. continue;
  18291. }
  18292. foreach ($annotations as $annotation) {
  18293. $annotation->remove();
  18294. }
  18295. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  18296. }
  18297. }
  18298. protected function createConfigurationDefinition()
  18299. {
  18300. return new FixerConfigurationResolverRootless('annotations', [
  18301. (new FixerOptionBuilder('annotations', 'List of annotations to remove, e.g. `["author"]`.'))
  18302. ->setAllowedTypes(['array'])
  18303. ->setDefault([])
  18304. ->getOption(),
  18305. ]);
  18306. }
  18307. }
  18308. <?php
  18309. namespace PhpCsFixer\Fixer\Phpdoc;
  18310. use PhpCsFixer\AbstractFixer;
  18311. use PhpCsFixer\FixerDefinition\CodeSample;
  18312. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18313. use PhpCsFixer\Tokenizer\Token;
  18314. use PhpCsFixer\Tokenizer\Tokens;
  18315. use PhpCsFixer\Utils;
  18316. final class NoBlankLinesAfterPhpdocFixer extends AbstractFixer
  18317. {
  18318. public function isCandidate(Tokens $tokens)
  18319. {
  18320. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18321. }
  18322. public function getDefinition()
  18323. {
  18324. return new FixerDefinition(
  18325. 'There should not be blank lines between docblock and the documented element.',
  18326. [
  18327. new CodeSample(
  18328. '<?php
  18329. /**
  18330. * This is the bar class.
  18331. */
  18332. class Bar {}
  18333. '
  18334. ),
  18335. ]
  18336. );
  18337. }
  18338. public function getPriority()
  18339. {
  18340. return 1;
  18341. }
  18342. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18343. {
  18344. static $forbiddenSuccessors = [
  18345. T_DOC_COMMENT,
  18346. T_COMMENT,
  18347. T_WHITESPACE,
  18348. T_RETURN,
  18349. T_THROW,
  18350. T_GOTO,
  18351. T_CONTINUE,
  18352. T_BREAK,
  18353. ];
  18354. foreach ($tokens as $index => $token) {
  18355. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18356. continue;
  18357. }
  18358. $next = $tokens->getNextNonWhitespace($index);
  18359. if ($index + 2 === $next && false === $tokens[$next]->isGivenKind($forbiddenSuccessors)) {
  18360. $this->fixWhitespace($tokens, $index + 1);
  18361. }
  18362. }
  18363. }
  18364. private function fixWhitespace(Tokens $tokens, $index)
  18365. {
  18366. $content = $tokens[$index]->getContent();
  18367. if (substr_count($content, "\n") > 1) {
  18368. $lines = Utils::splitLines($content);
  18369. $tokens[$index] = new Token([T_WHITESPACE, "\n".end($lines)]);
  18370. }
  18371. }
  18372. }
  18373. <?php
  18374. namespace PhpCsFixer\Fixer\Phpdoc;
  18375. use PhpCsFixer\AbstractFixer;
  18376. use PhpCsFixer\FixerDefinition\CodeSample;
  18377. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18378. use PhpCsFixer\Tokenizer\Tokens;
  18379. final class NoEmptyPhpdocFixer extends AbstractFixer
  18380. {
  18381. public function getDefinition()
  18382. {
  18383. return new FixerDefinition(
  18384. 'There should not be empty PHPDoc blocks.',
  18385. [new CodeSample("<?php /** */\n")]
  18386. );
  18387. }
  18388. public function getPriority()
  18389. {
  18390. return 5;
  18391. }
  18392. public function isCandidate(Tokens $tokens)
  18393. {
  18394. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18395. }
  18396. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18397. {
  18398. foreach ($tokens as $index => $token) {
  18399. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18400. continue;
  18401. }
  18402. if (preg_match('#^/\*\*[\s\*]*\*/$#', $token->getContent())) {
  18403. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  18404. }
  18405. }
  18406. }
  18407. }
  18408. <?php
  18409. namespace PhpCsFixer\Fixer\Phpdoc;
  18410. use PhpCsFixer\AbstractFunctionReferenceFixer;
  18411. use PhpCsFixer\DocBlock\DocBlock;
  18412. use PhpCsFixer\DocBlock\Line;
  18413. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  18414. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  18415. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  18416. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  18417. use PhpCsFixer\FixerDefinition\CodeSample;
  18418. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18419. use PhpCsFixer\Tokenizer\Analyzer\ArgumentsAnalyzer;
  18420. use PhpCsFixer\Tokenizer\Token;
  18421. use PhpCsFixer\Tokenizer\Tokens;
  18422. final class PhpdocAddMissingParamAnnotationFixer extends AbstractFunctionReferenceFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  18423. {
  18424. public function getDefinition()
  18425. {
  18426. return new FixerDefinition(
  18427. 'Phpdoc should contain @param for all params.',
  18428. [
  18429. new CodeSample(
  18430. '<?php
  18431. /**
  18432. * @param int $bar
  18433. *
  18434. * @return void
  18435. */
  18436. function f9(string $foo, $bar, $baz) {}
  18437. '
  18438. ),
  18439. new CodeSample(
  18440. '<?php
  18441. /**
  18442. * @param int $bar
  18443. *
  18444. * @return void
  18445. */
  18446. function f9(string $foo, $bar, $baz) {}
  18447. ',
  18448. ['only_untyped' => true]
  18449. ),
  18450. new CodeSample(
  18451. '<?php
  18452. /**
  18453. * @param int $bar
  18454. *
  18455. * @return void
  18456. */
  18457. function f9(string $foo, $bar, $baz) {}
  18458. ',
  18459. ['only_untyped' => false]
  18460. ),
  18461. ]
  18462. );
  18463. }
  18464. public function getPriority()
  18465. {
  18466. return -1;
  18467. }
  18468. public function isCandidate(Tokens $tokens)
  18469. {
  18470. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18471. }
  18472. public function isRisky()
  18473. {
  18474. return false;
  18475. }
  18476. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18477. {
  18478. $argumentsAnalyzer = new ArgumentsAnalyzer();
  18479. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  18480. $mainIndex = $index;
  18481. $token = $tokens[$index];
  18482. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18483. continue;
  18484. }
  18485. $tokenContent = $token->getContent();
  18486. if (false !== stripos($tokenContent, 'inheritdoc')) {
  18487. continue;
  18488. }
  18489. if (false === strpos($tokenContent, "\n")) {
  18490. continue;
  18491. }
  18492. $index = $tokens->getNextMeaningfulToken($index);
  18493. if (null === $index) {
  18494. return;
  18495. }
  18496. while ($tokens[$index]->isGivenKind([
  18497. T_ABSTRACT,
  18498. T_FINAL,
  18499. T_PRIVATE,
  18500. T_PROTECTED,
  18501. T_PUBLIC,
  18502. T_STATIC,
  18503. T_VAR,
  18504. ])) {
  18505. $index = $tokens->getNextMeaningfulToken($index);
  18506. }
  18507. if (!$tokens[$index]->isGivenKind(T_FUNCTION)) {
  18508. continue;
  18509. }
  18510. $openIndex = $tokens->getNextTokenOfKind($index, ['(']);
  18511. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $openIndex);
  18512. $arguments = [];
  18513. foreach ($argumentsAnalyzer->getArguments($tokens, $openIndex, $index) as $start => $end) {
  18514. $argumentInfo = $this->prepareArgumentInformation($tokens, $start, $end);
  18515. if (!$this->configuration['only_untyped'] || '' === $argumentInfo['type']) {
  18516. $arguments[$argumentInfo['name']] = $argumentInfo;
  18517. }
  18518. }
  18519. if (!count($arguments)) {
  18520. continue;
  18521. }
  18522. $doc = new DocBlock($tokenContent);
  18523. $lastParamLine = null;
  18524. foreach ($doc->getAnnotationsOfType('param') as $annotation) {
  18525. $pregMatched = preg_match('/^[^$]+(\$\w+).*$/s', $annotation->getContent(), $matches);
  18526. if (1 === $pregMatched) {
  18527. unset($arguments[$matches[1]]);
  18528. }
  18529. $lastParamLine = max($lastParamLine, $annotation->getEnd());
  18530. }
  18531. if (!count($arguments)) {
  18532. continue;
  18533. }
  18534. $lines = $doc->getLines();
  18535. $linesCount = count($lines);
  18536. preg_match('/^(\s*).*$/', $lines[$linesCount - 1]->getContent(), $matches);
  18537. $indent = $matches[1];
  18538. $newLines = [];
  18539. foreach ($arguments as $argument) {
  18540. $type = $argument['type'] ?: 'mixed';
  18541. if ('?' !== $type[0] && 'null' === strtolower($argument['default'])) {
  18542. $type = 'null|'.$type;
  18543. }
  18544. $newLines[] = new Line(sprintf(
  18545. '%s* @param %s %s%s',
  18546. $indent,
  18547. $type,
  18548. $argument['name'],
  18549. $this->whitespacesConfig->getLineEnding()
  18550. ));
  18551. }
  18552. array_splice(
  18553. $lines,
  18554. $lastParamLine ? $lastParamLine + 1 : $linesCount - 1,
  18555. 0,
  18556. $newLines
  18557. );
  18558. $tokens[$mainIndex] = new Token([T_DOC_COMMENT, implode('', $lines)]);
  18559. }
  18560. }
  18561. protected function createConfigurationDefinition()
  18562. {
  18563. return new FixerConfigurationResolver([
  18564. (new FixerOptionBuilder('only_untyped', 'Whether to add missing `@param` annotations for untyped parameters only.'))
  18565. ->setDefault(true)
  18566. ->setAllowedTypes(['bool'])
  18567. ->getOption(),
  18568. ]);
  18569. }
  18570. private function prepareArgumentInformation(Tokens $tokens, $start, $end)
  18571. {
  18572. $info = [
  18573. 'default' => '',
  18574. 'name' => '',
  18575. 'type' => '',
  18576. ];
  18577. $sawName = false;
  18578. for ($index = $start; $index <= $end; ++$index) {
  18579. $token = $tokens[$index];
  18580. if ($token->isComment() || $token->isWhitespace()) {
  18581. continue;
  18582. }
  18583. if ($token->isGivenKind(T_VARIABLE)) {
  18584. $sawName = true;
  18585. $info['name'] = $token->getContent();
  18586. continue;
  18587. }
  18588. if ($token->equals('=')) {
  18589. continue;
  18590. }
  18591. if ($sawName) {
  18592. $info['default'] .= $token->getContent();
  18593. } else {
  18594. $info['type'] .= $token->getContent();
  18595. }
  18596. }
  18597. return $info;
  18598. }
  18599. }
  18600. <?php
  18601. namespace PhpCsFixer\Fixer\Phpdoc;
  18602. use PhpCsFixer\AbstractFixer;
  18603. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  18604. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  18605. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  18606. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  18607. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  18608. use PhpCsFixer\FixerDefinition\CodeSample;
  18609. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18610. use PhpCsFixer\Tokenizer\Token;
  18611. use PhpCsFixer\Tokenizer\Tokens;
  18612. use PhpCsFixer\Utils;
  18613. final class PhpdocAlignFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  18614. {
  18615. private $regex;
  18616. private $regexCommentLine;
  18617. private static $alignableTags = [
  18618. 'param',
  18619. 'property',
  18620. 'return',
  18621. 'throws',
  18622. 'type',
  18623. 'var',
  18624. 'method',
  18625. ];
  18626. private static $tagsWithName = [
  18627. 'param',
  18628. 'property',
  18629. ];
  18630. private static $tagsWithMethodSignature = [
  18631. 'method',
  18632. ];
  18633. public function configure(array $configuration = null)
  18634. {
  18635. parent::configure($configuration);
  18636. $tagsWithNameToAlign = array_intersect($this->configuration['tags'], self::$tagsWithName);
  18637. $tagsWithMethodSignatureToAlign = array_intersect($this->configuration['tags'], self::$tagsWithMethodSignature);
  18638. $tagsWithoutNameToAlign = array_diff($this->configuration['tags'], $tagsWithNameToAlign, $tagsWithMethodSignatureToAlign);
  18639. $types = [];
  18640. $indent = '(?P<indent>(?: {2}|\t)*)';
  18641. if (!empty($tagsWithNameToAlign)) {
  18642. $types[] = '(?P<tag>'.implode('|', $tagsWithNameToAlign).')\s+(?P<hint>[^$]+?)\s+(?P<var>(?:&|\.{3})?\$[^\s]+)';
  18643. }
  18644. if (!empty($tagsWithoutNameToAlign)) {
  18645. $types[] = '(?P<tag2>'.implode('|', $tagsWithoutNameToAlign).')\s+(?P<hint2>[^\s]+?)';
  18646. }
  18647. if (!empty($tagsWithMethodSignatureToAlign)) {
  18648. $types[] = '(?P<tag3>'.implode('|', $tagsWithMethodSignatureToAlign).')(\s+(?P<hint3>[^\s(]+)|)\s+(?P<signature>.+\))';
  18649. }
  18650. $desc = '(?:\s+(?P<desc>\V*))';
  18651. $this->regex = '/^'.$indent.' \* @(?:'.implode('|', $types).')'.$desc.'\s*$/u';
  18652. $this->regexCommentLine = '/^'.$indent.' \*(?! @)(?:\s+(?P<desc>\V+))(?<!\*\/)$/u';
  18653. }
  18654. public function getDefinition()
  18655. {
  18656. return new FixerDefinition(
  18657. 'All items of the given phpdoc tags must be aligned vertically.',
  18658. [new CodeSample('<?php
  18659. /**
  18660. * @param EngineInterface $templating
  18661. * @param string $format
  18662. * @param int $code an HTTP response status code
  18663. * @param bool $debug
  18664. * @param mixed &$reference a parameter passed by reference
  18665. */
  18666. ')]
  18667. );
  18668. }
  18669. public function getPriority()
  18670. {
  18671. return -11;
  18672. }
  18673. public function isCandidate(Tokens $tokens)
  18674. {
  18675. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18676. }
  18677. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18678. {
  18679. foreach ($tokens as $index => $token) {
  18680. if ($token->isGivenKind(T_DOC_COMMENT)) {
  18681. $tokens[$index] = new Token([T_DOC_COMMENT, $this->fixDocBlock($token->getContent())]);
  18682. }
  18683. }
  18684. }
  18685. protected function createConfigurationDefinition()
  18686. {
  18687. $generator = new FixerOptionValidatorGenerator();
  18688. $tags = new FixerOptionBuilder('tags', 'The tags that should be aligned.');
  18689. $tags
  18690. ->setAllowedTypes(['array'])
  18691. ->setAllowedValues([
  18692. $generator->allowedValueIsSubsetOf(self::$alignableTags),
  18693. ])
  18694. ->setDefault([
  18695. 'param',
  18696. 'return',
  18697. 'throws',
  18698. 'type',
  18699. 'var',
  18700. ])
  18701. ;
  18702. return new FixerConfigurationResolver([$tags->getOption()]);
  18703. }
  18704. private function fixDocBlock($content)
  18705. {
  18706. $lineEnding = $this->whitespacesConfig->getLineEnding();
  18707. $lines = Utils::splitLines($content);
  18708. $l = count($lines);
  18709. for ($i = 0; $i < $l; ++$i) {
  18710. $items = [];
  18711. $matches = $this->getMatches($lines[$i]);
  18712. if (null === $matches) {
  18713. continue;
  18714. }
  18715. $current = $i;
  18716. $items[] = $matches;
  18717. while (true) {
  18718. if (!isset($lines[++$i])) {
  18719. break 2;
  18720. }
  18721. $matches = $this->getMatches($lines[$i], true);
  18722. if (!$matches) {
  18723. break;
  18724. }
  18725. $items[] = $matches;
  18726. }
  18727. $tagMax = 0;
  18728. $hintMax = 0;
  18729. $varMax = 0;
  18730. foreach ($items as $item) {
  18731. if (null === $item['tag']) {
  18732. continue;
  18733. }
  18734. $tagMax = max($tagMax, strlen($item['tag']));
  18735. $hintMax = max($hintMax, strlen($item['hint']));
  18736. $varMax = max($varMax, strlen($item['var']));
  18737. }
  18738. $currTag = null;
  18739. foreach ($items as $j => $item) {
  18740. if (null === $item['tag']) {
  18741. if ($item['desc'][0] === '@') {
  18742. $lines[$current + $j] = $item['indent'].' * '.$item['desc'].$lineEnding;
  18743. continue;
  18744. }
  18745. $extraIndent = 2;
  18746. if (in_array($currTag, self::$tagsWithName, true) || in_array($currTag, self::$tagsWithMethodSignature, true)) {
  18747. $extraIndent = 3;
  18748. }
  18749. $line =
  18750. $item['indent']
  18751. .' * '
  18752. .str_repeat(' ', $tagMax + $hintMax + $varMax + $extraIndent)
  18753. .$item['desc']
  18754. .$lineEnding;
  18755. $lines[$current + $j] = $line;
  18756. continue;
  18757. }
  18758. $currTag = $item['tag'];
  18759. $line =
  18760. $item['indent']
  18761. .' * @'
  18762. .$item['tag']
  18763. .str_repeat(' ', $tagMax - strlen($item['tag']) + 1)
  18764. .$item['hint']
  18765. ;
  18766. if (!empty($item['var'])) {
  18767. $line .=
  18768. str_repeat(' ', ($hintMax ?: -1) - strlen($item['hint']) + 1)
  18769. .$item['var']
  18770. .(
  18771. !empty($item['desc'])
  18772. ? str_repeat(' ', $varMax - strlen($item['var']) + 1).$item['desc'].$lineEnding
  18773. : $lineEnding
  18774. )
  18775. ;
  18776. } elseif (!empty($item['desc'])) {
  18777. $line .= str_repeat(' ', $hintMax - strlen($item['hint']) + 1).$item['desc'].$lineEnding;
  18778. } else {
  18779. $line .= $lineEnding;
  18780. }
  18781. $lines[$current + $j] = $line;
  18782. }
  18783. }
  18784. return implode($lines);
  18785. }
  18786. private function getMatches($line, $matchCommentOnly = false)
  18787. {
  18788. if (preg_match($this->regex, $line, $matches)) {
  18789. if (!empty($matches['tag2'])) {
  18790. $matches['tag'] = $matches['tag2'];
  18791. $matches['hint'] = $matches['hint2'];
  18792. $matches['var'] = '';
  18793. }
  18794. if (!empty($matches['tag3'])) {
  18795. $matches['tag'] = $matches['tag3'];
  18796. $matches['hint'] = $matches['hint3'];
  18797. $matches['var'] = $matches['signature'];
  18798. }
  18799. return $matches;
  18800. }
  18801. if ($matchCommentOnly && preg_match($this->regexCommentLine, $line, $matches)) {
  18802. $matches['tag'] = null;
  18803. $matches['var'] = '';
  18804. $matches['hint'] = '';
  18805. return $matches;
  18806. }
  18807. }
  18808. }
  18809. <?php
  18810. namespace PhpCsFixer\Fixer\Phpdoc;
  18811. use PhpCsFixer\AbstractFixer;
  18812. use PhpCsFixer\DocBlock\DocBlock;
  18813. use PhpCsFixer\FixerDefinition\CodeSample;
  18814. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18815. use PhpCsFixer\Tokenizer\Token;
  18816. use PhpCsFixer\Tokenizer\Tokens;
  18817. final class PhpdocAnnotationWithoutDotFixer extends AbstractFixer
  18818. {
  18819. private $tags = ['throws', 'return', 'param', 'internal', 'deprecated', 'var', 'type'];
  18820. public function getDefinition()
  18821. {
  18822. return new FixerDefinition(
  18823. 'Phpdocs annotation descriptions should not be a sentence.',
  18824. [new CodeSample('<?php
  18825. /**
  18826. * @param string $bar Some string.
  18827. */
  18828. function foo ($bar) {}
  18829. ')]
  18830. );
  18831. }
  18832. public function isCandidate(Tokens $tokens)
  18833. {
  18834. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18835. }
  18836. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18837. {
  18838. foreach ($tokens as $index => $token) {
  18839. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18840. continue;
  18841. }
  18842. $doc = new DocBlock($token->getContent());
  18843. $annotations = $doc->getAnnotations();
  18844. if (empty($annotations)) {
  18845. continue;
  18846. }
  18847. foreach ($annotations as $annotation) {
  18848. if (
  18849. !$annotation->getTag()->valid() || !in_array($annotation->getTag()->getName(), $this->tags, true)
  18850. ) {
  18851. continue;
  18852. }
  18853. $content = $annotation->getContent();
  18854. if (
  18855. 1 !== preg_match('/[.。]$/u', $content)
  18856. || 0 !== preg_match('/[.。](?!$)/u', $content, $matches)
  18857. ) {
  18858. continue;
  18859. }
  18860. $endLine = $doc->getLine($annotation->getEnd());
  18861. $endLine->setContent(preg_replace('/(?<![.。])[.。](\s+)$/u', '\1', $endLine->getContent()));
  18862. $startLine = $doc->getLine($annotation->getStart());
  18863. $optionalTypeRegEx = $annotation->supportTypes()
  18864. ? sprintf('(?:%s\s+(?:\$\w+\s+)?)?', preg_quote(implode('|', $annotation->getTypes()), '/'))
  18865. : '';
  18866. $content = preg_replace_callback(
  18867. '/^(\s*\*\s*@\w+\s+'.$optionalTypeRegEx.')(\p{Lu}?(?=\p{Ll}|\p{Zs}))(.*)$/',
  18868. static function (array $matches) {
  18869. return $matches[1].strtolower($matches[2]).$matches[3];
  18870. },
  18871. $startLine->getContent(),
  18872. 1
  18873. );
  18874. $startLine->setContent($content);
  18875. }
  18876. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  18877. }
  18878. }
  18879. }
  18880. <?php
  18881. namespace PhpCsFixer\Fixer\Phpdoc;
  18882. use PhpCsFixer\AbstractFixer;
  18883. use PhpCsFixer\FixerDefinition\CodeSample;
  18884. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18885. use PhpCsFixer\Tokenizer\Token;
  18886. use PhpCsFixer\Tokenizer\Tokens;
  18887. use PhpCsFixer\Utils;
  18888. final class PhpdocIndentFixer extends AbstractFixer
  18889. {
  18890. public function getDefinition()
  18891. {
  18892. return new FixerDefinition(
  18893. 'Docblocks should have the same indentation as the documented subject.',
  18894. [new CodeSample('<?php
  18895. class DocBlocks
  18896. {
  18897. /**
  18898. * Test constants
  18899. */
  18900. const INDENT = 1;
  18901. }
  18902. ')]
  18903. );
  18904. }
  18905. public function getPriority()
  18906. {
  18907. return 20;
  18908. }
  18909. public function isCandidate(Tokens $tokens)
  18910. {
  18911. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18912. }
  18913. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18914. {
  18915. foreach ($tokens as $index => $token) {
  18916. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18917. continue;
  18918. }
  18919. $nextIndex = $tokens->getNextMeaningfulToken($index);
  18920. if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {
  18921. continue;
  18922. }
  18923. $prevIndex = $index - 1;
  18924. $prevToken = $tokens[$prevIndex];
  18925. if (
  18926. $prevToken->isGivenKind(T_OPEN_TAG)
  18927. || ($prevToken->isWhitespace(" \t") && !$tokens[$index - 2]->isGivenKind(T_OPEN_TAG))
  18928. || $prevToken->equalsAny([';', ',', '{', '('])
  18929. ) {
  18930. continue;
  18931. }
  18932. $indent = '';
  18933. if ($tokens[$nextIndex - 1]->isWhitespace()) {
  18934. $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$nextIndex - 1]);
  18935. }
  18936. $newPrevContent = $this->fixWhitespaceBeforeDocblock($prevToken->getContent(), $indent);
  18937. if ($newPrevContent) {
  18938. $tokens[$prevIndex] = new Token([$prevToken->getId(), $newPrevContent]);
  18939. } else {
  18940. $tokens->clearAt($prevIndex);
  18941. }
  18942. $tokens[$index] = new Token([T_DOC_COMMENT, $this->fixDocBlock($token->getContent(), $indent)]);
  18943. }
  18944. }
  18945. private function fixDocBlock($content, $indent)
  18946. {
  18947. return ltrim(preg_replace('/^[ \t]*\*/m', $indent.' *', $content));
  18948. }
  18949. private function fixWhitespaceBeforeDocblock($content, $indent)
  18950. {
  18951. return rtrim($content, " \t").$indent;
  18952. }
  18953. }
  18954. <?php
  18955. namespace PhpCsFixer\Fixer\Phpdoc;
  18956. use PhpCsFixer\AbstractFixer;
  18957. use PhpCsFixer\FixerDefinition\CodeSample;
  18958. use PhpCsFixer\FixerDefinition\FixerDefinition;
  18959. use PhpCsFixer\Tokenizer\Token;
  18960. use PhpCsFixer\Tokenizer\Tokens;
  18961. final class PhpdocInlineTagFixer extends AbstractFixer
  18962. {
  18963. public function getDefinition()
  18964. {
  18965. return new FixerDefinition(
  18966. 'Fix phpdoc inline tags, make inheritdoc always inline.',
  18967. [new CodeSample(
  18968. '<?php
  18969. /**
  18970. * @{TUTORIAL}
  18971. * {{ @link }}
  18972. * {@examples}
  18973. * @inheritdocs
  18974. */
  18975. '
  18976. )]
  18977. );
  18978. }
  18979. public function isCandidate(Tokens $tokens)
  18980. {
  18981. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  18982. }
  18983. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  18984. {
  18985. foreach ($tokens as $index => $token) {
  18986. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  18987. continue;
  18988. }
  18989. $content = $token->getContent();
  18990. $content = preg_replace_callback(
  18991. '#(?:@{+|{+[ \t]*@)[ \t]*(example|id|internal|inheritdoc|link|source|toc|tutorial)s?([^}]*)(?:}+)#i',
  18992. static function (array $matches) {
  18993. $doc = trim($matches[2]);
  18994. if ('' === $doc) {
  18995. return '{@'.strtolower($matches[1]).'}';
  18996. }
  18997. return '{@'.strtolower($matches[1]).' '.$doc.'}';
  18998. },
  18999. $content
  19000. );
  19001. $content = preg_replace(
  19002. '#(?<!{)@inheritdocs?(?!})#i',
  19003. '{@inheritdoc}',
  19004. $content
  19005. );
  19006. $tokens[$index] = new Token([T_DOC_COMMENT, $content]);
  19007. }
  19008. }
  19009. }
  19010. <?php
  19011. namespace PhpCsFixer\Fixer\Phpdoc;
  19012. use PhpCsFixer\AbstractProxyFixer;
  19013. use PhpCsFixer\FixerDefinition\CodeSample;
  19014. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19015. final class PhpdocNoAccessFixer extends AbstractProxyFixer
  19016. {
  19017. public function getDefinition()
  19018. {
  19019. return new FixerDefinition(
  19020. '@access annotations should be omitted from phpdocs.',
  19021. [
  19022. new CodeSample(
  19023. '<?php
  19024. class Foo
  19025. {
  19026. /**
  19027. * @internal
  19028. * @access private
  19029. */
  19030. private $bar;
  19031. }
  19032. '
  19033. ),
  19034. ]
  19035. );
  19036. }
  19037. protected function createProxyFixers()
  19038. {
  19039. $fixer = new GeneralPhpdocAnnotationRemoveFixer();
  19040. $fixer->configure(['annotations' => ['access']]);
  19041. return [$fixer];
  19042. }
  19043. }
  19044. <?php
  19045. namespace PhpCsFixer\Fixer\Phpdoc;
  19046. use PhpCsFixer\AbstractFixer;
  19047. use PhpCsFixer\DocBlock\DocBlock;
  19048. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  19049. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  19050. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  19051. use PhpCsFixer\FixerDefinition\CodeSample;
  19052. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19053. use PhpCsFixer\Tokenizer\Token;
  19054. use PhpCsFixer\Tokenizer\Tokens;
  19055. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  19056. use Symfony\Component\OptionsResolver\Options;
  19057. final class PhpdocNoAliasTagFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  19058. {
  19059. public function isCandidate(Tokens $tokens)
  19060. {
  19061. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  19062. }
  19063. public function getDefinition()
  19064. {
  19065. return new FixerDefinition(
  19066. 'No alias PHPDoc tags should be used.',
  19067. [
  19068. new CodeSample(
  19069. '<?php
  19070. /**
  19071. * @property string $foo
  19072. * @property-read string $bar
  19073. *
  19074. * @link baz
  19075. */
  19076. final class Example
  19077. {
  19078. }
  19079. '
  19080. ),
  19081. new CodeSample(
  19082. '<?php
  19083. /**
  19084. * @property string $foo
  19085. * @property-read string $bar
  19086. *
  19087. * @link baz
  19088. */
  19089. final class Example
  19090. {
  19091. }
  19092. ',
  19093. ['replacements' => ['link' => 'website']]
  19094. ),
  19095. ]
  19096. );
  19097. }
  19098. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19099. {
  19100. $searchFor = array_keys($this->configuration['replacements']);
  19101. foreach ($tokens as $index => $token) {
  19102. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  19103. continue;
  19104. }
  19105. $doc = new DocBlock($token->getContent());
  19106. $annotations = $doc->getAnnotationsOfType($searchFor);
  19107. if (empty($annotations)) {
  19108. continue;
  19109. }
  19110. foreach ($annotations as $annotation) {
  19111. $annotation->getTag()->setName($this->configuration['replacements'][$annotation->getTag()->getName()]);
  19112. }
  19113. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  19114. }
  19115. }
  19116. protected function createConfigurationDefinition()
  19117. {
  19118. return new FixerConfigurationResolverRootless('replacements', [
  19119. (new FixerOptionBuilder('replacements', 'Mapping between replaced annotations with new ones.'))
  19120. ->setAllowedTypes(['array'])
  19121. ->setNormalizer(static function (Options $options, $value) {
  19122. $normalizedValue = [];
  19123. foreach ($value as $from => $to) {
  19124. if (!is_string($from)) {
  19125. throw new InvalidOptionsException('Tag to replace must be a string.');
  19126. }
  19127. if (!is_string($to)) {
  19128. throw new InvalidOptionsException(sprintf(
  19129. 'Tag to replace to from "%s" must be a string.',
  19130. $from
  19131. ));
  19132. }
  19133. if (1 !== preg_match('#^\S+$#', $to) || false !== strpos($to, '*/')) {
  19134. throw new InvalidOptionsException(sprintf(
  19135. 'Tag "%s" cannot be replaced by invalid tag "%s".',
  19136. $from,
  19137. $to
  19138. ));
  19139. }
  19140. $normalizedValue[trim($from)] = trim($to);
  19141. }
  19142. foreach ($normalizedValue as $from => $to) {
  19143. if (isset($normalizedValue[$to])) {
  19144. throw new InvalidOptionsException(sprintf(
  19145. 'Cannot change tag "%1$s" to tag "%2$s", as the tag "%2$s" is configured to be replaced to "%3$s".',
  19146. $from,
  19147. $to,
  19148. $normalizedValue[$to]
  19149. ));
  19150. }
  19151. }
  19152. return $normalizedValue;
  19153. })
  19154. ->setDefault([
  19155. 'property-read' => 'property',
  19156. 'property-write' => 'property',
  19157. 'type' => 'var',
  19158. 'link' => 'see',
  19159. ])
  19160. ->getOption(),
  19161. ]);
  19162. }
  19163. }
  19164. <?php
  19165. namespace PhpCsFixer\Fixer\Phpdoc;
  19166. use PhpCsFixer\AbstractFixer;
  19167. use PhpCsFixer\DocBlock\Annotation;
  19168. use PhpCsFixer\DocBlock\DocBlock;
  19169. use PhpCsFixer\FixerDefinition\CodeSample;
  19170. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19171. use PhpCsFixer\Tokenizer\Token;
  19172. use PhpCsFixer\Tokenizer\Tokens;
  19173. final class PhpdocNoEmptyReturnFixer extends AbstractFixer
  19174. {
  19175. public function isCandidate(Tokens $tokens)
  19176. {
  19177. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  19178. }
  19179. public function getDefinition()
  19180. {
  19181. return new FixerDefinition(
  19182. '@return void and @return null annotations should be omitted from phpdocs.',
  19183. [
  19184. new CodeSample(
  19185. '<?php
  19186. /**
  19187. * @return null
  19188. */
  19189. function foo() {}
  19190. '
  19191. ),
  19192. new CodeSample(
  19193. '<?php
  19194. /**
  19195. * @return void
  19196. */
  19197. function foo() {}
  19198. '
  19199. ),
  19200. ]
  19201. );
  19202. }
  19203. public function getPriority()
  19204. {
  19205. return 10;
  19206. }
  19207. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19208. {
  19209. foreach ($tokens as $index => $token) {
  19210. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  19211. continue;
  19212. }
  19213. $doc = new DocBlock($token->getContent());
  19214. $annotations = $doc->getAnnotationsOfType('return');
  19215. if (empty($annotations)) {
  19216. continue;
  19217. }
  19218. foreach ($annotations as $annotation) {
  19219. $this->fixAnnotation($doc, $annotation);
  19220. }
  19221. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  19222. }
  19223. }
  19224. private function fixAnnotation(DocBlock $doc, Annotation $annotation)
  19225. {
  19226. if (1 === preg_match('/@return\s+(void|null)(?!\|)/', $doc->getLine($annotation->getStart())->getContent())) {
  19227. $annotation->remove();
  19228. }
  19229. }
  19230. }
  19231. <?php
  19232. namespace PhpCsFixer\Fixer\Phpdoc;
  19233. use PhpCsFixer\AbstractProxyFixer;
  19234. use PhpCsFixer\FixerDefinition\CodeSample;
  19235. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19236. final class PhpdocNoPackageFixer extends AbstractProxyFixer
  19237. {
  19238. public function getDefinition()
  19239. {
  19240. return new FixerDefinition(
  19241. '@package and @subpackage annotations should be omitted from phpdocs.',
  19242. [
  19243. new CodeSample(
  19244. '<?php
  19245. /**
  19246. * @internal
  19247. * @package Foo
  19248. * subpackage Bar
  19249. */
  19250. class Baz
  19251. {
  19252. }
  19253. '
  19254. ),
  19255. ]
  19256. );
  19257. }
  19258. protected function createProxyFixers()
  19259. {
  19260. $fixer = new GeneralPhpdocAnnotationRemoveFixer();
  19261. $fixer->configure(['annotations' => ['package', 'subpackage']]);
  19262. return [$fixer];
  19263. }
  19264. }
  19265. <?php
  19266. namespace PhpCsFixer\Fixer\Phpdoc;
  19267. use PhpCsFixer\AbstractFixer;
  19268. use PhpCsFixer\FixerDefinition\CodeSample;
  19269. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19270. use PhpCsFixer\Tokenizer\CT;
  19271. use PhpCsFixer\Tokenizer\Token;
  19272. use PhpCsFixer\Tokenizer\Tokens;
  19273. final class PhpdocNoUselessInheritdocFixer extends AbstractFixer
  19274. {
  19275. public function getDefinition()
  19276. {
  19277. return new FixerDefinition(
  19278. 'Classy that does not inherit must not have inheritdoc tags.',
  19279. [
  19280. new CodeSample("<?php\n/** {@inheritdoc} */\nclass Sample\n{\n}\n"),
  19281. new CodeSample("<?php\nclass Sample\n{\n /**\n * @inheritdoc\n */\n public function Test()\n {\n }\n}\n"),
  19282. ]
  19283. );
  19284. }
  19285. public function getPriority()
  19286. {
  19287. return 6;
  19288. }
  19289. public function isCandidate(Tokens $tokens)
  19290. {
  19291. return $tokens->isTokenKindFound(T_DOC_COMMENT) && $tokens->isAnyTokenKindsFound([T_CLASS, T_INTERFACE]);
  19292. }
  19293. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19294. {
  19295. for ($index = 1, $count = count($tokens) - 4; $index < $count; ++$index) {
  19296. if ($tokens[$index]->isGivenKind([T_CLASS, T_INTERFACE])) {
  19297. $index = $this->fixClassy($tokens, $index);
  19298. }
  19299. }
  19300. }
  19301. private function fixClassy(Tokens $tokens, $index)
  19302. {
  19303. $classOpenIndex = $tokens->getNextTokenOfKind($index, ['{']);
  19304. $classEndIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $classOpenIndex);
  19305. $extendingOrImplementing = $this->isExtendingOrImplementing($tokens, $index, $classOpenIndex);
  19306. if (!$extendingOrImplementing) {
  19307. $this->fixClassyOutside($tokens, $index);
  19308. }
  19309. if (!$extendingOrImplementing && $this->isUsingTrait($tokens, $index, $classOpenIndex, $classEndIndex)) {
  19310. $extendingOrImplementing = true;
  19311. }
  19312. $this->fixClassyInside($tokens, $classOpenIndex, $classEndIndex, !$extendingOrImplementing);
  19313. return $classEndIndex;
  19314. }
  19315. private function fixClassyInside(Tokens $tokens, $classOpenIndex, $classEndIndex, $fixThisLevel)
  19316. {
  19317. for ($i = $classOpenIndex; $i < $classEndIndex; ++$i) {
  19318. if ($tokens[$i]->isGivenKind(T_CLASS)) {
  19319. $i = $this->fixClassy($tokens, $i);
  19320. } elseif ($fixThisLevel && $tokens[$i]->isGivenKind(T_DOC_COMMENT)) {
  19321. $this->fixToken($tokens, $i);
  19322. }
  19323. }
  19324. }
  19325. private function fixClassyOutside(Tokens $tokens, $classIndex)
  19326. {
  19327. $previousIndex = $tokens->getPrevNonWhitespace($classIndex);
  19328. if ($tokens[$previousIndex]->isGivenKind(T_DOC_COMMENT)) {
  19329. $this->fixToken($tokens, $previousIndex);
  19330. }
  19331. }
  19332. private function fixToken(Tokens $tokens, $tokenIndex)
  19333. {
  19334. $count = 0;
  19335. $content = preg_replace_callback(
  19336. '#(\h*(?:@{*|{*\h*@)\h*inheritdoc\h*)([^}]*)((?:}*)\h*)#i',
  19337. static function ($matches) {
  19338. return ' '.$matches[2];
  19339. },
  19340. $tokens[$tokenIndex]->getContent(),
  19341. -1,
  19342. $count
  19343. );
  19344. if ($count) {
  19345. $tokens[$tokenIndex] = new Token([T_DOC_COMMENT, $content]);
  19346. }
  19347. }
  19348. private function isExtendingOrImplementing(Tokens $tokens, $classIndex, $classOpenIndex)
  19349. {
  19350. for ($index = $classIndex; $index < $classOpenIndex; ++$index) {
  19351. if ($tokens[$index]->isGivenKind([T_EXTENDS, T_IMPLEMENTS])) {
  19352. return true;
  19353. }
  19354. }
  19355. return false;
  19356. }
  19357. private function isUsingTrait(Tokens $tokens, $classIndex, $classOpenIndex, $classCloseIndex)
  19358. {
  19359. if ($tokens[$classIndex]->isGivenKind(T_INTERFACE)) {
  19360. return false;
  19361. }
  19362. $useIndex = $tokens->getNextTokenOfKind($classOpenIndex, [[CT::T_USE_TRAIT]]);
  19363. return null !== $useIndex && $useIndex < $classCloseIndex;
  19364. }
  19365. }
  19366. <?php
  19367. namespace PhpCsFixer\Fixer\Phpdoc;
  19368. use PhpCsFixer\AbstractFixer;
  19369. use PhpCsFixer\DocBlock\DocBlock;
  19370. use PhpCsFixer\FixerDefinition\CodeSample;
  19371. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19372. use PhpCsFixer\Tokenizer\Token;
  19373. use PhpCsFixer\Tokenizer\Tokens;
  19374. final class PhpdocOrderFixer extends AbstractFixer
  19375. {
  19376. public function isCandidate(Tokens $tokens)
  19377. {
  19378. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  19379. }
  19380. public function getDefinition()
  19381. {
  19382. return new FixerDefinition(
  19383. 'Annotations in phpdocs should be ordered so that param annotations come first, then throws annotations, then return annotations.',
  19384. [
  19385. new CodeSample(
  19386. '<?php
  19387. /**
  19388. * Hello there!
  19389. *
  19390. * @throws Exception|RuntimeException dfsdf
  19391. * @custom Test!
  19392. * @return int Return the number of changes.
  19393. * @param string $foo
  19394. * @param bool $bar Bar
  19395. */
  19396. '
  19397. ),
  19398. ]
  19399. );
  19400. }
  19401. public function getPriority()
  19402. {
  19403. return -2;
  19404. }
  19405. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19406. {
  19407. foreach ($tokens as $index => $token) {
  19408. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  19409. continue;
  19410. }
  19411. $content = $token->getContent();
  19412. $content = $this->moveParamAnnotations($content);
  19413. $content = $this->moveReturnAnnotations($content);
  19414. $tokens[$index] = new Token([T_DOC_COMMENT, $content]);
  19415. }
  19416. }
  19417. private function moveParamAnnotations($content)
  19418. {
  19419. $doc = new DocBlock($content);
  19420. $params = $doc->getAnnotationsOfType('param');
  19421. if (empty($params)) {
  19422. return $content;
  19423. }
  19424. $others = $doc->getAnnotationsOfType(['throws', 'return']);
  19425. if (empty($others)) {
  19426. return $content;
  19427. }
  19428. $end = end($params)->getEnd();
  19429. $line = $doc->getLine($end);
  19430. foreach ($others as $other) {
  19431. if ($other->getStart() < $end) {
  19432. $line->setContent($line->getContent().$other->getContent());
  19433. $other->remove();
  19434. }
  19435. }
  19436. return $doc->getContent();
  19437. }
  19438. private function moveReturnAnnotations($content)
  19439. {
  19440. $doc = new DocBlock($content);
  19441. $returns = $doc->getAnnotationsOfType('return');
  19442. if (empty($returns)) {
  19443. return $content;
  19444. }
  19445. $others = $doc->getAnnotationsOfType(['param', 'throws']);
  19446. if (empty($others)) {
  19447. return $content;
  19448. }
  19449. $start = $returns[0]->getStart();
  19450. $line = $doc->getLine($start);
  19451. foreach (array_reverse($others) as $other) {
  19452. if ($other->getEnd() > $start) {
  19453. $line->setContent($other->getContent().$line->getContent());
  19454. $other->remove();
  19455. }
  19456. }
  19457. return $doc->getContent();
  19458. }
  19459. }
  19460. <?php
  19461. namespace PhpCsFixer\Fixer\Phpdoc;
  19462. use PhpCsFixer\AbstractFixer;
  19463. use PhpCsFixer\DocBlock\DocBlock;
  19464. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  19465. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  19466. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  19467. use PhpCsFixer\FixerDefinition\CodeSample;
  19468. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19469. use PhpCsFixer\Tokenizer\Token;
  19470. use PhpCsFixer\Tokenizer\Tokens;
  19471. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  19472. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  19473. use Symfony\Component\OptionsResolver\Options;
  19474. final class PhpdocReturnSelfReferenceFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  19475. {
  19476. private static $toTypes = [
  19477. '$this',
  19478. 'static',
  19479. 'self',
  19480. ];
  19481. public function getDefinition()
  19482. {
  19483. return new FixerDefinition(
  19484. 'The type of `@return` annotations of methods returning a reference to itself must the configured one.',
  19485. [
  19486. new CodeSample(
  19487. '<?php
  19488. class Sample
  19489. {
  19490. /**
  19491. * @return this
  19492. */
  19493. public function test1()
  19494. {
  19495. return $this;
  19496. }
  19497. /**
  19498. * @return $self
  19499. */
  19500. public function test2()
  19501. {
  19502. return $this;
  19503. }
  19504. }
  19505. '
  19506. ),
  19507. new CodeSample(
  19508. '<?php
  19509. class Sample
  19510. {
  19511. /**
  19512. * @return this
  19513. */
  19514. public function test1()
  19515. {
  19516. return $this;
  19517. }
  19518. /**
  19519. * @return $self
  19520. */
  19521. public function test2()
  19522. {
  19523. return $this;
  19524. }
  19525. }
  19526. ',
  19527. ['replacements' => ['this' => 'self']]
  19528. ),
  19529. ]
  19530. );
  19531. }
  19532. public function isCandidate(Tokens $tokens)
  19533. {
  19534. return count($tokens) > 10 && $tokens->isTokenKindFound(T_DOC_COMMENT) && $tokens->isAnyTokenKindsFound([T_CLASS, T_INTERFACE]);
  19535. }
  19536. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19537. {
  19538. $tokensAnalyzer = new TokensAnalyzer($tokens);
  19539. foreach ($tokensAnalyzer->getClassyElements() as $index => $element) {
  19540. if ('method' === $element['type']) {
  19541. $this->fixMethod($tokens, $index);
  19542. }
  19543. }
  19544. }
  19545. protected function createConfigurationDefinition()
  19546. {
  19547. $default = [
  19548. 'this' => '$this',
  19549. '@this' => '$this',
  19550. '$self' => 'self',
  19551. '@self' => 'self',
  19552. '$static' => 'static',
  19553. '@static' => 'static',
  19554. ];
  19555. return new FixerConfigurationResolverRootless('replacements', [
  19556. (new FixerOptionBuilder('replacements', 'Mapping between replaced return types with new ones.'))
  19557. ->setAllowedTypes(['array'])
  19558. ->setNormalizer(static function (Options $options, $value) use ($default) {
  19559. $normalizedValue = [];
  19560. foreach ($value as $from => $to) {
  19561. if (is_string($from)) {
  19562. $from = strtolower($from);
  19563. }
  19564. if (!isset($default[$from])) {
  19565. throw new InvalidOptionsException(sprintf(
  19566. 'Unknown key "%s", expected any of "%s".',
  19567. is_object($from) ? get_class($from) : gettype($from).(is_resource($from) ? '' : '#'.$from),
  19568. implode('", "', array_keys($default))
  19569. ));
  19570. }
  19571. if (!in_array($to, self::$toTypes, true)) {
  19572. throw new InvalidOptionsException(sprintf(
  19573. 'Unknown value "%s", expected any of "%s".',
  19574. is_object($to) ? get_class($to) : gettype($to).(is_resource($to) ? '' : '#'.$to),
  19575. implode('", "', self::$toTypes)
  19576. ));
  19577. }
  19578. $normalizedValue[$from] = $to;
  19579. }
  19580. return $normalizedValue;
  19581. })
  19582. ->setDefault($default)
  19583. ->getOption(),
  19584. ]);
  19585. }
  19586. private function fixMethod(Tokens $tokens, $index)
  19587. {
  19588. static $methodModifiers = [T_STATIC, T_FINAL, T_ABSTRACT, T_PRIVATE, T_PROTECTED, T_PUBLIC];
  19589. do {
  19590. $tokenIndex = $tokens->getPrevMeaningfulToken($index);
  19591. if (!$tokens[$tokenIndex]->isGivenKind($methodModifiers)) {
  19592. break;
  19593. }
  19594. $index = $tokenIndex;
  19595. } while (true);
  19596. $docIndex = $tokens->getPrevNonWhitespace($index);
  19597. if (!$tokens[$docIndex]->isGivenKind(T_DOC_COMMENT)) {
  19598. return;
  19599. }
  19600. $docBlock = new DocBlock($tokens[$docIndex]->getContent());
  19601. $returnsBlock = $docBlock->getAnnotationsOfType('return');
  19602. if (!count($returnsBlock)) {
  19603. return;
  19604. }
  19605. $returnsBlock = $returnsBlock[0];
  19606. $types = $returnsBlock->getTypes();
  19607. if (!count($types)) {
  19608. return;
  19609. }
  19610. $newTypes = [];
  19611. foreach ($types as $type) {
  19612. $lower = strtolower($type);
  19613. $newTypes[] = isset($this->configuration['replacements'][$lower]) ? $this->configuration['replacements'][$lower] : $type;
  19614. }
  19615. if ($types === $newTypes) {
  19616. return;
  19617. }
  19618. $returnsBlock->setTypes($newTypes);
  19619. $tokens[$docIndex] = new Token([T_DOC_COMMENT, $docBlock->getContent()]);
  19620. }
  19621. }
  19622. <?php
  19623. namespace PhpCsFixer\Fixer\Phpdoc;
  19624. use PhpCsFixer\AbstractPhpdocTypesFixer;
  19625. use PhpCsFixer\FixerDefinition\CodeSample;
  19626. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19627. final class PhpdocScalarFixer extends AbstractPhpdocTypesFixer
  19628. {
  19629. private static $types = [
  19630. 'boolean' => 'bool',
  19631. 'double' => 'float',
  19632. 'integer' => 'int',
  19633. 'real' => 'float',
  19634. 'str' => 'string',
  19635. ];
  19636. public function getDefinition()
  19637. {
  19638. return new FixerDefinition(
  19639. 'Scalar types should always be written in the same form. `int` not `integer`, `bool` not `boolean`, `float` not `real` or `double`.',
  19640. [new CodeSample('<?php
  19641. /**
  19642. * @param integer $a
  19643. * @param boolean $b
  19644. * @param real $c
  19645. *
  19646. * @return double
  19647. */
  19648. function sample($a, $b, $c)
  19649. {
  19650. return sample2($a, $b, $c);
  19651. }
  19652. ')]
  19653. );
  19654. }
  19655. public function getPriority()
  19656. {
  19657. return 15;
  19658. }
  19659. protected function normalize($type)
  19660. {
  19661. if (array_key_exists($type, self::$types)) {
  19662. return self::$types[$type];
  19663. }
  19664. return $type;
  19665. }
  19666. }
  19667. <?php
  19668. namespace PhpCsFixer\Fixer\Phpdoc;
  19669. use PhpCsFixer\AbstractFixer;
  19670. use PhpCsFixer\DocBlock\Annotation;
  19671. use PhpCsFixer\DocBlock\DocBlock;
  19672. use PhpCsFixer\DocBlock\TagComparator;
  19673. use PhpCsFixer\FixerDefinition\CodeSample;
  19674. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19675. use PhpCsFixer\Tokenizer\Token;
  19676. use PhpCsFixer\Tokenizer\Tokens;
  19677. final class PhpdocSeparationFixer extends AbstractFixer
  19678. {
  19679. public function getDefinition()
  19680. {
  19681. return new FixerDefinition(
  19682. 'Annotations in phpdocs should be grouped together so that annotations of the same type immediately follow each other, and annotations of a different type are separated by a single blank line.',
  19683. [
  19684. new CodeSample(
  19685. '<?php
  19686. /**
  19687. * Description.
  19688. * @param string $foo
  19689. *
  19690. *
  19691. * @param bool $bar Bar
  19692. * @throws Exception|RuntimeException
  19693. * @return bool
  19694. */
  19695. function fnc($foo, $bar) {}
  19696. '
  19697. ),
  19698. ]
  19699. );
  19700. }
  19701. public function getPriority()
  19702. {
  19703. return -3;
  19704. }
  19705. public function isCandidate(Tokens $tokens)
  19706. {
  19707. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  19708. }
  19709. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19710. {
  19711. foreach ($tokens as $index => $token) {
  19712. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  19713. continue;
  19714. }
  19715. $doc = new DocBlock($token->getContent());
  19716. $this->fixDescription($doc);
  19717. $this->fixAnnotations($doc);
  19718. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  19719. }
  19720. }
  19721. private function fixDescription(DocBlock $doc)
  19722. {
  19723. foreach ($doc->getLines() as $index => $line) {
  19724. if ($line->containsATag()) {
  19725. break;
  19726. }
  19727. if ($line->containsUsefulContent()) {
  19728. $next = $doc->getLine($index + 1);
  19729. if ($next->containsATag()) {
  19730. $line->addBlank();
  19731. break;
  19732. }
  19733. }
  19734. }
  19735. }
  19736. private function fixAnnotations(DocBlock $doc)
  19737. {
  19738. foreach ($doc->getAnnotations() as $index => $annotation) {
  19739. $next = $doc->getAnnotation($index + 1);
  19740. if (null === $next) {
  19741. break;
  19742. }
  19743. if (true === $next->getTag()->valid()) {
  19744. if (TagComparator::shouldBeTogether($annotation->getTag(), $next->getTag())) {
  19745. $this->ensureAreTogether($doc, $annotation, $next);
  19746. } else {
  19747. $this->ensureAreSeparate($doc, $annotation, $next);
  19748. }
  19749. }
  19750. }
  19751. return $doc->getContent();
  19752. }
  19753. private function ensureAreTogether(DocBlock $doc, Annotation $first, Annotation $second)
  19754. {
  19755. $pos = $first->getEnd();
  19756. $final = $second->getStart();
  19757. for ($pos = $pos + 1; $pos < $final; ++$pos) {
  19758. $doc->getLine($pos)->remove();
  19759. }
  19760. }
  19761. private function ensureAreSeparate(DocBlock $doc, Annotation $first, Annotation $second)
  19762. {
  19763. $pos = $first->getEnd();
  19764. $final = $second->getStart() - 1;
  19765. if ($pos === $final) {
  19766. $doc->getLine($pos)->addBlank();
  19767. return;
  19768. }
  19769. for ($pos = $pos + 1; $pos < $final; ++$pos) {
  19770. $doc->getLine($pos)->remove();
  19771. }
  19772. }
  19773. }
  19774. <?php
  19775. namespace PhpCsFixer\Fixer\Phpdoc;
  19776. use PhpCsFixer\AbstractFixer;
  19777. use PhpCsFixer\FixerDefinition\CodeSample;
  19778. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19779. use PhpCsFixer\Tokenizer\Token;
  19780. use PhpCsFixer\Tokenizer\Tokens;
  19781. final class PhpdocSingleLineVarSpacingFixer extends AbstractFixer
  19782. {
  19783. public function getDefinition()
  19784. {
  19785. return new FixerDefinition(
  19786. 'Single line @var PHPDoc should have proper spacing.',
  19787. [new CodeSample("<?php /**@var MyClass \$a */\n\$a = test();\n")]
  19788. );
  19789. }
  19790. public function getPriority()
  19791. {
  19792. return -10;
  19793. }
  19794. public function isCandidate(Tokens $tokens)
  19795. {
  19796. return $tokens->isAnyTokenKindsFound([T_COMMENT, T_DOC_COMMENT]);
  19797. }
  19798. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19799. {
  19800. foreach ($tokens as $index => $token) {
  19801. if ($token->isGivenKind(T_DOC_COMMENT)) {
  19802. $tokens[$index] = new Token([T_DOC_COMMENT, $this->fixTokenContent($token->getContent())]);
  19803. continue;
  19804. }
  19805. if (!$token->isGivenKind(T_COMMENT)) {
  19806. continue;
  19807. }
  19808. $content = $token->getContent();
  19809. $fixedContent = $this->fixTokenContent($content);
  19810. if ($content !== $fixedContent) {
  19811. $tokens[$index] = new Token([T_DOC_COMMENT, $fixedContent]);
  19812. }
  19813. }
  19814. }
  19815. private function fixTokenContent($content)
  19816. {
  19817. return preg_replace_callback(
  19818. '#^/\*\*[ \t]*@var[ \t]+(\S+)[ \t]*(\$\S+)?[ \t]*([^\n]*)\*/$#',
  19819. static function (array $matches) {
  19820. $content = '/** @var';
  19821. for ($i = 1, $m = count($matches); $i < $m; ++$i) {
  19822. if ('' !== $matches[$i]) {
  19823. $content .= ' '.$matches[$i];
  19824. }
  19825. }
  19826. $content = rtrim($content);
  19827. return $content.' */';
  19828. },
  19829. $content
  19830. );
  19831. }
  19832. }
  19833. <?php
  19834. namespace PhpCsFixer\Fixer\Phpdoc;
  19835. use PhpCsFixer\AbstractFixer;
  19836. use PhpCsFixer\DocBlock\DocBlock;
  19837. use PhpCsFixer\DocBlock\Line;
  19838. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  19839. use PhpCsFixer\FixerDefinition\CodeSample;
  19840. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19841. use PhpCsFixer\Tokenizer\Token;
  19842. use PhpCsFixer\Tokenizer\Tokens;
  19843. final class PhpdocSummaryFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  19844. {
  19845. public function getDefinition()
  19846. {
  19847. return new FixerDefinition(
  19848. 'Phpdocs summary should end in either a full stop, exclamation mark, or question mark.',
  19849. [new CodeSample('<?php
  19850. /**
  19851. * Foo function is great
  19852. */
  19853. function foo () {}
  19854. ')]
  19855. );
  19856. }
  19857. public function isCandidate(Tokens $tokens)
  19858. {
  19859. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  19860. }
  19861. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19862. {
  19863. foreach ($tokens as $index => $token) {
  19864. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  19865. continue;
  19866. }
  19867. $doc = new DocBlock($token->getContent());
  19868. $end = $this->findShortDescriptionEnd($doc->getLines());
  19869. if (null !== $end) {
  19870. $line = $doc->getLine($end);
  19871. $content = rtrim($line->getContent());
  19872. if (!$this->isCorrectlyFormatted($content)) {
  19873. $line->setContent($content.'.'.$this->whitespacesConfig->getLineEnding());
  19874. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  19875. }
  19876. }
  19877. }
  19878. }
  19879. private function findShortDescriptionEnd(array $lines)
  19880. {
  19881. $reachedContent = false;
  19882. foreach ($lines as $index => $line) {
  19883. if ($reachedContent && ($line->containsATag() || !$line->containsUsefulContent())) {
  19884. return $index - 1;
  19885. }
  19886. if ($line->containsATag()) {
  19887. return null;
  19888. }
  19889. if ($line->containsUsefulContent()) {
  19890. $reachedContent = true;
  19891. }
  19892. }
  19893. }
  19894. private function isCorrectlyFormatted($content)
  19895. {
  19896. if (false !== stripos($content, '{@inheritdoc}')) {
  19897. return true;
  19898. }
  19899. return $content !== rtrim($content, '.。!?¡¿�?');
  19900. }
  19901. }
  19902. <?php
  19903. namespace PhpCsFixer\Fixer\Phpdoc;
  19904. use PhpCsFixer\AbstractFixer;
  19905. use PhpCsFixer\FixerDefinition\CodeSample;
  19906. use PhpCsFixer\FixerDefinition\FixerDefinition;
  19907. use PhpCsFixer\Tokenizer\CT;
  19908. use PhpCsFixer\Tokenizer\Token;
  19909. use PhpCsFixer\Tokenizer\Tokens;
  19910. final class PhpdocToCommentFixer extends AbstractFixer
  19911. {
  19912. public function isCandidate(Tokens $tokens)
  19913. {
  19914. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  19915. }
  19916. public function getPriority()
  19917. {
  19918. return 25;
  19919. }
  19920. public function getDefinition()
  19921. {
  19922. return new FixerDefinition(
  19923. 'Docblocks should only be used on structural elements.',
  19924. [
  19925. new CodeSample(
  19926. '<?php
  19927. $first = true;// needed because by default first docblock is never fixed.
  19928. /** This should not be a docblock */
  19929. foreach($connections as $key => $sqlite) {
  19930. $sqlite->open($path);
  19931. }
  19932. '
  19933. ),
  19934. ]
  19935. );
  19936. }
  19937. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  19938. {
  19939. static $controlStructures = [
  19940. T_FOREACH,
  19941. T_IF,
  19942. T_SWITCH,
  19943. T_WHILE,
  19944. T_FOR,
  19945. ];
  19946. static $languageStructures = [
  19947. T_LIST,
  19948. T_PRINT,
  19949. T_ECHO,
  19950. CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN,
  19951. ];
  19952. foreach ($tokens as $index => $token) {
  19953. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  19954. continue;
  19955. }
  19956. $nextIndex = $tokens->getNextMeaningfulToken($index);
  19957. $nextToken = null !== $nextIndex ? $tokens[$nextIndex] : null;
  19958. if (null === $nextToken || $nextToken->equals('}')) {
  19959. $tokens[$index] = new Token([T_COMMENT, '/*'.ltrim($token->getContent(), '/*')]);
  19960. continue;
  19961. }
  19962. if ($this->isStructuralElement($nextToken)) {
  19963. continue;
  19964. }
  19965. if ($nextToken->isGivenKind($controlStructures) && $this->isValidControl($tokens, $token, $nextIndex)) {
  19966. continue;
  19967. }
  19968. if ($nextToken->isGivenKind(T_VARIABLE) && $this->isValidVariable($tokens, $nextIndex)) {
  19969. continue;
  19970. }
  19971. if ($nextToken->isGivenKind($languageStructures) && $this->isValidLanguageConstruct($tokens, $token, $nextIndex)) {
  19972. continue;
  19973. }
  19974. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  19975. if ($tokens[$prevIndex]->isGivenKind([T_OPEN_TAG, T_NAMESPACE])) {
  19976. continue;
  19977. }
  19978. $tokens[$index] = new Token([T_COMMENT, '/*'.ltrim($token->getContent(), '/*')]);
  19979. }
  19980. }
  19981. private function isStructuralElement(Token $token)
  19982. {
  19983. static $skip = [
  19984. T_PRIVATE,
  19985. T_PROTECTED,
  19986. T_PUBLIC,
  19987. T_VAR,
  19988. T_FUNCTION,
  19989. T_ABSTRACT,
  19990. T_CONST,
  19991. T_NAMESPACE,
  19992. T_REQUIRE,
  19993. T_REQUIRE_ONCE,
  19994. T_INCLUDE,
  19995. T_INCLUDE_ONCE,
  19996. T_FINAL,
  19997. T_STATIC,
  19998. ];
  19999. return $token->isClassy() || $token->isGivenKind($skip);
  20000. }
  20001. private function isValidControl(Tokens $tokens, Token $docsToken, $controlIndex)
  20002. {
  20003. $index = $tokens->getNextMeaningfulToken($controlIndex);
  20004. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  20005. $docsContent = $docsToken->getContent();
  20006. for ($index = $index + 1; $index < $endIndex; ++$index) {
  20007. $token = $tokens[$index];
  20008. if (
  20009. $token->isGivenKind(T_VARIABLE) &&
  20010. false !== strpos($docsContent, $token->getContent())
  20011. ) {
  20012. return true;
  20013. }
  20014. }
  20015. return false;
  20016. }
  20017. private function isValidLanguageConstruct(Tokens $tokens, Token $docsToken, $languageConstructIndex)
  20018. {
  20019. $endKind = $tokens[$languageConstructIndex]->isGivenKind(CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN)
  20020. ? [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE]
  20021. : ')'
  20022. ;
  20023. $endIndex = $tokens->getNextTokenOfKind($languageConstructIndex, [$endKind]);
  20024. $docsContent = $docsToken->getContent();
  20025. for ($index = $languageConstructIndex + 1; $index < $endIndex; ++$index) {
  20026. $token = $tokens[$index];
  20027. if (
  20028. $token->isGivenKind(T_VARIABLE)
  20029. && false !== strpos($docsContent, $token->getContent())
  20030. ) {
  20031. return true;
  20032. }
  20033. }
  20034. return false;
  20035. }
  20036. private function isValidVariable(Tokens $tokens, $variableIndex)
  20037. {
  20038. $nextIndex = $tokens->getNextMeaningfulToken($variableIndex);
  20039. return $tokens[$nextIndex]->equals('=');
  20040. }
  20041. }
  20042. <?php
  20043. namespace PhpCsFixer\Fixer\Phpdoc;
  20044. use PhpCsFixer\AbstractFixer;
  20045. use PhpCsFixer\FixerDefinition\CodeSample;
  20046. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20047. use PhpCsFixer\Tokenizer\Token;
  20048. use PhpCsFixer\Tokenizer\Tokens;
  20049. final class PhpdocTrimFixer extends AbstractFixer
  20050. {
  20051. public function getDefinition()
  20052. {
  20053. return new FixerDefinition(
  20054. 'Phpdocs should start and end with content, excluding the very first and last line of the docblocks.',
  20055. [new CodeSample('<?php
  20056. /**
  20057. *
  20058. * Foo must be final class.
  20059. *
  20060. *
  20061. */
  20062. final class Foo {}
  20063. ')]
  20064. );
  20065. }
  20066. public function getPriority()
  20067. {
  20068. return -5;
  20069. }
  20070. public function isCandidate(Tokens $tokens)
  20071. {
  20072. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  20073. }
  20074. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20075. {
  20076. foreach ($tokens as $index => $token) {
  20077. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  20078. continue;
  20079. }
  20080. $content = $token->getContent();
  20081. $content = $this->fixStart($content);
  20082. $content = $this->fixEnd($content);
  20083. $tokens[$index] = new Token([T_DOC_COMMENT, $content]);
  20084. }
  20085. }
  20086. private function fixStart($content)
  20087. {
  20088. return preg_replace(
  20089. '~
  20090. (^/\*\*) # DocComment begin
  20091. (?:
  20092. \R[ \t]*(?:\*[ \t]*)? # lines without useful content
  20093. (?!\R[ \t]*\*/) # not followed by a DocComment end
  20094. )+
  20095. (\R[ \t]*(?:\*[ \t]*)?\S) # first line with useful content
  20096. ~x',
  20097. '$1$2',
  20098. $content
  20099. );
  20100. }
  20101. private function fixEnd($content)
  20102. {
  20103. return preg_replace(
  20104. '~
  20105. (\R[ \t]*(?:\*[ \t]*)?\S.*?) # last line with useful content
  20106. (?:
  20107. (?<!/\*\*) # not preceded by a DocComment start
  20108. \R[ \t]*(?:\*[ \t]*)? # lines without useful content
  20109. )+
  20110. (\R[ \t]*\*/$) # DocComment end
  20111. ~xu',
  20112. '$1$2',
  20113. $content
  20114. );
  20115. }
  20116. }
  20117. <?php
  20118. namespace PhpCsFixer\Fixer\Phpdoc;
  20119. use PhpCsFixer\AbstractPhpdocTypesFixer;
  20120. use PhpCsFixer\FixerDefinition\CodeSample;
  20121. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20122. final class PhpdocTypesFixer extends AbstractPhpdocTypesFixer
  20123. {
  20124. private static $types = [
  20125. 'array',
  20126. 'bool',
  20127. 'boolean',
  20128. 'callable',
  20129. 'double',
  20130. 'false',
  20131. 'float',
  20132. 'int',
  20133. 'integer',
  20134. 'iterable',
  20135. 'mixed',
  20136. 'null',
  20137. 'object',
  20138. 'real',
  20139. 'resource',
  20140. 'self',
  20141. 'static',
  20142. 'string',
  20143. 'true',
  20144. 'void',
  20145. '$this',
  20146. ];
  20147. public function getDefinition()
  20148. {
  20149. return new FixerDefinition(
  20150. 'The correct case must be used for standard PHP types in phpdoc.',
  20151. [
  20152. new CodeSample(
  20153. '<?php
  20154. /**
  20155. * @param STRING|String[] $bar
  20156. *
  20157. * @return inT[]
  20158. */
  20159. '
  20160. ),
  20161. ]
  20162. );
  20163. }
  20164. public function getPriority()
  20165. {
  20166. return 16;
  20167. }
  20168. protected function normalize($type)
  20169. {
  20170. $lower = strtolower($type);
  20171. if (in_array($lower, self::$types, true)) {
  20172. return $lower;
  20173. }
  20174. return $type;
  20175. }
  20176. }
  20177. <?php
  20178. namespace PhpCsFixer\Fixer\Phpdoc;
  20179. use PhpCsFixer\AbstractFixer;
  20180. use PhpCsFixer\DocBlock\Annotation;
  20181. use PhpCsFixer\DocBlock\DocBlock;
  20182. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  20183. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  20184. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  20185. use PhpCsFixer\FixerDefinition\CodeSample;
  20186. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20187. use PhpCsFixer\Tokenizer\Token;
  20188. use PhpCsFixer\Tokenizer\Tokens;
  20189. use PhpCsFixer\Utils;
  20190. final class PhpdocTypesOrderFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  20191. {
  20192. public function getDefinition()
  20193. {
  20194. return new FixerDefinition(
  20195. 'Sorts PHPDoc types.',
  20196. [
  20197. new CodeSample(
  20198. '<?php
  20199. /**
  20200. * @param string|null $bar
  20201. */
  20202. '
  20203. ),
  20204. new CodeSample(
  20205. '<?php
  20206. /**
  20207. * @param null|string $bar
  20208. */
  20209. ',
  20210. ['null_adjustment' => 'always_last']
  20211. ),
  20212. new CodeSample(
  20213. '<?php
  20214. /**
  20215. * @param null|string|int|\Foo $bar
  20216. */
  20217. ',
  20218. ['sort_algorithm' => 'alpha']
  20219. ),
  20220. new CodeSample(
  20221. '<?php
  20222. /**
  20223. * @param null|string|int|\Foo $bar
  20224. */
  20225. ',
  20226. [
  20227. 'sort_algorithm' => 'alpha',
  20228. 'null_adjustment' => 'always_last',
  20229. ]
  20230. ),
  20231. new CodeSample(
  20232. '<?php
  20233. /**
  20234. * @param null|string|int|\Foo $bar
  20235. */
  20236. ',
  20237. [
  20238. 'sort_algorithm' => 'alpha',
  20239. 'null_adjustment' => 'none',
  20240. ]
  20241. ),
  20242. ]
  20243. );
  20244. }
  20245. public function isCandidate(Tokens $tokens)
  20246. {
  20247. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  20248. }
  20249. protected function createConfigurationDefinition()
  20250. {
  20251. return new FixerConfigurationResolver([
  20252. (new FixerOptionBuilder('sort_algorithm', 'The sorting algorithm to apply.'))
  20253. ->setAllowedValues(['alpha', 'none'])
  20254. ->setDefault('alpha')
  20255. ->getOption(),
  20256. (new FixerOptionBuilder('null_adjustment', 'Forces the position of `null` (overrides `sort_algorithm`).'))
  20257. ->setAllowedValues(['always_first', 'always_last', 'none'])
  20258. ->setDefault('always_first')
  20259. ->getOption(),
  20260. ]);
  20261. }
  20262. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20263. {
  20264. foreach ($tokens as $index => $token) {
  20265. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  20266. continue;
  20267. }
  20268. $doc = new DocBlock($token->getContent());
  20269. $annotations = $doc->getAnnotationsOfType(Annotation::getTagsWithTypes());
  20270. if (!count($annotations)) {
  20271. continue;
  20272. }
  20273. foreach ($annotations as $annotation) {
  20274. $types = $annotation->getTypes();
  20275. $annotation->setTypes($this->sortTypes($types));
  20276. $line = $doc->getLine($annotation->getStart());
  20277. $line->setContent(preg_replace_callback('/(@method\s+.+?\s+\w+\()(.*)\)/', function (array $matches) {
  20278. $sorted = preg_replace_callback('/((?:^|,)\s*)([^\s]+)/', function (array $matches) {
  20279. return $matches[1].$this->sortJoinedTypes($matches[2]);
  20280. }, $matches[2]);
  20281. return $matches[1].$sorted.')';
  20282. }, $line->getContent()));
  20283. }
  20284. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  20285. }
  20286. }
  20287. private function sortTypes(array $types)
  20288. {
  20289. foreach ($types as $index => $type) {
  20290. $types[$index] = preg_replace_callback('/^([^<]+)<(?:(.+?)(,\s*))?(.*)>$/', function (array $matches) {
  20291. return $matches[1].'<'.$this->sortJoinedTypes($matches[2]).$matches[3].$this->sortJoinedTypes($matches[4]).'>';
  20292. }, $type);
  20293. }
  20294. if ('alpha' === $this->configuration['sort_algorithm']) {
  20295. $types = Utils::stableSort(
  20296. $types,
  20297. static function ($type) { return $type; },
  20298. static function ($typeA, $typeB) {
  20299. $regexp = '/^\\??\\\?/';
  20300. return strcasecmp(
  20301. preg_replace($regexp, '', $typeA),
  20302. preg_replace($regexp, '', $typeB)
  20303. );
  20304. }
  20305. );
  20306. }
  20307. if ('none' !== $this->configuration['null_adjustment']) {
  20308. $nulls = [];
  20309. foreach ($types as $index => $type) {
  20310. if (preg_match('/^\\\?null$/i', $type)) {
  20311. $nulls[$index] = $type;
  20312. unset($types[$index]);
  20313. }
  20314. }
  20315. if (count($nulls)) {
  20316. if ('always_last' === $this->configuration['null_adjustment']) {
  20317. array_push($types, ...$nulls);
  20318. } else {
  20319. array_unshift($types, ...$nulls);
  20320. }
  20321. }
  20322. }
  20323. return $types;
  20324. }
  20325. private function sortJoinedTypes($types)
  20326. {
  20327. $types = array_filter(
  20328. preg_split('/([^|<]+(?:<.*>)?)/', $types, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY),
  20329. static function ($value) {
  20330. return '|' !== $value;
  20331. }
  20332. );
  20333. return implode('|', $this->sortTypes($types));
  20334. }
  20335. }
  20336. <?php
  20337. namespace PhpCsFixer\Fixer\Phpdoc;
  20338. use PhpCsFixer\AbstractFixer;
  20339. use PhpCsFixer\DocBlock\DocBlock;
  20340. use PhpCsFixer\DocBlock\Line;
  20341. use PhpCsFixer\FixerDefinition\CodeSample;
  20342. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20343. use PhpCsFixer\Tokenizer\Token;
  20344. use PhpCsFixer\Tokenizer\Tokens;
  20345. final class PhpdocVarWithoutNameFixer extends AbstractFixer
  20346. {
  20347. public function getDefinition()
  20348. {
  20349. return new FixerDefinition(
  20350. '@var and @type annotations should not contain the variable name.',
  20351. [new CodeSample('<?php
  20352. final class Foo
  20353. {
  20354. /**
  20355. * @var int $bar
  20356. */
  20357. public $bar;
  20358. /**
  20359. * @var $baz float
  20360. */
  20361. public $baz;
  20362. }
  20363. ')]
  20364. );
  20365. }
  20366. public function isCandidate(Tokens $tokens)
  20367. {
  20368. return $tokens->isTokenKindFound(T_DOC_COMMENT);
  20369. }
  20370. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20371. {
  20372. foreach ($tokens as $index => $token) {
  20373. if (!$token->isGivenKind(T_DOC_COMMENT)) {
  20374. continue;
  20375. }
  20376. $doc = new DocBlock($token->getContent());
  20377. if (1 === count($doc->getLines())) {
  20378. continue;
  20379. }
  20380. $annotations = $doc->getAnnotationsOfType(['param', 'return', 'type', 'var']);
  20381. if (!isset($annotations[0]) || !in_array($annotations[0]->getTag()->getName(), ['type', 'var'], true)) {
  20382. continue;
  20383. }
  20384. $this->fixLine($doc->getLine($annotations[0]->getStart()));
  20385. $tokens[$index] = new Token([T_DOC_COMMENT, $doc->getContent()]);
  20386. }
  20387. }
  20388. private function fixLine(Line $line)
  20389. {
  20390. $content = $line->getContent();
  20391. preg_match_all('/ \$[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*/', $content, $matches);
  20392. if (isset($matches[0][0])) {
  20393. $line->setContent(str_replace($matches[0][0], '', $content));
  20394. }
  20395. }
  20396. }
  20397. <?php
  20398. namespace PhpCsFixer\Fixer\ReturnNotation;
  20399. use PhpCsFixer\AbstractProxyFixer;
  20400. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  20401. use PhpCsFixer\Fixer\Whitespace\BlankLineBeforeStatementFixer;
  20402. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  20403. use PhpCsFixer\FixerDefinition\CodeSample;
  20404. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20405. final class BlankLineBeforeReturnFixer extends AbstractProxyFixer implements DeprecatedFixerInterface, WhitespacesAwareFixerInterface
  20406. {
  20407. public function getDefinition()
  20408. {
  20409. return new FixerDefinition(
  20410. 'An empty line feed should precede a return statement.',
  20411. [new CodeSample("<?php\nfunction A()\n{\n echo 1;\n return 1;\n}\n")]
  20412. );
  20413. }
  20414. public function getSuccessorsNames()
  20415. {
  20416. return array_keys($this->proxyFixers);
  20417. }
  20418. protected function createProxyFixers()
  20419. {
  20420. $fixer = new BlankLineBeforeStatementFixer();
  20421. $fixer->configure(['statements' => ['return']]);
  20422. return [$fixer];
  20423. }
  20424. }
  20425. <?php
  20426. namespace PhpCsFixer\Fixer\ReturnNotation;
  20427. use PhpCsFixer\AbstractFixer;
  20428. use PhpCsFixer\FixerDefinition\CodeSample;
  20429. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20430. use PhpCsFixer\Tokenizer\Tokens;
  20431. final class NoUselessReturnFixer extends AbstractFixer
  20432. {
  20433. public function isCandidate(Tokens $tokens)
  20434. {
  20435. return $tokens->isAllTokenKindsFound([T_FUNCTION, T_RETURN]);
  20436. }
  20437. public function getDefinition()
  20438. {
  20439. return new FixerDefinition(
  20440. 'There should not be an empty return statement at the end of a function.',
  20441. [
  20442. new CodeSample(
  20443. '<?php
  20444. function example($b) {
  20445. if ($b) {
  20446. return;
  20447. }
  20448. return;
  20449. }
  20450. '
  20451. ),
  20452. ]
  20453. );
  20454. }
  20455. public function getPriority()
  20456. {
  20457. return -18;
  20458. }
  20459. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20460. {
  20461. foreach ($tokens as $index => $token) {
  20462. if (!$token->isGivenKind(T_FUNCTION)) {
  20463. continue;
  20464. }
  20465. $index = $tokens->getNextTokenOfKind($index, [';', '{']);
  20466. if ($tokens[$index]->equals('{')) {
  20467. $this->fixFunction($tokens, $index, $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index));
  20468. }
  20469. }
  20470. }
  20471. private function fixFunction(Tokens $tokens, $start, $end)
  20472. {
  20473. for ($index = $end; $index > $start; --$index) {
  20474. if (!$tokens[$index]->isGivenKind(T_RETURN)) {
  20475. continue;
  20476. }
  20477. $nextAt = $tokens->getNextMeaningfulToken($index);
  20478. if (!$tokens[$nextAt]->equals(';')) {
  20479. continue;
  20480. }
  20481. if ($tokens->getNextMeaningfulToken($nextAt) !== $end) {
  20482. continue;
  20483. }
  20484. $previous = $tokens->getPrevMeaningfulToken($index);
  20485. if ($tokens[$previous]->equalsAny([[T_ELSE], ')'])) {
  20486. continue;
  20487. }
  20488. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  20489. $tokens->clearTokenAndMergeSurroundingWhitespace($nextAt);
  20490. }
  20491. }
  20492. }
  20493. <?php
  20494. namespace PhpCsFixer\Fixer\ReturnNotation;
  20495. use PhpCsFixer\AbstractFixer;
  20496. use PhpCsFixer\FixerDefinition\CodeSample;
  20497. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20498. use PhpCsFixer\FixerDefinition\VersionSpecification;
  20499. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  20500. use PhpCsFixer\Tokenizer\CT;
  20501. use PhpCsFixer\Tokenizer\Tokens;
  20502. final class SimplifiedNullReturnFixer extends AbstractFixer
  20503. {
  20504. public function getDefinition()
  20505. {
  20506. return new FixerDefinition(
  20507. 'A return statement wishing to return `void` should not return `null`.',
  20508. [
  20509. new CodeSample("<?php return null;\n"),
  20510. new VersionSpecificCodeSample(
  20511. <<<'EOT'
  20512. <?php
  20513. function foo() { return null; }
  20514. function bar(): int { return null; }
  20515. function baz(): ?int { return null; }
  20516. function xyz(): void { return null; }
  20517. EOT
  20518. ,
  20519. new VersionSpecification(70100)
  20520. ),
  20521. ]
  20522. );
  20523. }
  20524. public function getPriority()
  20525. {
  20526. return -17;
  20527. }
  20528. public function isCandidate(Tokens $tokens)
  20529. {
  20530. return $tokens->isTokenKindFound(T_RETURN);
  20531. }
  20532. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20533. {
  20534. foreach ($tokens as $index => $token) {
  20535. if (!$token->isGivenKind(T_RETURN)) {
  20536. continue;
  20537. }
  20538. if ($this->needFixing($tokens, $index)) {
  20539. $this->clear($tokens, $index);
  20540. }
  20541. }
  20542. }
  20543. private function clear(Tokens $tokens, $index)
  20544. {
  20545. while (!$tokens[++$index]->equals(';')) {
  20546. if ($this->shouldClearToken($tokens, $index)) {
  20547. $tokens->clearAt($index);
  20548. }
  20549. }
  20550. }
  20551. private function needFixing(Tokens $tokens, $index)
  20552. {
  20553. if ($this->isStrictOrNullableReturnTypeFunction($tokens, $index)) {
  20554. return false;
  20555. }
  20556. $content = '';
  20557. while (!$tokens[$index]->equals(';')) {
  20558. $index = $tokens->getNextMeaningfulToken($index);
  20559. $content .= $tokens[$index]->getContent();
  20560. }
  20561. $content = ltrim($content, '(');
  20562. $content = rtrim($content, ');');
  20563. return 'null' === strtolower($content);
  20564. }
  20565. private function isStrictOrNullableReturnTypeFunction(Tokens $tokens, $returnIndex)
  20566. {
  20567. $functionIndex = $returnIndex;
  20568. do {
  20569. $functionIndex = $tokens->getPrevTokenOfKind($functionIndex, [[T_FUNCTION]]);
  20570. if (null === $functionIndex) {
  20571. return false;
  20572. }
  20573. $openingCurlyBraceIndex = $tokens->getNextTokenOfKind($functionIndex, ['{']);
  20574. $closingCurlyBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openingCurlyBraceIndex);
  20575. } while ($closingCurlyBraceIndex < $returnIndex);
  20576. $possibleVoidIndex = $tokens->getPrevMeaningfulToken($openingCurlyBraceIndex);
  20577. $isStrictReturnType = $tokens[$possibleVoidIndex]->isGivenKind(T_STRING) && 'void' !== $tokens[$possibleVoidIndex]->getContent();
  20578. $nullableTypeIndex = $tokens->getNextTokenOfKind($functionIndex, [[CT::T_NULLABLE_TYPE]]);
  20579. $isNullableReturnType = null !== $nullableTypeIndex && $nullableTypeIndex < $openingCurlyBraceIndex;
  20580. return $isStrictReturnType || $isNullableReturnType;
  20581. }
  20582. private function shouldClearToken(Tokens $tokens, $index)
  20583. {
  20584. $token = $tokens[$index];
  20585. return !$token->isComment() && !($token->isWhitespace() && $tokens[$index + 1]->isComment());
  20586. }
  20587. }
  20588. <?php
  20589. namespace PhpCsFixer\Fixer\Semicolon;
  20590. use PhpCsFixer\AbstractFixer;
  20591. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  20592. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  20593. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  20594. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  20595. use PhpCsFixer\FixerDefinition\CodeSample;
  20596. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20597. use PhpCsFixer\Tokenizer\Token;
  20598. use PhpCsFixer\Tokenizer\Tokens;
  20599. final class MultilineWhitespaceBeforeSemicolonsFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  20600. {
  20601. const STRATEGY_NO_MULTI_LINE = 'no_multi_line';
  20602. const STRATEGY_NEW_LINE_FOR_CHAINED_CALLS = 'new_line_for_chained_calls';
  20603. public function isCandidate(Tokens $tokens)
  20604. {
  20605. return $tokens->isTokenKindFound(';');
  20606. }
  20607. public function getDefinition()
  20608. {
  20609. return new FixerDefinition(
  20610. 'Forbid multi-line whitespace before the closing semicolon or move the semicolon to the new line for chained calls.',
  20611. [
  20612. new CodeSample(
  20613. '<?php
  20614. function foo () {
  20615. return 1 + 2
  20616. ;
  20617. }
  20618. '
  20619. ),
  20620. new CodeSample(
  20621. '<?php
  20622. $this->method1()
  20623. ->method2()
  20624. ->method(3);
  20625. ?>
  20626. ',
  20627. ['strategy' => self::STRATEGY_NEW_LINE_FOR_CHAINED_CALLS]
  20628. ),
  20629. ]
  20630. );
  20631. }
  20632. protected function createConfigurationDefinition()
  20633. {
  20634. return new FixerConfigurationResolver([
  20635. (new FixerOptionBuilder(
  20636. 'strategy',
  20637. 'Forbid multi-line whitespace or move the semicolon to the new line for chained calls.'
  20638. ))
  20639. ->setAllowedValues([self::STRATEGY_NO_MULTI_LINE, self::STRATEGY_NEW_LINE_FOR_CHAINED_CALLS])
  20640. ->setDefault(self::STRATEGY_NO_MULTI_LINE)
  20641. ->getOption(),
  20642. ]);
  20643. }
  20644. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20645. {
  20646. if (self::STRATEGY_NEW_LINE_FOR_CHAINED_CALLS === $this->configuration['strategy']) {
  20647. $this->applyChainedCallsFix($tokens);
  20648. return;
  20649. }
  20650. if (self::STRATEGY_NO_MULTI_LINE === $this->configuration['strategy']) {
  20651. $this->applyNoMultiLineFix($tokens);
  20652. }
  20653. }
  20654. private function applyNoMultiLineFix(Tokens $tokens)
  20655. {
  20656. $lineEnding = $this->whitespacesConfig->getLineEnding();
  20657. foreach ($tokens as $index => $token) {
  20658. if (!$token->equals(';')) {
  20659. continue;
  20660. }
  20661. $previousIndex = $index - 1;
  20662. $previous = $tokens[$previousIndex];
  20663. if (!$previous->isWhitespace() || false === strpos($previous->getContent(), "\n")) {
  20664. continue;
  20665. }
  20666. $content = $previous->getContent();
  20667. if (0 === strpos($content, $lineEnding) && $tokens[$index - 2]->isComment()) {
  20668. $tokens->ensureWhitespaceAtIndex($previousIndex, 0, $lineEnding);
  20669. } else {
  20670. $tokens->clearAt($previousIndex);
  20671. }
  20672. }
  20673. }
  20674. private function applyChainedCallsFix(Tokens $tokens)
  20675. {
  20676. for ($index = count($tokens) - 1; $index >= 0; --$index) {
  20677. if (!$tokens[$index]->equals(';')) {
  20678. continue;
  20679. }
  20680. $indent = $this->findWhitespaceBeforeFirstCall($index - 1, $tokens);
  20681. if (null === $indent) {
  20682. continue;
  20683. }
  20684. $tokens->clearAt($index);
  20685. $index = $this->getNewLineIndex($index, $tokens);
  20686. $lineEnding = $this->whitespacesConfig->getLineEnding();
  20687. $newline = new Token([T_WHITESPACE, $lineEnding.$indent]);
  20688. $tokens->insertAt($index, [$newline, new Token(';')]);
  20689. }
  20690. }
  20691. private function getNewLineIndex($index, Tokens $tokens)
  20692. {
  20693. $lineEnding = $this->whitespacesConfig->getLineEnding();
  20694. for ($index, $count = count($tokens); $index < $count; ++$index) {
  20695. if (false !== strstr($tokens[$index]->getContent(), $lineEnding)) {
  20696. return $index;
  20697. }
  20698. }
  20699. return $index;
  20700. }
  20701. private function findWhitespaceBeforeFirstCall($index, Tokens $tokens)
  20702. {
  20703. if (!$tokens[$index]->equals(')')) {
  20704. return null;
  20705. }
  20706. $openingBrackets = 1;
  20707. for (--$index; $index > 0; --$index) {
  20708. if ($tokens[$index]->equals(')')) {
  20709. ++$openingBrackets;
  20710. continue;
  20711. }
  20712. if ($tokens[$index]->equals('(')) {
  20713. if (1 === $openingBrackets) {
  20714. break;
  20715. }
  20716. --$openingBrackets;
  20717. }
  20718. }
  20719. if (!$tokens[--$index]->isGivenKind(T_STRING)) {
  20720. return null;
  20721. }
  20722. if (!$tokens[--$index]->isGivenKind(T_OBJECT_OPERATOR)) {
  20723. return null;
  20724. }
  20725. if (!$tokens[--$index]->isGivenKind(T_WHITESPACE)) {
  20726. return null;
  20727. }
  20728. $closingBrackets = 0;
  20729. for ($index; $index >= 0; --$index) {
  20730. if ($tokens[$index]->equals(')')) {
  20731. ++$closingBrackets;
  20732. }
  20733. if ($tokens[$index]->equals('(')) {
  20734. --$closingBrackets;
  20735. }
  20736. if ($tokens[$index]->isGivenKind(T_VARIABLE) && 0 === $closingBrackets) {
  20737. if ($tokens[--$index]->isGivenKind(T_WHITESPACE)
  20738. || $tokens[$index]->isGivenKind(T_OPEN_TAG)) {
  20739. return $this->getIndentAt($tokens, $index);
  20740. }
  20741. }
  20742. }
  20743. return null;
  20744. }
  20745. private function getIndentAt(Tokens $tokens, $index)
  20746. {
  20747. $content = '';
  20748. $lineEnding = $this->whitespacesConfig->getLineEnding();
  20749. for ($index; $index > 0; --$index) {
  20750. if (false !== strstr($tokens[$index]->getContent(), $lineEnding)) {
  20751. break;
  20752. }
  20753. }
  20754. if ($tokens[$index]->isWhitespace()) {
  20755. $content = $tokens[$index]->getContent();
  20756. --$index;
  20757. }
  20758. if ($tokens[$index]->isGivenKind(T_OPEN_TAG)) {
  20759. $content = $tokens[$index]->getContent().$content;
  20760. }
  20761. if (1 === preg_match('/\R{1}([ \t]*)$/', $content, $matches)) {
  20762. return $matches[1];
  20763. }
  20764. return null;
  20765. }
  20766. }
  20767. <?php
  20768. namespace PhpCsFixer\Fixer\Semicolon;
  20769. use PhpCsFixer\AbstractFixer;
  20770. use PhpCsFixer\FixerDefinition\CodeSample;
  20771. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20772. use PhpCsFixer\Tokenizer\Tokens;
  20773. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  20774. final class NoEmptyStatementFixer extends AbstractFixer
  20775. {
  20776. public function getDefinition()
  20777. {
  20778. return new FixerDefinition(
  20779. 'Remove useless semicolon statements.',
  20780. [new CodeSample("<?php \$a = 1;;\n")]
  20781. );
  20782. }
  20783. public function getPriority()
  20784. {
  20785. return 26;
  20786. }
  20787. public function isCandidate(Tokens $tokens)
  20788. {
  20789. return $tokens->isTokenKindFound(';');
  20790. }
  20791. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20792. {
  20793. for ($index = 0, $count = $tokens->count(); $index < $count; ++$index) {
  20794. if ($tokens[$index]->isGivenKind(T_FOR)) {
  20795. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $tokens->getNextMeaningfulToken($index)) + 1;
  20796. continue;
  20797. }
  20798. if (!$tokens[$index]->equals(';')) {
  20799. continue;
  20800. }
  20801. $previousMeaningfulIndex = $tokens->getPrevMeaningfulToken($index);
  20802. if ($tokens[$previousMeaningfulIndex]->equalsAny(['{', ';', [T_OPEN_TAG]])) {
  20803. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  20804. continue;
  20805. }
  20806. if ($tokens[$previousMeaningfulIndex]->equals('}')) {
  20807. $this->fixSemicolonAfterCurlyBraceClose($tokens, $index, $previousMeaningfulIndex);
  20808. }
  20809. }
  20810. }
  20811. private function fixSemicolonAfterCurlyBraceClose(Tokens $tokens, $index, $curlyCloseIndex)
  20812. {
  20813. static $beforeCurlyOpeningKinds = null;
  20814. if (null === $beforeCurlyOpeningKinds) {
  20815. $beforeCurlyOpeningKinds = [T_ELSE, T_FINALLY, T_NAMESPACE, T_OPEN_TAG];
  20816. }
  20817. $curlyOpeningIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $curlyCloseIndex, false);
  20818. $beforeCurlyOpening = $tokens->getPrevMeaningfulToken($curlyOpeningIndex);
  20819. if ($tokens[$beforeCurlyOpening]->isGivenKind($beforeCurlyOpeningKinds) || $tokens[$beforeCurlyOpening]->equalsAny([';', '{', '}'])) {
  20820. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  20821. return;
  20822. }
  20823. if ($tokens[$beforeCurlyOpening]->isGivenKind(T_STRING)) {
  20824. $classyTest = $tokens->getPrevMeaningfulToken($beforeCurlyOpening);
  20825. while ($tokens[$classyTest]->equals(',') || $tokens[$classyTest]->isGivenKind([T_STRING, T_NS_SEPARATOR, T_EXTENDS, T_IMPLEMENTS])) {
  20826. $classyTest = $tokens->getPrevMeaningfulToken($classyTest);
  20827. }
  20828. $tokensAnalyzer = new TokensAnalyzer($tokens);
  20829. if (
  20830. $tokens[$classyTest]->isGivenKind(T_NAMESPACE) ||
  20831. ($tokens[$classyTest]->isClassy() && !$tokensAnalyzer->isAnonymousClass($classyTest))
  20832. ) {
  20833. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  20834. }
  20835. return;
  20836. }
  20837. if (!$tokens[$beforeCurlyOpening]->equals(')')) {
  20838. return;
  20839. }
  20840. $openingBrace = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $beforeCurlyOpening, false);
  20841. $beforeOpeningBrace = $tokens->getPrevMeaningfulToken($openingBrace);
  20842. if ($tokens[$beforeOpeningBrace]->isGivenKind([T_IF, T_ELSEIF, T_FOR, T_FOREACH, T_WHILE, T_SWITCH, T_CATCH, T_DECLARE])) {
  20843. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  20844. return;
  20845. }
  20846. if ($tokens[$beforeOpeningBrace]->isGivenKind(T_STRING)) {
  20847. $beforeString = $tokens->getPrevMeaningfulToken($beforeOpeningBrace);
  20848. if ($tokens[$beforeString]->isGivenKind(T_FUNCTION)) {
  20849. $tokens->clearTokenAndMergeSurroundingWhitespace($index);
  20850. }
  20851. }
  20852. }
  20853. }
  20854. <?php
  20855. namespace PhpCsFixer\Fixer\Semicolon;
  20856. use PhpCsFixer\AbstractProxyFixer;
  20857. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  20858. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  20859. use PhpCsFixer\FixerDefinition\CodeSample;
  20860. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20861. final class NoMultilineWhitespaceBeforeSemicolonsFixer extends AbstractProxyFixer implements DeprecatedFixerInterface, WhitespacesAwareFixerInterface
  20862. {
  20863. public function getDefinition()
  20864. {
  20865. return new FixerDefinition(
  20866. 'Multi-line whitespace before closing semicolon are prohibited.',
  20867. [
  20868. new CodeSample(
  20869. '<?php
  20870. function foo () {
  20871. return 1 + 2
  20872. ;
  20873. }
  20874. '
  20875. ),
  20876. ]
  20877. );
  20878. }
  20879. public function getSuccessorsNames()
  20880. {
  20881. return array_keys($this->proxyFixers);
  20882. }
  20883. protected function createProxyFixers()
  20884. {
  20885. $fixer = new MultilineWhitespaceBeforeSemicolonsFixer();
  20886. $fixer->configure(['strategy' => MultilineWhitespaceBeforeSemicolonsFixer::STRATEGY_NO_MULTI_LINE]);
  20887. return [$fixer];
  20888. }
  20889. }
  20890. <?php
  20891. namespace PhpCsFixer\Fixer\Semicolon;
  20892. use PhpCsFixer\AbstractFixer;
  20893. use PhpCsFixer\FixerDefinition\CodeSample;
  20894. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20895. use PhpCsFixer\Tokenizer\Token;
  20896. use PhpCsFixer\Tokenizer\Tokens;
  20897. final class NoSinglelineWhitespaceBeforeSemicolonsFixer extends AbstractFixer
  20898. {
  20899. public function getDefinition()
  20900. {
  20901. return new FixerDefinition(
  20902. 'Single-line whitespace before closing semicolon are prohibited.',
  20903. [new CodeSample("<?php \$this->foo() ;\n")]
  20904. );
  20905. }
  20906. public function isCandidate(Tokens $tokens)
  20907. {
  20908. return $tokens->isTokenKindFound(';');
  20909. }
  20910. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20911. {
  20912. foreach ($tokens as $index => $token) {
  20913. if (!$token->equals(';') || !$tokens[$index - 1]->isWhitespace(" \t")) {
  20914. continue;
  20915. }
  20916. if ($tokens[$index - 2]->equals(';')) {
  20917. if (!$tokens[$index - 1]->equals(' ')) {
  20918. $tokens[$index - 1] = new Token([T_WHITESPACE, ' ']);
  20919. }
  20920. } elseif (!$tokens[$index - 2]->isComment()) {
  20921. $tokens->clearAt($index - 1);
  20922. }
  20923. }
  20924. }
  20925. }
  20926. <?php
  20927. namespace PhpCsFixer\Fixer\Semicolon;
  20928. use PhpCsFixer\AbstractFixer;
  20929. use PhpCsFixer\FixerDefinition\CodeSample;
  20930. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20931. use PhpCsFixer\Tokenizer\Token;
  20932. use PhpCsFixer\Tokenizer\Tokens;
  20933. final class SemicolonAfterInstructionFixer extends AbstractFixer
  20934. {
  20935. public function getDefinition()
  20936. {
  20937. return new FixerDefinition(
  20938. 'Instructions must be terminated with a semicolon.',
  20939. [new CodeSample("<?php echo 1 ?>\n")]
  20940. );
  20941. }
  20942. public function isCandidate(Tokens $tokens)
  20943. {
  20944. return $tokens->isTokenKindFound(T_CLOSE_TAG);
  20945. }
  20946. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  20947. {
  20948. for ($index = count($tokens) - 1; $index > 1; --$index) {
  20949. if (!$tokens[$index]->isGivenKind(T_CLOSE_TAG)) {
  20950. continue;
  20951. }
  20952. $prev = $tokens->getPrevMeaningfulToken($index);
  20953. if ($tokens[$prev]->equalsAny([';', '{', '}', ':', [T_OPEN_TAG]])) {
  20954. continue;
  20955. }
  20956. $tokens->insertAt($prev + 1, new Token(';'));
  20957. }
  20958. }
  20959. }
  20960. <?php
  20961. namespace PhpCsFixer\Fixer\Semicolon;
  20962. use PhpCsFixer\AbstractFixer;
  20963. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  20964. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  20965. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  20966. use PhpCsFixer\FixerDefinition\CodeSample;
  20967. use PhpCsFixer\FixerDefinition\FixerDefinition;
  20968. use PhpCsFixer\Tokenizer\Token;
  20969. use PhpCsFixer\Tokenizer\Tokens;
  20970. final class SpaceAfterSemicolonFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  20971. {
  20972. public function getDefinition()
  20973. {
  20974. return new FixerDefinition(
  20975. 'Fix whitespace after a semicolon.',
  20976. [
  20977. new CodeSample(
  20978. "<?php
  20979. sample(); \$test = 1;
  20980. sample();\$test = 2;
  20981. for ( ;;++\$sample) {
  20982. }\n"
  20983. ),
  20984. new CodeSample("<?php\nfor (\$i = 0; ; ++\$i) {\n}\n", [
  20985. 'remove_in_empty_for_expressions' => true,
  20986. ]),
  20987. ]
  20988. );
  20989. }
  20990. public function getPriority()
  20991. {
  20992. return -1;
  20993. }
  20994. public function isCandidate(Tokens $tokens)
  20995. {
  20996. return $tokens->isTokenKindFound(';');
  20997. }
  20998. protected function createConfigurationDefinition()
  20999. {
  21000. return new FixerConfigurationResolver([
  21001. (new FixerOptionBuilder('remove_in_empty_for_expressions', 'Whether spaces should be removed for empty `for` expressions.'))
  21002. ->setAllowedTypes(['bool'])
  21003. ->setDefault(false)
  21004. ->getOption(),
  21005. ]);
  21006. }
  21007. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21008. {
  21009. $insideForParenthesesUntil = null;
  21010. for ($index = 0, $max = count($tokens) - 1; $index < $max; ++$index) {
  21011. if ($this->configuration['remove_in_empty_for_expressions']) {
  21012. if ($tokens[$index]->isGivenKind(T_FOR)) {
  21013. $index = $tokens->getNextMeaningfulToken($index);
  21014. $insideForParenthesesUntil = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  21015. continue;
  21016. }
  21017. if ($index === $insideForParenthesesUntil) {
  21018. $insideForParenthesesUntil = null;
  21019. continue;
  21020. }
  21021. }
  21022. if (!$tokens[$index]->equals(';')) {
  21023. continue;
  21024. }
  21025. if (!$tokens[$index + 1]->isWhitespace()) {
  21026. if (
  21027. !$tokens[$index + 1]->equalsAny([')', [T_INLINE_HTML]]) && (
  21028. !$this->configuration['remove_in_empty_for_expressions']
  21029. || !$tokens[$index + 1]->equals(';')
  21030. )
  21031. ) {
  21032. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, ' ']));
  21033. }
  21034. continue;
  21035. }
  21036. if (
  21037. null !== $insideForParenthesesUntil
  21038. && ($tokens[$index + 2]->equals(';') || $index + 2 === $insideForParenthesesUntil)
  21039. && !preg_match('/\R/', $tokens[$index + 1]->getContent())
  21040. ) {
  21041. $tokens->clearAt($index + 1);
  21042. continue;
  21043. }
  21044. if (
  21045. isset($tokens[$index + 2])
  21046. && !$tokens[$index + 1]->equals([T_WHITESPACE, ' '])
  21047. && $tokens[$index + 1]->isWhitespace(" \t")
  21048. && !$tokens[$index + 2]->isComment()
  21049. && !$tokens[$index + 2]->equals(')')
  21050. ) {
  21051. $tokens[$index + 1] = new Token([T_WHITESPACE, ' ']);
  21052. }
  21053. }
  21054. }
  21055. }
  21056. <?php
  21057. namespace PhpCsFixer\Fixer\Strict;
  21058. use PhpCsFixer\AbstractFixer;
  21059. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  21060. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21061. use PhpCsFixer\FixerDefinition\VersionSpecification;
  21062. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  21063. use PhpCsFixer\Tokenizer\Token;
  21064. use PhpCsFixer\Tokenizer\Tokens;
  21065. final class DeclareStrictTypesFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  21066. {
  21067. public function getDefinition()
  21068. {
  21069. return new FixerDefinition(
  21070. 'Force strict types declaration in all files. Requires PHP >= 7.0.',
  21071. [
  21072. new VersionSpecificCodeSample(
  21073. "<?php\n",
  21074. new VersionSpecification(70000)
  21075. ),
  21076. ],
  21077. null,
  21078. 'Forcing strict types will stop non strict code from working.'
  21079. );
  21080. }
  21081. public function getPriority()
  21082. {
  21083. return 2;
  21084. }
  21085. public function isCandidate(Tokens $tokens)
  21086. {
  21087. return PHP_VERSION_ID >= 70000 && $tokens[0]->isGivenKind(T_OPEN_TAG);
  21088. }
  21089. public function isRisky()
  21090. {
  21091. return true;
  21092. }
  21093. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21094. {
  21095. $searchIndex = $tokens->getNextMeaningfulToken(0);
  21096. if (null === $searchIndex) {
  21097. $this->insertSequence($tokens);
  21098. return;
  21099. }
  21100. $sequence = $this->getDeclareStrictTypeSequence();
  21101. $sequenceLocation = $tokens->findSequence($sequence, $searchIndex, null, false);
  21102. if (null === $sequenceLocation) {
  21103. $this->insertSequence($tokens);
  21104. return;
  21105. }
  21106. $this->fixStrictTypesCasing($tokens, $sequenceLocation);
  21107. }
  21108. private function getDeclareStrictTypeSequence()
  21109. {
  21110. static $sequence = null;
  21111. if (null === $sequence) {
  21112. $sequence = [
  21113. new Token([T_DECLARE, 'declare']),
  21114. new Token('('),
  21115. new Token([T_STRING, 'strict_types']),
  21116. new Token('='),
  21117. new Token([T_LNUMBER, '1']),
  21118. new Token(')'),
  21119. ];
  21120. }
  21121. return $sequence;
  21122. }
  21123. private function fixStrictTypesCasing(Tokens $tokens, array $sequence)
  21124. {
  21125. foreach ($sequence as $index => $token) {
  21126. if ($token->isGivenKind(T_STRING)) {
  21127. $tokens[$index] = new Token([T_STRING, strtolower($token->getContent())]);
  21128. break;
  21129. }
  21130. }
  21131. }
  21132. private function insertSequence(Tokens $tokens)
  21133. {
  21134. $sequence = $this->getDeclareStrictTypeSequence();
  21135. $sequence[] = new Token(';');
  21136. $endIndex = count($sequence);
  21137. $tokens->insertAt(1, $sequence);
  21138. if (false !== strpos($tokens[0]->getContent(), "\n")) {
  21139. $tokens[0] = new Token([$tokens[0]->getId(), trim($tokens[0]->getContent()).' ']);
  21140. }
  21141. if ($endIndex === count($tokens) - 1) {
  21142. return;
  21143. }
  21144. $lineEnding = $this->whitespacesConfig->getLineEnding();
  21145. if (!$tokens[1 + $endIndex]->isWhitespace()) {
  21146. $tokens->insertAt(1 + $endIndex, new Token([T_WHITESPACE, $lineEnding]));
  21147. return;
  21148. }
  21149. $content = $tokens[1 + $endIndex]->getContent();
  21150. if (false !== strpos($content, "\n")) {
  21151. return;
  21152. }
  21153. $tokens[1 + $endIndex] = new Token([T_WHITESPACE, $lineEnding.ltrim($content)]);
  21154. }
  21155. }
  21156. <?php
  21157. namespace PhpCsFixer\Fixer\Strict;
  21158. use PhpCsFixer\AbstractFixer;
  21159. use PhpCsFixer\FixerDefinition\CodeSample;
  21160. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21161. use PhpCsFixer\Tokenizer\Token;
  21162. use PhpCsFixer\Tokenizer\Tokens;
  21163. final class StrictComparisonFixer extends AbstractFixer
  21164. {
  21165. public function getDefinition()
  21166. {
  21167. return new FixerDefinition(
  21168. 'Comparisons should be strict.',
  21169. [new CodeSample("<?php\n\$a = 1== \$b;\n")],
  21170. null,
  21171. 'Changing comparisons to strict might change code behavior.'
  21172. );
  21173. }
  21174. public function isCandidate(Tokens $tokens)
  21175. {
  21176. return $tokens->isAnyTokenKindsFound([T_IS_EQUAL, T_IS_NOT_EQUAL]);
  21177. }
  21178. public function isRisky()
  21179. {
  21180. return true;
  21181. }
  21182. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21183. {
  21184. static $map = [
  21185. T_IS_EQUAL => [
  21186. 'id' => T_IS_IDENTICAL,
  21187. 'content' => '===',
  21188. ],
  21189. T_IS_NOT_EQUAL => [
  21190. 'id' => T_IS_NOT_IDENTICAL,
  21191. 'content' => '!==',
  21192. ],
  21193. ];
  21194. foreach ($tokens as $index => $token) {
  21195. $tokenId = $token->getId();
  21196. if (isset($map[$tokenId])) {
  21197. $tokens[$index] = new Token([$map[$tokenId]['id'], $map[$tokenId]['content']]);
  21198. }
  21199. }
  21200. }
  21201. }
  21202. <?php
  21203. namespace PhpCsFixer\Fixer\Strict;
  21204. use PhpCsFixer\AbstractFixer;
  21205. use PhpCsFixer\FixerDefinition\CodeSample;
  21206. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21207. use PhpCsFixer\Tokenizer\CT;
  21208. use PhpCsFixer\Tokenizer\Token;
  21209. use PhpCsFixer\Tokenizer\Tokens;
  21210. final class StrictParamFixer extends AbstractFixer
  21211. {
  21212. public function getDefinition()
  21213. {
  21214. return new FixerDefinition(
  21215. 'Functions should be used with `$strict` param set to `true`.',
  21216. [new CodeSample("<?php\n\$a = array_keys(\$b);\n\$a = array_search(\$b, \$c);\n\$a = base64_decode(\$b);\n\$a = in_array(\$b, \$c);\n\$a = mb_detect_encoding(\$b, \$c);\n")],
  21217. 'The functions "array_keys", "array_search", "base64_decode", "in_array" and "mb_detect_encoding" should be used with $strict param.',
  21218. 'Risky when the fixed function is overridden or if the code relies on non-strict usage.'
  21219. );
  21220. }
  21221. public function isCandidate(Tokens $tokens)
  21222. {
  21223. return $tokens->isTokenKindFound(T_STRING);
  21224. }
  21225. public function isRisky()
  21226. {
  21227. return true;
  21228. }
  21229. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21230. {
  21231. static $map = null;
  21232. if (null === $map) {
  21233. $trueToken = new Token([T_STRING, 'true']);
  21234. $map = [
  21235. 'array_keys' => [null, null, $trueToken],
  21236. 'array_search' => [null, null, $trueToken],
  21237. 'base64_decode' => [null, $trueToken],
  21238. 'in_array' => [null, null, $trueToken],
  21239. 'mb_detect_encoding' => [null, [new Token([T_STRING, 'mb_detect_order']), new Token('('), new Token(')')], $trueToken],
  21240. ];
  21241. }
  21242. for ($index = $tokens->count() - 1; 0 <= $index; --$index) {
  21243. $token = $tokens[$index];
  21244. if ($token->isGivenKind(T_STRING) && isset($map[$token->getContent()])) {
  21245. $this->fixFunction($tokens, $index, $map[$token->getContent()]);
  21246. }
  21247. }
  21248. }
  21249. private function fixFunction(Tokens $tokens, $functionIndex, array $functionParams)
  21250. {
  21251. $startBraceIndex = $tokens->getNextTokenOfKind($functionIndex, ['(']);
  21252. $endBraceIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $startBraceIndex);
  21253. $commaCounter = 0;
  21254. $sawParameter = false;
  21255. for ($index = $startBraceIndex + 1; $index < $endBraceIndex; ++$index) {
  21256. $token = $tokens[$index];
  21257. if (!$token->isWhitespace() && !$token->isComment()) {
  21258. $sawParameter = true;
  21259. }
  21260. if ($token->equals('(')) {
  21261. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  21262. continue;
  21263. }
  21264. if ($token->isGivenKind(CT::T_ARRAY_SQUARE_BRACE_OPEN)) {
  21265. $index = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index);
  21266. continue;
  21267. }
  21268. if ($token->equals(',')) {
  21269. ++$commaCounter;
  21270. continue;
  21271. }
  21272. }
  21273. $functionParamsQuantity = count($functionParams);
  21274. $paramsQuantity = ($sawParameter ? 1 : 0) + $commaCounter;
  21275. if ($paramsQuantity === $functionParamsQuantity) {
  21276. return;
  21277. }
  21278. $tokensToInsert = [];
  21279. for ($i = $paramsQuantity; $i < $functionParamsQuantity; ++$i) {
  21280. if (!$functionParams[$i]) {
  21281. return;
  21282. }
  21283. $tokensToInsert[] = new Token(',');
  21284. $tokensToInsert[] = new Token([T_WHITESPACE, ' ']);
  21285. if (!is_array($functionParams[$i])) {
  21286. $tokensToInsert[] = clone $functionParams[$i];
  21287. continue;
  21288. }
  21289. foreach ($functionParams[$i] as $param) {
  21290. $tokensToInsert[] = clone $param;
  21291. }
  21292. }
  21293. $beforeEndBraceIndex = $tokens->getPrevNonWhitespace($endBraceIndex);
  21294. $tokens->insertAt($beforeEndBraceIndex + 1, $tokensToInsert);
  21295. }
  21296. }
  21297. <?php
  21298. namespace PhpCsFixer\Fixer\StringNotation;
  21299. use PhpCsFixer\AbstractFixer;
  21300. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  21301. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  21302. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  21303. use PhpCsFixer\FixerDefinition\CodeSample;
  21304. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21305. use PhpCsFixer\Tokenizer\Token;
  21306. use PhpCsFixer\Tokenizer\Tokens;
  21307. final class EscapeImplicitBackslashesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  21308. {
  21309. public function getDefinition()
  21310. {
  21311. $codeSamble = <<<'EOF'
  21312. <?php
  21313. $singleQuoted = 'String with \" and My\Prefix\\';
  21314. $doubleQuoted = "Interpret my \n but not my \a";
  21315. $hereDoc = <<<HEREDOC
  21316. Interpret my \100 but not my \999
  21317. HEREDOC;
  21318. EOF;
  21319. return new FixerDefinition(
  21320. 'Escape implicit backslashes in strings and heredocs to ease the understanding of which are special chars interpreted by PHP and which not.',
  21321. [
  21322. new CodeSample($codeSamble),
  21323. new CodeSample(
  21324. $codeSamble,
  21325. ['single_quoted' => true]
  21326. ),
  21327. new CodeSample(
  21328. $codeSamble,
  21329. ['double_quoted' => false]
  21330. ),
  21331. new CodeSample(
  21332. $codeSamble,
  21333. ['heredoc_syntax' => false]
  21334. ),
  21335. ],
  21336. 'In PHP double-quoted strings and heredocs some chars like `n`, `$` or `u` have special meanings if preceded by a backslash '
  21337. .'(and some are special only if followed by other special chars), while a backslash preceding other chars are interpreted like a plain '
  21338. .'backslash. The precise list of those special chars is hard to remember and to identify quickly: this fixer escapes backslashes '
  21339. .'that do not start a special interpretation with the char after them.'
  21340. .PHP_EOL
  21341. .'It is possible to fix also single-quoted strings: in this case there is no special chars apart from single-quote and backslash '
  21342. .'itself, so the fixer simply ensure that all backslashes are escaped. Both single and double backslashes are allowed in single-quoted '
  21343. .'strings, so the purpose in this context is mainly to have a uniformed way to have them written all over the codebase.'
  21344. );
  21345. }
  21346. public function isCandidate(Tokens $tokens)
  21347. {
  21348. return $tokens->isAnyTokenKindsFound([T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING]);
  21349. }
  21350. public function getPriority()
  21351. {
  21352. return 1;
  21353. }
  21354. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21355. {
  21356. static $singleQuotedRegex = '/(?<!\\\\)\\\\(?![\\\'\\\\])/';
  21357. static $doubleQuotedRegex = '/(?<!\\\\)\\\\(?![efnrtv$"\\\\0-7]|x[0-9A-Fa-f]|u{)/';
  21358. static $heredocSyntaxRegex = '/(?<!\\\\)\\\\(?![efnrtv$\\\\0-7]|x[0-9A-Fa-f]|u{)/';
  21359. $doubleQuoteOpened = false;
  21360. foreach ($tokens as $index => $token) {
  21361. $content = $token->getContent();
  21362. if ($token->equals('"')) {
  21363. $doubleQuoteOpened = !$doubleQuoteOpened;
  21364. }
  21365. if (!$token->isGivenKind([T_ENCAPSED_AND_WHITESPACE, T_CONSTANT_ENCAPSED_STRING]) || false === strpos($content, '\\')) {
  21366. continue;
  21367. }
  21368. if ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE) && '\'' === substr(rtrim($tokens[$index - 1]->getContent()), -1)) {
  21369. continue;
  21370. }
  21371. $isSingleQuotedString = $token->isGivenKind(T_CONSTANT_ENCAPSED_STRING) && '\'' === $content[0];
  21372. $isDoubleQuotedString =
  21373. ($token->isGivenKind(T_CONSTANT_ENCAPSED_STRING) && '"' === $content[0])
  21374. || ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE) && $doubleQuoteOpened)
  21375. ;
  21376. $isHeredocSyntax = !$isSingleQuotedString && !$isDoubleQuotedString;
  21377. if (
  21378. (false === $this->configuration['single_quoted'] && $isSingleQuotedString)
  21379. || (false === $this->configuration['double_quoted'] && $isDoubleQuotedString)
  21380. || (false === $this->configuration['heredoc_syntax'] && $isHeredocSyntax)
  21381. ) {
  21382. continue;
  21383. }
  21384. $regex = $heredocSyntaxRegex;
  21385. if ($isSingleQuotedString) {
  21386. $regex = $singleQuotedRegex;
  21387. } elseif ($isDoubleQuotedString) {
  21388. $regex = $doubleQuotedRegex;
  21389. }
  21390. $newContent = preg_replace($regex, '\\\\\\\\', $content);
  21391. if ($newContent !== $content) {
  21392. $tokens[$index] = new Token([$token->getId(), $newContent]);
  21393. }
  21394. }
  21395. }
  21396. protected function createConfigurationDefinition()
  21397. {
  21398. return new FixerConfigurationResolver([
  21399. (new FixerOptionBuilder('single_quoted', 'Whether to fix single-quoted strings.'))
  21400. ->setAllowedTypes(['bool'])
  21401. ->setDefault(false)
  21402. ->getOption(),
  21403. (new FixerOptionBuilder('double_quoted', 'Whether to fix double-quoted strings.'))
  21404. ->setAllowedTypes(['bool'])
  21405. ->setDefault(true)
  21406. ->getOption(),
  21407. (new FixerOptionBuilder('heredoc_syntax', 'Whether to fix heredoc syntax.'))
  21408. ->setAllowedTypes(['bool'])
  21409. ->setDefault(true)
  21410. ->getOption(),
  21411. ]);
  21412. }
  21413. }
  21414. <?php
  21415. namespace PhpCsFixer\Fixer\StringNotation;
  21416. use PhpCsFixer\AbstractFixer;
  21417. use PhpCsFixer\FixerDefinition\CodeSample;
  21418. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21419. use PhpCsFixer\Tokenizer\CT;
  21420. use PhpCsFixer\Tokenizer\Token;
  21421. use PhpCsFixer\Tokenizer\Tokens;
  21422. final class ExplicitStringVariableFixer extends AbstractFixer
  21423. {
  21424. public function getDefinition()
  21425. {
  21426. return new FixerDefinition(
  21427. 'Converts implicit variables into explicit ones in double-quoted strings or heredoc syntax.',
  21428. [new CodeSample(
  21429. <<<'EOT'
  21430. <?php
  21431. $a = "My name is $name !";
  21432. $b = "I live in $state->country !";
  21433. $c = "I have $farm[0] chickens !";
  21434. EOT
  21435. )],
  21436. 'The reasoning behind this rule is the following:'
  21437. ."\n".'- When there are two valid ways of doing the same thing, using both is confusing, there should be a coding standard to follow'
  21438. ."\n".'- PHP manual marks `"$var"` syntax as implicit and `"${var}"` syntax as explicit: explicit code should always be preferred'
  21439. ."\n".'- Explicit syntax allows word concatenation inside strings, e.g. `"${var}IsAVar"`, implicit doesn\'t'
  21440. ."\n".'- Explicit syntax is easier to detect for IDE/editors and therefore has colors/hightlight with higher contrast, which is easier to read'
  21441. );
  21442. }
  21443. public function isCandidate(Tokens $tokens)
  21444. {
  21445. return $tokens->isTokenKindFound(T_VARIABLE);
  21446. }
  21447. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21448. {
  21449. for ($index = count($tokens) - 1; $index > 0; --$index) {
  21450. $token = $tokens[$index];
  21451. if (!$token->isGivenKind(T_VARIABLE)) {
  21452. continue;
  21453. }
  21454. $prevToken = $tokens[$index - 1];
  21455. if (!$this->isStringPartToken($prevToken)) {
  21456. continue;
  21457. }
  21458. $variableTokens = [
  21459. $index => $token,
  21460. ];
  21461. $firstVariableTokenIndex = $index;
  21462. $lastVariableTokenIndex = $index;
  21463. $nextIndex = $index + 1;
  21464. while (!$this->isStringPartToken($tokens[$nextIndex])) {
  21465. $variableTokens[$nextIndex] = $tokens[$nextIndex];
  21466. $lastVariableTokenIndex = $nextIndex;
  21467. ++$nextIndex;
  21468. }
  21469. if (1 === count($variableTokens)) {
  21470. $tokens->overrideRange($index, $index, [
  21471. new Token([T_DOLLAR_OPEN_CURLY_BRACES, '${']),
  21472. new Token([T_STRING_VARNAME, substr($token->getContent(), 1)]),
  21473. new Token([CT::T_DOLLAR_CLOSE_CURLY_BRACES, '}']),
  21474. ]);
  21475. } else {
  21476. foreach ($variableTokens as $variablePartIndex => $variablePartToken) {
  21477. if ($variablePartToken->isGivenKind(T_NUM_STRING)) {
  21478. $tokens[$variablePartIndex] = new Token([T_LNUMBER, $variablePartToken->getContent()]);
  21479. }
  21480. }
  21481. $tokens->insertAt($lastVariableTokenIndex + 1, new Token([CT::T_CURLY_CLOSE, '}']));
  21482. $tokens->insertAt($firstVariableTokenIndex, new Token([T_CURLY_OPEN, '{']));
  21483. }
  21484. }
  21485. }
  21486. private function isStringPartToken(Token $token)
  21487. {
  21488. return $token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)
  21489. || $token->isGivenKind(T_START_HEREDOC)
  21490. || '"' === $token->getContent()
  21491. ;
  21492. }
  21493. }
  21494. <?php
  21495. namespace PhpCsFixer\Fixer\StringNotation;
  21496. use PhpCsFixer\AbstractFixer;
  21497. use PhpCsFixer\FixerDefinition\CodeSample;
  21498. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21499. use PhpCsFixer\Tokenizer\Token;
  21500. use PhpCsFixer\Tokenizer\Tokens;
  21501. final class HeredocToNowdocFixer extends AbstractFixer
  21502. {
  21503. public function getDefinition()
  21504. {
  21505. return new FixerDefinition(
  21506. 'Convert `heredoc` to `nowdoc` where possible.',
  21507. [
  21508. new CodeSample(
  21509. <<<'EOF'
  21510. <?php $a = <<<"TEST"
  21511. Foo
  21512. TEST;
  21513. EOF
  21514. ),
  21515. ]
  21516. );
  21517. }
  21518. public function isCandidate(Tokens $tokens)
  21519. {
  21520. return $tokens->isTokenKindFound(T_START_HEREDOC);
  21521. }
  21522. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21523. {
  21524. foreach ($tokens as $index => $token) {
  21525. if (!$token->isGivenKind(T_START_HEREDOC) || false !== strpos($token->getContent(), "'")) {
  21526. continue;
  21527. }
  21528. if ($tokens[$index + 1]->isGivenKind(T_END_HEREDOC)) {
  21529. $tokens[$index] = $this->convertToNowdoc($token);
  21530. continue;
  21531. }
  21532. if (
  21533. !$tokens[$index + 1]->isGivenKind(T_ENCAPSED_AND_WHITESPACE) ||
  21534. !$tokens[$index + 2]->isGivenKind(T_END_HEREDOC)
  21535. ) {
  21536. continue;
  21537. }
  21538. $content = $tokens[$index + 1]->getContent();
  21539. if (preg_match('/(?<!\\\\)(?:\\\\{2})*\\\\(?![$\\\\])/', $content)) {
  21540. continue;
  21541. }
  21542. $tokens[$index] = $this->convertToNowdoc($token);
  21543. $content = str_replace(['\\\\', '\\$'], ['\\', '$'], $content);
  21544. $tokens[$index + 1] = new Token([
  21545. $tokens[$index + 1]->getId(),
  21546. $content,
  21547. ]);
  21548. }
  21549. }
  21550. private function convertToNowdoc(Token $token)
  21551. {
  21552. return new Token([
  21553. $token->getId(),
  21554. preg_replace('/(?<=^<<<)([ \t]*)"?([^\s"]+)"?/', '$1\'$2\'', $token->getContent()),
  21555. ]);
  21556. }
  21557. }
  21558. <?php
  21559. namespace PhpCsFixer\Fixer\StringNotation;
  21560. use PhpCsFixer\AbstractFixer;
  21561. use PhpCsFixer\FixerDefinition\CodeSample;
  21562. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21563. use PhpCsFixer\Tokenizer\Token;
  21564. use PhpCsFixer\Tokenizer\Tokens;
  21565. final class SingleQuoteFixer extends AbstractFixer
  21566. {
  21567. public function getDefinition()
  21568. {
  21569. return new FixerDefinition(
  21570. 'Convert double quotes to single quotes for simple strings.',
  21571. [new CodeSample("<?php \$a = \"sample\";\n")]
  21572. );
  21573. }
  21574. public function isCandidate(Tokens $tokens)
  21575. {
  21576. return $tokens->isTokenKindFound(T_CONSTANT_ENCAPSED_STRING);
  21577. }
  21578. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21579. {
  21580. foreach ($tokens as $index => $token) {
  21581. if (!$token->isGivenKind(T_CONSTANT_ENCAPSED_STRING)) {
  21582. continue;
  21583. }
  21584. $content = $token->getContent();
  21585. if (
  21586. '"' === $content[0] &&
  21587. false === strpos($content, "'") &&
  21588. !preg_match('/(?<!\\\\)(?:\\\\{2})*\\\\(?!["$\\\\])/', $content)
  21589. ) {
  21590. $content = substr($content, 1, -1);
  21591. $content = str_replace(['\\"', '\\$'], ['"', '$'], $content);
  21592. $tokens[$index] = new Token([T_CONSTANT_ENCAPSED_STRING, '\''.$content.'\'']);
  21593. }
  21594. }
  21595. }
  21596. }
  21597. <?php
  21598. namespace PhpCsFixer\Fixer\Whitespace;
  21599. use PhpCsFixer\AbstractFixer;
  21600. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  21601. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  21602. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolver;
  21603. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  21604. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  21605. use PhpCsFixer\FixerDefinition\CodeSample;
  21606. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21607. use PhpCsFixer\Tokenizer\Token;
  21608. use PhpCsFixer\Tokenizer\Tokens;
  21609. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  21610. final class BlankLineBeforeStatementFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  21611. {
  21612. private static $tokenMap = [
  21613. 'break' => T_BREAK,
  21614. 'continue' => T_CONTINUE,
  21615. 'declare' => T_DECLARE,
  21616. 'die' => T_EXIT,
  21617. 'do' => T_DO,
  21618. 'exit' => T_EXIT,
  21619. 'for' => T_FOR,
  21620. 'foreach' => T_FOREACH,
  21621. 'goto' => T_GOTO,
  21622. 'if' => T_IF,
  21623. 'include' => T_INCLUDE,
  21624. 'include_once' => T_INCLUDE_ONCE,
  21625. 'require' => T_REQUIRE,
  21626. 'require_once' => T_REQUIRE_ONCE,
  21627. 'return' => T_RETURN,
  21628. 'switch' => T_SWITCH,
  21629. 'throw' => T_THROW,
  21630. 'try' => T_TRY,
  21631. 'while' => T_WHILE,
  21632. 'yield' => T_YIELD,
  21633. ];
  21634. private $fixTokenMap = [];
  21635. public function configure(array $configuration = null)
  21636. {
  21637. parent::configure($configuration);
  21638. $this->fixTokenMap = [];
  21639. foreach ($this->configuration['statements'] as $key) {
  21640. $this->fixTokenMap[$key] = self::$tokenMap[$key];
  21641. }
  21642. }
  21643. public function getDefinition()
  21644. {
  21645. return new FixerDefinition(
  21646. 'An empty line feed must precede any configured statement.',
  21647. [
  21648. new CodeSample(
  21649. '<?php
  21650. function A() {
  21651. echo 1;
  21652. return 1;
  21653. }
  21654. '
  21655. ),
  21656. new CodeSample(
  21657. '<?php
  21658. switch ($foo) {
  21659. case 42:
  21660. $bar->process();
  21661. break;
  21662. case 44:
  21663. break;
  21664. }
  21665. ',
  21666. [
  21667. 'statements' => ['break'],
  21668. ]
  21669. ),
  21670. new CodeSample(
  21671. '<?php
  21672. foreach ($foo as $bar) {
  21673. if ($bar->isTired()) {
  21674. $bar->sleep();
  21675. continue;
  21676. }
  21677. }
  21678. ',
  21679. [
  21680. 'statements' => ['continue'],
  21681. ]
  21682. ),
  21683. new CodeSample(
  21684. '<?php
  21685. if ($foo === false) {
  21686. die(0);
  21687. } else {
  21688. $bar = 9000;
  21689. die(1);
  21690. }
  21691. ',
  21692. [
  21693. 'statements' => ['die'],
  21694. ]
  21695. ),
  21696. new CodeSample(
  21697. '<?php
  21698. $i = 0;
  21699. do {
  21700. echo $i;
  21701. } while ($i > 0);
  21702. ',
  21703. [
  21704. 'statements' => ['do'],
  21705. ]
  21706. ),
  21707. new CodeSample(
  21708. '<?php
  21709. if ($foo === false) {
  21710. exit(0);
  21711. } else {
  21712. $bar = 9000;
  21713. exit(1);
  21714. }
  21715. ',
  21716. [
  21717. 'statements' => ['exit'],
  21718. ]
  21719. ),
  21720. new CodeSample(
  21721. '<?php
  21722. a:
  21723. if ($foo === false) {
  21724. goto a;
  21725. } else {
  21726. $bar = 9000;
  21727. goto b;
  21728. }
  21729. ',
  21730. [
  21731. 'statements' => ['goto'],
  21732. ]
  21733. ),
  21734. new CodeSample(
  21735. '<?php
  21736. $a = 9000;
  21737. if (true) {
  21738. $foo = $bar;
  21739. }
  21740. ',
  21741. [
  21742. 'statements' => ['if'],
  21743. ]
  21744. ),
  21745. new CodeSample(
  21746. '<?php
  21747. if (true) {
  21748. $foo = $bar;
  21749. return;
  21750. }
  21751. ',
  21752. [
  21753. 'statements' => ['return'],
  21754. ]
  21755. ),
  21756. new CodeSample(
  21757. '<?php
  21758. $a = 9000;
  21759. switch ($a) {
  21760. case 42:
  21761. break;
  21762. }
  21763. ',
  21764. [
  21765. 'statements' => ['switch'],
  21766. ]
  21767. ),
  21768. new CodeSample(
  21769. '<?php
  21770. if (null === $a) {
  21771. $foo->bar();
  21772. throw new \UnexpectedValueException("A cannot be null");
  21773. }
  21774. ',
  21775. [
  21776. 'statements' => ['throw'],
  21777. ]
  21778. ),
  21779. new CodeSample(
  21780. '<?php
  21781. $a = 9000;
  21782. try {
  21783. $foo->bar();
  21784. } catch (\Exception $exception) {
  21785. $a = -1;
  21786. }
  21787. ',
  21788. [
  21789. 'statements' => ['try'],
  21790. ]
  21791. ),
  21792. new CodeSample(
  21793. '<?php
  21794. if (true) {
  21795. $foo = $bar;
  21796. yield $foo;
  21797. }
  21798. ',
  21799. [
  21800. 'statements' => ['yield'],
  21801. ]
  21802. ),
  21803. ]
  21804. );
  21805. }
  21806. public function getPriority()
  21807. {
  21808. return -19;
  21809. }
  21810. public function isCandidate(Tokens $tokens)
  21811. {
  21812. return $tokens->isAnyTokenKindsFound(array_values($this->fixTokenMap));
  21813. }
  21814. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21815. {
  21816. $lineEnding = $this->whitespacesConfig->getLineEnding();
  21817. $tokenKinds = array_values($this->fixTokenMap);
  21818. $analyzer = new TokensAnalyzer($tokens);
  21819. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  21820. $token = $tokens[$index];
  21821. if (!$token->isGivenKind($tokenKinds) || ($token->isGivenKind(T_WHILE) && $analyzer->isWhilePartOfDoWhile($index))) {
  21822. continue;
  21823. }
  21824. $prevNonWhitespaceToken = $tokens[$tokens->getPrevNonWhitespace($index)];
  21825. if (!$prevNonWhitespaceToken->equalsAny([';', '}'])) {
  21826. continue;
  21827. }
  21828. $prevIndex = $index - 1;
  21829. $prevToken = $tokens[$prevIndex];
  21830. if ($prevToken->isWhitespace()) {
  21831. $countParts = substr_count($prevToken->getContent(), "\n");
  21832. if (0 === $countParts) {
  21833. $tokens[$prevIndex] = new Token([T_WHITESPACE, rtrim($prevToken->getContent(), " \t").$lineEnding.$lineEnding]);
  21834. } elseif (1 === $countParts) {
  21835. $tokens[$prevIndex] = new Token([T_WHITESPACE, $lineEnding.$prevToken->getContent()]);
  21836. }
  21837. } else {
  21838. $tokens->insertAt($index, new Token([T_WHITESPACE, $lineEnding.$lineEnding]));
  21839. ++$index;
  21840. ++$limit;
  21841. }
  21842. }
  21843. }
  21844. protected function createConfigurationDefinition()
  21845. {
  21846. return new FixerConfigurationResolver([
  21847. (new FixerOptionBuilder('statements', 'List of statements which must be preceded by an empty line.'))
  21848. ->setAllowedTypes(['array'])
  21849. ->setAllowedValues([
  21850. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(array_keys(self::$tokenMap)),
  21851. ])
  21852. ->setDefault([
  21853. 'break',
  21854. 'continue',
  21855. 'declare',
  21856. 'return',
  21857. 'throw',
  21858. 'try',
  21859. ])
  21860. ->getOption(),
  21861. ]);
  21862. }
  21863. }
  21864. <?php
  21865. namespace PhpCsFixer\Fixer\Whitespace;
  21866. use PhpCsFixer\AbstractFixer;
  21867. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21868. use PhpCsFixer\FixerDefinition\VersionSpecification;
  21869. use PhpCsFixer\FixerDefinition\VersionSpecificCodeSample;
  21870. use PhpCsFixer\Tokenizer\CT;
  21871. use PhpCsFixer\Tokenizer\Tokens;
  21872. final class CompactNullableTypehintFixer extends AbstractFixer
  21873. {
  21874. public function getDefinition()
  21875. {
  21876. return new FixerDefinition(
  21877. 'Remove extra spaces in a nullable typehint.',
  21878. [
  21879. new VersionSpecificCodeSample(
  21880. "<?php\nfunction sample(? string \$str): ? string\n{}\n",
  21881. new VersionSpecification(70100)
  21882. ),
  21883. ],
  21884. 'Rule is applied only in a PHP 7.1+ environment.'
  21885. );
  21886. }
  21887. public function isCandidate(Tokens $tokens)
  21888. {
  21889. return PHP_VERSION_ID >= 70100 && $tokens->isTokenKindFound(CT::T_NULLABLE_TYPE);
  21890. }
  21891. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21892. {
  21893. static $typehintKinds = [
  21894. CT::T_ARRAY_TYPEHINT,
  21895. T_CALLABLE,
  21896. T_NS_SEPARATOR,
  21897. T_STRING,
  21898. ];
  21899. for ($index = $tokens->count() - 1; $index >= 0; --$index) {
  21900. if (!$tokens[$index]->isGivenKind(CT::T_NULLABLE_TYPE)) {
  21901. continue;
  21902. }
  21903. if (
  21904. $tokens[$index + 1]->isWhitespace() &&
  21905. $tokens[$index + 2]->isGivenKind($typehintKinds)
  21906. ) {
  21907. $tokens->removeTrailingWhitespace($index);
  21908. }
  21909. }
  21910. }
  21911. }
  21912. <?php
  21913. namespace PhpCsFixer\Fixer\Whitespace;
  21914. use PhpCsFixer\AbstractFixer;
  21915. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  21916. use PhpCsFixer\FixerDefinition\CodeSample;
  21917. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21918. use PhpCsFixer\Tokenizer\Token;
  21919. use PhpCsFixer\Tokenizer\Tokens;
  21920. final class IndentationTypeFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  21921. {
  21922. private $indent;
  21923. public function getDefinition()
  21924. {
  21925. return new FixerDefinition(
  21926. 'Code MUST use configured indentation type.',
  21927. [
  21928. new CodeSample("<?php\n\nif (true) {\n\techo 'Hello!';\n}\n"),
  21929. ]
  21930. );
  21931. }
  21932. public function getPriority()
  21933. {
  21934. return 50;
  21935. }
  21936. public function isCandidate(Tokens $tokens)
  21937. {
  21938. return $tokens->isAnyTokenKindsFound([T_COMMENT, T_DOC_COMMENT, T_WHITESPACE]);
  21939. }
  21940. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  21941. {
  21942. $this->indent = $this->whitespacesConfig->getIndent();
  21943. foreach ($tokens as $index => $token) {
  21944. if ($token->isComment()) {
  21945. $tokens[$index] = $this->fixIndentInComment($tokens, $index);
  21946. continue;
  21947. }
  21948. if ($token->isWhitespace()) {
  21949. $tokens[$index] = $this->fixIndentToken($tokens, $index);
  21950. continue;
  21951. }
  21952. }
  21953. }
  21954. private function fixIndentInComment(Tokens $tokens, $index)
  21955. {
  21956. $content = preg_replace('/^(?:(?<! ) {1,3})?\t/m', '\1 ', $tokens[$index]->getContent(), -1, $count);
  21957. while (0 !== $count) {
  21958. $content = preg_replace('/^(\ +)?\t/m', '\1 ', $content, -1, $count);
  21959. }
  21960. $indent = $this->indent;
  21961. $content = preg_replace_callback('/^(?: )+/m', static function ($matches) use ($indent) {
  21962. return str_replace(' ', $indent, $matches[0]);
  21963. }, $content);
  21964. return new Token([$tokens[$index]->getId(), $content]);
  21965. }
  21966. private function fixIndentToken(Tokens $tokens, $index)
  21967. {
  21968. $content = $tokens[$index]->getContent();
  21969. $previousTokenHasTrailingLinebreak = false;
  21970. if (false !== strpos($tokens[$index - 1]->getContent(), "\n")) {
  21971. $content = "\n".$content;
  21972. $previousTokenHasTrailingLinebreak = true;
  21973. }
  21974. $indent = $this->indent;
  21975. $newContent = preg_replace_callback(
  21976. '/(\R)(\h+)/',
  21977. static function (array $matches) use ($indent) {
  21978. $content = preg_replace('/(?:(?<! ) {1,3})?\t/', ' ', $matches[2]);
  21979. return $matches[1].str_replace(' ', $indent, $content);
  21980. },
  21981. $content
  21982. );
  21983. if ($previousTokenHasTrailingLinebreak) {
  21984. $newContent = substr($newContent, 1);
  21985. }
  21986. return new Token([T_WHITESPACE, $newContent]);
  21987. }
  21988. }
  21989. <?php
  21990. namespace PhpCsFixer\Fixer\Whitespace;
  21991. use PhpCsFixer\AbstractFixer;
  21992. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  21993. use PhpCsFixer\FixerDefinition\CodeSample;
  21994. use PhpCsFixer\FixerDefinition\FixerDefinition;
  21995. use PhpCsFixer\Tokenizer\Token;
  21996. use PhpCsFixer\Tokenizer\Tokens;
  21997. final class LineEndingFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  21998. {
  21999. public function isCandidate(Tokens $tokens)
  22000. {
  22001. return true;
  22002. }
  22003. public function getDefinition()
  22004. {
  22005. return new FixerDefinition(
  22006. 'All PHP files must use same line ending.',
  22007. [
  22008. new CodeSample(
  22009. "<?php \$b = \" \$a \r\n 123\"; \$a = <<<TEST\r\nAAAAA \r\n |\r\nTEST;\n"
  22010. ),
  22011. ]
  22012. );
  22013. }
  22014. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22015. {
  22016. $ending = $this->whitespacesConfig->getLineEnding();
  22017. for ($index = 0, $count = count($tokens); $index < $count; ++$index) {
  22018. $token = $tokens[$index];
  22019. if ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) {
  22020. if ($tokens[$tokens->getNextMeaningfulToken($index)]->isGivenKind(T_END_HEREDOC)) {
  22021. $tokens[$index] = new Token([
  22022. $token->getId(),
  22023. preg_replace(
  22024. "#\r\n|\n#",
  22025. $ending,
  22026. $token->getContent()
  22027. ),
  22028. ]);
  22029. }
  22030. continue;
  22031. }
  22032. if ($token->isGivenKind([T_OPEN_TAG, T_WHITESPACE, T_COMMENT, T_DOC_COMMENT, T_START_HEREDOC])) {
  22033. $tokens[$index] = new Token([
  22034. $token->getId(),
  22035. preg_replace(
  22036. "#\r\n|\n#",
  22037. $ending,
  22038. $token->getContent()
  22039. ),
  22040. ]);
  22041. }
  22042. }
  22043. }
  22044. }
  22045. <?php
  22046. namespace PhpCsFixer\Fixer\Whitespace;
  22047. use PhpCsFixer\AbstractFixer;
  22048. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  22049. use PhpCsFixer\FixerDefinition\CodeSample;
  22050. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22051. use PhpCsFixer\Tokenizer\CT;
  22052. use PhpCsFixer\Tokenizer\Token;
  22053. use PhpCsFixer\Tokenizer\Tokens;
  22054. final class MethodChainingIndentationFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  22055. {
  22056. public function getDefinition()
  22057. {
  22058. return new FixerDefinition(
  22059. 'Method chaining MUST be properly indented. Method chaining with different levels of indentation is not supported.',
  22060. [new CodeSample("<?php\n\$user->setEmail('voff.web@gmail.com')\n ->setPassword('233434');\n")]
  22061. );
  22062. }
  22063. public function isCandidate(Tokens $tokens)
  22064. {
  22065. return $tokens->isTokenKindFound(T_OBJECT_OPERATOR);
  22066. }
  22067. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22068. {
  22069. $lineEnding = $this->whitespacesConfig->getLineEnding();
  22070. for ($index = 1, $count = count($tokens); $index < $count; ++$index) {
  22071. if (!$tokens[$index]->isGivenKind(T_OBJECT_OPERATOR)) {
  22072. continue;
  22073. }
  22074. if ($this->canBeMovedToNextLine($index, $tokens)) {
  22075. $newline = new Token([T_WHITESPACE, $lineEnding]);
  22076. if ($tokens[$index - 1]->isWhitespace()) {
  22077. $tokens[$index - 1] = $newline;
  22078. } else {
  22079. $tokens->insertAt($index, $newline);
  22080. ++$index;
  22081. }
  22082. }
  22083. $currentIndent = $this->getIndentAt($tokens, $index - 1);
  22084. if (null === $currentIndent) {
  22085. continue;
  22086. }
  22087. $expectedIndent = $this->getExpectedIndentAt($tokens, $index);
  22088. if ($currentIndent !== $expectedIndent) {
  22089. $tokens[$index - 1] = new Token([T_WHITESPACE, $lineEnding.$expectedIndent]);
  22090. }
  22091. }
  22092. }
  22093. private function getExpectedIndentAt(Tokens $tokens, $index)
  22094. {
  22095. $index = $tokens->getPrevMeaningfulToken($index);
  22096. $indent = $this->whitespacesConfig->getIndent();
  22097. for ($i = $index - 1; $i >= 0; --$i) {
  22098. $currentIndent = $this->getIndentAt($tokens, $i);
  22099. if (null === $currentIndent) {
  22100. continue;
  22101. }
  22102. if ($this->currentLineRequiresExtraIndentLevel($tokens, $i, $index)) {
  22103. return $currentIndent.$indent;
  22104. }
  22105. return $currentIndent;
  22106. }
  22107. return $indent;
  22108. }
  22109. private function canBeMovedToNextLine($index, Tokens $tokens)
  22110. {
  22111. $prevMeaningful = $tokens->getPrevMeaningfulToken($index);
  22112. $hasCommentBefore = false;
  22113. for ($i = $index - 1; $i > $prevMeaningful; --$i) {
  22114. if ($tokens[$i]->isComment()) {
  22115. $hasCommentBefore = true;
  22116. continue;
  22117. }
  22118. if ($tokens[$i]->isWhitespace() && 1 === preg_match('/\R/', $tokens[$i]->getContent())) {
  22119. return $hasCommentBefore;
  22120. }
  22121. }
  22122. return false;
  22123. }
  22124. private function getIndentAt(Tokens $tokens, $index)
  22125. {
  22126. $content = '';
  22127. if ($tokens[$index]->isWhitespace()) {
  22128. $content = $tokens[$index]->getContent();
  22129. --$index;
  22130. }
  22131. if ($tokens[$index]->isGivenKind(T_OPEN_TAG)) {
  22132. $content = $tokens[$index]->getContent().$content;
  22133. }
  22134. if (1 === preg_match('/\R{1}([ \t]*)$/', $content, $matches)) {
  22135. return $matches[1];
  22136. }
  22137. return null;
  22138. }
  22139. private function currentLineRequiresExtraIndentLevel(Tokens $tokens, $start, $end)
  22140. {
  22141. if ($tokens[$start + 1]->isGivenKind(T_OBJECT_OPERATOR)) {
  22142. return false;
  22143. }
  22144. if ($tokens[$end]->isGivenKind(CT::T_BRACE_CLASS_INSTANTIATION_CLOSE)) {
  22145. return true;
  22146. }
  22147. return
  22148. !$tokens[$end]->equals(')')
  22149. || $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $end, false) >= $start
  22150. ;
  22151. }
  22152. }
  22153. <?php
  22154. namespace PhpCsFixer\Fixer\Whitespace;
  22155. use PhpCsFixer\AbstractFixer;
  22156. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  22157. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  22158. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  22159. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  22160. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  22161. use PhpCsFixer\FixerDefinition\CodeSample;
  22162. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22163. use PhpCsFixer\Tokenizer\CT;
  22164. use PhpCsFixer\Tokenizer\Token;
  22165. use PhpCsFixer\Tokenizer\Tokens;
  22166. use PhpCsFixer\Tokenizer\TokensAnalyzer;
  22167. use Symfony\Component\OptionsResolver\Options;
  22168. final class NoExtraBlankLinesFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface, WhitespacesAwareFixerInterface
  22169. {
  22170. private static $availableTokens = [
  22171. 'break',
  22172. 'case',
  22173. 'continue',
  22174. 'curly_brace_block',
  22175. 'default',
  22176. 'extra',
  22177. 'parenthesis_brace_block',
  22178. 'return',
  22179. 'square_brace_block',
  22180. 'switch',
  22181. 'throw',
  22182. 'use',
  22183. 'useTrait',
  22184. 'use_trait',
  22185. ];
  22186. private $tokenKindCallbackMap;
  22187. private $tokenEqualsMap;
  22188. private $tokens;
  22189. private $tokensAnalyzer;
  22190. public function configure(array $configuration = null)
  22191. {
  22192. parent::configure($configuration);
  22193. static $reprToTokenMap = [
  22194. 'break' => T_BREAK,
  22195. 'case' => T_CASE,
  22196. 'continue' => T_CONTINUE,
  22197. 'curly_brace_block' => '{',
  22198. 'default' => T_DEFAULT,
  22199. 'extra' => T_WHITESPACE,
  22200. 'parenthesis_brace_block' => '(',
  22201. 'return' => T_RETURN,
  22202. 'square_brace_block' => CT::T_ARRAY_SQUARE_BRACE_OPEN,
  22203. 'switch' => T_SWITCH,
  22204. 'throw' => T_THROW,
  22205. 'use' => T_USE,
  22206. 'use_trait' => CT::T_USE_TRAIT,
  22207. ];
  22208. static $tokenKindCallbackMap = [
  22209. T_BREAK => 'fixAfterToken',
  22210. T_CASE => 'fixAfterToken',
  22211. T_CONTINUE => 'fixAfterToken',
  22212. T_DEFAULT => 'fixAfterToken',
  22213. T_RETURN => 'fixAfterToken',
  22214. T_SWITCH => 'fixAfterToken',
  22215. T_THROW => 'fixAfterToken',
  22216. T_USE => 'removeBetweenUse',
  22217. T_WHITESPACE => 'removeMultipleBlankLines',
  22218. CT::T_USE_TRAIT => 'removeBetweenUse',
  22219. CT::T_ARRAY_SQUARE_BRACE_OPEN => 'fixStructureOpenCloseIfMultiLine',
  22220. ];
  22221. static $tokenEqualsMap = [
  22222. '{' => 'fixStructureOpenCloseIfMultiLine',
  22223. '(' => 'fixStructureOpenCloseIfMultiLine',
  22224. ];
  22225. $tokensAssoc = array_flip(array_intersect_key($reprToTokenMap, array_flip($this->configuration['tokens'])));
  22226. $this->tokenKindCallbackMap = array_intersect_key($tokenKindCallbackMap, $tokensAssoc);
  22227. $this->tokenEqualsMap = array_intersect_key($tokenEqualsMap, $tokensAssoc);
  22228. }
  22229. public function getDefinition()
  22230. {
  22231. return new FixerDefinition(
  22232. 'Removes extra blank lines and/or blank lines following configuration.',
  22233. [
  22234. new CodeSample(
  22235. '<?php
  22236. $foo = array("foo");
  22237. $bar = "bar";
  22238. '
  22239. ),
  22240. new CodeSample(
  22241. '<?php
  22242. switch ($foo) {
  22243. case 41:
  22244. echo "foo";
  22245. break;
  22246. case 42:
  22247. break;
  22248. }
  22249. ',
  22250. ['tokens' => ['break']]
  22251. ),
  22252. new CodeSample(
  22253. '<?php
  22254. for ($i = 0; $i < 9000; ++$i) {
  22255. if (true) {
  22256. continue;
  22257. }
  22258. }
  22259. ',
  22260. ['tokens' => ['continue']]
  22261. ),
  22262. new CodeSample(
  22263. '<?php
  22264. for ($i = 0; $i < 9000; ++$i) {
  22265. echo $i;
  22266. }
  22267. ',
  22268. ['tokens' => ['curly_brace_block']]
  22269. ),
  22270. new CodeSample(
  22271. '<?php
  22272. $foo = array("foo");
  22273. $bar = "bar";
  22274. ',
  22275. ['tokens' => ['extra']]
  22276. ),
  22277. new CodeSample(
  22278. '<?php
  22279. $foo = array(
  22280. "foo"
  22281. );
  22282. ',
  22283. ['tokens' => ['parenthesis_brace_block']]
  22284. ),
  22285. new CodeSample(
  22286. '<?php
  22287. function foo($bar)
  22288. {
  22289. return $bar;
  22290. }
  22291. ',
  22292. ['tokens' => ['return']]
  22293. ),
  22294. new CodeSample(
  22295. '<?php
  22296. $foo = [
  22297. "foo"
  22298. ];
  22299. ',
  22300. ['tokens' => ['square_brace_block']]
  22301. ),
  22302. new CodeSample(
  22303. '<?php
  22304. function foo($bar)
  22305. {
  22306. throw new \Exception("Hello!");
  22307. }
  22308. ',
  22309. ['tokens' => ['throw']]
  22310. ),
  22311. new CodeSample(
  22312. '<?php
  22313. namespace Foo;
  22314. use Bar\Baz;
  22315. use Baz\Bar;
  22316. class Bar
  22317. {
  22318. }
  22319. ',
  22320. ['tokens' => ['use']]
  22321. ),
  22322. new CodeSample(
  22323. '<?php
  22324. class Foo
  22325. {
  22326. use Bar;
  22327. use Baz;
  22328. }
  22329. ',
  22330. ['tokens' => ['use_trait']]
  22331. ),
  22332. new CodeSample(
  22333. '<?php
  22334. switch($a) {
  22335. case 1:
  22336. default:
  22337. echo 3;
  22338. }
  22339. ',
  22340. ['tokens' => ['switch', 'case', 'default']]
  22341. ),
  22342. ]
  22343. );
  22344. }
  22345. public function getPriority()
  22346. {
  22347. return -20;
  22348. }
  22349. public function isCandidate(Tokens $tokens)
  22350. {
  22351. return true;
  22352. }
  22353. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22354. {
  22355. $this->tokens = $tokens;
  22356. $this->tokensAnalyzer = new TokensAnalyzer($this->tokens);
  22357. for ($index = $tokens->getSize() - 1; $index > 0; --$index) {
  22358. $this->fixByToken($tokens[$index], $index);
  22359. }
  22360. }
  22361. protected function createConfigurationDefinition()
  22362. {
  22363. return new FixerConfigurationResolverRootless('tokens', [
  22364. (new FixerOptionBuilder('tokens', 'List of tokens to fix.'))
  22365. ->setAllowedTypes(['array'])
  22366. ->setAllowedValues([
  22367. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf(self::$availableTokens),
  22368. ])
  22369. ->setNormalizer(static function (Options $options, $tokens) {
  22370. foreach ($tokens as &$token) {
  22371. if ('useTrait' === $token) {
  22372. @trigger_error('Token "useTrait" is deprecated and will be removed in 3.0, use "use_trait" instead.', E_USER_DEPRECATED);
  22373. $token = 'use_trait';
  22374. break;
  22375. }
  22376. }
  22377. return $tokens;
  22378. })
  22379. ->setDefault(['extra'])
  22380. ->getOption(),
  22381. ]);
  22382. }
  22383. private function fixByToken(Token $token, $index)
  22384. {
  22385. foreach ($this->tokenKindCallbackMap as $kind => $callback) {
  22386. if (!$token->isGivenKind($kind)) {
  22387. continue;
  22388. }
  22389. $this->{$callback}($index);
  22390. return;
  22391. }
  22392. foreach ($this->tokenEqualsMap as $equals => $callback) {
  22393. if (!$token->equals($equals)) {
  22394. continue;
  22395. }
  22396. $this->{$callback}($index);
  22397. return;
  22398. }
  22399. }
  22400. private function removeBetweenUse($index)
  22401. {
  22402. $next = $this->tokens->getNextTokenOfKind($index, [';', T_CLOSE_TAG]);
  22403. if (null === $next || $this->tokens[$next]->isGivenKind(T_CLOSE_TAG)) {
  22404. return;
  22405. }
  22406. $nextUseCandidate = $this->tokens->getNextMeaningfulToken($next);
  22407. if (null === $nextUseCandidate || 1 === $nextUseCandidate - $next || !$this->tokens[$nextUseCandidate]->isGivenKind($this->tokens[$index]->getId())) {
  22408. return;
  22409. }
  22410. return $this->removeEmptyLinesAfterLineWithTokenAt($next);
  22411. }
  22412. private function removeMultipleBlankLines($index)
  22413. {
  22414. $parts = \preg_split('/(.*\R)/', $this->tokens[$index]->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  22415. $count = \count($parts);
  22416. if ($count > 2) {
  22417. $this->tokens[$index] = new Token([T_WHITESPACE, $parts[0].$parts[1].rtrim($parts[$count - 1], "\r\n")]);
  22418. }
  22419. }
  22420. private function fixAfterToken($index)
  22421. {
  22422. for ($i = $index - 1; $i > 0; --$i) {
  22423. if ($this->tokens[$i]->isGivenKind(T_FUNCTION) && $this->tokensAnalyzer->isLambda($i)) {
  22424. return;
  22425. }
  22426. if ($this->tokens[$i]->isGivenKind(T_CLASS) && $this->tokensAnalyzer->isAnonymousClass($i)) {
  22427. return;
  22428. }
  22429. if ($this->tokens[$i]->isWhitespace() && false !== strpos($this->tokens[$i]->getContent(), "\n")) {
  22430. break;
  22431. }
  22432. }
  22433. $this->removeEmptyLinesAfterLineWithTokenAt($index);
  22434. }
  22435. private function fixStructureOpenCloseIfMultiLine($index)
  22436. {
  22437. $blockTypeInfo = Tokens::detectBlockType($this->tokens[$index]);
  22438. $bodyEnd = $this->tokens->findBlockEnd($blockTypeInfo['type'], $index);
  22439. for ($i = $bodyEnd - 1; $i >= $index; --$i) {
  22440. if (false !== strpos($this->tokens[$i]->getContent(), "\n")) {
  22441. $this->removeEmptyLinesAfterLineWithTokenAt($i);
  22442. $this->removeEmptyLinesAfterLineWithTokenAt($index);
  22443. break;
  22444. }
  22445. }
  22446. }
  22447. private function removeEmptyLinesAfterLineWithTokenAt($index)
  22448. {
  22449. $tokenCount = count($this->tokens);
  22450. for ($end = $index; $end < $tokenCount; ++$end) {
  22451. if (
  22452. $this->tokens[$end]->equals('}')
  22453. || false !== strpos($this->tokens[$end]->getContent(), "\n")
  22454. ) {
  22455. break;
  22456. }
  22457. }
  22458. if ($end === $tokenCount) {
  22459. return;
  22460. }
  22461. $ending = $this->whitespacesConfig->getLineEnding();
  22462. for ($i = $end; $i < $tokenCount && $this->tokens[$i]->isWhitespace(); ++$i) {
  22463. $content = $this->tokens[$i]->getContent();
  22464. if (substr_count($content, "\n") < 1) {
  22465. continue;
  22466. }
  22467. $pos = strrpos($content, "\n");
  22468. if ($pos + 2 <= strlen($content)) {
  22469. $newContent = $ending.substr($content, $pos + 1);
  22470. } else {
  22471. $newContent = $ending;
  22472. }
  22473. $this->tokens[$i] = new Token([T_WHITESPACE, $newContent]);
  22474. }
  22475. }
  22476. }
  22477. <?php
  22478. namespace PhpCsFixer\Fixer\Whitespace;
  22479. use PhpCsFixer\AbstractProxyFixer;
  22480. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  22481. use PhpCsFixer\Fixer\DeprecatedFixerInterface;
  22482. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  22483. final class NoExtraConsecutiveBlankLinesFixer extends AbstractProxyFixer implements ConfigurationDefinitionFixerInterface, DeprecatedFixerInterface, WhitespacesAwareFixerInterface
  22484. {
  22485. private $fixer;
  22486. public function getDefinition()
  22487. {
  22488. return $this->getFixer()->getDefinition();
  22489. }
  22490. public function configure(array $configuration = null)
  22491. {
  22492. $this->getFixer()->configure($configuration);
  22493. $this->configuration = $configuration;
  22494. }
  22495. public function getConfigurationDefinition()
  22496. {
  22497. return $this->getFixer()->getConfigurationDefinition();
  22498. }
  22499. public function getSuccessorsNames()
  22500. {
  22501. return array_keys($this->proxyFixers);
  22502. }
  22503. protected function createProxyFixers()
  22504. {
  22505. return [$this->getFixer()];
  22506. }
  22507. private function getFixer()
  22508. {
  22509. if (null === $this->fixer) {
  22510. $this->fixer = new NoExtraBlankLinesFixer();
  22511. }
  22512. return $this->fixer;
  22513. }
  22514. }
  22515. <?php
  22516. namespace PhpCsFixer\Fixer\Whitespace;
  22517. use PhpCsFixer\AbstractFixer;
  22518. use PhpCsFixer\Fixer\ConfigurationDefinitionFixerInterface;
  22519. use PhpCsFixer\FixerConfiguration\FixerConfigurationResolverRootless;
  22520. use PhpCsFixer\FixerConfiguration\FixerOptionBuilder;
  22521. use PhpCsFixer\FixerConfiguration\FixerOptionValidatorGenerator;
  22522. use PhpCsFixer\FixerDefinition\CodeSample;
  22523. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22524. use PhpCsFixer\Tokenizer\CT;
  22525. use PhpCsFixer\Tokenizer\Tokens;
  22526. final class NoSpacesAroundOffsetFixer extends AbstractFixer implements ConfigurationDefinitionFixerInterface
  22527. {
  22528. public function getDefinition()
  22529. {
  22530. return new FixerDefinition(
  22531. 'There MUST NOT be spaces around offset braces.',
  22532. [
  22533. new CodeSample("<?php\n\$sample = \$b [ 'a' ] [ 'b' ];\n"),
  22534. new CodeSample("<?php\n\$sample = \$b [ 'a' ] [ 'b' ];\n", ['positions' => ['inside']]),
  22535. new CodeSample("<?php\n\$sample = \$b [ 'a' ] [ 'b' ];\n", ['positions' => ['outside']]),
  22536. ]
  22537. );
  22538. }
  22539. public function isCandidate(Tokens $tokens)
  22540. {
  22541. return $tokens->isAnyTokenKindsFound(['[', CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN]);
  22542. }
  22543. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22544. {
  22545. foreach ($tokens as $index => $token) {
  22546. if (!$token->equalsAny(['[', [CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN]])) {
  22547. continue;
  22548. }
  22549. if (in_array('inside', $this->configuration['positions'], true)) {
  22550. if ($token->equals('[')) {
  22551. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
  22552. } else {
  22553. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE, $index);
  22554. }
  22555. if ($tokens[$index + 1]->isWhitespace(" \t")) {
  22556. $tokens->clearAt($index + 1);
  22557. }
  22558. if ($tokens[$endIndex - 1]->isWhitespace(" \t")) {
  22559. $tokens->clearAt($endIndex - 1);
  22560. }
  22561. }
  22562. if (in_array('outside', $this->configuration['positions'], true)) {
  22563. $prevNonWhitespaceIndex = $tokens->getPrevNonWhitespace($index);
  22564. if ($tokens[$prevNonWhitespaceIndex]->isComment()) {
  22565. continue;
  22566. }
  22567. $tokens->removeLeadingWhitespace($index);
  22568. }
  22569. }
  22570. }
  22571. protected function createConfigurationDefinition()
  22572. {
  22573. $values = ['inside', 'outside'];
  22574. return new FixerConfigurationResolverRootless('positions', [
  22575. (new FixerOptionBuilder('positions', 'Whether spacing should be fixed inside and/or outside the offset braces.'))
  22576. ->setAllowedTypes(['array'])
  22577. ->setAllowedValues([
  22578. (new FixerOptionValidatorGenerator())->allowedValueIsSubsetOf($values),
  22579. ])
  22580. ->setDefault($values)
  22581. ->getOption(),
  22582. ]);
  22583. }
  22584. }
  22585. <?php
  22586. namespace PhpCsFixer\Fixer\Whitespace;
  22587. use PhpCsFixer\AbstractFixer;
  22588. use PhpCsFixer\FixerDefinition\CodeSample;
  22589. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22590. use PhpCsFixer\Tokenizer\Tokens;
  22591. final class NoSpacesInsideParenthesisFixer extends AbstractFixer
  22592. {
  22593. public function getDefinition()
  22594. {
  22595. return new FixerDefinition(
  22596. 'There MUST NOT be a space after the opening parenthesis. There MUST NOT be a space before the closing parenthesis.',
  22597. [
  22598. new CodeSample("<?php\nif ( \$a ) {\n foo( );\n}\n"),
  22599. new CodeSample(
  22600. "<?php
  22601. function foo( \$bar, \$baz )
  22602. {
  22603. }\n"
  22604. ),
  22605. ]
  22606. );
  22607. }
  22608. public function getPriority()
  22609. {
  22610. return 2;
  22611. }
  22612. public function isCandidate(Tokens $tokens)
  22613. {
  22614. return $tokens->isTokenKindFound('(');
  22615. }
  22616. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22617. {
  22618. foreach ($tokens as $index => $token) {
  22619. if (!$token->equals('(')) {
  22620. continue;
  22621. }
  22622. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  22623. if (null !== $prevIndex && $tokens[$prevIndex]->isGivenKind(T_ARRAY)) {
  22624. continue;
  22625. }
  22626. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  22627. if (!$tokens[$tokens->getNextNonWhitespace($index)]->isComment()) {
  22628. $this->removeSpaceAroundToken($tokens, $index + 1);
  22629. }
  22630. if (!$tokens[$tokens->getPrevMeaningfulToken($endIndex)]->equals(',')) {
  22631. $this->removeSpaceAroundToken($tokens, $endIndex - 1);
  22632. }
  22633. }
  22634. }
  22635. private function removeSpaceAroundToken(Tokens $tokens, $index)
  22636. {
  22637. $token = $tokens[$index];
  22638. if ($token->isWhitespace() && false === strpos($token->getContent(), "\n")) {
  22639. $tokens->clearAt($index);
  22640. }
  22641. }
  22642. }
  22643. <?php
  22644. namespace PhpCsFixer\Fixer\Whitespace;
  22645. use PhpCsFixer\AbstractFixer;
  22646. use PhpCsFixer\FixerDefinition\CodeSample;
  22647. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22648. use PhpCsFixer\Tokenizer\Token;
  22649. use PhpCsFixer\Tokenizer\Tokens;
  22650. final class NoTrailingWhitespaceFixer extends AbstractFixer
  22651. {
  22652. public function getDefinition()
  22653. {
  22654. return new FixerDefinition(
  22655. 'Remove trailing whitespace at the end of non-blank lines.',
  22656. [new CodeSample("<?php\n\$a = 1; \n")]
  22657. );
  22658. }
  22659. public function getPriority()
  22660. {
  22661. return 0;
  22662. }
  22663. public function isCandidate(Tokens $tokens)
  22664. {
  22665. return true;
  22666. }
  22667. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22668. {
  22669. foreach ($tokens as $index => $token) {
  22670. if (!$token->isWhitespace()) {
  22671. continue;
  22672. }
  22673. $lines = preg_split("/([\r\n]+)/", $token->getContent(), -1, PREG_SPLIT_DELIM_CAPTURE);
  22674. $linesSize = count($lines);
  22675. if ($linesSize > 1 || !isset($tokens[$index + 1])) {
  22676. $lines[0] = rtrim($lines[0], " \t");
  22677. for ($i = 1; $i < $linesSize; ++$i) {
  22678. $trimmedLine = rtrim($lines[$i], " \t");
  22679. if ('' !== $trimmedLine) {
  22680. $lines[$i] = $trimmedLine;
  22681. }
  22682. }
  22683. $content = implode($lines);
  22684. if ('' !== $content) {
  22685. $tokens[$index] = new Token([$token->getId(), $content]);
  22686. } else {
  22687. $tokens->clearAt($index);
  22688. }
  22689. }
  22690. }
  22691. }
  22692. }
  22693. <?php
  22694. namespace PhpCsFixer\Fixer\Whitespace;
  22695. use PhpCsFixer\AbstractFixer;
  22696. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  22697. use PhpCsFixer\FixerDefinition\CodeSample;
  22698. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22699. use PhpCsFixer\Tokenizer\Token;
  22700. use PhpCsFixer\Tokenizer\Tokens;
  22701. final class NoWhitespaceInBlankLineFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  22702. {
  22703. public function getDefinition()
  22704. {
  22705. return new FixerDefinition(
  22706. 'Remove trailing whitespace at the end of blank lines.',
  22707. [new CodeSample("<?php\n \n\$a = 1;\n")]
  22708. );
  22709. }
  22710. public function getPriority()
  22711. {
  22712. return -19;
  22713. }
  22714. public function isCandidate(Tokens $tokens)
  22715. {
  22716. return true;
  22717. }
  22718. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22719. {
  22720. for ($i = 1, $count = count($tokens); $i < $count; ++$i) {
  22721. if ($tokens[$i]->isWhitespace()) {
  22722. $this->fixWhitespaceToken($tokens, $i);
  22723. }
  22724. }
  22725. }
  22726. private function fixWhitespaceToken(Tokens $tokens, $index)
  22727. {
  22728. $content = $tokens[$index]->getContent();
  22729. $lines = preg_split("/(\r\n|\n)/", $content);
  22730. $lineCount = count($lines);
  22731. if (
  22732. $lineCount > 2
  22733. || ($lineCount > 0 && (!isset($tokens[$index + 1]) || $tokens[$index - 1]->isGivenKind(T_OPEN_TAG)))
  22734. ) {
  22735. $lMax = isset($tokens[$index + 1]) ? $lineCount - 1 : $lineCount;
  22736. $lStart = 1;
  22737. if ($tokens[$index - 1]->isGivenKind(T_OPEN_TAG) && "\n" === substr($tokens[$index - 1]->getContent(), -1)) {
  22738. $lStart = 0;
  22739. }
  22740. for ($l = $lStart; $l < $lMax; ++$l) {
  22741. $lines[$l] = preg_replace('/^\h+$/', '', $lines[$l]);
  22742. }
  22743. $content = implode($this->whitespacesConfig->getLineEnding(), $lines);
  22744. if ('' !== $content) {
  22745. $tokens[$index] = new Token([T_WHITESPACE, $content]);
  22746. } else {
  22747. $tokens->clearAt($index);
  22748. }
  22749. }
  22750. }
  22751. }
  22752. <?php
  22753. namespace PhpCsFixer\Fixer\Whitespace;
  22754. use PhpCsFixer\AbstractFixer;
  22755. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  22756. use PhpCsFixer\FixerDefinition\CodeSample;
  22757. use PhpCsFixer\FixerDefinition\FixerDefinition;
  22758. use PhpCsFixer\Tokenizer\Tokens;
  22759. final class SingleBlankLineAtEofFixer extends AbstractFixer implements WhitespacesAwareFixerInterface
  22760. {
  22761. public function getDefinition()
  22762. {
  22763. return new FixerDefinition(
  22764. 'A PHP file without end tag must always end with a single empty line feed.',
  22765. [new CodeSample("<?php\n\$a = 1;")]
  22766. );
  22767. }
  22768. public function getPriority()
  22769. {
  22770. return -50;
  22771. }
  22772. public function isCandidate(Tokens $tokens)
  22773. {
  22774. return true;
  22775. }
  22776. protected function applyFix(\SplFileInfo $file, Tokens $tokens)
  22777. {
  22778. $count = $tokens->count();
  22779. if ($count && !$tokens[$count - 1]->isGivenKind([T_INLINE_HTML, T_CLOSE_TAG, T_OPEN_TAG])) {
  22780. $tokens->ensureWhitespaceAtIndex($count - 1, 1, $this->whitespacesConfig->getLineEnding());
  22781. }
  22782. }
  22783. }
  22784. <?php
  22785. namespace PhpCsFixer\Fixer;
  22786. use PhpCsFixer\WhitespacesFixerConfig;
  22787. interface WhitespacesAwareFixerInterface extends FixerInterface
  22788. {
  22789. public function setWhitespacesConfig(WhitespacesFixerConfig $config);
  22790. }
  22791. <?php
  22792. namespace PhpCsFixer\FixerConfiguration;
  22793. use Symfony\Component\OptionsResolver\OptionsResolver;
  22794. final class FixerConfigurationResolver implements FixerConfigurationResolverInterface
  22795. {
  22796. private $options = [];
  22797. private $registeredNames = [];
  22798. public function __construct($options)
  22799. {
  22800. foreach ($options as $option) {
  22801. $this->addOption($option);
  22802. }
  22803. if (empty($this->registeredNames)) {
  22804. throw new \LogicException('Options cannot be empty.');
  22805. }
  22806. }
  22807. public function getOptions()
  22808. {
  22809. return $this->options;
  22810. }
  22811. public function resolve(array $options)
  22812. {
  22813. $resolver = new OptionsResolver();
  22814. foreach ($this->options as $option) {
  22815. $name = $option->getName();
  22816. if ($option->hasDefault()) {
  22817. $resolver->setDefault($name, $option->getDefault());
  22818. } else {
  22819. $resolver->setRequired($name);
  22820. }
  22821. $allowedValues = $option->getAllowedValues();
  22822. if (null !== $allowedValues) {
  22823. $resolver->setAllowedValues($name, $allowedValues);
  22824. }
  22825. $allowedTypes = $option->getAllowedTypes();
  22826. if (null !== $allowedTypes) {
  22827. $resolver->setAllowedTypes($name, $allowedTypes);
  22828. }
  22829. $normalizer = $option->getNormalizer();
  22830. if (null !== $normalizer) {
  22831. $resolver->setNormalizer($name, $normalizer);
  22832. }
  22833. }
  22834. return $resolver->resolve($options);
  22835. }
  22836. private function addOption(FixerOptionInterface $option)
  22837. {
  22838. $name = $option->getName();
  22839. if (in_array($name, $this->registeredNames, true)) {
  22840. throw new \LogicException(sprintf('The "%s" option is defined multiple times.', $name));
  22841. }
  22842. $this->options[] = $option;
  22843. $this->registeredNames[] = $name;
  22844. return $this;
  22845. }
  22846. }
  22847. <?php
  22848. namespace PhpCsFixer\FixerConfiguration;
  22849. interface FixerConfigurationResolverInterface
  22850. {
  22851. public function getOptions();
  22852. public function resolve(array $configuration);
  22853. }
  22854. <?php
  22855. namespace PhpCsFixer\FixerConfiguration;
  22856. final class FixerConfigurationResolverRootless implements FixerConfigurationResolverInterface
  22857. {
  22858. private $resolver;
  22859. private $root;
  22860. public function __construct($root, $options)
  22861. {
  22862. $this->resolver = new FixerConfigurationResolver($options);
  22863. $names = array_map(
  22864. static function (FixerOptionInterface $option) {
  22865. return $option->getName();
  22866. },
  22867. $this->resolver->getOptions()
  22868. );
  22869. if (!in_array($root, $names, true)) {
  22870. throw new \LogicException(sprintf('The "%s" option is not defined.', $root));
  22871. }
  22872. $this->root = $root;
  22873. }
  22874. public function getOptions()
  22875. {
  22876. return $this->resolver->getOptions();
  22877. }
  22878. public function resolve(array $options)
  22879. {
  22880. if (!empty($options) && !array_key_exists($this->root, $options)) {
  22881. $names = array_map(
  22882. function (FixerOptionInterface $option) {
  22883. return $option->getName();
  22884. },
  22885. $this->resolver->getOptions()
  22886. );
  22887. $passedNames = array_keys($options);
  22888. if (!empty(array_diff($passedNames, $names))) {
  22889. if (getenv('PHP_CS_FIXER_FUTURE_MODE')) {
  22890. throw new \RuntimeException(sprintf(
  22891. 'Passing "%1$s" at the root of the configuration is deprecated and will not be supported in 3.0, use "%1$s" => array(...) option instead. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.',
  22892. $this->root
  22893. ));
  22894. }
  22895. @trigger_error(sprintf(
  22896. 'Passing "%1$s" at the root of the configuration is deprecated and will not be supported in 3.0, use "%1$s" => array(...) option instead.',
  22897. $this->root
  22898. ), E_USER_DEPRECATED);
  22899. $options = [$this->root => $options];
  22900. }
  22901. }
  22902. return $this->resolver->resolve($options);
  22903. }
  22904. }
  22905. <?php
  22906. namespace PhpCsFixer\FixerConfiguration;
  22907. final class FixerOption implements FixerOptionInterface
  22908. {
  22909. private $name;
  22910. private $description;
  22911. private $default;
  22912. private $isRequired;
  22913. private $allowedTypes;
  22914. private $allowedValues;
  22915. private $normalizer;
  22916. public function __construct(
  22917. $name,
  22918. $description,
  22919. $isRequired = true,
  22920. $default = null,
  22921. array $allowedTypes = null,
  22922. array $allowedValues = null,
  22923. \Closure $normalizer = null
  22924. ) {
  22925. if ($isRequired && null !== $default) {
  22926. throw new \LogicException('Required options cannot have a default value.');
  22927. }
  22928. if (null !== $allowedValues) {
  22929. foreach ($allowedValues as &$allowedValue) {
  22930. if ($allowedValue instanceof \Closure) {
  22931. $allowedValue = $this->unbind($allowedValue);
  22932. }
  22933. }
  22934. }
  22935. $this->name = $name;
  22936. $this->description = $description;
  22937. $this->isRequired = $isRequired;
  22938. $this->default = $default;
  22939. $this->allowedTypes = $allowedTypes;
  22940. $this->allowedValues = $allowedValues;
  22941. if (null !== $normalizer) {
  22942. $this->normalizer = $this->unbind($normalizer);
  22943. }
  22944. }
  22945. public function getName()
  22946. {
  22947. return $this->name;
  22948. }
  22949. public function getDescription()
  22950. {
  22951. return $this->description;
  22952. }
  22953. public function hasDefault()
  22954. {
  22955. return !$this->isRequired;
  22956. }
  22957. public function getDefault()
  22958. {
  22959. if (!$this->hasDefault()) {
  22960. throw new \LogicException('No default value defined.');
  22961. }
  22962. return $this->default;
  22963. }
  22964. public function getAllowedTypes()
  22965. {
  22966. return $this->allowedTypes;
  22967. }
  22968. public function getAllowedValues()
  22969. {
  22970. return $this->allowedValues;
  22971. }
  22972. public function getNormalizer()
  22973. {
  22974. return $this->normalizer;
  22975. }
  22976. private function unbind(\Closure $closure)
  22977. {
  22978. return $closure->bindTo(null);
  22979. }
  22980. }
  22981. <?php
  22982. namespace PhpCsFixer\FixerConfiguration;
  22983. final class FixerOptionBuilder
  22984. {
  22985. private $name;
  22986. private $description;
  22987. private $default;
  22988. private $isRequired = true;
  22989. private $allowedTypes;
  22990. private $allowedValues;
  22991. private $normalizer;
  22992. public function __construct($name, $description)
  22993. {
  22994. $this->name = $name;
  22995. $this->description = $description;
  22996. }
  22997. public function setDefault($default)
  22998. {
  22999. $this->default = $default;
  23000. $this->isRequired = false;
  23001. return $this;
  23002. }
  23003. public function setAllowedTypes(array $allowedTypes)
  23004. {
  23005. $this->allowedTypes = $allowedTypes;
  23006. return $this;
  23007. }
  23008. public function setAllowedValues(array $allowedValues)
  23009. {
  23010. $this->allowedValues = $allowedValues;
  23011. return $this;
  23012. }
  23013. public function setNormalizer(\Closure $normalizer)
  23014. {
  23015. $this->normalizer = $normalizer;
  23016. return $this;
  23017. }
  23018. public function getOption()
  23019. {
  23020. return new FixerOption(
  23021. $this->name,
  23022. $this->description,
  23023. $this->isRequired,
  23024. $this->default,
  23025. $this->allowedTypes,
  23026. $this->allowedValues,
  23027. $this->normalizer
  23028. );
  23029. }
  23030. }
  23031. <?php
  23032. namespace PhpCsFixer\FixerConfiguration;
  23033. interface FixerOptionInterface
  23034. {
  23035. public function getName();
  23036. public function getDescription();
  23037. public function hasDefault();
  23038. public function getDefault();
  23039. public function getAllowedTypes();
  23040. public function getAllowedValues();
  23041. public function getNormalizer();
  23042. }
  23043. <?php
  23044. namespace PhpCsFixer\FixerConfiguration;
  23045. final class FixerOptionValidatorGenerator
  23046. {
  23047. public function allowedValueIsSubsetOf(array $allowedArrayValues)
  23048. {
  23049. return static function ($values) use ($allowedArrayValues) {
  23050. foreach ($values as $value) {
  23051. if (!in_array($value, $allowedArrayValues, true)) {
  23052. return false;
  23053. }
  23054. }
  23055. return true;
  23056. };
  23057. }
  23058. }
  23059. <?php
  23060. namespace PhpCsFixer\FixerConfiguration;
  23061. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  23062. final class InvalidOptionsForEnvException extends InvalidOptionsException
  23063. {
  23064. }
  23065. <?php
  23066. namespace PhpCsFixer\FixerDefinition;
  23067. final class CodeSample implements CodeSampleInterface
  23068. {
  23069. private $code;
  23070. private $configuration;
  23071. public function __construct($code, array $configuration = null)
  23072. {
  23073. $this->code = $code;
  23074. $this->configuration = $configuration;
  23075. }
  23076. public function getCode()
  23077. {
  23078. return $this->code;
  23079. }
  23080. public function getConfiguration()
  23081. {
  23082. return $this->configuration;
  23083. }
  23084. }
  23085. <?php
  23086. namespace PhpCsFixer\FixerDefinition;
  23087. interface CodeSampleInterface
  23088. {
  23089. public function getCode();
  23090. public function getConfiguration();
  23091. }
  23092. <?php
  23093. namespace PhpCsFixer\FixerDefinition;
  23094. final class FileSpecificCodeSample implements FileSpecificCodeSampleInterface
  23095. {
  23096. private $codeSample;
  23097. private $splFileInfo;
  23098. public function __construct(
  23099. $code,
  23100. \SplFileInfo $splFileInfo,
  23101. array $configuration = null
  23102. ) {
  23103. $this->codeSample = new CodeSample($code, $configuration);
  23104. $this->splFileInfo = $splFileInfo;
  23105. }
  23106. public function getCode()
  23107. {
  23108. return $this->codeSample->getCode();
  23109. }
  23110. public function getConfiguration()
  23111. {
  23112. return $this->codeSample->getConfiguration();
  23113. }
  23114. public function getSplFileInfo()
  23115. {
  23116. return $this->splFileInfo;
  23117. }
  23118. }
  23119. <?php
  23120. namespace PhpCsFixer\FixerDefinition;
  23121. interface FileSpecificCodeSampleInterface extends CodeSampleInterface
  23122. {
  23123. public function getSplFileInfo();
  23124. }
  23125. <?php
  23126. namespace PhpCsFixer\FixerDefinition;
  23127. final class FixerDefinition implements FixerDefinitionInterface
  23128. {
  23129. private $riskyDescription;
  23130. private $configurationDescription;
  23131. private $defaultConfiguration;
  23132. private $codeSamples;
  23133. private $summary;
  23134. private $description;
  23135. public function __construct(
  23136. $summary,
  23137. array $codeSamples,
  23138. $description = null,
  23139. $configurationDescription = null,
  23140. array $defaultConfiguration = null,
  23141. $riskyDescription = null
  23142. ) {
  23143. if (6 === func_num_args()) {
  23144. @trigger_error('Arguments #5 and #6 of FixerDefinition::__construct() are deprecated and will be removed in 3.0, use argument #4 instead.', E_USER_DEPRECATED);
  23145. } elseif (5 === func_num_args()) {
  23146. @trigger_error('Argument #5 of FixerDefinition::__construct() is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  23147. } else {
  23148. $riskyDescription = $configurationDescription;
  23149. $configurationDescription = null;
  23150. }
  23151. $this->summary = $summary;
  23152. $this->codeSamples = $codeSamples;
  23153. $this->description = $description;
  23154. $this->configurationDescription = $configurationDescription;
  23155. $this->defaultConfiguration = $defaultConfiguration;
  23156. $this->riskyDescription = $riskyDescription;
  23157. }
  23158. public function getSummary()
  23159. {
  23160. return $this->summary;
  23161. }
  23162. public function getDescription()
  23163. {
  23164. return $this->description;
  23165. }
  23166. public function getConfigurationDescription()
  23167. {
  23168. @trigger_error(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
  23169. return $this->configurationDescription;
  23170. }
  23171. public function getDefaultConfiguration()
  23172. {
  23173. @trigger_error(sprintf('%s is deprecated and will be removed in 3.0.', __METHOD__), E_USER_DEPRECATED);
  23174. return $this->defaultConfiguration;
  23175. }
  23176. public function getRiskyDescription()
  23177. {
  23178. return $this->riskyDescription;
  23179. }
  23180. public function getCodeSamples()
  23181. {
  23182. return $this->codeSamples;
  23183. }
  23184. }
  23185. <?php
  23186. namespace PhpCsFixer\FixerDefinition;
  23187. interface FixerDefinitionInterface
  23188. {
  23189. public function getSummary();
  23190. public function getDescription();
  23191. public function getConfigurationDescription();
  23192. public function getDefaultConfiguration();
  23193. public function getRiskyDescription();
  23194. public function getCodeSamples();
  23195. }
  23196. <?php
  23197. namespace PhpCsFixer\FixerDefinition;
  23198. final class VersionSpecificCodeSample implements VersionSpecificCodeSampleInterface
  23199. {
  23200. private $codeSample;
  23201. private $versionSpecification;
  23202. public function __construct(
  23203. $code,
  23204. VersionSpecificationInterface $versionSpecification,
  23205. array $configuration = null
  23206. ) {
  23207. $this->codeSample = new CodeSample($code, $configuration);
  23208. $this->versionSpecification = $versionSpecification;
  23209. }
  23210. public function getCode()
  23211. {
  23212. return $this->codeSample->getCode();
  23213. }
  23214. public function getConfiguration()
  23215. {
  23216. return $this->codeSample->getConfiguration();
  23217. }
  23218. public function isSuitableFor($version)
  23219. {
  23220. return $this->versionSpecification->isSatisfiedBy($version);
  23221. }
  23222. }
  23223. <?php
  23224. namespace PhpCsFixer\FixerDefinition;
  23225. interface VersionSpecificCodeSampleInterface extends CodeSampleInterface
  23226. {
  23227. public function isSuitableFor($version);
  23228. }
  23229. <?php
  23230. namespace PhpCsFixer\FixerDefinition;
  23231. final class VersionSpecification implements VersionSpecificationInterface
  23232. {
  23233. private $minimum;
  23234. private $maximum;
  23235. public function __construct($minimum = null, $maximum = null)
  23236. {
  23237. if (null === $minimum && null === $maximum) {
  23238. throw new \InvalidArgumentException('Minimum or maximum need to be specified.');
  23239. }
  23240. if (null !== $minimum && (!is_int($minimum) || 1 > $minimum)) {
  23241. throw new \InvalidArgumentException('Minimum needs to be either null or an integer greater than 0.');
  23242. }
  23243. if (null !== $maximum) {
  23244. if (!is_int($maximum) || 1 > $maximum) {
  23245. throw new \InvalidArgumentException('Maximum needs to be either null or an integer greater than 0.');
  23246. }
  23247. if (null !== $minimum && $maximum < $minimum) {
  23248. throw new \InvalidArgumentException('Maximum should not be lower than the minimum.');
  23249. }
  23250. }
  23251. $this->minimum = $minimum;
  23252. $this->maximum = $maximum;
  23253. }
  23254. public function isSatisfiedBy($version)
  23255. {
  23256. if (null !== $this->minimum && $version < $this->minimum) {
  23257. return false;
  23258. }
  23259. if (null !== $this->maximum && $version > $this->maximum) {
  23260. return false;
  23261. }
  23262. return true;
  23263. }
  23264. }
  23265. <?php
  23266. namespace PhpCsFixer\FixerDefinition;
  23267. interface VersionSpecificationInterface
  23268. {
  23269. public function isSatisfiedBy($version);
  23270. }
  23271. <?php
  23272. namespace PhpCsFixer;
  23273. use PhpCsFixer\ConfigurationException\InvalidFixerConfigurationException;
  23274. use PhpCsFixer\Fixer\ConfigurableFixerInterface;
  23275. use PhpCsFixer\Fixer\FixerInterface;
  23276. use PhpCsFixer\Fixer\WhitespacesAwareFixerInterface;
  23277. use Symfony\Component\Finder\Finder as SymfonyFinder;
  23278. final class FixerFactory
  23279. {
  23280. private $nameValidator;
  23281. private $fixers = [];
  23282. private $fixersByName = [];
  23283. public function __construct()
  23284. {
  23285. $this->nameValidator = new FixerNameValidator();
  23286. }
  23287. public static function create()
  23288. {
  23289. return new self();
  23290. }
  23291. public function setWhitespacesConfig(WhitespacesFixerConfig $config)
  23292. {
  23293. foreach ($this->fixers as $fixer) {
  23294. if ($fixer instanceof WhitespacesAwareFixerInterface) {
  23295. $fixer->setWhitespacesConfig($config);
  23296. }
  23297. }
  23298. return $this;
  23299. }
  23300. public function getFixers()
  23301. {
  23302. $this->fixers = Utils::sortFixers($this->fixers);
  23303. return $this->fixers;
  23304. }
  23305. public function registerBuiltInFixers()
  23306. {
  23307. static $builtInFixers = null;
  23308. if (null === $builtInFixers) {
  23309. $builtInFixers = [];
  23310. foreach (SymfonyFinder::create()->files()->in(__DIR__.'/Fixer') as $file) {
  23311. $relativeNamespace = $file->getRelativePath();
  23312. $fixerClass = 'PhpCsFixer\\Fixer\\'.($relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php');
  23313. if ('Fixer' === substr($fixerClass, -5)) {
  23314. $builtInFixers[] = $fixerClass;
  23315. }
  23316. }
  23317. }
  23318. foreach ($builtInFixers as $class) {
  23319. $this->registerFixer(new $class(), false);
  23320. }
  23321. return $this;
  23322. }
  23323. public function registerCustomFixers(array $fixers)
  23324. {
  23325. foreach ($fixers as $fixer) {
  23326. $this->registerFixer($fixer, true);
  23327. }
  23328. return $this;
  23329. }
  23330. public function registerFixer(FixerInterface $fixer, $isCustom)
  23331. {
  23332. $name = $fixer->getName();
  23333. if (isset($this->fixersByName[$name])) {
  23334. throw new \UnexpectedValueException(sprintf('Fixer named "%s" is already registered.', $name));
  23335. }
  23336. if (!$this->nameValidator->isValid($name, $isCustom)) {
  23337. throw new \UnexpectedValueException(sprintf('Fixer named "%s" has invalid name.', $name));
  23338. }
  23339. $this->fixers[] = $fixer;
  23340. $this->fixersByName[$name] = $fixer;
  23341. return $this;
  23342. }
  23343. public function useRuleSet(RuleSetInterface $ruleSet)
  23344. {
  23345. $fixers = [];
  23346. $fixersByName = [];
  23347. $fixerConflicts = [];
  23348. $fixerNames = array_keys($ruleSet->getRules());
  23349. foreach ($fixerNames as $name) {
  23350. if (!array_key_exists($name, $this->fixersByName)) {
  23351. throw new \UnexpectedValueException(sprintf('Rule "%s" does not exist.', $name));
  23352. }
  23353. $fixer = $this->fixersByName[$name];
  23354. $config = $ruleSet->getRuleConfiguration($name);
  23355. if (null !== $config) {
  23356. if ($fixer instanceof ConfigurableFixerInterface) {
  23357. if (!is_array($config) || !count($config)) {
  23358. throw new InvalidFixerConfigurationException($fixer->getName(), 'Configuration must be an array and may not be empty.');
  23359. }
  23360. $fixer->configure($config);
  23361. } else {
  23362. throw new InvalidFixerConfigurationException($fixer->getName(), 'Is not configurable.');
  23363. }
  23364. }
  23365. $fixers[] = $fixer;
  23366. $fixersByName[$name] = $fixer;
  23367. $conflicts = array_intersect($this->getFixersConflicts($fixer), $fixerNames);
  23368. if (count($conflicts) > 0) {
  23369. $fixerConflicts[$name] = $conflicts;
  23370. }
  23371. }
  23372. if (count($fixerConflicts) > 0) {
  23373. throw new \UnexpectedValueException($this->generateConflictMessage($fixerConflicts));
  23374. }
  23375. $this->fixers = $fixers;
  23376. $this->fixersByName = $fixersByName;
  23377. return $this;
  23378. }
  23379. public function hasRule($name)
  23380. {
  23381. return isset($this->fixersByName[$name]);
  23382. }
  23383. private function getFixersConflicts(FixerInterface $fixer)
  23384. {
  23385. static $conflictMap = [
  23386. 'no_blank_lines_before_namespace' => ['single_blank_line_before_namespace'],
  23387. ];
  23388. $fixerName = $fixer->getName();
  23389. return array_key_exists($fixerName, $conflictMap) ? $conflictMap[$fixerName] : [];
  23390. }
  23391. private function generateConflictMessage(array $fixerConflicts)
  23392. {
  23393. $message = 'Rule contains conflicting fixers:';
  23394. $report = [];
  23395. foreach ($fixerConflicts as $fixer => $fixers) {
  23396. $report[$fixer] = array_filter(
  23397. $fixers,
  23398. static function ($candidate) use ($report, $fixer) {
  23399. return !array_key_exists($candidate, $report) || !in_array($fixer, $report[$candidate], true);
  23400. }
  23401. );
  23402. if (count($report[$fixer]) > 0) {
  23403. $message .= sprintf("\n- \"%s\" with \"%s\"", $fixer, implode('", "', $report[$fixer]));
  23404. }
  23405. }
  23406. return $message;
  23407. }
  23408. }
  23409. <?php
  23410. namespace PhpCsFixer;
  23411. use Symfony\Component\EventDispatcher\Event;
  23412. final class FixerFileProcessedEvent extends Event
  23413. {
  23414. const NAME = 'fixer.file_processed';
  23415. const STATUS_UNKNOWN = 0;
  23416. const STATUS_INVALID = 1;
  23417. const STATUS_SKIPPED = 2;
  23418. const STATUS_NO_CHANGES = 3;
  23419. const STATUS_FIXED = 4;
  23420. const STATUS_EXCEPTION = 5;
  23421. const STATUS_LINT = 6;
  23422. private $status;
  23423. public function __construct($status)
  23424. {
  23425. $this->status = $status;
  23426. }
  23427. public function getStatus()
  23428. {
  23429. return $this->status;
  23430. }
  23431. }
  23432. <?php
  23433. namespace PhpCsFixer;
  23434. final class FixerNameValidator
  23435. {
  23436. public function isValid($name, $isCustom)
  23437. {
  23438. if (!$isCustom) {
  23439. return 1 === preg_match('/^[a-z][a-z0-9_]*$/', $name);
  23440. }
  23441. return 1 === preg_match('/^[A-Z][a-zA-Z0-9]*\/[a-z][a-z0-9_]*$/', $name);
  23442. }
  23443. }
  23444. <?php
  23445. namespace PhpCsFixer\Indicator;
  23446. use PhpCsFixer\Tokenizer\Tokens;
  23447. final class PhpUnitTestCaseIndicator
  23448. {
  23449. public function isPhpUnitClass(Tokens $tokens, $index)
  23450. {
  23451. if (!$tokens[$index]->isGivenKind(T_CLASS)) {
  23452. throw new \LogicException(sprintf('No T_CLASS at given index %d, got %s.', $index, $tokens[$index]->getName()));
  23453. }
  23454. $classNameIndex = $tokens->getNextMeaningfulToken($index);
  23455. if (0 !== preg_match('/(?:Test|TestCase)$/', $tokens[$classNameIndex]->getContent())) {
  23456. return true;
  23457. }
  23458. $braceIndex = $tokens->getNextTokenOfKind($index, ['{']);
  23459. $maybeParentSubNameToken = $tokens[$tokens->getPrevMeaningfulToken($braceIndex)];
  23460. if (
  23461. $maybeParentSubNameToken->isGivenKind(T_STRING) &&
  23462. 0 !== preg_match('/(?:Test|TestCase)$/', $maybeParentSubNameToken->getContent())
  23463. ) {
  23464. return true;
  23465. }
  23466. return false;
  23467. }
  23468. }
  23469. <?php
  23470. namespace PhpCsFixer\Linter;
  23471. final class Linter implements LinterInterface
  23472. {
  23473. private $sublinter;
  23474. public function __construct($executable = null)
  23475. {
  23476. try {
  23477. $this->sublinter = new TokenizerLinter();
  23478. } catch (UnavailableLinterException $e) {
  23479. $this->sublinter = new ProcessLinter($executable);
  23480. }
  23481. }
  23482. public function isAsync()
  23483. {
  23484. return $this->sublinter->isAsync();
  23485. }
  23486. public function lintFile($path)
  23487. {
  23488. return $this->sublinter->lintFile($path);
  23489. }
  23490. public function lintSource($source)
  23491. {
  23492. return $this->sublinter->lintSource($source);
  23493. }
  23494. }
  23495. <?php
  23496. namespace PhpCsFixer\Linter;
  23497. interface LinterInterface
  23498. {
  23499. public function isAsync();
  23500. public function lintFile($path);
  23501. public function lintSource($source);
  23502. }
  23503. <?php
  23504. namespace PhpCsFixer\Linter;
  23505. class LintingException extends \RuntimeException
  23506. {
  23507. }
  23508. <?php
  23509. namespace PhpCsFixer\Linter;
  23510. interface LintingResultInterface
  23511. {
  23512. public function check();
  23513. }
  23514. <?php
  23515. namespace PhpCsFixer\Linter;
  23516. use PhpCsFixer\FileReader;
  23517. use PhpCsFixer\FileRemoval;
  23518. use Symfony\Component\Filesystem\Exception\IOException;
  23519. use Symfony\Component\Process\PhpExecutableFinder;
  23520. use Symfony\Component\Process\Process;
  23521. final class ProcessLinter implements LinterInterface
  23522. {
  23523. private $fileRemoval;
  23524. private $processBuilder;
  23525. private $temporaryFile;
  23526. public function __construct($executable = null)
  23527. {
  23528. if (null === $executable) {
  23529. $executableFinder = new PhpExecutableFinder();
  23530. $executable = $executableFinder->find(false);
  23531. if (false === $executable) {
  23532. throw new UnavailableLinterException('Cannot find PHP executable.');
  23533. }
  23534. if ('phpdbg' === PHP_SAPI) {
  23535. if (false === strpos($executable, 'phpdbg')) {
  23536. throw new UnavailableLinterException('Automatically found PHP executable is non-standard phpdbg. Could not find proper PHP executable.');
  23537. }
  23538. $executable = str_replace('phpdbg', 'php', $executable);
  23539. if (!is_executable($executable)) {
  23540. throw new UnavailableLinterException('Automatically found PHP executable is phpdbg. Could not find proper PHP executable.');
  23541. }
  23542. }
  23543. }
  23544. $this->processBuilder = new ProcessLinterProcessBuilder($executable);
  23545. $this->fileRemoval = new FileRemoval();
  23546. }
  23547. public function __destruct()
  23548. {
  23549. if (null !== $this->temporaryFile) {
  23550. $this->fileRemoval->delete($this->temporaryFile);
  23551. }
  23552. }
  23553. public function isAsync()
  23554. {
  23555. return true;
  23556. }
  23557. public function lintFile($path)
  23558. {
  23559. return new ProcessLintingResult($this->createProcessForFile($path));
  23560. }
  23561. public function lintSource($source)
  23562. {
  23563. return new ProcessLintingResult($this->createProcessForSource($source));
  23564. }
  23565. private function createProcessForFile($path)
  23566. {
  23567. if (!is_file($path)) {
  23568. return $this->createProcessForSource(FileReader::createSingleton()->read($path));
  23569. }
  23570. $process = $this->processBuilder->build($path);
  23571. $process->setTimeout(null);
  23572. $process->start();
  23573. return $process;
  23574. }
  23575. private function createProcessForSource($source)
  23576. {
  23577. if (null === $this->temporaryFile) {
  23578. $this->temporaryFile = tempnam('.', 'cs_fixer_tmp_');
  23579. $this->fileRemoval->observe($this->temporaryFile);
  23580. }
  23581. if (false === @file_put_contents($this->temporaryFile, $source)) {
  23582. throw new IOException(sprintf('Failed to write file "%s".', $this->temporaryFile), 0, null, $this->temporaryFile);
  23583. }
  23584. return $this->createProcessForFile($this->temporaryFile);
  23585. }
  23586. }
  23587. <?php
  23588. namespace PhpCsFixer\Linter;
  23589. use Symfony\Component\Process\Process;
  23590. final class ProcessLinterProcessBuilder
  23591. {
  23592. private $executable;
  23593. public function __construct($executable)
  23594. {
  23595. $this->executable = $executable;
  23596. }
  23597. public function build($path)
  23598. {
  23599. return new Process(sprintf(
  23600. '"%s" -l "%s"',
  23601. $this->executable,
  23602. $path
  23603. ));
  23604. }
  23605. }
  23606. <?php
  23607. namespace PhpCsFixer\Linter;
  23608. use Symfony\Component\Process\Process;
  23609. final class ProcessLintingResult implements LintingResultInterface
  23610. {
  23611. private $isSuccessful;
  23612. private $process;
  23613. public function __construct(Process $process)
  23614. {
  23615. $this->process = $process;
  23616. }
  23617. public function check()
  23618. {
  23619. if (!$this->isSuccessful()) {
  23620. throw new LintingException($this->process->getErrorOutput() ?: $this->process->getOutput(), $this->process->getExitCode());
  23621. }
  23622. }
  23623. private function isSuccessful()
  23624. {
  23625. if (null === $this->isSuccessful) {
  23626. $this->process->wait();
  23627. $this->isSuccessful = $this->process->isSuccessful();
  23628. }
  23629. return $this->isSuccessful;
  23630. }
  23631. }
  23632. <?php
  23633. namespace PhpCsFixer\Linter;
  23634. use PhpCsFixer\FileReader;
  23635. use PhpCsFixer\Tokenizer\CodeHasher;
  23636. use PhpCsFixer\Tokenizer\Tokens;
  23637. final class TokenizerLinter implements LinterInterface
  23638. {
  23639. public function __construct()
  23640. {
  23641. if (false === defined('TOKEN_PARSE')) {
  23642. throw new UnavailableLinterException('Cannot use tokenizer as linter.');
  23643. }
  23644. }
  23645. public function isAsync()
  23646. {
  23647. return false;
  23648. }
  23649. public function lintFile($path)
  23650. {
  23651. return $this->lintSource(FileReader::createSingleton()->read($path));
  23652. }
  23653. public function lintSource($source)
  23654. {
  23655. try {
  23656. $codeHash = CodeHasher::calculateCodeHash($source);
  23657. Tokens::clearCache($codeHash);
  23658. Tokens::fromCode($source);
  23659. return new TokenizerLintingResult();
  23660. } catch (\ParseError $e) {
  23661. return new TokenizerLintingResult($e);
  23662. }
  23663. }
  23664. }
  23665. <?php
  23666. namespace PhpCsFixer\Linter;
  23667. final class TokenizerLintingResult implements LintingResultInterface
  23668. {
  23669. private $error;
  23670. public function __construct(\ParseError $error = null)
  23671. {
  23672. $this->error = $error;
  23673. }
  23674. public function check()
  23675. {
  23676. if (null !== $this->error) {
  23677. throw new LintingException(
  23678. sprintf('PHP Parse error: %s on line %d.', $this->error->getMessage(), $this->error->getLine()),
  23679. $this->error->getCode(),
  23680. $this->error
  23681. );
  23682. }
  23683. }
  23684. }
  23685. <?php
  23686. namespace PhpCsFixer\Linter;
  23687. class UnavailableLinterException extends \RuntimeException
  23688. {
  23689. }
  23690. <?php
  23691. namespace PhpCsFixer;
  23692. final class PharChecker implements PharCheckerInterface
  23693. {
  23694. public function checkFileValidity($filename)
  23695. {
  23696. try {
  23697. $phar = new \Phar($filename);
  23698. unset($phar);
  23699. } catch (\Exception $e) {
  23700. if (!$e instanceof \UnexpectedValueException && !$e instanceof \PharException) {
  23701. throw $e;
  23702. }
  23703. return $e->getMessage();
  23704. }
  23705. return null;
  23706. }
  23707. }
  23708. <?php
  23709. namespace PhpCsFixer;
  23710. interface PharCheckerInterface
  23711. {
  23712. public function checkFileValidity($filename);
  23713. }
  23714. <?php
  23715. namespace PhpCsFixer\Report;
  23716. use Symfony\Component\Console\Formatter\OutputFormatter;
  23717. final class CheckstyleReporter implements ReporterInterface
  23718. {
  23719. public function getFormat()
  23720. {
  23721. return 'checkstyle';
  23722. }
  23723. public function generate(ReportSummary $reportSummary)
  23724. {
  23725. if (!extension_loaded('dom')) {
  23726. throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!');
  23727. }
  23728. $dom = new \DOMDocument('1.0', 'UTF-8');
  23729. $checkstyles = $dom->appendChild($dom->createElement('checkstyle'));
  23730. foreach ($reportSummary->getChanged() as $filePath => $fixResult) {
  23731. $file = $checkstyles->appendChild($dom->createElement('file'));
  23732. $file->setAttribute('name', $filePath);
  23733. foreach ($fixResult['appliedFixers'] as $appliedFixer) {
  23734. $error = $this->createError($dom, $appliedFixer);
  23735. $file->appendChild($error);
  23736. }
  23737. }
  23738. $dom->formatOutput = true;
  23739. return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($dom->saveXML()) : $dom->saveXML();
  23740. }
  23741. private function createError(\DOMDocument $dom, $appliedFixer)
  23742. {
  23743. $error = $dom->createElement('error');
  23744. $error->setAttribute('severity', 'warning');
  23745. $error->setAttribute('source', 'PHP-CS-Fixer.'.$appliedFixer);
  23746. $error->setAttribute('message', 'Found violation(s) of type: '.$appliedFixer);
  23747. return $error;
  23748. }
  23749. }
  23750. <?php
  23751. namespace PhpCsFixer\Report;
  23752. use Symfony\Component\Console\Formatter\OutputFormatter;
  23753. final class JsonReporter implements ReporterInterface
  23754. {
  23755. public function getFormat()
  23756. {
  23757. return 'json';
  23758. }
  23759. public function generate(ReportSummary $reportSummary)
  23760. {
  23761. $jFiles = [];
  23762. foreach ($reportSummary->getChanged() as $file => $fixResult) {
  23763. $jfile = ['name' => $file];
  23764. if ($reportSummary->shouldAddAppliedFixers()) {
  23765. $jfile['appliedFixers'] = $fixResult['appliedFixers'];
  23766. }
  23767. if (!empty($fixResult['diff'])) {
  23768. $jfile['diff'] = $fixResult['diff'];
  23769. }
  23770. $jFiles[] = $jfile;
  23771. }
  23772. $json = [
  23773. 'files' => $jFiles,
  23774. ];
  23775. if (null !== $reportSummary->getTime()) {
  23776. $json['time'] = [
  23777. 'total' => round($reportSummary->getTime() / 1000, 3),
  23778. ];
  23779. }
  23780. if (null !== $reportSummary->getMemory()) {
  23781. $json['memory'] = round($reportSummary->getMemory() / 1024 / 1024, 3);
  23782. }
  23783. $json = json_encode($json);
  23784. return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($json) : $json;
  23785. }
  23786. }
  23787. <?php
  23788. namespace PhpCsFixer\Report;
  23789. use Symfony\Component\Console\Formatter\OutputFormatter;
  23790. final class JunitReporter implements ReporterInterface
  23791. {
  23792. public function getFormat()
  23793. {
  23794. return 'junit';
  23795. }
  23796. public function generate(ReportSummary $reportSummary)
  23797. {
  23798. if (!extension_loaded('dom')) {
  23799. throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!');
  23800. }
  23801. $dom = new \DOMDocument('1.0', 'UTF-8');
  23802. $testsuites = $dom->appendChild($dom->createElement('testsuites'));
  23803. $testsuite = $testsuites->appendChild($dom->createElement('testsuite'));
  23804. $testsuite->setAttribute('name', 'PHP CS Fixer');
  23805. if (count($reportSummary->getChanged())) {
  23806. $this->createFailedTestCases($dom, $testsuite, $reportSummary);
  23807. } else {
  23808. $this->createSuccessTestCase($dom, $testsuite);
  23809. }
  23810. if ($reportSummary->getTime()) {
  23811. $testsuite->setAttribute(
  23812. 'time',
  23813. sprintf(
  23814. '%.3f',
  23815. $reportSummary->getTime() / 1000
  23816. )
  23817. );
  23818. }
  23819. $dom->formatOutput = true;
  23820. return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($dom->saveXML()) : $dom->saveXML();
  23821. }
  23822. private function createSuccessTestCase(\DOMDocument $dom, \DOMElement $testsuite)
  23823. {
  23824. $testcase = $dom->createElement('testcase');
  23825. $testcase->setAttribute('name', 'All OK');
  23826. $testcase->setAttribute('assertions', '1');
  23827. $testsuite->appendChild($testcase);
  23828. $testsuite->setAttribute('tests', '1');
  23829. $testsuite->setAttribute('assertions', '1');
  23830. $testsuite->setAttribute('failures', '0');
  23831. $testsuite->setAttribute('errors', '0');
  23832. }
  23833. private function createFailedTestCases(\DOMDocument $dom, \DOMElement $testsuite, ReportSummary $reportSummary)
  23834. {
  23835. $assertionsCount = 0;
  23836. foreach ($reportSummary->getChanged() as $file => $fixResult) {
  23837. $testcase = $this->createFailedTestCase(
  23838. $dom,
  23839. $file,
  23840. $fixResult,
  23841. $reportSummary->shouldAddAppliedFixers()
  23842. );
  23843. $testsuite->appendChild($testcase);
  23844. $assertionsCount += (int) $testcase->getAttribute('assertions');
  23845. }
  23846. $testsuite->setAttribute('tests', (string) count($reportSummary->getChanged()));
  23847. $testsuite->setAttribute('assertions', (string) $assertionsCount);
  23848. $testsuite->setAttribute('failures', (string) $assertionsCount);
  23849. $testsuite->setAttribute('errors', '0');
  23850. }
  23851. private function createFailedTestCase(\DOMDocument $dom, $file, array $fixResult, $shouldAddAppliedFixers)
  23852. {
  23853. $appliedFixersCount = count($fixResult['appliedFixers']);
  23854. $testName = str_replace('.', '_DOT_', preg_replace('@\.'.pathinfo($file, PATHINFO_EXTENSION).'$@', '', $file));
  23855. $testcase = $dom->createElement('testcase');
  23856. $testcase->setAttribute('name', $testName);
  23857. $testcase->setAttribute('file', $file);
  23858. $testcase->setAttribute('assertions', (string) $appliedFixersCount);
  23859. $failure = $dom->createElement('failure');
  23860. $failure->setAttribute('type', 'code_style');
  23861. $testcase->appendChild($failure);
  23862. if ($shouldAddAppliedFixers) {
  23863. $failureContent = "applied fixers:\n---------------\n";
  23864. foreach ($fixResult['appliedFixers'] as $appliedFixer) {
  23865. $failureContent .= "* {$appliedFixer}\n";
  23866. }
  23867. } else {
  23868. $failureContent = "Wrong code style\n";
  23869. }
  23870. if (!empty($fixResult['diff'])) {
  23871. $failureContent .= "\nDiff:\n---------------\n\n".$fixResult['diff'];
  23872. }
  23873. $failure->appendChild($dom->createCDATASection(trim($failureContent)));
  23874. return $testcase;
  23875. }
  23876. }
  23877. <?php
  23878. namespace PhpCsFixer\Report;
  23879. final class ReportSummary
  23880. {
  23881. private $addAppliedFixers;
  23882. private $changed;
  23883. private $isDecoratedOutput;
  23884. private $isDryRun;
  23885. private $memory;
  23886. private $time;
  23887. public function __construct(
  23888. array $changed,
  23889. $time,
  23890. $memory,
  23891. $addAppliedFixers,
  23892. $isDryRun,
  23893. $isDecoratedOutput
  23894. ) {
  23895. $this->changed = $changed;
  23896. $this->time = $time;
  23897. $this->memory = $memory;
  23898. $this->addAppliedFixers = $addAppliedFixers;
  23899. $this->isDryRun = $isDryRun;
  23900. $this->isDecoratedOutput = $isDecoratedOutput;
  23901. }
  23902. public function isDecoratedOutput()
  23903. {
  23904. return $this->isDecoratedOutput;
  23905. }
  23906. public function isDryRun()
  23907. {
  23908. return $this->isDryRun;
  23909. }
  23910. public function getChanged()
  23911. {
  23912. return $this->changed;
  23913. }
  23914. public function getMemory()
  23915. {
  23916. return $this->memory;
  23917. }
  23918. public function getTime()
  23919. {
  23920. return $this->time;
  23921. }
  23922. public function shouldAddAppliedFixers()
  23923. {
  23924. return $this->addAppliedFixers;
  23925. }
  23926. }
  23927. <?php
  23928. namespace PhpCsFixer\Report;
  23929. use Symfony\Component\Finder\Finder as SymfonyFinder;
  23930. use Symfony\Component\Finder\SplFileInfo;
  23931. final class ReporterFactory
  23932. {
  23933. private $reporters = [];
  23934. public static function create()
  23935. {
  23936. return new self();
  23937. }
  23938. public function registerBuiltInReporters()
  23939. {
  23940. static $builtInReporters;
  23941. if (null === $builtInReporters) {
  23942. $builtInReporters = [];
  23943. foreach (SymfonyFinder::create()->files()->name('*Reporter.php')->in(__DIR__) as $file) {
  23944. $relativeNamespace = $file->getRelativePath();
  23945. $builtInReporters[] = sprintf(
  23946. '%s\\%s%s',
  23947. __NAMESPACE__,
  23948. $relativeNamespace ? $relativeNamespace.'\\' : '',
  23949. $file->getBasename('.php')
  23950. );
  23951. }
  23952. }
  23953. foreach ($builtInReporters as $reporterClass) {
  23954. $this->registerReporter(new $reporterClass());
  23955. }
  23956. return $this;
  23957. }
  23958. public function registerReporter(ReporterInterface $reporter)
  23959. {
  23960. $format = $reporter->getFormat();
  23961. if (isset($this->reporters[$format])) {
  23962. throw new \UnexpectedValueException(sprintf('Reporter for format "%s" is already registered.', $format));
  23963. }
  23964. $this->reporters[$format] = $reporter;
  23965. return $this;
  23966. }
  23967. public function getFormats()
  23968. {
  23969. $formats = array_keys($this->reporters);
  23970. sort($formats);
  23971. return $formats;
  23972. }
  23973. public function getReporter($format)
  23974. {
  23975. if (!isset($this->reporters[$format])) {
  23976. throw new \UnexpectedValueException(sprintf('Reporter for format "%s" is not registered.', $format));
  23977. }
  23978. return $this->reporters[$format];
  23979. }
  23980. }
  23981. <?php
  23982. namespace PhpCsFixer\Report;
  23983. interface ReporterInterface
  23984. {
  23985. public function getFormat();
  23986. public function generate(ReportSummary $reportSummary);
  23987. }
  23988. <?php
  23989. namespace PhpCsFixer\Report;
  23990. use PhpCsFixer\Differ\DiffConsoleFormatter;
  23991. final class TextReporter implements ReporterInterface
  23992. {
  23993. public function getFormat()
  23994. {
  23995. return 'txt';
  23996. }
  23997. public function generate(ReportSummary $reportSummary)
  23998. {
  23999. $output = '';
  24000. $i = 0;
  24001. foreach ($reportSummary->getChanged() as $file => $fixResult) {
  24002. ++$i;
  24003. $output .= sprintf('%4d) %s', $i, $file);
  24004. if ($reportSummary->shouldAddAppliedFixers()) {
  24005. $output .= $this->getAppliedFixers($reportSummary->isDecoratedOutput(), $fixResult);
  24006. }
  24007. $output .= $this->getDiff($reportSummary->isDecoratedOutput(), $fixResult);
  24008. $output .= PHP_EOL;
  24009. }
  24010. return $output.$this->getFooter($reportSummary->getTime(), $reportSummary->getMemory(), $reportSummary->isDryRun());
  24011. }
  24012. private function getAppliedFixers($isDecoratedOutput, array $fixResult)
  24013. {
  24014. return sprintf(
  24015. $isDecoratedOutput ? ' (<comment>%s</comment>)' : ' (%s)',
  24016. implode(', ', $fixResult['appliedFixers'])
  24017. );
  24018. }
  24019. private function getDiff($isDecoratedOutput, array $fixResult)
  24020. {
  24021. if (empty($fixResult['diff'])) {
  24022. return '';
  24023. }
  24024. $diffFormatter = new DiffConsoleFormatter($isDecoratedOutput, sprintf(
  24025. '<comment> ---------- begin diff ----------</comment>%s%%s%s<comment> ----------- end diff -----------</comment>',
  24026. PHP_EOL,
  24027. PHP_EOL
  24028. ));
  24029. return PHP_EOL.$diffFormatter->format($fixResult['diff']).PHP_EOL;
  24030. }
  24031. private function getFooter($time, $memory, $isDryRun)
  24032. {
  24033. if (0 === $time || 0 === $memory) {
  24034. return '';
  24035. }
  24036. return PHP_EOL.sprintf(
  24037. '%s all files in %.3f seconds, %.3f MB memory used'.PHP_EOL,
  24038. $isDryRun ? 'Checked' : 'Fixed',
  24039. $time / 1000,
  24040. $memory / 1024 / 1024
  24041. );
  24042. }
  24043. }
  24044. <?php
  24045. namespace PhpCsFixer\Report;
  24046. use Symfony\Component\Console\Formatter\OutputFormatter;
  24047. final class XmlReporter implements ReporterInterface
  24048. {
  24049. public function getFormat()
  24050. {
  24051. return 'xml';
  24052. }
  24053. public function generate(ReportSummary $reportSummary)
  24054. {
  24055. if (!extension_loaded('dom')) {
  24056. throw new \RuntimeException('Cannot generate report! `ext-dom` is not available!');
  24057. }
  24058. $dom = new \DOMDocument('1.0', 'UTF-8');
  24059. $root = $dom->createElement('report');
  24060. $dom->appendChild($root);
  24061. $filesXML = $dom->createElement('files');
  24062. $root->appendChild($filesXML);
  24063. $i = 1;
  24064. foreach ($reportSummary->getChanged() as $file => $fixResult) {
  24065. $fileXML = $dom->createElement('file');
  24066. $fileXML->setAttribute('id', (string) $i++);
  24067. $fileXML->setAttribute('name', $file);
  24068. $filesXML->appendChild($fileXML);
  24069. if ($reportSummary->shouldAddAppliedFixers()) {
  24070. $fileXML->appendChild($this->createAppliedFixersElement($dom, $fixResult));
  24071. }
  24072. if (!empty($fixResult['diff'])) {
  24073. $fileXML->appendChild($this->createDiffElement($dom, $fixResult));
  24074. }
  24075. }
  24076. if (0 !== $reportSummary->getTime()) {
  24077. $root->appendChild($this->createTimeElement($reportSummary->getTime(), $dom));
  24078. }
  24079. if (0 !== $reportSummary->getMemory()) {
  24080. $root->appendChild($this->createMemoryElement($reportSummary->getMemory(), $dom));
  24081. }
  24082. $dom->formatOutput = true;
  24083. return $reportSummary->isDecoratedOutput() ? OutputFormatter::escape($dom->saveXML()) : $dom->saveXML();
  24084. }
  24085. private function createAppliedFixersElement($dom, array $fixResult)
  24086. {
  24087. $appliedFixersXML = $dom->createElement('applied_fixers');
  24088. foreach ($fixResult['appliedFixers'] as $appliedFixer) {
  24089. $appliedFixerXML = $dom->createElement('applied_fixer');
  24090. $appliedFixerXML->setAttribute('name', $appliedFixer);
  24091. $appliedFixersXML->appendChild($appliedFixerXML);
  24092. }
  24093. return $appliedFixersXML;
  24094. }
  24095. private function createDiffElement(\DOMDocument $dom, array $fixResult)
  24096. {
  24097. $diffXML = $dom->createElement('diff');
  24098. $diffXML->appendChild($dom->createCDATASection($fixResult['diff']));
  24099. return $diffXML;
  24100. }
  24101. private function createTimeElement($time, \DOMDocument $dom)
  24102. {
  24103. $time = round($time / 1000, 3);
  24104. $timeXML = $dom->createElement('time');
  24105. $timeXML->setAttribute('unit', 's');
  24106. $timeTotalXML = $dom->createElement('total');
  24107. $timeTotalXML->setAttribute('value', (string) $time);
  24108. $timeXML->appendChild($timeTotalXML);
  24109. return $timeXML;
  24110. }
  24111. private function createMemoryElement($memory, \DOMDocument $dom)
  24112. {
  24113. $memory = round($memory / 1024 / 1024, 3);
  24114. $memoryXML = $dom->createElement('memory');
  24115. $memoryXML->setAttribute('value', (string) $memory);
  24116. $memoryXML->setAttribute('unit', 'MB');
  24117. return $memoryXML;
  24118. }
  24119. }
  24120. <?php
  24121. namespace PhpCsFixer;
  24122. use PhpCsFixer\Fixer\PhpUnit\PhpUnitTargetVersion;
  24123. final class RuleSet implements RuleSetInterface
  24124. {
  24125. private $setDefinitions = [
  24126. '@PSR1' => [
  24127. 'encoding' => true,
  24128. 'full_opening_tag' => true,
  24129. ],
  24130. '@PSR2' => [
  24131. '@PSR1' => true,
  24132. 'blank_line_after_namespace' => true,
  24133. 'braces' => true,
  24134. 'class_definition' => true,
  24135. 'elseif' => true,
  24136. 'function_declaration' => true,
  24137. 'indentation_type' => true,
  24138. 'line_ending' => true,
  24139. 'lowercase_constants' => true,
  24140. 'lowercase_keywords' => true,
  24141. 'method_argument_space' => ['ensure_fully_multiline' => true],
  24142. 'no_break_comment' => true,
  24143. 'no_closing_tag' => true,
  24144. 'no_spaces_after_function_name' => true,
  24145. 'no_spaces_inside_parenthesis' => true,
  24146. 'no_trailing_whitespace' => true,
  24147. 'no_trailing_whitespace_in_comment' => true,
  24148. 'single_blank_line_at_eof' => true,
  24149. 'single_class_element_per_statement' => ['elements' => ['property']],
  24150. 'single_import_per_statement' => true,
  24151. 'single_line_after_imports' => true,
  24152. 'switch_case_semicolon_to_colon' => true,
  24153. 'switch_case_space' => true,
  24154. 'visibility_required' => true,
  24155. ],
  24156. '@Symfony' => [
  24157. '@PSR2' => true,
  24158. 'binary_operator_spaces' => true,
  24159. 'blank_line_after_opening_tag' => true,
  24160. 'blank_line_before_statement' => [
  24161. 'statements' => ['return'],
  24162. ],
  24163. 'braces' => [
  24164. 'allow_single_line_closure' => true,
  24165. ],
  24166. 'cast_spaces' => true,
  24167. 'class_attributes_separation' => ['elements' => ['method']],
  24168. 'class_definition' => ['singleLine' => true],
  24169. 'concat_space' => ['spacing' => 'none'],
  24170. 'declare_equal_normalize' => true,
  24171. 'function_typehint_space' => true,
  24172. 'include' => true,
  24173. 'increment_style' => true,
  24174. 'lowercase_cast' => true,
  24175. 'magic_constant_casing' => true,
  24176. 'method_argument_space' => true,
  24177. 'native_function_casing' => true,
  24178. 'new_with_braces' => true,
  24179. 'no_blank_lines_after_class_opening' => true,
  24180. 'no_blank_lines_after_phpdoc' => true,
  24181. 'no_empty_comment' => true,
  24182. 'no_empty_phpdoc' => true,
  24183. 'no_empty_statement' => true,
  24184. 'no_extra_blank_lines' => ['tokens' => [
  24185. 'curly_brace_block',
  24186. 'extra',
  24187. 'parenthesis_brace_block',
  24188. 'square_brace_block',
  24189. 'throw',
  24190. 'use',
  24191. ]],
  24192. 'no_leading_import_slash' => true,
  24193. 'no_leading_namespace_whitespace' => true,
  24194. 'no_mixed_echo_print' => ['use' => 'echo'],
  24195. 'no_multiline_whitespace_around_double_arrow' => true,
  24196. 'no_short_bool_cast' => true,
  24197. 'no_singleline_whitespace_before_semicolons' => true,
  24198. 'no_spaces_around_offset' => true,
  24199. 'no_trailing_comma_in_list_call' => true,
  24200. 'no_trailing_comma_in_singleline_array' => true,
  24201. 'no_unneeded_control_parentheses' => true,
  24202. 'no_unneeded_curly_braces' => true,
  24203. 'no_unneeded_final_method' => true,
  24204. 'no_unused_imports' => true,
  24205. 'no_whitespace_before_comma_in_array' => true,
  24206. 'no_whitespace_in_blank_line' => true,
  24207. 'normalize_index_brace' => true,
  24208. 'object_operator_without_whitespace' => true,
  24209. 'php_unit_fqcn_annotation' => true,
  24210. 'phpdoc_align' => [
  24211. 'tags' => [
  24212. 'method',
  24213. 'param',
  24214. 'property',
  24215. 'return',
  24216. 'throws',
  24217. 'type',
  24218. 'var',
  24219. ],
  24220. ],
  24221. 'phpdoc_annotation_without_dot' => true,
  24222. 'phpdoc_indent' => true,
  24223. 'phpdoc_inline_tag' => true,
  24224. 'phpdoc_no_access' => true,
  24225. 'phpdoc_no_alias_tag' => true,
  24226. 'phpdoc_no_empty_return' => true,
  24227. 'phpdoc_no_package' => true,
  24228. 'phpdoc_no_useless_inheritdoc' => true,
  24229. 'phpdoc_return_self_reference' => true,
  24230. 'phpdoc_scalar' => true,
  24231. 'phpdoc_separation' => true,
  24232. 'phpdoc_single_line_var_spacing' => true,
  24233. 'phpdoc_summary' => true,
  24234. 'phpdoc_to_comment' => true,
  24235. 'phpdoc_trim' => true,
  24236. 'phpdoc_types' => true,
  24237. 'phpdoc_var_without_name' => true,
  24238. 'protected_to_private' => true,
  24239. 'return_type_declaration' => true,
  24240. 'self_accessor' => true,
  24241. 'semicolon_after_instruction' => true,
  24242. 'short_scalar_cast' => true,
  24243. 'single_blank_line_before_namespace' => true,
  24244. 'single_class_element_per_statement' => true,
  24245. 'single_line_comment_style' => [
  24246. 'comment_types' => ['hash'],
  24247. ],
  24248. 'single_quote' => true,
  24249. 'space_after_semicolon' => [
  24250. 'remove_in_empty_for_expressions' => true,
  24251. ],
  24252. 'standardize_not_equals' => true,
  24253. 'ternary_operator_spaces' => true,
  24254. 'trailing_comma_in_multiline_array' => true,
  24255. 'trim_array_spaces' => true,
  24256. 'unary_operator_spaces' => true,
  24257. 'whitespace_after_comma_in_array' => true,
  24258. 'yoda_style' => true,
  24259. ],
  24260. '@Symfony:risky' => [
  24261. 'dir_constant' => true,
  24262. 'ereg_to_preg' => true,
  24263. 'function_to_constant' => true,
  24264. 'is_null' => true,
  24265. 'modernize_types_casting' => true,
  24266. 'no_alias_functions' => true,
  24267. 'no_homoglyph_names' => true,
  24268. 'non_printable_character' => [
  24269. 'use_escape_sequences_in_strings' => false,
  24270. ],
  24271. 'php_unit_construct' => true,
  24272. 'psr4' => true,
  24273. 'silenced_deprecation_error' => true,
  24274. ],
  24275. '@DoctrineAnnotation' => [
  24276. 'doctrine_annotation_array_assignment' => [
  24277. 'operator' => ':',
  24278. ],
  24279. 'doctrine_annotation_braces' => true,
  24280. 'doctrine_annotation_indentation' => true,
  24281. 'doctrine_annotation_spaces' => [
  24282. 'before_array_assignments_colon' => false,
  24283. ],
  24284. ],
  24285. '@PHP56Migration' => [],
  24286. '@PHP56Migration:risky' => [
  24287. 'pow_to_exponentiation' => true,
  24288. ],
  24289. '@PHP70Migration' => [
  24290. '@PHP56Migration' => true,
  24291. 'ternary_to_null_coalescing' => true,
  24292. ],
  24293. '@PHP70Migration:risky' => [
  24294. '@PHP56Migration:risky' => true,
  24295. 'declare_strict_types' => true,
  24296. 'non_printable_character' => [
  24297. 'use_escape_sequences_in_strings' => true,
  24298. ],
  24299. 'random_api_migration' => ['replacements' => [
  24300. 'mt_rand' => 'random_int',
  24301. 'rand' => 'random_int',
  24302. ]],
  24303. ],
  24304. '@PHP71Migration' => [
  24305. '@PHP70Migration' => true,
  24306. 'visibility_required' => ['elements' => [
  24307. 'const',
  24308. 'method',
  24309. 'property',
  24310. ]],
  24311. ],
  24312. '@PHP71Migration:risky' => [
  24313. '@PHP70Migration:risky' => true,
  24314. 'void_return' => true,
  24315. ],
  24316. '@PHPUnit30Migration:risky' => [
  24317. 'php_unit_dedicate_assert' => ['target' => PhpUnitTargetVersion::VERSION_3_0],
  24318. ],
  24319. '@PHPUnit32Migration:risky' => [
  24320. '@PHPUnit30Migration:risky' => true,
  24321. 'php_unit_no_expectation_annotation' => ['target' => PhpUnitTargetVersion::VERSION_3_2],
  24322. ],
  24323. '@PHPUnit35Migration:risky' => [
  24324. '@PHPUnit32Migration:risky' => true,
  24325. 'php_unit_dedicate_assert' => ['target' => PhpUnitTargetVersion::VERSION_3_5],
  24326. ],
  24327. '@PHPUnit43Migration:risky' => [
  24328. '@PHPUnit35Migration:risky' => true,
  24329. 'php_unit_no_expectation_annotation' => ['target' => PhpUnitTargetVersion::VERSION_4_3],
  24330. ],
  24331. '@PHPUnit48Migration:risky' => [
  24332. '@PHPUnit43Migration:risky' => true,
  24333. 'php_unit_namespaced' => ['target' => PhpUnitTargetVersion::VERSION_4_8],
  24334. ],
  24335. '@PHPUnit50Migration:risky' => [
  24336. '@PHPUnit48Migration:risky' => true,
  24337. 'php_unit_dedicate_assert' => ['target' => PhpUnitTargetVersion::VERSION_5_0],
  24338. ],
  24339. '@PHPUnit52Migration:risky' => [
  24340. '@PHPUnit50Migration:risky' => true,
  24341. 'php_unit_expectation' => ['target' => PhpUnitTargetVersion::VERSION_5_2],
  24342. ],
  24343. '@PHPUnit54Migration:risky' => [
  24344. '@PHPUnit52Migration:risky' => true,
  24345. 'php_unit_mock' => ['target' => PhpUnitTargetVersion::VERSION_5_4],
  24346. ],
  24347. '@PHPUnit55Migration:risky' => [
  24348. '@PHPUnit54Migration:risky' => true,
  24349. 'php_unit_mock' => ['target' => PhpUnitTargetVersion::VERSION_5_5],
  24350. ],
  24351. '@PHPUnit56Migration:risky' => [
  24352. '@PHPUnit55Migration:risky' => true,
  24353. 'php_unit_dedicate_assert' => ['target' => PhpUnitTargetVersion::VERSION_5_6],
  24354. 'php_unit_expectation' => ['target' => PhpUnitTargetVersion::VERSION_5_6],
  24355. ],
  24356. '@PHPUnit57Migration:risky' => [
  24357. '@PHPUnit56Migration:risky' => true,
  24358. 'php_unit_namespaced' => ['target' => PhpUnitTargetVersion::VERSION_5_7],
  24359. ],
  24360. '@PHPUnit60Migration:risky' => [
  24361. '@PHPUnit57Migration:risky' => true,
  24362. 'php_unit_namespaced' => ['target' => PhpUnitTargetVersion::VERSION_6_0],
  24363. ],
  24364. ];
  24365. private $set;
  24366. private $rules;
  24367. public function __construct(array $set = [])
  24368. {
  24369. foreach ($set as $key => $value) {
  24370. if (is_int($key)) {
  24371. throw new \InvalidArgumentException(sprintf('Missing value for "%s" rule/set.', $value));
  24372. }
  24373. }
  24374. $this->set = $set;
  24375. $this->resolveSet();
  24376. }
  24377. public static function create(array $set = [])
  24378. {
  24379. return new self($set);
  24380. }
  24381. public function hasRule($rule)
  24382. {
  24383. return array_key_exists($rule, $this->rules);
  24384. }
  24385. public function getRuleConfiguration($rule)
  24386. {
  24387. if (!$this->hasRule($rule)) {
  24388. throw new \InvalidArgumentException(sprintf('Rule "%s" is not in the set.', $rule));
  24389. }
  24390. if (true === $this->rules[$rule]) {
  24391. return null;
  24392. }
  24393. return $this->rules[$rule];
  24394. }
  24395. public function getRules()
  24396. {
  24397. return $this->rules;
  24398. }
  24399. public function getSetDefinitionNames()
  24400. {
  24401. return array_keys($this->setDefinitions);
  24402. }
  24403. private function getSetDefinition($name)
  24404. {
  24405. if (!isset($this->setDefinitions[$name])) {
  24406. throw new \InvalidArgumentException(sprintf('Set "%s" does not exist.', $name));
  24407. }
  24408. return $this->setDefinitions[$name];
  24409. }
  24410. private function resolveSet()
  24411. {
  24412. $rules = $this->set;
  24413. $resolvedRules = [];
  24414. foreach ($rules as $name => $value) {
  24415. if ('@' === $name[0]) {
  24416. if (!is_bool($value)) {
  24417. throw new \UnexpectedValueException(sprintf('Nested rule set "%s" configuration must be a boolean.', $name));
  24418. }
  24419. $set = $this->resolveSubset($name, $value);
  24420. $resolvedRules = array_merge($resolvedRules, $set);
  24421. } else {
  24422. $resolvedRules[$name] = $value;
  24423. }
  24424. }
  24425. $resolvedRules = array_filter($resolvedRules);
  24426. $this->rules = $resolvedRules;
  24427. return $this;
  24428. }
  24429. private function resolveSubset($setName, $setValue)
  24430. {
  24431. $rules = $this->getSetDefinition($setName);
  24432. foreach ($rules as $name => $value) {
  24433. if ('@' === $name[0]) {
  24434. $set = $this->resolveSubset($name, $setValue);
  24435. unset($rules[$name]);
  24436. $rules = array_merge($rules, $set);
  24437. } elseif (!$setValue) {
  24438. $rules[$name] = false;
  24439. } else {
  24440. $rules[$name] = $value;
  24441. }
  24442. }
  24443. return $rules;
  24444. }
  24445. }
  24446. <?php
  24447. namespace PhpCsFixer;
  24448. interface RuleSetInterface
  24449. {
  24450. public function __construct(array $set = []);
  24451. public static function create(array $set = []);
  24452. public function getRuleConfiguration($rule);
  24453. public function getRules();
  24454. public function getSetDefinitionNames();
  24455. public function hasRule($rule);
  24456. }
  24457. <?php
  24458. namespace PhpCsFixer\Runner;
  24459. use PhpCsFixer\Linter\LinterInterface;
  24460. use PhpCsFixer\Linter\LintingResultInterface;
  24461. final class FileCachingLintingIterator extends \CachingIterator
  24462. {
  24463. private $currentResult;
  24464. private $linter;
  24465. private $nextResult;
  24466. public function __construct(\Iterator $iterator, LinterInterface $linter)
  24467. {
  24468. parent::__construct($iterator);
  24469. $this->linter = $linter;
  24470. }
  24471. public function currentLintingResult()
  24472. {
  24473. return $this->currentResult;
  24474. }
  24475. public function next()
  24476. {
  24477. parent::next();
  24478. $this->currentResult = $this->nextResult;
  24479. if ($this->hasNext()) {
  24480. $this->nextResult = $this->handleItem($this->getInnerIterator()->current());
  24481. }
  24482. }
  24483. public function rewind()
  24484. {
  24485. parent::rewind();
  24486. if ($this->valid()) {
  24487. $this->currentResult = $this->handleItem($this->current());
  24488. }
  24489. if ($this->hasNext()) {
  24490. $this->nextResult = $this->handleItem($this->getInnerIterator()->current());
  24491. }
  24492. }
  24493. private function handleItem(\SplFileInfo $file)
  24494. {
  24495. return $this->linter->lintFile($file->getRealPath());
  24496. }
  24497. }
  24498. <?php
  24499. namespace PhpCsFixer\Runner;
  24500. use PhpCsFixer\Cache\CacheManagerInterface;
  24501. use PhpCsFixer\FileReader;
  24502. use PhpCsFixer\FixerFileProcessedEvent;
  24503. use Symfony\Component\EventDispatcher\Event;
  24504. use Symfony\Component\EventDispatcher\EventDispatcher;
  24505. final class FileFilterIterator extends \FilterIterator
  24506. {
  24507. private $eventDispatcher;
  24508. private $cacheManager;
  24509. private $visitedElements = [];
  24510. public function __construct(
  24511. \Iterator $iterator,
  24512. EventDispatcher $eventDispatcher = null,
  24513. CacheManagerInterface $cacheManager
  24514. ) {
  24515. parent::__construct($iterator);
  24516. $this->eventDispatcher = $eventDispatcher;
  24517. $this->cacheManager = $cacheManager;
  24518. }
  24519. public function accept()
  24520. {
  24521. $file = $this->current();
  24522. if (!$file instanceof \SplFileInfo) {
  24523. throw new \RuntimeException(
  24524. sprintf(
  24525. 'Expected instance of "\SplFileInfo", got "%s".',
  24526. is_object($file) ? get_class($file) : gettype($file)
  24527. )
  24528. );
  24529. }
  24530. $path = $file->getRealPath();
  24531. if (isset($this->visitedElements[$path])) {
  24532. return false;
  24533. }
  24534. $this->visitedElements[$path] = true;
  24535. if (!$file->isFile() || $file->isLink()) {
  24536. return false;
  24537. }
  24538. $content = @FileReader::createSingleton()->read($path);
  24539. if (false === $content) {
  24540. $error = error_get_last();
  24541. throw new \RuntimeException(sprintf(
  24542. 'Failed to read content from "%s".%s',
  24543. $path,
  24544. $error ? ' '.$error['message'] : ''
  24545. ));
  24546. }
  24547. if (
  24548. '' === $content
  24549. || !$this->cacheManager->needFixing($file->getPathname(), $content)
  24550. ) {
  24551. $this->dispatchEvent(
  24552. FixerFileProcessedEvent::NAME,
  24553. new FixerFileProcessedEvent(FixerFileProcessedEvent::STATUS_SKIPPED)
  24554. );
  24555. return false;
  24556. }
  24557. return true;
  24558. }
  24559. private function dispatchEvent($name, Event $event)
  24560. {
  24561. if (null === $this->eventDispatcher) {
  24562. return;
  24563. }
  24564. $this->eventDispatcher->dispatch($name, $event);
  24565. }
  24566. }
  24567. <?php
  24568. namespace PhpCsFixer\Runner;
  24569. use PhpCsFixer\Linter\LinterInterface;
  24570. use PhpCsFixer\Linter\LintingResultInterface;
  24571. final class FileLintingIterator extends \IteratorIterator
  24572. {
  24573. private $currentResult;
  24574. private $linter;
  24575. public function __construct(\Iterator $iterator, LinterInterface $linter)
  24576. {
  24577. parent::__construct($iterator);
  24578. $this->linter = $linter;
  24579. }
  24580. public function currentLintingResult()
  24581. {
  24582. return $this->currentResult;
  24583. }
  24584. public function next()
  24585. {
  24586. parent::next();
  24587. if ($this->valid()) {
  24588. $this->currentResult = $this->handleItem($this->current());
  24589. }
  24590. }
  24591. public function rewind()
  24592. {
  24593. parent::rewind();
  24594. if ($this->valid()) {
  24595. $this->currentResult = $this->handleItem($this->current());
  24596. }
  24597. }
  24598. private function handleItem(\SplFileInfo $file)
  24599. {
  24600. return $this->linter->lintFile($file->getRealPath());
  24601. }
  24602. }
  24603. <?php
  24604. namespace PhpCsFixer\Runner;
  24605. use PhpCsFixer\AbstractFixer;
  24606. use PhpCsFixer\Cache\CacheManagerInterface;
  24607. use PhpCsFixer\Cache\Directory;
  24608. use PhpCsFixer\Cache\DirectoryInterface;
  24609. use PhpCsFixer\Differ\DifferInterface;
  24610. use PhpCsFixer\Error\Error;
  24611. use PhpCsFixer\Error\ErrorsManager;
  24612. use PhpCsFixer\FileReader;
  24613. use PhpCsFixer\Fixer\FixerInterface;
  24614. use PhpCsFixer\FixerFileProcessedEvent;
  24615. use PhpCsFixer\Linter\LinterInterface;
  24616. use PhpCsFixer\Linter\LintingException;
  24617. use PhpCsFixer\Linter\LintingResultInterface;
  24618. use PhpCsFixer\Tokenizer\Tokens;
  24619. use Symfony\Component\EventDispatcher\Event;
  24620. use Symfony\Component\EventDispatcher\EventDispatcher;
  24621. use Symfony\Component\Filesystem\Exception\IOException;
  24622. final class Runner
  24623. {
  24624. private $differ;
  24625. private $directory;
  24626. private $eventDispatcher;
  24627. private $errorsManager;
  24628. private $cacheManager;
  24629. private $isDryRun;
  24630. private $linter;
  24631. private $finder;
  24632. private $fixers;
  24633. private $stopOnViolation;
  24634. public function __construct(
  24635. $finder,
  24636. array $fixers,
  24637. DifferInterface $differ,
  24638. EventDispatcher $eventDispatcher = null,
  24639. ErrorsManager $errorsManager,
  24640. LinterInterface $linter,
  24641. $isDryRun,
  24642. CacheManagerInterface $cacheManager,
  24643. DirectoryInterface $directory = null,
  24644. $stopOnViolation = false
  24645. ) {
  24646. $this->finder = $finder;
  24647. $this->fixers = $fixers;
  24648. $this->differ = $differ;
  24649. $this->eventDispatcher = $eventDispatcher;
  24650. $this->errorsManager = $errorsManager;
  24651. $this->linter = $linter;
  24652. $this->isDryRun = $isDryRun;
  24653. $this->cacheManager = $cacheManager;
  24654. $this->directory = $directory ?: new Directory('');
  24655. $this->stopOnViolation = $stopOnViolation;
  24656. }
  24657. public function fix()
  24658. {
  24659. $changed = [];
  24660. $finder = $this->finder;
  24661. $finderIterator = $finder instanceof \IteratorAggregate ? $finder->getIterator() : $finder;
  24662. $fileFilteredFileIterator = new FileFilterIterator(
  24663. $finderIterator,
  24664. $this->eventDispatcher,
  24665. $this->cacheManager
  24666. );
  24667. $collection = $this->linter->isAsync()
  24668. ? new FileCachingLintingIterator($fileFilteredFileIterator, $this->linter)
  24669. : new FileLintingIterator($fileFilteredFileIterator, $this->linter);
  24670. foreach ($collection as $file) {
  24671. $fixInfo = $this->fixFile($file, $collection->currentLintingResult());
  24672. Tokens::clearCache();
  24673. if ($fixInfo) {
  24674. $name = $this->directory->getRelativePathTo($file);
  24675. $changed[$name] = $fixInfo;
  24676. if ($this->stopOnViolation) {
  24677. break;
  24678. }
  24679. }
  24680. }
  24681. return $changed;
  24682. }
  24683. private function fixFile(\SplFileInfo $file, LintingResultInterface $lintingResult)
  24684. {
  24685. $name = $file->getPathname();
  24686. try {
  24687. $lintingResult->check();
  24688. } catch (LintingException $e) {
  24689. $this->dispatchEvent(
  24690. FixerFileProcessedEvent::NAME,
  24691. new FixerFileProcessedEvent(FixerFileProcessedEvent::STATUS_INVALID)
  24692. );
  24693. $this->errorsManager->report(new Error(Error::TYPE_INVALID, $name, $e));
  24694. return;
  24695. }
  24696. $old = FileReader::createSingleton()->read($file->getRealPath());
  24697. Tokens::setLegacyMode(false);
  24698. $tokens = Tokens::fromCode($old);
  24699. $oldHash = $tokens->getCodeHash();
  24700. $newHash = $oldHash;
  24701. $new = $old;
  24702. $appliedFixers = [];
  24703. try {
  24704. foreach ($this->fixers as $fixer) {
  24705. if (
  24706. !$fixer instanceof AbstractFixer &&
  24707. (!$fixer->supports($file) || !$fixer->isCandidate($tokens))
  24708. ) {
  24709. continue;
  24710. }
  24711. $fixer->fix($file, $tokens);
  24712. if ($tokens->isChanged()) {
  24713. $tokens->clearEmptyTokens();
  24714. $tokens->clearChanged();
  24715. $appliedFixers[] = $fixer->getName();
  24716. }
  24717. }
  24718. } catch (\Exception $e) {
  24719. $this->processException($name, $e);
  24720. return;
  24721. } catch (\ParseError $e) {
  24722. $this->dispatchEvent(
  24723. FixerFileProcessedEvent::NAME,
  24724. new FixerFileProcessedEvent(FixerFileProcessedEvent::STATUS_LINT)
  24725. );
  24726. $this->errorsManager->report(new Error(Error::TYPE_LINT, $name, $e));
  24727. return;
  24728. } catch (\Throwable $e) {
  24729. $this->processException($name, $e);
  24730. return;
  24731. }
  24732. $fixInfo = null;
  24733. if (!empty($appliedFixers)) {
  24734. $new = $tokens->generateCode();
  24735. $newHash = $tokens->getCodeHash();
  24736. }
  24737. if ($oldHash !== $newHash) {
  24738. try {
  24739. $this->linter->lintSource($new)->check();
  24740. } catch (LintingException $e) {
  24741. $this->dispatchEvent(
  24742. FixerFileProcessedEvent::NAME,
  24743. new FixerFileProcessedEvent(FixerFileProcessedEvent::STATUS_LINT)
  24744. );
  24745. $this->errorsManager->report(new Error(Error::TYPE_LINT, $name, $e));
  24746. return;
  24747. }
  24748. if (!$this->isDryRun) {
  24749. if (false === @file_put_contents($file->getRealPath(), $new)) {
  24750. $error = error_get_last();
  24751. throw new IOException(
  24752. sprintf('Failed to write file "%s", "%s".', $file->getPathname(), $error ? $error['message'] : 'no reason available'),
  24753. 0,
  24754. null,
  24755. $file->getRealPath()
  24756. );
  24757. }
  24758. }
  24759. $fixInfo = [
  24760. 'appliedFixers' => $appliedFixers,
  24761. 'diff' => $this->differ->diff($old, $new),
  24762. ];
  24763. }
  24764. $this->cacheManager->setFile($name, $new);
  24765. $this->dispatchEvent(
  24766. FixerFileProcessedEvent::NAME,
  24767. new FixerFileProcessedEvent($fixInfo ? FixerFileProcessedEvent::STATUS_FIXED : FixerFileProcessedEvent::STATUS_NO_CHANGES)
  24768. );
  24769. return $fixInfo;
  24770. }
  24771. private function processException($name, $e)
  24772. {
  24773. $this->dispatchEvent(
  24774. FixerFileProcessedEvent::NAME,
  24775. new FixerFileProcessedEvent(FixerFileProcessedEvent::STATUS_EXCEPTION)
  24776. );
  24777. $this->errorsManager->report(new Error(Error::TYPE_EXCEPTION, $name, $e));
  24778. }
  24779. private function dispatchEvent($name, Event $event)
  24780. {
  24781. if (null === $this->eventDispatcher) {
  24782. return;
  24783. }
  24784. $this->eventDispatcher->dispatch($name, $event);
  24785. }
  24786. }
  24787. <?php
  24788. namespace PhpCsFixer;
  24789. final class StdinFileInfo extends \SplFileInfo
  24790. {
  24791. public function __construct()
  24792. {
  24793. }
  24794. public function __toString()
  24795. {
  24796. return $this->getRealPath();
  24797. }
  24798. public function getRealPath()
  24799. {
  24800. return 'php://stdin';
  24801. }
  24802. public function getATime()
  24803. {
  24804. return 0;
  24805. }
  24806. public function getBasename($suffix = null)
  24807. {
  24808. return $this->getFilename();
  24809. }
  24810. public function getCTime()
  24811. {
  24812. return 0;
  24813. }
  24814. public function getExtension()
  24815. {
  24816. return '.php';
  24817. }
  24818. public function getFileInfo($className = null)
  24819. {
  24820. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  24821. }
  24822. public function getFilename()
  24823. {
  24824. return 'stdin.php';
  24825. }
  24826. public function getGroup()
  24827. {
  24828. return 0;
  24829. }
  24830. public function getInode()
  24831. {
  24832. return 0;
  24833. }
  24834. public function getLinkTarget()
  24835. {
  24836. return '';
  24837. }
  24838. public function getMTime()
  24839. {
  24840. return 0;
  24841. }
  24842. public function getOwner()
  24843. {
  24844. return 0;
  24845. }
  24846. public function getPath()
  24847. {
  24848. return '';
  24849. }
  24850. public function getPathInfo($className = null)
  24851. {
  24852. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  24853. }
  24854. public function getPathname()
  24855. {
  24856. return $this->getFilename();
  24857. }
  24858. public function getPerms()
  24859. {
  24860. return 0;
  24861. }
  24862. public function getSize()
  24863. {
  24864. return 0;
  24865. }
  24866. public function getType()
  24867. {
  24868. return 'file';
  24869. }
  24870. public function isDir()
  24871. {
  24872. return false;
  24873. }
  24874. public function isExecutable()
  24875. {
  24876. return false;
  24877. }
  24878. public function isFile()
  24879. {
  24880. return true;
  24881. }
  24882. public function isLink()
  24883. {
  24884. return false;
  24885. }
  24886. public function isReadable()
  24887. {
  24888. return true;
  24889. }
  24890. public function isWritable()
  24891. {
  24892. return false;
  24893. }
  24894. public function openFile($openMode = 'r', $useIncludePath = false, $context = null)
  24895. {
  24896. throw new \BadMethodCallException(sprintf('Method "%s" is not implemented.', __METHOD__));
  24897. }
  24898. public function setFileClass($className = null)
  24899. {
  24900. }
  24901. public function setInfoClass($className = null)
  24902. {
  24903. }
  24904. }
  24905. <?php
  24906. namespace PhpCsFixer\Tokenizer;
  24907. use PhpCsFixer\Utils;
  24908. abstract class AbstractTransformer implements TransformerInterface
  24909. {
  24910. public function getName()
  24911. {
  24912. $nameParts = explode('\\', get_called_class());
  24913. $name = substr(end($nameParts), 0, -strlen('Transformer'));
  24914. return Utils::camelCaseToUnderscore($name);
  24915. }
  24916. public function getPriority()
  24917. {
  24918. return 0;
  24919. }
  24920. }
  24921. <?php
  24922. namespace PhpCsFixer\Tokenizer\Analyzer;
  24923. use PhpCsFixer\Tokenizer\Tokens;
  24924. final class ArgumentsAnalyzer
  24925. {
  24926. public function countArguments(Tokens $tokens, $openParenthesis, $closeParenthesis)
  24927. {
  24928. return count($this->getArguments($tokens, $openParenthesis, $closeParenthesis));
  24929. }
  24930. public function getArguments(Tokens $tokens, $openParenthesis, $closeParenthesis)
  24931. {
  24932. $arguments = [];
  24933. $firstSensibleToken = $tokens->getNextMeaningfulToken($openParenthesis);
  24934. if ($tokens[$firstSensibleToken]->equals(')')) {
  24935. return $arguments;
  24936. }
  24937. $paramContentIndex = $openParenthesis + 1;
  24938. $argumentsStart = $paramContentIndex;
  24939. for (; $paramContentIndex < $closeParenthesis; ++$paramContentIndex) {
  24940. $token = $tokens[$paramContentIndex];
  24941. $blockDefinitionProbe = Tokens::detectBlockType($token);
  24942. if (null !== $blockDefinitionProbe && true === $blockDefinitionProbe['isStart']) {
  24943. $paramContentIndex = $tokens->findBlockEnd($blockDefinitionProbe['type'], $paramContentIndex);
  24944. continue;
  24945. }
  24946. if ($token->equals(',')) {
  24947. $arguments[$argumentsStart] = $paramContentIndex - 1;
  24948. $argumentsStart = $paramContentIndex + 1;
  24949. }
  24950. }
  24951. $arguments[$argumentsStart] = $paramContentIndex - 1;
  24952. return $arguments;
  24953. }
  24954. }
  24955. <?php
  24956. namespace PhpCsFixer\Tokenizer;
  24957. final class CT
  24958. {
  24959. const T_ARRAY_INDEX_CURLY_BRACE_CLOSE = 10001;
  24960. const T_ARRAY_INDEX_CURLY_BRACE_OPEN = 10002;
  24961. const T_ARRAY_SQUARE_BRACE_CLOSE = 10003;
  24962. const T_ARRAY_SQUARE_BRACE_OPEN = 10004;
  24963. const T_ARRAY_TYPEHINT = 10005;
  24964. const T_BRACE_CLASS_INSTANTIATION_CLOSE = 10006;
  24965. const T_BRACE_CLASS_INSTANTIATION_OPEN = 10007;
  24966. const T_CLASS_CONSTANT = 10008;
  24967. const T_CONST_IMPORT = 10009;
  24968. const T_CURLY_CLOSE = 10010;
  24969. const T_DESTRUCTURING_SQUARE_BRACE_CLOSE = 10011;
  24970. const T_DESTRUCTURING_SQUARE_BRACE_OPEN = 10012;
  24971. const T_DOLLAR_CLOSE_CURLY_BRACES = 10013;
  24972. const T_DYNAMIC_PROP_BRACE_CLOSE = 10014;
  24973. const T_DYNAMIC_PROP_BRACE_OPEN = 10015;
  24974. const T_DYNAMIC_VAR_BRACE_CLOSE = 10016;
  24975. const T_DYNAMIC_VAR_BRACE_OPEN = 10017;
  24976. const T_FUNCTION_IMPORT = 10018;
  24977. const T_GROUP_IMPORT_BRACE_CLOSE = 10019;
  24978. const T_GROUP_IMPORT_BRACE_OPEN = 10020;
  24979. const T_NAMESPACE_OPERATOR = 10021;
  24980. const T_NULLABLE_TYPE = 10022;
  24981. const T_RETURN_REF = 10023;
  24982. const T_TYPE_ALTERNATION = 10024;
  24983. const T_TYPE_COLON = 10025;
  24984. const T_USE_LAMBDA = 10026;
  24985. const T_USE_TRAIT = 10027;
  24986. private function __construct()
  24987. {
  24988. }
  24989. public static function getName($value)
  24990. {
  24991. if (!self::has($value)) {
  24992. throw new \InvalidArgumentException(sprintf('No custom token was found for "%s".', $value));
  24993. }
  24994. $tokens = self::getMapById();
  24995. return 'CT::'.$tokens[$value];
  24996. }
  24997. public static function has($value)
  24998. {
  24999. $tokens = self::getMapById();
  25000. return isset($tokens[$value]);
  25001. }
  25002. private static function getMapById()
  25003. {
  25004. static $constants;
  25005. if (null === $constants) {
  25006. $reflection = new \ReflectionClass(__CLASS__);
  25007. $constants = array_flip($reflection->getConstants());
  25008. }
  25009. return $constants;
  25010. }
  25011. }
  25012. <?php
  25013. namespace PhpCsFixer\Tokenizer;
  25014. final class CodeHasher
  25015. {
  25016. private function __construct()
  25017. {
  25018. }
  25019. public static function calculateCodeHash($code)
  25020. {
  25021. return (string) crc32($code);
  25022. }
  25023. }
  25024. <?php
  25025. namespace PhpCsFixer\Tokenizer;
  25026. use PhpCsFixer\Utils;
  25027. class Token
  25028. {
  25029. private $content;
  25030. private $id;
  25031. private $isArray;
  25032. private $changed = false;
  25033. public function __construct($token)
  25034. {
  25035. if (is_array($token)) {
  25036. if (!is_int($token[0])) {
  25037. throw new \InvalidArgumentException(sprintf(
  25038. 'Id must be an int, got "%s".',
  25039. is_object($token[0]) ? get_class($token[0]) : gettype($token[0])
  25040. ));
  25041. }
  25042. if (!is_string($token[1])) {
  25043. throw new \InvalidArgumentException(sprintf(
  25044. 'Content must be a string, got "%s".',
  25045. is_object($token[1]) ? get_class($token[1]) : gettype($token[1])
  25046. ));
  25047. }
  25048. if ('' === $token[1]) {
  25049. throw new \InvalidArgumentException('Cannot set empty content for id-based Token.');
  25050. }
  25051. $this->isArray = true;
  25052. $this->id = $token[0];
  25053. $this->content = $token[1];
  25054. if ($token[0] && '' === $token[1]) {
  25055. throw new \InvalidArgumentException('Cannot set empty content for id-based Token.');
  25056. }
  25057. } elseif (is_string($token)) {
  25058. $this->isArray = false;
  25059. $this->content = $token;
  25060. } else {
  25061. throw new \InvalidArgumentException(sprintf(
  25062. 'Cannot recognize input value as valid Token prototype, got "%s".',
  25063. is_object($token) ? get_class($token) : gettype($token)
  25064. ));
  25065. }
  25066. }
  25067. public static function getCastTokenKinds()
  25068. {
  25069. static $castTokens = [T_ARRAY_CAST, T_BOOL_CAST, T_DOUBLE_CAST, T_INT_CAST, T_OBJECT_CAST, T_STRING_CAST, T_UNSET_CAST];
  25070. return $castTokens;
  25071. }
  25072. public static function getClassyTokenKinds()
  25073. {
  25074. static $classTokens = [T_CLASS, T_TRAIT, T_INTERFACE];
  25075. return $classTokens;
  25076. }
  25077. public function clear()
  25078. {
  25079. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  25080. Tokens::setLegacyMode(true);
  25081. $this->content = '';
  25082. $this->id = null;
  25083. $this->isArray = false;
  25084. }
  25085. public function clearChanged()
  25086. {
  25087. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  25088. Tokens::setLegacyMode(true);
  25089. $this->changed = false;
  25090. }
  25091. public function equals($other, $caseSensitive = true)
  25092. {
  25093. $otherPrototype = $other instanceof self ? $other->getPrototype() : $other;
  25094. if ($this->isArray !== is_array($otherPrototype)) {
  25095. return false;
  25096. }
  25097. if (!$this->isArray) {
  25098. return $this->content === $otherPrototype;
  25099. }
  25100. if (array_key_exists(0, $otherPrototype) && $this->id !== $otherPrototype[0]) {
  25101. return false;
  25102. }
  25103. if (array_key_exists(1, $otherPrototype)) {
  25104. if ($caseSensitive) {
  25105. if ($this->content !== $otherPrototype[1]) {
  25106. return false;
  25107. }
  25108. } elseif (0 !== strcasecmp($this->content, $otherPrototype[1])) {
  25109. return false;
  25110. }
  25111. }
  25112. unset($otherPrototype[0], $otherPrototype[1]);
  25113. return empty($otherPrototype);
  25114. }
  25115. public function equalsAny(array $others, $caseSensitive = true)
  25116. {
  25117. foreach ($others as $other) {
  25118. if ($this->equals($other, $caseSensitive)) {
  25119. return true;
  25120. }
  25121. }
  25122. return false;
  25123. }
  25124. public static function isKeyCaseSensitive($caseSensitive, $key)
  25125. {
  25126. if (is_array($caseSensitive)) {
  25127. return isset($caseSensitive[$key]) ? $caseSensitive[$key] : true;
  25128. }
  25129. return $caseSensitive;
  25130. }
  25131. public function getPrototype()
  25132. {
  25133. if (!$this->isArray) {
  25134. return $this->content;
  25135. }
  25136. return [
  25137. $this->id,
  25138. $this->content,
  25139. ];
  25140. }
  25141. public function getContent()
  25142. {
  25143. return $this->content;
  25144. }
  25145. public function getId()
  25146. {
  25147. return $this->id;
  25148. }
  25149. public function getName()
  25150. {
  25151. if (null === $this->id) {
  25152. return null;
  25153. }
  25154. return self::getNameForId($this->id);
  25155. }
  25156. public static function getNameForId($id)
  25157. {
  25158. if (CT::has($id)) {
  25159. return CT::getName($id);
  25160. }
  25161. $name = token_name($id);
  25162. return 'UNKNOWN' === $name ? null : $name;
  25163. }
  25164. public static function getKeywords()
  25165. {
  25166. static $keywords = null;
  25167. if (null === $keywords) {
  25168. $keywords = self::getTokenKindsForNames(['T_ABSTRACT', 'T_ARRAY', 'T_AS', 'T_BREAK', 'T_CALLABLE', 'T_CASE',
  25169. 'T_CATCH', 'T_CLASS', 'T_CLONE', 'T_CONST', 'T_CONTINUE', 'T_DECLARE', 'T_DEFAULT', 'T_DO',
  25170. 'T_ECHO', 'T_ELSE', 'T_ELSEIF', 'T_EMPTY', 'T_ENDDECLARE', 'T_ENDFOR', 'T_ENDFOREACH',
  25171. 'T_ENDIF', 'T_ENDSWITCH', 'T_ENDWHILE', 'T_EVAL', 'T_EXIT', 'T_EXTENDS', 'T_FINAL',
  25172. 'T_FINALLY', 'T_FOR', 'T_FOREACH', 'T_FUNCTION', 'T_GLOBAL', 'T_GOTO', 'T_HALT_COMPILER',
  25173. 'T_IF', 'T_IMPLEMENTS', 'T_INCLUDE', 'T_INCLUDE_ONCE', 'T_INSTANCEOF', 'T_INSTEADOF',
  25174. 'T_INTERFACE', 'T_ISSET', 'T_LIST', 'T_LOGICAL_AND', 'T_LOGICAL_OR', 'T_LOGICAL_XOR',
  25175. 'T_NAMESPACE', 'T_NEW', 'T_PRINT', 'T_PRIVATE', 'T_PROTECTED', 'T_PUBLIC', 'T_REQUIRE',
  25176. 'T_REQUIRE_ONCE', 'T_RETURN', 'T_STATIC', 'T_SWITCH', 'T_THROW', 'T_TRAIT', 'T_TRY',
  25177. 'T_UNSET', 'T_USE', 'T_VAR', 'T_WHILE', 'T_YIELD',
  25178. ]) + [
  25179. CT::T_ARRAY_TYPEHINT => CT::T_ARRAY_TYPEHINT,
  25180. CT::T_CLASS_CONSTANT => CT::T_CLASS_CONSTANT,
  25181. CT::T_CONST_IMPORT => CT::T_CONST_IMPORT,
  25182. CT::T_FUNCTION_IMPORT => CT::T_FUNCTION_IMPORT,
  25183. CT::T_NAMESPACE_OPERATOR => CT::T_NAMESPACE_OPERATOR,
  25184. CT::T_USE_TRAIT => CT::T_USE_TRAIT,
  25185. CT::T_USE_LAMBDA => CT::T_USE_LAMBDA,
  25186. ];
  25187. }
  25188. return $keywords;
  25189. }
  25190. public static function getMagicConstants()
  25191. {
  25192. static $magicConstants = null;
  25193. if (null === $magicConstants) {
  25194. $magicConstants = self::getTokenKindsForNames(['T_CLASS_C', 'T_DIR', 'T_FILE', 'T_FUNC_C', 'T_LINE', 'T_METHOD_C', 'T_NS_C', 'T_TRAIT_C']);
  25195. }
  25196. return $magicConstants;
  25197. }
  25198. public function isArray()
  25199. {
  25200. return $this->isArray;
  25201. }
  25202. public function isCast()
  25203. {
  25204. return $this->isGivenKind(self::getCastTokenKinds());
  25205. }
  25206. public function isChanged()
  25207. {
  25208. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  25209. return $this->changed;
  25210. }
  25211. public function isClassy()
  25212. {
  25213. return $this->isGivenKind(self::getClassyTokenKinds());
  25214. }
  25215. public function isComment()
  25216. {
  25217. static $commentTokens = [T_COMMENT, T_DOC_COMMENT];
  25218. return $this->isGivenKind($commentTokens);
  25219. }
  25220. public function isEmpty()
  25221. {
  25222. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  25223. return null === $this->id && ('' === $this->content || null === $this->content);
  25224. }
  25225. public function isGivenKind($possibleKind)
  25226. {
  25227. return $this->isArray && (is_array($possibleKind) ? in_array($this->id, $possibleKind, true) : $this->id === $possibleKind);
  25228. }
  25229. public function isKeyword()
  25230. {
  25231. $keywords = static::getKeywords();
  25232. return $this->isArray && isset($keywords[$this->id]);
  25233. }
  25234. public function isNativeConstant()
  25235. {
  25236. static $nativeConstantStrings = ['true', 'false', 'null'];
  25237. return $this->isArray && in_array(strtolower($this->content), $nativeConstantStrings, true);
  25238. }
  25239. public function isMagicConstant()
  25240. {
  25241. $magicConstants = static::getMagicConstants();
  25242. return $this->isArray && isset($magicConstants[$this->id]);
  25243. }
  25244. public function isWhitespace($whitespaces = " \t\n\r\0\x0B")
  25245. {
  25246. if (null === $whitespaces) {
  25247. $whitespaces = " \t\n\r\0\x0B";
  25248. }
  25249. if ($this->isArray && !$this->isGivenKind(T_WHITESPACE)) {
  25250. return false;
  25251. }
  25252. return '' === trim($this->content, $whitespaces);
  25253. }
  25254. public function override($other)
  25255. {
  25256. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  25257. Tokens::setLegacyMode(true);
  25258. $prototype = $other instanceof self ? $other->getPrototype() : $other;
  25259. if ($this->equals($prototype)) {
  25260. return;
  25261. }
  25262. $this->changed = true;
  25263. if (is_array($prototype)) {
  25264. $this->isArray = true;
  25265. $this->id = $prototype[0];
  25266. $this->content = $prototype[1];
  25267. return;
  25268. }
  25269. $this->isArray = false;
  25270. $this->id = null;
  25271. $this->content = $prototype;
  25272. }
  25273. public function setContent($content)
  25274. {
  25275. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0.', E_USER_DEPRECATED);
  25276. Tokens::setLegacyMode(true);
  25277. if ($this->content === $content) {
  25278. return;
  25279. }
  25280. $this->changed = true;
  25281. $this->content = $content;
  25282. if ('' === $content) {
  25283. @trigger_error(__METHOD__.' shall not be used to clear token, use Tokens::clearAt instead.', E_USER_DEPRECATED);
  25284. $this->id = null;
  25285. $this->isArray = false;
  25286. }
  25287. }
  25288. public function toArray()
  25289. {
  25290. return [
  25291. 'id' => $this->id,
  25292. 'name' => $this->getName(),
  25293. 'content' => $this->content,
  25294. 'isArray' => $this->isArray,
  25295. 'changed' => $this->changed,
  25296. ];
  25297. }
  25298. public function toJson(array $options = null)
  25299. {
  25300. static $defaultOptions = null;
  25301. if (null === $options) {
  25302. if (null === $defaultOptions) {
  25303. $defaultOptions = Utils::calculateBitmask(['JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK']);
  25304. }
  25305. $options = $defaultOptions;
  25306. } else {
  25307. $options = Utils::calculateBitmask($options);
  25308. }
  25309. return json_encode($this->toArray(), $options);
  25310. }
  25311. private static function getTokenKindsForNames(array $tokenNames)
  25312. {
  25313. $keywords = [];
  25314. foreach ($tokenNames as $keywordName) {
  25315. if (defined($keywordName)) {
  25316. $keyword = constant($keywordName);
  25317. $keywords[$keyword] = $keyword;
  25318. }
  25319. }
  25320. return $keywords;
  25321. }
  25322. }
  25323. <?php
  25324. namespace PhpCsFixer\Tokenizer;
  25325. use PhpCsFixer\Utils;
  25326. class Tokens extends \SplFixedArray
  25327. {
  25328. const BLOCK_TYPE_PARENTHESIS_BRACE = 1;
  25329. const BLOCK_TYPE_CURLY_BRACE = 2;
  25330. const BLOCK_TYPE_INDEX_SQUARE_BRACE = 3;
  25331. const BLOCK_TYPE_ARRAY_SQUARE_BRACE = 4;
  25332. const BLOCK_TYPE_DYNAMIC_PROP_BRACE = 5;
  25333. const BLOCK_TYPE_DYNAMIC_VAR_BRACE = 6;
  25334. const BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE = 7;
  25335. const BLOCK_TYPE_GROUP_IMPORT_BRACE = 8;
  25336. const BLOCK_TYPE_DESTRUCTURING_SQUARE_BRACE = 9;
  25337. const BLOCK_TYPE_BRACE_CLASS_INSTANTIATION = 10;
  25338. private static $cache = [];
  25339. private $blockEndCache = [];
  25340. private $codeHash;
  25341. private $changed = false;
  25342. private $foundTokenKinds = [];
  25343. private static $isLegacyMode = false;
  25344. public function __clone()
  25345. {
  25346. foreach ($this as $key => $val) {
  25347. $this[$key] = clone $val;
  25348. }
  25349. }
  25350. public static function isLegacyMode()
  25351. {
  25352. return self::$isLegacyMode;
  25353. }
  25354. public static function setLegacyMode($isLegacy)
  25355. {
  25356. if (getenv('PHP_CS_FIXER_FUTURE_MODE') && $isLegacy) {
  25357. throw new \RuntimeException('Cannot enable `legacy mode` when using `future mode`. This check was performed as `PHP_CS_FIXER_FUTURE_MODE` env var is set.');
  25358. }
  25359. self::$isLegacyMode = $isLegacy;
  25360. }
  25361. public static function clearCache($key = null)
  25362. {
  25363. if (null === $key) {
  25364. self::$cache = [];
  25365. return;
  25366. }
  25367. if (self::hasCache($key)) {
  25368. unset(self::$cache[$key]);
  25369. }
  25370. }
  25371. public static function detectBlockType(Token $token)
  25372. {
  25373. foreach (self::getBlockEdgeDefinitions() as $type => $definition) {
  25374. if ($token->equals($definition['start'])) {
  25375. return ['type' => $type, 'isStart' => true];
  25376. }
  25377. if ($token->equals($definition['end'])) {
  25378. return ['type' => $type, 'isStart' => false];
  25379. }
  25380. }
  25381. }
  25382. public static function fromArray($array, $saveIndexes = null)
  25383. {
  25384. $tokens = new self(count($array));
  25385. if (null === $saveIndexes || $saveIndexes) {
  25386. foreach ($array as $key => $val) {
  25387. $tokens[$key] = $val;
  25388. }
  25389. } else {
  25390. $index = 0;
  25391. foreach ($array as $val) {
  25392. $tokens[$index++] = $val;
  25393. }
  25394. }
  25395. $tokens->generateCode();
  25396. return $tokens;
  25397. }
  25398. public static function fromCode($code)
  25399. {
  25400. $codeHash = self::calculateCodeHash($code);
  25401. if (self::hasCache($codeHash)) {
  25402. $tokens = self::getCache($codeHash);
  25403. $tokens->generateCode();
  25404. if ($codeHash === $tokens->codeHash) {
  25405. $tokens->clearEmptyTokens();
  25406. $tokens->clearChanged();
  25407. return $tokens;
  25408. }
  25409. }
  25410. $tokens = new self();
  25411. $tokens->setCode($code);
  25412. $tokens->clearChanged();
  25413. return $tokens;
  25414. }
  25415. public static function getBlockEdgeDefinitions()
  25416. {
  25417. return [
  25418. self::BLOCK_TYPE_CURLY_BRACE => [
  25419. 'start' => '{',
  25420. 'end' => '}',
  25421. ],
  25422. self::BLOCK_TYPE_PARENTHESIS_BRACE => [
  25423. 'start' => '(',
  25424. 'end' => ')',
  25425. ],
  25426. self::BLOCK_TYPE_INDEX_SQUARE_BRACE => [
  25427. 'start' => '[',
  25428. 'end' => ']',
  25429. ],
  25430. self::BLOCK_TYPE_ARRAY_SQUARE_BRACE => [
  25431. 'start' => [CT::T_ARRAY_SQUARE_BRACE_OPEN, '['],
  25432. 'end' => [CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']'],
  25433. ],
  25434. self::BLOCK_TYPE_DYNAMIC_PROP_BRACE => [
  25435. 'start' => [CT::T_DYNAMIC_PROP_BRACE_OPEN, '{'],
  25436. 'end' => [CT::T_DYNAMIC_PROP_BRACE_CLOSE, '}'],
  25437. ],
  25438. self::BLOCK_TYPE_DYNAMIC_VAR_BRACE => [
  25439. 'start' => [CT::T_DYNAMIC_VAR_BRACE_OPEN, '{'],
  25440. 'end' => [CT::T_DYNAMIC_VAR_BRACE_CLOSE, '}'],
  25441. ],
  25442. self::BLOCK_TYPE_ARRAY_INDEX_CURLY_BRACE => [
  25443. 'start' => [CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN, '{'],
  25444. 'end' => [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE, '}'],
  25445. ],
  25446. self::BLOCK_TYPE_GROUP_IMPORT_BRACE => [
  25447. 'start' => [CT::T_GROUP_IMPORT_BRACE_OPEN, '{'],
  25448. 'end' => [CT::T_GROUP_IMPORT_BRACE_CLOSE, '}'],
  25449. ],
  25450. self::BLOCK_TYPE_DESTRUCTURING_SQUARE_BRACE => [
  25451. 'start' => [CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '['],
  25452. 'end' => [CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']'],
  25453. ],
  25454. self::BLOCK_TYPE_BRACE_CLASS_INSTANTIATION => [
  25455. 'start' => [CT::T_BRACE_CLASS_INSTANTIATION_OPEN, '('],
  25456. 'end' => [CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, ')'],
  25457. ],
  25458. ];
  25459. }
  25460. public function setSize($size)
  25461. {
  25462. if ($this->getSize() !== $size) {
  25463. $this->changed = true;
  25464. parent::setSize($size);
  25465. }
  25466. }
  25467. public function offsetUnset($index)
  25468. {
  25469. $this->changed = true;
  25470. $this->unregisterFoundToken($this[$index]);
  25471. parent::offsetUnset($index);
  25472. }
  25473. public function offsetSet($index, $newval)
  25474. {
  25475. $this->blockEndCache = [];
  25476. if (!$this[$index] || !$this[$index]->equals($newval)) {
  25477. $this->changed = true;
  25478. }
  25479. if (isset($this[$index])) {
  25480. $this->unregisterFoundToken($this[$index]);
  25481. }
  25482. $this->registerFoundToken($newval);
  25483. parent::offsetSet($index, $newval);
  25484. }
  25485. public function clearChanged()
  25486. {
  25487. $this->changed = false;
  25488. if (self::isLegacyMode()) {
  25489. foreach ($this as $token) {
  25490. $token->clearChanged();
  25491. }
  25492. }
  25493. }
  25494. public function clearEmptyTokens()
  25495. {
  25496. $limit = $this->count();
  25497. $index = 0;
  25498. for (; $index < $limit; ++$index) {
  25499. if ($this->isEmptyAt($index)) {
  25500. break;
  25501. }
  25502. }
  25503. if ($limit === $index) {
  25504. return;
  25505. }
  25506. for ($count = $index; $index < $limit; ++$index) {
  25507. if (!$this->isEmptyAt($index)) {
  25508. $this[$count++] = $this[$index];
  25509. }
  25510. }
  25511. $this->setSize($count);
  25512. }
  25513. public function ensureWhitespaceAtIndex($index, $indexOffset, $whitespace)
  25514. {
  25515. $removeLastCommentLine = static function (self $tokens, $index, $indexOffset, $whitespace) {
  25516. $token = $tokens[$index];
  25517. if (1 === $indexOffset && $token->isGivenKind(T_OPEN_TAG)) {
  25518. if (0 === strpos($whitespace, "\r\n")) {
  25519. $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent())."\r\n"]);
  25520. return strlen($whitespace) > 2
  25521. ? substr($whitespace, 2)
  25522. : ''
  25523. ;
  25524. }
  25525. $tokens[$index] = new Token([T_OPEN_TAG, rtrim($token->getContent()).$whitespace[0]]);
  25526. return strlen($whitespace) > 1
  25527. ? substr($whitespace, 1)
  25528. : ''
  25529. ;
  25530. }
  25531. return $whitespace;
  25532. };
  25533. if ($this[$index]->isWhitespace()) {
  25534. $whitespace = $removeLastCommentLine($this, $index - 1, $indexOffset, $whitespace);
  25535. if ('' === $whitespace) {
  25536. $this->clearAt($index);
  25537. } else {
  25538. $this[$index] = new Token([T_WHITESPACE, $whitespace]);
  25539. }
  25540. return false;
  25541. }
  25542. $whitespace = $removeLastCommentLine($this, $index, $indexOffset, $whitespace);
  25543. if ('' === $whitespace) {
  25544. return false;
  25545. }
  25546. $this->insertAt(
  25547. $index + $indexOffset,
  25548. [
  25549. new Token([T_WHITESPACE, $whitespace]),
  25550. ]
  25551. );
  25552. return true;
  25553. }
  25554. public function findBlockEnd($type, $searchIndex, $findEnd = true)
  25555. {
  25556. $blockEdgeDefinitions = self::getBlockEdgeDefinitions();
  25557. if (!isset($blockEdgeDefinitions[$type])) {
  25558. throw new \InvalidArgumentException(sprintf('Invalid param type: %s.', $type));
  25559. }
  25560. if (!self::isLegacyMode() && isset($this->blockEndCache[$searchIndex])) {
  25561. return $this->blockEndCache[$searchIndex];
  25562. }
  25563. $startEdge = $blockEdgeDefinitions[$type]['start'];
  25564. $endEdge = $blockEdgeDefinitions[$type]['end'];
  25565. $startIndex = $searchIndex;
  25566. $endIndex = $this->count() - 1;
  25567. $indexOffset = 1;
  25568. if (!$findEnd) {
  25569. list($startEdge, $endEdge) = [$endEdge, $startEdge];
  25570. $indexOffset = -1;
  25571. $endIndex = 0;
  25572. }
  25573. if (!$this[$startIndex]->equals($startEdge)) {
  25574. throw new \InvalidArgumentException(sprintf('Invalid param $startIndex - not a proper block %s.', $findEnd ? 'start' : 'end'));
  25575. }
  25576. $blockLevel = 0;
  25577. for ($index = $startIndex; $index !== $endIndex; $index += $indexOffset) {
  25578. $token = $this[$index];
  25579. if ($token->equals($startEdge)) {
  25580. ++$blockLevel;
  25581. continue;
  25582. }
  25583. if ($token->equals($endEdge)) {
  25584. --$blockLevel;
  25585. if (0 === $blockLevel) {
  25586. break;
  25587. }
  25588. continue;
  25589. }
  25590. }
  25591. if (!$this[$index]->equals($endEdge)) {
  25592. throw new \UnexpectedValueException(sprintf('Missing block %s.', $findEnd ? 'end' : 'start'));
  25593. }
  25594. $this->blockEndCache[$startIndex] = $index;
  25595. $this->blockEndCache[$index] = $startIndex;
  25596. return $index;
  25597. }
  25598. public function findGivenKind($possibleKind, $start = 0, $end = null)
  25599. {
  25600. $this->rewind();
  25601. if (null === $end) {
  25602. $end = $this->count();
  25603. }
  25604. $elements = [];
  25605. $possibleKinds = (array) $possibleKind;
  25606. foreach ($possibleKinds as $kind) {
  25607. $elements[$kind] = [];
  25608. }
  25609. if (!self::isLegacyMode()) {
  25610. $possibleKinds = array_filter($possibleKinds, function ($kind) {
  25611. return $this->isTokenKindFound($kind);
  25612. });
  25613. }
  25614. if (count($possibleKinds)) {
  25615. for ($i = $start; $i < $end; ++$i) {
  25616. $token = $this[$i];
  25617. if ($token->isGivenKind($possibleKinds)) {
  25618. $elements[$token->getId()][$i] = $token;
  25619. }
  25620. }
  25621. }
  25622. return is_array($possibleKind) ? $elements : $elements[$possibleKind];
  25623. }
  25624. public function generateCode()
  25625. {
  25626. $code = $this->generatePartialCode(0, count($this) - 1);
  25627. $this->changeCodeHash(self::calculateCodeHash($code));
  25628. return $code;
  25629. }
  25630. public function generatePartialCode($start, $end)
  25631. {
  25632. $code = '';
  25633. for ($i = $start; $i <= $end; ++$i) {
  25634. $code .= $this[$i]->getContent();
  25635. }
  25636. return $code;
  25637. }
  25638. public function getCodeHash()
  25639. {
  25640. return $this->codeHash;
  25641. }
  25642. public function getNextNonWhitespace($index, $whitespaces = null)
  25643. {
  25644. return $this->getNonWhitespaceSibling($index, 1, $whitespaces);
  25645. }
  25646. public function getNextTokenOfKind($index, array $tokens = [], $caseSensitive = true)
  25647. {
  25648. return $this->getTokenOfKindSibling($index, 1, $tokens, $caseSensitive);
  25649. }
  25650. public function getNonWhitespaceSibling($index, $direction, $whitespaces = null)
  25651. {
  25652. while (true) {
  25653. $index += $direction;
  25654. if (!$this->offsetExists($index)) {
  25655. return null;
  25656. }
  25657. $token = $this[$index];
  25658. if (!$token->isWhitespace($whitespaces)) {
  25659. return $index;
  25660. }
  25661. }
  25662. }
  25663. public function getPrevNonWhitespace($index, $whitespaces = null)
  25664. {
  25665. return $this->getNonWhitespaceSibling($index, -1, $whitespaces);
  25666. }
  25667. public function getPrevTokenOfKind($index, array $tokens = [], $caseSensitive = true)
  25668. {
  25669. return $this->getTokenOfKindSibling($index, -1, $tokens, $caseSensitive);
  25670. }
  25671. public function getTokenOfKindSibling($index, $direction, array $tokens = [], $caseSensitive = true)
  25672. {
  25673. if (!self::isLegacyMode()) {
  25674. $tokens = array_filter($tokens, function ($token) {
  25675. return $this->isTokenKindFound($this->extractTokenKind($token));
  25676. });
  25677. }
  25678. if (!count($tokens)) {
  25679. return null;
  25680. }
  25681. while (true) {
  25682. $index += $direction;
  25683. if (!$this->offsetExists($index)) {
  25684. return null;
  25685. }
  25686. $token = $this[$index];
  25687. if ($token->equalsAny($tokens, $caseSensitive)) {
  25688. return $index;
  25689. }
  25690. }
  25691. }
  25692. public function getTokenNotOfKindSibling($index, $direction, array $tokens = [])
  25693. {
  25694. while (true) {
  25695. $index += $direction;
  25696. if (!$this->offsetExists($index)) {
  25697. return null;
  25698. }
  25699. if ($this->isEmptyAt($index)) {
  25700. continue;
  25701. }
  25702. if ($this[$index]->equalsAny($tokens)) {
  25703. continue;
  25704. }
  25705. return $index;
  25706. }
  25707. }
  25708. public function getMeaningfulTokenSibling($index, $direction)
  25709. {
  25710. return $this->getTokenNotOfKindSibling(
  25711. $index,
  25712. $direction,
  25713. [[T_WHITESPACE], [T_COMMENT], [T_DOC_COMMENT]]
  25714. );
  25715. }
  25716. public function getNonEmptySibling($index, $direction)
  25717. {
  25718. while (true) {
  25719. $index += $direction;
  25720. if (!$this->offsetExists($index)) {
  25721. return null;
  25722. }
  25723. if (!$this->isEmptyAt($index)) {
  25724. return $index;
  25725. }
  25726. }
  25727. }
  25728. public function getNextMeaningfulToken($index)
  25729. {
  25730. return $this->getMeaningfulTokenSibling($index, 1);
  25731. }
  25732. public function getPrevMeaningfulToken($index)
  25733. {
  25734. return $this->getMeaningfulTokenSibling($index, -1);
  25735. }
  25736. public function findSequence(array $sequence, $start = 0, $end = null, $caseSensitive = true)
  25737. {
  25738. $sequenceCount = count($sequence);
  25739. if (0 === $sequenceCount) {
  25740. throw new \InvalidArgumentException('Invalid sequence.');
  25741. }
  25742. $end = null === $end ? count($this) - 1 : min($end, count($this) - 1);
  25743. if ($start + $sequenceCount - 1 > $end) {
  25744. return null;
  25745. }
  25746. foreach ($sequence as $key => $token) {
  25747. if (!$token instanceof Token) {
  25748. if (is_array($token) && !isset($token[1])) {
  25749. $token[1] = 'DUMMY';
  25750. }
  25751. $token = new Token($token);
  25752. }
  25753. if ($token->isWhitespace() || $token->isComment() || '' === $token->getContent()) {
  25754. throw new \InvalidArgumentException(sprintf('Non-meaningful token at position: %s.', $key));
  25755. }
  25756. }
  25757. if (!self::isLegacyMode()) {
  25758. foreach ($sequence as $token) {
  25759. if (!$this->isTokenKindFound($this->extractTokenKind($token))) {
  25760. return null;
  25761. }
  25762. }
  25763. }
  25764. $key = key($sequence);
  25765. $firstCs = Token::isKeyCaseSensitive($caseSensitive, $key);
  25766. $firstToken = $sequence[$key];
  25767. unset($sequence[$key]);
  25768. $index = $start - 1;
  25769. while (null !== $index && $index <= $end) {
  25770. $index = $this->getNextTokenOfKind($index, [$firstToken], $firstCs);
  25771. if (null === $index || $index > $end) {
  25772. return null;
  25773. }
  25774. $result = [$index => $this[$index]];
  25775. $currIdx = $index;
  25776. foreach ($sequence as $key => $token) {
  25777. $currIdx = $this->getNextMeaningfulToken($currIdx);
  25778. if (null === $currIdx || $currIdx > $end) {
  25779. return null;
  25780. }
  25781. if (!$this[$currIdx]->equals($token, Token::isKeyCaseSensitive($caseSensitive, $key))) {
  25782. continue 2;
  25783. }
  25784. $result[$currIdx] = $this[$currIdx];
  25785. }
  25786. if (count($sequence) < count($result)) {
  25787. return $result;
  25788. }
  25789. }
  25790. }
  25791. public function insertAt($index, $items)
  25792. {
  25793. $items = is_array($items) || $items instanceof self ? $items : [$items];
  25794. $itemsCnt = count($items);
  25795. if (0 === $itemsCnt) {
  25796. return;
  25797. }
  25798. $oldSize = count($this);
  25799. $this->changed = true;
  25800. $this->setSize($oldSize + $itemsCnt);
  25801. for ($i = $oldSize + $itemsCnt - 1; $i >= $index; --$i) {
  25802. $this[$i] = $this->offsetExists($i - $itemsCnt) ? $this[$i - $itemsCnt] : new Token('');
  25803. }
  25804. for ($i = 0; $i < $itemsCnt; ++$i) {
  25805. if ('' === $items[$i]->getContent()) {
  25806. throw new \InvalidArgumentException('Must not add empty token to collection.');
  25807. }
  25808. $this[$i + $index] = $items[$i];
  25809. }
  25810. }
  25811. public function isChanged()
  25812. {
  25813. if ($this->changed) {
  25814. return true;
  25815. }
  25816. if (self::isLegacyMode()) {
  25817. foreach ($this as $token) {
  25818. if ($token->isChanged()) {
  25819. return true;
  25820. }
  25821. }
  25822. }
  25823. return false;
  25824. }
  25825. public function isEmptyAt($index)
  25826. {
  25827. $token = $this[$index];
  25828. return null === $token->getId() && '' === $token->getContent();
  25829. }
  25830. public function clearAt($index)
  25831. {
  25832. $this[$index] = new Token('');
  25833. }
  25834. public function overrideAt($index, $token)
  25835. {
  25836. @trigger_error(__METHOD__.' is deprecated and will be removed in 3.0, use offsetSet instead.', E_USER_DEPRECATED);
  25837. self::$isLegacyMode = true;
  25838. $this[$index]->override($token);
  25839. $this->registerFoundToken($token);
  25840. }
  25841. public function overrideRange($indexStart, $indexEnd, $items)
  25842. {
  25843. $oldCode = $this->generatePartialCode($indexStart, $indexEnd);
  25844. $newCode = '';
  25845. foreach ($items as $item) {
  25846. $newCode .= $item->getContent();
  25847. }
  25848. if ($oldCode === $newCode) {
  25849. return;
  25850. }
  25851. $indexToChange = $indexEnd - $indexStart + 1;
  25852. $itemsCount = count($items);
  25853. if ($itemsCount > $indexToChange) {
  25854. $placeholders = [];
  25855. while ($itemsCount > $indexToChange) {
  25856. $placeholders[] = new Token('__PLACEHOLDER__');
  25857. ++$indexToChange;
  25858. }
  25859. $this->insertAt($indexEnd + 1, $placeholders);
  25860. }
  25861. foreach ($items as $itemIndex => $item) {
  25862. $this[$indexStart + $itemIndex] = $item;
  25863. }
  25864. if ($itemsCount < $indexToChange) {
  25865. $this->clearRange($indexStart + $itemsCount, $indexEnd);
  25866. }
  25867. }
  25868. public function removeLeadingWhitespace($index, $whitespaces = null)
  25869. {
  25870. if (isset($this[$index - 1]) && $this[$index - 1]->isWhitespace($whitespaces)) {
  25871. $this->clearAt($index - 1);
  25872. }
  25873. }
  25874. public function removeTrailingWhitespace($index, $whitespaces = null)
  25875. {
  25876. if (isset($this[$index + 1]) && $this[$index + 1]->isWhitespace($whitespaces)) {
  25877. $this->clearAt($index + 1);
  25878. }
  25879. }
  25880. public function setCode($code)
  25881. {
  25882. if ($code === $this->generateCode()) {
  25883. return;
  25884. }
  25885. $this->setSize(0);
  25886. $tokens = defined('TOKEN_PARSE')
  25887. ? token_get_all($code, TOKEN_PARSE)
  25888. : token_get_all($code);
  25889. $this->setSize(count($tokens));
  25890. foreach ($tokens as $index => $token) {
  25891. $this[$index] = new Token($token);
  25892. }
  25893. $transformers = Transformers::create();
  25894. $transformers->transform($this);
  25895. $this->foundTokenKinds = [];
  25896. foreach ($this as $index => $token) {
  25897. $this->registerFoundToken($token);
  25898. }
  25899. $this->rewind();
  25900. $this->changeCodeHash(self::calculateCodeHash($code));
  25901. $this->changed = true;
  25902. }
  25903. public function toJson()
  25904. {
  25905. static $options = null;
  25906. if (null === $options) {
  25907. $options = Utils::calculateBitmask(['JSON_PRETTY_PRINT', 'JSON_NUMERIC_CHECK']);
  25908. }
  25909. $output = new \SplFixedArray(count($this));
  25910. foreach ($this as $index => $token) {
  25911. $output[$index] = $token->toArray();
  25912. }
  25913. $this->rewind();
  25914. return json_encode($output, $options);
  25915. }
  25916. public function isAllTokenKindsFound(array $tokenKinds)
  25917. {
  25918. foreach ($tokenKinds as $tokenKind) {
  25919. if (empty($this->foundTokenKinds[$tokenKind])) {
  25920. return false;
  25921. }
  25922. }
  25923. return true;
  25924. }
  25925. public function isAnyTokenKindsFound(array $tokenKinds)
  25926. {
  25927. foreach ($tokenKinds as $tokenKind) {
  25928. if (!empty($this->foundTokenKinds[$tokenKind])) {
  25929. return true;
  25930. }
  25931. }
  25932. return false;
  25933. }
  25934. public function isTokenKindFound($tokenKind)
  25935. {
  25936. return !empty($this->foundTokenKinds[$tokenKind]);
  25937. }
  25938. public function countTokenKind($tokenKind)
  25939. {
  25940. if (self::isLegacyMode()) {
  25941. throw new \RuntimeException(sprintf('%s is not available in legacy mode.', __METHOD__));
  25942. }
  25943. return isset($this->foundTokenKinds[$tokenKind]) ? $this->foundTokenKinds[$tokenKind] : 0;
  25944. }
  25945. public function clearRange($indexStart, $indexEnd)
  25946. {
  25947. for ($i = $indexStart; $i <= $indexEnd; ++$i) {
  25948. $this->clearAt($i);
  25949. }
  25950. }
  25951. public function isMonolithicPhp()
  25952. {
  25953. $size = $this->count();
  25954. if (0 === $size) {
  25955. return false;
  25956. }
  25957. if (self::isLegacyMode()) {
  25958. if ($this[0]->isGivenKind(T_INLINE_HTML) || $this[$size - 1]->isGivenKind(T_INLINE_HTML)) {
  25959. return false;
  25960. }
  25961. for ($index = 1; $index < $size; ++$index) {
  25962. if ($this[$index]->isGivenKind([T_INLINE_HTML, T_OPEN_TAG, T_OPEN_TAG_WITH_ECHO])) {
  25963. return false;
  25964. }
  25965. }
  25966. return true;
  25967. }
  25968. if ($this->isTokenKindFound(T_INLINE_HTML)) {
  25969. return false;
  25970. }
  25971. return 1 >= ($this->countTokenKind(T_OPEN_TAG) + $this->countTokenKind(T_OPEN_TAG_WITH_ECHO));
  25972. }
  25973. public function isPartialCodeMultiline($start, $end)
  25974. {
  25975. for ($i = $start; $i <= $end; ++$i) {
  25976. if (false !== strpos($this[$i]->getContent(), "\n")) {
  25977. return true;
  25978. }
  25979. }
  25980. return false;
  25981. }
  25982. public function clearTokenAndMergeSurroundingWhitespace($index)
  25983. {
  25984. $count = count($this);
  25985. $this->clearAt($index);
  25986. if ($index === $count - 1) {
  25987. return;
  25988. }
  25989. $nextIndex = $this->getNonEmptySibling($index, 1);
  25990. if (null === $nextIndex || !$this[$nextIndex]->isWhitespace()) {
  25991. return;
  25992. }
  25993. $prevIndex = $this->getNonEmptySibling($index, -1);
  25994. if ($this[$prevIndex]->isWhitespace()) {
  25995. $this[$prevIndex] = new Token([T_WHITESPACE, $this[$prevIndex]->getContent().$this[$nextIndex]->getContent()]);
  25996. } elseif ($this->isEmptyAt($prevIndex + 1)) {
  25997. $this[$prevIndex + 1] = new Token([T_WHITESPACE, $this[$nextIndex]->getContent()]);
  25998. }
  25999. $this->clearAt($nextIndex);
  26000. }
  26001. private static function calculateCodeHash($code)
  26002. {
  26003. return CodeHasher::calculateCodeHash($code);
  26004. }
  26005. private static function getCache($key)
  26006. {
  26007. if (!self::hasCache($key)) {
  26008. throw new \OutOfBoundsException(sprintf('Unknown cache key: "%s".', $key));
  26009. }
  26010. return self::$cache[$key];
  26011. }
  26012. private static function hasCache($key)
  26013. {
  26014. return isset(self::$cache[$key]);
  26015. }
  26016. private static function setCache($key, self $value)
  26017. {
  26018. self::$cache[$key] = $value;
  26019. }
  26020. private function changeCodeHash($codeHash)
  26021. {
  26022. if (null !== $this->codeHash) {
  26023. self::clearCache($this->codeHash);
  26024. }
  26025. $this->codeHash = $codeHash;
  26026. self::setCache($this->codeHash, $this);
  26027. }
  26028. private function registerFoundToken($token)
  26029. {
  26030. $tokenKind = $this->extractTokenKind($token);
  26031. if (!isset($this->foundTokenKinds[$tokenKind])) {
  26032. $this->foundTokenKinds[$tokenKind] = 0;
  26033. }
  26034. ++$this->foundTokenKinds[$tokenKind];
  26035. }
  26036. private function unregisterFoundToken($token)
  26037. {
  26038. $tokenKind = $this->extractTokenKind($token);
  26039. if (!isset($this->foundTokenKinds[$tokenKind])) {
  26040. return;
  26041. }
  26042. --$this->foundTokenKinds[$tokenKind];
  26043. }
  26044. private function extractTokenKind($token)
  26045. {
  26046. return $token instanceof Token
  26047. ? ($token->isArray() ? $token->getId() : $token->getContent())
  26048. : (is_array($token) ? $token[0] : $token)
  26049. ;
  26050. }
  26051. }
  26052. <?php
  26053. namespace PhpCsFixer\Tokenizer;
  26054. final class TokensAnalyzer
  26055. {
  26056. private $tokens;
  26057. public function __construct(Tokens $tokens)
  26058. {
  26059. $this->tokens = $tokens;
  26060. }
  26061. public function getClassyElements()
  26062. {
  26063. $this->tokens->rewind();
  26064. $elements = [];
  26065. for ($index = 1, $count = count($this->tokens) - 2; $index < $count; ++$index) {
  26066. if ($this->tokens[$index]->isClassy()) {
  26067. list($index, $newElements) = $this->findClassyElements($index);
  26068. $elements += $newElements;
  26069. }
  26070. }
  26071. ksort($elements);
  26072. return $elements;
  26073. }
  26074. public function getImportUseIndexes($perNamespace = false)
  26075. {
  26076. $tokens = $this->tokens;
  26077. $tokens->rewind();
  26078. $uses = [];
  26079. $namespaceIndex = 0;
  26080. for ($index = 0, $limit = $tokens->count(); $index < $limit; ++$index) {
  26081. $token = $tokens[$index];
  26082. if ($token->isGivenKind(T_NAMESPACE)) {
  26083. $nextTokenIndex = $tokens->getNextTokenOfKind($index, [';', '{']);
  26084. $nextToken = $tokens[$nextTokenIndex];
  26085. if ($nextToken->equals('{')) {
  26086. $index = $nextTokenIndex;
  26087. }
  26088. if ($perNamespace) {
  26089. ++$namespaceIndex;
  26090. }
  26091. continue;
  26092. }
  26093. if ($token->isGivenKind(T_USE)) {
  26094. $uses[$namespaceIndex][] = $index;
  26095. }
  26096. }
  26097. if (!$perNamespace && isset($uses[$namespaceIndex])) {
  26098. return $uses[$namespaceIndex];
  26099. }
  26100. return $uses;
  26101. }
  26102. public function isArray($index)
  26103. {
  26104. return $this->tokens[$index]->isGivenKind([T_ARRAY, CT::T_ARRAY_SQUARE_BRACE_OPEN]);
  26105. }
  26106. public function isArrayMultiLine($index)
  26107. {
  26108. if (!$this->isArray($index)) {
  26109. throw new \InvalidArgumentException(sprintf('Not an array at given index %d.', $index));
  26110. }
  26111. $tokens = $this->tokens;
  26112. if ($tokens[$index]->isGivenKind(T_ARRAY)) {
  26113. $index = $tokens->getNextMeaningfulToken($index);
  26114. }
  26115. $endIndex = $tokens[$index]->equals('(')
  26116. ? $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index)
  26117. : $tokens->findBlockEnd(Tokens::BLOCK_TYPE_ARRAY_SQUARE_BRACE, $index)
  26118. ;
  26119. for (++$index; $index < $endIndex; ++$index) {
  26120. $token = $tokens[$index];
  26121. $blockType = Tokens::detectBlockType($token);
  26122. if ($blockType && $blockType['isStart']) {
  26123. $index = $tokens->findBlockEnd($blockType['type'], $index);
  26124. continue;
  26125. }
  26126. if (
  26127. $token->isWhitespace() &&
  26128. !$tokens[$index - 1]->isGivenKind(T_END_HEREDOC) &&
  26129. false !== strpos($token->getContent(), "\n")
  26130. ) {
  26131. return true;
  26132. }
  26133. }
  26134. return false;
  26135. }
  26136. public function getMethodAttributes($index)
  26137. {
  26138. $tokens = $this->tokens;
  26139. $token = $tokens[$index];
  26140. if (!$token->isGivenKind(T_FUNCTION)) {
  26141. throw new \LogicException(sprintf('No T_FUNCTION at given index %d, got %s.', $index, $token->getName()));
  26142. }
  26143. $attributes = [
  26144. 'visibility' => null,
  26145. 'static' => false,
  26146. 'abstract' => false,
  26147. 'final' => false,
  26148. ];
  26149. for ($i = $index; $i >= 0; --$i) {
  26150. $tokenIndex = $tokens->getPrevMeaningfulToken($i);
  26151. $i = $tokenIndex;
  26152. $token = $tokens[$tokenIndex];
  26153. if ($token->isGivenKind([T_STATIC])) {
  26154. $attributes['static'] = true;
  26155. continue;
  26156. }
  26157. if ($token->isGivenKind([T_FINAL])) {
  26158. $attributes['final'] = true;
  26159. continue;
  26160. }
  26161. if ($token->isGivenKind([T_ABSTRACT])) {
  26162. $attributes['abstract'] = true;
  26163. continue;
  26164. }
  26165. if ($token->isGivenKind([T_PRIVATE])) {
  26166. $attributes['visibility'] = T_PRIVATE;
  26167. continue;
  26168. }
  26169. if ($token->isGivenKind([T_PROTECTED])) {
  26170. $attributes['visibility'] = T_PROTECTED;
  26171. continue;
  26172. }
  26173. if ($token->isGivenKind([T_PUBLIC])) {
  26174. $attributes['visibility'] = T_PUBLIC;
  26175. continue;
  26176. }
  26177. break;
  26178. }
  26179. return $attributes;
  26180. }
  26181. public function isAnonymousClass($index)
  26182. {
  26183. $tokens = $this->tokens;
  26184. $token = $tokens[$index];
  26185. if (!$token->isClassy()) {
  26186. throw new \LogicException(sprintf('No classy token at given index %d.', $index));
  26187. }
  26188. if (!$token->isGivenKind(T_CLASS)) {
  26189. return false;
  26190. }
  26191. return $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_NEW);
  26192. }
  26193. public function isLambda($index)
  26194. {
  26195. if (!$this->tokens[$index]->isGivenKind(T_FUNCTION)) {
  26196. throw new \LogicException(sprintf('No T_FUNCTION at given index %d, got %s.', $index, $this->tokens[$index]->getName()));
  26197. }
  26198. $startParenthesisIndex = $this->tokens->getNextMeaningfulToken($index);
  26199. $startParenthesisToken = $this->tokens[$startParenthesisIndex];
  26200. if ($startParenthesisToken->isGivenKind(CT::T_RETURN_REF)) {
  26201. $startParenthesisIndex = $this->tokens->getNextMeaningfulToken($startParenthesisIndex);
  26202. $startParenthesisToken = $this->tokens[$startParenthesisIndex];
  26203. }
  26204. return $startParenthesisToken->equals('(');
  26205. }
  26206. public function isUnarySuccessorOperator($index)
  26207. {
  26208. static $allowedPrevToken = [
  26209. ']',
  26210. [T_STRING],
  26211. [T_VARIABLE],
  26212. [CT::T_DYNAMIC_PROP_BRACE_CLOSE],
  26213. [CT::T_DYNAMIC_VAR_BRACE_CLOSE],
  26214. ];
  26215. $tokens = $this->tokens;
  26216. $token = $tokens[$index];
  26217. if (!$token->isGivenKind([T_INC, T_DEC])) {
  26218. return false;
  26219. }
  26220. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  26221. return $prevToken->equalsAny($allowedPrevToken);
  26222. }
  26223. public function isUnaryPredecessorOperator($index)
  26224. {
  26225. static $potentialSuccessorOperator = [T_INC, T_DEC];
  26226. static $potentialBinaryOperator = ['+', '-', '&', [CT::T_RETURN_REF]];
  26227. static $otherOperators;
  26228. if (null === $otherOperators) {
  26229. $otherOperators = ['!', '~', '@', [T_ELLIPSIS]];
  26230. }
  26231. static $disallowedPrevTokens;
  26232. if (null === $disallowedPrevTokens) {
  26233. $disallowedPrevTokens = [
  26234. ']',
  26235. '}',
  26236. ')',
  26237. '"',
  26238. '`',
  26239. [CT::T_ARRAY_SQUARE_BRACE_CLOSE],
  26240. [CT::T_DYNAMIC_PROP_BRACE_CLOSE],
  26241. [CT::T_DYNAMIC_VAR_BRACE_CLOSE],
  26242. [T_CLASS_C],
  26243. [T_CONSTANT_ENCAPSED_STRING],
  26244. [T_DEC],
  26245. [T_DIR],
  26246. [T_DNUMBER],
  26247. [T_FILE],
  26248. [T_FUNC_C],
  26249. [T_INC],
  26250. [T_LINE],
  26251. [T_LNUMBER],
  26252. [T_METHOD_C],
  26253. [T_NS_C],
  26254. [T_STRING],
  26255. [T_TRAIT_C],
  26256. [T_VARIABLE],
  26257. ];
  26258. }
  26259. $tokens = $this->tokens;
  26260. $token = $tokens[$index];
  26261. if ($token->isGivenKind($potentialSuccessorOperator)) {
  26262. return !$this->isUnarySuccessorOperator($index);
  26263. }
  26264. if ($token->equalsAny($otherOperators)) {
  26265. return true;
  26266. }
  26267. if (!$token->equalsAny($potentialBinaryOperator)) {
  26268. return false;
  26269. }
  26270. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  26271. if (!$prevToken->equalsAny($disallowedPrevTokens)) {
  26272. return true;
  26273. }
  26274. if (!$token->equals('&') || !$prevToken->isGivenKind(T_STRING)) {
  26275. return false;
  26276. }
  26277. static $searchTokens = [
  26278. ';',
  26279. '{',
  26280. '}',
  26281. [T_FUNCTION],
  26282. [T_OPEN_TAG],
  26283. [T_OPEN_TAG_WITH_ECHO],
  26284. ];
  26285. $prevToken = $tokens[$tokens->getPrevTokenOfKind($index, $searchTokens)];
  26286. return $prevToken->isGivenKind(T_FUNCTION);
  26287. }
  26288. public function isBinaryOperator($index)
  26289. {
  26290. static $nonArrayOperators = [
  26291. '=' => true,
  26292. '*' => true,
  26293. '/' => true,
  26294. '%' => true,
  26295. '<' => true,
  26296. '>' => true,
  26297. '|' => true,
  26298. '^' => true,
  26299. ];
  26300. static $potentialUnaryNonArrayOperators = [
  26301. '+' => true,
  26302. '-' => true,
  26303. '&' => true,
  26304. ];
  26305. static $arrayOperators;
  26306. if (null === $arrayOperators) {
  26307. $arrayOperators = [
  26308. T_AND_EQUAL => true,
  26309. T_BOOLEAN_AND => true,
  26310. T_BOOLEAN_OR => true,
  26311. T_CONCAT_EQUAL => true,
  26312. T_DIV_EQUAL => true,
  26313. T_DOUBLE_ARROW => true,
  26314. T_IS_EQUAL => true,
  26315. T_IS_GREATER_OR_EQUAL => true,
  26316. T_IS_IDENTICAL => true,
  26317. T_IS_NOT_EQUAL => true,
  26318. T_IS_NOT_IDENTICAL => true,
  26319. T_IS_SMALLER_OR_EQUAL => true,
  26320. T_LOGICAL_AND => true,
  26321. T_LOGICAL_OR => true,
  26322. T_LOGICAL_XOR => true,
  26323. T_MINUS_EQUAL => true,
  26324. T_MOD_EQUAL => true,
  26325. T_MUL_EQUAL => true,
  26326. T_OR_EQUAL => true,
  26327. T_PLUS_EQUAL => true,
  26328. T_POW => true,
  26329. T_POW_EQUAL => true,
  26330. T_SL => true,
  26331. T_SL_EQUAL => true,
  26332. T_SR => true,
  26333. T_SR_EQUAL => true,
  26334. T_XOR_EQUAL => true,
  26335. CT::T_TYPE_ALTERNATION => true,
  26336. ];
  26337. if (defined('T_SPACESHIP')) {
  26338. $arrayOperators[T_SPACESHIP] = true;
  26339. }
  26340. if (defined('T_COALESCE')) {
  26341. $arrayOperators[T_COALESCE] = true;
  26342. }
  26343. }
  26344. $tokens = $this->tokens;
  26345. $token = $tokens[$index];
  26346. if ($token->isArray()) {
  26347. return isset($arrayOperators[$token->getId()]);
  26348. }
  26349. if (isset($nonArrayOperators[$token->getContent()])) {
  26350. return true;
  26351. }
  26352. if (isset($potentialUnaryNonArrayOperators[$token->getContent()])) {
  26353. return !$this->isUnaryPredecessorOperator($index);
  26354. }
  26355. return false;
  26356. }
  26357. public function isWhilePartOfDoWhile($index)
  26358. {
  26359. $tokens = $this->tokens;
  26360. $token = $tokens[$index];
  26361. if (!$token->isGivenKind(T_WHILE)) {
  26362. throw new \LogicException(sprintf('No T_WHILE at given index %d, got %s.', $index, $token->getName()));
  26363. }
  26364. $endIndex = $tokens->getPrevMeaningfulToken($index);
  26365. if (!$tokens[$endIndex]->equals('}')) {
  26366. return false;
  26367. }
  26368. $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $endIndex, false);
  26369. $beforeStartIndex = $tokens->getPrevMeaningfulToken($startIndex);
  26370. return $tokens[$beforeStartIndex]->isGivenKind(T_DO);
  26371. }
  26372. private function findClassyElements($index)
  26373. {
  26374. $elements = [];
  26375. $curlyBracesLevel = 0;
  26376. $bracesLevel = 0;
  26377. $classIndex = $index;
  26378. ++$index;
  26379. for ($count = count($this->tokens); $index < $count; ++$index) {
  26380. $token = $this->tokens[$index];
  26381. if ($token->isGivenKind(T_ENCAPSED_AND_WHITESPACE)) {
  26382. continue;
  26383. }
  26384. if ($token->isClassy()) {
  26385. list($index, $newElements) = $this->findClassyElements($index);
  26386. $elements += $newElements;
  26387. continue;
  26388. }
  26389. if ($token->equals('(')) {
  26390. ++$bracesLevel;
  26391. continue;
  26392. }
  26393. if ($token->equals(')')) {
  26394. --$bracesLevel;
  26395. continue;
  26396. }
  26397. if ($token->equals('{')) {
  26398. ++$curlyBracesLevel;
  26399. continue;
  26400. }
  26401. if ($token->equals('}')) {
  26402. --$curlyBracesLevel;
  26403. if (0 === $curlyBracesLevel) {
  26404. break;
  26405. }
  26406. continue;
  26407. }
  26408. if (1 !== $curlyBracesLevel || !$token->isArray()) {
  26409. continue;
  26410. }
  26411. if (0 === $bracesLevel && $token->isGivenKind(T_VARIABLE)) {
  26412. $elements[$index] = [
  26413. 'token' => $token,
  26414. 'type' => 'property',
  26415. 'classIndex' => $classIndex,
  26416. ];
  26417. continue;
  26418. }
  26419. if ($token->isGivenKind(T_FUNCTION)) {
  26420. $elements[$index] = [
  26421. 'token' => $token,
  26422. 'type' => 'method',
  26423. 'classIndex' => $classIndex,
  26424. ];
  26425. } elseif ($token->isGivenKind(T_CONST)) {
  26426. $elements[$index] = [
  26427. 'token' => $token,
  26428. 'type' => 'const',
  26429. 'classIndex' => $classIndex,
  26430. ];
  26431. }
  26432. }
  26433. return [$index, $elements];
  26434. }
  26435. }
  26436. <?php
  26437. namespace PhpCsFixer\Tokenizer\Transformer;
  26438. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26439. use PhpCsFixer\Tokenizer\CT;
  26440. use PhpCsFixer\Tokenizer\Token;
  26441. use PhpCsFixer\Tokenizer\Tokens;
  26442. final class ArrayTypehintTransformer extends AbstractTransformer
  26443. {
  26444. public function getCustomTokens()
  26445. {
  26446. return [CT::T_ARRAY_TYPEHINT];
  26447. }
  26448. public function getRequiredPhpVersionId()
  26449. {
  26450. return 50000;
  26451. }
  26452. public function process(Tokens $tokens, Token $token, $index)
  26453. {
  26454. if (!$token->isGivenKind(T_ARRAY)) {
  26455. return;
  26456. }
  26457. $nextIndex = $tokens->getNextMeaningfulToken($index);
  26458. $nextToken = $tokens[$nextIndex];
  26459. if (!$nextToken->equals('(')) {
  26460. $tokens[$index] = new Token([CT::T_ARRAY_TYPEHINT, $token->getContent()]);
  26461. }
  26462. }
  26463. }
  26464. <?php
  26465. namespace PhpCsFixer\Tokenizer\Transformer;
  26466. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26467. use PhpCsFixer\Tokenizer\CT;
  26468. use PhpCsFixer\Tokenizer\Token;
  26469. use PhpCsFixer\Tokenizer\Tokens;
  26470. final class BraceClassInstantiationTransformer extends AbstractTransformer
  26471. {
  26472. public function getCustomTokens()
  26473. {
  26474. return [CT::T_BRACE_CLASS_INSTANTIATION_OPEN, CT::T_BRACE_CLASS_INSTANTIATION_CLOSE];
  26475. }
  26476. public function getPriority()
  26477. {
  26478. return -1;
  26479. }
  26480. public function getRequiredPhpVersionId()
  26481. {
  26482. return 50000;
  26483. }
  26484. public function process(Tokens $tokens, Token $token, $index)
  26485. {
  26486. if (!$tokens[$index]->equals('(') || !$tokens[$tokens->getNextMeaningfulToken($index)]->equals([T_NEW])) {
  26487. return;
  26488. }
  26489. if ($tokens[$tokens->getPrevMeaningfulToken($index)]->equalsAny([
  26490. ']',
  26491. [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE],
  26492. [CT::T_ARRAY_SQUARE_BRACE_CLOSE],
  26493. [T_ARRAY],
  26494. [T_CLASS],
  26495. [T_ELSEIF],
  26496. [T_FOR],
  26497. [T_FOREACH],
  26498. [T_IF],
  26499. [T_STATIC],
  26500. [T_STRING],
  26501. [T_SWITCH],
  26502. [T_VARIABLE],
  26503. [T_WHILE],
  26504. ])) {
  26505. return;
  26506. }
  26507. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $index);
  26508. $tokens[$index] = new Token([CT::T_BRACE_CLASS_INSTANTIATION_OPEN, '(']);
  26509. $tokens[$closeIndex] = new Token([CT::T_BRACE_CLASS_INSTANTIATION_CLOSE, ')']);
  26510. }
  26511. }
  26512. <?php
  26513. namespace PhpCsFixer\Tokenizer\Transformer;
  26514. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26515. use PhpCsFixer\Tokenizer\CT;
  26516. use PhpCsFixer\Tokenizer\Token;
  26517. use PhpCsFixer\Tokenizer\Tokens;
  26518. final class ClassConstantTransformer extends AbstractTransformer
  26519. {
  26520. public function getCustomTokens()
  26521. {
  26522. return [CT::T_CLASS_CONSTANT];
  26523. }
  26524. public function getRequiredPhpVersionId()
  26525. {
  26526. return 50500;
  26527. }
  26528. public function process(Tokens $tokens, Token $token, $index)
  26529. {
  26530. if (!$token->equalsAny([
  26531. [T_CLASS, 'class'],
  26532. [T_STRING, 'class'],
  26533. ], false)) {
  26534. return;
  26535. }
  26536. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  26537. $prevToken = $tokens[$prevIndex];
  26538. if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
  26539. $tokens[$index] = new Token([CT::T_CLASS_CONSTANT, $token->getContent()]);
  26540. }
  26541. }
  26542. }
  26543. <?php
  26544. namespace PhpCsFixer\Tokenizer\Transformer;
  26545. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26546. use PhpCsFixer\Tokenizer\CT;
  26547. use PhpCsFixer\Tokenizer\Token;
  26548. use PhpCsFixer\Tokenizer\Tokens;
  26549. final class CurlyBraceTransformer extends AbstractTransformer
  26550. {
  26551. public function getCustomTokens()
  26552. {
  26553. return [
  26554. CT::T_CURLY_CLOSE,
  26555. CT::T_DOLLAR_CLOSE_CURLY_BRACES,
  26556. CT::T_DYNAMIC_PROP_BRACE_OPEN,
  26557. CT::T_DYNAMIC_PROP_BRACE_CLOSE,
  26558. CT::T_DYNAMIC_VAR_BRACE_OPEN,
  26559. CT::T_DYNAMIC_VAR_BRACE_CLOSE,
  26560. CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN,
  26561. CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE,
  26562. CT::T_GROUP_IMPORT_BRACE_OPEN,
  26563. CT::T_GROUP_IMPORT_BRACE_CLOSE,
  26564. ];
  26565. }
  26566. public function getRequiredPhpVersionId()
  26567. {
  26568. return 50000;
  26569. }
  26570. public function process(Tokens $tokens, Token $token, $index)
  26571. {
  26572. $this->transformIntoCurlyCloseBrace($tokens, $token, $index);
  26573. $this->transformIntoDollarCloseBrace($tokens, $token, $index);
  26574. $this->transformIntoDynamicPropBraces($tokens, $token, $index);
  26575. $this->transformIntoDynamicVarBraces($tokens, $token, $index);
  26576. $this->transformIntoCurlyIndexBraces($tokens, $token, $index);
  26577. if (PHP_VERSION_ID >= 70000) {
  26578. $this->transformIntoGroupUseBraces($tokens, $token, $index);
  26579. }
  26580. }
  26581. private function transformIntoCurlyCloseBrace(Tokens $tokens, Token $token, $index)
  26582. {
  26583. if (!$token->isGivenKind(T_CURLY_OPEN)) {
  26584. return;
  26585. }
  26586. $level = 1;
  26587. $nestIndex = $index;
  26588. while (0 < $level) {
  26589. ++$nestIndex;
  26590. if ($tokens[$nestIndex]->equals('{')) {
  26591. ++$level;
  26592. continue;
  26593. }
  26594. if ($tokens[$nestIndex]->equals('}')) {
  26595. --$level;
  26596. }
  26597. }
  26598. $tokens[$nestIndex] = new Token([CT::T_CURLY_CLOSE, '}']);
  26599. }
  26600. private function transformIntoDollarCloseBrace(Tokens $tokens, Token $token, $index)
  26601. {
  26602. if ($token->isGivenKind(T_DOLLAR_OPEN_CURLY_BRACES)) {
  26603. $nextIndex = $tokens->getNextTokenOfKind($index, ['}']);
  26604. $tokens[$nextIndex] = new Token([CT::T_DOLLAR_CLOSE_CURLY_BRACES, '}']);
  26605. }
  26606. }
  26607. private function transformIntoDynamicPropBraces(Tokens $tokens, Token $token, $index)
  26608. {
  26609. if (!$token->isGivenKind(T_OBJECT_OPERATOR)) {
  26610. return;
  26611. }
  26612. if (!$tokens[$index + 1]->equals('{')) {
  26613. return;
  26614. }
  26615. $openIndex = $index + 1;
  26616. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex);
  26617. $tokens[$openIndex] = new Token([CT::T_DYNAMIC_PROP_BRACE_OPEN, '{']);
  26618. $tokens[$closeIndex] = new Token([CT::T_DYNAMIC_PROP_BRACE_CLOSE, '}']);
  26619. }
  26620. private function transformIntoDynamicVarBraces(Tokens $tokens, Token $token, $index)
  26621. {
  26622. if (!$token->equals('$')) {
  26623. return;
  26624. }
  26625. $openIndex = $tokens->getNextMeaningfulToken($index);
  26626. if (null === $openIndex) {
  26627. return;
  26628. }
  26629. $openToken = $tokens[$openIndex];
  26630. if (!$openToken->equals('{')) {
  26631. return;
  26632. }
  26633. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $openIndex);
  26634. $tokens[$openIndex] = new Token([CT::T_DYNAMIC_VAR_BRACE_OPEN, '{']);
  26635. $tokens[$closeIndex] = new Token([CT::T_DYNAMIC_VAR_BRACE_CLOSE, '}']);
  26636. }
  26637. private function transformIntoCurlyIndexBraces(Tokens $tokens, Token $token, $index)
  26638. {
  26639. if (!$token->equals('{')) {
  26640. return;
  26641. }
  26642. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  26643. if (!$tokens[$prevIndex]->equalsAny([
  26644. [T_STRING],
  26645. [T_VARIABLE],
  26646. [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE],
  26647. [CT::T_ARRAY_SQUARE_BRACE_CLOSE],
  26648. ']',
  26649. ')',
  26650. ])) {
  26651. return;
  26652. }
  26653. if (
  26654. $tokens[$prevIndex]->isGivenKind(T_STRING)
  26655. && !$tokens[$tokens->getPrevMeaningfulToken($prevIndex)]->isGivenKind(T_OBJECT_OPERATOR)
  26656. ) {
  26657. return;
  26658. }
  26659. if (
  26660. $tokens[$prevIndex]->equals(')')
  26661. && !$tokens[$tokens->getPrevMeaningfulToken(
  26662. $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $prevIndex, false)
  26663. )]->isGivenKind(T_ARRAY)
  26664. ) {
  26665. return;
  26666. }
  26667. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  26668. $tokens[$index] = new Token([CT::T_ARRAY_INDEX_CURLY_BRACE_OPEN, '{']);
  26669. $tokens[$closeIndex] = new Token([CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE, '}']);
  26670. }
  26671. private function transformIntoGroupUseBraces(Tokens $tokens, Token $token, $index)
  26672. {
  26673. if (!$token->equals('{')) {
  26674. return;
  26675. }
  26676. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  26677. if (!$tokens[$prevIndex]->isGivenKind(T_NS_SEPARATOR)) {
  26678. return;
  26679. }
  26680. $closeIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  26681. $tokens[$index] = new Token([CT::T_GROUP_IMPORT_BRACE_OPEN, '{']);
  26682. $tokens[$closeIndex] = new Token([CT::T_GROUP_IMPORT_BRACE_CLOSE, '}']);
  26683. }
  26684. }
  26685. <?php
  26686. namespace PhpCsFixer\Tokenizer\Transformer;
  26687. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26688. use PhpCsFixer\Tokenizer\CT;
  26689. use PhpCsFixer\Tokenizer\Token;
  26690. use PhpCsFixer\Tokenizer\Tokens;
  26691. final class ImportTransformer extends AbstractTransformer
  26692. {
  26693. public function getCustomTokens()
  26694. {
  26695. return [CT::T_CONST_IMPORT, CT::T_FUNCTION_IMPORT];
  26696. }
  26697. public function getRequiredPhpVersionId()
  26698. {
  26699. return 50600;
  26700. }
  26701. public function process(Tokens $tokens, Token $token, $index)
  26702. {
  26703. if (!$token->isGivenKind([T_CONST, T_FUNCTION])) {
  26704. return;
  26705. }
  26706. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  26707. if ($prevToken->isGivenKind(T_USE)) {
  26708. $tokens[$index] = new Token([
  26709. $token->isGivenKind(T_FUNCTION) ? CT::T_FUNCTION_IMPORT : CT::T_CONST_IMPORT,
  26710. $token->getContent(),
  26711. ]);
  26712. }
  26713. }
  26714. }
  26715. <?php
  26716. namespace PhpCsFixer\Tokenizer\Transformer;
  26717. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26718. use PhpCsFixer\Tokenizer\CT;
  26719. use PhpCsFixer\Tokenizer\Token;
  26720. use PhpCsFixer\Tokenizer\Tokens;
  26721. final class NamespaceOperatorTransformer extends AbstractTransformer
  26722. {
  26723. public function getCustomTokens()
  26724. {
  26725. return [CT::T_NAMESPACE_OPERATOR];
  26726. }
  26727. public function getRequiredPhpVersionId()
  26728. {
  26729. return 50300;
  26730. }
  26731. public function process(Tokens $tokens, Token $token, $index)
  26732. {
  26733. if (!$token->isGivenKind(T_NAMESPACE)) {
  26734. return;
  26735. }
  26736. $nextIndex = $tokens->getNextMeaningfulToken($index);
  26737. $nextToken = $tokens[$nextIndex];
  26738. if ($nextToken->isGivenKind(T_NS_SEPARATOR)) {
  26739. $tokens[$index] = new Token([CT::T_NAMESPACE_OPERATOR, $token->getContent()]);
  26740. }
  26741. }
  26742. }
  26743. <?php
  26744. namespace PhpCsFixer\Tokenizer\Transformer;
  26745. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26746. use PhpCsFixer\Tokenizer\CT;
  26747. use PhpCsFixer\Tokenizer\Token;
  26748. use PhpCsFixer\Tokenizer\Tokens;
  26749. final class NullableTypeTransformer extends AbstractTransformer
  26750. {
  26751. public function getCustomTokens()
  26752. {
  26753. return [CT::T_NULLABLE_TYPE];
  26754. }
  26755. public function getPriority()
  26756. {
  26757. return -20;
  26758. }
  26759. public function getRequiredPhpVersionId()
  26760. {
  26761. return 70100;
  26762. }
  26763. public function process(Tokens $tokens, Token $token, $index)
  26764. {
  26765. if (!$token->equals('?')) {
  26766. return;
  26767. }
  26768. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  26769. $prevToken = $tokens[$prevIndex];
  26770. if ($prevToken->equalsAny(['(', ',', [CT::T_TYPE_COLON]])) {
  26771. $tokens[$index] = new Token([CT::T_NULLABLE_TYPE, '?']);
  26772. }
  26773. }
  26774. }
  26775. <?php
  26776. namespace PhpCsFixer\Tokenizer\Transformer;
  26777. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26778. use PhpCsFixer\Tokenizer\CT;
  26779. use PhpCsFixer\Tokenizer\Token;
  26780. use PhpCsFixer\Tokenizer\Tokens;
  26781. final class ReturnRefTransformer extends AbstractTransformer
  26782. {
  26783. public function getCustomTokens()
  26784. {
  26785. return [CT::T_RETURN_REF];
  26786. }
  26787. public function getRequiredPhpVersionId()
  26788. {
  26789. return 50000;
  26790. }
  26791. public function process(Tokens $tokens, Token $token, $index)
  26792. {
  26793. if (
  26794. $token->equals('&')
  26795. && $tokens[$tokens->getPrevMeaningfulToken($index)]->isGivenKind(T_FUNCTION)
  26796. ) {
  26797. $tokens[$index] = new Token([CT::T_RETURN_REF, '&']);
  26798. }
  26799. }
  26800. }
  26801. <?php
  26802. namespace PhpCsFixer\Tokenizer\Transformer;
  26803. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26804. use PhpCsFixer\Tokenizer\CT;
  26805. use PhpCsFixer\Tokenizer\Token;
  26806. use PhpCsFixer\Tokenizer\Tokens;
  26807. final class SquareBraceTransformer extends AbstractTransformer
  26808. {
  26809. public function getCustomTokens()
  26810. {
  26811. return [
  26812. CT::T_ARRAY_SQUARE_BRACE_OPEN,
  26813. CT::T_ARRAY_SQUARE_BRACE_CLOSE,
  26814. CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN,
  26815. CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE,
  26816. ];
  26817. }
  26818. public function getRequiredPhpVersionId()
  26819. {
  26820. return 50000;
  26821. }
  26822. public function process(Tokens $tokens, Token $token, $index)
  26823. {
  26824. if ($this->isArrayDestructing($tokens, $index)) {
  26825. $this->transformIntoDestructuringSquareBrace($tokens, $index);
  26826. return;
  26827. }
  26828. if ($this->isShortArray($tokens, $index)) {
  26829. $this->transformIntoArraySquareBrace($tokens, $index);
  26830. }
  26831. }
  26832. private function transformIntoArraySquareBrace(Tokens $tokens, $index)
  26833. {
  26834. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
  26835. $tokens[$index] = new Token([CT::T_ARRAY_SQUARE_BRACE_OPEN, '[']);
  26836. $tokens[$endIndex] = new Token([CT::T_ARRAY_SQUARE_BRACE_CLOSE, ']']);
  26837. }
  26838. private function transformIntoDestructuringSquareBrace(Tokens $tokens, $index)
  26839. {
  26840. $endIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_INDEX_SQUARE_BRACE, $index);
  26841. $tokens[$index] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_OPEN, '[']);
  26842. $tokens[$endIndex] = new Token([CT::T_DESTRUCTURING_SQUARE_BRACE_CLOSE, ']']);
  26843. }
  26844. private function isShortArray(Tokens $tokens, $index)
  26845. {
  26846. static $disallowedPrevTokens = [
  26847. ')',
  26848. ']',
  26849. '}',
  26850. '"',
  26851. [T_CONSTANT_ENCAPSED_STRING],
  26852. [T_STRING],
  26853. [T_STRING_VARNAME],
  26854. [T_VARIABLE],
  26855. [CT::T_ARRAY_SQUARE_BRACE_CLOSE],
  26856. [CT::T_DYNAMIC_PROP_BRACE_CLOSE],
  26857. [CT::T_DYNAMIC_VAR_BRACE_CLOSE],
  26858. [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE],
  26859. ];
  26860. $token = $tokens[$index];
  26861. if (!$token->equals('[')) {
  26862. return false;
  26863. }
  26864. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  26865. if ($prevToken->equalsAny($disallowedPrevTokens)) {
  26866. return false;
  26867. }
  26868. $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
  26869. if ($nextToken->equals(']')) {
  26870. return true;
  26871. }
  26872. return !$this->isArrayDestructing($tokens, $index);
  26873. }
  26874. private function isArrayDestructing(Tokens $tokens, $index)
  26875. {
  26876. if (PHP_VERSION_ID < 70100 || !$tokens[$index]->equals('[')) {
  26877. return false;
  26878. }
  26879. static $disallowedPrevTokens = [
  26880. ')',
  26881. ']',
  26882. '"',
  26883. [T_CONSTANT_ENCAPSED_STRING],
  26884. [T_STRING],
  26885. [T_STRING_VARNAME],
  26886. [T_VARIABLE],
  26887. [CT::T_ARRAY_SQUARE_BRACE_CLOSE],
  26888. [CT::T_DYNAMIC_PROP_BRACE_CLOSE],
  26889. [CT::T_DYNAMIC_VAR_BRACE_CLOSE],
  26890. [CT::T_ARRAY_INDEX_CURLY_BRACE_CLOSE],
  26891. ];
  26892. $prevToken = $tokens[$tokens->getPrevMeaningfulToken($index)];
  26893. if ($prevToken->equalsAny($disallowedPrevTokens)) {
  26894. return false;
  26895. }
  26896. $type = Tokens::detectBlockType($tokens[$index]);
  26897. $end = $tokens->findBlockEnd($type['type'], $index);
  26898. $nextToken = $tokens[$tokens->getNextMeaningfulToken($end)];
  26899. return $nextToken->equals('=');
  26900. }
  26901. }
  26902. <?php
  26903. namespace PhpCsFixer\Tokenizer\Transformer;
  26904. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26905. use PhpCsFixer\Tokenizer\CT;
  26906. use PhpCsFixer\Tokenizer\Token;
  26907. use PhpCsFixer\Tokenizer\Tokens;
  26908. final class TypeAlternationTransformer extends AbstractTransformer
  26909. {
  26910. public function getCustomTokens()
  26911. {
  26912. return [CT::T_TYPE_ALTERNATION];
  26913. }
  26914. public function getRequiredPhpVersionId()
  26915. {
  26916. return 70100;
  26917. }
  26918. public function process(Tokens $tokens, Token $token, $index)
  26919. {
  26920. if (!$token->equals('|')) {
  26921. return;
  26922. }
  26923. $prevIndex = $tokens->getPrevMeaningfulToken($index);
  26924. $prevToken = $tokens[$prevIndex];
  26925. if (!$prevToken->isGivenKind(T_STRING)) {
  26926. return;
  26927. }
  26928. $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
  26929. $prevToken = $tokens[$prevIndex];
  26930. if (!$prevToken->equalsAny(['(', [CT::T_TYPE_ALTERNATION]])) {
  26931. return;
  26932. }
  26933. $tokens[$index] = new Token([CT::T_TYPE_ALTERNATION, '|']);
  26934. }
  26935. }
  26936. <?php
  26937. namespace PhpCsFixer\Tokenizer\Transformer;
  26938. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26939. use PhpCsFixer\Tokenizer\CT;
  26940. use PhpCsFixer\Tokenizer\Token;
  26941. use PhpCsFixer\Tokenizer\Tokens;
  26942. final class TypeColonTransformer extends AbstractTransformer
  26943. {
  26944. public function getCustomTokens()
  26945. {
  26946. return [CT::T_TYPE_COLON];
  26947. }
  26948. public function getPriority()
  26949. {
  26950. return -10;
  26951. }
  26952. public function getRequiredPhpVersionId()
  26953. {
  26954. return 70000;
  26955. }
  26956. public function process(Tokens $tokens, Token $token, $index)
  26957. {
  26958. if (!$token->equals(':')) {
  26959. return;
  26960. }
  26961. $endIndex = $tokens->getPrevMeaningfulToken($index);
  26962. if (!$tokens[$endIndex]->equals(')')) {
  26963. return;
  26964. }
  26965. $startIndex = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_PARENTHESIS_BRACE, $endIndex, false);
  26966. $prevIndex = $tokens->getPrevMeaningfulToken($startIndex);
  26967. $prevToken = $tokens[$prevIndex];
  26968. if ($prevToken->isGivenKind(T_STRING)) {
  26969. $prevIndex = $tokens->getPrevMeaningfulToken($prevIndex);
  26970. $prevToken = $tokens[$prevIndex];
  26971. }
  26972. if ($prevToken->isGivenKind([T_FUNCTION, CT::T_RETURN_REF, CT::T_USE_LAMBDA])) {
  26973. $tokens[$index] = new Token([CT::T_TYPE_COLON, ':']);
  26974. }
  26975. }
  26976. }
  26977. <?php
  26978. namespace PhpCsFixer\Tokenizer\Transformer;
  26979. use PhpCsFixer\Tokenizer\AbstractTransformer;
  26980. use PhpCsFixer\Tokenizer\CT;
  26981. use PhpCsFixer\Tokenizer\Token;
  26982. use PhpCsFixer\Tokenizer\Tokens;
  26983. final class UseTransformer extends AbstractTransformer
  26984. {
  26985. public function getCustomTokens()
  26986. {
  26987. return [CT::T_USE_TRAIT, CT::T_USE_LAMBDA];
  26988. }
  26989. public function getRequiredPhpVersionId()
  26990. {
  26991. return 50300;
  26992. }
  26993. public function process(Tokens $tokens, Token $token, $index)
  26994. {
  26995. if ($token->isGivenKind(T_USE) && $this->isUseForLambda($tokens, $index)) {
  26996. $tokens[$index] = new Token([CT::T_USE_LAMBDA, $token->getContent()]);
  26997. }
  26998. if (!$token->isClassy()) {
  26999. return;
  27000. }
  27001. $prevTokenIndex = $tokens->getPrevMeaningfulToken($index);
  27002. $prevToken = null === $prevTokenIndex ? null : $tokens[$prevTokenIndex];
  27003. if ($prevToken->isGivenKind(T_DOUBLE_COLON)) {
  27004. return;
  27005. }
  27006. $index = $tokens->getNextTokenOfKind($index, ['{']);
  27007. $innerLimit = $tokens->findBlockEnd(Tokens::BLOCK_TYPE_CURLY_BRACE, $index);
  27008. while ($index < $innerLimit) {
  27009. $token = $tokens[++$index];
  27010. if (!$token->isGivenKind(T_USE)) {
  27011. continue;
  27012. }
  27013. if ($this->isUseForLambda($tokens, $index)) {
  27014. $tokens[$index] = new Token([CT::T_USE_LAMBDA, $token->getContent()]);
  27015. } else {
  27016. $tokens[$index] = new Token([CT::T_USE_TRAIT, $token->getContent()]);
  27017. }
  27018. }
  27019. }
  27020. private function isUseForLambda(Tokens $tokens, $index)
  27021. {
  27022. $nextToken = $tokens[$tokens->getNextMeaningfulToken($index)];
  27023. return $nextToken->equals('(');
  27024. }
  27025. }
  27026. <?php
  27027. namespace PhpCsFixer\Tokenizer\Transformer;
  27028. use PhpCsFixer\Tokenizer\AbstractTransformer;
  27029. use PhpCsFixer\Tokenizer\Token;
  27030. use PhpCsFixer\Tokenizer\Tokens;
  27031. final class WhitespacyCommentTransformer extends AbstractTransformer
  27032. {
  27033. public function getCustomTokens()
  27034. {
  27035. return [];
  27036. }
  27037. public function getRequiredPhpVersionId()
  27038. {
  27039. return 50000;
  27040. }
  27041. public function process(Tokens $tokens, Token $token, $index)
  27042. {
  27043. if (!$token->isComment()) {
  27044. return;
  27045. }
  27046. $content = $token->getContent();
  27047. $trimmedContent = rtrim($content);
  27048. if ($content === $trimmedContent) {
  27049. return;
  27050. }
  27051. $whitespaces = substr($content, strlen($trimmedContent));
  27052. $tokens[$index] = new Token([$token->getId(), $trimmedContent]);
  27053. if (isset($tokens[$index + 1]) && $tokens[$index + 1]->isWhitespace()) {
  27054. $tokens[$index + 1] = new Token([T_WHITESPACE, $whitespaces.$tokens[$index + 1]->getContent()]);
  27055. } else {
  27056. $tokens->insertAt($index + 1, new Token([T_WHITESPACE, $whitespaces]));
  27057. }
  27058. }
  27059. }
  27060. <?php
  27061. namespace PhpCsFixer\Tokenizer;
  27062. interface TransformerInterface
  27063. {
  27064. public function getCustomTokens();
  27065. public function getName();
  27066. public function getPriority();
  27067. public function getRequiredPhpVersionId();
  27068. public function process(Tokens $tokens, Token $token, $index);
  27069. }
  27070. <?php
  27071. namespace PhpCsFixer\Tokenizer;
  27072. use PhpCsFixer\Utils;
  27073. use Symfony\Component\Finder\Finder;
  27074. final class Transformers
  27075. {
  27076. private $items = [];
  27077. private function __construct()
  27078. {
  27079. $this->registerBuiltInTransformers();
  27080. usort($this->items, static function (TransformerInterface $a, TransformerInterface $b) {
  27081. return Utils::cmpInt($b->getPriority(), $a->getPriority());
  27082. });
  27083. }
  27084. public static function create()
  27085. {
  27086. static $instance = null;
  27087. if (!$instance) {
  27088. $instance = new self();
  27089. }
  27090. return $instance;
  27091. }
  27092. public function transform(Tokens $tokens)
  27093. {
  27094. foreach ($tokens as $index => $token) {
  27095. foreach ($this->items as $transformer) {
  27096. $transformer->process($tokens, $token, $index);
  27097. }
  27098. }
  27099. }
  27100. private function registerTransformer(TransformerInterface $transformer)
  27101. {
  27102. if (PHP_VERSION_ID >= $transformer->getRequiredPhpVersionId()) {
  27103. $this->items[] = $transformer;
  27104. }
  27105. }
  27106. private function registerBuiltInTransformers()
  27107. {
  27108. static $registered = false;
  27109. if ($registered) {
  27110. return;
  27111. }
  27112. $registered = true;
  27113. foreach (Finder::create()->files()->in(__DIR__.'/Transformer') as $file) {
  27114. $relativeNamespace = $file->getRelativePath();
  27115. $class = __NAMESPACE__.'\\Transformer\\'.($relativeNamespace ? $relativeNamespace.'\\' : '').$file->getBasename('.php');
  27116. $this->registerTransformer(new $class());
  27117. }
  27118. }
  27119. }
  27120. <?php
  27121. namespace PhpCsFixer;
  27122. use PhpCsFixer\Console\Application;
  27123. final class ToolInfo implements ToolInfoInterface
  27124. {
  27125. const COMPOSER_PACKAGE_NAME = 'friendsofphp/php-cs-fixer';
  27126. const COMPOSER_LEGACY_PACKAGE_NAME = 'fabpot/php-cs-fixer';
  27127. private $composerInstallationDetails;
  27128. private $isInstalledByComposer;
  27129. public function getComposerInstallationDetails()
  27130. {
  27131. if (!$this->isInstalledByComposer()) {
  27132. throw new \LogicException('Cannot get composer version for tool not installed by composer.');
  27133. }
  27134. if (null === $this->composerInstallationDetails) {
  27135. $composerInstalled = json_decode(file_get_contents($this->getComposerInstalledFile()), true);
  27136. foreach ($composerInstalled as $package) {
  27137. if (in_array($package['name'], [self::COMPOSER_PACKAGE_NAME, self::COMPOSER_LEGACY_PACKAGE_NAME], true)) {
  27138. $this->composerInstallationDetails = $package;
  27139. break;
  27140. }
  27141. }
  27142. }
  27143. return $this->composerInstallationDetails;
  27144. }
  27145. public function getComposerVersion()
  27146. {
  27147. $package = $this->getComposerInstallationDetails();
  27148. $versionSuffix = '';
  27149. if (isset($package['dist'])) {
  27150. $versionSuffix = '#'.$package['dist']['reference'];
  27151. }
  27152. return $package['version'].$versionSuffix;
  27153. }
  27154. public function getVersion()
  27155. {
  27156. if ($this->isInstalledByComposer()) {
  27157. return Application::VERSION.':'.$this->getComposerVersion();
  27158. }
  27159. return Application::VERSION;
  27160. }
  27161. public function isInstalledAsPhar()
  27162. {
  27163. return 'phar://' === substr(__DIR__, 0, 7);
  27164. }
  27165. public function isInstalledByComposer()
  27166. {
  27167. if (null === $this->isInstalledByComposer) {
  27168. $this->isInstalledByComposer = !$this->isInstalledAsPhar() && file_exists($this->getComposerInstalledFile());
  27169. }
  27170. return $this->isInstalledByComposer;
  27171. }
  27172. public function getPharDownloadUri($version)
  27173. {
  27174. return sprintf(
  27175. 'https://github.com/FriendsOfPHP/PHP-CS-Fixer/releases/download/%s/php-cs-fixer.phar',
  27176. $version
  27177. );
  27178. }
  27179. private function getComposerInstalledFile()
  27180. {
  27181. return __DIR__.'/../../../composer/installed.json';
  27182. }
  27183. }
  27184. <?php
  27185. namespace PhpCsFixer;
  27186. interface ToolInfoInterface
  27187. {
  27188. public function getComposerInstallationDetails();
  27189. public function getComposerVersion();
  27190. public function getVersion();
  27191. public function isInstalledAsPhar();
  27192. public function isInstalledByComposer();
  27193. public function getPharDownloadUri($version);
  27194. }
  27195. <?php
  27196. namespace PhpCsFixer;
  27197. use PhpCsFixer\Fixer\FixerInterface;
  27198. use PhpCsFixer\Tokenizer\Token;
  27199. final class Utils
  27200. {
  27201. public static function calculateBitmask(array $options)
  27202. {
  27203. $bitmask = 0;
  27204. foreach ($options as $optionName) {
  27205. if (defined($optionName)) {
  27206. $bitmask |= constant($optionName);
  27207. }
  27208. }
  27209. return $bitmask;
  27210. }
  27211. public static function camelCaseToUnderscore($string)
  27212. {
  27213. return preg_replace_callback(
  27214. '/(^|[a-z0-9])([A-Z])/',
  27215. static function (array $matches) {
  27216. return strtolower('' !== $matches[1] ? $matches[1].'_'.$matches[2] : $matches[2]);
  27217. },
  27218. $string
  27219. );
  27220. }
  27221. public static function cmpInt($a, $b)
  27222. {
  27223. if ($a === $b) {
  27224. return 0;
  27225. }
  27226. return $a < $b ? -1 : 1;
  27227. }
  27228. public static function splitLines($content)
  27229. {
  27230. preg_match_all("/[^\n\r]+[\r\n]*/", $content, $matches);
  27231. return $matches[0];
  27232. }
  27233. public static function calculateTrailingWhitespaceIndent(Token $token)
  27234. {
  27235. if (!$token->isWhitespace()) {
  27236. throw new \InvalidArgumentException(sprintf('The given token must be whitespace, got "%s".', $token->getName()));
  27237. }
  27238. $str = strrchr(
  27239. str_replace(["\r\n", "\r"], "\n", $token->getContent()),
  27240. "\n"
  27241. );
  27242. if (false === $str) {
  27243. return '';
  27244. }
  27245. return ltrim($str, "\n");
  27246. }
  27247. public static function stableSort(array $elements, callable $getComparedValue, callable $compareValues)
  27248. {
  27249. array_walk($elements, static function (&$element, $index) use ($getComparedValue) {
  27250. $element = [$element, $index, $getComparedValue($element)];
  27251. });
  27252. usort($elements, static function ($a, $b) use ($compareValues) {
  27253. $comparison = $compareValues($a[2], $b[2]);
  27254. if (0 !== $comparison) {
  27255. return $comparison;
  27256. }
  27257. return self::cmpInt($a[1], $b[1]);
  27258. });
  27259. return array_map(static function (array $item) {
  27260. return $item[0];
  27261. }, $elements);
  27262. }
  27263. public static function sortFixers(array $fixers)
  27264. {
  27265. return self::stableSort(
  27266. $fixers,
  27267. static function (FixerInterface $fixer) {
  27268. return $fixer->getPriority();
  27269. },
  27270. static function ($a, $b) {
  27271. return Utils::cmpInt($b, $a);
  27272. }
  27273. );
  27274. }
  27275. public static function naturalLanguageJoinWithBackticks(array $names)
  27276. {
  27277. if (empty($names)) {
  27278. throw new \InvalidArgumentException('Array of names cannot be empty');
  27279. }
  27280. $names = array_map(static function ($name) {
  27281. return sprintf('`%s`', $name);
  27282. }, $names);
  27283. $last = array_pop($names);
  27284. if ($names) {
  27285. return implode(', ', $names).' and '.$last;
  27286. }
  27287. return $last;
  27288. }
  27289. }
  27290. <?php
  27291. namespace PhpCsFixer;
  27292. final class WhitespacesFixerConfig
  27293. {
  27294. private $indent;
  27295. private $lineEnding;
  27296. public function __construct($indent = ' ', $lineEnding = "\n")
  27297. {
  27298. if (!in_array($indent, [' ', ' ', "\t"], true)) {
  27299. throw new \InvalidArgumentException('Invalid "indent" param, expected tab or two or four spaces.');
  27300. }
  27301. if (!in_array($lineEnding, ["\n", "\r\n"], true)) {
  27302. throw new \InvalidArgumentException('Invalid "lineEnding" param, expected "\n" or "\r\n".');
  27303. }
  27304. $this->indent = $indent;
  27305. $this->lineEnding = $lineEnding;
  27306. }
  27307. public function getIndent()
  27308. {
  27309. return $this->indent;
  27310. }
  27311. public function getLineEnding()
  27312. {
  27313. return $this->lineEnding;
  27314. }
  27315. }
  27316. <?php
  27317. namespace PhpCsFixer;
  27318. final class WordMatcher
  27319. {
  27320. private $candidates;
  27321. public function __construct(array $candidates)
  27322. {
  27323. $this->candidates = $candidates;
  27324. }
  27325. public function match($needle)
  27326. {
  27327. $word = null;
  27328. $distance = ceil(strlen($needle) * 0.35);
  27329. foreach ($this->candidates as $candidate) {
  27330. $candidateDistance = levenshtein($needle, $candidate);
  27331. if ($candidateDistance < $distance) {
  27332. $word = $candidate;
  27333. $distance = $candidateDistance;
  27334. }
  27335. }
  27336. return $word;
  27337. }
  27338. }
  27339. <?php
  27340. namespace PhpCsFixer\Diff\GeckoPackages\DiffOutputBuilder;
  27341. use Exception;
  27342. final class ConfigurationException extends \InvalidArgumentException
  27343. {
  27344. public function __construct(
  27345. $option,
  27346. $expected,
  27347. $value,
  27348. $code = 0,
  27349. Exception $previous = null
  27350. ) {
  27351. parent::__construct(
  27352. \sprintf(
  27353. 'Option "%s" must be %s, got "%s".',
  27354. $option,
  27355. $expected,
  27356. \is_object($value) ? \get_class($value) : (null === $value ? '<null>' : \gettype($value).'#'.$value)
  27357. ),
  27358. $code,
  27359. $previous
  27360. );
  27361. }
  27362. }
  27363. <?php
  27364. namespace PhpCsFixer\Diff\GeckoPackages\DiffOutputBuilder;
  27365. use PhpCsFixer\Diff\v2_0\Output\DiffOutputBuilderInterface;
  27366. final class UnifiedDiffOutputBuilder implements DiffOutputBuilderInterface
  27367. {
  27368. private static $noNewlineAtOEFid = 998877;
  27369. private $changed;
  27370. private $collapseRanges;
  27371. private $commonLineThreshold;
  27372. private $header;
  27373. private $contextLines;
  27374. private static $default = [
  27375. 'contextLines' => 3,
  27376. 'collapseRanges' => true,
  27377. 'fromFile' => null,
  27378. 'fromFileDate' => null,
  27379. 'toFile' => null,
  27380. 'toFileDate' => null,
  27381. 'commonLineThreshold' => 6,
  27382. ];
  27383. public function __construct(array $options = [])
  27384. {
  27385. $options = \array_merge(self::$default, $options);
  27386. if (!\is_bool($options['collapseRanges'])) {
  27387. throw new ConfigurationException('collapseRanges', 'a bool', $options['collapseRanges']);
  27388. }
  27389. if (!\is_int($options['contextLines']) || $options['contextLines'] < 0) {
  27390. throw new ConfigurationException('contextLines', 'an int >= 0', $options['contextLines']);
  27391. }
  27392. if (!\is_int($options['commonLineThreshold']) || $options['commonLineThreshold'] < 1) {
  27393. throw new ConfigurationException('commonLineThreshold', 'an int > 0', $options['commonLineThreshold']);
  27394. }
  27395. foreach (['fromFile', 'toFile'] as $option) {
  27396. if (!\is_string($options[$option])) {
  27397. throw new ConfigurationException($option, 'a string', $options[$option]);
  27398. }
  27399. }
  27400. foreach (['fromFileDate', 'toFileDate'] as $option) {
  27401. if (null !== $options[$option] && !\is_string($options[$option])) {
  27402. throw new ConfigurationException($option, 'a string or <null>', $options[$option]);
  27403. }
  27404. }
  27405. $this->header = \sprintf(
  27406. "--- %s%s\n+++ %s%s\n",
  27407. $options['fromFile'],
  27408. null === $options['fromFileDate'] ? '' : "\t".$options['fromFileDate'],
  27409. $options['toFile'],
  27410. null === $options['toFileDate'] ? '' : "\t".$options['toFileDate']
  27411. );
  27412. $this->collapseRanges = $options['collapseRanges'];
  27413. $this->commonLineThreshold = $options['commonLineThreshold'];
  27414. $this->contextLines = $options['contextLines'];
  27415. }
  27416. public function getDiff(array $diff)
  27417. {
  27418. if (0 === \count($diff)) {
  27419. return '';
  27420. }
  27421. $this->changed = false;
  27422. $buffer = \fopen('php://memory', 'r+b');
  27423. \fwrite($buffer, $this->header);
  27424. $this->writeDiffHunks($buffer, $diff);
  27425. $diff = \stream_get_contents($buffer, -1, 0);
  27426. \fclose($buffer);
  27427. if (!$this->changed) {
  27428. return '';
  27429. }
  27430. return $diff;
  27431. }
  27432. private function writeDiffHunks($output, array $diff)
  27433. {
  27434. $upperLimit = \count($diff);
  27435. if (0 === $diff[$upperLimit - 1][1]) {
  27436. $lc = \substr($diff[$upperLimit - 1][0], -1);
  27437. if ("\n" !== $lc) {
  27438. \array_splice($diff, $upperLimit, 0, [["\n\\ No newline at end of file\n", self::$noNewlineAtOEFid]]);
  27439. }
  27440. } else {
  27441. $toFind = [1 => true, 2 => true];
  27442. for ($i = $upperLimit - 1; $i >= 0; --$i) {
  27443. if (isset($toFind[$diff[$i][1]])) {
  27444. unset($toFind[$diff[$i][1]]);
  27445. $lc = \substr($diff[$i][0], -1);
  27446. if ("\n" !== $lc) {
  27447. \array_splice($diff, $i + 1, 0, [["\n\\ No newline at end of file\n", self::$noNewlineAtOEFid]]);
  27448. }
  27449. if (!\count($toFind)) {
  27450. break;
  27451. }
  27452. }
  27453. }
  27454. }
  27455. $cutOff = \max($this->commonLineThreshold, $this->contextLines);
  27456. $hunkCapture = false;
  27457. $sameCount = $toRange = $fromRange = 0;
  27458. $toStart = $fromStart = 1;
  27459. foreach ($diff as $i => $entry) {
  27460. if (0 === $entry[1]) {
  27461. if (false === $hunkCapture) {
  27462. ++$fromStart;
  27463. ++$toStart;
  27464. continue;
  27465. }
  27466. ++$sameCount;
  27467. ++$toRange;
  27468. ++$fromRange;
  27469. if ($sameCount === $cutOff) {
  27470. $contextStartOffset = $hunkCapture - $this->contextLines < 0
  27471. ? $hunkCapture
  27472. : $this->contextLines
  27473. ;
  27474. $contextEndOffset = $i + $this->contextLines >= \count($diff)
  27475. ? \count($diff) - $i
  27476. : $this->contextLines
  27477. ;
  27478. $this->writeHunk(
  27479. $diff,
  27480. $hunkCapture - $contextStartOffset,
  27481. $i - $cutOff + $contextEndOffset + 1,
  27482. $fromStart - $contextStartOffset,
  27483. $fromRange - $cutOff + $contextStartOffset + $contextEndOffset,
  27484. $toStart - $contextStartOffset,
  27485. $toRange - $cutOff + $contextStartOffset + $contextEndOffset,
  27486. $output
  27487. );
  27488. $fromStart += $fromRange;
  27489. $toStart += $toRange;
  27490. $hunkCapture = false;
  27491. $sameCount = $toRange = $fromRange = 0;
  27492. }
  27493. continue;
  27494. }
  27495. $sameCount = 0;
  27496. if ($entry[1] === self::$noNewlineAtOEFid) {
  27497. continue;
  27498. }
  27499. $this->changed = true;
  27500. if (false === $hunkCapture) {
  27501. $hunkCapture = $i;
  27502. }
  27503. if (1 === $entry[1]) {
  27504. ++$toRange;
  27505. }
  27506. if (2 === $entry[1]) {
  27507. ++$fromRange;
  27508. }
  27509. }
  27510. if (false !== $hunkCapture) {
  27511. $contextStartOffset = $hunkCapture - $this->contextLines < 0
  27512. ? $hunkCapture
  27513. : $this->contextLines
  27514. ;
  27515. $this->writeHunk(
  27516. $diff,
  27517. $hunkCapture - $contextStartOffset,
  27518. \count($diff),
  27519. $fromStart - $contextStartOffset,
  27520. $fromRange + $contextStartOffset,
  27521. $toStart - $contextStartOffset,
  27522. $toRange + $contextStartOffset,
  27523. $output
  27524. );
  27525. }
  27526. }
  27527. private function writeHunk(
  27528. array $diff,
  27529. $diffStartIndex,
  27530. $diffEndIndex,
  27531. $fromStart,
  27532. $fromRange,
  27533. $toStart,
  27534. $toRange,
  27535. $output
  27536. ) {
  27537. \fwrite($output, '@@ -'.$fromStart);
  27538. if (!$this->collapseRanges || 1 !== $fromRange) {
  27539. \fwrite($output, ','.$fromRange);
  27540. }
  27541. \fwrite($output, ' +'.$toStart);
  27542. if (!$this->collapseRanges || 1 !== $toRange) {
  27543. \fwrite($output, ','.$toRange);
  27544. }
  27545. \fwrite($output, " @@\n");
  27546. for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
  27547. if ($diff[$i][1] === 1) {
  27548. $this->changed = true;
  27549. \fwrite($output, '+'.$diff[$i][0]);
  27550. } elseif ($diff[$i][1] === 2) {
  27551. $this->changed = true;
  27552. \fwrite($output, '-'.$diff[$i][0]);
  27553. } elseif ($diff[$i][1] === 0) {
  27554. \fwrite($output, ' '.$diff[$i][0]);
  27555. } elseif ($diff[$i][1] === self::$noNewlineAtOEFid) {
  27556. $this->changed = true;
  27557. \fwrite($output, $diff[$i][0]);
  27558. }
  27559. }
  27560. }
  27561. }
  27562. <?php
  27563. namespace PhpCsFixer\Diff\v1_4;
  27564. class Chunk
  27565. {
  27566. private $start;
  27567. private $startRange;
  27568. private $end;
  27569. private $endRange;
  27570. private $lines;
  27571. public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = array())
  27572. {
  27573. $this->start = (int) $start;
  27574. $this->startRange = (int) $startRange;
  27575. $this->end = (int) $end;
  27576. $this->endRange = (int) $endRange;
  27577. $this->lines = $lines;
  27578. }
  27579. public function getStart()
  27580. {
  27581. return $this->start;
  27582. }
  27583. public function getStartRange()
  27584. {
  27585. return $this->startRange;
  27586. }
  27587. public function getEnd()
  27588. {
  27589. return $this->end;
  27590. }
  27591. public function getEndRange()
  27592. {
  27593. return $this->endRange;
  27594. }
  27595. public function getLines()
  27596. {
  27597. return $this->lines;
  27598. }
  27599. public function setLines(array $lines)
  27600. {
  27601. $this->lines = $lines;
  27602. }
  27603. }
  27604. <?php
  27605. namespace PhpCsFixer\Diff\v1_4;
  27606. class Diff
  27607. {
  27608. private $from;
  27609. private $to;
  27610. private $chunks;
  27611. public function __construct($from, $to, array $chunks = array())
  27612. {
  27613. $this->from = $from;
  27614. $this->to = $to;
  27615. $this->chunks = $chunks;
  27616. }
  27617. public function getFrom()
  27618. {
  27619. return $this->from;
  27620. }
  27621. public function getTo()
  27622. {
  27623. return $this->to;
  27624. }
  27625. public function getChunks()
  27626. {
  27627. return $this->chunks;
  27628. }
  27629. public function setChunks(array $chunks)
  27630. {
  27631. $this->chunks = $chunks;
  27632. }
  27633. }
  27634. <?php
  27635. namespace PhpCsFixer\Diff\v1_4;
  27636. use PhpCsFixer\Diff\v1_4\LCS\LongestCommonSubsequence;
  27637. use PhpCsFixer\Diff\v1_4\LCS\TimeEfficientImplementation;
  27638. use PhpCsFixer\Diff\v1_4\LCS\MemoryEfficientImplementation;
  27639. class Differ
  27640. {
  27641. private $header;
  27642. private $showNonDiffLines;
  27643. public function __construct($header = "--- Original\n+++ New\n", $showNonDiffLines = true)
  27644. {
  27645. $this->header = $header;
  27646. $this->showNonDiffLines = $showNonDiffLines;
  27647. }
  27648. public function diff($from, $to, LongestCommonSubsequence $lcs = null)
  27649. {
  27650. $from = $this->validateDiffInput($from);
  27651. $to = $this->validateDiffInput($to);
  27652. $diff = $this->diffToArray($from, $to, $lcs);
  27653. $old = $this->checkIfDiffInOld($diff);
  27654. $start = isset($old[0]) ? $old[0] : 0;
  27655. $end = \count($diff);
  27656. if ($tmp = \array_search($end, $old)) {
  27657. $end = $tmp;
  27658. }
  27659. return $this->getBuffer($diff, $old, $start, $end);
  27660. }
  27661. private function validateDiffInput($input)
  27662. {
  27663. if (!\is_array($input) && !\is_string($input)) {
  27664. return (string) $input;
  27665. }
  27666. return $input;
  27667. }
  27668. private function checkIfDiffInOld(array $diff)
  27669. {
  27670. $inOld = false;
  27671. $i = 0;
  27672. $old = array();
  27673. foreach ($diff as $line) {
  27674. if ($line[1] === 0 ) {
  27675. if ($inOld === false) {
  27676. $inOld = $i;
  27677. }
  27678. } elseif ($inOld !== false) {
  27679. if (($i - $inOld) > 5) {
  27680. $old[$inOld] = $i - 1;
  27681. }
  27682. $inOld = false;
  27683. }
  27684. ++$i;
  27685. }
  27686. return $old;
  27687. }
  27688. private function getBuffer(array $diff, array $old, $start, $end)
  27689. {
  27690. $buffer = $this->header;
  27691. if (!isset($old[$start])) {
  27692. $buffer = $this->getDiffBufferElementNew($diff, $buffer, $start);
  27693. ++$start;
  27694. }
  27695. for ($i = $start; $i < $end; $i++) {
  27696. if (isset($old[$i])) {
  27697. $i = $old[$i];
  27698. $buffer = $this->getDiffBufferElementNew($diff, $buffer, $i);
  27699. } else {
  27700. $buffer = $this->getDiffBufferElement($diff, $buffer, $i);
  27701. }
  27702. }
  27703. return $buffer;
  27704. }
  27705. private function getDiffBufferElement(array $diff, $buffer, $diffIndex)
  27706. {
  27707. if ($diff[$diffIndex][1] === 1 ) {
  27708. $buffer .= '+' . $diff[$diffIndex][0] . "\n";
  27709. } elseif ($diff[$diffIndex][1] === 2 ) {
  27710. $buffer .= '-' . $diff[$diffIndex][0] . "\n";
  27711. } elseif ($this->showNonDiffLines === true) {
  27712. $buffer .= ' ' . $diff[$diffIndex][0] . "\n";
  27713. }
  27714. return $buffer;
  27715. }
  27716. private function getDiffBufferElementNew(array $diff, $buffer, $diffIndex)
  27717. {
  27718. if ($this->showNonDiffLines === true) {
  27719. $buffer .= "@@ @@\n";
  27720. }
  27721. return $this->getDiffBufferElement($diff, $buffer, $diffIndex);
  27722. }
  27723. public function diffToArray($from, $to, LongestCommonSubsequence $lcs = null)
  27724. {
  27725. if (\is_string($from)) {
  27726. $fromMatches = $this->getNewLineMatches($from);
  27727. $from = $this->splitStringByLines($from);
  27728. } elseif (\is_array($from)) {
  27729. $fromMatches = array();
  27730. } else {
  27731. throw new \InvalidArgumentException('"from" must be an array or string.');
  27732. }
  27733. if (\is_string($to)) {
  27734. $toMatches = $this->getNewLineMatches($to);
  27735. $to = $this->splitStringByLines($to);
  27736. } elseif (\is_array($to)) {
  27737. $toMatches = array();
  27738. } else {
  27739. throw new \InvalidArgumentException('"to" must be an array or string.');
  27740. }
  27741. list($from, $to, $start, $end) = self::getArrayDiffParted($from, $to);
  27742. if ($lcs === null) {
  27743. $lcs = $this->selectLcsImplementation($from, $to);
  27744. }
  27745. $common = $lcs->calculate(\array_values($from), \array_values($to));
  27746. $diff = array();
  27747. if ($this->detectUnmatchedLineEndings($fromMatches, $toMatches)) {
  27748. $diff[] = array(
  27749. '#Warning: Strings contain different line endings!',
  27750. 0
  27751. );
  27752. }
  27753. foreach ($start as $token) {
  27754. $diff[] = array($token, 0 );
  27755. }
  27756. \reset($from);
  27757. \reset($to);
  27758. foreach ($common as $token) {
  27759. while (($fromToken = \reset($from)) !== $token) {
  27760. $diff[] = array(\array_shift($from), 2 );
  27761. }
  27762. while (($toToken = \reset($to)) !== $token) {
  27763. $diff[] = array(\array_shift($to), 1 );
  27764. }
  27765. $diff[] = array($token, 0 );
  27766. \array_shift($from);
  27767. \array_shift($to);
  27768. }
  27769. while (($token = \array_shift($from)) !== null) {
  27770. $diff[] = array($token, 2 );
  27771. }
  27772. while (($token = \array_shift($to)) !== null) {
  27773. $diff[] = array($token, 1 );
  27774. }
  27775. foreach ($end as $token) {
  27776. $diff[] = array($token, 0 );
  27777. }
  27778. return $diff;
  27779. }
  27780. private function getNewLineMatches($string)
  27781. {
  27782. \preg_match_all('(\r\n|\r|\n)', $string, $stringMatches);
  27783. return $stringMatches;
  27784. }
  27785. private function splitStringByLines($input)
  27786. {
  27787. return \preg_split('(\r\n|\r|\n)', $input);
  27788. }
  27789. private function selectLcsImplementation(array $from, array $to)
  27790. {
  27791. $memoryLimit = 100 * 1024 * 1024;
  27792. if ($this->calculateEstimatedFootprint($from, $to) > $memoryLimit) {
  27793. return new MemoryEfficientImplementation;
  27794. }
  27795. return new TimeEfficientImplementation;
  27796. }
  27797. private function calculateEstimatedFootprint(array $from, array $to)
  27798. {
  27799. $itemSize = PHP_INT_SIZE === 4 ? 76 : 144;
  27800. return $itemSize * \pow(\min(\count($from), \count($to)), 2);
  27801. }
  27802. private function detectUnmatchedLineEndings(array $fromMatches, array $toMatches)
  27803. {
  27804. return isset($fromMatches[0], $toMatches[0]) &&
  27805. \count($fromMatches[0]) === \count($toMatches[0]) &&
  27806. $fromMatches[0] !== $toMatches[0];
  27807. }
  27808. private static function getArrayDiffParted(array &$from, array &$to)
  27809. {
  27810. $start = array();
  27811. $end = array();
  27812. \reset($to);
  27813. foreach ($from as $k => $v) {
  27814. $toK = \key($to);
  27815. if ($toK === $k && $v === $to[$k]) {
  27816. $start[$k] = $v;
  27817. unset($from[$k], $to[$k]);
  27818. } else {
  27819. break;
  27820. }
  27821. }
  27822. \end($from);
  27823. \end($to);
  27824. do {
  27825. $fromK = \key($from);
  27826. $toK = \key($to);
  27827. if (null === $fromK || null === $toK || \current($from) !== \current($to)) {
  27828. break;
  27829. }
  27830. \prev($from);
  27831. \prev($to);
  27832. $end = array($fromK => $from[$fromK]) + $end;
  27833. unset($from[$fromK], $to[$toK]);
  27834. } while (true);
  27835. return array($from, $to, $start, $end);
  27836. }
  27837. }
  27838. <?php
  27839. namespace PhpCsFixer\Diff\v1_4\LCS;
  27840. interface LongestCommonSubsequence
  27841. {
  27842. public function calculate(array $from, array $to);
  27843. }
  27844. <?php
  27845. namespace PhpCsFixer\Diff\v1_4\LCS;
  27846. class MemoryEfficientImplementation implements LongestCommonSubsequence
  27847. {
  27848. public function calculate(array $from, array $to)
  27849. {
  27850. $cFrom = \count($from);
  27851. $cTo = \count($to);
  27852. if ($cFrom === 0) {
  27853. return array();
  27854. }
  27855. if ($cFrom === 1) {
  27856. if (\in_array($from[0], $to, true)) {
  27857. return array($from[0]);
  27858. }
  27859. return array();
  27860. }
  27861. $i = (int) ($cFrom / 2);
  27862. $fromStart = \array_slice($from, 0, $i);
  27863. $fromEnd = \array_slice($from, $i);
  27864. $llB = $this->length($fromStart, $to);
  27865. $llE = $this->length(\array_reverse($fromEnd), \array_reverse($to));
  27866. $jMax = 0;
  27867. $max = 0;
  27868. for ($j = 0; $j <= $cTo; $j++) {
  27869. $m = $llB[$j] + $llE[$cTo - $j];
  27870. if ($m >= $max) {
  27871. $max = $m;
  27872. $jMax = $j;
  27873. }
  27874. }
  27875. $toStart = \array_slice($to, 0, $jMax);
  27876. $toEnd = \array_slice($to, $jMax);
  27877. return \array_merge(
  27878. $this->calculate($fromStart, $toStart),
  27879. $this->calculate($fromEnd, $toEnd)
  27880. );
  27881. }
  27882. private function length(array $from, array $to)
  27883. {
  27884. $current = \array_fill(0, \count($to) + 1, 0);
  27885. $cFrom = \count($from);
  27886. $cTo = \count($to);
  27887. for ($i = 0; $i < $cFrom; $i++) {
  27888. $prev = $current;
  27889. for ($j = 0; $j < $cTo; $j++) {
  27890. if ($from[$i] === $to[$j]) {
  27891. $current[$j + 1] = $prev[$j] + 1;
  27892. } else {
  27893. $current[$j + 1] = \max($current[$j], $prev[$j + 1]);
  27894. }
  27895. }
  27896. }
  27897. return $current;
  27898. }
  27899. }
  27900. <?php
  27901. namespace PhpCsFixer\Diff\v1_4\LCS;
  27902. class TimeEfficientImplementation implements LongestCommonSubsequence
  27903. {
  27904. public function calculate(array $from, array $to)
  27905. {
  27906. $common = array();
  27907. $fromLength = \count($from);
  27908. $toLength = \count($to);
  27909. $width = $fromLength + 1;
  27910. $matrix = new \SplFixedArray($width * ($toLength + 1));
  27911. for ($i = 0; $i <= $fromLength; ++$i) {
  27912. $matrix[$i] = 0;
  27913. }
  27914. for ($j = 0; $j <= $toLength; ++$j) {
  27915. $matrix[$j * $width] = 0;
  27916. }
  27917. for ($i = 1; $i <= $fromLength; ++$i) {
  27918. for ($j = 1; $j <= $toLength; ++$j) {
  27919. $o = ($j * $width) + $i;
  27920. $matrix[$o] = \max(
  27921. $matrix[$o - 1],
  27922. $matrix[$o - $width],
  27923. $from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0
  27924. );
  27925. }
  27926. }
  27927. $i = $fromLength;
  27928. $j = $toLength;
  27929. while ($i > 0 && $j > 0) {
  27930. if ($from[$i - 1] === $to[$j - 1]) {
  27931. $common[] = $from[$i - 1];
  27932. --$i;
  27933. --$j;
  27934. } else {
  27935. $o = ($j * $width) + $i;
  27936. if ($matrix[$o - $width] > $matrix[$o - 1]) {
  27937. --$j;
  27938. } else {
  27939. --$i;
  27940. }
  27941. }
  27942. }
  27943. return \array_reverse($common);
  27944. }
  27945. }
  27946. <?php
  27947. namespace PhpCsFixer\Diff\v1_4;
  27948. class Line
  27949. {
  27950. const ADDED = 1;
  27951. const REMOVED = 2;
  27952. const UNCHANGED = 3;
  27953. private $type;
  27954. private $content;
  27955. public function __construct($type = self::UNCHANGED, $content = '')
  27956. {
  27957. $this->type = $type;
  27958. $this->content = $content;
  27959. }
  27960. public function getContent()
  27961. {
  27962. return $this->content;
  27963. }
  27964. public function getType()
  27965. {
  27966. return $this->type;
  27967. }
  27968. }
  27969. <?php
  27970. namespace PhpCsFixer\Diff\v1_4;
  27971. class Parser
  27972. {
  27973. public function parse($string)
  27974. {
  27975. $lines = \preg_split('(\r\n|\r|\n)', $string);
  27976. if (!empty($lines) && $lines[\count($lines) - 1] == '') {
  27977. \array_pop($lines);
  27978. }
  27979. $lineCount = \count($lines);
  27980. $diffs = array();
  27981. $diff = null;
  27982. $collected = array();
  27983. for ($i = 0; $i < $lineCount; ++$i) {
  27984. if (\preg_match('(^---\\s+(?P<file>\\S+))', $lines[$i], $fromMatch) &&
  27985. \preg_match('(^\\+\\+\\+\\s+(?P<file>\\S+))', $lines[$i + 1], $toMatch)) {
  27986. if ($diff !== null) {
  27987. $this->parseFileDiff($diff, $collected);
  27988. $diffs[] = $diff;
  27989. $collected = array();
  27990. }
  27991. $diff = new Diff($fromMatch['file'], $toMatch['file']);
  27992. ++$i;
  27993. } else {
  27994. if (\preg_match('/^(?:diff --git |index [\da-f\.]+|[+-]{3} [ab])/', $lines[$i])) {
  27995. continue;
  27996. }
  27997. $collected[] = $lines[$i];
  27998. }
  27999. }
  28000. if ($diff !== null && \count($collected)) {
  28001. $this->parseFileDiff($diff, $collected);
  28002. $diffs[] = $diff;
  28003. }
  28004. return $diffs;
  28005. }
  28006. private function parseFileDiff(Diff $diff, array $lines)
  28007. {
  28008. $chunks = array();
  28009. $chunk = null;
  28010. foreach ($lines as $line) {
  28011. if (\preg_match('/^@@\s+-(?P<start>\d+)(?:,\s*(?P<startrange>\d+))?\s+\+(?P<end>\d+)(?:,\s*(?P<endrange>\d+))?\s+@@/', $line, $match)) {
  28012. $chunk = new Chunk(
  28013. $match['start'],
  28014. isset($match['startrange']) ? \max(1, $match['startrange']) : 1,
  28015. $match['end'],
  28016. isset($match['endrange']) ? \max(1, $match['endrange']) : 1
  28017. );
  28018. $chunks[] = $chunk;
  28019. $diffLines = array();
  28020. continue;
  28021. }
  28022. if (\preg_match('/^(?P<type>[+ -])?(?P<line>.*)/', $line, $match)) {
  28023. $type = Line::UNCHANGED;
  28024. if ($match['type'] === '+') {
  28025. $type = Line::ADDED;
  28026. } elseif ($match['type'] === '-') {
  28027. $type = Line::REMOVED;
  28028. }
  28029. $diffLines[] = new Line($type, $match['line']);
  28030. if (null !== $chunk) {
  28031. $chunk->setLines($diffLines);
  28032. }
  28033. }
  28034. }
  28035. $diff->setChunks($chunks);
  28036. }
  28037. }
  28038. <?php
  28039. namespace PhpCsFixer\Diff\v2_0;
  28040. final class Chunk
  28041. {
  28042. private $start;
  28043. private $startRange;
  28044. private $end;
  28045. private $endRange;
  28046. private $lines;
  28047. public function __construct($start = 0, $startRange = 1, $end = 0, $endRange = 1, array $lines = [])
  28048. {
  28049. $this->start = $start;
  28050. $this->startRange = $startRange;
  28051. $this->end = $end;
  28052. $this->endRange = $endRange;
  28053. $this->lines = $lines;
  28054. }
  28055. public function getStart()
  28056. {
  28057. return $this->start;
  28058. }
  28059. public function getStartRange()
  28060. {
  28061. return $this->startRange;
  28062. }
  28063. public function getEnd()
  28064. {
  28065. return $this->end;
  28066. }
  28067. public function getEndRange()
  28068. {
  28069. return $this->endRange;
  28070. }
  28071. public function getLines()
  28072. {
  28073. return $this->lines;
  28074. }
  28075. public function setLines(array $lines)
  28076. {
  28077. $this->lines = $lines;
  28078. }
  28079. }
  28080. <?php
  28081. namespace PhpCsFixer\Diff\v2_0;
  28082. final class Diff
  28083. {
  28084. private $from;
  28085. private $to;
  28086. private $chunks;
  28087. public function __construct($from, $to, array $chunks = [])
  28088. {
  28089. $this->from = $from;
  28090. $this->to = $to;
  28091. $this->chunks = $chunks;
  28092. }
  28093. public function getFrom()
  28094. {
  28095. return $this->from;
  28096. }
  28097. public function getTo()
  28098. {
  28099. return $this->to;
  28100. }
  28101. public function getChunks()
  28102. {
  28103. return $this->chunks;
  28104. }
  28105. public function setChunks(array $chunks)
  28106. {
  28107. $this->chunks = $chunks;
  28108. }
  28109. }
  28110. <?php
  28111. namespace PhpCsFixer\Diff\v2_0;
  28112. use PhpCsFixer\Diff\v2_0\Output\DiffOutputBuilderInterface;
  28113. use PhpCsFixer\Diff\v2_0\Output\UnifiedDiffOutputBuilder;
  28114. final class Differ
  28115. {
  28116. private $outputBuilder;
  28117. public function __construct($outputBuilder = null)
  28118. {
  28119. if ($outputBuilder instanceof DiffOutputBuilderInterface) {
  28120. $this->outputBuilder = $outputBuilder;
  28121. } elseif (null === $outputBuilder) {
  28122. $this->outputBuilder = new UnifiedDiffOutputBuilder;
  28123. } elseif (\is_string($outputBuilder)) {
  28124. $this->outputBuilder = new UnifiedDiffOutputBuilder($outputBuilder);
  28125. } else {
  28126. throw new InvalidArgumentException(
  28127. \sprintf(
  28128. 'Expected builder to be an instance of DiffOutputBuilderInterface, <null> or a string, got %s.',
  28129. \is_object($outputBuilder) ? 'instance of "' . \get_class($outputBuilder) . '"' : \gettype($outputBuilder) . ' "' . $outputBuilder . '"'
  28130. )
  28131. );
  28132. }
  28133. }
  28134. public function diff($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
  28135. {
  28136. $from = $this->validateDiffInput($from);
  28137. $to = $this->validateDiffInput($to);
  28138. $diff = $this->diffToArray($from, $to, $lcs);
  28139. return $this->outputBuilder->getDiff($diff);
  28140. }
  28141. private function validateDiffInput($input)
  28142. {
  28143. if (!\is_array($input) && !\is_string($input)) {
  28144. return (string) $input;
  28145. }
  28146. return $input;
  28147. }
  28148. public function diffToArray($from, $to, LongestCommonSubsequenceCalculator $lcs = null)
  28149. {
  28150. if (\is_string($from)) {
  28151. $from = $this->splitStringByLines($from);
  28152. } elseif (!\is_array($from)) {
  28153. throw new \InvalidArgumentException('"from" must be an array or string.');
  28154. }
  28155. if (\is_string($to)) {
  28156. $to = $this->splitStringByLines($to);
  28157. } elseif (!\is_array($to)) {
  28158. throw new \InvalidArgumentException('"to" must be an array or string.');
  28159. }
  28160. list($from, $to, $start, $end) = self::getArrayDiffParted($from, $to);
  28161. if ($lcs === null) {
  28162. $lcs = $this->selectLcsImplementation($from, $to);
  28163. }
  28164. $common = $lcs->calculate(\array_values($from), \array_values($to));
  28165. $diff = [];
  28166. foreach ($start as $token) {
  28167. $diff[] = [$token, 0 ];
  28168. }
  28169. \reset($from);
  28170. \reset($to);
  28171. foreach ($common as $token) {
  28172. while (($fromToken = \reset($from)) !== $token) {
  28173. $diff[] = [\array_shift($from), 2 ];
  28174. }
  28175. while (($toToken = \reset($to)) !== $token) {
  28176. $diff[] = [\array_shift($to), 1 ];
  28177. }
  28178. $diff[] = [$token, 0 ];
  28179. \array_shift($from);
  28180. \array_shift($to);
  28181. }
  28182. while (($token = \array_shift($from)) !== null) {
  28183. $diff[] = [$token, 2 ];
  28184. }
  28185. while (($token = \array_shift($to)) !== null) {
  28186. $diff[] = [$token, 1 ];
  28187. }
  28188. foreach ($end as $token) {
  28189. $diff[] = [$token, 0 ];
  28190. }
  28191. if ($this->detectUnmatchedLineEndings($diff)) {
  28192. \array_unshift($diff, ["#Warning: Strings contain different line endings!\n", 3]);
  28193. }
  28194. return $diff;
  28195. }
  28196. private function splitStringByLines($input)
  28197. {
  28198. return \preg_split('/(.*\R)/', $input, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
  28199. }
  28200. private function selectLcsImplementation(array $from, array $to)
  28201. {
  28202. $memoryLimit = 100 * 1024 * 1024;
  28203. if ($this->calculateEstimatedFootprint($from, $to) > $memoryLimit) {
  28204. return new MemoryEfficientLongestCommonSubsequenceCalculator;
  28205. }
  28206. return new TimeEfficientLongestCommonSubsequenceCalculator;
  28207. }
  28208. private function calculateEstimatedFootprint(array $from, array $to)
  28209. {
  28210. $itemSize = PHP_INT_SIZE === 4 ? 76 : 144;
  28211. return $itemSize * \min(\count($from), \count($to)) ** 2;
  28212. }
  28213. private function detectUnmatchedLineEndings(array $diff)
  28214. {
  28215. $newLineBreaks = ['' => true];
  28216. $oldLineBreaks = ['' => true];
  28217. foreach ($diff as $entry) {
  28218. if (0 === $entry[1]) {
  28219. $ln = $this->getLinebreak($entry[0]);
  28220. $oldLineBreaks[$ln] = true;
  28221. $newLineBreaks[$ln] = true;
  28222. } elseif (1 === $entry[1]) {
  28223. $newLineBreaks[$this->getLinebreak($entry[0])] = true;
  28224. } elseif (2 === $entry[1]) {
  28225. $oldLineBreaks[$this->getLinebreak($entry[0])] = true;
  28226. }
  28227. }
  28228. if (['' => true] === $newLineBreaks || ['' => true] === $oldLineBreaks) {
  28229. return false;
  28230. }
  28231. foreach ($newLineBreaks as $break => $set) {
  28232. if (!isset($oldLineBreaks[$break])) {
  28233. return true;
  28234. }
  28235. }
  28236. foreach ($oldLineBreaks as $break => $set) {
  28237. if (!isset($newLineBreaks[$break])) {
  28238. return true;
  28239. }
  28240. }
  28241. return false;
  28242. }
  28243. private function getLinebreak($line)
  28244. {
  28245. if (!\is_string($line)) {
  28246. return '';
  28247. }
  28248. $lc = \substr($line, -1);
  28249. if ("\r" === $lc) {
  28250. return "\r";
  28251. }
  28252. if ("\n" !== $lc) {
  28253. return '';
  28254. }
  28255. if ("\r\n" === \substr($line, -2)) {
  28256. return "\r\n";
  28257. }
  28258. return "\n";
  28259. }
  28260. private static function getArrayDiffParted(array &$from, array &$to)
  28261. {
  28262. $start = [];
  28263. $end = [];
  28264. \reset($to);
  28265. foreach ($from as $k => $v) {
  28266. $toK = \key($to);
  28267. if ($toK === $k && $v === $to[$k]) {
  28268. $start[$k] = $v;
  28269. unset($from[$k], $to[$k]);
  28270. } else {
  28271. break;
  28272. }
  28273. }
  28274. \end($from);
  28275. \end($to);
  28276. do {
  28277. $fromK = \key($from);
  28278. $toK = \key($to);
  28279. if (null === $fromK || null === $toK || \current($from) !== \current($to)) {
  28280. break;
  28281. }
  28282. \prev($from);
  28283. \prev($to);
  28284. $end = [$fromK => $from[$fromK]] + $end;
  28285. unset($from[$fromK], $to[$toK]);
  28286. } while (true);
  28287. return [$from, $to, $start, $end];
  28288. }
  28289. }
  28290. <?php
  28291. namespace PhpCsFixer\Diff\v2_0;
  28292. interface Exception
  28293. {
  28294. }
  28295. <?php
  28296. namespace PhpCsFixer\Diff\v2_0;
  28297. class InvalidArgumentException extends \InvalidArgumentException implements Exception
  28298. {
  28299. }
  28300. <?php
  28301. namespace PhpCsFixer\Diff\v2_0;
  28302. final class Line
  28303. {
  28304. const ADDED = 1;
  28305. const REMOVED = 2;
  28306. const UNCHANGED = 3;
  28307. private $type;
  28308. private $content;
  28309. public function __construct($type = self::UNCHANGED, $content = '')
  28310. {
  28311. $this->type = $type;
  28312. $this->content = $content;
  28313. }
  28314. public function getContent()
  28315. {
  28316. return $this->content;
  28317. }
  28318. public function getType()
  28319. {
  28320. return $this->type;
  28321. }
  28322. }
  28323. <?php
  28324. namespace PhpCsFixer\Diff\v2_0;
  28325. interface LongestCommonSubsequenceCalculator
  28326. {
  28327. public function calculate(array $from, array $to);
  28328. }
  28329. <?php
  28330. namespace PhpCsFixer\Diff\v2_0;
  28331. final class MemoryEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
  28332. {
  28333. public function calculate(array $from, array $to)
  28334. {
  28335. $cFrom = \count($from);
  28336. $cTo = \count($to);
  28337. if ($cFrom === 0) {
  28338. return [];
  28339. }
  28340. if ($cFrom === 1) {
  28341. if (\in_array($from[0], $to, true)) {
  28342. return [$from[0]];
  28343. }
  28344. return [];
  28345. }
  28346. $i = (int) ($cFrom / 2);
  28347. $fromStart = \array_slice($from, 0, $i);
  28348. $fromEnd = \array_slice($from, $i);
  28349. $llB = $this->length($fromStart, $to);
  28350. $llE = $this->length(\array_reverse($fromEnd), \array_reverse($to));
  28351. $jMax = 0;
  28352. $max = 0;
  28353. for ($j = 0; $j <= $cTo; $j++) {
  28354. $m = $llB[$j] + $llE[$cTo - $j];
  28355. if ($m >= $max) {
  28356. $max = $m;
  28357. $jMax = $j;
  28358. }
  28359. }
  28360. $toStart = \array_slice($to, 0, $jMax);
  28361. $toEnd = \array_slice($to, $jMax);
  28362. return \array_merge(
  28363. $this->calculate($fromStart, $toStart),
  28364. $this->calculate($fromEnd, $toEnd)
  28365. );
  28366. }
  28367. private function length(array $from, array $to)
  28368. {
  28369. $current = \array_fill(0, \count($to) + 1, 0);
  28370. $cFrom = \count($from);
  28371. $cTo = \count($to);
  28372. for ($i = 0; $i < $cFrom; $i++) {
  28373. $prev = $current;
  28374. for ($j = 0; $j < $cTo; $j++) {
  28375. if ($from[$i] === $to[$j]) {
  28376. $current[$j + 1] = $prev[$j] + 1;
  28377. } else {
  28378. $current[$j + 1] = \max($current[$j], $prev[$j + 1]);
  28379. }
  28380. }
  28381. }
  28382. return $current;
  28383. }
  28384. }
  28385. <?php
  28386. namespace PhpCsFixer\Diff\v2_0\Output;
  28387. abstract class AbstractChunkOutputBuilder implements DiffOutputBuilderInterface
  28388. {
  28389. protected function getCommonChunks(array $diff, $lineThreshold = 5)
  28390. {
  28391. $diffSize = \count($diff);
  28392. $capturing = false;
  28393. $chunkStart = 0;
  28394. $chunkSize = 0;
  28395. $commonChunks = [];
  28396. for ($i = 0; $i < $diffSize; ++$i) {
  28397. if ($diff[$i][1] === 0 ) {
  28398. if ($capturing === false) {
  28399. $capturing = true;
  28400. $chunkStart = $i;
  28401. $chunkSize = 0;
  28402. } else {
  28403. ++$chunkSize;
  28404. }
  28405. } elseif ($capturing !== false) {
  28406. if ($chunkSize >= $lineThreshold) {
  28407. $commonChunks[$chunkStart] = $chunkStart + $chunkSize;
  28408. }
  28409. $capturing = false;
  28410. }
  28411. }
  28412. if ($capturing !== false && $chunkSize >= $lineThreshold) {
  28413. $commonChunks[$chunkStart] = $chunkStart + $chunkSize;
  28414. }
  28415. return $commonChunks;
  28416. }
  28417. }
  28418. <?php
  28419. namespace PhpCsFixer\Diff\v2_0\Output;
  28420. final class DiffOnlyOutputBuilder implements DiffOutputBuilderInterface
  28421. {
  28422. private $header;
  28423. public function __construct($header = "--- Original\n+++ New\n")
  28424. {
  28425. $this->header = $header;
  28426. }
  28427. public function getDiff(array $diff)
  28428. {
  28429. $buffer = \fopen('php://memory', 'r+b');
  28430. if ('' !== $this->header) {
  28431. \fwrite($buffer, $this->header);
  28432. if ("\n" !== \substr($this->header, -1, 1)) {
  28433. \fwrite($buffer, "\n");
  28434. }
  28435. }
  28436. foreach ($diff as $diffEntry) {
  28437. if ($diffEntry[1] === 1 ) {
  28438. \fwrite($buffer, '+' . $diffEntry[0]);
  28439. } elseif ($diffEntry[1] === 2 ) {
  28440. \fwrite($buffer, '-' . $diffEntry[0]);
  28441. } elseif ($diffEntry[1] === 3 ) {
  28442. \fwrite($buffer, ' ' . $diffEntry[0]);
  28443. continue;
  28444. } else {
  28445. continue;
  28446. }
  28447. $lc = \substr($diffEntry[0], -1);
  28448. if ($lc !== "\n" && $lc !== "\r") {
  28449. \fwrite($buffer, "\n");
  28450. }
  28451. }
  28452. $diff = \stream_get_contents($buffer, -1, 0);
  28453. \fclose($buffer);
  28454. return $diff;
  28455. }
  28456. }
  28457. <?php
  28458. namespace PhpCsFixer\Diff\v2_0\Output;
  28459. interface DiffOutputBuilderInterface
  28460. {
  28461. public function getDiff(array $diff);
  28462. }
  28463. <?php
  28464. namespace PhpCsFixer\Diff\v2_0\Output;
  28465. final class UnifiedDiffOutputBuilder extends AbstractChunkOutputBuilder
  28466. {
  28467. private $header;
  28468. private $addLineNumbers;
  28469. public function __construct($header = "--- Original\n+++ New\n", $addLineNumbers = false)
  28470. {
  28471. $this->header = $header;
  28472. $this->addLineNumbers = $addLineNumbers;
  28473. }
  28474. public function getDiff(array $diff)
  28475. {
  28476. $buffer = \fopen('php://memory', 'r+b');
  28477. if ('' !== $this->header) {
  28478. \fwrite($buffer, $this->header);
  28479. if ("\n" !== \substr($this->header, -1, 1)) {
  28480. \fwrite($buffer, "\n");
  28481. }
  28482. }
  28483. $this->writeDiffChunked($buffer, $diff, $this->getCommonChunks($diff));
  28484. $diff = \stream_get_contents($buffer, -1, 0);
  28485. \fclose($buffer);
  28486. return $diff;
  28487. }
  28488. private function writeDiffChunked($output, array $diff, array $old)
  28489. {
  28490. $upperLimit = \count($diff);
  28491. $start = 0;
  28492. $fromStart = 0;
  28493. $toStart = 0;
  28494. if (\count($old)) {
  28495. \reset($old);
  28496. do {
  28497. $commonStart = \key($old);
  28498. $commonEnd = \current($old);
  28499. if ($commonStart !== $start) {
  28500. list($fromRange, $toRange) = $this->getChunkRange($diff, $start, $commonStart);
  28501. $this->writeChunk($output, $diff, $start, $commonStart, $fromStart, $fromRange, $toStart, $toRange);
  28502. $fromStart += $fromRange;
  28503. $toStart += $toRange;
  28504. }
  28505. $start = $commonEnd + 1;
  28506. $commonLength = $commonEnd - $commonStart + 1;
  28507. $fromStart += $commonLength;
  28508. $toStart += $commonLength;
  28509. } while (false !== \next($old));
  28510. \end($old);
  28511. $tmp = \key($old);
  28512. \reset($old);
  28513. if ($old[$tmp] === $upperLimit - 1) {
  28514. $upperLimit = $tmp;
  28515. }
  28516. }
  28517. if ($start < $upperLimit - 1) {
  28518. do {
  28519. --$upperLimit;
  28520. } while (isset($diff[$upperLimit][1]) && $diff[$upperLimit][1] === 0);
  28521. ++$upperLimit;
  28522. list($fromRange, $toRange) = $this->getChunkRange($diff, $start, $upperLimit);
  28523. $this->writeChunk($output, $diff, $start, $upperLimit, $fromStart, $fromRange, $toStart, $toRange);
  28524. }
  28525. }
  28526. private function writeChunk(
  28527. $output,
  28528. array $diff,
  28529. $diffStartIndex,
  28530. $diffEndIndex,
  28531. $fromStart,
  28532. $fromRange,
  28533. $toStart,
  28534. $toRange
  28535. ) {
  28536. if ($this->addLineNumbers) {
  28537. \fwrite($output, '@@ -' . (1 + $fromStart));
  28538. if ($fromRange !== 1) {
  28539. \fwrite($output, ',' . $fromRange);
  28540. }
  28541. \fwrite($output, ' +' . (1 + $toStart));
  28542. if ($toRange !== 1) {
  28543. \fwrite($output, ',' . $toRange);
  28544. }
  28545. \fwrite($output, " @@\n");
  28546. } else {
  28547. \fwrite($output, "@@ @@\n");
  28548. }
  28549. for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
  28550. if ($diff[$i][1] === 1 ) {
  28551. \fwrite($output, '+' . $diff[$i][0]);
  28552. } elseif ($diff[$i][1] === 2 ) {
  28553. \fwrite($output, '-' . $diff[$i][0]);
  28554. } else {
  28555. \fwrite($output, ' ' . $diff[$i][0]);
  28556. }
  28557. $lc = \substr($diff[$i][0], -1);
  28558. if ($lc !== "\n" && $lc !== "\r") {
  28559. \fwrite($output, "\n");
  28560. }
  28561. }
  28562. }
  28563. private function getChunkRange(array $diff, $diffStartIndex, $diffEndIndex)
  28564. {
  28565. $toRange = 0;
  28566. $fromRange = 0;
  28567. for ($i = $diffStartIndex; $i < $diffEndIndex; ++$i) {
  28568. if ($diff[$i][1] === 1) {
  28569. ++$toRange;
  28570. } elseif ($diff[$i][1] === 2) {
  28571. ++$fromRange;
  28572. } elseif ($diff[$i][1] === 0) {
  28573. ++$fromRange;
  28574. ++$toRange;
  28575. }
  28576. }
  28577. return [$fromRange, $toRange];
  28578. }
  28579. }
  28580. <?php
  28581. namespace PhpCsFixer\Diff\v2_0;
  28582. final class Parser
  28583. {
  28584. public function parse($string)
  28585. {
  28586. $lines = \preg_split('(\r\n|\r|\n)', $string);
  28587. if (!empty($lines) && $lines[\count($lines) - 1] === '') {
  28588. \array_pop($lines);
  28589. }
  28590. $lineCount = \count($lines);
  28591. $diffs = [];
  28592. $diff = null;
  28593. $collected = [];
  28594. for ($i = 0; $i < $lineCount; ++$i) {
  28595. if (\preg_match('(^---\\s+(?P<file>\\S+))', $lines[$i], $fromMatch) &&
  28596. \preg_match('(^\\+\\+\\+\\s+(?P<file>\\S+))', $lines[$i + 1], $toMatch)) {
  28597. if ($diff !== null) {
  28598. $this->parseFileDiff($diff, $collected);
  28599. $diffs[] = $diff;
  28600. $collected = [];
  28601. }
  28602. $diff = new Diff($fromMatch['file'], $toMatch['file']);
  28603. ++$i;
  28604. } else {
  28605. if (\preg_match('/^(?:diff --git |index [\da-f\.]+|[+-]{3} [ab])/', $lines[$i])) {
  28606. continue;
  28607. }
  28608. $collected[] = $lines[$i];
  28609. }
  28610. }
  28611. if ($diff !== null && \count($collected)) {
  28612. $this->parseFileDiff($diff, $collected);
  28613. $diffs[] = $diff;
  28614. }
  28615. return $diffs;
  28616. }
  28617. private function parseFileDiff(Diff $diff, array $lines)
  28618. {
  28619. $chunks = [];
  28620. $chunk = null;
  28621. foreach ($lines as $line) {
  28622. if (\preg_match('/^@@\s+-(?P<start>\d+)(?:,\s*(?P<startrange>\d+))?\s+\+(?P<end>\d+)(?:,\s*(?P<endrange>\d+))?\s+@@/', $line, $match)) {
  28623. $chunk = new Chunk(
  28624. (int) $match['start'],
  28625. isset($match['startrange']) ? \max(1, (int) $match['startrange']) : 1,
  28626. (int) $match['end'],
  28627. isset($match['endrange']) ? \max(1, (int) $match['endrange']) : 1
  28628. );
  28629. $chunks[] = $chunk;
  28630. $diffLines = [];
  28631. continue;
  28632. }
  28633. if (\preg_match('/^(?P<type>[+ -])?(?P<line>.*)/', $line, $match)) {
  28634. $type = Line::UNCHANGED;
  28635. if ($match['type'] === '+') {
  28636. $type = Line::ADDED;
  28637. } elseif ($match['type'] === '-') {
  28638. $type = Line::REMOVED;
  28639. }
  28640. $diffLines[] = new Line($type, $match['line']);
  28641. if (null !== $chunk) {
  28642. $chunk->setLines($diffLines);
  28643. }
  28644. }
  28645. }
  28646. $diff->setChunks($chunks);
  28647. }
  28648. }
  28649. <?php
  28650. namespace PhpCsFixer\Diff\v2_0;
  28651. final class TimeEfficientLongestCommonSubsequenceCalculator implements LongestCommonSubsequenceCalculator
  28652. {
  28653. public function calculate(array $from, array $to)
  28654. {
  28655. $common = [];
  28656. $fromLength = \count($from);
  28657. $toLength = \count($to);
  28658. $width = $fromLength + 1;
  28659. $matrix = new \SplFixedArray($width * ($toLength + 1));
  28660. for ($i = 0; $i <= $fromLength; ++$i) {
  28661. $matrix[$i] = 0;
  28662. }
  28663. for ($j = 0; $j <= $toLength; ++$j) {
  28664. $matrix[$j * $width] = 0;
  28665. }
  28666. for ($i = 1; $i <= $fromLength; ++$i) {
  28667. for ($j = 1; $j <= $toLength; ++$j) {
  28668. $o = ($j * $width) + $i;
  28669. $matrix[$o] = \max(
  28670. $matrix[$o - 1],
  28671. $matrix[$o - $width],
  28672. $from[$i - 1] === $to[$j - 1] ? $matrix[$o - $width - 1] + 1 : 0
  28673. );
  28674. }
  28675. }
  28676. $i = $fromLength;
  28677. $j = $toLength;
  28678. while ($i > 0 && $j > 0) {
  28679. if ($from[$i - 1] === $to[$j - 1]) {
  28680. $common[] = $from[$i - 1];
  28681. --$i;
  28682. --$j;
  28683. } else {
  28684. $o = ($j * $width) + $i;
  28685. if ($matrix[$o - $width] > $matrix[$o - 1]) {
  28686. --$j;
  28687. } else {
  28688. --$i;
  28689. }
  28690. }
  28691. }
  28692. return \array_reverse($common);
  28693. }
  28694. }
  28695. <?php
  28696. namespace Composer\Semver;
  28697. use Composer\Semver\Constraint\Constraint;
  28698. class Comparator
  28699. {
  28700. public static function greaterThan($version1, $version2)
  28701. {
  28702. return self::compare($version1, '>', $version2);
  28703. }
  28704. public static function greaterThanOrEqualTo($version1, $version2)
  28705. {
  28706. return self::compare($version1, '>=', $version2);
  28707. }
  28708. public static function lessThan($version1, $version2)
  28709. {
  28710. return self::compare($version1, '<', $version2);
  28711. }
  28712. public static function lessThanOrEqualTo($version1, $version2)
  28713. {
  28714. return self::compare($version1, '<=', $version2);
  28715. }
  28716. public static function equalTo($version1, $version2)
  28717. {
  28718. return self::compare($version1, '==', $version2);
  28719. }
  28720. public static function notEqualTo($version1, $version2)
  28721. {
  28722. return self::compare($version1, '!=', $version2);
  28723. }
  28724. public static function compare($version1, $operator, $version2)
  28725. {
  28726. $constraint = new Constraint($operator, $version2);
  28727. return $constraint->matches(new Constraint('==', $version1));
  28728. }
  28729. }
  28730. <?php
  28731. namespace Composer\Semver\Constraint;
  28732. trigger_error('The ' . __CLASS__ . ' abstract class is deprecated, there is no replacement for it, it will be removed in the next major version.', E_USER_DEPRECATED);
  28733. abstract class AbstractConstraint implements ConstraintInterface
  28734. {
  28735. protected $prettyString;
  28736. public function matches(ConstraintInterface $provider)
  28737. {
  28738. if ($provider instanceof $this) {
  28739. return $this->matchSpecific($provider);
  28740. }
  28741. return $provider->matches($this);
  28742. }
  28743. public function setPrettyString($prettyString)
  28744. {
  28745. $this->prettyString = $prettyString;
  28746. }
  28747. public function getPrettyString()
  28748. {
  28749. if ($this->prettyString) {
  28750. return $this->prettyString;
  28751. }
  28752. return $this->__toString();
  28753. }
  28754. }
  28755. <?php
  28756. namespace Composer\Semver\Constraint;
  28757. class Constraint implements ConstraintInterface
  28758. {
  28759. const OP_EQ = 0;
  28760. const OP_LT = 1;
  28761. const OP_LE = 2;
  28762. const OP_GT = 3;
  28763. const OP_GE = 4;
  28764. const OP_NE = 5;
  28765. private static $transOpStr = array(
  28766. '=' => self::OP_EQ,
  28767. '==' => self::OP_EQ,
  28768. '<' => self::OP_LT,
  28769. '<=' => self::OP_LE,
  28770. '>' => self::OP_GT,
  28771. '>=' => self::OP_GE,
  28772. '<>' => self::OP_NE,
  28773. '!=' => self::OP_NE,
  28774. );
  28775. private static $transOpInt = array(
  28776. self::OP_EQ => '==',
  28777. self::OP_LT => '<',
  28778. self::OP_LE => '<=',
  28779. self::OP_GT => '>',
  28780. self::OP_GE => '>=',
  28781. self::OP_NE => '!=',
  28782. );
  28783. protected $operator;
  28784. protected $version;
  28785. protected $prettyString;
  28786. public function matches(ConstraintInterface $provider)
  28787. {
  28788. if ($provider instanceof $this) {
  28789. return $this->matchSpecific($provider);
  28790. }
  28791. return $provider->matches($this);
  28792. }
  28793. public function setPrettyString($prettyString)
  28794. {
  28795. $this->prettyString = $prettyString;
  28796. }
  28797. public function getPrettyString()
  28798. {
  28799. if ($this->prettyString) {
  28800. return $this->prettyString;
  28801. }
  28802. return $this->__toString();
  28803. }
  28804. public static function getSupportedOperators()
  28805. {
  28806. return array_keys(self::$transOpStr);
  28807. }
  28808. public function __construct($operator, $version)
  28809. {
  28810. if (!isset(self::$transOpStr[$operator])) {
  28811. throw new \InvalidArgumentException(sprintf(
  28812. 'Invalid operator "%s" given, expected one of: %s',
  28813. $operator,
  28814. implode(', ', self::getSupportedOperators())
  28815. ));
  28816. }
  28817. $this->operator = self::$transOpStr[$operator];
  28818. $this->version = $version;
  28819. }
  28820. public function versionCompare($a, $b, $operator, $compareBranches = false)
  28821. {
  28822. if (!isset(self::$transOpStr[$operator])) {
  28823. throw new \InvalidArgumentException(sprintf(
  28824. 'Invalid operator "%s" given, expected one of: %s',
  28825. $operator,
  28826. implode(', ', self::getSupportedOperators())
  28827. ));
  28828. }
  28829. $aIsBranch = 'dev-' === substr($a, 0, 4);
  28830. $bIsBranch = 'dev-' === substr($b, 0, 4);
  28831. if ($aIsBranch && $bIsBranch) {
  28832. return $operator === '==' && $a === $b;
  28833. }
  28834. if (!$compareBranches && ($aIsBranch || $bIsBranch)) {
  28835. return false;
  28836. }
  28837. return version_compare($a, $b, $operator);
  28838. }
  28839. public function matchSpecific(Constraint $provider, $compareBranches = false)
  28840. {
  28841. $noEqualOp = str_replace('=', '', self::$transOpInt[$this->operator]);
  28842. $providerNoEqualOp = str_replace('=', '', self::$transOpInt[$provider->operator]);
  28843. $isEqualOp = self::OP_EQ === $this->operator;
  28844. $isNonEqualOp = self::OP_NE === $this->operator;
  28845. $isProviderEqualOp = self::OP_EQ === $provider->operator;
  28846. $isProviderNonEqualOp = self::OP_NE === $provider->operator;
  28847. if ($isNonEqualOp || $isProviderNonEqualOp) {
  28848. return !$isEqualOp && !$isProviderEqualOp
  28849. || $this->versionCompare($provider->version, $this->version, '!=', $compareBranches);
  28850. }
  28851. if ($this->operator !== self::OP_EQ && $noEqualOp === $providerNoEqualOp) {
  28852. return true;
  28853. }
  28854. if ($this->versionCompare($provider->version, $this->version, self::$transOpInt[$this->operator], $compareBranches)) {
  28855. if ($provider->version === $this->version
  28856. && self::$transOpInt[$provider->operator] === $providerNoEqualOp
  28857. && self::$transOpInt[$this->operator] !== $noEqualOp) {
  28858. return false;
  28859. }
  28860. return true;
  28861. }
  28862. return false;
  28863. }
  28864. public function __toString()
  28865. {
  28866. return self::$transOpInt[$this->operator] . ' ' . $this->version;
  28867. }
  28868. }
  28869. <?php
  28870. namespace Composer\Semver\Constraint;
  28871. interface ConstraintInterface
  28872. {
  28873. public function matches(ConstraintInterface $provider);
  28874. public function getPrettyString();
  28875. public function __toString();
  28876. }
  28877. <?php
  28878. namespace Composer\Semver\Constraint;
  28879. class EmptyConstraint implements ConstraintInterface
  28880. {
  28881. protected $prettyString;
  28882. public function matches(ConstraintInterface $provider)
  28883. {
  28884. return true;
  28885. }
  28886. public function setPrettyString($prettyString)
  28887. {
  28888. $this->prettyString = $prettyString;
  28889. }
  28890. public function getPrettyString()
  28891. {
  28892. if ($this->prettyString) {
  28893. return $this->prettyString;
  28894. }
  28895. return $this->__toString();
  28896. }
  28897. public function __toString()
  28898. {
  28899. return '[]';
  28900. }
  28901. }
  28902. <?php
  28903. namespace Composer\Semver\Constraint;
  28904. class MultiConstraint implements ConstraintInterface
  28905. {
  28906. protected $constraints;
  28907. protected $prettyString;
  28908. protected $conjunctive;
  28909. public function __construct(array $constraints, $conjunctive = true)
  28910. {
  28911. $this->constraints = $constraints;
  28912. $this->conjunctive = $conjunctive;
  28913. }
  28914. public function getConstraints()
  28915. {
  28916. return $this->constraints;
  28917. }
  28918. public function isConjunctive()
  28919. {
  28920. return $this->conjunctive;
  28921. }
  28922. public function isDisjunctive()
  28923. {
  28924. return !$this->conjunctive;
  28925. }
  28926. public function matches(ConstraintInterface $provider)
  28927. {
  28928. if (false === $this->conjunctive) {
  28929. foreach ($this->constraints as $constraint) {
  28930. if ($constraint->matches($provider)) {
  28931. return true;
  28932. }
  28933. }
  28934. return false;
  28935. }
  28936. foreach ($this->constraints as $constraint) {
  28937. if (!$constraint->matches($provider)) {
  28938. return false;
  28939. }
  28940. }
  28941. return true;
  28942. }
  28943. public function setPrettyString($prettyString)
  28944. {
  28945. $this->prettyString = $prettyString;
  28946. }
  28947. public function getPrettyString()
  28948. {
  28949. if ($this->prettyString) {
  28950. return $this->prettyString;
  28951. }
  28952. return $this->__toString();
  28953. }
  28954. public function __toString()
  28955. {
  28956. $constraints = array();
  28957. foreach ($this->constraints as $constraint) {
  28958. $constraints[] = (string) $constraint;
  28959. }
  28960. return '[' . implode($this->conjunctive ? ' ' : ' || ', $constraints) . ']';
  28961. }
  28962. }
  28963. <?php
  28964. namespace Composer\Semver;
  28965. use Composer\Semver\Constraint\Constraint;
  28966. class Semver
  28967. {
  28968. const SORT_ASC = 1;
  28969. const SORT_DESC = -1;
  28970. private static $versionParser;
  28971. public static function satisfies($version, $constraints)
  28972. {
  28973. if (null === self::$versionParser) {
  28974. self::$versionParser = new VersionParser();
  28975. }
  28976. $versionParser = self::$versionParser;
  28977. $provider = new Constraint('==', $versionParser->normalize($version));
  28978. $constraints = $versionParser->parseConstraints($constraints);
  28979. return $constraints->matches($provider);
  28980. }
  28981. public static function satisfiedBy(array $versions, $constraints)
  28982. {
  28983. $versions = array_filter($versions, function ($version) use ($constraints) {
  28984. return Semver::satisfies($version, $constraints);
  28985. });
  28986. return array_values($versions);
  28987. }
  28988. public static function sort(array $versions)
  28989. {
  28990. return self::usort($versions, self::SORT_ASC);
  28991. }
  28992. public static function rsort(array $versions)
  28993. {
  28994. return self::usort($versions, self::SORT_DESC);
  28995. }
  28996. private static function usort(array $versions, $direction)
  28997. {
  28998. if (null === self::$versionParser) {
  28999. self::$versionParser = new VersionParser();
  29000. }
  29001. $versionParser = self::$versionParser;
  29002. $normalized = array();
  29003. foreach ($versions as $key => $version) {
  29004. $normalized[] = array($versionParser->normalize($version), $key);
  29005. }
  29006. usort($normalized, function (array $left, array $right) use ($direction) {
  29007. if ($left[0] === $right[0]) {
  29008. return 0;
  29009. }
  29010. if (Comparator::lessThan($left[0], $right[0])) {
  29011. return -$direction;
  29012. }
  29013. return $direction;
  29014. });
  29015. $sorted = array();
  29016. foreach ($normalized as $item) {
  29017. $sorted[] = $versions[$item[1]];
  29018. }
  29019. return $sorted;
  29020. }
  29021. }
  29022. <?php
  29023. namespace Composer\Semver;
  29024. use Composer\Semver\Constraint\ConstraintInterface;
  29025. use Composer\Semver\Constraint\EmptyConstraint;
  29026. use Composer\Semver\Constraint\MultiConstraint;
  29027. use Composer\Semver\Constraint\Constraint;
  29028. class VersionParser
  29029. {
  29030. private static $modifierRegex = '[._-]?(?:(stable|beta|b|RC|alpha|a|patch|pl|p)((?:[.-]?\d+)*+)?)?([.-]?dev)?';
  29031. private static $stabilities = array('stable', 'RC', 'beta', 'alpha', 'dev');
  29032. public static function parseStability($version)
  29033. {
  29034. $version = preg_replace('{#.+$}i', '', $version);
  29035. if ('dev-' === substr($version, 0, 4) || '-dev' === substr($version, -4)) {
  29036. return 'dev';
  29037. }
  29038. preg_match('{' . self::$modifierRegex . '(?:\+.*)?$}i', strtolower($version), $match);
  29039. if (!empty($match[3])) {
  29040. return 'dev';
  29041. }
  29042. if (!empty($match[1])) {
  29043. if ('beta' === $match[1] || 'b' === $match[1]) {
  29044. return 'beta';
  29045. }
  29046. if ('alpha' === $match[1] || 'a' === $match[1]) {
  29047. return 'alpha';
  29048. }
  29049. if ('rc' === $match[1]) {
  29050. return 'RC';
  29051. }
  29052. }
  29053. return 'stable';
  29054. }
  29055. public static function normalizeStability($stability)
  29056. {
  29057. $stability = strtolower($stability);
  29058. return $stability === 'rc' ? 'RC' : $stability;
  29059. }
  29060. public function normalize($version, $fullVersion = null)
  29061. {
  29062. $version = trim($version);
  29063. if (null === $fullVersion) {
  29064. $fullVersion = $version;
  29065. }
  29066. if (preg_match('{^([^,\s]++) ++as ++([^,\s]++)$}', $version, $match)) {
  29067. $version = $match[1];
  29068. }
  29069. if (preg_match('{^(?:dev-)?(?:master|trunk|default)$}i', $version)) {
  29070. return '9999999-dev';
  29071. }
  29072. if ('dev-' === strtolower(substr($version, 0, 4))) {
  29073. return 'dev-' . substr($version, 4);
  29074. }
  29075. if (preg_match('{^([^,\s+]++)\+[^\s]++$}', $version, $match)) {
  29076. $version = $match[1];
  29077. }
  29078. if (preg_match('{^v?(\d{1,5})(\.\d++)?(\.\d++)?(\.\d++)?' . self::$modifierRegex . '$}i', $version, $matches)) {
  29079. $version = $matches[1]
  29080. . (!empty($matches[2]) ? $matches[2] : '.0')
  29081. . (!empty($matches[3]) ? $matches[3] : '.0')
  29082. . (!empty($matches[4]) ? $matches[4] : '.0');
  29083. $index = 5;
  29084. } elseif (preg_match('{^v?(\d{4}(?:[.:-]?\d{2}){1,6}(?:[.:-]?\d{1,3})?)' . self::$modifierRegex . '$}i', $version, $matches)) {
  29085. $version = preg_replace('{\D}', '.', $matches[1]);
  29086. $index = 2;
  29087. }
  29088. if (isset($index)) {
  29089. if (!empty($matches[$index])) {
  29090. if ('stable' === $matches[$index]) {
  29091. return $version;
  29092. }
  29093. $version .= '-' . $this->expandStability($matches[$index]) . (!empty($matches[$index + 1]) ? ltrim($matches[$index + 1], '.-') : '');
  29094. }
  29095. if (!empty($matches[$index + 2])) {
  29096. $version .= '-dev';
  29097. }
  29098. return $version;
  29099. }
  29100. if (preg_match('{(.*?)[.-]?dev$}i', $version, $match)) {
  29101. try {
  29102. return $this->normalizeBranch($match[1]);
  29103. } catch (\Exception $e) {
  29104. }
  29105. }
  29106. $extraMessage = '';
  29107. if (preg_match('{ +as +' . preg_quote($version) . '$}', $fullVersion)) {
  29108. $extraMessage = ' in "' . $fullVersion . '", the alias must be an exact version';
  29109. } elseif (preg_match('{^' . preg_quote($version) . ' +as +}', $fullVersion)) {
  29110. $extraMessage = ' in "' . $fullVersion . '", the alias source must be an exact version, if it is a branch name you should prefix it with dev-';
  29111. }
  29112. throw new \UnexpectedValueException('Invalid version string "' . $version . '"' . $extraMessage);
  29113. }
  29114. public function parseNumericAliasPrefix($branch)
  29115. {
  29116. if (preg_match('{^(?P<version>(\d++\\.)*\d++)(?:\.x)?-dev$}i', $branch, $matches)) {
  29117. return $matches['version'] . '.';
  29118. }
  29119. return false;
  29120. }
  29121. public function normalizeBranch($name)
  29122. {
  29123. $name = trim($name);
  29124. if (in_array($name, array('master', 'trunk', 'default'))) {
  29125. return $this->normalize($name);
  29126. }
  29127. if (preg_match('{^v?(\d++)(\.(?:\d++|[xX*]))?(\.(?:\d++|[xX*]))?(\.(?:\d++|[xX*]))?$}i', $name, $matches)) {
  29128. $version = '';
  29129. for ($i = 1; $i < 5; ++$i) {
  29130. $version .= isset($matches[$i]) ? str_replace(array('*', 'X'), 'x', $matches[$i]) : '.x';
  29131. }
  29132. return str_replace('x', '9999999', $version) . '-dev';
  29133. }
  29134. return 'dev-' . $name;
  29135. }
  29136. public function parseConstraints($constraints)
  29137. {
  29138. $prettyConstraint = $constraints;
  29139. if (preg_match('{^([^,\s]*?)@(' . implode('|', self::$stabilities) . ')$}i', $constraints, $match)) {
  29140. $constraints = empty($match[1]) ? '*' : $match[1];
  29141. }
  29142. if (preg_match('{^(dev-[^,\s@]+?|[^,\s@]+?\.x-dev)#.+$}i', $constraints, $match)) {
  29143. $constraints = $match[1];
  29144. }
  29145. $orConstraints = preg_split('{\s*\|\|?\s*}', trim($constraints));
  29146. $orGroups = array();
  29147. foreach ($orConstraints as $constraints) {
  29148. $andConstraints = preg_split('{(?<!^|as|[=>< ,]) *(?<!-)[, ](?!-) *(?!,|as|$)}', $constraints);
  29149. if (count($andConstraints) > 1) {
  29150. $constraintObjects = array();
  29151. foreach ($andConstraints as $constraint) {
  29152. foreach ($this->parseConstraint($constraint) as $parsedConstraint) {
  29153. $constraintObjects[] = $parsedConstraint;
  29154. }
  29155. }
  29156. } else {
  29157. $constraintObjects = $this->parseConstraint($andConstraints[0]);
  29158. }
  29159. if (1 === count($constraintObjects)) {
  29160. $constraint = $constraintObjects[0];
  29161. } else {
  29162. $constraint = new MultiConstraint($constraintObjects);
  29163. }
  29164. $orGroups[] = $constraint;
  29165. }
  29166. if (1 === count($orGroups)) {
  29167. $constraint = $orGroups[0];
  29168. } elseif (2 === count($orGroups)
  29169. && $orGroups[0] instanceof MultiConstraint
  29170. && $orGroups[1] instanceof MultiConstraint
  29171. && 2 === count($orGroups[0]->getConstraints())
  29172. && 2 === count($orGroups[1]->getConstraints())
  29173. && ($a = (string) $orGroups[0])
  29174. && substr($a, 0, 3) === '[>=' && (false !== ($posA = strpos($a, '<', 4)))
  29175. && ($b = (string) $orGroups[1])
  29176. && substr($b, 0, 3) === '[>=' && (false !== ($posB = strpos($b, '<', 4)))
  29177. && substr($a, $posA + 2, -1) === substr($b, 4, $posB - 5)
  29178. ) {
  29179. $constraint = new MultiConstraint(array(
  29180. new Constraint('>=', substr($a, 4, $posA - 5)),
  29181. new Constraint('<', substr($b, $posB + 2, -1)),
  29182. ));
  29183. } else {
  29184. $constraint = new MultiConstraint($orGroups, false);
  29185. }
  29186. $constraint->setPrettyString($prettyConstraint);
  29187. return $constraint;
  29188. }
  29189. private function parseConstraint($constraint)
  29190. {
  29191. if (preg_match('{^([^,\s]+?)@(' . implode('|', self::$stabilities) . ')$}i', $constraint, $match)) {
  29192. $constraint = $match[1];
  29193. if ($match[2] !== 'stable') {
  29194. $stabilityModifier = $match[2];
  29195. }
  29196. }
  29197. if (preg_match('{^v?[xX*](\.[xX*])*$}i', $constraint)) {
  29198. return array(new EmptyConstraint());
  29199. }
  29200. $versionRegex = 'v?(\d++)(?:\.(\d++))?(?:\.(\d++))?(?:\.(\d++))?' . self::$modifierRegex . '(?:\+[^\s]+)?';
  29201. if (preg_match('{^~>?' . $versionRegex . '$}i', $constraint, $matches)) {
  29202. if (substr($constraint, 0, 2) === '~>') {
  29203. throw new \UnexpectedValueException(
  29204. 'Could not parse version constraint ' . $constraint . ': ' .
  29205. 'Invalid operator "~>", you probably meant to use the "~" operator'
  29206. );
  29207. }
  29208. if (isset($matches[4]) && '' !== $matches[4]) {
  29209. $position = 4;
  29210. } elseif (isset($matches[3]) && '' !== $matches[3]) {
  29211. $position = 3;
  29212. } elseif (isset($matches[2]) && '' !== $matches[2]) {
  29213. $position = 2;
  29214. } else {
  29215. $position = 1;
  29216. }
  29217. $stabilitySuffix = '';
  29218. if (!empty($matches[5])) {
  29219. $stabilitySuffix .= '-' . $this->expandStability($matches[5]) . (!empty($matches[6]) ? $matches[6] : '');
  29220. }
  29221. if (!empty($matches[7])) {
  29222. $stabilitySuffix .= '-dev';
  29223. }
  29224. if (!$stabilitySuffix) {
  29225. $stabilitySuffix = '-dev';
  29226. }
  29227. $lowVersion = $this->manipulateVersionString($matches, $position, 0) . $stabilitySuffix;
  29228. $lowerBound = new Constraint('>=', $lowVersion);
  29229. $highPosition = max(1, $position - 1);
  29230. $highVersion = $this->manipulateVersionString($matches, $highPosition, 1) . '-dev';
  29231. $upperBound = new Constraint('<', $highVersion);
  29232. return array(
  29233. $lowerBound,
  29234. $upperBound,
  29235. );
  29236. }
  29237. if (preg_match('{^\^' . $versionRegex . '($)}i', $constraint, $matches)) {
  29238. if ('0' !== $matches[1] || '' === $matches[2]) {
  29239. $position = 1;
  29240. } elseif ('0' !== $matches[2] || '' === $matches[3]) {
  29241. $position = 2;
  29242. } else {
  29243. $position = 3;
  29244. }
  29245. $stabilitySuffix = '';
  29246. if (empty($matches[5]) && empty($matches[7])) {
  29247. $stabilitySuffix .= '-dev';
  29248. }
  29249. $lowVersion = $this->normalize(substr($constraint . $stabilitySuffix, 1));
  29250. $lowerBound = new Constraint('>=', $lowVersion);
  29251. $highVersion = $this->manipulateVersionString($matches, $position, 1) . '-dev';
  29252. $upperBound = new Constraint('<', $highVersion);
  29253. return array(
  29254. $lowerBound,
  29255. $upperBound,
  29256. );
  29257. }
  29258. if (preg_match('{^v?(\d++)(?:\.(\d++))?(?:\.(\d++))?(?:\.[xX*])++$}', $constraint, $matches)) {
  29259. if (isset($matches[3]) && '' !== $matches[3]) {
  29260. $position = 3;
  29261. } elseif (isset($matches[2]) && '' !== $matches[2]) {
  29262. $position = 2;
  29263. } else {
  29264. $position = 1;
  29265. }
  29266. $lowVersion = $this->manipulateVersionString($matches, $position) . '-dev';
  29267. $highVersion = $this->manipulateVersionString($matches, $position, 1) . '-dev';
  29268. if ($lowVersion === '0.0.0.0-dev') {
  29269. return array(new Constraint('<', $highVersion));
  29270. }
  29271. return array(
  29272. new Constraint('>=', $lowVersion),
  29273. new Constraint('<', $highVersion),
  29274. );
  29275. }
  29276. if (preg_match('{^(?P<from>' . $versionRegex . ') +- +(?P<to>' . $versionRegex . ')($)}i', $constraint, $matches)) {
  29277. $lowStabilitySuffix = '';
  29278. if (empty($matches[6]) && empty($matches[8])) {
  29279. $lowStabilitySuffix = '-dev';
  29280. }
  29281. $lowVersion = $this->normalize($matches['from']);
  29282. $lowerBound = new Constraint('>=', $lowVersion . $lowStabilitySuffix);
  29283. $empty = function ($x) {
  29284. return ($x === 0 || $x === '0') ? false : empty($x);
  29285. };
  29286. if ((!$empty($matches[11]) && !$empty($matches[12])) || !empty($matches[14]) || !empty($matches[16])) {
  29287. $highVersion = $this->normalize($matches['to']);
  29288. $upperBound = new Constraint('<=', $highVersion);
  29289. } else {
  29290. $highMatch = array('', $matches[10], $matches[11], $matches[12], $matches[13]);
  29291. $highVersion = $this->manipulateVersionString($highMatch, $empty($matches[11]) ? 1 : 2, 1) . '-dev';
  29292. $upperBound = new Constraint('<', $highVersion);
  29293. }
  29294. return array(
  29295. $lowerBound,
  29296. $upperBound,
  29297. );
  29298. }
  29299. if (preg_match('{^(<>|!=|>=?|<=?|==?)?\s*(.*)}', $constraint, $matches)) {
  29300. try {
  29301. $version = $this->normalize($matches[2]);
  29302. if (!empty($stabilityModifier) && $this->parseStability($version) === 'stable') {
  29303. $version .= '-' . $stabilityModifier;
  29304. } elseif ('<' === $matches[1] || '>=' === $matches[1]) {
  29305. if (!preg_match('/-' . self::$modifierRegex . '$/', strtolower($matches[2]))) {
  29306. if (substr($matches[2], 0, 4) !== 'dev-') {
  29307. $version .= '-dev';
  29308. }
  29309. }
  29310. }
  29311. return array(new Constraint($matches[1] ?: '=', $version));
  29312. } catch (\Exception $e) {
  29313. }
  29314. }
  29315. $message = 'Could not parse version constraint ' . $constraint;
  29316. if (isset($e)) {
  29317. $message .= ': ' . $e->getMessage();
  29318. }
  29319. throw new \UnexpectedValueException($message);
  29320. }
  29321. private function manipulateVersionString($matches, $position, $increment = 0, $pad = '0')
  29322. {
  29323. for ($i = 4; $i > 0; --$i) {
  29324. if ($i > $position) {
  29325. $matches[$i] = $pad;
  29326. } elseif ($i === $position && $increment) {
  29327. $matches[$i] += $increment;
  29328. if ($matches[$i] < 0) {
  29329. $matches[$i] = $pad;
  29330. --$position;
  29331. if ($i === 1) {
  29332. return;
  29333. }
  29334. }
  29335. }
  29336. }
  29337. return $matches[1] . '.' . $matches[2] . '.' . $matches[3] . '.' . $matches[4];
  29338. }
  29339. private function expandStability($stability)
  29340. {
  29341. $stability = strtolower($stability);
  29342. switch ($stability) {
  29343. case 'a':
  29344. return 'alpha';
  29345. case 'b':
  29346. return 'beta';
  29347. case 'p':
  29348. case 'pl':
  29349. return 'patch';
  29350. case 'rc':
  29351. return 'RC';
  29352. default:
  29353. return $stability;
  29354. }
  29355. }
  29356. }
  29357. <?php
  29358. $vendorDir = dirname(dirname(__FILE__));
  29359. $baseDir = dirname($vendorDir);
  29360. return array(
  29361. 'Doctrine\\Common\\Lexer\\' => array($vendorDir . '/doctrine/lexer/lib'),
  29362. );
  29363. <?php
  29364. $vendorDir = dirname(dirname(__FILE__));
  29365. $baseDir = dirname($vendorDir);
  29366. return array(
  29367. 'Symfony\\Polyfill\\Php72\\' => array($vendorDir . '/symfony/polyfill-php72'),
  29368. 'Symfony\\Polyfill\\Php70\\' => array($vendorDir . '/symfony/polyfill-php70'),
  29369. 'Symfony\\Polyfill\\Mbstring\\' => array($vendorDir . '/symfony/polyfill-mbstring'),
  29370. 'Symfony\\Component\\Stopwatch\\' => array($vendorDir . '/symfony/stopwatch'),
  29371. 'Symfony\\Component\\Process\\' => array($vendorDir . '/symfony/process'),
  29372. 'Symfony\\Component\\OptionsResolver\\' => array($vendorDir . '/symfony/options-resolver'),
  29373. 'Symfony\\Component\\Finder\\' => array($vendorDir . '/symfony/finder'),
  29374. 'Symfony\\Component\\Filesystem\\' => array($vendorDir . '/symfony/filesystem'),
  29375. 'Symfony\\Component\\EventDispatcher\\' => array($vendorDir . '/symfony/event-dispatcher'),
  29376. 'Symfony\\Component\\Debug\\' => array($vendorDir . '/symfony/debug'),
  29377. 'Symfony\\Component\\Console\\' => array($vendorDir . '/symfony/console'),
  29378. 'Psr\\Log\\' => array($vendorDir . '/psr/log/Psr/Log'),
  29379. 'PhpCsFixer\\' => array($baseDir . '/src'),
  29380. 'GeckoPackages\\PHPUnit\\' => array($vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit'),
  29381. 'Doctrine\\Common\\Annotations\\' => array($vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations'),
  29382. 'Composer\\Semver\\' => array($vendorDir . '/composer/semver/src'),
  29383. );
  29384. <?php
  29385. $vendorDir = dirname(dirname(__FILE__));
  29386. $baseDir = dirname($vendorDir);
  29387. return array(
  29388. 'ArithmeticError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php',
  29389. 'AssertionError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php',
  29390. 'Composer\\Semver\\Comparator' => $vendorDir . '/composer/semver/src/Comparator.php',
  29391. 'Composer\\Semver\\Constraint\\AbstractConstraint' => $vendorDir . '/composer/semver/src/Constraint/AbstractConstraint.php',
  29392. 'Composer\\Semver\\Constraint\\Constraint' => $vendorDir . '/composer/semver/src/Constraint/Constraint.php',
  29393. 'Composer\\Semver\\Constraint\\ConstraintInterface' => $vendorDir . '/composer/semver/src/Constraint/ConstraintInterface.php',
  29394. 'Composer\\Semver\\Constraint\\EmptyConstraint' => $vendorDir . '/composer/semver/src/Constraint/EmptyConstraint.php',
  29395. 'Composer\\Semver\\Constraint\\MultiConstraint' => $vendorDir . '/composer/semver/src/Constraint/MultiConstraint.php',
  29396. 'Composer\\Semver\\Semver' => $vendorDir . '/composer/semver/src/Semver.php',
  29397. 'Composer\\Semver\\VersionParser' => $vendorDir . '/composer/semver/src/VersionParser.php',
  29398. 'DivisionByZeroError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',
  29399. 'Doctrine\\Common\\Annotations\\Annotation' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation.php',
  29400. 'Doctrine\\Common\\Annotations\\AnnotationException' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php',
  29401. 'Doctrine\\Common\\Annotations\\AnnotationReader' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php',
  29402. 'Doctrine\\Common\\Annotations\\AnnotationRegistry' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php',
  29403. 'Doctrine\\Common\\Annotations\\Annotation\\Attribute' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attribute.php',
  29404. 'Doctrine\\Common\\Annotations\\Annotation\\Attributes' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attributes.php',
  29405. 'Doctrine\\Common\\Annotations\\Annotation\\Enum' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php',
  29406. 'Doctrine\\Common\\Annotations\\Annotation\\IgnoreAnnotation' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php',
  29407. 'Doctrine\\Common\\Annotations\\Annotation\\Required' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Required.php',
  29408. 'Doctrine\\Common\\Annotations\\Annotation\\Target' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php',
  29409. 'Doctrine\\Common\\Annotations\\CachedReader' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php',
  29410. 'Doctrine\\Common\\Annotations\\DocLexer' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php',
  29411. 'Doctrine\\Common\\Annotations\\DocParser' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php',
  29412. 'Doctrine\\Common\\Annotations\\FileCacheReader' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/FileCacheReader.php',
  29413. 'Doctrine\\Common\\Annotations\\IndexedReader' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.php',
  29414. 'Doctrine\\Common\\Annotations\\PhpParser' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php',
  29415. 'Doctrine\\Common\\Annotations\\Reader' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Reader.php',
  29416. 'Doctrine\\Common\\Annotations\\SimpleAnnotationReader' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php',
  29417. 'Doctrine\\Common\\Annotations\\TokenParser' => $vendorDir . '/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php',
  29418. 'Doctrine\\Common\\Lexer\\AbstractLexer' => $vendorDir . '/doctrine/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php',
  29419. 'Error' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/Error.php',
  29420. 'GeckoPackages\\PHPUnit\\Asserts\\AssertHelper' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/AssertHelper.php',
  29421. 'GeckoPackages\\PHPUnit\\Asserts\\FileExistsAssertTrait' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/FileExistsAssertTrait.php',
  29422. 'GeckoPackages\\PHPUnit\\Asserts\\FileSystemAssertTrait' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/FileSystemAssertTrait.php',
  29423. 'GeckoPackages\\PHPUnit\\Asserts\\RangeAssertTrait' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/RangeAssertTrait.php',
  29424. 'GeckoPackages\\PHPUnit\\Asserts\\ScalarAssertTrait' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/ScalarAssertTrait.php',
  29425. 'GeckoPackages\\PHPUnit\\Asserts\\StringsAssertTrait' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/StringsAssertTrait.php',
  29426. 'GeckoPackages\\PHPUnit\\Asserts\\XMLAssertTrait' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/XMLAssertTrait.php',
  29427. 'GeckoPackages\\PHPUnit\\Constraints\\DirectoryEmptyConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/DirectoryEmptyConstraint.php',
  29428. 'GeckoPackages\\PHPUnit\\Constraints\\DirectoryExistsConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/DirectoryExistsConstraint.php',
  29429. 'GeckoPackages\\PHPUnit\\Constraints\\FileExistsConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileExistsConstraint.php',
  29430. 'GeckoPackages\\PHPUnit\\Constraints\\FileIsLinkConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileIsLinkConstraint.php',
  29431. 'GeckoPackages\\PHPUnit\\Constraints\\FileIsValidLinkConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileIsValidLinkConstraint.php',
  29432. 'GeckoPackages\\PHPUnit\\Constraints\\FilePermissionsIsIdenticalConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FilePermissionsIsIdenticalConstraint.php',
  29433. 'GeckoPackages\\PHPUnit\\Constraints\\FilePermissionsMaskConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FilePermissionsMaskConstraint.php',
  29434. 'GeckoPackages\\PHPUnit\\Constraints\\NumberRangeConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/NumberRangeConstraint.php',
  29435. 'GeckoPackages\\PHPUnit\\Constraints\\SameStringsConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/SameStringsConstraint.php',
  29436. 'GeckoPackages\\PHPUnit\\Constraints\\ScalarConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/ScalarConstraint.php',
  29437. 'GeckoPackages\\PHPUnit\\Constraints\\UnsignedIntConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/UnsignedIntConstraint.php',
  29438. 'GeckoPackages\\PHPUnit\\Constraints\\XML\\AbstractXMLConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/AbstractXMLConstraint.php',
  29439. 'GeckoPackages\\PHPUnit\\Constraints\\XML\\XMLMatchesXSDConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/XMLMatchesXSDConstraint.php',
  29440. 'GeckoPackages\\PHPUnit\\Constraints\\XML\\XMLValidConstraint' => $vendorDir . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/XMLValidConstraint.php',
  29441. 'ParseError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/ParseError.php',
  29442. 'PhpCsFixer\\AbstractAlignFixerHelper' => $baseDir . '/src/AbstractAlignFixerHelper.php',
  29443. 'PhpCsFixer\\AbstractDoctrineAnnotationFixer' => $baseDir . '/src/AbstractDoctrineAnnotationFixer.php',
  29444. 'PhpCsFixer\\AbstractFixer' => $baseDir . '/src/AbstractFixer.php',
  29445. 'PhpCsFixer\\AbstractFunctionReferenceFixer' => $baseDir . '/src/AbstractFunctionReferenceFixer.php',
  29446. 'PhpCsFixer\\AbstractLinesBeforeNamespaceFixer' => $baseDir . '/src/AbstractLinesBeforeNamespaceFixer.php',
  29447. 'PhpCsFixer\\AbstractNoUselessElseFixer' => $baseDir . '/src/AbstractNoUselessElseFixer.php',
  29448. 'PhpCsFixer\\AbstractPhpdocTypesFixer' => $baseDir . '/src/AbstractPhpdocTypesFixer.php',
  29449. 'PhpCsFixer\\AbstractProxyFixer' => $baseDir . '/src/AbstractProxyFixer.php',
  29450. 'PhpCsFixer\\AbstractPsrAutoloadingFixer' => $baseDir . '/src/AbstractPsrAutoloadingFixer.php',
  29451. 'PhpCsFixer\\Cache\\Cache' => $baseDir . '/src/Cache/Cache.php',
  29452. 'PhpCsFixer\\Cache\\CacheInterface' => $baseDir . '/src/Cache/CacheInterface.php',
  29453. 'PhpCsFixer\\Cache\\CacheManagerInterface' => $baseDir . '/src/Cache/CacheManagerInterface.php',
  29454. 'PhpCsFixer\\Cache\\Directory' => $baseDir . '/src/Cache/Directory.php',
  29455. 'PhpCsFixer\\Cache\\DirectoryInterface' => $baseDir . '/src/Cache/DirectoryInterface.php',
  29456. 'PhpCsFixer\\Cache\\FileCacheManager' => $baseDir . '/src/Cache/FileCacheManager.php',
  29457. 'PhpCsFixer\\Cache\\FileHandler' => $baseDir . '/src/Cache/FileHandler.php',
  29458. 'PhpCsFixer\\Cache\\FileHandlerInterface' => $baseDir . '/src/Cache/FileHandlerInterface.php',
  29459. 'PhpCsFixer\\Cache\\NullCacheManager' => $baseDir . '/src/Cache/NullCacheManager.php',
  29460. 'PhpCsFixer\\Cache\\Signature' => $baseDir . '/src/Cache/Signature.php',
  29461. 'PhpCsFixer\\Cache\\SignatureInterface' => $baseDir . '/src/Cache/SignatureInterface.php',
  29462. 'PhpCsFixer\\Config' => $baseDir . '/src/Config.php',
  29463. 'PhpCsFixer\\ConfigInterface' => $baseDir . '/src/ConfigInterface.php',
  29464. 'PhpCsFixer\\ConfigurationException\\InvalidConfigurationException' => $baseDir . '/src/ConfigurationException/InvalidConfigurationException.php',
  29465. 'PhpCsFixer\\ConfigurationException\\InvalidFixerConfigurationException' => $baseDir . '/src/ConfigurationException/InvalidFixerConfigurationException.php',
  29466. 'PhpCsFixer\\ConfigurationException\\InvalidForEnvFixerConfigurationException' => $baseDir . '/src/ConfigurationException/InvalidForEnvFixerConfigurationException.php',
  29467. 'PhpCsFixer\\ConfigurationException\\RequiredFixerConfigurationException' => $baseDir . '/src/ConfigurationException/RequiredFixerConfigurationException.php',
  29468. 'PhpCsFixer\\Console\\Application' => $baseDir . '/src/Console/Application.php',
  29469. 'PhpCsFixer\\Console\\Command\\DescribeCommand' => $baseDir . '/src/Console/Command/DescribeCommand.php',
  29470. 'PhpCsFixer\\Console\\Command\\DescribeNameNotFoundException' => $baseDir . '/src/Console/Command/DescribeNameNotFoundException.php',
  29471. 'PhpCsFixer\\Console\\Command\\FixCommand' => $baseDir . '/src/Console/Command/FixCommand.php',
  29472. 'PhpCsFixer\\Console\\Command\\FixCommandExitStatusCalculator' => $baseDir . '/src/Console/Command/FixCommandExitStatusCalculator.php',
  29473. 'PhpCsFixer\\Console\\Command\\HelpCommand' => $baseDir . '/src/Console/Command/HelpCommand.php',
  29474. 'PhpCsFixer\\Console\\Command\\ReadmeCommand' => $baseDir . '/src/Console/Command/ReadmeCommand.php',
  29475. 'PhpCsFixer\\Console\\Command\\SelfUpdateCommand' => $baseDir . '/src/Console/Command/SelfUpdateCommand.php',
  29476. 'PhpCsFixer\\Console\\ConfigurationResolver' => $baseDir . '/src/Console/ConfigurationResolver.php',
  29477. 'PhpCsFixer\\Console\\Output\\ErrorOutput' => $baseDir . '/src/Console/Output/ErrorOutput.php',
  29478. 'PhpCsFixer\\Console\\Output\\NullOutput' => $baseDir . '/src/Console/Output/NullOutput.php',
  29479. 'PhpCsFixer\\Console\\Output\\ProcessOutput' => $baseDir . '/src/Console/Output/ProcessOutput.php',
  29480. 'PhpCsFixer\\Console\\Output\\ProcessOutputInterface' => $baseDir . '/src/Console/Output/ProcessOutputInterface.php',
  29481. 'PhpCsFixer\\Console\\SelfUpdate\\GithubClient' => $baseDir . '/src/Console/SelfUpdate/GithubClient.php',
  29482. 'PhpCsFixer\\Console\\SelfUpdate\\GithubClientInterface' => $baseDir . '/src/Console/SelfUpdate/GithubClientInterface.php',
  29483. 'PhpCsFixer\\Console\\SelfUpdate\\NewVersionChecker' => $baseDir . '/src/Console/SelfUpdate/NewVersionChecker.php',
  29484. 'PhpCsFixer\\Console\\SelfUpdate\\NewVersionCheckerInterface' => $baseDir . '/src/Console/SelfUpdate/NewVersionCheckerInterface.php',
  29485. 'PhpCsFixer\\Console\\WarningsDetector' => $baseDir . '/src/Console/WarningsDetector.php',
  29486. 'PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\ConfigurationException' => $vendorDir . '/php-cs-fixer/diff/src/GeckoPackages/DiffOutputBuilder/ConfigurationException.php',
  29487. 'PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\UnifiedDiffOutputBuilder' => $vendorDir . '/php-cs-fixer/diff/src/GeckoPackages/DiffOutputBuilder/UnifiedDiffOutputBuilder.php',
  29488. 'PhpCsFixer\\Diff\\v1_4\\Chunk' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/Chunk.php',
  29489. 'PhpCsFixer\\Diff\\v1_4\\Diff' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/Diff.php',
  29490. 'PhpCsFixer\\Diff\\v1_4\\Differ' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/Differ.php',
  29491. 'PhpCsFixer\\Diff\\v1_4\\LCS\\LongestCommonSubsequence' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/LCS/LongestCommonSubsequence.php',
  29492. 'PhpCsFixer\\Diff\\v1_4\\LCS\\MemoryEfficientImplementation' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/LCS/MemoryEfficientLongestCommonSubsequenceImplementation.php',
  29493. 'PhpCsFixer\\Diff\\v1_4\\LCS\\TimeEfficientImplementation' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php',
  29494. 'PhpCsFixer\\Diff\\v1_4\\Line' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/Line.php',
  29495. 'PhpCsFixer\\Diff\\v1_4\\Parser' => $vendorDir . '/php-cs-fixer/diff/src/v1_4/Parser.php',
  29496. 'PhpCsFixer\\Diff\\v2_0\\Chunk' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Chunk.php',
  29497. 'PhpCsFixer\\Diff\\v2_0\\Diff' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Diff.php',
  29498. 'PhpCsFixer\\Diff\\v2_0\\Differ' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Differ.php',
  29499. 'PhpCsFixer\\Diff\\v2_0\\Exception' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Exception/Exception.php',
  29500. 'PhpCsFixer\\Diff\\v2_0\\InvalidArgumentException' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Exception/InvalidArgumentException.php',
  29501. 'PhpCsFixer\\Diff\\v2_0\\Line' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Line.php',
  29502. 'PhpCsFixer\\Diff\\v2_0\\LongestCommonSubsequenceCalculator' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/LongestCommonSubsequenceCalculator.php',
  29503. 'PhpCsFixer\\Diff\\v2_0\\MemoryEfficientLongestCommonSubsequenceCalculator' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/MemoryEfficientLongestCommonSubsequenceCalculator.php',
  29504. 'PhpCsFixer\\Diff\\v2_0\\Output\\AbstractChunkOutputBuilder' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Output/AbstractChunkOutputBuilder.php',
  29505. 'PhpCsFixer\\Diff\\v2_0\\Output\\DiffOnlyOutputBuilder' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Output/DiffOnlyOutputBuilder.php',
  29506. 'PhpCsFixer\\Diff\\v2_0\\Output\\DiffOutputBuilderInterface' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Output/DiffOutputBuilderInterface.php',
  29507. 'PhpCsFixer\\Diff\\v2_0\\Output\\UnifiedDiffOutputBuilder' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Output/UnifiedDiffOutputBuilder.php',
  29508. 'PhpCsFixer\\Diff\\v2_0\\Parser' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/Parser.php',
  29509. 'PhpCsFixer\\Diff\\v2_0\\TimeEfficientLongestCommonSubsequenceCalculator' => $vendorDir . '/php-cs-fixer/diff/src/v2_0/TimeEfficientLongestCommonSubsequenceCalculator.php',
  29510. 'PhpCsFixer\\Differ\\DiffConsoleFormatter' => $baseDir . '/src/Differ/DiffConsoleFormatter.php',
  29511. 'PhpCsFixer\\Differ\\DifferInterface' => $baseDir . '/src/Differ/DifferInterface.php',
  29512. 'PhpCsFixer\\Differ\\NullDiffer' => $baseDir . '/src/Differ/NullDiffer.php',
  29513. 'PhpCsFixer\\Differ\\SebastianBergmannDiffer' => $baseDir . '/src/Differ/SebastianBergmannDiffer.php',
  29514. 'PhpCsFixer\\Differ\\SebastianBergmannShortDiffer' => $baseDir . '/src/Differ/SebastianBergmannShortDiffer.php',
  29515. 'PhpCsFixer\\Differ\\UnifiedDiffer' => $baseDir . '/src/Differ/UnifiedDiffer.php',
  29516. 'PhpCsFixer\\DocBlock\\Annotation' => $baseDir . '/src/DocBlock/Annotation.php',
  29517. 'PhpCsFixer\\DocBlock\\DocBlock' => $baseDir . '/src/DocBlock/DocBlock.php',
  29518. 'PhpCsFixer\\DocBlock\\Line' => $baseDir . '/src/DocBlock/Line.php',
  29519. 'PhpCsFixer\\DocBlock\\Tag' => $baseDir . '/src/DocBlock/Tag.php',
  29520. 'PhpCsFixer\\DocBlock\\TagComparator' => $baseDir . '/src/DocBlock/TagComparator.php',
  29521. 'PhpCsFixer\\Doctrine\\Annotation\\Token' => $baseDir . '/src/Doctrine/Annotation/Token.php',
  29522. 'PhpCsFixer\\Doctrine\\Annotation\\Tokens' => $baseDir . '/src/Doctrine/Annotation/Tokens.php',
  29523. 'PhpCsFixer\\Error\\Error' => $baseDir . '/src/Error/Error.php',
  29524. 'PhpCsFixer\\Error\\ErrorsManager' => $baseDir . '/src/Error/ErrorsManager.php',
  29525. 'PhpCsFixer\\FileReader' => $baseDir . '/src/FileReader.php',
  29526. 'PhpCsFixer\\FileRemoval' => $baseDir . '/src/FileRemoval.php',
  29527. 'PhpCsFixer\\Finder' => $baseDir . '/src/Finder.php',
  29528. 'PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolver' => $baseDir . '/src/FixerConfiguration/FixerConfigurationResolver.php',
  29529. 'PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolverInterface' => $baseDir . '/src/FixerConfiguration/FixerConfigurationResolverInterface.php',
  29530. 'PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolverRootless' => $baseDir . '/src/FixerConfiguration/FixerConfigurationResolverRootless.php',
  29531. 'PhpCsFixer\\FixerConfiguration\\FixerOption' => $baseDir . '/src/FixerConfiguration/FixerOption.php',
  29532. 'PhpCsFixer\\FixerConfiguration\\FixerOptionBuilder' => $baseDir . '/src/FixerConfiguration/FixerOptionBuilder.php',
  29533. 'PhpCsFixer\\FixerConfiguration\\FixerOptionInterface' => $baseDir . '/src/FixerConfiguration/FixerOptionInterface.php',
  29534. 'PhpCsFixer\\FixerConfiguration\\FixerOptionValidatorGenerator' => $baseDir . '/src/FixerConfiguration/FixerOptionValidatorGenerator.php',
  29535. 'PhpCsFixer\\FixerConfiguration\\InvalidOptionsForEnvException' => $baseDir . '/src/FixerConfiguration/InvalidOptionsForEnvException.php',
  29536. 'PhpCsFixer\\FixerDefinition\\CodeSample' => $baseDir . '/src/FixerDefinition/CodeSample.php',
  29537. 'PhpCsFixer\\FixerDefinition\\CodeSampleInterface' => $baseDir . '/src/FixerDefinition/CodeSampleInterface.php',
  29538. 'PhpCsFixer\\FixerDefinition\\FileSpecificCodeSample' => $baseDir . '/src/FixerDefinition/FileSpecificCodeSample.php',
  29539. 'PhpCsFixer\\FixerDefinition\\FileSpecificCodeSampleInterface' => $baseDir . '/src/FixerDefinition/FileSpecificCodeSampleInterface.php',
  29540. 'PhpCsFixer\\FixerDefinition\\FixerDefinition' => $baseDir . '/src/FixerDefinition/FixerDefinition.php',
  29541. 'PhpCsFixer\\FixerDefinition\\FixerDefinitionInterface' => $baseDir . '/src/FixerDefinition/FixerDefinitionInterface.php',
  29542. 'PhpCsFixer\\FixerDefinition\\VersionSpecificCodeSample' => $baseDir . '/src/FixerDefinition/VersionSpecificCodeSample.php',
  29543. 'PhpCsFixer\\FixerDefinition\\VersionSpecificCodeSampleInterface' => $baseDir . '/src/FixerDefinition/VersionSpecificCodeSampleInterface.php',
  29544. 'PhpCsFixer\\FixerDefinition\\VersionSpecification' => $baseDir . '/src/FixerDefinition/VersionSpecification.php',
  29545. 'PhpCsFixer\\FixerDefinition\\VersionSpecificationInterface' => $baseDir . '/src/FixerDefinition/VersionSpecificationInterface.php',
  29546. 'PhpCsFixer\\FixerFactory' => $baseDir . '/src/FixerFactory.php',
  29547. 'PhpCsFixer\\FixerFileProcessedEvent' => $baseDir . '/src/FixerFileProcessedEvent.php',
  29548. 'PhpCsFixer\\FixerNameValidator' => $baseDir . '/src/FixerNameValidator.php',
  29549. 'PhpCsFixer\\Fixer\\Alias\\BacktickToShellExecFixer' => $baseDir . '/src/Fixer/Alias/BacktickToShellExecFixer.php',
  29550. 'PhpCsFixer\\Fixer\\Alias\\EregToPregFixer' => $baseDir . '/src/Fixer/Alias/EregToPregFixer.php',
  29551. 'PhpCsFixer\\Fixer\\Alias\\MbStrFunctionsFixer' => $baseDir . '/src/Fixer/Alias/MbStrFunctionsFixer.php',
  29552. 'PhpCsFixer\\Fixer\\Alias\\NoAliasFunctionsFixer' => $baseDir . '/src/Fixer/Alias/NoAliasFunctionsFixer.php',
  29553. 'PhpCsFixer\\Fixer\\Alias\\NoMixedEchoPrintFixer' => $baseDir . '/src/Fixer/Alias/NoMixedEchoPrintFixer.php',
  29554. 'PhpCsFixer\\Fixer\\Alias\\PowToExponentiationFixer' => $baseDir . '/src/Fixer/Alias/PowToExponentiationFixer.php',
  29555. 'PhpCsFixer\\Fixer\\Alias\\RandomApiMigrationFixer' => $baseDir . '/src/Fixer/Alias/RandomApiMigrationFixer.php',
  29556. 'PhpCsFixer\\Fixer\\ArrayNotation\\ArraySyntaxFixer' => $baseDir . '/src/Fixer/ArrayNotation/ArraySyntaxFixer.php',
  29557. 'PhpCsFixer\\Fixer\\ArrayNotation\\NoMultilineWhitespaceAroundDoubleArrowFixer' => $baseDir . '/src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php',
  29558. 'PhpCsFixer\\Fixer\\ArrayNotation\\NoTrailingCommaInSinglelineArrayFixer' => $baseDir . '/src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php',
  29559. 'PhpCsFixer\\Fixer\\ArrayNotation\\NoWhitespaceBeforeCommaInArrayFixer' => $baseDir . '/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php',
  29560. 'PhpCsFixer\\Fixer\\ArrayNotation\\NormalizeIndexBraceFixer' => $baseDir . '/src/Fixer/ArrayNotation/NormalizeIndexBraceFixer.php',
  29561. 'PhpCsFixer\\Fixer\\ArrayNotation\\TrailingCommaInMultilineArrayFixer' => $baseDir . '/src/Fixer/ArrayNotation/TrailingCommaInMultilineArrayFixer.php',
  29562. 'PhpCsFixer\\Fixer\\ArrayNotation\\TrimArraySpacesFixer' => $baseDir . '/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php',
  29563. 'PhpCsFixer\\Fixer\\ArrayNotation\\WhitespaceAfterCommaInArrayFixer' => $baseDir . '/src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php',
  29564. 'PhpCsFixer\\Fixer\\Basic\\BracesFixer' => $baseDir . '/src/Fixer/Basic/BracesFixer.php',
  29565. 'PhpCsFixer\\Fixer\\Basic\\EncodingFixer' => $baseDir . '/src/Fixer/Basic/EncodingFixer.php',
  29566. 'PhpCsFixer\\Fixer\\Basic\\NonPrintableCharacterFixer' => $baseDir . '/src/Fixer/Basic/NonPrintableCharacterFixer.php',
  29567. 'PhpCsFixer\\Fixer\\Basic\\Psr0Fixer' => $baseDir . '/src/Fixer/Basic/Psr0Fixer.php',
  29568. 'PhpCsFixer\\Fixer\\Basic\\Psr4Fixer' => $baseDir . '/src/Fixer/Basic/Psr4Fixer.php',
  29569. 'PhpCsFixer\\Fixer\\Casing\\LowercaseConstantsFixer' => $baseDir . '/src/Fixer/Casing/LowercaseConstantsFixer.php',
  29570. 'PhpCsFixer\\Fixer\\Casing\\LowercaseKeywordsFixer' => $baseDir . '/src/Fixer/Casing/LowercaseKeywordsFixer.php',
  29571. 'PhpCsFixer\\Fixer\\Casing\\MagicConstantCasingFixer' => $baseDir . '/src/Fixer/Casing/MagicConstantCasingFixer.php',
  29572. 'PhpCsFixer\\Fixer\\Casing\\NativeFunctionCasingFixer' => $baseDir . '/src/Fixer/Casing/NativeFunctionCasingFixer.php',
  29573. 'PhpCsFixer\\Fixer\\CastNotation\\CastSpacesFixer' => $baseDir . '/src/Fixer/CastNotation/CastSpacesFixer.php',
  29574. 'PhpCsFixer\\Fixer\\CastNotation\\LowercaseCastFixer' => $baseDir . '/src/Fixer/CastNotation/LowercaseCastFixer.php',
  29575. 'PhpCsFixer\\Fixer\\CastNotation\\ModernizeTypesCastingFixer' => $baseDir . '/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php',
  29576. 'PhpCsFixer\\Fixer\\CastNotation\\NoShortBoolCastFixer' => $baseDir . '/src/Fixer/CastNotation/NoShortBoolCastFixer.php',
  29577. 'PhpCsFixer\\Fixer\\CastNotation\\ShortScalarCastFixer' => $baseDir . '/src/Fixer/CastNotation/ShortScalarCastFixer.php',
  29578. 'PhpCsFixer\\Fixer\\ClassNotation\\ClassAttributesSeparationFixer' => $baseDir . '/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php',
  29579. 'PhpCsFixer\\Fixer\\ClassNotation\\ClassDefinitionFixer' => $baseDir . '/src/Fixer/ClassNotation/ClassDefinitionFixer.php',
  29580. 'PhpCsFixer\\Fixer\\ClassNotation\\FinalInternalClassFixer' => $baseDir . '/src/Fixer/ClassNotation/FinalInternalClassFixer.php',
  29581. 'PhpCsFixer\\Fixer\\ClassNotation\\MethodSeparationFixer' => $baseDir . '/src/Fixer/ClassNotation/MethodSeparationFixer.php',
  29582. 'PhpCsFixer\\Fixer\\ClassNotation\\NoBlankLinesAfterClassOpeningFixer' => $baseDir . '/src/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixer.php',
  29583. 'PhpCsFixer\\Fixer\\ClassNotation\\NoNullPropertyInitializationFixer' => $baseDir . '/src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php',
  29584. 'PhpCsFixer\\Fixer\\ClassNotation\\NoPhp4ConstructorFixer' => $baseDir . '/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php',
  29585. 'PhpCsFixer\\Fixer\\ClassNotation\\NoUnneededFinalMethodFixer' => $baseDir . '/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php',
  29586. 'PhpCsFixer\\Fixer\\ClassNotation\\OrderedClassElementsFixer' => $baseDir . '/src/Fixer/ClassNotation/OrderedClassElementsFixer.php',
  29587. 'PhpCsFixer\\Fixer\\ClassNotation\\ProtectedToPrivateFixer' => $baseDir . '/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php',
  29588. 'PhpCsFixer\\Fixer\\ClassNotation\\SelfAccessorFixer' => $baseDir . '/src/Fixer/ClassNotation/SelfAccessorFixer.php',
  29589. 'PhpCsFixer\\Fixer\\ClassNotation\\SingleClassElementPerStatementFixer' => $baseDir . '/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php',
  29590. 'PhpCsFixer\\Fixer\\ClassNotation\\VisibilityRequiredFixer' => $baseDir . '/src/Fixer/ClassNotation/VisibilityRequiredFixer.php',
  29591. 'PhpCsFixer\\Fixer\\Comment\\HashToSlashCommentFixer' => $baseDir . '/src/Fixer/Comment/HashToSlashCommentFixer.php',
  29592. 'PhpCsFixer\\Fixer\\Comment\\HeaderCommentFixer' => $baseDir . '/src/Fixer/Comment/HeaderCommentFixer.php',
  29593. 'PhpCsFixer\\Fixer\\Comment\\MultilineCommentOpeningClosingFixer' => $baseDir . '/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php',
  29594. 'PhpCsFixer\\Fixer\\Comment\\NoEmptyCommentFixer' => $baseDir . '/src/Fixer/Comment/NoEmptyCommentFixer.php',
  29595. 'PhpCsFixer\\Fixer\\Comment\\NoTrailingWhitespaceInCommentFixer' => $baseDir . '/src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php',
  29596. 'PhpCsFixer\\Fixer\\Comment\\SingleLineCommentStyleFixer' => $baseDir . '/src/Fixer/Comment/SingleLineCommentStyleFixer.php',
  29597. 'PhpCsFixer\\Fixer\\ConfigurableFixerInterface' => $baseDir . '/src/Fixer/ConfigurableFixerInterface.php',
  29598. 'PhpCsFixer\\Fixer\\ConfigurationDefinitionFixerInterface' => $baseDir . '/src/Fixer/ConfigurationDefinitionFixerInterface.php',
  29599. 'PhpCsFixer\\Fixer\\ControlStructure\\ElseifFixer' => $baseDir . '/src/Fixer/ControlStructure/ElseifFixer.php',
  29600. 'PhpCsFixer\\Fixer\\ControlStructure\\IncludeFixer' => $baseDir . '/src/Fixer/ControlStructure/IncludeFixer.php',
  29601. 'PhpCsFixer\\Fixer\\ControlStructure\\NoBreakCommentFixer' => $baseDir . '/src/Fixer/ControlStructure/NoBreakCommentFixer.php',
  29602. 'PhpCsFixer\\Fixer\\ControlStructure\\NoSuperfluousElseifFixer' => $baseDir . '/src/Fixer/ControlStructure/NoSuperfluousElseifFixer.php',
  29603. 'PhpCsFixer\\Fixer\\ControlStructure\\NoTrailingCommaInListCallFixer' => $baseDir . '/src/Fixer/ControlStructure/NoTrailingCommaInListCallFixer.php',
  29604. 'PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededControlParenthesesFixer' => $baseDir . '/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php',
  29605. 'PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededCurlyBracesFixer' => $baseDir . '/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php',
  29606. 'PhpCsFixer\\Fixer\\ControlStructure\\NoUselessElseFixer' => $baseDir . '/src/Fixer/ControlStructure/NoUselessElseFixer.php',
  29607. 'PhpCsFixer\\Fixer\\ControlStructure\\SwitchCaseSemicolonToColonFixer' => $baseDir . '/src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php',
  29608. 'PhpCsFixer\\Fixer\\ControlStructure\\SwitchCaseSpaceFixer' => $baseDir . '/src/Fixer/ControlStructure/SwitchCaseSpaceFixer.php',
  29609. 'PhpCsFixer\\Fixer\\ControlStructure\\YodaStyleFixer' => $baseDir . '/src/Fixer/ControlStructure/YodaStyleFixer.php',
  29610. 'PhpCsFixer\\Fixer\\DefinedFixerInterface' => $baseDir . '/src/Fixer/DefinedFixerInterface.php',
  29611. 'PhpCsFixer\\Fixer\\DeprecatedFixerInterface' => $baseDir . '/src/Fixer/DeprecatedFixerInterface.php',
  29612. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationArrayAssignmentFixer' => $baseDir . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationArrayAssignmentFixer.php',
  29613. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationBracesFixer' => $baseDir . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php',
  29614. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationIndentationFixer' => $baseDir . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php',
  29615. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationSpacesFixer' => $baseDir . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php',
  29616. 'PhpCsFixer\\Fixer\\FixerInterface' => $baseDir . '/src/Fixer/FixerInterface.php',
  29617. 'PhpCsFixer\\Fixer\\FunctionNotation\\FunctionDeclarationFixer' => $baseDir . '/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php',
  29618. 'PhpCsFixer\\Fixer\\FunctionNotation\\FunctionTypehintSpaceFixer' => $baseDir . '/src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php',
  29619. 'PhpCsFixer\\Fixer\\FunctionNotation\\MethodArgumentSpaceFixer' => $baseDir . '/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php',
  29620. 'PhpCsFixer\\Fixer\\FunctionNotation\\NativeFunctionInvocationFixer' => $baseDir . '/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php',
  29621. 'PhpCsFixer\\Fixer\\FunctionNotation\\NoSpacesAfterFunctionNameFixer' => $baseDir . '/src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php',
  29622. 'PhpCsFixer\\Fixer\\FunctionNotation\\NoUnreachableDefaultArgumentValueFixer' => $baseDir . '/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php',
  29623. 'PhpCsFixer\\Fixer\\FunctionNotation\\ReturnTypeDeclarationFixer' => $baseDir . '/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php',
  29624. 'PhpCsFixer\\Fixer\\FunctionNotation\\StaticLambdaFixer' => $baseDir . '/src/Fixer/FunctionNotation/StaticLambdaFixer.php',
  29625. 'PhpCsFixer\\Fixer\\FunctionNotation\\VoidReturnFixer' => $baseDir . '/src/Fixer/FunctionNotation/VoidReturnFixer.php',
  29626. 'PhpCsFixer\\Fixer\\Import\\NoLeadingImportSlashFixer' => $baseDir . '/src/Fixer/Import/NoLeadingImportSlashFixer.php',
  29627. 'PhpCsFixer\\Fixer\\Import\\NoUnusedImportsFixer' => $baseDir . '/src/Fixer/Import/NoUnusedImportsFixer.php',
  29628. 'PhpCsFixer\\Fixer\\Import\\OrderedImportsFixer' => $baseDir . '/src/Fixer/Import/OrderedImportsFixer.php',
  29629. 'PhpCsFixer\\Fixer\\Import\\SingleImportPerStatementFixer' => $baseDir . '/src/Fixer/Import/SingleImportPerStatementFixer.php',
  29630. 'PhpCsFixer\\Fixer\\Import\\SingleLineAfterImportsFixer' => $baseDir . '/src/Fixer/Import/SingleLineAfterImportsFixer.php',
  29631. 'PhpCsFixer\\Fixer\\LanguageConstruct\\ClassKeywordRemoveFixer' => $baseDir . '/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php',
  29632. 'PhpCsFixer\\Fixer\\LanguageConstruct\\CombineConsecutiveIssetsFixer' => $baseDir . '/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php',
  29633. 'PhpCsFixer\\Fixer\\LanguageConstruct\\CombineConsecutiveUnsetsFixer' => $baseDir . '/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php',
  29634. 'PhpCsFixer\\Fixer\\LanguageConstruct\\DeclareEqualNormalizeFixer' => $baseDir . '/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php',
  29635. 'PhpCsFixer\\Fixer\\LanguageConstruct\\DirConstantFixer' => $baseDir . '/src/Fixer/LanguageConstruct/DirConstantFixer.php',
  29636. 'PhpCsFixer\\Fixer\\LanguageConstruct\\ExplicitIndirectVariableFixer' => $baseDir . '/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php',
  29637. 'PhpCsFixer\\Fixer\\LanguageConstruct\\FunctionToConstantFixer' => $baseDir . '/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php',
  29638. 'PhpCsFixer\\Fixer\\LanguageConstruct\\IsNullFixer' => $baseDir . '/src/Fixer/LanguageConstruct/IsNullFixer.php',
  29639. 'PhpCsFixer\\Fixer\\LanguageConstruct\\SilencedDeprecationErrorFixer' => $baseDir . '/src/Fixer/LanguageConstruct/SilencedDeprecationErrorFixer.php',
  29640. 'PhpCsFixer\\Fixer\\ListNotation\\ListSyntaxFixer' => $baseDir . '/src/Fixer/ListNotation/ListSyntaxFixer.php',
  29641. 'PhpCsFixer\\Fixer\\NamespaceNotation\\BlankLineAfterNamespaceFixer' => $baseDir . '/src/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixer.php',
  29642. 'PhpCsFixer\\Fixer\\NamespaceNotation\\NoBlankLinesBeforeNamespaceFixer' => $baseDir . '/src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.php',
  29643. 'PhpCsFixer\\Fixer\\NamespaceNotation\\NoLeadingNamespaceWhitespaceFixer' => $baseDir . '/src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php',
  29644. 'PhpCsFixer\\Fixer\\NamespaceNotation\\SingleBlankLineBeforeNamespaceFixer' => $baseDir . '/src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php',
  29645. 'PhpCsFixer\\Fixer\\Naming\\NoHomoglyphNamesFixer' => $baseDir . '/src/Fixer/Naming/NoHomoglyphNamesFixer.php',
  29646. 'PhpCsFixer\\Fixer\\Operator\\AlignDoubleArrowFixerHelper' => $baseDir . '/src/Fixer/Operator/AlignDoubleArrowFixerHelper.php',
  29647. 'PhpCsFixer\\Fixer\\Operator\\AlignEqualsFixerHelper' => $baseDir . '/src/Fixer/Operator/AlignEqualsFixerHelper.php',
  29648. 'PhpCsFixer\\Fixer\\Operator\\BinaryOperatorSpacesFixer' => $baseDir . '/src/Fixer/Operator/BinaryOperatorSpacesFixer.php',
  29649. 'PhpCsFixer\\Fixer\\Operator\\ConcatSpaceFixer' => $baseDir . '/src/Fixer/Operator/ConcatSpaceFixer.php',
  29650. 'PhpCsFixer\\Fixer\\Operator\\IncrementStyleFixer' => $baseDir . '/src/Fixer/Operator/IncrementStyleFixer.php',
  29651. 'PhpCsFixer\\Fixer\\Operator\\NewWithBracesFixer' => $baseDir . '/src/Fixer/Operator/NewWithBracesFixer.php',
  29652. 'PhpCsFixer\\Fixer\\Operator\\NotOperatorWithSpaceFixer' => $baseDir . '/src/Fixer/Operator/NotOperatorWithSpaceFixer.php',
  29653. 'PhpCsFixer\\Fixer\\Operator\\NotOperatorWithSuccessorSpaceFixer' => $baseDir . '/src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php',
  29654. 'PhpCsFixer\\Fixer\\Operator\\ObjectOperatorWithoutWhitespaceFixer' => $baseDir . '/src/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixer.php',
  29655. 'PhpCsFixer\\Fixer\\Operator\\PreIncrementFixer' => $baseDir . '/src/Fixer/Operator/PreIncrementFixer.php',
  29656. 'PhpCsFixer\\Fixer\\Operator\\StandardizeNotEqualsFixer' => $baseDir . '/src/Fixer/Operator/StandardizeNotEqualsFixer.php',
  29657. 'PhpCsFixer\\Fixer\\Operator\\TernaryOperatorSpacesFixer' => $baseDir . '/src/Fixer/Operator/TernaryOperatorSpacesFixer.php',
  29658. 'PhpCsFixer\\Fixer\\Operator\\TernaryToNullCoalescingFixer' => $baseDir . '/src/Fixer/Operator/TernaryToNullCoalescingFixer.php',
  29659. 'PhpCsFixer\\Fixer\\Operator\\UnaryOperatorSpacesFixer' => $baseDir . '/src/Fixer/Operator/UnaryOperatorSpacesFixer.php',
  29660. 'PhpCsFixer\\Fixer\\PhpTag\\BlankLineAfterOpeningTagFixer' => $baseDir . '/src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php',
  29661. 'PhpCsFixer\\Fixer\\PhpTag\\FullOpeningTagFixer' => $baseDir . '/src/Fixer/PhpTag/FullOpeningTagFixer.php',
  29662. 'PhpCsFixer\\Fixer\\PhpTag\\LinebreakAfterOpeningTagFixer' => $baseDir . '/src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php',
  29663. 'PhpCsFixer\\Fixer\\PhpTag\\NoClosingTagFixer' => $baseDir . '/src/Fixer/PhpTag/NoClosingTagFixer.php',
  29664. 'PhpCsFixer\\Fixer\\PhpTag\\NoShortEchoTagFixer' => $baseDir . '/src/Fixer/PhpTag/NoShortEchoTagFixer.php',
  29665. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitConstructFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitConstructFixer.php',
  29666. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitDedicateAssertFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php',
  29667. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitExpectationFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php',
  29668. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitFqcnAnnotationFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.php',
  29669. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitMockFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitMockFixer.php',
  29670. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitNamespacedFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php',
  29671. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitNoExpectationAnnotationFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php',
  29672. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitStrictFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitStrictFixer.php',
  29673. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitTargetVersion' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitTargetVersion.php',
  29674. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitTestAnnotationFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php',
  29675. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitTestClassRequiresCoversFixer' => $baseDir . '/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php',
  29676. 'PhpCsFixer\\Fixer\\Phpdoc\\AlignMultilineCommentFixer' => $baseDir . '/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php',
  29677. 'PhpCsFixer\\Fixer\\Phpdoc\\GeneralPhpdocAnnotationRemoveFixer' => $baseDir . '/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php',
  29678. 'PhpCsFixer\\Fixer\\Phpdoc\\NoBlankLinesAfterPhpdocFixer' => $baseDir . '/src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php',
  29679. 'PhpCsFixer\\Fixer\\Phpdoc\\NoEmptyPhpdocFixer' => $baseDir . '/src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php',
  29680. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAddMissingParamAnnotationFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php',
  29681. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAlignFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocAlignFixer.php',
  29682. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAnnotationWithoutDotFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php',
  29683. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocIndentFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocIndentFixer.php',
  29684. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocInlineTagFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocInlineTagFixer.php',
  29685. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoAccessFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocNoAccessFixer.php',
  29686. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoAliasTagFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php',
  29687. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoEmptyReturnFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php',
  29688. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoPackageFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocNoPackageFixer.php',
  29689. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoUselessInheritdocFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php',
  29690. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocOrderFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocOrderFixer.php',
  29691. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocReturnSelfReferenceFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php',
  29692. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocScalarFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocScalarFixer.php',
  29693. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSeparationFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocSeparationFixer.php',
  29694. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSingleLineVarSpacingFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php',
  29695. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSummaryFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocSummaryFixer.php',
  29696. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocToCommentFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocToCommentFixer.php',
  29697. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocTrimFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocTrimFixer.php',
  29698. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocTypesFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocTypesFixer.php',
  29699. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocTypesOrderFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php',
  29700. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocVarWithoutNameFixer' => $baseDir . '/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php',
  29701. 'PhpCsFixer\\Fixer\\ReturnNotation\\BlankLineBeforeReturnFixer' => $baseDir . '/src/Fixer/ReturnNotation/BlankLineBeforeReturnFixer.php',
  29702. 'PhpCsFixer\\Fixer\\ReturnNotation\\NoUselessReturnFixer' => $baseDir . '/src/Fixer/ReturnNotation/NoUselessReturnFixer.php',
  29703. 'PhpCsFixer\\Fixer\\ReturnNotation\\SimplifiedNullReturnFixer' => $baseDir . '/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php',
  29704. 'PhpCsFixer\\Fixer\\Semicolon\\MultilineWhitespaceBeforeSemicolonsFixer' => $baseDir . '/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php',
  29705. 'PhpCsFixer\\Fixer\\Semicolon\\NoEmptyStatementFixer' => $baseDir . '/src/Fixer/Semicolon/NoEmptyStatementFixer.php',
  29706. 'PhpCsFixer\\Fixer\\Semicolon\\NoMultilineWhitespaceBeforeSemicolonsFixer' => $baseDir . '/src/Fixer/Semicolon/NoMultilineWhitespaceBeforeSemicolonsFixer.php',
  29707. 'PhpCsFixer\\Fixer\\Semicolon\\NoSinglelineWhitespaceBeforeSemicolonsFixer' => $baseDir . '/src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php',
  29708. 'PhpCsFixer\\Fixer\\Semicolon\\SemicolonAfterInstructionFixer' => $baseDir . '/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php',
  29709. 'PhpCsFixer\\Fixer\\Semicolon\\SpaceAfterSemicolonFixer' => $baseDir . '/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php',
  29710. 'PhpCsFixer\\Fixer\\Strict\\DeclareStrictTypesFixer' => $baseDir . '/src/Fixer/Strict/DeclareStrictTypesFixer.php',
  29711. 'PhpCsFixer\\Fixer\\Strict\\StrictComparisonFixer' => $baseDir . '/src/Fixer/Strict/StrictComparisonFixer.php',
  29712. 'PhpCsFixer\\Fixer\\Strict\\StrictParamFixer' => $baseDir . '/src/Fixer/Strict/StrictParamFixer.php',
  29713. 'PhpCsFixer\\Fixer\\StringNotation\\EscapeImplicitBackslashesFixer' => $baseDir . '/src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php',
  29714. 'PhpCsFixer\\Fixer\\StringNotation\\ExplicitStringVariableFixer' => $baseDir . '/src/Fixer/StringNotation/ExplicitStringVariableFixer.php',
  29715. 'PhpCsFixer\\Fixer\\StringNotation\\HeredocToNowdocFixer' => $baseDir . '/src/Fixer/StringNotation/HeredocToNowdocFixer.php',
  29716. 'PhpCsFixer\\Fixer\\StringNotation\\SingleQuoteFixer' => $baseDir . '/src/Fixer/StringNotation/SingleQuoteFixer.php',
  29717. 'PhpCsFixer\\Fixer\\Whitespace\\BlankLineBeforeStatementFixer' => $baseDir . '/src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php',
  29718. 'PhpCsFixer\\Fixer\\Whitespace\\CompactNullableTypehintFixer' => $baseDir . '/src/Fixer/Whitespace/CompactNullableTypehintFixer.php',
  29719. 'PhpCsFixer\\Fixer\\Whitespace\\IndentationTypeFixer' => $baseDir . '/src/Fixer/Whitespace/IndentationTypeFixer.php',
  29720. 'PhpCsFixer\\Fixer\\Whitespace\\LineEndingFixer' => $baseDir . '/src/Fixer/Whitespace/LineEndingFixer.php',
  29721. 'PhpCsFixer\\Fixer\\Whitespace\\MethodChainingIndentationFixer' => $baseDir . '/src/Fixer/Whitespace/MethodChainingIndentationFixer.php',
  29722. 'PhpCsFixer\\Fixer\\Whitespace\\NoExtraBlankLinesFixer' => $baseDir . '/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php',
  29723. 'PhpCsFixer\\Fixer\\Whitespace\\NoExtraConsecutiveBlankLinesFixer' => $baseDir . '/src/Fixer/Whitespace/NoExtraConsecutiveBlankLinesFixer.php',
  29724. 'PhpCsFixer\\Fixer\\Whitespace\\NoSpacesAroundOffsetFixer' => $baseDir . '/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php',
  29725. 'PhpCsFixer\\Fixer\\Whitespace\\NoSpacesInsideParenthesisFixer' => $baseDir . '/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php',
  29726. 'PhpCsFixer\\Fixer\\Whitespace\\NoTrailingWhitespaceFixer' => $baseDir . '/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php',
  29727. 'PhpCsFixer\\Fixer\\Whitespace\\NoWhitespaceInBlankLineFixer' => $baseDir . '/src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php',
  29728. 'PhpCsFixer\\Fixer\\Whitespace\\SingleBlankLineAtEofFixer' => $baseDir . '/src/Fixer/Whitespace/SingleBlankLineAtEofFixer.php',
  29729. 'PhpCsFixer\\Fixer\\WhitespacesAwareFixerInterface' => $baseDir . '/src/Fixer/WhitespacesAwareFixerInterface.php',
  29730. 'PhpCsFixer\\Indicator\\PhpUnitTestCaseIndicator' => $baseDir . '/src/Indicator/PhpUnitTestCaseIndicator.php',
  29731. 'PhpCsFixer\\Linter\\Linter' => $baseDir . '/src/Linter/Linter.php',
  29732. 'PhpCsFixer\\Linter\\LinterInterface' => $baseDir . '/src/Linter/LinterInterface.php',
  29733. 'PhpCsFixer\\Linter\\LintingException' => $baseDir . '/src/Linter/LintingException.php',
  29734. 'PhpCsFixer\\Linter\\LintingResultInterface' => $baseDir . '/src/Linter/LintingResultInterface.php',
  29735. 'PhpCsFixer\\Linter\\ProcessLinter' => $baseDir . '/src/Linter/ProcessLinter.php',
  29736. 'PhpCsFixer\\Linter\\ProcessLinterProcessBuilder' => $baseDir . '/src/Linter/ProcessLinterProcessBuilder.php',
  29737. 'PhpCsFixer\\Linter\\ProcessLintingResult' => $baseDir . '/src/Linter/ProcessLintingResult.php',
  29738. 'PhpCsFixer\\Linter\\TokenizerLinter' => $baseDir . '/src/Linter/TokenizerLinter.php',
  29739. 'PhpCsFixer\\Linter\\TokenizerLintingResult' => $baseDir . '/src/Linter/TokenizerLintingResult.php',
  29740. 'PhpCsFixer\\Linter\\UnavailableLinterException' => $baseDir . '/src/Linter/UnavailableLinterException.php',
  29741. 'PhpCsFixer\\PharChecker' => $baseDir . '/src/PharChecker.php',
  29742. 'PhpCsFixer\\PharCheckerInterface' => $baseDir . '/src/PharCheckerInterface.php',
  29743. 'PhpCsFixer\\Report\\CheckstyleReporter' => $baseDir . '/src/Report/CheckstyleReporter.php',
  29744. 'PhpCsFixer\\Report\\JsonReporter' => $baseDir . '/src/Report/JsonReporter.php',
  29745. 'PhpCsFixer\\Report\\JunitReporter' => $baseDir . '/src/Report/JunitReporter.php',
  29746. 'PhpCsFixer\\Report\\ReportSummary' => $baseDir . '/src/Report/ReportSummary.php',
  29747. 'PhpCsFixer\\Report\\ReporterFactory' => $baseDir . '/src/Report/ReporterFactory.php',
  29748. 'PhpCsFixer\\Report\\ReporterInterface' => $baseDir . '/src/Report/ReporterInterface.php',
  29749. 'PhpCsFixer\\Report\\TextReporter' => $baseDir . '/src/Report/TextReporter.php',
  29750. 'PhpCsFixer\\Report\\XmlReporter' => $baseDir . '/src/Report/XmlReporter.php',
  29751. 'PhpCsFixer\\RuleSet' => $baseDir . '/src/RuleSet.php',
  29752. 'PhpCsFixer\\RuleSetInterface' => $baseDir . '/src/RuleSetInterface.php',
  29753. 'PhpCsFixer\\Runner\\FileCachingLintingIterator' => $baseDir . '/src/Runner/FileCachingLintingIterator.php',
  29754. 'PhpCsFixer\\Runner\\FileFilterIterator' => $baseDir . '/src/Runner/FileFilterIterator.php',
  29755. 'PhpCsFixer\\Runner\\FileLintingIterator' => $baseDir . '/src/Runner/FileLintingIterator.php',
  29756. 'PhpCsFixer\\Runner\\Runner' => $baseDir . '/src/Runner/Runner.php',
  29757. 'PhpCsFixer\\StdinFileInfo' => $baseDir . '/src/StdinFileInfo.php',
  29758. 'PhpCsFixer\\Test\\AbstractFixerTestCase' => $baseDir . '/src/Test/AbstractFixerTestCase.php',
  29759. 'PhpCsFixer\\Test\\AbstractIntegrationTestCase' => $baseDir . '/src/Test/AbstractIntegrationTestCase.php',
  29760. 'PhpCsFixer\\Test\\AccessibleObject' => $baseDir . '/src/Test/AccessibleObject.php',
  29761. 'PhpCsFixer\\Test\\IntegrationCase' => $baseDir . '/src/Test/IntegrationCase.php',
  29762. 'PhpCsFixer\\Tests\\TestCase' => $baseDir . '/tests/TestCase.php',
  29763. 'PhpCsFixer\\Tests\\Test\\AbstractFixerTestCase' => $baseDir . '/tests/Test/AbstractFixerTestCase.php',
  29764. 'PhpCsFixer\\Tests\\Test\\AbstractIntegrationTestCase' => $baseDir . '/tests/Test/AbstractIntegrationTestCase.php',
  29765. 'PhpCsFixer\\Tests\\Test\\Assert\\AssertTokensTrait' => $baseDir . '/tests/Test/Assert/AssertTokensTrait.php',
  29766. 'PhpCsFixer\\Tests\\Test\\IntegrationCase' => $baseDir . '/tests/Test/IntegrationCase.php',
  29767. 'PhpCsFixer\\Tests\\Test\\IntegrationCaseFactory' => $baseDir . '/tests/Test/IntegrationCaseFactory.php',
  29768. 'PhpCsFixer\\Tokenizer\\AbstractTransformer' => $baseDir . '/src/Tokenizer/AbstractTransformer.php',
  29769. 'PhpCsFixer\\Tokenizer\\Analyzer\\ArgumentsAnalyzer' => $baseDir . '/src/Tokenizer/Analyzer/ArgumentsAnalyzer.php',
  29770. 'PhpCsFixer\\Tokenizer\\CT' => $baseDir . '/src/Tokenizer/CT.php',
  29771. 'PhpCsFixer\\Tokenizer\\CodeHasher' => $baseDir . '/src/Tokenizer/CodeHasher.php',
  29772. 'PhpCsFixer\\Tokenizer\\Token' => $baseDir . '/src/Tokenizer/Token.php',
  29773. 'PhpCsFixer\\Tokenizer\\Tokens' => $baseDir . '/src/Tokenizer/Tokens.php',
  29774. 'PhpCsFixer\\Tokenizer\\TokensAnalyzer' => $baseDir . '/src/Tokenizer/TokensAnalyzer.php',
  29775. 'PhpCsFixer\\Tokenizer\\TransformerInterface' => $baseDir . '/src/Tokenizer/TransformerInterface.php',
  29776. 'PhpCsFixer\\Tokenizer\\Transformer\\ArrayTypehintTransformer' => $baseDir . '/src/Tokenizer/Transformer/ArrayTypehintTransformer.php',
  29777. 'PhpCsFixer\\Tokenizer\\Transformer\\BraceClassInstantiationTransformer' => $baseDir . '/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php',
  29778. 'PhpCsFixer\\Tokenizer\\Transformer\\ClassConstantTransformer' => $baseDir . '/src/Tokenizer/Transformer/ClassConstantTransformer.php',
  29779. 'PhpCsFixer\\Tokenizer\\Transformer\\CurlyBraceTransformer' => $baseDir . '/src/Tokenizer/Transformer/CurlyBraceTransformer.php',
  29780. 'PhpCsFixer\\Tokenizer\\Transformer\\ImportTransformer' => $baseDir . '/src/Tokenizer/Transformer/ImportTransformer.php',
  29781. 'PhpCsFixer\\Tokenizer\\Transformer\\NamespaceOperatorTransformer' => $baseDir . '/src/Tokenizer/Transformer/NamespaceOperatorTransformer.php',
  29782. 'PhpCsFixer\\Tokenizer\\Transformer\\NullableTypeTransformer' => $baseDir . '/src/Tokenizer/Transformer/NullableTypeTransformer.php',
  29783. 'PhpCsFixer\\Tokenizer\\Transformer\\ReturnRefTransformer' => $baseDir . '/src/Tokenizer/Transformer/ReturnRefTransformer.php',
  29784. 'PhpCsFixer\\Tokenizer\\Transformer\\SquareBraceTransformer' => $baseDir . '/src/Tokenizer/Transformer/SquareBraceTransformer.php',
  29785. 'PhpCsFixer\\Tokenizer\\Transformer\\TypeAlternationTransformer' => $baseDir . '/src/Tokenizer/Transformer/TypeAlternationTransformer.php',
  29786. 'PhpCsFixer\\Tokenizer\\Transformer\\TypeColonTransformer' => $baseDir . '/src/Tokenizer/Transformer/TypeColonTransformer.php',
  29787. 'PhpCsFixer\\Tokenizer\\Transformer\\UseTransformer' => $baseDir . '/src/Tokenizer/Transformer/UseTransformer.php',
  29788. 'PhpCsFixer\\Tokenizer\\Transformer\\WhitespacyCommentTransformer' => $baseDir . '/src/Tokenizer/Transformer/WhitespacyCommentTransformer.php',
  29789. 'PhpCsFixer\\Tokenizer\\Transformers' => $baseDir . '/src/Tokenizer/Transformers.php',
  29790. 'PhpCsFixer\\ToolInfo' => $baseDir . '/src/ToolInfo.php',
  29791. 'PhpCsFixer\\ToolInfoInterface' => $baseDir . '/src/ToolInfoInterface.php',
  29792. 'PhpCsFixer\\Utils' => $baseDir . '/src/Utils.php',
  29793. 'PhpCsFixer\\WhitespacesFixerConfig' => $baseDir . '/src/WhitespacesFixerConfig.php',
  29794. 'PhpCsFixer\\WordMatcher' => $baseDir . '/src/WordMatcher.php',
  29795. 'Psr\\Log\\AbstractLogger' => $vendorDir . '/psr/log/Psr/Log/AbstractLogger.php',
  29796. 'Psr\\Log\\InvalidArgumentException' => $vendorDir . '/psr/log/Psr/Log/InvalidArgumentException.php',
  29797. 'Psr\\Log\\LogLevel' => $vendorDir . '/psr/log/Psr/Log/LogLevel.php',
  29798. 'Psr\\Log\\LoggerAwareInterface' => $vendorDir . '/psr/log/Psr/Log/LoggerAwareInterface.php',
  29799. 'Psr\\Log\\LoggerAwareTrait' => $vendorDir . '/psr/log/Psr/Log/LoggerAwareTrait.php',
  29800. 'Psr\\Log\\LoggerInterface' => $vendorDir . '/psr/log/Psr/Log/LoggerInterface.php',
  29801. 'Psr\\Log\\LoggerTrait' => $vendorDir . '/psr/log/Psr/Log/LoggerTrait.php',
  29802. 'Psr\\Log\\NullLogger' => $vendorDir . '/psr/log/Psr/Log/NullLogger.php',
  29803. 'Psr\\Log\\Test\\DummyTest' => $vendorDir . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
  29804. 'Psr\\Log\\Test\\LoggerInterfaceTest' => $vendorDir . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
  29805. 'SessionUpdateTimestampHandlerInterface' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/SessionUpdateTimestampHandlerInterface.php',
  29806. 'Symfony\\Component\\Console\\Application' => $vendorDir . '/symfony/console/Application.php',
  29807. 'Symfony\\Component\\Console\\CommandLoader\\CommandLoaderInterface' => $vendorDir . '/symfony/console/CommandLoader/CommandLoaderInterface.php',
  29808. 'Symfony\\Component\\Console\\CommandLoader\\ContainerCommandLoader' => $vendorDir . '/symfony/console/CommandLoader/ContainerCommandLoader.php',
  29809. 'Symfony\\Component\\Console\\CommandLoader\\FactoryCommandLoader' => $vendorDir . '/symfony/console/CommandLoader/FactoryCommandLoader.php',
  29810. 'Symfony\\Component\\Console\\Command\\Command' => $vendorDir . '/symfony/console/Command/Command.php',
  29811. 'Symfony\\Component\\Console\\Command\\HelpCommand' => $vendorDir . '/symfony/console/Command/HelpCommand.php',
  29812. 'Symfony\\Component\\Console\\Command\\ListCommand' => $vendorDir . '/symfony/console/Command/ListCommand.php',
  29813. 'Symfony\\Component\\Console\\Command\\LockableTrait' => $vendorDir . '/symfony/console/Command/LockableTrait.php',
  29814. 'Symfony\\Component\\Console\\ConsoleEvents' => $vendorDir . '/symfony/console/ConsoleEvents.php',
  29815. 'Symfony\\Component\\Console\\DependencyInjection\\AddConsoleCommandPass' => $vendorDir . '/symfony/console/DependencyInjection/AddConsoleCommandPass.php',
  29816. 'Symfony\\Component\\Console\\Descriptor\\ApplicationDescription' => $vendorDir . '/symfony/console/Descriptor/ApplicationDescription.php',
  29817. 'Symfony\\Component\\Console\\Descriptor\\Descriptor' => $vendorDir . '/symfony/console/Descriptor/Descriptor.php',
  29818. 'Symfony\\Component\\Console\\Descriptor\\DescriptorInterface' => $vendorDir . '/symfony/console/Descriptor/DescriptorInterface.php',
  29819. 'Symfony\\Component\\Console\\Descriptor\\JsonDescriptor' => $vendorDir . '/symfony/console/Descriptor/JsonDescriptor.php',
  29820. 'Symfony\\Component\\Console\\Descriptor\\MarkdownDescriptor' => $vendorDir . '/symfony/console/Descriptor/MarkdownDescriptor.php',
  29821. 'Symfony\\Component\\Console\\Descriptor\\TextDescriptor' => $vendorDir . '/symfony/console/Descriptor/TextDescriptor.php',
  29822. 'Symfony\\Component\\Console\\Descriptor\\XmlDescriptor' => $vendorDir . '/symfony/console/Descriptor/XmlDescriptor.php',
  29823. 'Symfony\\Component\\Console\\EventListener\\ErrorListener' => $vendorDir . '/symfony/console/EventListener/ErrorListener.php',
  29824. 'Symfony\\Component\\Console\\Event\\ConsoleCommandEvent' => $vendorDir . '/symfony/console/Event/ConsoleCommandEvent.php',
  29825. 'Symfony\\Component\\Console\\Event\\ConsoleErrorEvent' => $vendorDir . '/symfony/console/Event/ConsoleErrorEvent.php',
  29826. 'Symfony\\Component\\Console\\Event\\ConsoleEvent' => $vendorDir . '/symfony/console/Event/ConsoleEvent.php',
  29827. 'Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent' => $vendorDir . '/symfony/console/Event/ConsoleExceptionEvent.php',
  29828. 'Symfony\\Component\\Console\\Event\\ConsoleTerminateEvent' => $vendorDir . '/symfony/console/Event/ConsoleTerminateEvent.php',
  29829. 'Symfony\\Component\\Console\\Exception\\CommandNotFoundException' => $vendorDir . '/symfony/console/Exception/CommandNotFoundException.php',
  29830. 'Symfony\\Component\\Console\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/console/Exception/ExceptionInterface.php',
  29831. 'Symfony\\Component\\Console\\Exception\\InvalidArgumentException' => $vendorDir . '/symfony/console/Exception/InvalidArgumentException.php',
  29832. 'Symfony\\Component\\Console\\Exception\\InvalidOptionException' => $vendorDir . '/symfony/console/Exception/InvalidOptionException.php',
  29833. 'Symfony\\Component\\Console\\Exception\\LogicException' => $vendorDir . '/symfony/console/Exception/LogicException.php',
  29834. 'Symfony\\Component\\Console\\Exception\\RuntimeException' => $vendorDir . '/symfony/console/Exception/RuntimeException.php',
  29835. 'Symfony\\Component\\Console\\Formatter\\OutputFormatter' => $vendorDir . '/symfony/console/Formatter/OutputFormatter.php',
  29836. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterInterface' => $vendorDir . '/symfony/console/Formatter/OutputFormatterInterface.php',
  29837. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle' => $vendorDir . '/symfony/console/Formatter/OutputFormatterStyle.php',
  29838. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyleInterface' => $vendorDir . '/symfony/console/Formatter/OutputFormatterStyleInterface.php',
  29839. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyleStack' => $vendorDir . '/symfony/console/Formatter/OutputFormatterStyleStack.php',
  29840. 'Symfony\\Component\\Console\\Helper\\DebugFormatterHelper' => $vendorDir . '/symfony/console/Helper/DebugFormatterHelper.php',
  29841. 'Symfony\\Component\\Console\\Helper\\DescriptorHelper' => $vendorDir . '/symfony/console/Helper/DescriptorHelper.php',
  29842. 'Symfony\\Component\\Console\\Helper\\FormatterHelper' => $vendorDir . '/symfony/console/Helper/FormatterHelper.php',
  29843. 'Symfony\\Component\\Console\\Helper\\Helper' => $vendorDir . '/symfony/console/Helper/Helper.php',
  29844. 'Symfony\\Component\\Console\\Helper\\HelperInterface' => $vendorDir . '/symfony/console/Helper/HelperInterface.php',
  29845. 'Symfony\\Component\\Console\\Helper\\HelperSet' => $vendorDir . '/symfony/console/Helper/HelperSet.php',
  29846. 'Symfony\\Component\\Console\\Helper\\InputAwareHelper' => $vendorDir . '/symfony/console/Helper/InputAwareHelper.php',
  29847. 'Symfony\\Component\\Console\\Helper\\ProcessHelper' => $vendorDir . '/symfony/console/Helper/ProcessHelper.php',
  29848. 'Symfony\\Component\\Console\\Helper\\ProgressBar' => $vendorDir . '/symfony/console/Helper/ProgressBar.php',
  29849. 'Symfony\\Component\\Console\\Helper\\ProgressIndicator' => $vendorDir . '/symfony/console/Helper/ProgressIndicator.php',
  29850. 'Symfony\\Component\\Console\\Helper\\QuestionHelper' => $vendorDir . '/symfony/console/Helper/QuestionHelper.php',
  29851. 'Symfony\\Component\\Console\\Helper\\SymfonyQuestionHelper' => $vendorDir . '/symfony/console/Helper/SymfonyQuestionHelper.php',
  29852. 'Symfony\\Component\\Console\\Helper\\Table' => $vendorDir . '/symfony/console/Helper/Table.php',
  29853. 'Symfony\\Component\\Console\\Helper\\TableCell' => $vendorDir . '/symfony/console/Helper/TableCell.php',
  29854. 'Symfony\\Component\\Console\\Helper\\TableSeparator' => $vendorDir . '/symfony/console/Helper/TableSeparator.php',
  29855. 'Symfony\\Component\\Console\\Helper\\TableStyle' => $vendorDir . '/symfony/console/Helper/TableStyle.php',
  29856. 'Symfony\\Component\\Console\\Input\\ArgvInput' => $vendorDir . '/symfony/console/Input/ArgvInput.php',
  29857. 'Symfony\\Component\\Console\\Input\\ArrayInput' => $vendorDir . '/symfony/console/Input/ArrayInput.php',
  29858. 'Symfony\\Component\\Console\\Input\\Input' => $vendorDir . '/symfony/console/Input/Input.php',
  29859. 'Symfony\\Component\\Console\\Input\\InputArgument' => $vendorDir . '/symfony/console/Input/InputArgument.php',
  29860. 'Symfony\\Component\\Console\\Input\\InputAwareInterface' => $vendorDir . '/symfony/console/Input/InputAwareInterface.php',
  29861. 'Symfony\\Component\\Console\\Input\\InputDefinition' => $vendorDir . '/symfony/console/Input/InputDefinition.php',
  29862. 'Symfony\\Component\\Console\\Input\\InputInterface' => $vendorDir . '/symfony/console/Input/InputInterface.php',
  29863. 'Symfony\\Component\\Console\\Input\\InputOption' => $vendorDir . '/symfony/console/Input/InputOption.php',
  29864. 'Symfony\\Component\\Console\\Input\\StreamableInputInterface' => $vendorDir . '/symfony/console/Input/StreamableInputInterface.php',
  29865. 'Symfony\\Component\\Console\\Input\\StringInput' => $vendorDir . '/symfony/console/Input/StringInput.php',
  29866. 'Symfony\\Component\\Console\\Logger\\ConsoleLogger' => $vendorDir . '/symfony/console/Logger/ConsoleLogger.php',
  29867. 'Symfony\\Component\\Console\\Output\\BufferedOutput' => $vendorDir . '/symfony/console/Output/BufferedOutput.php',
  29868. 'Symfony\\Component\\Console\\Output\\ConsoleOutput' => $vendorDir . '/symfony/console/Output/ConsoleOutput.php',
  29869. 'Symfony\\Component\\Console\\Output\\ConsoleOutputInterface' => $vendorDir . '/symfony/console/Output/ConsoleOutputInterface.php',
  29870. 'Symfony\\Component\\Console\\Output\\NullOutput' => $vendorDir . '/symfony/console/Output/NullOutput.php',
  29871. 'Symfony\\Component\\Console\\Output\\Output' => $vendorDir . '/symfony/console/Output/Output.php',
  29872. 'Symfony\\Component\\Console\\Output\\OutputInterface' => $vendorDir . '/symfony/console/Output/OutputInterface.php',
  29873. 'Symfony\\Component\\Console\\Output\\StreamOutput' => $vendorDir . '/symfony/console/Output/StreamOutput.php',
  29874. 'Symfony\\Component\\Console\\Question\\ChoiceQuestion' => $vendorDir . '/symfony/console/Question/ChoiceQuestion.php',
  29875. 'Symfony\\Component\\Console\\Question\\ConfirmationQuestion' => $vendorDir . '/symfony/console/Question/ConfirmationQuestion.php',
  29876. 'Symfony\\Component\\Console\\Question\\Question' => $vendorDir . '/symfony/console/Question/Question.php',
  29877. 'Symfony\\Component\\Console\\Style\\OutputStyle' => $vendorDir . '/symfony/console/Style/OutputStyle.php',
  29878. 'Symfony\\Component\\Console\\Style\\StyleInterface' => $vendorDir . '/symfony/console/Style/StyleInterface.php',
  29879. 'Symfony\\Component\\Console\\Style\\SymfonyStyle' => $vendorDir . '/symfony/console/Style/SymfonyStyle.php',
  29880. 'Symfony\\Component\\Console\\Terminal' => $vendorDir . '/symfony/console/Terminal.php',
  29881. 'Symfony\\Component\\Console\\Tester\\ApplicationTester' => $vendorDir . '/symfony/console/Tester/ApplicationTester.php',
  29882. 'Symfony\\Component\\Console\\Tester\\CommandTester' => $vendorDir . '/symfony/console/Tester/CommandTester.php',
  29883. 'Symfony\\Component\\Debug\\BufferingLogger' => $vendorDir . '/symfony/debug/BufferingLogger.php',
  29884. 'Symfony\\Component\\Debug\\Debug' => $vendorDir . '/symfony/debug/Debug.php',
  29885. 'Symfony\\Component\\Debug\\DebugClassLoader' => $vendorDir . '/symfony/debug/DebugClassLoader.php',
  29886. 'Symfony\\Component\\Debug\\ErrorHandler' => $vendorDir . '/symfony/debug/ErrorHandler.php',
  29887. 'Symfony\\Component\\Debug\\ExceptionHandler' => $vendorDir . '/symfony/debug/ExceptionHandler.php',
  29888. 'Symfony\\Component\\Debug\\Exception\\ClassNotFoundException' => $vendorDir . '/symfony/debug/Exception/ClassNotFoundException.php',
  29889. 'Symfony\\Component\\Debug\\Exception\\ContextErrorException' => $vendorDir . '/symfony/debug/Exception/ContextErrorException.php',
  29890. 'Symfony\\Component\\Debug\\Exception\\FatalErrorException' => $vendorDir . '/symfony/debug/Exception/FatalErrorException.php',
  29891. 'Symfony\\Component\\Debug\\Exception\\FatalThrowableError' => $vendorDir . '/symfony/debug/Exception/FatalThrowableError.php',
  29892. 'Symfony\\Component\\Debug\\Exception\\FlattenException' => $vendorDir . '/symfony/debug/Exception/FlattenException.php',
  29893. 'Symfony\\Component\\Debug\\Exception\\OutOfMemoryException' => $vendorDir . '/symfony/debug/Exception/OutOfMemoryException.php',
  29894. 'Symfony\\Component\\Debug\\Exception\\SilencedErrorContext' => $vendorDir . '/symfony/debug/Exception/SilencedErrorContext.php',
  29895. 'Symfony\\Component\\Debug\\Exception\\UndefinedFunctionException' => $vendorDir . '/symfony/debug/Exception/UndefinedFunctionException.php',
  29896. 'Symfony\\Component\\Debug\\Exception\\UndefinedMethodException' => $vendorDir . '/symfony/debug/Exception/UndefinedMethodException.php',
  29897. 'Symfony\\Component\\Debug\\FatalErrorHandler\\ClassNotFoundFatalErrorHandler' => $vendorDir . '/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php',
  29898. 'Symfony\\Component\\Debug\\FatalErrorHandler\\FatalErrorHandlerInterface' => $vendorDir . '/symfony/debug/FatalErrorHandler/FatalErrorHandlerInterface.php',
  29899. 'Symfony\\Component\\Debug\\FatalErrorHandler\\UndefinedFunctionFatalErrorHandler' => $vendorDir . '/symfony/debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php',
  29900. 'Symfony\\Component\\Debug\\FatalErrorHandler\\UndefinedMethodFatalErrorHandler' => $vendorDir . '/symfony/debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php',
  29901. 'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher' => $vendorDir . '/symfony/event-dispatcher/ContainerAwareEventDispatcher.php',
  29902. 'Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher' => $vendorDir . '/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php',
  29903. 'Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface' => $vendorDir . '/symfony/event-dispatcher/Debug/TraceableEventDispatcherInterface.php',
  29904. 'Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener' => $vendorDir . '/symfony/event-dispatcher/Debug/WrappedListener.php',
  29905. 'Symfony\\Component\\EventDispatcher\\DependencyInjection\\ExtractingEventDispatcher' => $vendorDir . '/symfony/event-dispatcher/DependencyInjection/RegisterListenersPass.php',
  29906. 'Symfony\\Component\\EventDispatcher\\DependencyInjection\\RegisterListenersPass' => $vendorDir . '/symfony/event-dispatcher/DependencyInjection/RegisterListenersPass.php',
  29907. 'Symfony\\Component\\EventDispatcher\\Event' => $vendorDir . '/symfony/event-dispatcher/Event.php',
  29908. 'Symfony\\Component\\EventDispatcher\\EventDispatcher' => $vendorDir . '/symfony/event-dispatcher/EventDispatcher.php',
  29909. 'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface' => $vendorDir . '/symfony/event-dispatcher/EventDispatcherInterface.php',
  29910. 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface' => $vendorDir . '/symfony/event-dispatcher/EventSubscriberInterface.php',
  29911. 'Symfony\\Component\\EventDispatcher\\GenericEvent' => $vendorDir . '/symfony/event-dispatcher/GenericEvent.php',
  29912. 'Symfony\\Component\\EventDispatcher\\ImmutableEventDispatcher' => $vendorDir . '/symfony/event-dispatcher/ImmutableEventDispatcher.php',
  29913. 'Symfony\\Component\\Filesystem\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/filesystem/Exception/ExceptionInterface.php',
  29914. 'Symfony\\Component\\Filesystem\\Exception\\FileNotFoundException' => $vendorDir . '/symfony/filesystem/Exception/FileNotFoundException.php',
  29915. 'Symfony\\Component\\Filesystem\\Exception\\IOException' => $vendorDir . '/symfony/filesystem/Exception/IOException.php',
  29916. 'Symfony\\Component\\Filesystem\\Exception\\IOExceptionInterface' => $vendorDir . '/symfony/filesystem/Exception/IOExceptionInterface.php',
  29917. 'Symfony\\Component\\Filesystem\\Filesystem' => $vendorDir . '/symfony/filesystem/Filesystem.php',
  29918. 'Symfony\\Component\\Filesystem\\LockHandler' => $vendorDir . '/symfony/filesystem/LockHandler.php',
  29919. 'Symfony\\Component\\Finder\\Comparator\\Comparator' => $vendorDir . '/symfony/finder/Comparator/Comparator.php',
  29920. 'Symfony\\Component\\Finder\\Comparator\\DateComparator' => $vendorDir . '/symfony/finder/Comparator/DateComparator.php',
  29921. 'Symfony\\Component\\Finder\\Comparator\\NumberComparator' => $vendorDir . '/symfony/finder/Comparator/NumberComparator.php',
  29922. 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException' => $vendorDir . '/symfony/finder/Exception/AccessDeniedException.php',
  29923. 'Symfony\\Component\\Finder\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/finder/Exception/ExceptionInterface.php',
  29924. 'Symfony\\Component\\Finder\\Finder' => $vendorDir . '/symfony/finder/Finder.php',
  29925. 'Symfony\\Component\\Finder\\Glob' => $vendorDir . '/symfony/finder/Glob.php',
  29926. 'Symfony\\Component\\Finder\\Iterator\\CustomFilterIterator' => $vendorDir . '/symfony/finder/Iterator/CustomFilterIterator.php',
  29927. 'Symfony\\Component\\Finder\\Iterator\\DateRangeFilterIterator' => $vendorDir . '/symfony/finder/Iterator/DateRangeFilterIterator.php',
  29928. 'Symfony\\Component\\Finder\\Iterator\\DepthRangeFilterIterator' => $vendorDir . '/symfony/finder/Iterator/DepthRangeFilterIterator.php',
  29929. 'Symfony\\Component\\Finder\\Iterator\\ExcludeDirectoryFilterIterator' => $vendorDir . '/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php',
  29930. 'Symfony\\Component\\Finder\\Iterator\\FileTypeFilterIterator' => $vendorDir . '/symfony/finder/Iterator/FileTypeFilterIterator.php',
  29931. 'Symfony\\Component\\Finder\\Iterator\\FilecontentFilterIterator' => $vendorDir . '/symfony/finder/Iterator/FilecontentFilterIterator.php',
  29932. 'Symfony\\Component\\Finder\\Iterator\\FilenameFilterIterator' => $vendorDir . '/symfony/finder/Iterator/FilenameFilterIterator.php',
  29933. 'Symfony\\Component\\Finder\\Iterator\\FilterIterator' => $vendorDir . '/symfony/finder/Iterator/FilterIterator.php',
  29934. 'Symfony\\Component\\Finder\\Iterator\\MultiplePcreFilterIterator' => $vendorDir . '/symfony/finder/Iterator/MultiplePcreFilterIterator.php',
  29935. 'Symfony\\Component\\Finder\\Iterator\\PathFilterIterator' => $vendorDir . '/symfony/finder/Iterator/PathFilterIterator.php',
  29936. 'Symfony\\Component\\Finder\\Iterator\\RecursiveDirectoryIterator' => $vendorDir . '/symfony/finder/Iterator/RecursiveDirectoryIterator.php',
  29937. 'Symfony\\Component\\Finder\\Iterator\\SizeRangeFilterIterator' => $vendorDir . '/symfony/finder/Iterator/SizeRangeFilterIterator.php',
  29938. 'Symfony\\Component\\Finder\\Iterator\\SortableIterator' => $vendorDir . '/symfony/finder/Iterator/SortableIterator.php',
  29939. 'Symfony\\Component\\Finder\\SplFileInfo' => $vendorDir . '/symfony/finder/SplFileInfo.php',
  29940. 'Symfony\\Component\\OptionsResolver\\Debug\\OptionsResolverIntrospector' => $vendorDir . '/symfony/options-resolver/Debug/OptionsResolverIntrospector.php',
  29941. 'Symfony\\Component\\OptionsResolver\\Exception\\AccessException' => $vendorDir . '/symfony/options-resolver/Exception/AccessException.php',
  29942. 'Symfony\\Component\\OptionsResolver\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/options-resolver/Exception/ExceptionInterface.php',
  29943. 'Symfony\\Component\\OptionsResolver\\Exception\\InvalidArgumentException' => $vendorDir . '/symfony/options-resolver/Exception/InvalidArgumentException.php',
  29944. 'Symfony\\Component\\OptionsResolver\\Exception\\InvalidOptionsException' => $vendorDir . '/symfony/options-resolver/Exception/InvalidOptionsException.php',
  29945. 'Symfony\\Component\\OptionsResolver\\Exception\\MissingOptionsException' => $vendorDir . '/symfony/options-resolver/Exception/MissingOptionsException.php',
  29946. 'Symfony\\Component\\OptionsResolver\\Exception\\NoConfigurationException' => $vendorDir . '/symfony/options-resolver/Exception/NoConfigurationException.php',
  29947. 'Symfony\\Component\\OptionsResolver\\Exception\\NoSuchOptionException' => $vendorDir . '/symfony/options-resolver/Exception/NoSuchOptionException.php',
  29948. 'Symfony\\Component\\OptionsResolver\\Exception\\OptionDefinitionException' => $vendorDir . '/symfony/options-resolver/Exception/OptionDefinitionException.php',
  29949. 'Symfony\\Component\\OptionsResolver\\Exception\\UndefinedOptionsException' => $vendorDir . '/symfony/options-resolver/Exception/UndefinedOptionsException.php',
  29950. 'Symfony\\Component\\OptionsResolver\\Options' => $vendorDir . '/symfony/options-resolver/Options.php',
  29951. 'Symfony\\Component\\OptionsResolver\\OptionsResolver' => $vendorDir . '/symfony/options-resolver/OptionsResolver.php',
  29952. 'Symfony\\Component\\Process\\Exception\\ExceptionInterface' => $vendorDir . '/symfony/process/Exception/ExceptionInterface.php',
  29953. 'Symfony\\Component\\Process\\Exception\\InvalidArgumentException' => $vendorDir . '/symfony/process/Exception/InvalidArgumentException.php',
  29954. 'Symfony\\Component\\Process\\Exception\\LogicException' => $vendorDir . '/symfony/process/Exception/LogicException.php',
  29955. 'Symfony\\Component\\Process\\Exception\\ProcessFailedException' => $vendorDir . '/symfony/process/Exception/ProcessFailedException.php',
  29956. 'Symfony\\Component\\Process\\Exception\\ProcessTimedOutException' => $vendorDir . '/symfony/process/Exception/ProcessTimedOutException.php',
  29957. 'Symfony\\Component\\Process\\Exception\\RuntimeException' => $vendorDir . '/symfony/process/Exception/RuntimeException.php',
  29958. 'Symfony\\Component\\Process\\ExecutableFinder' => $vendorDir . '/symfony/process/ExecutableFinder.php',
  29959. 'Symfony\\Component\\Process\\InputStream' => $vendorDir . '/symfony/process/InputStream.php',
  29960. 'Symfony\\Component\\Process\\PhpExecutableFinder' => $vendorDir . '/symfony/process/PhpExecutableFinder.php',
  29961. 'Symfony\\Component\\Process\\PhpProcess' => $vendorDir . '/symfony/process/PhpProcess.php',
  29962. 'Symfony\\Component\\Process\\Pipes\\AbstractPipes' => $vendorDir . '/symfony/process/Pipes/AbstractPipes.php',
  29963. 'Symfony\\Component\\Process\\Pipes\\PipesInterface' => $vendorDir . '/symfony/process/Pipes/PipesInterface.php',
  29964. 'Symfony\\Component\\Process\\Pipes\\UnixPipes' => $vendorDir . '/symfony/process/Pipes/UnixPipes.php',
  29965. 'Symfony\\Component\\Process\\Pipes\\WindowsPipes' => $vendorDir . '/symfony/process/Pipes/WindowsPipes.php',
  29966. 'Symfony\\Component\\Process\\Process' => $vendorDir . '/symfony/process/Process.php',
  29967. 'Symfony\\Component\\Process\\ProcessBuilder' => $vendorDir . '/symfony/process/ProcessBuilder.php',
  29968. 'Symfony\\Component\\Process\\ProcessUtils' => $vendorDir . '/symfony/process/ProcessUtils.php',
  29969. 'Symfony\\Component\\Stopwatch\\Section' => $vendorDir . '/symfony/stopwatch/Section.php',
  29970. 'Symfony\\Component\\Stopwatch\\Stopwatch' => $vendorDir . '/symfony/stopwatch/Stopwatch.php',
  29971. 'Symfony\\Component\\Stopwatch\\StopwatchEvent' => $vendorDir . '/symfony/stopwatch/StopwatchEvent.php',
  29972. 'Symfony\\Component\\Stopwatch\\StopwatchPeriod' => $vendorDir . '/symfony/stopwatch/StopwatchPeriod.php',
  29973. 'Symfony\\Polyfill\\Mbstring\\Mbstring' => $vendorDir . '/symfony/polyfill-mbstring/Mbstring.php',
  29974. 'Symfony\\Polyfill\\Php70\\Php70' => $vendorDir . '/symfony/polyfill-php70/Php70.php',
  29975. 'Symfony\\Polyfill\\Php72\\Php72' => $vendorDir . '/symfony/polyfill-php72/Php72.php',
  29976. 'TypeError' => $vendorDir . '/symfony/polyfill-php70/Resources/stubs/TypeError.php',
  29977. );
  29978. <?php
  29979. $vendorDir = dirname(dirname(__FILE__));
  29980. $baseDir = dirname($vendorDir);
  29981. return array(
  29982. '5255c38a0faeba867671b61dfda6d864' => $vendorDir . '/paragonie/random_compat/lib/random.php',
  29983. '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => $vendorDir . '/symfony/polyfill-mbstring/bootstrap.php',
  29984. '023d27dca8066ef29e6739335ea73bad' => $vendorDir . '/symfony/polyfill-php70/bootstrap.php',
  29985. '25072dd6e2470089de65ae7bf11d3109' => $vendorDir . '/symfony/polyfill-php72/bootstrap.php',
  29986. );
  29987. <?php
  29988. namespace Composer\Autoload;
  29989. class ComposerStaticInit1d283854a5726c702db972976066d6a2
  29990. {
  29991. public static $files = array (
  29992. '5255c38a0faeba867671b61dfda6d864' => __DIR__ . '/..' . '/paragonie/random_compat/lib/random.php',
  29993. '0e6d7bf4a5811bfa5cf40c5ccd6fae6a' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/bootstrap.php',
  29994. '023d27dca8066ef29e6739335ea73bad' => __DIR__ . '/..' . '/symfony/polyfill-php70/bootstrap.php',
  29995. '25072dd6e2470089de65ae7bf11d3109' => __DIR__ . '/..' . '/symfony/polyfill-php72/bootstrap.php',
  29996. );
  29997. public static $prefixLengthsPsr4 = array (
  29998. 'S' =>
  29999. array (
  30000. 'Symfony\\Polyfill\\Php72\\' => 23,
  30001. 'Symfony\\Polyfill\\Php70\\' => 23,
  30002. 'Symfony\\Polyfill\\Mbstring\\' => 26,
  30003. 'Symfony\\Component\\Stopwatch\\' => 28,
  30004. 'Symfony\\Component\\Process\\' => 26,
  30005. 'Symfony\\Component\\OptionsResolver\\' => 34,
  30006. 'Symfony\\Component\\Finder\\' => 25,
  30007. 'Symfony\\Component\\Filesystem\\' => 29,
  30008. 'Symfony\\Component\\EventDispatcher\\' => 34,
  30009. 'Symfony\\Component\\Debug\\' => 24,
  30010. 'Symfony\\Component\\Console\\' => 26,
  30011. ),
  30012. 'P' =>
  30013. array (
  30014. 'Psr\\Log\\' => 8,
  30015. 'PhpCsFixer\\' => 11,
  30016. ),
  30017. 'G' =>
  30018. array (
  30019. 'GeckoPackages\\PHPUnit\\' => 22,
  30020. ),
  30021. 'D' =>
  30022. array (
  30023. 'Doctrine\\Common\\Annotations\\' => 28,
  30024. ),
  30025. 'C' =>
  30026. array (
  30027. 'Composer\\Semver\\' => 16,
  30028. ),
  30029. );
  30030. public static $prefixDirsPsr4 = array (
  30031. 'Symfony\\Polyfill\\Php72\\' =>
  30032. array (
  30033. 0 => __DIR__ . '/..' . '/symfony/polyfill-php72',
  30034. ),
  30035. 'Symfony\\Polyfill\\Php70\\' =>
  30036. array (
  30037. 0 => __DIR__ . '/..' . '/symfony/polyfill-php70',
  30038. ),
  30039. 'Symfony\\Polyfill\\Mbstring\\' =>
  30040. array (
  30041. 0 => __DIR__ . '/..' . '/symfony/polyfill-mbstring',
  30042. ),
  30043. 'Symfony\\Component\\Stopwatch\\' =>
  30044. array (
  30045. 0 => __DIR__ . '/..' . '/symfony/stopwatch',
  30046. ),
  30047. 'Symfony\\Component\\Process\\' =>
  30048. array (
  30049. 0 => __DIR__ . '/..' . '/symfony/process',
  30050. ),
  30051. 'Symfony\\Component\\OptionsResolver\\' =>
  30052. array (
  30053. 0 => __DIR__ . '/..' . '/symfony/options-resolver',
  30054. ),
  30055. 'Symfony\\Component\\Finder\\' =>
  30056. array (
  30057. 0 => __DIR__ . '/..' . '/symfony/finder',
  30058. ),
  30059. 'Symfony\\Component\\Filesystem\\' =>
  30060. array (
  30061. 0 => __DIR__ . '/..' . '/symfony/filesystem',
  30062. ),
  30063. 'Symfony\\Component\\EventDispatcher\\' =>
  30064. array (
  30065. 0 => __DIR__ . '/..' . '/symfony/event-dispatcher',
  30066. ),
  30067. 'Symfony\\Component\\Debug\\' =>
  30068. array (
  30069. 0 => __DIR__ . '/..' . '/symfony/debug',
  30070. ),
  30071. 'Symfony\\Component\\Console\\' =>
  30072. array (
  30073. 0 => __DIR__ . '/..' . '/symfony/console',
  30074. ),
  30075. 'Psr\\Log\\' =>
  30076. array (
  30077. 0 => __DIR__ . '/..' . '/psr/log/Psr/Log',
  30078. ),
  30079. 'PhpCsFixer\\' =>
  30080. array (
  30081. 0 => __DIR__ . '/../..' . '/src',
  30082. ),
  30083. 'GeckoPackages\\PHPUnit\\' =>
  30084. array (
  30085. 0 => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit',
  30086. ),
  30087. 'Doctrine\\Common\\Annotations\\' =>
  30088. array (
  30089. 0 => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations',
  30090. ),
  30091. 'Composer\\Semver\\' =>
  30092. array (
  30093. 0 => __DIR__ . '/..' . '/composer/semver/src',
  30094. ),
  30095. );
  30096. public static $prefixesPsr0 = array (
  30097. 'D' =>
  30098. array (
  30099. 'Doctrine\\Common\\Lexer\\' =>
  30100. array (
  30101. 0 => __DIR__ . '/..' . '/doctrine/lexer/lib',
  30102. ),
  30103. ),
  30104. );
  30105. public static $classMap = array (
  30106. 'ArithmeticError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/ArithmeticError.php',
  30107. 'AssertionError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/AssertionError.php',
  30108. 'Composer\\Semver\\Comparator' => __DIR__ . '/..' . '/composer/semver/src/Comparator.php',
  30109. 'Composer\\Semver\\Constraint\\AbstractConstraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/AbstractConstraint.php',
  30110. 'Composer\\Semver\\Constraint\\Constraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/Constraint.php',
  30111. 'Composer\\Semver\\Constraint\\ConstraintInterface' => __DIR__ . '/..' . '/composer/semver/src/Constraint/ConstraintInterface.php',
  30112. 'Composer\\Semver\\Constraint\\EmptyConstraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/EmptyConstraint.php',
  30113. 'Composer\\Semver\\Constraint\\MultiConstraint' => __DIR__ . '/..' . '/composer/semver/src/Constraint/MultiConstraint.php',
  30114. 'Composer\\Semver\\Semver' => __DIR__ . '/..' . '/composer/semver/src/Semver.php',
  30115. 'Composer\\Semver\\VersionParser' => __DIR__ . '/..' . '/composer/semver/src/VersionParser.php',
  30116. 'DivisionByZeroError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/DivisionByZeroError.php',
  30117. 'Doctrine\\Common\\Annotations\\Annotation' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation.php',
  30118. 'Doctrine\\Common\\Annotations\\AnnotationException' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationException.php',
  30119. 'Doctrine\\Common\\Annotations\\AnnotationReader' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationReader.php',
  30120. 'Doctrine\\Common\\Annotations\\AnnotationRegistry' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/AnnotationRegistry.php',
  30121. 'Doctrine\\Common\\Annotations\\Annotation\\Attribute' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attribute.php',
  30122. 'Doctrine\\Common\\Annotations\\Annotation\\Attributes' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Attributes.php',
  30123. 'Doctrine\\Common\\Annotations\\Annotation\\Enum' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Enum.php',
  30124. 'Doctrine\\Common\\Annotations\\Annotation\\IgnoreAnnotation' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/IgnoreAnnotation.php',
  30125. 'Doctrine\\Common\\Annotations\\Annotation\\Required' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Required.php',
  30126. 'Doctrine\\Common\\Annotations\\Annotation\\Target' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Annotation/Target.php',
  30127. 'Doctrine\\Common\\Annotations\\CachedReader' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/CachedReader.php',
  30128. 'Doctrine\\Common\\Annotations\\DocLexer' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/DocLexer.php',
  30129. 'Doctrine\\Common\\Annotations\\DocParser' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/DocParser.php',
  30130. 'Doctrine\\Common\\Annotations\\FileCacheReader' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/FileCacheReader.php',
  30131. 'Doctrine\\Common\\Annotations\\IndexedReader' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/IndexedReader.php',
  30132. 'Doctrine\\Common\\Annotations\\PhpParser' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/PhpParser.php',
  30133. 'Doctrine\\Common\\Annotations\\Reader' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/Reader.php',
  30134. 'Doctrine\\Common\\Annotations\\SimpleAnnotationReader' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/SimpleAnnotationReader.php',
  30135. 'Doctrine\\Common\\Annotations\\TokenParser' => __DIR__ . '/..' . '/doctrine/annotations/lib/Doctrine/Common/Annotations/TokenParser.php',
  30136. 'Doctrine\\Common\\Lexer\\AbstractLexer' => __DIR__ . '/..' . '/doctrine/lexer/lib/Doctrine/Common/Lexer/AbstractLexer.php',
  30137. 'Error' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/Error.php',
  30138. 'GeckoPackages\\PHPUnit\\Asserts\\AssertHelper' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/AssertHelper.php',
  30139. 'GeckoPackages\\PHPUnit\\Asserts\\FileExistsAssertTrait' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/FileExistsAssertTrait.php',
  30140. 'GeckoPackages\\PHPUnit\\Asserts\\FileSystemAssertTrait' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/FileSystemAssertTrait.php',
  30141. 'GeckoPackages\\PHPUnit\\Asserts\\RangeAssertTrait' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/RangeAssertTrait.php',
  30142. 'GeckoPackages\\PHPUnit\\Asserts\\ScalarAssertTrait' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/ScalarAssertTrait.php',
  30143. 'GeckoPackages\\PHPUnit\\Asserts\\StringsAssertTrait' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/StringsAssertTrait.php',
  30144. 'GeckoPackages\\PHPUnit\\Asserts\\XMLAssertTrait' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Asserts/XMLAssertTrait.php',
  30145. 'GeckoPackages\\PHPUnit\\Constraints\\DirectoryEmptyConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/DirectoryEmptyConstraint.php',
  30146. 'GeckoPackages\\PHPUnit\\Constraints\\DirectoryExistsConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/DirectoryExistsConstraint.php',
  30147. 'GeckoPackages\\PHPUnit\\Constraints\\FileExistsConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileExistsConstraint.php',
  30148. 'GeckoPackages\\PHPUnit\\Constraints\\FileIsLinkConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileIsLinkConstraint.php',
  30149. 'GeckoPackages\\PHPUnit\\Constraints\\FileIsValidLinkConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FileIsValidLinkConstraint.php',
  30150. 'GeckoPackages\\PHPUnit\\Constraints\\FilePermissionsIsIdenticalConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FilePermissionsIsIdenticalConstraint.php',
  30151. 'GeckoPackages\\PHPUnit\\Constraints\\FilePermissionsMaskConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/FilePermissionsMaskConstraint.php',
  30152. 'GeckoPackages\\PHPUnit\\Constraints\\NumberRangeConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/NumberRangeConstraint.php',
  30153. 'GeckoPackages\\PHPUnit\\Constraints\\SameStringsConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/SameStringsConstraint.php',
  30154. 'GeckoPackages\\PHPUnit\\Constraints\\ScalarConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/ScalarConstraint.php',
  30155. 'GeckoPackages\\PHPUnit\\Constraints\\UnsignedIntConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/UnsignedIntConstraint.php',
  30156. 'GeckoPackages\\PHPUnit\\Constraints\\XML\\AbstractXMLConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/AbstractXMLConstraint.php',
  30157. 'GeckoPackages\\PHPUnit\\Constraints\\XML\\XMLMatchesXSDConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/XMLMatchesXSDConstraint.php',
  30158. 'GeckoPackages\\PHPUnit\\Constraints\\XML\\XMLValidConstraint' => __DIR__ . '/..' . '/gecko-packages/gecko-php-unit/src/PHPUnit/Constraints/XML/XMLValidConstraint.php',
  30159. 'ParseError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/ParseError.php',
  30160. 'PhpCsFixer\\AbstractAlignFixerHelper' => __DIR__ . '/../..' . '/src/AbstractAlignFixerHelper.php',
  30161. 'PhpCsFixer\\AbstractDoctrineAnnotationFixer' => __DIR__ . '/../..' . '/src/AbstractDoctrineAnnotationFixer.php',
  30162. 'PhpCsFixer\\AbstractFixer' => __DIR__ . '/../..' . '/src/AbstractFixer.php',
  30163. 'PhpCsFixer\\AbstractFunctionReferenceFixer' => __DIR__ . '/../..' . '/src/AbstractFunctionReferenceFixer.php',
  30164. 'PhpCsFixer\\AbstractLinesBeforeNamespaceFixer' => __DIR__ . '/../..' . '/src/AbstractLinesBeforeNamespaceFixer.php',
  30165. 'PhpCsFixer\\AbstractNoUselessElseFixer' => __DIR__ . '/../..' . '/src/AbstractNoUselessElseFixer.php',
  30166. 'PhpCsFixer\\AbstractPhpdocTypesFixer' => __DIR__ . '/../..' . '/src/AbstractPhpdocTypesFixer.php',
  30167. 'PhpCsFixer\\AbstractProxyFixer' => __DIR__ . '/../..' . '/src/AbstractProxyFixer.php',
  30168. 'PhpCsFixer\\AbstractPsrAutoloadingFixer' => __DIR__ . '/../..' . '/src/AbstractPsrAutoloadingFixer.php',
  30169. 'PhpCsFixer\\Cache\\Cache' => __DIR__ . '/../..' . '/src/Cache/Cache.php',
  30170. 'PhpCsFixer\\Cache\\CacheInterface' => __DIR__ . '/../..' . '/src/Cache/CacheInterface.php',
  30171. 'PhpCsFixer\\Cache\\CacheManagerInterface' => __DIR__ . '/../..' . '/src/Cache/CacheManagerInterface.php',
  30172. 'PhpCsFixer\\Cache\\Directory' => __DIR__ . '/../..' . '/src/Cache/Directory.php',
  30173. 'PhpCsFixer\\Cache\\DirectoryInterface' => __DIR__ . '/../..' . '/src/Cache/DirectoryInterface.php',
  30174. 'PhpCsFixer\\Cache\\FileCacheManager' => __DIR__ . '/../..' . '/src/Cache/FileCacheManager.php',
  30175. 'PhpCsFixer\\Cache\\FileHandler' => __DIR__ . '/../..' . '/src/Cache/FileHandler.php',
  30176. 'PhpCsFixer\\Cache\\FileHandlerInterface' => __DIR__ . '/../..' . '/src/Cache/FileHandlerInterface.php',
  30177. 'PhpCsFixer\\Cache\\NullCacheManager' => __DIR__ . '/../..' . '/src/Cache/NullCacheManager.php',
  30178. 'PhpCsFixer\\Cache\\Signature' => __DIR__ . '/../..' . '/src/Cache/Signature.php',
  30179. 'PhpCsFixer\\Cache\\SignatureInterface' => __DIR__ . '/../..' . '/src/Cache/SignatureInterface.php',
  30180. 'PhpCsFixer\\Config' => __DIR__ . '/../..' . '/src/Config.php',
  30181. 'PhpCsFixer\\ConfigInterface' => __DIR__ . '/../..' . '/src/ConfigInterface.php',
  30182. 'PhpCsFixer\\ConfigurationException\\InvalidConfigurationException' => __DIR__ . '/../..' . '/src/ConfigurationException/InvalidConfigurationException.php',
  30183. 'PhpCsFixer\\ConfigurationException\\InvalidFixerConfigurationException' => __DIR__ . '/../..' . '/src/ConfigurationException/InvalidFixerConfigurationException.php',
  30184. 'PhpCsFixer\\ConfigurationException\\InvalidForEnvFixerConfigurationException' => __DIR__ . '/../..' . '/src/ConfigurationException/InvalidForEnvFixerConfigurationException.php',
  30185. 'PhpCsFixer\\ConfigurationException\\RequiredFixerConfigurationException' => __DIR__ . '/../..' . '/src/ConfigurationException/RequiredFixerConfigurationException.php',
  30186. 'PhpCsFixer\\Console\\Application' => __DIR__ . '/../..' . '/src/Console/Application.php',
  30187. 'PhpCsFixer\\Console\\Command\\DescribeCommand' => __DIR__ . '/../..' . '/src/Console/Command/DescribeCommand.php',
  30188. 'PhpCsFixer\\Console\\Command\\DescribeNameNotFoundException' => __DIR__ . '/../..' . '/src/Console/Command/DescribeNameNotFoundException.php',
  30189. 'PhpCsFixer\\Console\\Command\\FixCommand' => __DIR__ . '/../..' . '/src/Console/Command/FixCommand.php',
  30190. 'PhpCsFixer\\Console\\Command\\FixCommandExitStatusCalculator' => __DIR__ . '/../..' . '/src/Console/Command/FixCommandExitStatusCalculator.php',
  30191. 'PhpCsFixer\\Console\\Command\\HelpCommand' => __DIR__ . '/../..' . '/src/Console/Command/HelpCommand.php',
  30192. 'PhpCsFixer\\Console\\Command\\ReadmeCommand' => __DIR__ . '/../..' . '/src/Console/Command/ReadmeCommand.php',
  30193. 'PhpCsFixer\\Console\\Command\\SelfUpdateCommand' => __DIR__ . '/../..' . '/src/Console/Command/SelfUpdateCommand.php',
  30194. 'PhpCsFixer\\Console\\ConfigurationResolver' => __DIR__ . '/../..' . '/src/Console/ConfigurationResolver.php',
  30195. 'PhpCsFixer\\Console\\Output\\ErrorOutput' => __DIR__ . '/../..' . '/src/Console/Output/ErrorOutput.php',
  30196. 'PhpCsFixer\\Console\\Output\\NullOutput' => __DIR__ . '/../..' . '/src/Console/Output/NullOutput.php',
  30197. 'PhpCsFixer\\Console\\Output\\ProcessOutput' => __DIR__ . '/../..' . '/src/Console/Output/ProcessOutput.php',
  30198. 'PhpCsFixer\\Console\\Output\\ProcessOutputInterface' => __DIR__ . '/../..' . '/src/Console/Output/ProcessOutputInterface.php',
  30199. 'PhpCsFixer\\Console\\SelfUpdate\\GithubClient' => __DIR__ . '/../..' . '/src/Console/SelfUpdate/GithubClient.php',
  30200. 'PhpCsFixer\\Console\\SelfUpdate\\GithubClientInterface' => __DIR__ . '/../..' . '/src/Console/SelfUpdate/GithubClientInterface.php',
  30201. 'PhpCsFixer\\Console\\SelfUpdate\\NewVersionChecker' => __DIR__ . '/../..' . '/src/Console/SelfUpdate/NewVersionChecker.php',
  30202. 'PhpCsFixer\\Console\\SelfUpdate\\NewVersionCheckerInterface' => __DIR__ . '/../..' . '/src/Console/SelfUpdate/NewVersionCheckerInterface.php',
  30203. 'PhpCsFixer\\Console\\WarningsDetector' => __DIR__ . '/../..' . '/src/Console/WarningsDetector.php',
  30204. 'PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\ConfigurationException' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/GeckoPackages/DiffOutputBuilder/ConfigurationException.php',
  30205. 'PhpCsFixer\\Diff\\GeckoPackages\\DiffOutputBuilder\\UnifiedDiffOutputBuilder' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/GeckoPackages/DiffOutputBuilder/UnifiedDiffOutputBuilder.php',
  30206. 'PhpCsFixer\\Diff\\v1_4\\Chunk' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/Chunk.php',
  30207. 'PhpCsFixer\\Diff\\v1_4\\Diff' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/Diff.php',
  30208. 'PhpCsFixer\\Diff\\v1_4\\Differ' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/Differ.php',
  30209. 'PhpCsFixer\\Diff\\v1_4\\LCS\\LongestCommonSubsequence' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/LCS/LongestCommonSubsequence.php',
  30210. 'PhpCsFixer\\Diff\\v1_4\\LCS\\MemoryEfficientImplementation' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/LCS/MemoryEfficientLongestCommonSubsequenceImplementation.php',
  30211. 'PhpCsFixer\\Diff\\v1_4\\LCS\\TimeEfficientImplementation' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/LCS/TimeEfficientLongestCommonSubsequenceImplementation.php',
  30212. 'PhpCsFixer\\Diff\\v1_4\\Line' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/Line.php',
  30213. 'PhpCsFixer\\Diff\\v1_4\\Parser' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v1_4/Parser.php',
  30214. 'PhpCsFixer\\Diff\\v2_0\\Chunk' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Chunk.php',
  30215. 'PhpCsFixer\\Diff\\v2_0\\Diff' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Diff.php',
  30216. 'PhpCsFixer\\Diff\\v2_0\\Differ' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Differ.php',
  30217. 'PhpCsFixer\\Diff\\v2_0\\Exception' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Exception/Exception.php',
  30218. 'PhpCsFixer\\Diff\\v2_0\\InvalidArgumentException' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Exception/InvalidArgumentException.php',
  30219. 'PhpCsFixer\\Diff\\v2_0\\Line' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Line.php',
  30220. 'PhpCsFixer\\Diff\\v2_0\\LongestCommonSubsequenceCalculator' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/LongestCommonSubsequenceCalculator.php',
  30221. 'PhpCsFixer\\Diff\\v2_0\\MemoryEfficientLongestCommonSubsequenceCalculator' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/MemoryEfficientLongestCommonSubsequenceCalculator.php',
  30222. 'PhpCsFixer\\Diff\\v2_0\\Output\\AbstractChunkOutputBuilder' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Output/AbstractChunkOutputBuilder.php',
  30223. 'PhpCsFixer\\Diff\\v2_0\\Output\\DiffOnlyOutputBuilder' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Output/DiffOnlyOutputBuilder.php',
  30224. 'PhpCsFixer\\Diff\\v2_0\\Output\\DiffOutputBuilderInterface' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Output/DiffOutputBuilderInterface.php',
  30225. 'PhpCsFixer\\Diff\\v2_0\\Output\\UnifiedDiffOutputBuilder' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Output/UnifiedDiffOutputBuilder.php',
  30226. 'PhpCsFixer\\Diff\\v2_0\\Parser' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/Parser.php',
  30227. 'PhpCsFixer\\Diff\\v2_0\\TimeEfficientLongestCommonSubsequenceCalculator' => __DIR__ . '/..' . '/php-cs-fixer/diff/src/v2_0/TimeEfficientLongestCommonSubsequenceCalculator.php',
  30228. 'PhpCsFixer\\Differ\\DiffConsoleFormatter' => __DIR__ . '/../..' . '/src/Differ/DiffConsoleFormatter.php',
  30229. 'PhpCsFixer\\Differ\\DifferInterface' => __DIR__ . '/../..' . '/src/Differ/DifferInterface.php',
  30230. 'PhpCsFixer\\Differ\\NullDiffer' => __DIR__ . '/../..' . '/src/Differ/NullDiffer.php',
  30231. 'PhpCsFixer\\Differ\\SebastianBergmannDiffer' => __DIR__ . '/../..' . '/src/Differ/SebastianBergmannDiffer.php',
  30232. 'PhpCsFixer\\Differ\\SebastianBergmannShortDiffer' => __DIR__ . '/../..' . '/src/Differ/SebastianBergmannShortDiffer.php',
  30233. 'PhpCsFixer\\Differ\\UnifiedDiffer' => __DIR__ . '/../..' . '/src/Differ/UnifiedDiffer.php',
  30234. 'PhpCsFixer\\DocBlock\\Annotation' => __DIR__ . '/../..' . '/src/DocBlock/Annotation.php',
  30235. 'PhpCsFixer\\DocBlock\\DocBlock' => __DIR__ . '/../..' . '/src/DocBlock/DocBlock.php',
  30236. 'PhpCsFixer\\DocBlock\\Line' => __DIR__ . '/../..' . '/src/DocBlock/Line.php',
  30237. 'PhpCsFixer\\DocBlock\\Tag' => __DIR__ . '/../..' . '/src/DocBlock/Tag.php',
  30238. 'PhpCsFixer\\DocBlock\\TagComparator' => __DIR__ . '/../..' . '/src/DocBlock/TagComparator.php',
  30239. 'PhpCsFixer\\Doctrine\\Annotation\\Token' => __DIR__ . '/../..' . '/src/Doctrine/Annotation/Token.php',
  30240. 'PhpCsFixer\\Doctrine\\Annotation\\Tokens' => __DIR__ . '/../..' . '/src/Doctrine/Annotation/Tokens.php',
  30241. 'PhpCsFixer\\Error\\Error' => __DIR__ . '/../..' . '/src/Error/Error.php',
  30242. 'PhpCsFixer\\Error\\ErrorsManager' => __DIR__ . '/../..' . '/src/Error/ErrorsManager.php',
  30243. 'PhpCsFixer\\FileReader' => __DIR__ . '/../..' . '/src/FileReader.php',
  30244. 'PhpCsFixer\\FileRemoval' => __DIR__ . '/../..' . '/src/FileRemoval.php',
  30245. 'PhpCsFixer\\Finder' => __DIR__ . '/../..' . '/src/Finder.php',
  30246. 'PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolver' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerConfigurationResolver.php',
  30247. 'PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolverInterface' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerConfigurationResolverInterface.php',
  30248. 'PhpCsFixer\\FixerConfiguration\\FixerConfigurationResolverRootless' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerConfigurationResolverRootless.php',
  30249. 'PhpCsFixer\\FixerConfiguration\\FixerOption' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerOption.php',
  30250. 'PhpCsFixer\\FixerConfiguration\\FixerOptionBuilder' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerOptionBuilder.php',
  30251. 'PhpCsFixer\\FixerConfiguration\\FixerOptionInterface' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerOptionInterface.php',
  30252. 'PhpCsFixer\\FixerConfiguration\\FixerOptionValidatorGenerator' => __DIR__ . '/../..' . '/src/FixerConfiguration/FixerOptionValidatorGenerator.php',
  30253. 'PhpCsFixer\\FixerConfiguration\\InvalidOptionsForEnvException' => __DIR__ . '/../..' . '/src/FixerConfiguration/InvalidOptionsForEnvException.php',
  30254. 'PhpCsFixer\\FixerDefinition\\CodeSample' => __DIR__ . '/../..' . '/src/FixerDefinition/CodeSample.php',
  30255. 'PhpCsFixer\\FixerDefinition\\CodeSampleInterface' => __DIR__ . '/../..' . '/src/FixerDefinition/CodeSampleInterface.php',
  30256. 'PhpCsFixer\\FixerDefinition\\FileSpecificCodeSample' => __DIR__ . '/../..' . '/src/FixerDefinition/FileSpecificCodeSample.php',
  30257. 'PhpCsFixer\\FixerDefinition\\FileSpecificCodeSampleInterface' => __DIR__ . '/../..' . '/src/FixerDefinition/FileSpecificCodeSampleInterface.php',
  30258. 'PhpCsFixer\\FixerDefinition\\FixerDefinition' => __DIR__ . '/../..' . '/src/FixerDefinition/FixerDefinition.php',
  30259. 'PhpCsFixer\\FixerDefinition\\FixerDefinitionInterface' => __DIR__ . '/../..' . '/src/FixerDefinition/FixerDefinitionInterface.php',
  30260. 'PhpCsFixer\\FixerDefinition\\VersionSpecificCodeSample' => __DIR__ . '/../..' . '/src/FixerDefinition/VersionSpecificCodeSample.php',
  30261. 'PhpCsFixer\\FixerDefinition\\VersionSpecificCodeSampleInterface' => __DIR__ . '/../..' . '/src/FixerDefinition/VersionSpecificCodeSampleInterface.php',
  30262. 'PhpCsFixer\\FixerDefinition\\VersionSpecification' => __DIR__ . '/../..' . '/src/FixerDefinition/VersionSpecification.php',
  30263. 'PhpCsFixer\\FixerDefinition\\VersionSpecificationInterface' => __DIR__ . '/../..' . '/src/FixerDefinition/VersionSpecificationInterface.php',
  30264. 'PhpCsFixer\\FixerFactory' => __DIR__ . '/../..' . '/src/FixerFactory.php',
  30265. 'PhpCsFixer\\FixerFileProcessedEvent' => __DIR__ . '/../..' . '/src/FixerFileProcessedEvent.php',
  30266. 'PhpCsFixer\\FixerNameValidator' => __DIR__ . '/../..' . '/src/FixerNameValidator.php',
  30267. 'PhpCsFixer\\Fixer\\Alias\\BacktickToShellExecFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/BacktickToShellExecFixer.php',
  30268. 'PhpCsFixer\\Fixer\\Alias\\EregToPregFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/EregToPregFixer.php',
  30269. 'PhpCsFixer\\Fixer\\Alias\\MbStrFunctionsFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/MbStrFunctionsFixer.php',
  30270. 'PhpCsFixer\\Fixer\\Alias\\NoAliasFunctionsFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/NoAliasFunctionsFixer.php',
  30271. 'PhpCsFixer\\Fixer\\Alias\\NoMixedEchoPrintFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/NoMixedEchoPrintFixer.php',
  30272. 'PhpCsFixer\\Fixer\\Alias\\PowToExponentiationFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/PowToExponentiationFixer.php',
  30273. 'PhpCsFixer\\Fixer\\Alias\\RandomApiMigrationFixer' => __DIR__ . '/../..' . '/src/Fixer/Alias/RandomApiMigrationFixer.php',
  30274. 'PhpCsFixer\\Fixer\\ArrayNotation\\ArraySyntaxFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/ArraySyntaxFixer.php',
  30275. 'PhpCsFixer\\Fixer\\ArrayNotation\\NoMultilineWhitespaceAroundDoubleArrowFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/NoMultilineWhitespaceAroundDoubleArrowFixer.php',
  30276. 'PhpCsFixer\\Fixer\\ArrayNotation\\NoTrailingCommaInSinglelineArrayFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/NoTrailingCommaInSinglelineArrayFixer.php',
  30277. 'PhpCsFixer\\Fixer\\ArrayNotation\\NoWhitespaceBeforeCommaInArrayFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/NoWhitespaceBeforeCommaInArrayFixer.php',
  30278. 'PhpCsFixer\\Fixer\\ArrayNotation\\NormalizeIndexBraceFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/NormalizeIndexBraceFixer.php',
  30279. 'PhpCsFixer\\Fixer\\ArrayNotation\\TrailingCommaInMultilineArrayFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/TrailingCommaInMultilineArrayFixer.php',
  30280. 'PhpCsFixer\\Fixer\\ArrayNotation\\TrimArraySpacesFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/TrimArraySpacesFixer.php',
  30281. 'PhpCsFixer\\Fixer\\ArrayNotation\\WhitespaceAfterCommaInArrayFixer' => __DIR__ . '/../..' . '/src/Fixer/ArrayNotation/WhitespaceAfterCommaInArrayFixer.php',
  30282. 'PhpCsFixer\\Fixer\\Basic\\BracesFixer' => __DIR__ . '/../..' . '/src/Fixer/Basic/BracesFixer.php',
  30283. 'PhpCsFixer\\Fixer\\Basic\\EncodingFixer' => __DIR__ . '/../..' . '/src/Fixer/Basic/EncodingFixer.php',
  30284. 'PhpCsFixer\\Fixer\\Basic\\NonPrintableCharacterFixer' => __DIR__ . '/../..' . '/src/Fixer/Basic/NonPrintableCharacterFixer.php',
  30285. 'PhpCsFixer\\Fixer\\Basic\\Psr0Fixer' => __DIR__ . '/../..' . '/src/Fixer/Basic/Psr0Fixer.php',
  30286. 'PhpCsFixer\\Fixer\\Basic\\Psr4Fixer' => __DIR__ . '/../..' . '/src/Fixer/Basic/Psr4Fixer.php',
  30287. 'PhpCsFixer\\Fixer\\Casing\\LowercaseConstantsFixer' => __DIR__ . '/../..' . '/src/Fixer/Casing/LowercaseConstantsFixer.php',
  30288. 'PhpCsFixer\\Fixer\\Casing\\LowercaseKeywordsFixer' => __DIR__ . '/../..' . '/src/Fixer/Casing/LowercaseKeywordsFixer.php',
  30289. 'PhpCsFixer\\Fixer\\Casing\\MagicConstantCasingFixer' => __DIR__ . '/../..' . '/src/Fixer/Casing/MagicConstantCasingFixer.php',
  30290. 'PhpCsFixer\\Fixer\\Casing\\NativeFunctionCasingFixer' => __DIR__ . '/../..' . '/src/Fixer/Casing/NativeFunctionCasingFixer.php',
  30291. 'PhpCsFixer\\Fixer\\CastNotation\\CastSpacesFixer' => __DIR__ . '/../..' . '/src/Fixer/CastNotation/CastSpacesFixer.php',
  30292. 'PhpCsFixer\\Fixer\\CastNotation\\LowercaseCastFixer' => __DIR__ . '/../..' . '/src/Fixer/CastNotation/LowercaseCastFixer.php',
  30293. 'PhpCsFixer\\Fixer\\CastNotation\\ModernizeTypesCastingFixer' => __DIR__ . '/../..' . '/src/Fixer/CastNotation/ModernizeTypesCastingFixer.php',
  30294. 'PhpCsFixer\\Fixer\\CastNotation\\NoShortBoolCastFixer' => __DIR__ . '/../..' . '/src/Fixer/CastNotation/NoShortBoolCastFixer.php',
  30295. 'PhpCsFixer\\Fixer\\CastNotation\\ShortScalarCastFixer' => __DIR__ . '/../..' . '/src/Fixer/CastNotation/ShortScalarCastFixer.php',
  30296. 'PhpCsFixer\\Fixer\\ClassNotation\\ClassAttributesSeparationFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/ClassAttributesSeparationFixer.php',
  30297. 'PhpCsFixer\\Fixer\\ClassNotation\\ClassDefinitionFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/ClassDefinitionFixer.php',
  30298. 'PhpCsFixer\\Fixer\\ClassNotation\\FinalInternalClassFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/FinalInternalClassFixer.php',
  30299. 'PhpCsFixer\\Fixer\\ClassNotation\\MethodSeparationFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/MethodSeparationFixer.php',
  30300. 'PhpCsFixer\\Fixer\\ClassNotation\\NoBlankLinesAfterClassOpeningFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/NoBlankLinesAfterClassOpeningFixer.php',
  30301. 'PhpCsFixer\\Fixer\\ClassNotation\\NoNullPropertyInitializationFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/NoNullPropertyInitializationFixer.php',
  30302. 'PhpCsFixer\\Fixer\\ClassNotation\\NoPhp4ConstructorFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/NoPhp4ConstructorFixer.php',
  30303. 'PhpCsFixer\\Fixer\\ClassNotation\\NoUnneededFinalMethodFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/NoUnneededFinalMethodFixer.php',
  30304. 'PhpCsFixer\\Fixer\\ClassNotation\\OrderedClassElementsFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/OrderedClassElementsFixer.php',
  30305. 'PhpCsFixer\\Fixer\\ClassNotation\\ProtectedToPrivateFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/ProtectedToPrivateFixer.php',
  30306. 'PhpCsFixer\\Fixer\\ClassNotation\\SelfAccessorFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/SelfAccessorFixer.php',
  30307. 'PhpCsFixer\\Fixer\\ClassNotation\\SingleClassElementPerStatementFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/SingleClassElementPerStatementFixer.php',
  30308. 'PhpCsFixer\\Fixer\\ClassNotation\\VisibilityRequiredFixer' => __DIR__ . '/../..' . '/src/Fixer/ClassNotation/VisibilityRequiredFixer.php',
  30309. 'PhpCsFixer\\Fixer\\Comment\\HashToSlashCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/Comment/HashToSlashCommentFixer.php',
  30310. 'PhpCsFixer\\Fixer\\Comment\\HeaderCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/Comment/HeaderCommentFixer.php',
  30311. 'PhpCsFixer\\Fixer\\Comment\\MultilineCommentOpeningClosingFixer' => __DIR__ . '/../..' . '/src/Fixer/Comment/MultilineCommentOpeningClosingFixer.php',
  30312. 'PhpCsFixer\\Fixer\\Comment\\NoEmptyCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/Comment/NoEmptyCommentFixer.php',
  30313. 'PhpCsFixer\\Fixer\\Comment\\NoTrailingWhitespaceInCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/Comment/NoTrailingWhitespaceInCommentFixer.php',
  30314. 'PhpCsFixer\\Fixer\\Comment\\SingleLineCommentStyleFixer' => __DIR__ . '/../..' . '/src/Fixer/Comment/SingleLineCommentStyleFixer.php',
  30315. 'PhpCsFixer\\Fixer\\ConfigurableFixerInterface' => __DIR__ . '/../..' . '/src/Fixer/ConfigurableFixerInterface.php',
  30316. 'PhpCsFixer\\Fixer\\ConfigurationDefinitionFixerInterface' => __DIR__ . '/../..' . '/src/Fixer/ConfigurationDefinitionFixerInterface.php',
  30317. 'PhpCsFixer\\Fixer\\ControlStructure\\ElseifFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/ElseifFixer.php',
  30318. 'PhpCsFixer\\Fixer\\ControlStructure\\IncludeFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/IncludeFixer.php',
  30319. 'PhpCsFixer\\Fixer\\ControlStructure\\NoBreakCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/NoBreakCommentFixer.php',
  30320. 'PhpCsFixer\\Fixer\\ControlStructure\\NoSuperfluousElseifFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/NoSuperfluousElseifFixer.php',
  30321. 'PhpCsFixer\\Fixer\\ControlStructure\\NoTrailingCommaInListCallFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/NoTrailingCommaInListCallFixer.php',
  30322. 'PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededControlParenthesesFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/NoUnneededControlParenthesesFixer.php',
  30323. 'PhpCsFixer\\Fixer\\ControlStructure\\NoUnneededCurlyBracesFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/NoUnneededCurlyBracesFixer.php',
  30324. 'PhpCsFixer\\Fixer\\ControlStructure\\NoUselessElseFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/NoUselessElseFixer.php',
  30325. 'PhpCsFixer\\Fixer\\ControlStructure\\SwitchCaseSemicolonToColonFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/SwitchCaseSemicolonToColonFixer.php',
  30326. 'PhpCsFixer\\Fixer\\ControlStructure\\SwitchCaseSpaceFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/SwitchCaseSpaceFixer.php',
  30327. 'PhpCsFixer\\Fixer\\ControlStructure\\YodaStyleFixer' => __DIR__ . '/../..' . '/src/Fixer/ControlStructure/YodaStyleFixer.php',
  30328. 'PhpCsFixer\\Fixer\\DefinedFixerInterface' => __DIR__ . '/../..' . '/src/Fixer/DefinedFixerInterface.php',
  30329. 'PhpCsFixer\\Fixer\\DeprecatedFixerInterface' => __DIR__ . '/../..' . '/src/Fixer/DeprecatedFixerInterface.php',
  30330. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationArrayAssignmentFixer' => __DIR__ . '/../..' . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationArrayAssignmentFixer.php',
  30331. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationBracesFixer' => __DIR__ . '/../..' . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationBracesFixer.php',
  30332. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationIndentationFixer' => __DIR__ . '/../..' . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationIndentationFixer.php',
  30333. 'PhpCsFixer\\Fixer\\DoctrineAnnotation\\DoctrineAnnotationSpacesFixer' => __DIR__ . '/../..' . '/src/Fixer/DoctrineAnnotation/DoctrineAnnotationSpacesFixer.php',
  30334. 'PhpCsFixer\\Fixer\\FixerInterface' => __DIR__ . '/../..' . '/src/Fixer/FixerInterface.php',
  30335. 'PhpCsFixer\\Fixer\\FunctionNotation\\FunctionDeclarationFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/FunctionDeclarationFixer.php',
  30336. 'PhpCsFixer\\Fixer\\FunctionNotation\\FunctionTypehintSpaceFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/FunctionTypehintSpaceFixer.php',
  30337. 'PhpCsFixer\\Fixer\\FunctionNotation\\MethodArgumentSpaceFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/MethodArgumentSpaceFixer.php',
  30338. 'PhpCsFixer\\Fixer\\FunctionNotation\\NativeFunctionInvocationFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/NativeFunctionInvocationFixer.php',
  30339. 'PhpCsFixer\\Fixer\\FunctionNotation\\NoSpacesAfterFunctionNameFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/NoSpacesAfterFunctionNameFixer.php',
  30340. 'PhpCsFixer\\Fixer\\FunctionNotation\\NoUnreachableDefaultArgumentValueFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/NoUnreachableDefaultArgumentValueFixer.php',
  30341. 'PhpCsFixer\\Fixer\\FunctionNotation\\ReturnTypeDeclarationFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/ReturnTypeDeclarationFixer.php',
  30342. 'PhpCsFixer\\Fixer\\FunctionNotation\\StaticLambdaFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/StaticLambdaFixer.php',
  30343. 'PhpCsFixer\\Fixer\\FunctionNotation\\VoidReturnFixer' => __DIR__ . '/../..' . '/src/Fixer/FunctionNotation/VoidReturnFixer.php',
  30344. 'PhpCsFixer\\Fixer\\Import\\NoLeadingImportSlashFixer' => __DIR__ . '/../..' . '/src/Fixer/Import/NoLeadingImportSlashFixer.php',
  30345. 'PhpCsFixer\\Fixer\\Import\\NoUnusedImportsFixer' => __DIR__ . '/../..' . '/src/Fixer/Import/NoUnusedImportsFixer.php',
  30346. 'PhpCsFixer\\Fixer\\Import\\OrderedImportsFixer' => __DIR__ . '/../..' . '/src/Fixer/Import/OrderedImportsFixer.php',
  30347. 'PhpCsFixer\\Fixer\\Import\\SingleImportPerStatementFixer' => __DIR__ . '/../..' . '/src/Fixer/Import/SingleImportPerStatementFixer.php',
  30348. 'PhpCsFixer\\Fixer\\Import\\SingleLineAfterImportsFixer' => __DIR__ . '/../..' . '/src/Fixer/Import/SingleLineAfterImportsFixer.php',
  30349. 'PhpCsFixer\\Fixer\\LanguageConstruct\\ClassKeywordRemoveFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/ClassKeywordRemoveFixer.php',
  30350. 'PhpCsFixer\\Fixer\\LanguageConstruct\\CombineConsecutiveIssetsFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/CombineConsecutiveIssetsFixer.php',
  30351. 'PhpCsFixer\\Fixer\\LanguageConstruct\\CombineConsecutiveUnsetsFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/CombineConsecutiveUnsetsFixer.php',
  30352. 'PhpCsFixer\\Fixer\\LanguageConstruct\\DeclareEqualNormalizeFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/DeclareEqualNormalizeFixer.php',
  30353. 'PhpCsFixer\\Fixer\\LanguageConstruct\\DirConstantFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/DirConstantFixer.php',
  30354. 'PhpCsFixer\\Fixer\\LanguageConstruct\\ExplicitIndirectVariableFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/ExplicitIndirectVariableFixer.php',
  30355. 'PhpCsFixer\\Fixer\\LanguageConstruct\\FunctionToConstantFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/FunctionToConstantFixer.php',
  30356. 'PhpCsFixer\\Fixer\\LanguageConstruct\\IsNullFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/IsNullFixer.php',
  30357. 'PhpCsFixer\\Fixer\\LanguageConstruct\\SilencedDeprecationErrorFixer' => __DIR__ . '/../..' . '/src/Fixer/LanguageConstruct/SilencedDeprecationErrorFixer.php',
  30358. 'PhpCsFixer\\Fixer\\ListNotation\\ListSyntaxFixer' => __DIR__ . '/../..' . '/src/Fixer/ListNotation/ListSyntaxFixer.php',
  30359. 'PhpCsFixer\\Fixer\\NamespaceNotation\\BlankLineAfterNamespaceFixer' => __DIR__ . '/../..' . '/src/Fixer/NamespaceNotation/BlankLineAfterNamespaceFixer.php',
  30360. 'PhpCsFixer\\Fixer\\NamespaceNotation\\NoBlankLinesBeforeNamespaceFixer' => __DIR__ . '/../..' . '/src/Fixer/NamespaceNotation/NoBlankLinesBeforeNamespaceFixer.php',
  30361. 'PhpCsFixer\\Fixer\\NamespaceNotation\\NoLeadingNamespaceWhitespaceFixer' => __DIR__ . '/../..' . '/src/Fixer/NamespaceNotation/NoLeadingNamespaceWhitespaceFixer.php',
  30362. 'PhpCsFixer\\Fixer\\NamespaceNotation\\SingleBlankLineBeforeNamespaceFixer' => __DIR__ . '/../..' . '/src/Fixer/NamespaceNotation/SingleBlankLineBeforeNamespaceFixer.php',
  30363. 'PhpCsFixer\\Fixer\\Naming\\NoHomoglyphNamesFixer' => __DIR__ . '/../..' . '/src/Fixer/Naming/NoHomoglyphNamesFixer.php',
  30364. 'PhpCsFixer\\Fixer\\Operator\\AlignDoubleArrowFixerHelper' => __DIR__ . '/../..' . '/src/Fixer/Operator/AlignDoubleArrowFixerHelper.php',
  30365. 'PhpCsFixer\\Fixer\\Operator\\AlignEqualsFixerHelper' => __DIR__ . '/../..' . '/src/Fixer/Operator/AlignEqualsFixerHelper.php',
  30366. 'PhpCsFixer\\Fixer\\Operator\\BinaryOperatorSpacesFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/BinaryOperatorSpacesFixer.php',
  30367. 'PhpCsFixer\\Fixer\\Operator\\ConcatSpaceFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/ConcatSpaceFixer.php',
  30368. 'PhpCsFixer\\Fixer\\Operator\\IncrementStyleFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/IncrementStyleFixer.php',
  30369. 'PhpCsFixer\\Fixer\\Operator\\NewWithBracesFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/NewWithBracesFixer.php',
  30370. 'PhpCsFixer\\Fixer\\Operator\\NotOperatorWithSpaceFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/NotOperatorWithSpaceFixer.php',
  30371. 'PhpCsFixer\\Fixer\\Operator\\NotOperatorWithSuccessorSpaceFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/NotOperatorWithSuccessorSpaceFixer.php',
  30372. 'PhpCsFixer\\Fixer\\Operator\\ObjectOperatorWithoutWhitespaceFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/ObjectOperatorWithoutWhitespaceFixer.php',
  30373. 'PhpCsFixer\\Fixer\\Operator\\PreIncrementFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/PreIncrementFixer.php',
  30374. 'PhpCsFixer\\Fixer\\Operator\\StandardizeNotEqualsFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/StandardizeNotEqualsFixer.php',
  30375. 'PhpCsFixer\\Fixer\\Operator\\TernaryOperatorSpacesFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/TernaryOperatorSpacesFixer.php',
  30376. 'PhpCsFixer\\Fixer\\Operator\\TernaryToNullCoalescingFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/TernaryToNullCoalescingFixer.php',
  30377. 'PhpCsFixer\\Fixer\\Operator\\UnaryOperatorSpacesFixer' => __DIR__ . '/../..' . '/src/Fixer/Operator/UnaryOperatorSpacesFixer.php',
  30378. 'PhpCsFixer\\Fixer\\PhpTag\\BlankLineAfterOpeningTagFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpTag/BlankLineAfterOpeningTagFixer.php',
  30379. 'PhpCsFixer\\Fixer\\PhpTag\\FullOpeningTagFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpTag/FullOpeningTagFixer.php',
  30380. 'PhpCsFixer\\Fixer\\PhpTag\\LinebreakAfterOpeningTagFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpTag/LinebreakAfterOpeningTagFixer.php',
  30381. 'PhpCsFixer\\Fixer\\PhpTag\\NoClosingTagFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpTag/NoClosingTagFixer.php',
  30382. 'PhpCsFixer\\Fixer\\PhpTag\\NoShortEchoTagFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpTag/NoShortEchoTagFixer.php',
  30383. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitConstructFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitConstructFixer.php',
  30384. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitDedicateAssertFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitDedicateAssertFixer.php',
  30385. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitExpectationFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitExpectationFixer.php',
  30386. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitFqcnAnnotationFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitFqcnAnnotationFixer.php',
  30387. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitMockFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitMockFixer.php',
  30388. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitNamespacedFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitNamespacedFixer.php',
  30389. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitNoExpectationAnnotationFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitNoExpectationAnnotationFixer.php',
  30390. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitStrictFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitStrictFixer.php',
  30391. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitTargetVersion' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitTargetVersion.php',
  30392. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitTestAnnotationFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitTestAnnotationFixer.php',
  30393. 'PhpCsFixer\\Fixer\\PhpUnit\\PhpUnitTestClassRequiresCoversFixer' => __DIR__ . '/../..' . '/src/Fixer/PhpUnit/PhpUnitTestClassRequiresCoversFixer.php',
  30394. 'PhpCsFixer\\Fixer\\Phpdoc\\AlignMultilineCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/AlignMultilineCommentFixer.php',
  30395. 'PhpCsFixer\\Fixer\\Phpdoc\\GeneralPhpdocAnnotationRemoveFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/GeneralPhpdocAnnotationRemoveFixer.php',
  30396. 'PhpCsFixer\\Fixer\\Phpdoc\\NoBlankLinesAfterPhpdocFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/NoBlankLinesAfterPhpdocFixer.php',
  30397. 'PhpCsFixer\\Fixer\\Phpdoc\\NoEmptyPhpdocFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/NoEmptyPhpdocFixer.php',
  30398. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAddMissingParamAnnotationFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocAddMissingParamAnnotationFixer.php',
  30399. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAlignFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocAlignFixer.php',
  30400. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocAnnotationWithoutDotFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocAnnotationWithoutDotFixer.php',
  30401. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocIndentFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocIndentFixer.php',
  30402. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocInlineTagFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocInlineTagFixer.php',
  30403. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoAccessFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocNoAccessFixer.php',
  30404. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoAliasTagFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocNoAliasTagFixer.php',
  30405. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoEmptyReturnFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocNoEmptyReturnFixer.php',
  30406. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoPackageFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocNoPackageFixer.php',
  30407. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocNoUselessInheritdocFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocNoUselessInheritdocFixer.php',
  30408. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocOrderFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocOrderFixer.php',
  30409. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocReturnSelfReferenceFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocReturnSelfReferenceFixer.php',
  30410. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocScalarFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocScalarFixer.php',
  30411. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSeparationFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocSeparationFixer.php',
  30412. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSingleLineVarSpacingFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocSingleLineVarSpacingFixer.php',
  30413. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocSummaryFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocSummaryFixer.php',
  30414. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocToCommentFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocToCommentFixer.php',
  30415. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocTrimFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocTrimFixer.php',
  30416. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocTypesFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocTypesFixer.php',
  30417. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocTypesOrderFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocTypesOrderFixer.php',
  30418. 'PhpCsFixer\\Fixer\\Phpdoc\\PhpdocVarWithoutNameFixer' => __DIR__ . '/../..' . '/src/Fixer/Phpdoc/PhpdocVarWithoutNameFixer.php',
  30419. 'PhpCsFixer\\Fixer\\ReturnNotation\\BlankLineBeforeReturnFixer' => __DIR__ . '/../..' . '/src/Fixer/ReturnNotation/BlankLineBeforeReturnFixer.php',
  30420. 'PhpCsFixer\\Fixer\\ReturnNotation\\NoUselessReturnFixer' => __DIR__ . '/../..' . '/src/Fixer/ReturnNotation/NoUselessReturnFixer.php',
  30421. 'PhpCsFixer\\Fixer\\ReturnNotation\\SimplifiedNullReturnFixer' => __DIR__ . '/../..' . '/src/Fixer/ReturnNotation/SimplifiedNullReturnFixer.php',
  30422. 'PhpCsFixer\\Fixer\\Semicolon\\MultilineWhitespaceBeforeSemicolonsFixer' => __DIR__ . '/../..' . '/src/Fixer/Semicolon/MultilineWhitespaceBeforeSemicolonsFixer.php',
  30423. 'PhpCsFixer\\Fixer\\Semicolon\\NoEmptyStatementFixer' => __DIR__ . '/../..' . '/src/Fixer/Semicolon/NoEmptyStatementFixer.php',
  30424. 'PhpCsFixer\\Fixer\\Semicolon\\NoMultilineWhitespaceBeforeSemicolonsFixer' => __DIR__ . '/../..' . '/src/Fixer/Semicolon/NoMultilineWhitespaceBeforeSemicolonsFixer.php',
  30425. 'PhpCsFixer\\Fixer\\Semicolon\\NoSinglelineWhitespaceBeforeSemicolonsFixer' => __DIR__ . '/../..' . '/src/Fixer/Semicolon/NoSinglelineWhitespaceBeforeSemicolonsFixer.php',
  30426. 'PhpCsFixer\\Fixer\\Semicolon\\SemicolonAfterInstructionFixer' => __DIR__ . '/../..' . '/src/Fixer/Semicolon/SemicolonAfterInstructionFixer.php',
  30427. 'PhpCsFixer\\Fixer\\Semicolon\\SpaceAfterSemicolonFixer' => __DIR__ . '/../..' . '/src/Fixer/Semicolon/SpaceAfterSemicolonFixer.php',
  30428. 'PhpCsFixer\\Fixer\\Strict\\DeclareStrictTypesFixer' => __DIR__ . '/../..' . '/src/Fixer/Strict/DeclareStrictTypesFixer.php',
  30429. 'PhpCsFixer\\Fixer\\Strict\\StrictComparisonFixer' => __DIR__ . '/../..' . '/src/Fixer/Strict/StrictComparisonFixer.php',
  30430. 'PhpCsFixer\\Fixer\\Strict\\StrictParamFixer' => __DIR__ . '/../..' . '/src/Fixer/Strict/StrictParamFixer.php',
  30431. 'PhpCsFixer\\Fixer\\StringNotation\\EscapeImplicitBackslashesFixer' => __DIR__ . '/../..' . '/src/Fixer/StringNotation/EscapeImplicitBackslashesFixer.php',
  30432. 'PhpCsFixer\\Fixer\\StringNotation\\ExplicitStringVariableFixer' => __DIR__ . '/../..' . '/src/Fixer/StringNotation/ExplicitStringVariableFixer.php',
  30433. 'PhpCsFixer\\Fixer\\StringNotation\\HeredocToNowdocFixer' => __DIR__ . '/../..' . '/src/Fixer/StringNotation/HeredocToNowdocFixer.php',
  30434. 'PhpCsFixer\\Fixer\\StringNotation\\SingleQuoteFixer' => __DIR__ . '/../..' . '/src/Fixer/StringNotation/SingleQuoteFixer.php',
  30435. 'PhpCsFixer\\Fixer\\Whitespace\\BlankLineBeforeStatementFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/BlankLineBeforeStatementFixer.php',
  30436. 'PhpCsFixer\\Fixer\\Whitespace\\CompactNullableTypehintFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/CompactNullableTypehintFixer.php',
  30437. 'PhpCsFixer\\Fixer\\Whitespace\\IndentationTypeFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/IndentationTypeFixer.php',
  30438. 'PhpCsFixer\\Fixer\\Whitespace\\LineEndingFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/LineEndingFixer.php',
  30439. 'PhpCsFixer\\Fixer\\Whitespace\\MethodChainingIndentationFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/MethodChainingIndentationFixer.php',
  30440. 'PhpCsFixer\\Fixer\\Whitespace\\NoExtraBlankLinesFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/NoExtraBlankLinesFixer.php',
  30441. 'PhpCsFixer\\Fixer\\Whitespace\\NoExtraConsecutiveBlankLinesFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/NoExtraConsecutiveBlankLinesFixer.php',
  30442. 'PhpCsFixer\\Fixer\\Whitespace\\NoSpacesAroundOffsetFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/NoSpacesAroundOffsetFixer.php',
  30443. 'PhpCsFixer\\Fixer\\Whitespace\\NoSpacesInsideParenthesisFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/NoSpacesInsideParenthesisFixer.php',
  30444. 'PhpCsFixer\\Fixer\\Whitespace\\NoTrailingWhitespaceFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/NoTrailingWhitespaceFixer.php',
  30445. 'PhpCsFixer\\Fixer\\Whitespace\\NoWhitespaceInBlankLineFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/NoWhitespaceInBlankLineFixer.php',
  30446. 'PhpCsFixer\\Fixer\\Whitespace\\SingleBlankLineAtEofFixer' => __DIR__ . '/../..' . '/src/Fixer/Whitespace/SingleBlankLineAtEofFixer.php',
  30447. 'PhpCsFixer\\Fixer\\WhitespacesAwareFixerInterface' => __DIR__ . '/../..' . '/src/Fixer/WhitespacesAwareFixerInterface.php',
  30448. 'PhpCsFixer\\Indicator\\PhpUnitTestCaseIndicator' => __DIR__ . '/../..' . '/src/Indicator/PhpUnitTestCaseIndicator.php',
  30449. 'PhpCsFixer\\Linter\\Linter' => __DIR__ . '/../..' . '/src/Linter/Linter.php',
  30450. 'PhpCsFixer\\Linter\\LinterInterface' => __DIR__ . '/../..' . '/src/Linter/LinterInterface.php',
  30451. 'PhpCsFixer\\Linter\\LintingException' => __DIR__ . '/../..' . '/src/Linter/LintingException.php',
  30452. 'PhpCsFixer\\Linter\\LintingResultInterface' => __DIR__ . '/../..' . '/src/Linter/LintingResultInterface.php',
  30453. 'PhpCsFixer\\Linter\\ProcessLinter' => __DIR__ . '/../..' . '/src/Linter/ProcessLinter.php',
  30454. 'PhpCsFixer\\Linter\\ProcessLinterProcessBuilder' => __DIR__ . '/../..' . '/src/Linter/ProcessLinterProcessBuilder.php',
  30455. 'PhpCsFixer\\Linter\\ProcessLintingResult' => __DIR__ . '/../..' . '/src/Linter/ProcessLintingResult.php',
  30456. 'PhpCsFixer\\Linter\\TokenizerLinter' => __DIR__ . '/../..' . '/src/Linter/TokenizerLinter.php',
  30457. 'PhpCsFixer\\Linter\\TokenizerLintingResult' => __DIR__ . '/../..' . '/src/Linter/TokenizerLintingResult.php',
  30458. 'PhpCsFixer\\Linter\\UnavailableLinterException' => __DIR__ . '/../..' . '/src/Linter/UnavailableLinterException.php',
  30459. 'PhpCsFixer\\PharChecker' => __DIR__ . '/../..' . '/src/PharChecker.php',
  30460. 'PhpCsFixer\\PharCheckerInterface' => __DIR__ . '/../..' . '/src/PharCheckerInterface.php',
  30461. 'PhpCsFixer\\Report\\CheckstyleReporter' => __DIR__ . '/../..' . '/src/Report/CheckstyleReporter.php',
  30462. 'PhpCsFixer\\Report\\JsonReporter' => __DIR__ . '/../..' . '/src/Report/JsonReporter.php',
  30463. 'PhpCsFixer\\Report\\JunitReporter' => __DIR__ . '/../..' . '/src/Report/JunitReporter.php',
  30464. 'PhpCsFixer\\Report\\ReportSummary' => __DIR__ . '/../..' . '/src/Report/ReportSummary.php',
  30465. 'PhpCsFixer\\Report\\ReporterFactory' => __DIR__ . '/../..' . '/src/Report/ReporterFactory.php',
  30466. 'PhpCsFixer\\Report\\ReporterInterface' => __DIR__ . '/../..' . '/src/Report/ReporterInterface.php',
  30467. 'PhpCsFixer\\Report\\TextReporter' => __DIR__ . '/../..' . '/src/Report/TextReporter.php',
  30468. 'PhpCsFixer\\Report\\XmlReporter' => __DIR__ . '/../..' . '/src/Report/XmlReporter.php',
  30469. 'PhpCsFixer\\RuleSet' => __DIR__ . '/../..' . '/src/RuleSet.php',
  30470. 'PhpCsFixer\\RuleSetInterface' => __DIR__ . '/../..' . '/src/RuleSetInterface.php',
  30471. 'PhpCsFixer\\Runner\\FileCachingLintingIterator' => __DIR__ . '/../..' . '/src/Runner/FileCachingLintingIterator.php',
  30472. 'PhpCsFixer\\Runner\\FileFilterIterator' => __DIR__ . '/../..' . '/src/Runner/FileFilterIterator.php',
  30473. 'PhpCsFixer\\Runner\\FileLintingIterator' => __DIR__ . '/../..' . '/src/Runner/FileLintingIterator.php',
  30474. 'PhpCsFixer\\Runner\\Runner' => __DIR__ . '/../..' . '/src/Runner/Runner.php',
  30475. 'PhpCsFixer\\StdinFileInfo' => __DIR__ . '/../..' . '/src/StdinFileInfo.php',
  30476. 'PhpCsFixer\\Test\\AbstractFixerTestCase' => __DIR__ . '/../..' . '/src/Test/AbstractFixerTestCase.php',
  30477. 'PhpCsFixer\\Test\\AbstractIntegrationTestCase' => __DIR__ . '/../..' . '/src/Test/AbstractIntegrationTestCase.php',
  30478. 'PhpCsFixer\\Test\\AccessibleObject' => __DIR__ . '/../..' . '/src/Test/AccessibleObject.php',
  30479. 'PhpCsFixer\\Test\\IntegrationCase' => __DIR__ . '/../..' . '/src/Test/IntegrationCase.php',
  30480. 'PhpCsFixer\\Tests\\TestCase' => __DIR__ . '/../..' . '/tests/TestCase.php',
  30481. 'PhpCsFixer\\Tests\\Test\\AbstractFixerTestCase' => __DIR__ . '/../..' . '/tests/Test/AbstractFixerTestCase.php',
  30482. 'PhpCsFixer\\Tests\\Test\\AbstractIntegrationTestCase' => __DIR__ . '/../..' . '/tests/Test/AbstractIntegrationTestCase.php',
  30483. 'PhpCsFixer\\Tests\\Test\\Assert\\AssertTokensTrait' => __DIR__ . '/../..' . '/tests/Test/Assert/AssertTokensTrait.php',
  30484. 'PhpCsFixer\\Tests\\Test\\IntegrationCase' => __DIR__ . '/../..' . '/tests/Test/IntegrationCase.php',
  30485. 'PhpCsFixer\\Tests\\Test\\IntegrationCaseFactory' => __DIR__ . '/../..' . '/tests/Test/IntegrationCaseFactory.php',
  30486. 'PhpCsFixer\\Tokenizer\\AbstractTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/AbstractTransformer.php',
  30487. 'PhpCsFixer\\Tokenizer\\Analyzer\\ArgumentsAnalyzer' => __DIR__ . '/../..' . '/src/Tokenizer/Analyzer/ArgumentsAnalyzer.php',
  30488. 'PhpCsFixer\\Tokenizer\\CT' => __DIR__ . '/../..' . '/src/Tokenizer/CT.php',
  30489. 'PhpCsFixer\\Tokenizer\\CodeHasher' => __DIR__ . '/../..' . '/src/Tokenizer/CodeHasher.php',
  30490. 'PhpCsFixer\\Tokenizer\\Token' => __DIR__ . '/../..' . '/src/Tokenizer/Token.php',
  30491. 'PhpCsFixer\\Tokenizer\\Tokens' => __DIR__ . '/../..' . '/src/Tokenizer/Tokens.php',
  30492. 'PhpCsFixer\\Tokenizer\\TokensAnalyzer' => __DIR__ . '/../..' . '/src/Tokenizer/TokensAnalyzer.php',
  30493. 'PhpCsFixer\\Tokenizer\\TransformerInterface' => __DIR__ . '/../..' . '/src/Tokenizer/TransformerInterface.php',
  30494. 'PhpCsFixer\\Tokenizer\\Transformer\\ArrayTypehintTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/ArrayTypehintTransformer.php',
  30495. 'PhpCsFixer\\Tokenizer\\Transformer\\BraceClassInstantiationTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/BraceClassInstantiationTransformer.php',
  30496. 'PhpCsFixer\\Tokenizer\\Transformer\\ClassConstantTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/ClassConstantTransformer.php',
  30497. 'PhpCsFixer\\Tokenizer\\Transformer\\CurlyBraceTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/CurlyBraceTransformer.php',
  30498. 'PhpCsFixer\\Tokenizer\\Transformer\\ImportTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/ImportTransformer.php',
  30499. 'PhpCsFixer\\Tokenizer\\Transformer\\NamespaceOperatorTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/NamespaceOperatorTransformer.php',
  30500. 'PhpCsFixer\\Tokenizer\\Transformer\\NullableTypeTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/NullableTypeTransformer.php',
  30501. 'PhpCsFixer\\Tokenizer\\Transformer\\ReturnRefTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/ReturnRefTransformer.php',
  30502. 'PhpCsFixer\\Tokenizer\\Transformer\\SquareBraceTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/SquareBraceTransformer.php',
  30503. 'PhpCsFixer\\Tokenizer\\Transformer\\TypeAlternationTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/TypeAlternationTransformer.php',
  30504. 'PhpCsFixer\\Tokenizer\\Transformer\\TypeColonTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/TypeColonTransformer.php',
  30505. 'PhpCsFixer\\Tokenizer\\Transformer\\UseTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/UseTransformer.php',
  30506. 'PhpCsFixer\\Tokenizer\\Transformer\\WhitespacyCommentTransformer' => __DIR__ . '/../..' . '/src/Tokenizer/Transformer/WhitespacyCommentTransformer.php',
  30507. 'PhpCsFixer\\Tokenizer\\Transformers' => __DIR__ . '/../..' . '/src/Tokenizer/Transformers.php',
  30508. 'PhpCsFixer\\ToolInfo' => __DIR__ . '/../..' . '/src/ToolInfo.php',
  30509. 'PhpCsFixer\\ToolInfoInterface' => __DIR__ . '/../..' . '/src/ToolInfoInterface.php',
  30510. 'PhpCsFixer\\Utils' => __DIR__ . '/../..' . '/src/Utils.php',
  30511. 'PhpCsFixer\\WhitespacesFixerConfig' => __DIR__ . '/../..' . '/src/WhitespacesFixerConfig.php',
  30512. 'PhpCsFixer\\WordMatcher' => __DIR__ . '/../..' . '/src/WordMatcher.php',
  30513. 'Psr\\Log\\AbstractLogger' => __DIR__ . '/..' . '/psr/log/Psr/Log/AbstractLogger.php',
  30514. 'Psr\\Log\\InvalidArgumentException' => __DIR__ . '/..' . '/psr/log/Psr/Log/InvalidArgumentException.php',
  30515. 'Psr\\Log\\LogLevel' => __DIR__ . '/..' . '/psr/log/Psr/Log/LogLevel.php',
  30516. 'Psr\\Log\\LoggerAwareInterface' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerAwareInterface.php',
  30517. 'Psr\\Log\\LoggerAwareTrait' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerAwareTrait.php',
  30518. 'Psr\\Log\\LoggerInterface' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerInterface.php',
  30519. 'Psr\\Log\\LoggerTrait' => __DIR__ . '/..' . '/psr/log/Psr/Log/LoggerTrait.php',
  30520. 'Psr\\Log\\NullLogger' => __DIR__ . '/..' . '/psr/log/Psr/Log/NullLogger.php',
  30521. 'Psr\\Log\\Test\\DummyTest' => __DIR__ . '/..' . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
  30522. 'Psr\\Log\\Test\\LoggerInterfaceTest' => __DIR__ . '/..' . '/psr/log/Psr/Log/Test/LoggerInterfaceTest.php',
  30523. 'SessionUpdateTimestampHandlerInterface' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/SessionUpdateTimestampHandlerInterface.php',
  30524. 'Symfony\\Component\\Console\\Application' => __DIR__ . '/..' . '/symfony/console/Application.php',
  30525. 'Symfony\\Component\\Console\\CommandLoader\\CommandLoaderInterface' => __DIR__ . '/..' . '/symfony/console/CommandLoader/CommandLoaderInterface.php',
  30526. 'Symfony\\Component\\Console\\CommandLoader\\ContainerCommandLoader' => __DIR__ . '/..' . '/symfony/console/CommandLoader/ContainerCommandLoader.php',
  30527. 'Symfony\\Component\\Console\\CommandLoader\\FactoryCommandLoader' => __DIR__ . '/..' . '/symfony/console/CommandLoader/FactoryCommandLoader.php',
  30528. 'Symfony\\Component\\Console\\Command\\Command' => __DIR__ . '/..' . '/symfony/console/Command/Command.php',
  30529. 'Symfony\\Component\\Console\\Command\\HelpCommand' => __DIR__ . '/..' . '/symfony/console/Command/HelpCommand.php',
  30530. 'Symfony\\Component\\Console\\Command\\ListCommand' => __DIR__ . '/..' . '/symfony/console/Command/ListCommand.php',
  30531. 'Symfony\\Component\\Console\\Command\\LockableTrait' => __DIR__ . '/..' . '/symfony/console/Command/LockableTrait.php',
  30532. 'Symfony\\Component\\Console\\ConsoleEvents' => __DIR__ . '/..' . '/symfony/console/ConsoleEvents.php',
  30533. 'Symfony\\Component\\Console\\DependencyInjection\\AddConsoleCommandPass' => __DIR__ . '/..' . '/symfony/console/DependencyInjection/AddConsoleCommandPass.php',
  30534. 'Symfony\\Component\\Console\\Descriptor\\ApplicationDescription' => __DIR__ . '/..' . '/symfony/console/Descriptor/ApplicationDescription.php',
  30535. 'Symfony\\Component\\Console\\Descriptor\\Descriptor' => __DIR__ . '/..' . '/symfony/console/Descriptor/Descriptor.php',
  30536. 'Symfony\\Component\\Console\\Descriptor\\DescriptorInterface' => __DIR__ . '/..' . '/symfony/console/Descriptor/DescriptorInterface.php',
  30537. 'Symfony\\Component\\Console\\Descriptor\\JsonDescriptor' => __DIR__ . '/..' . '/symfony/console/Descriptor/JsonDescriptor.php',
  30538. 'Symfony\\Component\\Console\\Descriptor\\MarkdownDescriptor' => __DIR__ . '/..' . '/symfony/console/Descriptor/MarkdownDescriptor.php',
  30539. 'Symfony\\Component\\Console\\Descriptor\\TextDescriptor' => __DIR__ . '/..' . '/symfony/console/Descriptor/TextDescriptor.php',
  30540. 'Symfony\\Component\\Console\\Descriptor\\XmlDescriptor' => __DIR__ . '/..' . '/symfony/console/Descriptor/XmlDescriptor.php',
  30541. 'Symfony\\Component\\Console\\EventListener\\ErrorListener' => __DIR__ . '/..' . '/symfony/console/EventListener/ErrorListener.php',
  30542. 'Symfony\\Component\\Console\\Event\\ConsoleCommandEvent' => __DIR__ . '/..' . '/symfony/console/Event/ConsoleCommandEvent.php',
  30543. 'Symfony\\Component\\Console\\Event\\ConsoleErrorEvent' => __DIR__ . '/..' . '/symfony/console/Event/ConsoleErrorEvent.php',
  30544. 'Symfony\\Component\\Console\\Event\\ConsoleEvent' => __DIR__ . '/..' . '/symfony/console/Event/ConsoleEvent.php',
  30545. 'Symfony\\Component\\Console\\Event\\ConsoleExceptionEvent' => __DIR__ . '/..' . '/symfony/console/Event/ConsoleExceptionEvent.php',
  30546. 'Symfony\\Component\\Console\\Event\\ConsoleTerminateEvent' => __DIR__ . '/..' . '/symfony/console/Event/ConsoleTerminateEvent.php',
  30547. 'Symfony\\Component\\Console\\Exception\\CommandNotFoundException' => __DIR__ . '/..' . '/symfony/console/Exception/CommandNotFoundException.php',
  30548. 'Symfony\\Component\\Console\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/console/Exception/ExceptionInterface.php',
  30549. 'Symfony\\Component\\Console\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/symfony/console/Exception/InvalidArgumentException.php',
  30550. 'Symfony\\Component\\Console\\Exception\\InvalidOptionException' => __DIR__ . '/..' . '/symfony/console/Exception/InvalidOptionException.php',
  30551. 'Symfony\\Component\\Console\\Exception\\LogicException' => __DIR__ . '/..' . '/symfony/console/Exception/LogicException.php',
  30552. 'Symfony\\Component\\Console\\Exception\\RuntimeException' => __DIR__ . '/..' . '/symfony/console/Exception/RuntimeException.php',
  30553. 'Symfony\\Component\\Console\\Formatter\\OutputFormatter' => __DIR__ . '/..' . '/symfony/console/Formatter/OutputFormatter.php',
  30554. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterInterface' => __DIR__ . '/..' . '/symfony/console/Formatter/OutputFormatterInterface.php',
  30555. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyle' => __DIR__ . '/..' . '/symfony/console/Formatter/OutputFormatterStyle.php',
  30556. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyleInterface' => __DIR__ . '/..' . '/symfony/console/Formatter/OutputFormatterStyleInterface.php',
  30557. 'Symfony\\Component\\Console\\Formatter\\OutputFormatterStyleStack' => __DIR__ . '/..' . '/symfony/console/Formatter/OutputFormatterStyleStack.php',
  30558. 'Symfony\\Component\\Console\\Helper\\DebugFormatterHelper' => __DIR__ . '/..' . '/symfony/console/Helper/DebugFormatterHelper.php',
  30559. 'Symfony\\Component\\Console\\Helper\\DescriptorHelper' => __DIR__ . '/..' . '/symfony/console/Helper/DescriptorHelper.php',
  30560. 'Symfony\\Component\\Console\\Helper\\FormatterHelper' => __DIR__ . '/..' . '/symfony/console/Helper/FormatterHelper.php',
  30561. 'Symfony\\Component\\Console\\Helper\\Helper' => __DIR__ . '/..' . '/symfony/console/Helper/Helper.php',
  30562. 'Symfony\\Component\\Console\\Helper\\HelperInterface' => __DIR__ . '/..' . '/symfony/console/Helper/HelperInterface.php',
  30563. 'Symfony\\Component\\Console\\Helper\\HelperSet' => __DIR__ . '/..' . '/symfony/console/Helper/HelperSet.php',
  30564. 'Symfony\\Component\\Console\\Helper\\InputAwareHelper' => __DIR__ . '/..' . '/symfony/console/Helper/InputAwareHelper.php',
  30565. 'Symfony\\Component\\Console\\Helper\\ProcessHelper' => __DIR__ . '/..' . '/symfony/console/Helper/ProcessHelper.php',
  30566. 'Symfony\\Component\\Console\\Helper\\ProgressBar' => __DIR__ . '/..' . '/symfony/console/Helper/ProgressBar.php',
  30567. 'Symfony\\Component\\Console\\Helper\\ProgressIndicator' => __DIR__ . '/..' . '/symfony/console/Helper/ProgressIndicator.php',
  30568. 'Symfony\\Component\\Console\\Helper\\QuestionHelper' => __DIR__ . '/..' . '/symfony/console/Helper/QuestionHelper.php',
  30569. 'Symfony\\Component\\Console\\Helper\\SymfonyQuestionHelper' => __DIR__ . '/..' . '/symfony/console/Helper/SymfonyQuestionHelper.php',
  30570. 'Symfony\\Component\\Console\\Helper\\Table' => __DIR__ . '/..' . '/symfony/console/Helper/Table.php',
  30571. 'Symfony\\Component\\Console\\Helper\\TableCell' => __DIR__ . '/..' . '/symfony/console/Helper/TableCell.php',
  30572. 'Symfony\\Component\\Console\\Helper\\TableSeparator' => __DIR__ . '/..' . '/symfony/console/Helper/TableSeparator.php',
  30573. 'Symfony\\Component\\Console\\Helper\\TableStyle' => __DIR__ . '/..' . '/symfony/console/Helper/TableStyle.php',
  30574. 'Symfony\\Component\\Console\\Input\\ArgvInput' => __DIR__ . '/..' . '/symfony/console/Input/ArgvInput.php',
  30575. 'Symfony\\Component\\Console\\Input\\ArrayInput' => __DIR__ . '/..' . '/symfony/console/Input/ArrayInput.php',
  30576. 'Symfony\\Component\\Console\\Input\\Input' => __DIR__ . '/..' . '/symfony/console/Input/Input.php',
  30577. 'Symfony\\Component\\Console\\Input\\InputArgument' => __DIR__ . '/..' . '/symfony/console/Input/InputArgument.php',
  30578. 'Symfony\\Component\\Console\\Input\\InputAwareInterface' => __DIR__ . '/..' . '/symfony/console/Input/InputAwareInterface.php',
  30579. 'Symfony\\Component\\Console\\Input\\InputDefinition' => __DIR__ . '/..' . '/symfony/console/Input/InputDefinition.php',
  30580. 'Symfony\\Component\\Console\\Input\\InputInterface' => __DIR__ . '/..' . '/symfony/console/Input/InputInterface.php',
  30581. 'Symfony\\Component\\Console\\Input\\InputOption' => __DIR__ . '/..' . '/symfony/console/Input/InputOption.php',
  30582. 'Symfony\\Component\\Console\\Input\\StreamableInputInterface' => __DIR__ . '/..' . '/symfony/console/Input/StreamableInputInterface.php',
  30583. 'Symfony\\Component\\Console\\Input\\StringInput' => __DIR__ . '/..' . '/symfony/console/Input/StringInput.php',
  30584. 'Symfony\\Component\\Console\\Logger\\ConsoleLogger' => __DIR__ . '/..' . '/symfony/console/Logger/ConsoleLogger.php',
  30585. 'Symfony\\Component\\Console\\Output\\BufferedOutput' => __DIR__ . '/..' . '/symfony/console/Output/BufferedOutput.php',
  30586. 'Symfony\\Component\\Console\\Output\\ConsoleOutput' => __DIR__ . '/..' . '/symfony/console/Output/ConsoleOutput.php',
  30587. 'Symfony\\Component\\Console\\Output\\ConsoleOutputInterface' => __DIR__ . '/..' . '/symfony/console/Output/ConsoleOutputInterface.php',
  30588. 'Symfony\\Component\\Console\\Output\\NullOutput' => __DIR__ . '/..' . '/symfony/console/Output/NullOutput.php',
  30589. 'Symfony\\Component\\Console\\Output\\Output' => __DIR__ . '/..' . '/symfony/console/Output/Output.php',
  30590. 'Symfony\\Component\\Console\\Output\\OutputInterface' => __DIR__ . '/..' . '/symfony/console/Output/OutputInterface.php',
  30591. 'Symfony\\Component\\Console\\Output\\StreamOutput' => __DIR__ . '/..' . '/symfony/console/Output/StreamOutput.php',
  30592. 'Symfony\\Component\\Console\\Question\\ChoiceQuestion' => __DIR__ . '/..' . '/symfony/console/Question/ChoiceQuestion.php',
  30593. 'Symfony\\Component\\Console\\Question\\ConfirmationQuestion' => __DIR__ . '/..' . '/symfony/console/Question/ConfirmationQuestion.php',
  30594. 'Symfony\\Component\\Console\\Question\\Question' => __DIR__ . '/..' . '/symfony/console/Question/Question.php',
  30595. 'Symfony\\Component\\Console\\Style\\OutputStyle' => __DIR__ . '/..' . '/symfony/console/Style/OutputStyle.php',
  30596. 'Symfony\\Component\\Console\\Style\\StyleInterface' => __DIR__ . '/..' . '/symfony/console/Style/StyleInterface.php',
  30597. 'Symfony\\Component\\Console\\Style\\SymfonyStyle' => __DIR__ . '/..' . '/symfony/console/Style/SymfonyStyle.php',
  30598. 'Symfony\\Component\\Console\\Terminal' => __DIR__ . '/..' . '/symfony/console/Terminal.php',
  30599. 'Symfony\\Component\\Console\\Tester\\ApplicationTester' => __DIR__ . '/..' . '/symfony/console/Tester/ApplicationTester.php',
  30600. 'Symfony\\Component\\Console\\Tester\\CommandTester' => __DIR__ . '/..' . '/symfony/console/Tester/CommandTester.php',
  30601. 'Symfony\\Component\\Debug\\BufferingLogger' => __DIR__ . '/..' . '/symfony/debug/BufferingLogger.php',
  30602. 'Symfony\\Component\\Debug\\Debug' => __DIR__ . '/..' . '/symfony/debug/Debug.php',
  30603. 'Symfony\\Component\\Debug\\DebugClassLoader' => __DIR__ . '/..' . '/symfony/debug/DebugClassLoader.php',
  30604. 'Symfony\\Component\\Debug\\ErrorHandler' => __DIR__ . '/..' . '/symfony/debug/ErrorHandler.php',
  30605. 'Symfony\\Component\\Debug\\ExceptionHandler' => __DIR__ . '/..' . '/symfony/debug/ExceptionHandler.php',
  30606. 'Symfony\\Component\\Debug\\Exception\\ClassNotFoundException' => __DIR__ . '/..' . '/symfony/debug/Exception/ClassNotFoundException.php',
  30607. 'Symfony\\Component\\Debug\\Exception\\ContextErrorException' => __DIR__ . '/..' . '/symfony/debug/Exception/ContextErrorException.php',
  30608. 'Symfony\\Component\\Debug\\Exception\\FatalErrorException' => __DIR__ . '/..' . '/symfony/debug/Exception/FatalErrorException.php',
  30609. 'Symfony\\Component\\Debug\\Exception\\FatalThrowableError' => __DIR__ . '/..' . '/symfony/debug/Exception/FatalThrowableError.php',
  30610. 'Symfony\\Component\\Debug\\Exception\\FlattenException' => __DIR__ . '/..' . '/symfony/debug/Exception/FlattenException.php',
  30611. 'Symfony\\Component\\Debug\\Exception\\OutOfMemoryException' => __DIR__ . '/..' . '/symfony/debug/Exception/OutOfMemoryException.php',
  30612. 'Symfony\\Component\\Debug\\Exception\\SilencedErrorContext' => __DIR__ . '/..' . '/symfony/debug/Exception/SilencedErrorContext.php',
  30613. 'Symfony\\Component\\Debug\\Exception\\UndefinedFunctionException' => __DIR__ . '/..' . '/symfony/debug/Exception/UndefinedFunctionException.php',
  30614. 'Symfony\\Component\\Debug\\Exception\\UndefinedMethodException' => __DIR__ . '/..' . '/symfony/debug/Exception/UndefinedMethodException.php',
  30615. 'Symfony\\Component\\Debug\\FatalErrorHandler\\ClassNotFoundFatalErrorHandler' => __DIR__ . '/..' . '/symfony/debug/FatalErrorHandler/ClassNotFoundFatalErrorHandler.php',
  30616. 'Symfony\\Component\\Debug\\FatalErrorHandler\\FatalErrorHandlerInterface' => __DIR__ . '/..' . '/symfony/debug/FatalErrorHandler/FatalErrorHandlerInterface.php',
  30617. 'Symfony\\Component\\Debug\\FatalErrorHandler\\UndefinedFunctionFatalErrorHandler' => __DIR__ . '/..' . '/symfony/debug/FatalErrorHandler/UndefinedFunctionFatalErrorHandler.php',
  30618. 'Symfony\\Component\\Debug\\FatalErrorHandler\\UndefinedMethodFatalErrorHandler' => __DIR__ . '/..' . '/symfony/debug/FatalErrorHandler/UndefinedMethodFatalErrorHandler.php',
  30619. 'Symfony\\Component\\EventDispatcher\\ContainerAwareEventDispatcher' => __DIR__ . '/..' . '/symfony/event-dispatcher/ContainerAwareEventDispatcher.php',
  30620. 'Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcher' => __DIR__ . '/..' . '/symfony/event-dispatcher/Debug/TraceableEventDispatcher.php',
  30621. 'Symfony\\Component\\EventDispatcher\\Debug\\TraceableEventDispatcherInterface' => __DIR__ . '/..' . '/symfony/event-dispatcher/Debug/TraceableEventDispatcherInterface.php',
  30622. 'Symfony\\Component\\EventDispatcher\\Debug\\WrappedListener' => __DIR__ . '/..' . '/symfony/event-dispatcher/Debug/WrappedListener.php',
  30623. 'Symfony\\Component\\EventDispatcher\\DependencyInjection\\ExtractingEventDispatcher' => __DIR__ . '/..' . '/symfony/event-dispatcher/DependencyInjection/RegisterListenersPass.php',
  30624. 'Symfony\\Component\\EventDispatcher\\DependencyInjection\\RegisterListenersPass' => __DIR__ . '/..' . '/symfony/event-dispatcher/DependencyInjection/RegisterListenersPass.php',
  30625. 'Symfony\\Component\\EventDispatcher\\Event' => __DIR__ . '/..' . '/symfony/event-dispatcher/Event.php',
  30626. 'Symfony\\Component\\EventDispatcher\\EventDispatcher' => __DIR__ . '/..' . '/symfony/event-dispatcher/EventDispatcher.php',
  30627. 'Symfony\\Component\\EventDispatcher\\EventDispatcherInterface' => __DIR__ . '/..' . '/symfony/event-dispatcher/EventDispatcherInterface.php',
  30628. 'Symfony\\Component\\EventDispatcher\\EventSubscriberInterface' => __DIR__ . '/..' . '/symfony/event-dispatcher/EventSubscriberInterface.php',
  30629. 'Symfony\\Component\\EventDispatcher\\GenericEvent' => __DIR__ . '/..' . '/symfony/event-dispatcher/GenericEvent.php',
  30630. 'Symfony\\Component\\EventDispatcher\\ImmutableEventDispatcher' => __DIR__ . '/..' . '/symfony/event-dispatcher/ImmutableEventDispatcher.php',
  30631. 'Symfony\\Component\\Filesystem\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/filesystem/Exception/ExceptionInterface.php',
  30632. 'Symfony\\Component\\Filesystem\\Exception\\FileNotFoundException' => __DIR__ . '/..' . '/symfony/filesystem/Exception/FileNotFoundException.php',
  30633. 'Symfony\\Component\\Filesystem\\Exception\\IOException' => __DIR__ . '/..' . '/symfony/filesystem/Exception/IOException.php',
  30634. 'Symfony\\Component\\Filesystem\\Exception\\IOExceptionInterface' => __DIR__ . '/..' . '/symfony/filesystem/Exception/IOExceptionInterface.php',
  30635. 'Symfony\\Component\\Filesystem\\Filesystem' => __DIR__ . '/..' . '/symfony/filesystem/Filesystem.php',
  30636. 'Symfony\\Component\\Filesystem\\LockHandler' => __DIR__ . '/..' . '/symfony/filesystem/LockHandler.php',
  30637. 'Symfony\\Component\\Finder\\Comparator\\Comparator' => __DIR__ . '/..' . '/symfony/finder/Comparator/Comparator.php',
  30638. 'Symfony\\Component\\Finder\\Comparator\\DateComparator' => __DIR__ . '/..' . '/symfony/finder/Comparator/DateComparator.php',
  30639. 'Symfony\\Component\\Finder\\Comparator\\NumberComparator' => __DIR__ . '/..' . '/symfony/finder/Comparator/NumberComparator.php',
  30640. 'Symfony\\Component\\Finder\\Exception\\AccessDeniedException' => __DIR__ . '/..' . '/symfony/finder/Exception/AccessDeniedException.php',
  30641. 'Symfony\\Component\\Finder\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/finder/Exception/ExceptionInterface.php',
  30642. 'Symfony\\Component\\Finder\\Finder' => __DIR__ . '/..' . '/symfony/finder/Finder.php',
  30643. 'Symfony\\Component\\Finder\\Glob' => __DIR__ . '/..' . '/symfony/finder/Glob.php',
  30644. 'Symfony\\Component\\Finder\\Iterator\\CustomFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/CustomFilterIterator.php',
  30645. 'Symfony\\Component\\Finder\\Iterator\\DateRangeFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/DateRangeFilterIterator.php',
  30646. 'Symfony\\Component\\Finder\\Iterator\\DepthRangeFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/DepthRangeFilterIterator.php',
  30647. 'Symfony\\Component\\Finder\\Iterator\\ExcludeDirectoryFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/ExcludeDirectoryFilterIterator.php',
  30648. 'Symfony\\Component\\Finder\\Iterator\\FileTypeFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/FileTypeFilterIterator.php',
  30649. 'Symfony\\Component\\Finder\\Iterator\\FilecontentFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/FilecontentFilterIterator.php',
  30650. 'Symfony\\Component\\Finder\\Iterator\\FilenameFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/FilenameFilterIterator.php',
  30651. 'Symfony\\Component\\Finder\\Iterator\\FilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/FilterIterator.php',
  30652. 'Symfony\\Component\\Finder\\Iterator\\MultiplePcreFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/MultiplePcreFilterIterator.php',
  30653. 'Symfony\\Component\\Finder\\Iterator\\PathFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/PathFilterIterator.php',
  30654. 'Symfony\\Component\\Finder\\Iterator\\RecursiveDirectoryIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/RecursiveDirectoryIterator.php',
  30655. 'Symfony\\Component\\Finder\\Iterator\\SizeRangeFilterIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/SizeRangeFilterIterator.php',
  30656. 'Symfony\\Component\\Finder\\Iterator\\SortableIterator' => __DIR__ . '/..' . '/symfony/finder/Iterator/SortableIterator.php',
  30657. 'Symfony\\Component\\Finder\\SplFileInfo' => __DIR__ . '/..' . '/symfony/finder/SplFileInfo.php',
  30658. 'Symfony\\Component\\OptionsResolver\\Debug\\OptionsResolverIntrospector' => __DIR__ . '/..' . '/symfony/options-resolver/Debug/OptionsResolverIntrospector.php',
  30659. 'Symfony\\Component\\OptionsResolver\\Exception\\AccessException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/AccessException.php',
  30660. 'Symfony\\Component\\OptionsResolver\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/ExceptionInterface.php',
  30661. 'Symfony\\Component\\OptionsResolver\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/InvalidArgumentException.php',
  30662. 'Symfony\\Component\\OptionsResolver\\Exception\\InvalidOptionsException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/InvalidOptionsException.php',
  30663. 'Symfony\\Component\\OptionsResolver\\Exception\\MissingOptionsException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/MissingOptionsException.php',
  30664. 'Symfony\\Component\\OptionsResolver\\Exception\\NoConfigurationException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/NoConfigurationException.php',
  30665. 'Symfony\\Component\\OptionsResolver\\Exception\\NoSuchOptionException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/NoSuchOptionException.php',
  30666. 'Symfony\\Component\\OptionsResolver\\Exception\\OptionDefinitionException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/OptionDefinitionException.php',
  30667. 'Symfony\\Component\\OptionsResolver\\Exception\\UndefinedOptionsException' => __DIR__ . '/..' . '/symfony/options-resolver/Exception/UndefinedOptionsException.php',
  30668. 'Symfony\\Component\\OptionsResolver\\Options' => __DIR__ . '/..' . '/symfony/options-resolver/Options.php',
  30669. 'Symfony\\Component\\OptionsResolver\\OptionsResolver' => __DIR__ . '/..' . '/symfony/options-resolver/OptionsResolver.php',
  30670. 'Symfony\\Component\\Process\\Exception\\ExceptionInterface' => __DIR__ . '/..' . '/symfony/process/Exception/ExceptionInterface.php',
  30671. 'Symfony\\Component\\Process\\Exception\\InvalidArgumentException' => __DIR__ . '/..' . '/symfony/process/Exception/InvalidArgumentException.php',
  30672. 'Symfony\\Component\\Process\\Exception\\LogicException' => __DIR__ . '/..' . '/symfony/process/Exception/LogicException.php',
  30673. 'Symfony\\Component\\Process\\Exception\\ProcessFailedException' => __DIR__ . '/..' . '/symfony/process/Exception/ProcessFailedException.php',
  30674. 'Symfony\\Component\\Process\\Exception\\ProcessTimedOutException' => __DIR__ . '/..' . '/symfony/process/Exception/ProcessTimedOutException.php',
  30675. 'Symfony\\Component\\Process\\Exception\\RuntimeException' => __DIR__ . '/..' . '/symfony/process/Exception/RuntimeException.php',
  30676. 'Symfony\\Component\\Process\\ExecutableFinder' => __DIR__ . '/..' . '/symfony/process/ExecutableFinder.php',
  30677. 'Symfony\\Component\\Process\\InputStream' => __DIR__ . '/..' . '/symfony/process/InputStream.php',
  30678. 'Symfony\\Component\\Process\\PhpExecutableFinder' => __DIR__ . '/..' . '/symfony/process/PhpExecutableFinder.php',
  30679. 'Symfony\\Component\\Process\\PhpProcess' => __DIR__ . '/..' . '/symfony/process/PhpProcess.php',
  30680. 'Symfony\\Component\\Process\\Pipes\\AbstractPipes' => __DIR__ . '/..' . '/symfony/process/Pipes/AbstractPipes.php',
  30681. 'Symfony\\Component\\Process\\Pipes\\PipesInterface' => __DIR__ . '/..' . '/symfony/process/Pipes/PipesInterface.php',
  30682. 'Symfony\\Component\\Process\\Pipes\\UnixPipes' => __DIR__ . '/..' . '/symfony/process/Pipes/UnixPipes.php',
  30683. 'Symfony\\Component\\Process\\Pipes\\WindowsPipes' => __DIR__ . '/..' . '/symfony/process/Pipes/WindowsPipes.php',
  30684. 'Symfony\\Component\\Process\\Process' => __DIR__ . '/..' . '/symfony/process/Process.php',
  30685. 'Symfony\\Component\\Process\\ProcessBuilder' => __DIR__ . '/..' . '/symfony/process/ProcessBuilder.php',
  30686. 'Symfony\\Component\\Process\\ProcessUtils' => __DIR__ . '/..' . '/symfony/process/ProcessUtils.php',
  30687. 'Symfony\\Component\\Stopwatch\\Section' => __DIR__ . '/..' . '/symfony/stopwatch/Section.php',
  30688. 'Symfony\\Component\\Stopwatch\\Stopwatch' => __DIR__ . '/..' . '/symfony/stopwatch/Stopwatch.php',
  30689. 'Symfony\\Component\\Stopwatch\\StopwatchEvent' => __DIR__ . '/..' . '/symfony/stopwatch/StopwatchEvent.php',
  30690. 'Symfony\\Component\\Stopwatch\\StopwatchPeriod' => __DIR__ . '/..' . '/symfony/stopwatch/StopwatchPeriod.php',
  30691. 'Symfony\\Polyfill\\Mbstring\\Mbstring' => __DIR__ . '/..' . '/symfony/polyfill-mbstring/Mbstring.php',
  30692. 'Symfony\\Polyfill\\Php70\\Php70' => __DIR__ . '/..' . '/symfony/polyfill-php70/Php70.php',
  30693. 'Symfony\\Polyfill\\Php72\\Php72' => __DIR__ . '/..' . '/symfony/polyfill-php72/Php72.php',
  30694. 'TypeError' => __DIR__ . '/..' . '/symfony/polyfill-php70/Resources/stubs/TypeError.php',
  30695. );
  30696. public static function getInitializer(ClassLoader $loader)
  30697. {
  30698. return \Closure::bind(function () use ($loader) {
  30699. $loader->prefixLengthsPsr4 = ComposerStaticInit1d283854a5726c702db972976066d6a2::$prefixLengthsPsr4;
  30700. $loader->prefixDirsPsr4 = ComposerStaticInit1d283854a5726c702db972976066d6a2::$prefixDirsPsr4;
  30701. $loader->prefixesPsr0 = ComposerStaticInit1d283854a5726c702db972976066d6a2::$prefixesPsr0;
  30702. $loader->classMap = ComposerStaticInit1d283854a5726c702db972976066d6a2::$classMap;
  30703. }, null, ClassLoader::class);
  30704. }
  30705. }
  30706. <?php
  30707. class ComposerAutoloaderInit1d283854a5726c702db972976066d6a2
  30708. {
  30709. private static $loader;
  30710. public static function loadClassLoader($class)
  30711. {
  30712. if ('Composer\Autoload\ClassLoader' === $class) {
  30713. require __DIR__ . '/ClassLoader.php';
  30714. }
  30715. }
  30716. public static function getLoader()
  30717. {
  30718. if (null !== self::$loader) {
  30719. return self::$loader;
  30720. }
  30721. spl_autoload_register(array('ComposerAutoloaderInit1d283854a5726c702db972976066d6a2', 'loadClassLoader'), true, true);
  30722. self::$loader = $loader = new \Composer\Autoload\ClassLoader();
  30723. spl_autoload_unregister(array('ComposerAutoloaderInit1d283854a5726c702db972976066d6a2', 'loadClassLoader'));
  30724. $useStaticLoader = PHP_VERSION_ID >= 50600 && !defined('HHVM_VERSION') && (!function_exists('zend_loader_file_encoded') || !zend_loader_file_encoded());
  30725. if ($useStaticLoader) {
  30726. require_once __DIR__ . '/autoload_static.php';
  30727. call_user_func(\Composer\Autoload\ComposerStaticInit1d283854a5726c702db972976066d6a2::getInitializer($loader));
  30728. } else {
  30729. $map = require __DIR__ . '/autoload_namespaces.php';
  30730. foreach ($map as $namespace => $path) {
  30731. $loader->set($namespace, $path);
  30732. }
  30733. $map = require __DIR__ . '/autoload_psr4.php';
  30734. foreach ($map as $namespace => $path) {
  30735. $loader->setPsr4($namespace, $path);
  30736. }
  30737. $classMap = require __DIR__ . '/autoload_classmap.php';
  30738. if ($classMap) {
  30739. $loader->addClassMap($classMap);
  30740. }
  30741. }
  30742. $loader->register(true);
  30743. if ($useStaticLoader) {
  30744. $includeFiles = Composer\Autoload\ComposerStaticInit1d283854a5726c702db972976066d6a2::$files;
  30745. } else {
  30746. $includeFiles = require __DIR__ . '/autoload_files.php';
  30747. }
  30748. foreach ($includeFiles as $fileIdentifier => $file) {
  30749. composerRequire1d283854a5726c702db972976066d6a2($fileIdentifier, $file);
  30750. }
  30751. return $loader;
  30752. }
  30753. }
  30754. function composerRequire1d283854a5726c702db972976066d6a2($fileIdentifier, $file)
  30755. {
  30756. if (empty($GLOBALS['__composer_autoload_files'][$fileIdentifier])) {
  30757. require $file;
  30758. $GLOBALS['__composer_autoload_files'][$fileIdentifier] = true;
  30759. }
  30760. }
  30761. <?php
  30762. namespace Composer\Autoload;
  30763. class ClassLoader
  30764. {
  30765. private $prefixLengthsPsr4 = array();
  30766. private $prefixDirsPsr4 = array();
  30767. private $fallbackDirsPsr4 = array();
  30768. private $prefixesPsr0 = array();
  30769. private $fallbackDirsPsr0 = array();
  30770. private $useIncludePath = false;
  30771. private $classMap = array();
  30772. private $classMapAuthoritative = false;
  30773. private $missingClasses = array();
  30774. private $apcuPrefix;
  30775. public function getPrefixes()
  30776. {
  30777. if (!empty($this->prefixesPsr0)) {
  30778. return call_user_func_array('array_merge', $this->prefixesPsr0);
  30779. }
  30780. return array();
  30781. }
  30782. public function getPrefixesPsr4()
  30783. {
  30784. return $this->prefixDirsPsr4;
  30785. }
  30786. public function getFallbackDirs()
  30787. {
  30788. return $this->fallbackDirsPsr0;
  30789. }
  30790. public function getFallbackDirsPsr4()
  30791. {
  30792. return $this->fallbackDirsPsr4;
  30793. }
  30794. public function getClassMap()
  30795. {
  30796. return $this->classMap;
  30797. }
  30798. public function addClassMap(array $classMap)
  30799. {
  30800. if ($this->classMap) {
  30801. $this->classMap = array_merge($this->classMap, $classMap);
  30802. } else {
  30803. $this->classMap = $classMap;
  30804. }
  30805. }
  30806. public function add($prefix, $paths, $prepend = false)
  30807. {
  30808. if (!$prefix) {
  30809. if ($prepend) {
  30810. $this->fallbackDirsPsr0 = array_merge(
  30811. (array) $paths,
  30812. $this->fallbackDirsPsr0
  30813. );
  30814. } else {
  30815. $this->fallbackDirsPsr0 = array_merge(
  30816. $this->fallbackDirsPsr0,
  30817. (array) $paths
  30818. );
  30819. }
  30820. return;
  30821. }
  30822. $first = $prefix[0];
  30823. if (!isset($this->prefixesPsr0[$first][$prefix])) {
  30824. $this->prefixesPsr0[$first][$prefix] = (array) $paths;
  30825. return;
  30826. }
  30827. if ($prepend) {
  30828. $this->prefixesPsr0[$first][$prefix] = array_merge(
  30829. (array) $paths,
  30830. $this->prefixesPsr0[$first][$prefix]
  30831. );
  30832. } else {
  30833. $this->prefixesPsr0[$first][$prefix] = array_merge(
  30834. $this->prefixesPsr0[$first][$prefix],
  30835. (array) $paths
  30836. );
  30837. }
  30838. }
  30839. public function addPsr4($prefix, $paths, $prepend = false)
  30840. {
  30841. if (!$prefix) {
  30842. if ($prepend) {
  30843. $this->fallbackDirsPsr4 = array_merge(
  30844. (array) $paths,
  30845. $this->fallbackDirsPsr4
  30846. );
  30847. } else {
  30848. $this->fallbackDirsPsr4 = array_merge(
  30849. $this->fallbackDirsPsr4,
  30850. (array) $paths
  30851. );
  30852. }
  30853. } elseif (!isset($this->prefixDirsPsr4[$prefix])) {
  30854. $length = strlen($prefix);
  30855. if ('\\' !== $prefix[$length - 1]) {
  30856. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  30857. }
  30858. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  30859. $this->prefixDirsPsr4[$prefix] = (array) $paths;
  30860. } elseif ($prepend) {
  30861. $this->prefixDirsPsr4[$prefix] = array_merge(
  30862. (array) $paths,
  30863. $this->prefixDirsPsr4[$prefix]
  30864. );
  30865. } else {
  30866. $this->prefixDirsPsr4[$prefix] = array_merge(
  30867. $this->prefixDirsPsr4[$prefix],
  30868. (array) $paths
  30869. );
  30870. }
  30871. }
  30872. public function set($prefix, $paths)
  30873. {
  30874. if (!$prefix) {
  30875. $this->fallbackDirsPsr0 = (array) $paths;
  30876. } else {
  30877. $this->prefixesPsr0[$prefix[0]][$prefix] = (array) $paths;
  30878. }
  30879. }
  30880. public function setPsr4($prefix, $paths)
  30881. {
  30882. if (!$prefix) {
  30883. $this->fallbackDirsPsr4 = (array) $paths;
  30884. } else {
  30885. $length = strlen($prefix);
  30886. if ('\\' !== $prefix[$length - 1]) {
  30887. throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator.");
  30888. }
  30889. $this->prefixLengthsPsr4[$prefix[0]][$prefix] = $length;
  30890. $this->prefixDirsPsr4[$prefix] = (array) $paths;
  30891. }
  30892. }
  30893. public function setUseIncludePath($useIncludePath)
  30894. {
  30895. $this->useIncludePath = $useIncludePath;
  30896. }
  30897. public function getUseIncludePath()
  30898. {
  30899. return $this->useIncludePath;
  30900. }
  30901. public function setClassMapAuthoritative($classMapAuthoritative)
  30902. {
  30903. $this->classMapAuthoritative = $classMapAuthoritative;
  30904. }
  30905. public function isClassMapAuthoritative()
  30906. {
  30907. return $this->classMapAuthoritative;
  30908. }
  30909. public function setApcuPrefix($apcuPrefix)
  30910. {
  30911. $this->apcuPrefix = function_exists('apcu_fetch') && ini_get('apc.enabled') ? $apcuPrefix : null;
  30912. }
  30913. public function getApcuPrefix()
  30914. {
  30915. return $this->apcuPrefix;
  30916. }
  30917. public function register($prepend = false)
  30918. {
  30919. spl_autoload_register(array($this, 'loadClass'), true, $prepend);
  30920. }
  30921. public function unregister()
  30922. {
  30923. spl_autoload_unregister(array($this, 'loadClass'));
  30924. }
  30925. public function loadClass($class)
  30926. {
  30927. if ($file = $this->findFile($class)) {
  30928. includeFile($file);
  30929. return true;
  30930. }
  30931. }
  30932. public function findFile($class)
  30933. {
  30934. if (isset($this->classMap[$class])) {
  30935. return $this->classMap[$class];
  30936. }
  30937. if ($this->classMapAuthoritative || isset($this->missingClasses[$class])) {
  30938. return false;
  30939. }
  30940. if (null !== $this->apcuPrefix) {
  30941. $file = apcu_fetch($this->apcuPrefix.$class, $hit);
  30942. if ($hit) {
  30943. return $file;
  30944. }
  30945. }
  30946. $file = $this->findFileWithExtension($class, '.php');
  30947. if (false === $file && defined('HHVM_VERSION')) {
  30948. $file = $this->findFileWithExtension($class, '.hh');
  30949. }
  30950. if (null !== $this->apcuPrefix) {
  30951. apcu_add($this->apcuPrefix.$class, $file);
  30952. }
  30953. if (false === $file) {
  30954. $this->missingClasses[$class] = true;
  30955. }
  30956. return $file;
  30957. }
  30958. private function findFileWithExtension($class, $ext)
  30959. {
  30960. $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext;
  30961. $first = $class[0];
  30962. if (isset($this->prefixLengthsPsr4[$first])) {
  30963. $subPath = $class;
  30964. while (false !== $lastPos = strrpos($subPath, '\\')) {
  30965. $subPath = substr($subPath, 0, $lastPos);
  30966. $search = $subPath.'\\';
  30967. if (isset($this->prefixDirsPsr4[$search])) {
  30968. $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1);
  30969. foreach ($this->prefixDirsPsr4[$search] as $dir) {
  30970. if (file_exists($file = $dir . $pathEnd)) {
  30971. return $file;
  30972. }
  30973. }
  30974. }
  30975. }
  30976. }
  30977. foreach ($this->fallbackDirsPsr4 as $dir) {
  30978. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) {
  30979. return $file;
  30980. }
  30981. }
  30982. if (false !== $pos = strrpos($class, '\\')) {
  30983. $logicalPathPsr0 = substr($logicalPathPsr4, 0, $pos + 1)
  30984. . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR);
  30985. } else {
  30986. $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext;
  30987. }
  30988. if (isset($this->prefixesPsr0[$first])) {
  30989. foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) {
  30990. if (0 === strpos($class, $prefix)) {
  30991. foreach ($dirs as $dir) {
  30992. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  30993. return $file;
  30994. }
  30995. }
  30996. }
  30997. }
  30998. }
  30999. foreach ($this->fallbackDirsPsr0 as $dir) {
  31000. if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) {
  31001. return $file;
  31002. }
  31003. }
  31004. if ($this->useIncludePath && $file = stream_resolve_include_path($logicalPathPsr0)) {
  31005. return $file;
  31006. }
  31007. return false;
  31008. }
  31009. }
  31010. function includeFile($file)
  31011. {
  31012. include $file;
  31013. }
  31014. <?php
  31015. namespace Symfony\Component\Process\Exception;
  31016. interface ExceptionInterface
  31017. {
  31018. }
  31019. <?php
  31020. namespace Symfony\Component\Process\Exception;
  31021. class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
  31022. {
  31023. }
  31024. <?php
  31025. namespace Symfony\Component\Process\Exception;
  31026. class LogicException extends \LogicException implements ExceptionInterface
  31027. {
  31028. }
  31029. <?php
  31030. namespace Symfony\Component\Process\Exception;
  31031. use Symfony\Component\Process\Process;
  31032. class ProcessFailedException extends RuntimeException
  31033. {
  31034. private $process;
  31035. public function __construct(Process $process)
  31036. {
  31037. if ($process->isSuccessful()) {
  31038. throw new InvalidArgumentException('Expected a failed process, but the given process was successful.');
  31039. }
  31040. $error = sprintf('The command "%s" failed.'."\n\nExit Code: %s(%s)\n\nWorking directory: %s",
  31041. $process->getCommandLine(),
  31042. $process->getExitCode(),
  31043. $process->getExitCodeText(),
  31044. $process->getWorkingDirectory()
  31045. );
  31046. if (!$process->isOutputDisabled()) {
  31047. $error .= sprintf("\n\nOutput:\n================\n%s\n\nError Output:\n================\n%s",
  31048. $process->getOutput(),
  31049. $process->getErrorOutput()
  31050. );
  31051. }
  31052. parent::__construct($error);
  31053. $this->process = $process;
  31054. }
  31055. public function getProcess()
  31056. {
  31057. return $this->process;
  31058. }
  31059. }
  31060. <?php
  31061. namespace Symfony\Component\Process\Exception;
  31062. use Symfony\Component\Process\Process;
  31063. class ProcessTimedOutException extends RuntimeException
  31064. {
  31065. const TYPE_GENERAL = 1;
  31066. const TYPE_IDLE = 2;
  31067. private $process;
  31068. private $timeoutType;
  31069. public function __construct(Process $process, $timeoutType)
  31070. {
  31071. $this->process = $process;
  31072. $this->timeoutType = $timeoutType;
  31073. parent::__construct(sprintf(
  31074. 'The process "%s" exceeded the timeout of %s seconds.',
  31075. $process->getCommandLine(),
  31076. $this->getExceededTimeout()
  31077. ));
  31078. }
  31079. public function getProcess()
  31080. {
  31081. return $this->process;
  31082. }
  31083. public function isGeneralTimeout()
  31084. {
  31085. return self::TYPE_GENERAL === $this->timeoutType;
  31086. }
  31087. public function isIdleTimeout()
  31088. {
  31089. return self::TYPE_IDLE === $this->timeoutType;
  31090. }
  31091. public function getExceededTimeout()
  31092. {
  31093. switch ($this->timeoutType) {
  31094. case self::TYPE_GENERAL:
  31095. return $this->process->getTimeout();
  31096. case self::TYPE_IDLE:
  31097. return $this->process->getIdleTimeout();
  31098. default:
  31099. throw new \LogicException(sprintf('Unknown timeout type "%d".', $this->timeoutType));
  31100. }
  31101. }
  31102. }
  31103. <?php
  31104. namespace Symfony\Component\Process\Exception;
  31105. class RuntimeException extends \RuntimeException implements ExceptionInterface
  31106. {
  31107. }
  31108. <?php
  31109. namespace Symfony\Component\Process;
  31110. class ExecutableFinder
  31111. {
  31112. private $suffixes = array('.exe', '.bat', '.cmd', '.com');
  31113. public function setSuffixes(array $suffixes)
  31114. {
  31115. $this->suffixes = $suffixes;
  31116. }
  31117. public function addSuffix($suffix)
  31118. {
  31119. $this->suffixes[] = $suffix;
  31120. }
  31121. public function find($name, $default = null, array $extraDirs = array())
  31122. {
  31123. if (ini_get('open_basedir')) {
  31124. $searchPath = explode(PATH_SEPARATOR, ini_get('open_basedir'));
  31125. $dirs = array();
  31126. foreach ($searchPath as $path) {
  31127. if (@is_dir($path)) {
  31128. $dirs[] = $path;
  31129. } else {
  31130. if (basename($path) == $name && @is_executable($path)) {
  31131. return $path;
  31132. }
  31133. }
  31134. }
  31135. } else {
  31136. $dirs = array_merge(
  31137. explode(PATH_SEPARATOR, getenv('PATH') ?: getenv('Path')),
  31138. $extraDirs
  31139. );
  31140. }
  31141. $suffixes = array('');
  31142. if ('\\' === DIRECTORY_SEPARATOR) {
  31143. $pathExt = getenv('PATHEXT');
  31144. $suffixes = array_merge($suffixes, $pathExt ? explode(PATH_SEPARATOR, $pathExt) : $this->suffixes);
  31145. }
  31146. foreach ($suffixes as $suffix) {
  31147. foreach ($dirs as $dir) {
  31148. if (@is_file($file = $dir.DIRECTORY_SEPARATOR.$name.$suffix) && ('\\' === DIRECTORY_SEPARATOR || is_executable($file))) {
  31149. return $file;
  31150. }
  31151. }
  31152. }
  31153. return $default;
  31154. }
  31155. }
  31156. <?php
  31157. namespace Symfony\Component\Process;
  31158. use Symfony\Component\Process\Exception\RuntimeException;
  31159. class InputStream implements \IteratorAggregate
  31160. {
  31161. private $onEmpty = null;
  31162. private $input = array();
  31163. private $open = true;
  31164. public function onEmpty(callable $onEmpty = null)
  31165. {
  31166. $this->onEmpty = $onEmpty;
  31167. }
  31168. public function write($input)
  31169. {
  31170. if (null === $input) {
  31171. return;
  31172. }
  31173. if ($this->isClosed()) {
  31174. throw new RuntimeException(sprintf('%s is closed', static::class));
  31175. }
  31176. $this->input[] = ProcessUtils::validateInput(__METHOD__, $input);
  31177. }
  31178. public function close()
  31179. {
  31180. $this->open = false;
  31181. }
  31182. public function isClosed()
  31183. {
  31184. return !$this->open;
  31185. }
  31186. public function getIterator()
  31187. {
  31188. $this->open = true;
  31189. while ($this->open || $this->input) {
  31190. if (!$this->input) {
  31191. yield '';
  31192. continue;
  31193. }
  31194. $current = array_shift($this->input);
  31195. if ($current instanceof \Iterator) {
  31196. foreach ($current as $cur) {
  31197. yield $cur;
  31198. }
  31199. } else {
  31200. yield $current;
  31201. }
  31202. if (!$this->input && $this->open && null !== $onEmpty = $this->onEmpty) {
  31203. $this->write($onEmpty($this));
  31204. }
  31205. }
  31206. }
  31207. }
  31208. <?php
  31209. namespace Symfony\Component\Process;
  31210. class PhpExecutableFinder
  31211. {
  31212. private $executableFinder;
  31213. public function __construct()
  31214. {
  31215. $this->executableFinder = new ExecutableFinder();
  31216. }
  31217. public function find($includeArgs = true)
  31218. {
  31219. $args = $this->findArguments();
  31220. $args = $includeArgs && $args ? ' '.implode(' ', $args) : '';
  31221. if (defined('HHVM_VERSION')) {
  31222. return (getenv('PHP_BINARY') ?: PHP_BINARY).$args;
  31223. }
  31224. if (PHP_BINARY && in_array(PHP_SAPI, array('cli', 'cli-server', 'phpdbg')) && is_file(PHP_BINARY)) {
  31225. return PHP_BINARY.$args;
  31226. }
  31227. if ($php = getenv('PHP_PATH')) {
  31228. if (!is_executable($php)) {
  31229. return false;
  31230. }
  31231. return $php;
  31232. }
  31233. if ($php = getenv('PHP_PEAR_PHP_BIN')) {
  31234. if (is_executable($php)) {
  31235. return $php;
  31236. }
  31237. }
  31238. $dirs = array(PHP_BINDIR);
  31239. if ('\\' === DIRECTORY_SEPARATOR) {
  31240. $dirs[] = 'C:\xampp\php\\';
  31241. }
  31242. return $this->executableFinder->find('php', false, $dirs);
  31243. }
  31244. public function findArguments()
  31245. {
  31246. $arguments = array();
  31247. if (defined('HHVM_VERSION')) {
  31248. $arguments[] = '--php';
  31249. } elseif ('phpdbg' === PHP_SAPI) {
  31250. $arguments[] = '-qrr';
  31251. }
  31252. return $arguments;
  31253. }
  31254. }
  31255. <?php
  31256. namespace Symfony\Component\Process;
  31257. use Symfony\Component\Process\Exception\RuntimeException;
  31258. class PhpProcess extends Process
  31259. {
  31260. public function __construct($script, $cwd = null, array $env = null, $timeout = 60, array $options = null)
  31261. {
  31262. $executableFinder = new PhpExecutableFinder();
  31263. if (false === $php = $executableFinder->find(false)) {
  31264. $php = null;
  31265. } else {
  31266. $php = array_merge(array($php), $executableFinder->findArguments());
  31267. }
  31268. if ('phpdbg' === PHP_SAPI) {
  31269. $file = tempnam(sys_get_temp_dir(), 'dbg');
  31270. file_put_contents($file, $script);
  31271. register_shutdown_function('unlink', $file);
  31272. $php[] = $file;
  31273. $script = null;
  31274. }
  31275. if (null !== $options) {
  31276. @trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since Symfony 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
  31277. }
  31278. parent::__construct($php, $cwd, $env, $script, $timeout, $options);
  31279. }
  31280. public function setPhpBinary($php)
  31281. {
  31282. $this->setCommandLine($php);
  31283. }
  31284. public function start(callable $callback = null)
  31285. {
  31286. if (null === $this->getCommandLine()) {
  31287. throw new RuntimeException('Unable to find the PHP executable.');
  31288. }
  31289. $env = 1 < func_num_args() ? func_get_arg(1) : null;
  31290. parent::start($callback, $env);
  31291. }
  31292. }
  31293. <?php
  31294. namespace Symfony\Component\Process\Pipes;
  31295. use Symfony\Component\Process\Exception\InvalidArgumentException;
  31296. abstract class AbstractPipes implements PipesInterface
  31297. {
  31298. public $pipes = array();
  31299. private $inputBuffer = '';
  31300. private $input;
  31301. private $blocked = true;
  31302. public function __construct($input)
  31303. {
  31304. if (is_resource($input) || $input instanceof \Iterator) {
  31305. $this->input = $input;
  31306. } elseif (is_string($input)) {
  31307. $this->inputBuffer = $input;
  31308. } else {
  31309. $this->inputBuffer = (string) $input;
  31310. }
  31311. }
  31312. public function close()
  31313. {
  31314. foreach ($this->pipes as $pipe) {
  31315. fclose($pipe);
  31316. }
  31317. $this->pipes = array();
  31318. }
  31319. protected function hasSystemCallBeenInterrupted()
  31320. {
  31321. $lastError = error_get_last();
  31322. return isset($lastError['message']) && false !== stripos($lastError['message'], 'interrupted system call');
  31323. }
  31324. protected function unblock()
  31325. {
  31326. if (!$this->blocked) {
  31327. return;
  31328. }
  31329. foreach ($this->pipes as $pipe) {
  31330. stream_set_blocking($pipe, 0);
  31331. }
  31332. if (is_resource($this->input)) {
  31333. stream_set_blocking($this->input, 0);
  31334. }
  31335. $this->blocked = false;
  31336. }
  31337. protected function write()
  31338. {
  31339. if (!isset($this->pipes[0])) {
  31340. return;
  31341. }
  31342. $input = $this->input;
  31343. if ($input instanceof \Iterator) {
  31344. if (!$input->valid()) {
  31345. $input = null;
  31346. } elseif (is_resource($input = $input->current())) {
  31347. stream_set_blocking($input, 0);
  31348. } elseif (!isset($this->inputBuffer[0])) {
  31349. if (!is_string($input)) {
  31350. if (!is_scalar($input)) {
  31351. throw new InvalidArgumentException(sprintf('%s yielded a value of type "%s", but only scalars and stream resources are supported', get_class($this->input), gettype($input)));
  31352. }
  31353. $input = (string) $input;
  31354. }
  31355. $this->inputBuffer = $input;
  31356. $this->input->next();
  31357. $input = null;
  31358. } else {
  31359. $input = null;
  31360. }
  31361. }
  31362. $r = $e = array();
  31363. $w = array($this->pipes[0]);
  31364. if (false === @stream_select($r, $w, $e, 0, 0)) {
  31365. return;
  31366. }
  31367. foreach ($w as $stdin) {
  31368. if (isset($this->inputBuffer[0])) {
  31369. $written = fwrite($stdin, $this->inputBuffer);
  31370. $this->inputBuffer = substr($this->inputBuffer, $written);
  31371. if (isset($this->inputBuffer[0])) {
  31372. return array($this->pipes[0]);
  31373. }
  31374. }
  31375. if ($input) {
  31376. for (;;) {
  31377. $data = fread($input, self::CHUNK_SIZE);
  31378. if (!isset($data[0])) {
  31379. break;
  31380. }
  31381. $written = fwrite($stdin, $data);
  31382. $data = substr($data, $written);
  31383. if (isset($data[0])) {
  31384. $this->inputBuffer = $data;
  31385. return array($this->pipes[0]);
  31386. }
  31387. }
  31388. if (feof($input)) {
  31389. if ($this->input instanceof \Iterator) {
  31390. $this->input->next();
  31391. } else {
  31392. $this->input = null;
  31393. }
  31394. }
  31395. }
  31396. }
  31397. if (!isset($this->inputBuffer[0]) && !($this->input instanceof \Iterator ? $this->input->valid() : $this->input)) {
  31398. $this->input = null;
  31399. fclose($this->pipes[0]);
  31400. unset($this->pipes[0]);
  31401. } elseif (!$w) {
  31402. return array($this->pipes[0]);
  31403. }
  31404. }
  31405. }
  31406. <?php
  31407. namespace Symfony\Component\Process\Pipes;
  31408. interface PipesInterface
  31409. {
  31410. const CHUNK_SIZE = 16384;
  31411. public function getDescriptors();
  31412. public function getFiles();
  31413. public function readAndWrite($blocking, $close = false);
  31414. public function areOpen();
  31415. public function haveReadSupport();
  31416. public function close();
  31417. }
  31418. <?php
  31419. namespace Symfony\Component\Process\Pipes;
  31420. use Symfony\Component\Process\Process;
  31421. class UnixPipes extends AbstractPipes
  31422. {
  31423. private $ttyMode;
  31424. private $ptyMode;
  31425. private $haveReadSupport;
  31426. public function __construct($ttyMode, $ptyMode, $input, $haveReadSupport)
  31427. {
  31428. $this->ttyMode = (bool) $ttyMode;
  31429. $this->ptyMode = (bool) $ptyMode;
  31430. $this->haveReadSupport = (bool) $haveReadSupport;
  31431. parent::__construct($input);
  31432. }
  31433. public function __destruct()
  31434. {
  31435. $this->close();
  31436. }
  31437. public function getDescriptors()
  31438. {
  31439. if (!$this->haveReadSupport) {
  31440. $nullstream = fopen('/dev/null', 'c');
  31441. return array(
  31442. array('pipe', 'r'),
  31443. $nullstream,
  31444. $nullstream,
  31445. );
  31446. }
  31447. if ($this->ttyMode) {
  31448. return array(
  31449. array('file', '/dev/tty', 'r'),
  31450. array('file', '/dev/tty', 'w'),
  31451. array('file', '/dev/tty', 'w'),
  31452. );
  31453. }
  31454. if ($this->ptyMode && Process::isPtySupported()) {
  31455. return array(
  31456. array('pty'),
  31457. array('pty'),
  31458. array('pty'),
  31459. );
  31460. }
  31461. return array(
  31462. array('pipe', 'r'),
  31463. array('pipe', 'w'),
  31464. array('pipe', 'w'),
  31465. );
  31466. }
  31467. public function getFiles()
  31468. {
  31469. return array();
  31470. }
  31471. public function readAndWrite($blocking, $close = false)
  31472. {
  31473. $this->unblock();
  31474. $w = $this->write();
  31475. $read = $e = array();
  31476. $r = $this->pipes;
  31477. unset($r[0]);
  31478. if (($r || $w) && false === @stream_select($r, $w, $e, 0, $blocking ? Process::TIMEOUT_PRECISION * 1E6 : 0)) {
  31479. if (!$this->hasSystemCallBeenInterrupted()) {
  31480. $this->pipes = array();
  31481. }
  31482. return $read;
  31483. }
  31484. foreach ($r as $pipe) {
  31485. $read[$type = array_search($pipe, $this->pipes, true)] = '';
  31486. do {
  31487. $data = fread($pipe, self::CHUNK_SIZE);
  31488. $read[$type] .= $data;
  31489. } while (isset($data[0]) && ($close || isset($data[self::CHUNK_SIZE - 1])));
  31490. if (!isset($read[$type][0])) {
  31491. unset($read[$type]);
  31492. }
  31493. if ($close && feof($pipe)) {
  31494. fclose($pipe);
  31495. unset($this->pipes[$type]);
  31496. }
  31497. }
  31498. return $read;
  31499. }
  31500. public function haveReadSupport()
  31501. {
  31502. return $this->haveReadSupport;
  31503. }
  31504. public function areOpen()
  31505. {
  31506. return (bool) $this->pipes;
  31507. }
  31508. }
  31509. <?php
  31510. namespace Symfony\Component\Process\Pipes;
  31511. use Symfony\Component\Process\Process;
  31512. use Symfony\Component\Process\Exception\RuntimeException;
  31513. class WindowsPipes extends AbstractPipes
  31514. {
  31515. private $files = array();
  31516. private $fileHandles = array();
  31517. private $readBytes = array(
  31518. Process::STDOUT => 0,
  31519. Process::STDERR => 0,
  31520. );
  31521. private $haveReadSupport;
  31522. public function __construct($input, $haveReadSupport)
  31523. {
  31524. $this->haveReadSupport = (bool) $haveReadSupport;
  31525. if ($this->haveReadSupport) {
  31526. $pipes = array(
  31527. Process::STDOUT => Process::OUT,
  31528. Process::STDERR => Process::ERR,
  31529. );
  31530. $tmpCheck = false;
  31531. $tmpDir = sys_get_temp_dir();
  31532. $lastError = 'unknown reason';
  31533. set_error_handler(function ($type, $msg) use (&$lastError) { $lastError = $msg; });
  31534. for ($i = 0;; ++$i) {
  31535. foreach ($pipes as $pipe => $name) {
  31536. $file = sprintf('%s\\sf_proc_%02X.%s', $tmpDir, $i, $name);
  31537. if (file_exists($file) && !unlink($file)) {
  31538. continue 2;
  31539. }
  31540. $h = fopen($file, 'xb');
  31541. if (!$h) {
  31542. $error = $lastError;
  31543. if ($tmpCheck || $tmpCheck = unlink(tempnam(false, 'sf_check_'))) {
  31544. continue;
  31545. }
  31546. restore_error_handler();
  31547. throw new RuntimeException(sprintf('A temporary file could not be opened to write the process output: %s', $error));
  31548. }
  31549. if (!$h || !$this->fileHandles[$pipe] = fopen($file, 'rb')) {
  31550. continue 2;
  31551. }
  31552. if (isset($this->files[$pipe])) {
  31553. unlink($this->files[$pipe]);
  31554. }
  31555. $this->files[$pipe] = $file;
  31556. }
  31557. break;
  31558. }
  31559. restore_error_handler();
  31560. }
  31561. parent::__construct($input);
  31562. }
  31563. public function __destruct()
  31564. {
  31565. $this->close();
  31566. $this->removeFiles();
  31567. }
  31568. public function getDescriptors()
  31569. {
  31570. if (!$this->haveReadSupport) {
  31571. $nullstream = fopen('NUL', 'c');
  31572. return array(
  31573. array('pipe', 'r'),
  31574. $nullstream,
  31575. $nullstream,
  31576. );
  31577. }
  31578. return array(
  31579. array('pipe', 'r'),
  31580. array('file', 'NUL', 'w'),
  31581. array('file', 'NUL', 'w'),
  31582. );
  31583. }
  31584. public function getFiles()
  31585. {
  31586. return $this->files;
  31587. }
  31588. public function readAndWrite($blocking, $close = false)
  31589. {
  31590. $this->unblock();
  31591. $w = $this->write();
  31592. $read = $r = $e = array();
  31593. if ($blocking) {
  31594. if ($w) {
  31595. @stream_select($r, $w, $e, 0, Process::TIMEOUT_PRECISION * 1E6);
  31596. } elseif ($this->fileHandles) {
  31597. usleep(Process::TIMEOUT_PRECISION * 1E6);
  31598. }
  31599. }
  31600. foreach ($this->fileHandles as $type => $fileHandle) {
  31601. $data = stream_get_contents($fileHandle, -1, $this->readBytes[$type]);
  31602. if (isset($data[0])) {
  31603. $this->readBytes[$type] += strlen($data);
  31604. $read[$type] = $data;
  31605. }
  31606. if ($close) {
  31607. fclose($fileHandle);
  31608. unset($this->fileHandles[$type]);
  31609. }
  31610. }
  31611. return $read;
  31612. }
  31613. public function haveReadSupport()
  31614. {
  31615. return $this->haveReadSupport;
  31616. }
  31617. public function areOpen()
  31618. {
  31619. return $this->pipes && $this->fileHandles;
  31620. }
  31621. public function close()
  31622. {
  31623. parent::close();
  31624. foreach ($this->fileHandles as $handle) {
  31625. fclose($handle);
  31626. }
  31627. $this->fileHandles = array();
  31628. }
  31629. private function removeFiles()
  31630. {
  31631. foreach ($this->files as $filename) {
  31632. if (file_exists($filename)) {
  31633. @unlink($filename);
  31634. }
  31635. }
  31636. $this->files = array();
  31637. }
  31638. }
  31639. <?php
  31640. namespace Symfony\Component\Process;
  31641. use Symfony\Component\Process\Exception\InvalidArgumentException;
  31642. use Symfony\Component\Process\Exception\LogicException;
  31643. use Symfony\Component\Process\Exception\ProcessFailedException;
  31644. use Symfony\Component\Process\Exception\ProcessTimedOutException;
  31645. use Symfony\Component\Process\Exception\RuntimeException;
  31646. use Symfony\Component\Process\Pipes\PipesInterface;
  31647. use Symfony\Component\Process\Pipes\UnixPipes;
  31648. use Symfony\Component\Process\Pipes\WindowsPipes;
  31649. class Process implements \IteratorAggregate
  31650. {
  31651. const ERR = 'err';
  31652. const OUT = 'out';
  31653. const STATUS_READY = 'ready';
  31654. const STATUS_STARTED = 'started';
  31655. const STATUS_TERMINATED = 'terminated';
  31656. const STDIN = 0;
  31657. const STDOUT = 1;
  31658. const STDERR = 2;
  31659. const TIMEOUT_PRECISION = 0.2;
  31660. const ITER_NON_BLOCKING = 1;
  31661. const ITER_KEEP_OUTPUT = 2;
  31662. const ITER_SKIP_OUT = 4;
  31663. const ITER_SKIP_ERR = 8;
  31664. private $callback;
  31665. private $hasCallback = false;
  31666. private $commandline;
  31667. private $cwd;
  31668. private $env;
  31669. private $input;
  31670. private $starttime;
  31671. private $lastOutputTime;
  31672. private $timeout;
  31673. private $idleTimeout;
  31674. private $options = array('suppress_errors' => true);
  31675. private $exitcode;
  31676. private $fallbackStatus = array();
  31677. private $processInformation;
  31678. private $outputDisabled = false;
  31679. private $stdout;
  31680. private $stderr;
  31681. private $enhanceWindowsCompatibility = true;
  31682. private $enhanceSigchildCompatibility;
  31683. private $process;
  31684. private $status = self::STATUS_READY;
  31685. private $incrementalOutputOffset = 0;
  31686. private $incrementalErrorOutputOffset = 0;
  31687. private $tty;
  31688. private $pty;
  31689. private $inheritEnv = false;
  31690. private $useFileHandles = false;
  31691. private $processPipes;
  31692. private $latestSignal;
  31693. private static $sigchild;
  31694. public static $exitCodes = array(
  31695. 0 => 'OK',
  31696. 1 => 'General error',
  31697. 2 => 'Misuse of shell builtins',
  31698. 126 => 'Invoked command cannot execute',
  31699. 127 => 'Command not found',
  31700. 128 => 'Invalid exit argument',
  31701. 129 => 'Hangup',
  31702. 130 => 'Interrupt',
  31703. 131 => 'Quit and dump core',
  31704. 132 => 'Illegal instruction',
  31705. 133 => 'Trace/breakpoint trap',
  31706. 134 => 'Process aborted',
  31707. 135 => 'Bus error: "access to undefined portion of memory object"',
  31708. 136 => 'Floating point exception: "erroneous arithmetic operation"',
  31709. 137 => 'Kill (terminate immediately)',
  31710. 138 => 'User-defined 1',
  31711. 139 => 'Segmentation violation',
  31712. 140 => 'User-defined 2',
  31713. 141 => 'Write to pipe with no one reading',
  31714. 142 => 'Signal raised by alarm',
  31715. 143 => 'Termination (request to terminate)',
  31716. 145 => 'Child process terminated, stopped (or continued*)',
  31717. 146 => 'Continue if stopped',
  31718. 147 => 'Stop executing temporarily',
  31719. 148 => 'Terminal stop signal',
  31720. 149 => 'Background process attempting to read from tty ("in")',
  31721. 150 => 'Background process attempting to write to tty ("out")',
  31722. 151 => 'Urgent data available on socket',
  31723. 152 => 'CPU time limit exceeded',
  31724. 153 => 'File size limit exceeded',
  31725. 154 => 'Signal raised by timer counting virtual time: "virtual timer expired"',
  31726. 155 => 'Profiling timer expired',
  31727. 157 => 'Pollable event',
  31728. 159 => 'Bad syscall',
  31729. );
  31730. public function __construct($commandline, $cwd = null, array $env = null, $input = null, $timeout = 60, array $options = null)
  31731. {
  31732. if (!function_exists('proc_open')) {
  31733. throw new RuntimeException('The Process class relies on proc_open, which is not available on your PHP installation.');
  31734. }
  31735. $this->commandline = $commandline;
  31736. $this->cwd = $cwd;
  31737. if (null === $this->cwd && (defined('ZEND_THREAD_SAFE') || '\\' === DIRECTORY_SEPARATOR)) {
  31738. $this->cwd = getcwd();
  31739. }
  31740. if (null !== $env) {
  31741. $this->setEnv($env);
  31742. }
  31743. $this->setInput($input);
  31744. $this->setTimeout($timeout);
  31745. $this->useFileHandles = '\\' === DIRECTORY_SEPARATOR;
  31746. $this->pty = false;
  31747. $this->enhanceSigchildCompatibility = '\\' !== DIRECTORY_SEPARATOR && $this->isSigchildEnabled();
  31748. if (null !== $options) {
  31749. @trigger_error(sprintf('The $options parameter of the %s constructor is deprecated since Symfony 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
  31750. $this->options = array_replace($this->options, $options);
  31751. }
  31752. }
  31753. public function __destruct()
  31754. {
  31755. $this->stop(0);
  31756. }
  31757. public function __clone()
  31758. {
  31759. $this->resetProcessData();
  31760. }
  31761. public function run($callback = null)
  31762. {
  31763. $env = 1 < func_num_args() ? func_get_arg(1) : null;
  31764. $this->start($callback, $env);
  31765. return $this->wait();
  31766. }
  31767. public function mustRun(callable $callback = null)
  31768. {
  31769. if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  31770. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
  31771. }
  31772. $env = 1 < func_num_args() ? func_get_arg(1) : null;
  31773. if (0 !== $this->run($callback, $env)) {
  31774. throw new ProcessFailedException($this);
  31775. }
  31776. return $this;
  31777. }
  31778. public function start(callable $callback = null)
  31779. {
  31780. if ($this->isRunning()) {
  31781. throw new RuntimeException('Process is already running');
  31782. }
  31783. if (2 <= func_num_args()) {
  31784. $env = func_get_arg(1);
  31785. } else {
  31786. if (__CLASS__ !== static::class) {
  31787. $r = new \ReflectionMethod($this, __FUNCTION__);
  31788. if (__CLASS__ !== $r->getDeclaringClass()->getName() && (2 > $r->getNumberOfParameters() || 'env' !== $r->getParameters()[0]->name)) {
  31789. @trigger_error(sprintf('The %s::start() method expects a second "$env" argument since Symfony 3.3. It will be made mandatory in 4.0.', static::class), E_USER_DEPRECATED);
  31790. }
  31791. }
  31792. $env = null;
  31793. }
  31794. $this->resetProcessData();
  31795. $this->starttime = $this->lastOutputTime = microtime(true);
  31796. $this->callback = $this->buildCallback($callback);
  31797. $this->hasCallback = null !== $callback;
  31798. $descriptors = $this->getDescriptors();
  31799. $inheritEnv = $this->inheritEnv;
  31800. if (is_array($commandline = $this->commandline)) {
  31801. $commandline = implode(' ', array_map(array($this, 'escapeArgument'), $commandline));
  31802. if ('\\' !== DIRECTORY_SEPARATOR) {
  31803. $commandline = 'exec '.$commandline;
  31804. }
  31805. }
  31806. if (null === $env) {
  31807. $env = $this->env;
  31808. } else {
  31809. if ($this->env) {
  31810. $env += $this->env;
  31811. }
  31812. $inheritEnv = true;
  31813. }
  31814. if (null !== $env && $inheritEnv) {
  31815. $env += $this->getDefaultEnv();
  31816. } elseif (null !== $env) {
  31817. @trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
  31818. } else {
  31819. $env = $this->getDefaultEnv();
  31820. }
  31821. if ('\\' === DIRECTORY_SEPARATOR && $this->enhanceWindowsCompatibility) {
  31822. $this->options['bypass_shell'] = true;
  31823. $commandline = $this->prepareWindowsCommandLine($commandline, $env);
  31824. } elseif (!$this->useFileHandles && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  31825. $descriptors[3] = array('pipe', 'w');
  31826. $commandline = '{ ('.$commandline.') <&3 3<&- 3>/dev/null & } 3<&0;';
  31827. $commandline .= 'pid=$!; echo $pid >&3; wait $pid; code=$?; echo $code >&3; exit $code';
  31828. $ptsWorkaround = fopen(__FILE__, 'r');
  31829. }
  31830. if (defined('HHVM_VERSION')) {
  31831. $envPairs = $env;
  31832. } else {
  31833. $envPairs = array();
  31834. foreach ($env as $k => $v) {
  31835. $envPairs[] = $k.'='.$v;
  31836. }
  31837. }
  31838. if (!is_dir($this->cwd)) {
  31839. @trigger_error('The provided cwd does not exist. Command is currently ran against getcwd(). This behavior is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
  31840. }
  31841. $this->process = proc_open($commandline, $descriptors, $this->processPipes->pipes, $this->cwd, $envPairs, $this->options);
  31842. if (!is_resource($this->process)) {
  31843. throw new RuntimeException('Unable to launch a new process.');
  31844. }
  31845. $this->status = self::STATUS_STARTED;
  31846. if (isset($descriptors[3])) {
  31847. $this->fallbackStatus['pid'] = (int) fgets($this->processPipes->pipes[3]);
  31848. }
  31849. if ($this->tty) {
  31850. return;
  31851. }
  31852. $this->updateStatus(false);
  31853. $this->checkTimeout();
  31854. }
  31855. public function restart(callable $callback = null)
  31856. {
  31857. if ($this->isRunning()) {
  31858. throw new RuntimeException('Process is already running');
  31859. }
  31860. $env = 1 < func_num_args() ? func_get_arg(1) : null;
  31861. $process = clone $this;
  31862. $process->start($callback, $env);
  31863. return $process;
  31864. }
  31865. public function wait(callable $callback = null)
  31866. {
  31867. $this->requireProcessIsStarted(__FUNCTION__);
  31868. $this->updateStatus(false);
  31869. if (null !== $callback) {
  31870. if (!$this->processPipes->haveReadSupport()) {
  31871. $this->stop(0);
  31872. throw new \LogicException('Pass the callback to the Process::start method or enableOutput to use a callback with Process::wait');
  31873. }
  31874. $this->callback = $this->buildCallback($callback);
  31875. }
  31876. do {
  31877. $this->checkTimeout();
  31878. $running = '\\' === DIRECTORY_SEPARATOR ? $this->isRunning() : $this->processPipes->areOpen();
  31879. $this->readPipes($running, '\\' !== DIRECTORY_SEPARATOR || !$running);
  31880. } while ($running);
  31881. while ($this->isRunning()) {
  31882. usleep(1000);
  31883. }
  31884. if ($this->processInformation['signaled'] && $this->processInformation['termsig'] !== $this->latestSignal) {
  31885. throw new RuntimeException(sprintf('The process has been signaled with signal "%s".', $this->processInformation['termsig']));
  31886. }
  31887. return $this->exitcode;
  31888. }
  31889. public function getPid()
  31890. {
  31891. return $this->isRunning() ? $this->processInformation['pid'] : null;
  31892. }
  31893. public function signal($signal)
  31894. {
  31895. $this->doSignal($signal, true);
  31896. return $this;
  31897. }
  31898. public function disableOutput()
  31899. {
  31900. if ($this->isRunning()) {
  31901. throw new RuntimeException('Disabling output while the process is running is not possible.');
  31902. }
  31903. if (null !== $this->idleTimeout) {
  31904. throw new LogicException('Output can not be disabled while an idle timeout is set.');
  31905. }
  31906. $this->outputDisabled = true;
  31907. return $this;
  31908. }
  31909. public function enableOutput()
  31910. {
  31911. if ($this->isRunning()) {
  31912. throw new RuntimeException('Enabling output while the process is running is not possible.');
  31913. }
  31914. $this->outputDisabled = false;
  31915. return $this;
  31916. }
  31917. public function isOutputDisabled()
  31918. {
  31919. return $this->outputDisabled;
  31920. }
  31921. public function getOutput()
  31922. {
  31923. $this->readPipesForOutput(__FUNCTION__);
  31924. if (false === $ret = stream_get_contents($this->stdout, -1, 0)) {
  31925. return '';
  31926. }
  31927. return $ret;
  31928. }
  31929. public function getIncrementalOutput()
  31930. {
  31931. $this->readPipesForOutput(__FUNCTION__);
  31932. $latest = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
  31933. $this->incrementalOutputOffset = ftell($this->stdout);
  31934. if (false === $latest) {
  31935. return '';
  31936. }
  31937. return $latest;
  31938. }
  31939. public function getIterator($flags = 0)
  31940. {
  31941. $this->readPipesForOutput(__FUNCTION__, false);
  31942. $clearOutput = !(self::ITER_KEEP_OUTPUT & $flags);
  31943. $blocking = !(self::ITER_NON_BLOCKING & $flags);
  31944. $yieldOut = !(self::ITER_SKIP_OUT & $flags);
  31945. $yieldErr = !(self::ITER_SKIP_ERR & $flags);
  31946. while (null !== $this->callback || ($yieldOut && !feof($this->stdout)) || ($yieldErr && !feof($this->stderr))) {
  31947. if ($yieldOut) {
  31948. $out = stream_get_contents($this->stdout, -1, $this->incrementalOutputOffset);
  31949. if (isset($out[0])) {
  31950. if ($clearOutput) {
  31951. $this->clearOutput();
  31952. } else {
  31953. $this->incrementalOutputOffset = ftell($this->stdout);
  31954. }
  31955. yield self::OUT => $out;
  31956. }
  31957. }
  31958. if ($yieldErr) {
  31959. $err = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
  31960. if (isset($err[0])) {
  31961. if ($clearOutput) {
  31962. $this->clearErrorOutput();
  31963. } else {
  31964. $this->incrementalErrorOutputOffset = ftell($this->stderr);
  31965. }
  31966. yield self::ERR => $err;
  31967. }
  31968. }
  31969. if (!$blocking && !isset($out[0]) && !isset($err[0])) {
  31970. yield self::OUT => '';
  31971. }
  31972. $this->checkTimeout();
  31973. $this->readPipesForOutput(__FUNCTION__, $blocking);
  31974. }
  31975. }
  31976. public function clearOutput()
  31977. {
  31978. ftruncate($this->stdout, 0);
  31979. fseek($this->stdout, 0);
  31980. $this->incrementalOutputOffset = 0;
  31981. return $this;
  31982. }
  31983. public function getErrorOutput()
  31984. {
  31985. $this->readPipesForOutput(__FUNCTION__);
  31986. if (false === $ret = stream_get_contents($this->stderr, -1, 0)) {
  31987. return '';
  31988. }
  31989. return $ret;
  31990. }
  31991. public function getIncrementalErrorOutput()
  31992. {
  31993. $this->readPipesForOutput(__FUNCTION__);
  31994. $latest = stream_get_contents($this->stderr, -1, $this->incrementalErrorOutputOffset);
  31995. $this->incrementalErrorOutputOffset = ftell($this->stderr);
  31996. if (false === $latest) {
  31997. return '';
  31998. }
  31999. return $latest;
  32000. }
  32001. public function clearErrorOutput()
  32002. {
  32003. ftruncate($this->stderr, 0);
  32004. fseek($this->stderr, 0);
  32005. $this->incrementalErrorOutputOffset = 0;
  32006. return $this;
  32007. }
  32008. public function getExitCode()
  32009. {
  32010. if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  32011. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. You must use setEnhanceSigchildCompatibility() to use this method.');
  32012. }
  32013. $this->updateStatus(false);
  32014. return $this->exitcode;
  32015. }
  32016. public function getExitCodeText()
  32017. {
  32018. if (null === $exitcode = $this->getExitCode()) {
  32019. return;
  32020. }
  32021. return isset(self::$exitCodes[$exitcode]) ? self::$exitCodes[$exitcode] : 'Unknown error';
  32022. }
  32023. public function isSuccessful()
  32024. {
  32025. return 0 === $this->getExitCode();
  32026. }
  32027. public function hasBeenSignaled()
  32028. {
  32029. $this->requireProcessIsTerminated(__FUNCTION__);
  32030. if (!$this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  32031. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
  32032. }
  32033. return $this->processInformation['signaled'];
  32034. }
  32035. public function getTermSignal()
  32036. {
  32037. $this->requireProcessIsTerminated(__FUNCTION__);
  32038. if ($this->isSigchildEnabled() && (!$this->enhanceSigchildCompatibility || -1 === $this->processInformation['termsig'])) {
  32039. throw new RuntimeException('This PHP has been compiled with --enable-sigchild. Term signal can not be retrieved.');
  32040. }
  32041. return $this->processInformation['termsig'];
  32042. }
  32043. public function hasBeenStopped()
  32044. {
  32045. $this->requireProcessIsTerminated(__FUNCTION__);
  32046. return $this->processInformation['stopped'];
  32047. }
  32048. public function getStopSignal()
  32049. {
  32050. $this->requireProcessIsTerminated(__FUNCTION__);
  32051. return $this->processInformation['stopsig'];
  32052. }
  32053. public function isRunning()
  32054. {
  32055. if (self::STATUS_STARTED !== $this->status) {
  32056. return false;
  32057. }
  32058. $this->updateStatus(false);
  32059. return $this->processInformation['running'];
  32060. }
  32061. public function isStarted()
  32062. {
  32063. return self::STATUS_READY != $this->status;
  32064. }
  32065. public function isTerminated()
  32066. {
  32067. $this->updateStatus(false);
  32068. return self::STATUS_TERMINATED == $this->status;
  32069. }
  32070. public function getStatus()
  32071. {
  32072. $this->updateStatus(false);
  32073. return $this->status;
  32074. }
  32075. public function stop($timeout = 10, $signal = null)
  32076. {
  32077. $timeoutMicro = microtime(true) + $timeout;
  32078. if ($this->isRunning()) {
  32079. $this->doSignal(15, false);
  32080. do {
  32081. usleep(1000);
  32082. } while ($this->isRunning() && microtime(true) < $timeoutMicro);
  32083. if ($this->isRunning()) {
  32084. $this->doSignal($signal ?: 9, false);
  32085. }
  32086. }
  32087. if ($this->isRunning()) {
  32088. if (isset($this->fallbackStatus['pid'])) {
  32089. unset($this->fallbackStatus['pid']);
  32090. return $this->stop(0, $signal);
  32091. }
  32092. $this->close();
  32093. }
  32094. return $this->exitcode;
  32095. }
  32096. public function addOutput($line)
  32097. {
  32098. $this->lastOutputTime = microtime(true);
  32099. fseek($this->stdout, 0, SEEK_END);
  32100. fwrite($this->stdout, $line);
  32101. fseek($this->stdout, $this->incrementalOutputOffset);
  32102. }
  32103. public function addErrorOutput($line)
  32104. {
  32105. $this->lastOutputTime = microtime(true);
  32106. fseek($this->stderr, 0, SEEK_END);
  32107. fwrite($this->stderr, $line);
  32108. fseek($this->stderr, $this->incrementalErrorOutputOffset);
  32109. }
  32110. public function getCommandLine()
  32111. {
  32112. return is_array($this->commandline) ? implode(' ', array_map(array($this, 'escapeArgument'), $this->commandline)) : $this->commandline;
  32113. }
  32114. public function setCommandLine($commandline)
  32115. {
  32116. $this->commandline = $commandline;
  32117. return $this;
  32118. }
  32119. public function getTimeout()
  32120. {
  32121. return $this->timeout;
  32122. }
  32123. public function getIdleTimeout()
  32124. {
  32125. return $this->idleTimeout;
  32126. }
  32127. public function setTimeout($timeout)
  32128. {
  32129. $this->timeout = $this->validateTimeout($timeout);
  32130. return $this;
  32131. }
  32132. public function setIdleTimeout($timeout)
  32133. {
  32134. if (null !== $timeout && $this->outputDisabled) {
  32135. throw new LogicException('Idle timeout can not be set while the output is disabled.');
  32136. }
  32137. $this->idleTimeout = $this->validateTimeout($timeout);
  32138. return $this;
  32139. }
  32140. public function setTty($tty)
  32141. {
  32142. if ('\\' === DIRECTORY_SEPARATOR && $tty) {
  32143. throw new RuntimeException('TTY mode is not supported on Windows platform.');
  32144. }
  32145. if ($tty) {
  32146. static $isTtySupported;
  32147. if (null === $isTtySupported) {
  32148. $isTtySupported = (bool) @proc_open('echo 1 >/dev/null', array(array('file', '/dev/tty', 'r'), array('file', '/dev/tty', 'w'), array('file', '/dev/tty', 'w')), $pipes);
  32149. }
  32150. if (!$isTtySupported) {
  32151. throw new RuntimeException('TTY mode requires /dev/tty to be read/writable.');
  32152. }
  32153. }
  32154. $this->tty = (bool) $tty;
  32155. return $this;
  32156. }
  32157. public function isTty()
  32158. {
  32159. return $this->tty;
  32160. }
  32161. public function setPty($bool)
  32162. {
  32163. $this->pty = (bool) $bool;
  32164. return $this;
  32165. }
  32166. public function isPty()
  32167. {
  32168. return $this->pty;
  32169. }
  32170. public function getWorkingDirectory()
  32171. {
  32172. if (null === $this->cwd) {
  32173. return getcwd() ?: null;
  32174. }
  32175. return $this->cwd;
  32176. }
  32177. public function setWorkingDirectory($cwd)
  32178. {
  32179. $this->cwd = $cwd;
  32180. return $this;
  32181. }
  32182. public function getEnv()
  32183. {
  32184. return $this->env;
  32185. }
  32186. public function setEnv(array $env)
  32187. {
  32188. $env = array_filter($env, function ($value) {
  32189. return !is_array($value);
  32190. });
  32191. $this->env = $env;
  32192. return $this;
  32193. }
  32194. public function getInput()
  32195. {
  32196. return $this->input;
  32197. }
  32198. public function setInput($input)
  32199. {
  32200. if ($this->isRunning()) {
  32201. throw new LogicException('Input can not be set while the process is running.');
  32202. }
  32203. $this->input = ProcessUtils::validateInput(__METHOD__, $input);
  32204. return $this;
  32205. }
  32206. public function getOptions()
  32207. {
  32208. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
  32209. return $this->options;
  32210. }
  32211. public function setOptions(array $options)
  32212. {
  32213. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
  32214. $this->options = $options;
  32215. return $this;
  32216. }
  32217. public function getEnhanceWindowsCompatibility()
  32218. {
  32219. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
  32220. return $this->enhanceWindowsCompatibility;
  32221. }
  32222. public function setEnhanceWindowsCompatibility($enhance)
  32223. {
  32224. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Enhanced Windows compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
  32225. $this->enhanceWindowsCompatibility = (bool) $enhance;
  32226. return $this;
  32227. }
  32228. public function getEnhanceSigchildCompatibility()
  32229. {
  32230. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
  32231. return $this->enhanceSigchildCompatibility;
  32232. }
  32233. public function setEnhanceSigchildCompatibility($enhance)
  32234. {
  32235. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Sigchild compatibility will always be enabled.', __METHOD__), E_USER_DEPRECATED);
  32236. $this->enhanceSigchildCompatibility = (bool) $enhance;
  32237. return $this;
  32238. }
  32239. public function inheritEnvironmentVariables($inheritEnv = true)
  32240. {
  32241. if (!$inheritEnv) {
  32242. @trigger_error('Not inheriting environment variables is deprecated since Symfony 3.3 and will always happen in 4.0. Set "Process::inheritEnvironmentVariables()" to true instead.', E_USER_DEPRECATED);
  32243. }
  32244. $this->inheritEnv = (bool) $inheritEnv;
  32245. return $this;
  32246. }
  32247. public function areEnvironmentVariablesInherited()
  32248. {
  32249. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.3 and will be removed in 4.0. Environment variables will always be inherited.', __METHOD__), E_USER_DEPRECATED);
  32250. return $this->inheritEnv;
  32251. }
  32252. public function checkTimeout()
  32253. {
  32254. if (self::STATUS_STARTED !== $this->status) {
  32255. return;
  32256. }
  32257. if (null !== $this->timeout && $this->timeout < microtime(true) - $this->starttime) {
  32258. $this->stop(0);
  32259. throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_GENERAL);
  32260. }
  32261. if (null !== $this->idleTimeout && $this->idleTimeout < microtime(true) - $this->lastOutputTime) {
  32262. $this->stop(0);
  32263. throw new ProcessTimedOutException($this, ProcessTimedOutException::TYPE_IDLE);
  32264. }
  32265. }
  32266. public static function isPtySupported()
  32267. {
  32268. static $result;
  32269. if (null !== $result) {
  32270. return $result;
  32271. }
  32272. if ('\\' === DIRECTORY_SEPARATOR) {
  32273. return $result = false;
  32274. }
  32275. return $result = (bool) @proc_open('echo 1 >/dev/null', array(array('pty'), array('pty'), array('pty')), $pipes);
  32276. }
  32277. private function getDescriptors()
  32278. {
  32279. if ($this->input instanceof \Iterator) {
  32280. $this->input->rewind();
  32281. }
  32282. if ('\\' === DIRECTORY_SEPARATOR) {
  32283. $this->processPipes = new WindowsPipes($this->input, !$this->outputDisabled || $this->hasCallback);
  32284. } else {
  32285. $this->processPipes = new UnixPipes($this->isTty(), $this->isPty(), $this->input, !$this->outputDisabled || $this->hasCallback);
  32286. }
  32287. return $this->processPipes->getDescriptors();
  32288. }
  32289. protected function buildCallback(callable $callback = null)
  32290. {
  32291. if ($this->outputDisabled) {
  32292. return function ($type, $data) use ($callback) {
  32293. if (null !== $callback) {
  32294. call_user_func($callback, $type, $data);
  32295. }
  32296. };
  32297. }
  32298. $out = self::OUT;
  32299. return function ($type, $data) use ($callback, $out) {
  32300. if ($out == $type) {
  32301. $this->addOutput($data);
  32302. } else {
  32303. $this->addErrorOutput($data);
  32304. }
  32305. if (null !== $callback) {
  32306. call_user_func($callback, $type, $data);
  32307. }
  32308. };
  32309. }
  32310. protected function updateStatus($blocking)
  32311. {
  32312. if (self::STATUS_STARTED !== $this->status) {
  32313. return;
  32314. }
  32315. $this->processInformation = proc_get_status($this->process);
  32316. $running = $this->processInformation['running'];
  32317. $this->readPipes($running && $blocking, '\\' !== DIRECTORY_SEPARATOR || !$running);
  32318. if ($this->fallbackStatus && $this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  32319. $this->processInformation = $this->fallbackStatus + $this->processInformation;
  32320. }
  32321. if (!$running) {
  32322. $this->close();
  32323. }
  32324. }
  32325. protected function isSigchildEnabled()
  32326. {
  32327. if (null !== self::$sigchild) {
  32328. return self::$sigchild;
  32329. }
  32330. if (!function_exists('phpinfo') || defined('HHVM_VERSION')) {
  32331. return self::$sigchild = false;
  32332. }
  32333. ob_start();
  32334. phpinfo(INFO_GENERAL);
  32335. return self::$sigchild = false !== strpos(ob_get_clean(), '--enable-sigchild');
  32336. }
  32337. private function readPipesForOutput($caller, $blocking = false)
  32338. {
  32339. if ($this->outputDisabled) {
  32340. throw new LogicException('Output has been disabled.');
  32341. }
  32342. $this->requireProcessIsStarted($caller);
  32343. $this->updateStatus($blocking);
  32344. }
  32345. private function validateTimeout($timeout)
  32346. {
  32347. $timeout = (float) $timeout;
  32348. if (0.0 === $timeout) {
  32349. $timeout = null;
  32350. } elseif ($timeout < 0) {
  32351. throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
  32352. }
  32353. return $timeout;
  32354. }
  32355. private function readPipes($blocking, $close)
  32356. {
  32357. $result = $this->processPipes->readAndWrite($blocking, $close);
  32358. $callback = $this->callback;
  32359. foreach ($result as $type => $data) {
  32360. if (3 !== $type) {
  32361. $callback(self::STDOUT === $type ? self::OUT : self::ERR, $data);
  32362. } elseif (!isset($this->fallbackStatus['signaled'])) {
  32363. $this->fallbackStatus['exitcode'] = (int) $data;
  32364. }
  32365. }
  32366. }
  32367. private function close()
  32368. {
  32369. $this->processPipes->close();
  32370. if (is_resource($this->process)) {
  32371. proc_close($this->process);
  32372. }
  32373. $this->exitcode = $this->processInformation['exitcode'];
  32374. $this->status = self::STATUS_TERMINATED;
  32375. if (-1 === $this->exitcode) {
  32376. if ($this->processInformation['signaled'] && 0 < $this->processInformation['termsig']) {
  32377. $this->exitcode = 128 + $this->processInformation['termsig'];
  32378. } elseif ($this->enhanceSigchildCompatibility && $this->isSigchildEnabled()) {
  32379. $this->processInformation['signaled'] = true;
  32380. $this->processInformation['termsig'] = -1;
  32381. }
  32382. }
  32383. $this->callback = null;
  32384. return $this->exitcode;
  32385. }
  32386. private function resetProcessData()
  32387. {
  32388. $this->starttime = null;
  32389. $this->callback = null;
  32390. $this->exitcode = null;
  32391. $this->fallbackStatus = array();
  32392. $this->processInformation = null;
  32393. $this->stdout = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
  32394. $this->stderr = fopen('php://temp/maxmemory:'.(1024 * 1024), 'wb+');
  32395. $this->process = null;
  32396. $this->latestSignal = null;
  32397. $this->status = self::STATUS_READY;
  32398. $this->incrementalOutputOffset = 0;
  32399. $this->incrementalErrorOutputOffset = 0;
  32400. }
  32401. private function doSignal($signal, $throwException)
  32402. {
  32403. if (null === $pid = $this->getPid()) {
  32404. if ($throwException) {
  32405. throw new LogicException('Can not send signal on a non running process.');
  32406. }
  32407. return false;
  32408. }
  32409. if ('\\' === DIRECTORY_SEPARATOR) {
  32410. exec(sprintf('taskkill /F /T /PID %d 2>&1', $pid), $output, $exitCode);
  32411. if ($exitCode && $this->isRunning()) {
  32412. if ($throwException) {
  32413. throw new RuntimeException(sprintf('Unable to kill the process (%s).', implode(' ', $output)));
  32414. }
  32415. return false;
  32416. }
  32417. } else {
  32418. if (!$this->enhanceSigchildCompatibility || !$this->isSigchildEnabled()) {
  32419. $ok = @proc_terminate($this->process, $signal);
  32420. } elseif (function_exists('posix_kill')) {
  32421. $ok = @posix_kill($pid, $signal);
  32422. } elseif ($ok = proc_open(sprintf('kill -%d %d', $signal, $pid), array(2 => array('pipe', 'w')), $pipes)) {
  32423. $ok = false === fgets($pipes[2]);
  32424. }
  32425. if (!$ok) {
  32426. if ($throwException) {
  32427. throw new RuntimeException(sprintf('Error while sending signal `%s`.', $signal));
  32428. }
  32429. return false;
  32430. }
  32431. }
  32432. $this->latestSignal = (int) $signal;
  32433. $this->fallbackStatus['signaled'] = true;
  32434. $this->fallbackStatus['exitcode'] = -1;
  32435. $this->fallbackStatus['termsig'] = $this->latestSignal;
  32436. return true;
  32437. }
  32438. private function prepareWindowsCommandLine($cmd, array &$env)
  32439. {
  32440. $uid = uniqid('', true);
  32441. $varCount = 0;
  32442. $varCache = array();
  32443. $cmd = preg_replace_callback(
  32444. '/"(?:(
  32445. [^"%!^]*+
  32446. (?:
  32447. (?: !LF! | "(?:\^[%!^])?+" )
  32448. [^"%!^]*+
  32449. )++
  32450. ) | [^"]*+ )"/x',
  32451. function ($m) use (&$env, &$varCache, &$varCount, $uid) {
  32452. if (!isset($m[1])) {
  32453. return $m[0];
  32454. }
  32455. if (isset($varCache[$m[0]])) {
  32456. return $varCache[$m[0]];
  32457. }
  32458. if (false !== strpos($value = $m[1], "\0")) {
  32459. $value = str_replace("\0", '?', $value);
  32460. }
  32461. if (false === strpbrk($value, "\"%!\n")) {
  32462. return '"'.$value.'"';
  32463. }
  32464. $value = str_replace(array('!LF!', '"^!"', '"^%"', '"^^"', '""'), array("\n", '!', '%', '^', '"'), $value);
  32465. $value = '"'.preg_replace('/(\\\\*)"/', '$1$1\\"', $value).'"';
  32466. $var = $uid.++$varCount;
  32467. $env[$var] = $value;
  32468. return $varCache[$m[0]] = '!'.$var.'!';
  32469. },
  32470. $cmd
  32471. );
  32472. $cmd = 'cmd /V:ON /E:ON /D /C ('.str_replace("\n", ' ', $cmd).')';
  32473. foreach ($this->processPipes->getFiles() as $offset => $filename) {
  32474. $cmd .= ' '.$offset.'>"'.$filename.'"';
  32475. }
  32476. return $cmd;
  32477. }
  32478. private function requireProcessIsStarted($functionName)
  32479. {
  32480. if (!$this->isStarted()) {
  32481. throw new LogicException(sprintf('Process must be started before calling %s.', $functionName));
  32482. }
  32483. }
  32484. private function requireProcessIsTerminated($functionName)
  32485. {
  32486. if (!$this->isTerminated()) {
  32487. throw new LogicException(sprintf('Process must be terminated before calling %s.', $functionName));
  32488. }
  32489. }
  32490. private function escapeArgument($argument)
  32491. {
  32492. if ('\\' !== DIRECTORY_SEPARATOR) {
  32493. return "'".str_replace("'", "'\\''", $argument)."'";
  32494. }
  32495. if ('' === $argument = (string) $argument) {
  32496. return '""';
  32497. }
  32498. if (false !== strpos($argument, "\0")) {
  32499. $argument = str_replace("\0", '?', $argument);
  32500. }
  32501. if (!preg_match('/[\/()%!^"<>&|\s]/', $argument)) {
  32502. return $argument;
  32503. }
  32504. $argument = preg_replace('/(\\\\+)$/', '$1$1', $argument);
  32505. return '"'.str_replace(array('"', '^', '%', '!', "\n"), array('""', '"^^"', '"^%"', '"^!"', '!LF!'), $argument).'"';
  32506. }
  32507. private function getDefaultEnv()
  32508. {
  32509. $env = array();
  32510. foreach ($_SERVER as $k => $v) {
  32511. if (is_string($v) && false !== $v = getenv($k)) {
  32512. $env[$k] = $v;
  32513. }
  32514. }
  32515. foreach ($_ENV as $k => $v) {
  32516. if (is_string($v)) {
  32517. $env[$k] = $v;
  32518. }
  32519. }
  32520. return $env;
  32521. }
  32522. }
  32523. <?php
  32524. namespace Symfony\Component\Process;
  32525. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use the Process class instead.', ProcessBuilder::class), E_USER_DEPRECATED);
  32526. use Symfony\Component\Process\Exception\InvalidArgumentException;
  32527. use Symfony\Component\Process\Exception\LogicException;
  32528. class ProcessBuilder
  32529. {
  32530. private $arguments;
  32531. private $cwd;
  32532. private $env = array();
  32533. private $input;
  32534. private $timeout = 60;
  32535. private $options;
  32536. private $inheritEnv = true;
  32537. private $prefix = array();
  32538. private $outputDisabled = false;
  32539. public function __construct(array $arguments = array())
  32540. {
  32541. $this->arguments = $arguments;
  32542. }
  32543. public static function create(array $arguments = array())
  32544. {
  32545. return new static($arguments);
  32546. }
  32547. public function add($argument)
  32548. {
  32549. $this->arguments[] = $argument;
  32550. return $this;
  32551. }
  32552. public function setPrefix($prefix)
  32553. {
  32554. $this->prefix = is_array($prefix) ? $prefix : array($prefix);
  32555. return $this;
  32556. }
  32557. public function setArguments(array $arguments)
  32558. {
  32559. $this->arguments = $arguments;
  32560. return $this;
  32561. }
  32562. public function setWorkingDirectory($cwd)
  32563. {
  32564. $this->cwd = $cwd;
  32565. return $this;
  32566. }
  32567. public function inheritEnvironmentVariables($inheritEnv = true)
  32568. {
  32569. $this->inheritEnv = $inheritEnv;
  32570. return $this;
  32571. }
  32572. public function setEnv($name, $value)
  32573. {
  32574. $this->env[$name] = $value;
  32575. return $this;
  32576. }
  32577. public function addEnvironmentVariables(array $variables)
  32578. {
  32579. $this->env = array_replace($this->env, $variables);
  32580. return $this;
  32581. }
  32582. public function setInput($input)
  32583. {
  32584. $this->input = ProcessUtils::validateInput(__METHOD__, $input);
  32585. return $this;
  32586. }
  32587. public function setTimeout($timeout)
  32588. {
  32589. if (null === $timeout) {
  32590. $this->timeout = null;
  32591. return $this;
  32592. }
  32593. $timeout = (float) $timeout;
  32594. if ($timeout < 0) {
  32595. throw new InvalidArgumentException('The timeout value must be a valid positive integer or float number.');
  32596. }
  32597. $this->timeout = $timeout;
  32598. return $this;
  32599. }
  32600. public function setOption($name, $value)
  32601. {
  32602. $this->options[$name] = $value;
  32603. return $this;
  32604. }
  32605. public function disableOutput()
  32606. {
  32607. $this->outputDisabled = true;
  32608. return $this;
  32609. }
  32610. public function enableOutput()
  32611. {
  32612. $this->outputDisabled = false;
  32613. return $this;
  32614. }
  32615. public function getProcess()
  32616. {
  32617. if (0 === count($this->prefix) && 0 === count($this->arguments)) {
  32618. throw new LogicException('You must add() command arguments before calling getProcess().');
  32619. }
  32620. $arguments = array_merge($this->prefix, $this->arguments);
  32621. $process = new Process($arguments, $this->cwd, $this->env, $this->input, $this->timeout, $this->options);
  32622. $process->setCommandLine($process->getCommandLine());
  32623. if ($this->inheritEnv) {
  32624. $process->inheritEnvironmentVariables();
  32625. }
  32626. if ($this->outputDisabled) {
  32627. $process->disableOutput();
  32628. }
  32629. return $process;
  32630. }
  32631. }
  32632. <?php
  32633. namespace Symfony\Component\Process;
  32634. use Symfony\Component\Process\Exception\InvalidArgumentException;
  32635. class ProcessUtils
  32636. {
  32637. private function __construct()
  32638. {
  32639. }
  32640. public static function escapeArgument($argument)
  32641. {
  32642. @trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 and will be removed in 4.0. Use a command line array or give env vars to the Process::start/run() method instead.', E_USER_DEPRECATED);
  32643. if ('\\' === DIRECTORY_SEPARATOR) {
  32644. if ('' === $argument) {
  32645. return escapeshellarg($argument);
  32646. }
  32647. $escapedArgument = '';
  32648. $quote = false;
  32649. foreach (preg_split('/(")/', $argument, -1, PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE) as $part) {
  32650. if ('"' === $part) {
  32651. $escapedArgument .= '\\"';
  32652. } elseif (self::isSurroundedBy($part, '%')) {
  32653. $escapedArgument .= '^%"'.substr($part, 1, -1).'"^%';
  32654. } else {
  32655. if ('\\' === substr($part, -1)) {
  32656. $part .= '\\';
  32657. }
  32658. $quote = true;
  32659. $escapedArgument .= $part;
  32660. }
  32661. }
  32662. if ($quote) {
  32663. $escapedArgument = '"'.$escapedArgument.'"';
  32664. }
  32665. return $escapedArgument;
  32666. }
  32667. return "'".str_replace("'", "'\\''", $argument)."'";
  32668. }
  32669. public static function validateInput($caller, $input)
  32670. {
  32671. if (null !== $input) {
  32672. if (is_resource($input)) {
  32673. return $input;
  32674. }
  32675. if (is_string($input)) {
  32676. return $input;
  32677. }
  32678. if (is_scalar($input)) {
  32679. return (string) $input;
  32680. }
  32681. if ($input instanceof Process) {
  32682. return $input->getIterator($input::ITER_SKIP_ERR);
  32683. }
  32684. if ($input instanceof \Iterator) {
  32685. return $input;
  32686. }
  32687. if ($input instanceof \Traversable) {
  32688. return new \IteratorIterator($input);
  32689. }
  32690. throw new InvalidArgumentException(sprintf('%s only accepts strings, Traversable objects or stream resources.', $caller));
  32691. }
  32692. return $input;
  32693. }
  32694. private static function isSurroundedBy($arg, $char)
  32695. {
  32696. return 2 < strlen($arg) && $char === $arg[0] && $char === $arg[strlen($arg) - 1];
  32697. }
  32698. }
  32699. <?php
  32700. namespace Symfony\Component\Stopwatch;
  32701. class Section
  32702. {
  32703. private $events = array();
  32704. private $origin;
  32705. private $morePrecision;
  32706. private $id;
  32707. private $children = array();
  32708. public function __construct($origin = null, $morePrecision = false)
  32709. {
  32710. $this->origin = is_numeric($origin) ? $origin : null;
  32711. $this->morePrecision = $morePrecision;
  32712. }
  32713. public function get($id)
  32714. {
  32715. foreach ($this->children as $child) {
  32716. if ($id === $child->getId()) {
  32717. return $child;
  32718. }
  32719. }
  32720. }
  32721. public function open($id)
  32722. {
  32723. if (null === $session = $this->get($id)) {
  32724. $session = $this->children[] = new self(microtime(true) * 1000, $this->morePrecision);
  32725. }
  32726. return $session;
  32727. }
  32728. public function getId()
  32729. {
  32730. return $this->id;
  32731. }
  32732. public function setId($id)
  32733. {
  32734. $this->id = $id;
  32735. return $this;
  32736. }
  32737. public function startEvent($name, $category)
  32738. {
  32739. if (!isset($this->events[$name])) {
  32740. $this->events[$name] = new StopwatchEvent($this->origin ?: microtime(true) * 1000, $category, $this->morePrecision);
  32741. }
  32742. return $this->events[$name]->start();
  32743. }
  32744. public function isEventStarted($name)
  32745. {
  32746. return isset($this->events[$name]) && $this->events[$name]->isStarted();
  32747. }
  32748. public function stopEvent($name)
  32749. {
  32750. if (!isset($this->events[$name])) {
  32751. throw new \LogicException(sprintf('Event "%s" is not started.', $name));
  32752. }
  32753. return $this->events[$name]->stop();
  32754. }
  32755. public function lap($name)
  32756. {
  32757. return $this->stopEvent($name)->start();
  32758. }
  32759. public function getEvent($name)
  32760. {
  32761. if (!isset($this->events[$name])) {
  32762. throw new \LogicException(sprintf('Event "%s" is not known.', $name));
  32763. }
  32764. return $this->events[$name];
  32765. }
  32766. public function getEvents()
  32767. {
  32768. return $this->events;
  32769. }
  32770. }
  32771. <?php
  32772. namespace Symfony\Component\Stopwatch;
  32773. class Stopwatch
  32774. {
  32775. private $morePrecision;
  32776. private $sections;
  32777. private $activeSections;
  32778. public function __construct($morePrecision = false)
  32779. {
  32780. $this->morePrecision = $morePrecision;
  32781. $this->reset();
  32782. }
  32783. public function getSections()
  32784. {
  32785. return $this->sections;
  32786. }
  32787. public function openSection($id = null)
  32788. {
  32789. $current = end($this->activeSections);
  32790. if (null !== $id && null === $current->get($id)) {
  32791. throw new \LogicException(sprintf('The section "%s" has been started at an other level and can not be opened.', $id));
  32792. }
  32793. $this->start('__section__.child', 'section');
  32794. $this->activeSections[] = $current->open($id);
  32795. $this->start('__section__');
  32796. }
  32797. public function stopSection($id)
  32798. {
  32799. $this->stop('__section__');
  32800. if (1 == count($this->activeSections)) {
  32801. throw new \LogicException('There is no started section to stop.');
  32802. }
  32803. $this->sections[$id] = array_pop($this->activeSections)->setId($id);
  32804. $this->stop('__section__.child');
  32805. }
  32806. public function start($name, $category = null)
  32807. {
  32808. return end($this->activeSections)->startEvent($name, $category);
  32809. }
  32810. public function isStarted($name)
  32811. {
  32812. return end($this->activeSections)->isEventStarted($name);
  32813. }
  32814. public function stop($name)
  32815. {
  32816. return end($this->activeSections)->stopEvent($name);
  32817. }
  32818. public function lap($name)
  32819. {
  32820. return end($this->activeSections)->stopEvent($name)->start();
  32821. }
  32822. public function getEvent($name)
  32823. {
  32824. return end($this->activeSections)->getEvent($name);
  32825. }
  32826. public function getSectionEvents($id)
  32827. {
  32828. return isset($this->sections[$id]) ? $this->sections[$id]->getEvents() : array();
  32829. }
  32830. public function reset()
  32831. {
  32832. $this->sections = $this->activeSections = array('__root__' => new Section(null, $this->morePrecision));
  32833. }
  32834. }
  32835. <?php
  32836. namespace Symfony\Component\Stopwatch;
  32837. class StopwatchEvent
  32838. {
  32839. private $periods = array();
  32840. private $origin;
  32841. private $category;
  32842. private $morePrecision;
  32843. private $started = array();
  32844. public function __construct($origin, $category = null, $morePrecision = false)
  32845. {
  32846. $this->origin = $this->formatTime($origin);
  32847. $this->category = is_string($category) ? $category : 'default';
  32848. $this->morePrecision = $morePrecision;
  32849. }
  32850. public function getCategory()
  32851. {
  32852. return $this->category;
  32853. }
  32854. public function getOrigin()
  32855. {
  32856. return $this->origin;
  32857. }
  32858. public function start()
  32859. {
  32860. $this->started[] = $this->getNow();
  32861. return $this;
  32862. }
  32863. public function stop()
  32864. {
  32865. if (!count($this->started)) {
  32866. throw new \LogicException('stop() called but start() has not been called before.');
  32867. }
  32868. $this->periods[] = new StopwatchPeriod(array_pop($this->started), $this->getNow(), $this->morePrecision);
  32869. return $this;
  32870. }
  32871. public function isStarted()
  32872. {
  32873. return !empty($this->started);
  32874. }
  32875. public function lap()
  32876. {
  32877. return $this->stop()->start();
  32878. }
  32879. public function ensureStopped()
  32880. {
  32881. while (count($this->started)) {
  32882. $this->stop();
  32883. }
  32884. }
  32885. public function getPeriods()
  32886. {
  32887. return $this->periods;
  32888. }
  32889. public function getStartTime()
  32890. {
  32891. return isset($this->periods[0]) ? $this->periods[0]->getStartTime() : 0;
  32892. }
  32893. public function getEndTime()
  32894. {
  32895. $count = count($this->periods);
  32896. return $count ? $this->periods[$count - 1]->getEndTime() : 0;
  32897. }
  32898. public function getDuration()
  32899. {
  32900. $periods = $this->periods;
  32901. $stopped = count($periods);
  32902. $left = count($this->started) - $stopped;
  32903. for ($i = 0; $i < $left; ++$i) {
  32904. $index = $stopped + $i;
  32905. $periods[] = new StopwatchPeriod($this->started[$index], $this->getNow(), $this->morePrecision);
  32906. }
  32907. $total = 0;
  32908. foreach ($periods as $period) {
  32909. $total += $period->getDuration();
  32910. }
  32911. return $total;
  32912. }
  32913. public function getMemory()
  32914. {
  32915. $memory = 0;
  32916. foreach ($this->periods as $period) {
  32917. if ($period->getMemory() > $memory) {
  32918. $memory = $period->getMemory();
  32919. }
  32920. }
  32921. return $memory;
  32922. }
  32923. protected function getNow()
  32924. {
  32925. return $this->formatTime(microtime(true) * 1000 - $this->origin);
  32926. }
  32927. private function formatTime($time)
  32928. {
  32929. if (!is_numeric($time)) {
  32930. throw new \InvalidArgumentException('The time must be a numerical value');
  32931. }
  32932. return round($time, 1);
  32933. }
  32934. public function __toString()
  32935. {
  32936. return sprintf('%s: %.2F MiB - %d ms', $this->getCategory(), $this->getMemory() / 1024 / 1024, $this->getDuration());
  32937. }
  32938. }
  32939. <?php
  32940. namespace Symfony\Component\Stopwatch;
  32941. class StopwatchPeriod
  32942. {
  32943. private $start;
  32944. private $end;
  32945. private $memory;
  32946. public function __construct($start, $end, $morePrecision = false)
  32947. {
  32948. $this->start = $morePrecision ? (float) $start : (int) $start;
  32949. $this->end = $morePrecision ? (float) $end : (int) $end;
  32950. $this->memory = memory_get_usage(true);
  32951. }
  32952. public function getStartTime()
  32953. {
  32954. return $this->start;
  32955. }
  32956. public function getEndTime()
  32957. {
  32958. return $this->end;
  32959. }
  32960. public function getDuration()
  32961. {
  32962. return $this->end - $this->start;
  32963. }
  32964. public function getMemory()
  32965. {
  32966. return $this->memory;
  32967. }
  32968. }
  32969. <?php
  32970. namespace Symfony\Polyfill\Mbstring;
  32971. final class Mbstring
  32972. {
  32973. const MB_CASE_FOLD = PHP_INT_MAX;
  32974. private static $encodingList = array('ASCII', 'UTF-8');
  32975. private static $language = 'neutral';
  32976. private static $internalEncoding = 'UTF-8';
  32977. private static $caseFold = array(
  32978. array('µ','ſ',"\xCD\x85",'ς',"\xCF\x90","\xCF\x91","\xCF\x95","\xCF\x96","\xCF\xB0","\xCF\xB1","\xCF\xB5","\xE1\xBA\x9B","\xE1\xBE\xBE"),
  32979. array('μ','s','ι', 'σ','β', 'θ', 'φ', 'π', 'κ', '�', 'ε', "\xE1\xB9\xA1",'ι'),
  32980. );
  32981. public static function mb_convert_encoding($s, $toEncoding, $fromEncoding = null)
  32982. {
  32983. if (is_array($fromEncoding) || false !== strpos($fromEncoding, ',')) {
  32984. $fromEncoding = self::mb_detect_encoding($s, $fromEncoding);
  32985. } else {
  32986. $fromEncoding = self::getEncoding($fromEncoding);
  32987. }
  32988. $toEncoding = self::getEncoding($toEncoding);
  32989. if ('BASE64' === $fromEncoding) {
  32990. $s = base64_decode($s);
  32991. $fromEncoding = $toEncoding;
  32992. }
  32993. if ('BASE64' === $toEncoding) {
  32994. return base64_encode($s);
  32995. }
  32996. if ('HTML-ENTITIES' === $toEncoding || 'HTML' === $toEncoding) {
  32997. if ('HTML-ENTITIES' === $fromEncoding || 'HTML' === $fromEncoding) {
  32998. $fromEncoding = 'Windows-1252';
  32999. }
  33000. if ('UTF-8' !== $fromEncoding) {
  33001. $s = iconv($fromEncoding, 'UTF-8//IGNORE', $s);
  33002. }
  33003. return preg_replace_callback('/[\x80-\xFF]+/', array(__CLASS__, 'html_encoding_callback'), $s);
  33004. }
  33005. if ('HTML-ENTITIES' === $fromEncoding) {
  33006. $s = html_entity_decode($s, ENT_COMPAT, 'UTF-8');
  33007. $fromEncoding = 'UTF-8';
  33008. }
  33009. return iconv($fromEncoding, $toEncoding.'//IGNORE', $s);
  33010. }
  33011. public static function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null)
  33012. {
  33013. $vars = array(&$a, &$b, &$c, &$d, &$e, &$f);
  33014. $ok = true;
  33015. array_walk_recursive($vars, function (&$v) use (&$ok, $toEncoding, $fromEncoding) {
  33016. if (false === $v = Mbstring::mb_convert_encoding($v, $toEncoding, $fromEncoding)) {
  33017. $ok = false;
  33018. }
  33019. });
  33020. return $ok ? $fromEncoding : false;
  33021. }
  33022. public static function mb_decode_mimeheader($s)
  33023. {
  33024. return iconv_mime_decode($s, 2, self::$internalEncoding);
  33025. }
  33026. public static function mb_encode_mimeheader($s, $charset = null, $transferEncoding = null, $linefeed = null, $indent = null)
  33027. {
  33028. trigger_error('mb_encode_mimeheader() is bugged. Please use iconv_mime_encode() instead', E_USER_WARNING);
  33029. }
  33030. public static function mb_convert_case($s, $mode, $encoding = null)
  33031. {
  33032. if ('' === $s .= '') {
  33033. return '';
  33034. }
  33035. $encoding = self::getEncoding($encoding);
  33036. if ('UTF-8' === $encoding) {
  33037. $encoding = null;
  33038. if (!preg_match('//u', $s)) {
  33039. $s = @iconv('UTF-8', 'UTF-8//IGNORE', $s);
  33040. }
  33041. } else {
  33042. $s = iconv($encoding, 'UTF-8//IGNORE', $s);
  33043. }
  33044. if (MB_CASE_TITLE == $mode) {
  33045. $s = preg_replace_callback('/\b\p{Ll}/u', array(__CLASS__, 'title_case_upper'), $s);
  33046. $s = preg_replace_callback('/\B[\p{Lu}\p{Lt}]+/u', array(__CLASS__, 'title_case_lower'), $s);
  33047. } else {
  33048. if (MB_CASE_UPPER == $mode) {
  33049. static $upper = null;
  33050. if (null === $upper) {
  33051. $upper = self::getData('upperCase');
  33052. }
  33053. $map = $upper;
  33054. } else {
  33055. if (self::MB_CASE_FOLD === $mode) {
  33056. $s = str_replace(self::$caseFold[0], self::$caseFold[1], $s);
  33057. }
  33058. static $lower = null;
  33059. if (null === $lower) {
  33060. $lower = self::getData('lowerCase');
  33061. }
  33062. $map = $lower;
  33063. }
  33064. static $ulenMask = array("\xC0" => 2, "\xD0" => 2, "\xE0" => 3, "\xF0" => 4);
  33065. $i = 0;
  33066. $len = strlen($s);
  33067. while ($i < $len) {
  33068. $ulen = $s[$i] < "\x80" ? 1 : $ulenMask[$s[$i] & "\xF0"];
  33069. $uchr = substr($s, $i, $ulen);
  33070. $i += $ulen;
  33071. if (isset($map[$uchr])) {
  33072. $uchr = $map[$uchr];
  33073. $nlen = strlen($uchr);
  33074. if ($nlen == $ulen) {
  33075. $nlen = $i;
  33076. do {
  33077. $s[--$nlen] = $uchr[--$ulen];
  33078. } while ($ulen);
  33079. } else {
  33080. $s = substr_replace($s, $uchr, $i - $ulen, $ulen);
  33081. $len += $nlen - $ulen;
  33082. $i += $nlen - $ulen;
  33083. }
  33084. }
  33085. }
  33086. }
  33087. if (null === $encoding) {
  33088. return $s;
  33089. }
  33090. return iconv('UTF-8', $encoding.'//IGNORE', $s);
  33091. }
  33092. public static function mb_internal_encoding($encoding = null)
  33093. {
  33094. if (null === $encoding) {
  33095. return self::$internalEncoding;
  33096. }
  33097. $encoding = self::getEncoding($encoding);
  33098. if ('UTF-8' === $encoding || false !== @iconv($encoding, $encoding, ' ')) {
  33099. self::$internalEncoding = $encoding;
  33100. return true;
  33101. }
  33102. return false;
  33103. }
  33104. public static function mb_language($lang = null)
  33105. {
  33106. if (null === $lang) {
  33107. return self::$language;
  33108. }
  33109. switch ($lang = strtolower($lang)) {
  33110. case 'uni':
  33111. case 'neutral':
  33112. self::$language = $lang;
  33113. return true;
  33114. }
  33115. return false;
  33116. }
  33117. public static function mb_list_encodings()
  33118. {
  33119. return array('UTF-8');
  33120. }
  33121. public static function mb_encoding_aliases($encoding)
  33122. {
  33123. switch (strtoupper($encoding)) {
  33124. case 'UTF8':
  33125. case 'UTF-8':
  33126. return array('utf8');
  33127. }
  33128. return false;
  33129. }
  33130. public static function mb_check_encoding($var = null, $encoding = null)
  33131. {
  33132. if (null === $encoding) {
  33133. if (null === $var) {
  33134. return false;
  33135. }
  33136. $encoding = self::$internalEncoding;
  33137. }
  33138. return self::mb_detect_encoding($var, array($encoding)) || false !== @iconv($encoding, $encoding, $var);
  33139. }
  33140. public static function mb_detect_encoding($str, $encodingList = null, $strict = false)
  33141. {
  33142. if (null === $encodingList) {
  33143. $encodingList = self::$encodingList;
  33144. } else {
  33145. if (!is_array($encodingList)) {
  33146. $encodingList = array_map('trim', explode(',', $encodingList));
  33147. }
  33148. $encodingList = array_map('strtoupper', $encodingList);
  33149. }
  33150. foreach ($encodingList as $enc) {
  33151. switch ($enc) {
  33152. case 'ASCII':
  33153. if (!preg_match('/[\x80-\xFF]/', $str)) {
  33154. return $enc;
  33155. }
  33156. break;
  33157. case 'UTF8':
  33158. case 'UTF-8':
  33159. if (preg_match('//u', $str)) {
  33160. return 'UTF-8';
  33161. }
  33162. break;
  33163. default:
  33164. if (0 === strncmp($enc, 'ISO-8859-', 9)) {
  33165. return $enc;
  33166. }
  33167. }
  33168. }
  33169. return false;
  33170. }
  33171. public static function mb_detect_order($encodingList = null)
  33172. {
  33173. if (null === $encodingList) {
  33174. return self::$encodingList;
  33175. }
  33176. if (!is_array($encodingList)) {
  33177. $encodingList = array_map('trim', explode(',', $encodingList));
  33178. }
  33179. $encodingList = array_map('strtoupper', $encodingList);
  33180. foreach ($encodingList as $enc) {
  33181. switch ($enc) {
  33182. default:
  33183. if (strncmp($enc, 'ISO-8859-', 9)) {
  33184. return false;
  33185. }
  33186. case 'ASCII':
  33187. case 'UTF8':
  33188. case 'UTF-8':
  33189. }
  33190. }
  33191. self::$encodingList = $encodingList;
  33192. return true;
  33193. }
  33194. public static function mb_strlen($s, $encoding = null)
  33195. {
  33196. $encoding = self::getEncoding($encoding);
  33197. if ('CP850' === $encoding || 'ASCII' === $encoding) {
  33198. return strlen($s);
  33199. }
  33200. return @iconv_strlen($s, $encoding);
  33201. }
  33202. public static function mb_strpos($haystack, $needle, $offset = 0, $encoding = null)
  33203. {
  33204. $encoding = self::getEncoding($encoding);
  33205. if ('CP850' === $encoding || 'ASCII' === $encoding) {
  33206. return strpos($haystack, $needle, $offset);
  33207. }
  33208. if ('' === $needle .= '') {
  33209. trigger_error(__METHOD__.': Empty delimiter', E_USER_WARNING);
  33210. return false;
  33211. }
  33212. return iconv_strpos($haystack, $needle, $offset, $encoding);
  33213. }
  33214. public static function mb_strrpos($haystack, $needle, $offset = 0, $encoding = null)
  33215. {
  33216. $encoding = self::getEncoding($encoding);
  33217. if ('CP850' === $encoding || 'ASCII' === $encoding) {
  33218. return strrpos($haystack, $needle, $offset);
  33219. }
  33220. if ($offset != (int) $offset) {
  33221. $offset = 0;
  33222. } elseif ($offset = (int) $offset) {
  33223. if ($offset < 0) {
  33224. $haystack = self::mb_substr($haystack, 0, $offset, $encoding);
  33225. $offset = 0;
  33226. } else {
  33227. $haystack = self::mb_substr($haystack, $offset, 2147483647, $encoding);
  33228. }
  33229. }
  33230. $pos = iconv_strrpos($haystack, $needle, $encoding);
  33231. return false !== $pos ? $offset + $pos : false;
  33232. }
  33233. public static function mb_strtolower($s, $encoding = null)
  33234. {
  33235. return self::mb_convert_case($s, MB_CASE_LOWER, $encoding);
  33236. }
  33237. public static function mb_strtoupper($s, $encoding = null)
  33238. {
  33239. return self::mb_convert_case($s, MB_CASE_UPPER, $encoding);
  33240. }
  33241. public static function mb_substitute_character($c = null)
  33242. {
  33243. if (0 === strcasecmp($c, 'none')) {
  33244. return true;
  33245. }
  33246. return null !== $c ? false : 'none';
  33247. }
  33248. public static function mb_substr($s, $start, $length = null, $encoding = null)
  33249. {
  33250. $encoding = self::getEncoding($encoding);
  33251. if ('CP850' === $encoding || 'ASCII' === $encoding) {
  33252. return substr($s, $start, null === $length ? 2147483647 : $length);
  33253. }
  33254. if ($start < 0) {
  33255. $start = iconv_strlen($s, $encoding) + $start;
  33256. if ($start < 0) {
  33257. $start = 0;
  33258. }
  33259. }
  33260. if (null === $length) {
  33261. $length = 2147483647;
  33262. } elseif ($length < 0) {
  33263. $length = iconv_strlen($s, $encoding) + $length - $start;
  33264. if ($length < 0) {
  33265. return '';
  33266. }
  33267. }
  33268. return iconv_substr($s, $start, $length, $encoding).'';
  33269. }
  33270. public static function mb_stripos($haystack, $needle, $offset = 0, $encoding = null)
  33271. {
  33272. $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
  33273. $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
  33274. return self::mb_strpos($haystack, $needle, $offset, $encoding);
  33275. }
  33276. public static function mb_stristr($haystack, $needle, $part = false, $encoding = null)
  33277. {
  33278. $pos = self::mb_stripos($haystack, $needle, 0, $encoding);
  33279. return self::getSubpart($pos, $part, $haystack, $encoding);
  33280. }
  33281. public static function mb_strrchr($haystack, $needle, $part = false, $encoding = null)
  33282. {
  33283. $encoding = self::getEncoding($encoding);
  33284. if ('CP850' === $encoding || 'ASCII' === $encoding) {
  33285. return strrchr($haystack, $needle, $part);
  33286. }
  33287. $needle = self::mb_substr($needle, 0, 1, $encoding);
  33288. $pos = iconv_strrpos($haystack, $needle, $encoding);
  33289. return self::getSubpart($pos, $part, $haystack, $encoding);
  33290. }
  33291. public static function mb_strrichr($haystack, $needle, $part = false, $encoding = null)
  33292. {
  33293. $needle = self::mb_substr($needle, 0, 1, $encoding);
  33294. $pos = self::mb_strripos($haystack, $needle, $encoding);
  33295. return self::getSubpart($pos, $part, $haystack, $encoding);
  33296. }
  33297. public static function mb_strripos($haystack, $needle, $offset = 0, $encoding = null)
  33298. {
  33299. $haystack = self::mb_convert_case($haystack, self::MB_CASE_FOLD, $encoding);
  33300. $needle = self::mb_convert_case($needle, self::MB_CASE_FOLD, $encoding);
  33301. return self::mb_strrpos($haystack, $needle, $offset, $encoding);
  33302. }
  33303. public static function mb_strstr($haystack, $needle, $part = false, $encoding = null)
  33304. {
  33305. $pos = strpos($haystack, $needle);
  33306. if (false === $pos) {
  33307. return false;
  33308. }
  33309. if ($part) {
  33310. return substr($haystack, 0, $pos);
  33311. }
  33312. return substr($haystack, $pos);
  33313. }
  33314. public static function mb_get_info($type = 'all')
  33315. {
  33316. $info = array(
  33317. 'internal_encoding' => self::$internalEncoding,
  33318. 'http_output' => 'pass',
  33319. 'http_output_conv_mimetypes' => '^(text/|application/xhtml\+xml)',
  33320. 'func_overload' => 0,
  33321. 'func_overload_list' => 'no overload',
  33322. 'mail_charset' => 'UTF-8',
  33323. 'mail_header_encoding' => 'BASE64',
  33324. 'mail_body_encoding' => 'BASE64',
  33325. 'illegal_chars' => 0,
  33326. 'encoding_translation' => 'Off',
  33327. 'language' => self::$language,
  33328. 'detect_order' => self::$encodingList,
  33329. 'substitute_character' => 'none',
  33330. 'strict_detection' => 'Off',
  33331. );
  33332. if ('all' === $type) {
  33333. return $info;
  33334. }
  33335. if (isset($info[$type])) {
  33336. return $info[$type];
  33337. }
  33338. return false;
  33339. }
  33340. public static function mb_http_input($type = '')
  33341. {
  33342. return false;
  33343. }
  33344. public static function mb_http_output($encoding = null)
  33345. {
  33346. return null !== $encoding ? 'pass' === $encoding : 'pass';
  33347. }
  33348. public static function mb_strwidth($s, $encoding = null)
  33349. {
  33350. $encoding = self::getEncoding($encoding);
  33351. if ('UTF-8' !== $encoding) {
  33352. $s = iconv($encoding, 'UTF-8//IGNORE', $s);
  33353. }
  33354. $s = preg_replace('/[\x{1100}-\x{115F}\x{2329}\x{232A}\x{2E80}-\x{303E}\x{3040}-\x{A4CF}\x{AC00}-\x{D7A3}\x{F900}-\x{FAFF}\x{FE10}-\x{FE19}\x{FE30}-\x{FE6F}\x{FF00}-\x{FF60}\x{FFE0}-\x{FFE6}\x{20000}-\x{2FFFD}\x{30000}-\x{3FFFD}]/u', '', $s, -1, $wide);
  33355. return ($wide << 1) + iconv_strlen($s, 'UTF-8');
  33356. }
  33357. public static function mb_substr_count($haystack, $needle, $encoding = null)
  33358. {
  33359. return substr_count($haystack, $needle);
  33360. }
  33361. public static function mb_output_handler($contents, $status)
  33362. {
  33363. return $contents;
  33364. }
  33365. public static function mb_chr($code, $encoding = null)
  33366. {
  33367. if (0x80 > $code %= 0x200000) {
  33368. $s = chr($code);
  33369. } elseif (0x800 > $code) {
  33370. $s = chr(0xC0 | $code >> 6).chr(0x80 | $code & 0x3F);
  33371. } elseif (0x10000 > $code) {
  33372. $s = chr(0xE0 | $code >> 12).chr(0x80 | $code >> 6 & 0x3F).chr(0x80 | $code & 0x3F);
  33373. } else {
  33374. $s = chr(0xF0 | $code >> 18).chr(0x80 | $code >> 12 & 0x3F).chr(0x80 | $code >> 6 & 0x3F).chr(0x80 | $code & 0x3F);
  33375. }
  33376. if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
  33377. $s = mb_convert_encoding($s, $encoding, 'UTF-8');
  33378. }
  33379. return $s;
  33380. }
  33381. public static function mb_ord($s, $encoding = null)
  33382. {
  33383. if ('UTF-8' !== $encoding = self::getEncoding($encoding)) {
  33384. $s = mb_convert_encoding($s, 'UTF-8', $encoding);
  33385. }
  33386. $code = ($s = unpack('C*', substr($s, 0, 4))) ? $s[1] : 0;
  33387. if (0xF0 <= $code) {
  33388. return (($code - 0xF0) << 18) + (($s[2] - 0x80) << 12) + (($s[3] - 0x80) << 6) + $s[4] - 0x80;
  33389. }
  33390. if (0xE0 <= $code) {
  33391. return (($code - 0xE0) << 12) + (($s[2] - 0x80) << 6) + $s[3] - 0x80;
  33392. }
  33393. if (0xC0 <= $code) {
  33394. return (($code - 0xC0) << 6) + $s[2] - 0x80;
  33395. }
  33396. return $code;
  33397. }
  33398. private static function getSubpart($pos, $part, $haystack, $encoding)
  33399. {
  33400. if (false === $pos) {
  33401. return false;
  33402. }
  33403. if ($part) {
  33404. return self::mb_substr($haystack, 0, $pos, $encoding);
  33405. }
  33406. return self::mb_substr($haystack, $pos, null, $encoding);
  33407. }
  33408. private static function html_encoding_callback($m)
  33409. {
  33410. $i = 1;
  33411. $entities = '';
  33412. $m = unpack('C*', htmlentities($m[0], ENT_COMPAT, 'UTF-8'));
  33413. while (isset($m[$i])) {
  33414. if (0x80 > $m[$i]) {
  33415. $entities .= chr($m[$i++]);
  33416. continue;
  33417. }
  33418. if (0xF0 <= $m[$i]) {
  33419. $c = (($m[$i++] - 0xF0) << 18) + (($m[$i++] - 0x80) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
  33420. } elseif (0xE0 <= $m[$i]) {
  33421. $c = (($m[$i++] - 0xE0) << 12) + (($m[$i++] - 0x80) << 6) + $m[$i++] - 0x80;
  33422. } else {
  33423. $c = (($m[$i++] - 0xC0) << 6) + $m[$i++] - 0x80;
  33424. }
  33425. $entities .= '&#'.$c.';';
  33426. }
  33427. return $entities;
  33428. }
  33429. private static function title_case_lower($s)
  33430. {
  33431. return self::mb_convert_case($s[0], MB_CASE_LOWER, 'UTF-8');
  33432. }
  33433. private static function title_case_upper($s)
  33434. {
  33435. return self::mb_convert_case($s[0], MB_CASE_UPPER, 'UTF-8');
  33436. }
  33437. private static function getData($file)
  33438. {
  33439. if (file_exists($file = __DIR__.'/Resources/unidata/'.$file.'.php')) {
  33440. return require $file;
  33441. }
  33442. return false;
  33443. }
  33444. private static function getEncoding($encoding)
  33445. {
  33446. if (null === $encoding) {
  33447. return self::$internalEncoding;
  33448. }
  33449. $encoding = strtoupper($encoding);
  33450. if ('8BIT' === $encoding || 'BINARY' === $encoding) {
  33451. return 'CP850';
  33452. }
  33453. if ('UTF8' === $encoding) {
  33454. return 'UTF-8';
  33455. }
  33456. return $encoding;
  33457. }
  33458. }
  33459. <?php
  33460. static $data = array (
  33461. 'A' => 'a',
  33462. 'B' => 'b',
  33463. 'C' => 'c',
  33464. 'D' => 'd',
  33465. 'E' => 'e',
  33466. 'F' => 'f',
  33467. 'G' => 'g',
  33468. 'H' => 'h',
  33469. 'I' => 'i',
  33470. 'J' => 'j',
  33471. 'K' => 'k',
  33472. 'L' => 'l',
  33473. 'M' => 'm',
  33474. 'N' => 'n',
  33475. 'O' => 'o',
  33476. 'P' => 'p',
  33477. 'Q' => 'q',
  33478. 'R' => 'r',
  33479. 'S' => 's',
  33480. 'T' => 't',
  33481. 'U' => 'u',
  33482. 'V' => 'v',
  33483. 'W' => 'w',
  33484. 'X' => 'x',
  33485. 'Y' => 'y',
  33486. 'Z' => 'z',
  33487. 'À' => 'à',
  33488. '�' => 'á',
  33489. 'Â' => 'â',
  33490. 'Ã' => 'ã',
  33491. 'Ä' => 'ä',
  33492. 'Ã…' => 'Ã¥',
  33493. 'Æ' => 'æ',
  33494. 'Ç' => 'ç',
  33495. 'È' => 'è',
  33496. 'É' => 'é',
  33497. 'Ê' => 'ê',
  33498. 'Ë' => 'ë',
  33499. 'Ì' => 'ì',
  33500. '�' => 'í',
  33501. 'Î' => 'î',
  33502. '�' => 'ï',
  33503. '�' => 'ð',
  33504. 'Ñ' => 'ñ',
  33505. 'Ò' => 'ò',
  33506. 'Ó' => 'ó',
  33507. 'Ô' => 'ô',
  33508. 'Õ' => 'õ',
  33509. 'Ö' => 'ö',
  33510. 'Ø' => 'ø',
  33511. 'Ù' => 'ù',
  33512. 'Ú' => 'ú',
  33513. 'Û' => 'û',
  33514. 'Ü' => 'ü',
  33515. '�' => 'ý',
  33516. 'Þ' => 'þ',
  33517. 'Ā' => '�',
  33518. 'Ă' => 'ă',
  33519. 'Ä„' => 'Ä…',
  33520. 'Ć' => 'ć',
  33521. 'Ĉ' => 'ĉ',
  33522. 'ÄŠ' => 'Ä‹',
  33523. 'Č' => '�',
  33524. 'Ď' => '�',
  33525. '�' => 'đ',
  33526. 'Ä’' => 'Ä“',
  33527. 'Ä”' => 'Ä•',
  33528. 'Ä–' => 'Ä—',
  33529. 'Ę' => 'ę',
  33530. 'Äš' => 'Ä›',
  33531. 'Ĝ' => '�',
  33532. 'Äž' => 'ÄŸ',
  33533. 'Ä ' => 'Ä¡',
  33534. 'Ä¢' => 'Ä£',
  33535. 'Ĥ' => 'ĥ',
  33536. 'Ħ' => 'ħ',
  33537. 'Ĩ' => 'ĩ',
  33538. 'Ī' => 'ī',
  33539. 'Ĭ' => 'ĭ',
  33540. 'Į' => 'į',
  33541. 'İ' => 'i',
  33542. 'IJ' => 'ij',
  33543. 'Ĵ' => 'ĵ',
  33544. 'Ķ' => 'ķ',
  33545. 'Ĺ' => 'ĺ',
  33546. 'Ļ' => 'ļ',
  33547. 'Ľ' => 'ľ',
  33548. 'Ä¿' => 'Å€',
  33549. '�' => 'ł',
  33550. 'Ń' => 'ń',
  33551. 'Ņ' => 'ņ',
  33552. 'Ň' => 'ň',
  33553. 'ÅŠ' => 'Å‹',
  33554. 'Ō' => '�',
  33555. 'Ŏ' => '�',
  33556. '�' => 'ő',
  33557. 'Å’' => 'Å“',
  33558. 'Å”' => 'Å•',
  33559. 'Å–' => 'Å—',
  33560. 'Ř' => 'ř',
  33561. 'Åš' => 'Å›',
  33562. 'Ŝ' => '�',
  33563. 'Åž' => 'ÅŸ',
  33564. 'Å ' => 'Å¡',
  33565. 'Å¢' => 'Å£',
  33566. 'Ť' => 'ť',
  33567. 'Ŧ' => 'ŧ',
  33568. 'Ũ' => 'ũ',
  33569. 'Ū' => 'ū',
  33570. 'Ŭ' => 'ŭ',
  33571. 'Ů' => 'ů',
  33572. 'Ű' => 'ű',
  33573. 'Ų' => 'ų',
  33574. 'Ŵ' => 'ŵ',
  33575. 'Ŷ' => 'ŷ',
  33576. 'Ÿ' => 'ÿ',
  33577. 'Ź' => 'ź',
  33578. 'Ż' => 'ż',
  33579. 'Ž' => 'ž',
  33580. '�' => 'ɓ',
  33581. 'Ƃ' => 'ƃ',
  33582. 'Æ„' => 'Æ…',
  33583. 'Ɔ' => 'ɔ',
  33584. 'Ƈ' => 'ƈ',
  33585. 'Ɖ' => 'ɖ',
  33586. 'ÆŠ' => 'É—',
  33587. 'Ƌ' => 'ƌ',
  33588. 'Ǝ' => '�',
  33589. '�' => 'ə',
  33590. '�' => 'ɛ',
  33591. 'Æ‘' => 'Æ’',
  33592. 'Æ“' => 'É ',
  33593. 'Æ”' => 'É£',
  33594. 'Æ–' => 'É©',
  33595. 'Ɨ' => 'ɨ',
  33596. 'Ƙ' => 'ƙ',
  33597. 'Ɯ' => 'ɯ',
  33598. '�' => 'ɲ',
  33599. 'Ɵ' => 'ɵ',
  33600. 'Æ ' => 'Æ¡',
  33601. 'Æ¢' => 'Æ£',
  33602. 'Ƥ' => 'ƥ',
  33603. 'Ʀ' => 'ʀ',
  33604. 'Ƨ' => 'ƨ',
  33605. 'Ʃ' => 'ʃ',
  33606. 'Ƭ' => 'ƭ',
  33607. 'Ʈ' => 'ʈ',
  33608. 'Ư' => 'ư',
  33609. 'Ʊ' => 'ʊ',
  33610. 'Ʋ' => 'ʋ',
  33611. 'Ƴ' => 'ƴ',
  33612. 'Ƶ' => 'ƶ',
  33613. 'Æ·' => 'Ê’',
  33614. 'Ƹ' => 'ƹ',
  33615. 'Ƽ' => 'ƽ',
  33616. 'DŽ' => 'dž',
  33617. 'Dž' => 'dž',
  33618. 'LJ' => 'lj',
  33619. 'Lj' => 'lj',
  33620. 'NJ' => 'nj',
  33621. 'Nj' => 'nj',
  33622. '�' => 'ǎ',
  33623. '�' => '�',
  33624. 'Ç‘' => 'Ç’',
  33625. 'Ç“' => 'Ç”',
  33626. 'Ç•' => 'Ç–',
  33627. 'Ǘ' => 'ǘ',
  33628. 'Ç™' => 'Çš',
  33629. 'Ǜ' => 'ǜ',
  33630. 'Çž' => 'ÇŸ',
  33631. 'Ç ' => 'Ç¡',
  33632. 'Ç¢' => 'Ç£',
  33633. 'Ǥ' => 'ǥ',
  33634. 'Ǧ' => 'ǧ',
  33635. 'Ǩ' => 'ǩ',
  33636. 'Ǫ' => 'ǫ',
  33637. 'Ǭ' => 'ǭ',
  33638. 'Ǯ' => 'ǯ',
  33639. 'DZ' => 'dz',
  33640. 'Dz' => 'dz',
  33641. 'Ǵ' => 'ǵ',
  33642. 'Ƕ' => 'ƕ',
  33643. 'Ç·' => 'Æ¿',
  33644. 'Ǹ' => 'ǹ',
  33645. 'Ǻ' => 'ǻ',
  33646. 'Ǽ' => 'ǽ',
  33647. 'Ǿ' => 'ǿ',
  33648. 'Ȁ' => '�',
  33649. 'Ȃ' => 'ȃ',
  33650. 'È„' => 'È…',
  33651. 'Ȇ' => 'ȇ',
  33652. 'Ȉ' => 'ȉ',
  33653. 'ÈŠ' => 'È‹',
  33654. 'Ȍ' => '�',
  33655. 'Ȏ' => '�',
  33656. '�' => 'ȑ',
  33657. 'È’' => 'È“',
  33658. 'È”' => 'È•',
  33659. 'È–' => 'È—',
  33660. 'Ș' => 'ș',
  33661. 'Èš' => 'È›',
  33662. 'Ȝ' => '�',
  33663. 'Èž' => 'ÈŸ',
  33664. 'È ' => 'Æž',
  33665. 'È¢' => 'È£',
  33666. 'Ȥ' => 'ȥ',
  33667. 'Ȧ' => 'ȧ',
  33668. 'Ȩ' => 'ȩ',
  33669. 'Ȫ' => 'ȫ',
  33670. 'Ȭ' => 'ȭ',
  33671. 'Ȯ' => 'ȯ',
  33672. 'Ȱ' => 'ȱ',
  33673. 'Ȳ' => 'ȳ',
  33674. 'Ⱥ' => 'ⱥ',
  33675. 'Ȼ' => 'ȼ',
  33676. 'Ƚ' => 'ƚ',
  33677. 'Ⱦ' => 'ⱦ',
  33678. '�' => 'ɂ',
  33679. 'Ƀ' => 'ƀ',
  33680. 'Ʉ' => 'ʉ',
  33681. 'Ʌ' => 'ʌ',
  33682. 'Ɇ' => 'ɇ',
  33683. 'Ɉ' => 'ɉ',
  33684. 'ÉŠ' => 'É‹',
  33685. 'Ɍ' => '�',
  33686. 'Ɏ' => '�',
  33687. 'Ͱ' => 'ͱ',
  33688. 'Ͳ' => 'ͳ',
  33689. 'Ͷ' => 'ͷ',
  33690. 'Ϳ' => 'ϳ',
  33691. 'Ά' => 'ά',
  33692. 'Έ' => 'έ',
  33693. 'Ή' => 'ή',
  33694. 'Ί' => 'ί',
  33695. 'Ό' => 'ό',
  33696. 'Ύ' => '�',
  33697. '�' => 'ώ',
  33698. 'Α' => 'α',
  33699. 'Β' => 'β',
  33700. 'Γ' => 'γ',
  33701. 'Δ' => 'δ',
  33702. 'Ε' => 'ε',
  33703. 'Ζ' => 'ζ',
  33704. 'Η' => 'η',
  33705. 'Θ' => 'θ',
  33706. 'Ι' => 'ι',
  33707. 'Κ' => 'κ',
  33708. 'Λ' => 'λ',
  33709. 'Μ' => 'μ',
  33710. '�' => 'ν',
  33711. 'Ξ' => 'ξ',
  33712. 'Ο' => 'ο',
  33713. 'Π' => 'π',
  33714. 'Ρ' => '�',
  33715. 'Σ' => 'σ',
  33716. 'Τ' => 'τ',
  33717. 'Î¥' => 'Ï…',
  33718. 'Φ' => 'φ',
  33719. 'Χ' => 'χ',
  33720. 'Ψ' => 'ψ',
  33721. 'Ω' => 'ω',
  33722. 'Ϊ' => 'ϊ',
  33723. 'Ϋ' => 'ϋ',
  33724. '�' => 'ϗ',
  33725. 'Ϙ' => 'ϙ',
  33726. 'Ïš' => 'Ï›',
  33727. 'Ϝ' => '�',
  33728. 'Ïž' => 'ÏŸ',
  33729. 'Ï ' => 'Ï¡',
  33730. 'Ï¢' => 'Ï£',
  33731. 'Ϥ' => 'ϥ',
  33732. 'Ϧ' => 'ϧ',
  33733. 'Ϩ' => 'ϩ',
  33734. 'Ϫ' => 'ϫ',
  33735. 'Ϭ' => 'ϭ',
  33736. 'Ϯ' => 'ϯ',
  33737. 'ϴ' => 'θ',
  33738. 'Ϸ' => 'ϸ',
  33739. 'Ϲ' => 'ϲ',
  33740. 'Ϻ' => 'ϻ',
  33741. 'Ͻ' => 'ͻ',
  33742. 'Ͼ' => 'ͼ',
  33743. 'Ͽ' => 'ͽ',
  33744. 'Ѐ' => '�',
  33745. '�' => 'ё',
  33746. 'Ђ' => 'ђ',
  33747. 'Ѓ' => 'ѓ',
  33748. 'Є' => 'є',
  33749. 'Ð…' => 'Ñ•',
  33750. 'І' => 'і',
  33751. 'Ї' => 'ї',
  33752. 'Ј' => 'ј',
  33753. 'Љ' => 'љ',
  33754. 'Њ' => 'њ',
  33755. 'Ћ' => 'ћ',
  33756. 'Ќ' => 'ќ',
  33757. '�' => '�',
  33758. 'ÐŽ' => 'Ñž',
  33759. '�' => 'џ',
  33760. '�' => 'а',
  33761. 'Б' => 'б',
  33762. 'В' => 'в',
  33763. 'Г' => 'г',
  33764. 'Д' => 'д',
  33765. 'Е' => 'е',
  33766. 'Ж' => 'ж',
  33767. 'З' => 'з',
  33768. 'И' => 'и',
  33769. 'Й' => 'й',
  33770. 'К' => 'к',
  33771. 'Л' => 'л',
  33772. 'М' => 'м',
  33773. '�' => 'н',
  33774. 'О' => 'о',
  33775. 'П' => 'п',
  33776. 'Р' => 'р',
  33777. 'С' => '�',
  33778. 'Т' => 'т',
  33779. 'У' => 'у',
  33780. 'Ф' => 'ф',
  33781. 'Ð¥' => 'Ñ…',
  33782. 'Ц' => 'ц',
  33783. 'Ч' => 'ч',
  33784. 'Ш' => 'ш',
  33785. 'Щ' => 'щ',
  33786. 'Ъ' => 'ъ',
  33787. 'Ы' => 'ы',
  33788. 'Ь' => 'ь',
  33789. 'Э' => '�',
  33790. 'Ю' => 'ю',
  33791. 'Я' => '�',
  33792. 'Ñ ' => 'Ñ¡',
  33793. 'Ñ¢' => 'Ñ£',
  33794. 'Ѥ' => 'ѥ',
  33795. 'Ѧ' => 'ѧ',
  33796. 'Ѩ' => 'ѩ',
  33797. 'Ѫ' => 'ѫ',
  33798. 'Ѭ' => 'ѭ',
  33799. 'Ѯ' => 'ѯ',
  33800. 'Ѱ' => 'ѱ',
  33801. 'Ѳ' => 'ѳ',
  33802. 'Ѵ' => 'ѵ',
  33803. 'Ѷ' => 'ѷ',
  33804. 'Ѹ' => 'ѹ',
  33805. 'Ѻ' => 'ѻ',
  33806. 'Ѽ' => 'ѽ',
  33807. 'Ѿ' => 'ѿ',
  33808. 'Ò€' => 'Ò�',
  33809. 'ÒŠ' => 'Ò‹',
  33810. 'Ҍ' => '�',
  33811. 'ÒŽ' => 'Ò�',
  33812. 'Ò�' => 'Ò‘',
  33813. 'Ò’' => 'Ò“',
  33814. 'Ò”' => 'Ò•',
  33815. 'Ò–' => 'Ò—',
  33816. 'Ò˜' => 'Ò™',
  33817. 'Òš' => 'Ò›',
  33818. 'Ҝ' => '�',
  33819. 'Òž' => 'ÒŸ',
  33820. 'Ò ' => 'Ò¡',
  33821. 'Ò¢' => 'Ò£',
  33822. 'Ò¤' => 'Ò¥',
  33823. 'Ò¦' => 'Ò§',
  33824. 'Ò¨' => 'Ò©',
  33825. 'Òª' => 'Ò«',
  33826. 'Ò¬' => 'Ò­',
  33827. 'Ò®' => 'Ò¯',
  33828. 'Ò°' => 'Ò±',
  33829. 'Ò²' => 'Ò³',
  33830. 'Ò´' => 'Òµ',
  33831. 'Ò¶' => 'Ò·',
  33832. 'Ò¸' => 'Ò¹',
  33833. 'Òº' => 'Ò»',
  33834. 'Ò¼' => 'Ò½',
  33835. 'Ò¾' => 'Ò¿',
  33836. 'Ó€' => 'Ó�',
  33837. 'Ó�' => 'Ó‚',
  33838. 'Óƒ' => 'Ó„',
  33839. 'Ó…' => 'Ó†',
  33840. 'Ó‡' => 'Óˆ',
  33841. 'Ó‰' => 'ÓŠ',
  33842. 'Ӌ' => 'ӌ',
  33843. 'Ó�' => 'ÓŽ',
  33844. 'Ó�' => 'Ó‘',
  33845. 'Ó’' => 'Ó“',
  33846. 'Ó”' => 'Ó•',
  33847. 'Ó–' => 'Ó—',
  33848. 'Ó˜' => 'Ó™',
  33849. 'Óš' => 'Ó›',
  33850. 'Ӝ' => '�',
  33851. 'Óž' => 'ÓŸ',
  33852. 'Ó ' => 'Ó¡',
  33853. 'Ó¢' => 'Ó£',
  33854. 'Ó¤' => 'Ó¥',
  33855. 'Ó¦' => 'Ó§',
  33856. 'Ó¨' => 'Ó©',
  33857. 'Óª' => 'Ó«',
  33858. 'Ó¬' => 'Ó­',
  33859. 'Ó®' => 'Ó¯',
  33860. 'Ó°' => 'Ó±',
  33861. 'Ó²' => 'Ó³',
  33862. 'Ó´' => 'Óµ',
  33863. 'Ó¶' => 'Ó·',
  33864. 'Ó¸' => 'Ó¹',
  33865. 'Óº' => 'Ó»',
  33866. 'Ó¼' => 'Ó½',
  33867. 'Ó¾' => 'Ó¿',
  33868. 'Ô€' => 'Ô�',
  33869. 'Ô‚' => 'Ôƒ',
  33870. 'Ô„' => 'Ô…',
  33871. 'Ô†' => 'Ô‡',
  33872. 'Ôˆ' => 'Ô‰',
  33873. 'ÔŠ' => 'Ô‹',
  33874. 'Ԍ' => '�',
  33875. 'ÔŽ' => 'Ô�',
  33876. 'Ô�' => 'Ô‘',
  33877. 'Ô’' => 'Ô“',
  33878. 'Ô”' => 'Ô•',
  33879. 'Ô–' => 'Ô—',
  33880. 'Ô˜' => 'Ô™',
  33881. 'Ôš' => 'Ô›',
  33882. 'Ԝ' => '�',
  33883. 'Ôž' => 'ÔŸ',
  33884. 'Ô ' => 'Ô¡',
  33885. 'Ô¢' => 'Ô£',
  33886. 'Ô¤' => 'Ô¥',
  33887. 'Ô¦' => 'Ô§',
  33888. 'Ô¨' => 'Ô©',
  33889. 'Ôª' => 'Ô«',
  33890. 'Ô¬' => 'Ô­',
  33891. 'Ô®' => 'Ô¯',
  33892. 'Ô±' => 'Õ¡',
  33893. 'Ô²' => 'Õ¢',
  33894. 'Ô³' => 'Õ£',
  33895. 'Ô´' => 'Õ¤',
  33896. 'Ôµ' => 'Õ¥',
  33897. 'Ô¶' => 'Õ¦',
  33898. 'Ô·' => 'Õ§',
  33899. 'Ô¸' => 'Õ¨',
  33900. 'Ô¹' => 'Õ©',
  33901. 'Ôº' => 'Õª',
  33902. 'Ô»' => 'Õ«',
  33903. 'Ô¼' => 'Õ¬',
  33904. 'Ô½' => 'Õ­',
  33905. 'Ô¾' => 'Õ®',
  33906. 'Ô¿' => 'Õ¯',
  33907. 'Õ€' => 'Õ°',
  33908. 'Õ�' => 'Õ±',
  33909. 'Õ‚' => 'Õ²',
  33910. 'Õƒ' => 'Õ³',
  33911. 'Õ„' => 'Õ´',
  33912. 'Õ…' => 'Õµ',
  33913. 'Õ†' => 'Õ¶',
  33914. 'Õ‡' => 'Õ·',
  33915. 'Õˆ' => 'Õ¸',
  33916. 'Õ‰' => 'Õ¹',
  33917. 'ÕŠ' => 'Õº',
  33918. 'Õ‹' => 'Õ»',
  33919. 'Ռ' => 'ռ',
  33920. 'Õ�' => 'Õ½',
  33921. 'ÕŽ' => 'Õ¾',
  33922. 'Õ�' => 'Õ¿',
  33923. 'Õ�' => 'Ö€',
  33924. 'Õ‘' => 'Ö�',
  33925. 'Õ’' => 'Ö‚',
  33926. 'Õ“' => 'Öƒ',
  33927. 'Õ”' => 'Ö„',
  33928. 'Õ•' => 'Ö…',
  33929. 'Õ–' => 'Ö†',
  33930. 'á‚ ' => 'â´€',
  33931. 'á‚¡' => 'â´�',
  33932. 'á‚¢' => 'â´‚',
  33933. 'á‚£' => 'â´ƒ',
  33934. 'Ⴄ' => 'ⴄ',
  33935. 'á‚¥' => 'â´…',
  33936. 'Ⴆ' => 'ⴆ',
  33937. 'á‚§' => 'â´‡',
  33938. 'Ⴈ' => 'ⴈ',
  33939. 'á‚©' => 'â´‰',
  33940. 'Ⴊ' => 'ⴊ',
  33941. 'á‚«' => 'â´‹',
  33942. 'Ⴌ' => 'ⴌ',
  33943. 'á‚­' => 'â´�',
  33944. 'á‚®' => 'â´Ž',
  33945. 'Ⴏ' => '�',
  33946. 'á‚°' => 'â´�',
  33947. 'Ⴑ' => 'ⴑ',
  33948. 'Ⴒ' => 'ⴒ',
  33949. 'Ⴓ' => 'ⴓ',
  33950. 'á‚´' => 'â´”',
  33951. 'Ⴕ' => 'ⴕ',
  33952. 'á‚¶' => 'â´–',
  33953. 'á‚·' => 'â´—',
  33954. 'Ⴘ' => 'ⴘ',
  33955. 'Ⴙ' => 'ⴙ',
  33956. 'Ⴚ' => 'ⴚ',
  33957. 'á‚»' => 'â´›',
  33958. 'Ⴜ' => 'ⴜ',
  33959. 'Ⴝ' => '�',
  33960. 'Ⴞ' => 'ⴞ',
  33961. 'á‚¿' => 'â´Ÿ',
  33962. 'Ⴠ' => 'ⴠ',
  33963. '�' => 'ⴡ',
  33964. 'Ⴢ' => 'ⴢ',
  33965. 'Ⴣ' => 'ⴣ',
  33966. 'Ⴤ' => 'ⴤ',
  33967. 'Ⴥ' => 'ⴥ',
  33968. 'Ⴧ' => 'ⴧ',
  33969. '�' => 'ⴭ',
  33970. 'Ḁ' => '�',
  33971. 'Ḃ' => 'ḃ',
  33972. 'Ḅ' => 'ḅ',
  33973. 'Ḇ' => 'ḇ',
  33974. 'Ḉ' => 'ḉ',
  33975. 'Ḋ' => 'ḋ',
  33976. 'Ḍ' => '�',
  33977. 'Ḏ' => '�',
  33978. '�' => 'ḑ',
  33979. 'Ḓ' => 'ḓ',
  33980. 'Ḕ' => 'ḕ',
  33981. 'Ḗ' => 'ḗ',
  33982. 'Ḙ' => 'ḙ',
  33983. 'Ḛ' => 'ḛ',
  33984. 'Ḝ' => '�',
  33985. 'Ḟ' => 'ḟ',
  33986. 'Ḡ' => 'ḡ',
  33987. 'Ḣ' => 'ḣ',
  33988. 'Ḥ' => 'ḥ',
  33989. 'Ḧ' => 'ḧ',
  33990. 'Ḩ' => 'ḩ',
  33991. 'Ḫ' => 'ḫ',
  33992. 'Ḭ' => 'ḭ',
  33993. 'Ḯ' => 'ḯ',
  33994. 'Ḱ' => 'ḱ',
  33995. 'Ḳ' => 'ḳ',
  33996. 'Ḵ' => 'ḵ',
  33997. 'Ḷ' => 'ḷ',
  33998. 'Ḹ' => 'ḹ',
  33999. 'Ḻ' => 'ḻ',
  34000. 'Ḽ' => 'ḽ',
  34001. 'Ḿ' => 'ḿ',
  34002. 'Ṁ' => '�',
  34003. 'Ṃ' => 'ṃ',
  34004. 'Ṅ' => 'ṅ',
  34005. 'Ṇ' => 'ṇ',
  34006. 'Ṉ' => 'ṉ',
  34007. 'Ṋ' => 'ṋ',
  34008. 'Ṍ' => '�',
  34009. 'Ṏ' => '�',
  34010. '�' => 'ṑ',
  34011. 'Ṓ' => 'ṓ',
  34012. 'Ṕ' => 'ṕ',
  34013. 'á¹–' => 'á¹—',
  34014. 'Ṙ' => 'ṙ',
  34015. 'Ṛ' => 'ṛ',
  34016. 'Ṝ' => '�',
  34017. 'Ṟ' => 'ṟ',
  34018. 'Ṡ' => 'ṡ',
  34019. 'á¹¢' => 'á¹£',
  34020. 'Ṥ' => 'ṥ',
  34021. 'Ṧ' => 'ṧ',
  34022. 'Ṩ' => 'ṩ',
  34023. 'Ṫ' => 'ṫ',
  34024. 'Ṭ' => 'ṭ',
  34025. 'Ṯ' => 'ṯ',
  34026. 'á¹°' => 'á¹±',
  34027. 'á¹²' => 'á¹³',
  34028. 'á¹´' => 'á¹µ',
  34029. 'á¹¶' => 'á¹·',
  34030. 'Ṹ' => 'ṹ',
  34031. 'Ṻ' => 'ṻ',
  34032. 'á¹¼' => 'á¹½',
  34033. 'Ṿ' => 'ṿ',
  34034. 'Ẁ' => '�',
  34035. 'Ẃ' => 'ẃ',
  34036. 'Ẅ' => 'ẅ',
  34037. 'Ẇ' => 'ẇ',
  34038. 'Ẉ' => 'ẉ',
  34039. 'Ẋ' => 'ẋ',
  34040. 'Ẍ' => '�',
  34041. 'Ẏ' => '�',
  34042. '�' => 'ẑ',
  34043. 'Ẓ' => 'ẓ',
  34044. 'Ẕ' => 'ẕ',
  34045. 'ẞ' => 'ß',
  34046. 'Ạ' => 'ạ',
  34047. 'Ả' => 'ả',
  34048. 'Ấ' => 'ấ',
  34049. 'Ầ' => 'ầ',
  34050. 'Ẩ' => 'ẩ',
  34051. 'Ẫ' => 'ẫ',
  34052. 'Ậ' => 'ậ',
  34053. 'Ắ' => 'ắ',
  34054. 'Ằ' => 'ằ',
  34055. 'Ẳ' => 'ẳ',
  34056. 'Ẵ' => 'ẵ',
  34057. 'Ặ' => 'ặ',
  34058. 'Ẹ' => 'ẹ',
  34059. 'Ẻ' => 'ẻ',
  34060. 'Ẽ' => 'ẽ',
  34061. 'Ế' => 'ế',
  34062. 'Ề' => '�',
  34063. 'Ể' => 'ể',
  34064. 'Ễ' => 'ễ',
  34065. 'Ệ' => 'ệ',
  34066. 'Ỉ' => 'ỉ',
  34067. 'Ị' => 'ị',
  34068. 'Ọ' => '�',
  34069. 'Ỏ' => '�',
  34070. '�' => 'ố',
  34071. 'Ồ' => 'ồ',
  34072. 'Ổ' => 'ổ',
  34073. 'á»–' => 'á»—',
  34074. 'Ộ' => 'ộ',
  34075. 'Ớ' => 'ớ',
  34076. 'Ờ' => '�',
  34077. 'Ở' => 'ở',
  34078. 'Ỡ' => 'ỡ',
  34079. 'Ợ' => 'ợ',
  34080. 'Ụ' => 'ụ',
  34081. 'Ủ' => 'ủ',
  34082. 'Ứ' => 'ứ',
  34083. 'Ừ' => 'ừ',
  34084. 'Ử' => 'ử',
  34085. 'Ữ' => 'ữ',
  34086. 'á»°' => 'á»±',
  34087. 'Ỳ' => 'ỳ',
  34088. 'Ỵ' => 'ỵ',
  34089. 'á»¶' => 'á»·',
  34090. 'Ỹ' => 'ỹ',
  34091. 'Ỻ' => 'ỻ',
  34092. 'Ỽ' => 'ỽ',
  34093. 'Ỿ' => 'ỿ',
  34094. 'Ἀ' => 'ἀ',
  34095. 'Ἁ' => '�',
  34096. 'Ἂ' => 'ἂ',
  34097. 'Ἃ' => 'ἃ',
  34098. 'Ἄ' => 'ἄ',
  34099. '�' => 'ἅ',
  34100. 'Ἆ' => 'ἆ',
  34101. '�' => 'ἇ',
  34102. 'Ἐ' => '�',
  34103. 'Ἑ' => 'ἑ',
  34104. 'Ἒ' => 'ἒ',
  34105. 'Ἓ' => 'ἓ',
  34106. 'Ἔ' => 'ἔ',
  34107. '�' => 'ἕ',
  34108. 'Ἠ' => 'ἠ',
  34109. 'Ἡ' => 'ἡ',
  34110. 'Ἢ' => 'ἢ',
  34111. 'Ἣ' => 'ἣ',
  34112. 'Ἤ' => 'ἤ',
  34113. 'á¼­' => 'á¼¥',
  34114. 'Ἦ' => 'ἦ',
  34115. 'Ἧ' => 'ἧ',
  34116. 'Ἰ' => 'ἰ',
  34117. 'á¼¹' => 'á¼±',
  34118. 'Ἲ' => 'ἲ',
  34119. 'á¼»' => 'á¼³',
  34120. 'á¼¼' => 'á¼´',
  34121. 'á¼½' => 'á¼µ',
  34122. 'á¼¾' => 'á¼¶',
  34123. 'Ἷ' => 'ἷ',
  34124. 'Ὀ' => 'ὀ',
  34125. 'Ὁ' => '�',
  34126. 'Ὂ' => 'ὂ',
  34127. 'Ὃ' => 'ὃ',
  34128. 'Ὄ' => 'ὄ',
  34129. '�' => 'ὅ',
  34130. 'Ὑ' => 'ὑ',
  34131. 'Ὓ' => 'ὓ',
  34132. '�' => 'ὕ',
  34133. 'Ὗ' => 'ὗ',
  34134. 'Ὠ' => 'ὠ',
  34135. 'Ὡ' => 'ὡ',
  34136. 'Ὢ' => 'ὢ',
  34137. 'Ὣ' => 'ὣ',
  34138. 'Ὤ' => 'ὤ',
  34139. 'á½­' => 'á½¥',
  34140. 'Ὦ' => 'ὦ',
  34141. 'Ὧ' => 'ὧ',
  34142. 'ᾈ' => 'ᾀ',
  34143. 'ᾉ' => '�',
  34144. 'ᾊ' => 'ᾂ',
  34145. 'ᾋ' => 'ᾃ',
  34146. 'ᾌ' => 'ᾄ',
  34147. '�' => 'ᾅ',
  34148. 'ᾎ' => 'ᾆ',
  34149. '�' => 'ᾇ',
  34150. 'ᾘ' => '�',
  34151. 'ᾙ' => 'ᾑ',
  34152. 'ᾚ' => 'ᾒ',
  34153. 'ᾛ' => 'ᾓ',
  34154. 'ᾜ' => 'ᾔ',
  34155. '�' => 'ᾕ',
  34156. 'ᾞ' => 'ᾖ',
  34157. 'ᾟ' => 'ᾗ',
  34158. 'ᾨ' => 'ᾠ',
  34159. 'ᾩ' => 'ᾡ',
  34160. 'ᾪ' => 'ᾢ',
  34161. 'ᾫ' => 'ᾣ',
  34162. 'ᾬ' => 'ᾤ',
  34163. 'á¾­' => 'á¾¥',
  34164. 'ᾮ' => 'ᾦ',
  34165. 'ᾯ' => 'ᾧ',
  34166. 'Ᾰ' => 'ᾰ',
  34167. 'á¾¹' => 'á¾±',
  34168. 'Ὰ' => 'ὰ',
  34169. 'á¾»' => 'á½±',
  34170. 'á¾¼' => 'á¾³',
  34171. 'Ὲ' => 'ὲ',
  34172. 'Έ' => 'έ',
  34173. 'Ὴ' => 'ὴ',
  34174. 'á¿‹' => 'á½µ',
  34175. 'ῌ' => 'ῃ',
  34176. 'Ῐ' => '�',
  34177. 'á¿™' => 'á¿‘',
  34178. 'Ὶ' => 'ὶ',
  34179. 'á¿›' => 'á½·',
  34180. 'Ῠ' => 'ῠ',
  34181. 'á¿©' => 'á¿¡',
  34182. 'Ὺ' => 'ὺ',
  34183. 'á¿«' => 'á½»',
  34184. 'Ῥ' => 'ῥ',
  34185. 'Ὸ' => 'ὸ',
  34186. 'Ό' => 'ό',
  34187. 'Ὼ' => 'ὼ',
  34188. 'á¿»' => 'á½½',
  34189. 'ῼ' => 'ῳ',
  34190. 'Ω' => 'ω',
  34191. 'K' => 'k',
  34192. 'â„«' => 'Ã¥',
  34193. 'Ⅎ' => 'ⅎ',
  34194. 'â… ' => 'â…°',
  34195. 'â…¡' => 'â…±',
  34196. 'â…¢' => 'â…²',
  34197. 'â…£' => 'â…³',
  34198. 'â…¤' => 'â…´',
  34199. 'â…¥' => 'â…µ',
  34200. 'â…¦' => 'â…¶',
  34201. 'â…§' => 'â…·',
  34202. 'â…¨' => 'â…¸',
  34203. 'â…©' => 'â…¹',
  34204. 'â…ª' => 'â…º',
  34205. 'â…«' => 'â…»',
  34206. 'â…¬' => 'â…¼',
  34207. 'â…­' => 'â…½',
  34208. 'â…®' => 'â…¾',
  34209. 'â…¯' => 'â…¿',
  34210. 'Ↄ' => 'ↄ',
  34211. 'Ⓐ' => '�',
  34212. 'â’·' => 'â“‘',
  34213. 'â’¸' => 'â“’',
  34214. 'â’¹' => 'â““',
  34215. 'â’º' => 'â“”',
  34216. 'â’»' => 'â“•',
  34217. 'â’¼' => 'â“–',
  34218. 'â’½' => 'â“—',
  34219. 'Ⓘ' => 'ⓘ',
  34220. 'â’¿' => 'â“™',
  34221. 'Ⓚ' => 'ⓚ',
  34222. '�' => 'ⓛ',
  34223. 'Ⓜ' => 'ⓜ',
  34224. 'Ⓝ' => '�',
  34225. 'Ⓞ' => 'ⓞ',
  34226. 'Ⓟ' => 'ⓟ',
  34227. 'Ⓠ' => 'ⓠ',
  34228. 'Ⓡ' => 'ⓡ',
  34229. 'Ⓢ' => 'ⓢ',
  34230. 'Ⓣ' => 'ⓣ',
  34231. 'Ⓤ' => 'ⓤ',
  34232. 'â“‹' => 'â“¥',
  34233. 'Ⓦ' => 'ⓦ',
  34234. '�' => 'ⓧ',
  34235. 'Ⓨ' => 'ⓨ',
  34236. '�' => 'ⓩ',
  34237. 'â°€' => 'â°°',
  34238. 'â°�' => 'â°±',
  34239. 'â°‚' => 'â°²',
  34240. 'â°ƒ' => 'â°³',
  34241. 'â°„' => 'â°´',
  34242. 'â°…' => 'â°µ',
  34243. 'â°†' => 'â°¶',
  34244. 'â°‡' => 'â°·',
  34245. 'â°ˆ' => 'â°¸',
  34246. 'â°‰' => 'â°¹',
  34247. 'â°Š' => 'â°º',
  34248. 'â°‹' => 'â°»',
  34249. 'Ⰼ' => 'ⰼ',
  34250. 'â°�' => 'â°½',
  34251. 'â°Ž' => 'â°¾',
  34252. 'â°�' => 'â°¿',
  34253. 'â°�' => 'â±€',
  34254. 'Ⱁ' => '�',
  34255. 'Ⱂ' => 'ⱂ',
  34256. 'Ⱃ' => 'ⱃ',
  34257. 'Ⱄ' => 'ⱄ',
  34258. 'â°•' => 'â±…',
  34259. 'Ⱆ' => 'ⱆ',
  34260. 'Ⱇ' => 'ⱇ',
  34261. 'Ⱈ' => 'ⱈ',
  34262. 'Ⱉ' => 'ⱉ',
  34263. 'Ⱊ' => 'ⱊ',
  34264. 'Ⱋ' => 'ⱋ',
  34265. 'Ⱌ' => 'ⱌ',
  34266. '�' => '�',
  34267. 'Ⱎ' => 'ⱎ',
  34268. 'Ⱏ' => '�',
  34269. 'Ⱐ' => '�',
  34270. 'Ⱑ' => 'ⱑ',
  34271. 'â°¢' => 'â±’',
  34272. 'Ⱓ' => 'ⱓ',
  34273. 'â°¤' => 'â±”',
  34274. 'Ⱕ' => 'ⱕ',
  34275. 'â°¦' => 'â±–',
  34276. 'â°§' => 'â±—',
  34277. 'Ⱘ' => 'ⱘ',
  34278. 'â°©' => 'â±™',
  34279. 'Ⱚ' => 'ⱚ',
  34280. 'â°«' => 'â±›',
  34281. 'Ⱜ' => 'ⱜ',
  34282. 'Ⱝ' => '�',
  34283. 'Ⱞ' => 'ⱞ',
  34284. 'Ⱡ' => 'ⱡ',
  34285. 'â±¢' => 'É«',
  34286. 'â±£' => 'áµ½',
  34287. 'Ɽ' => 'ɽ',
  34288. 'Ⱨ' => 'ⱨ',
  34289. 'Ⱪ' => 'ⱪ',
  34290. 'Ⱬ' => 'ⱬ',
  34291. 'â±­' => 'É‘',
  34292. 'Ɱ' => 'ɱ',
  34293. 'Ɐ' => '�',
  34294. 'â±°' => 'É’',
  34295. 'â±²' => 'â±³',
  34296. 'â±µ' => 'â±¶',
  34297. 'â±¾' => 'È¿',
  34298. 'Ɀ' => 'ɀ',
  34299. 'Ⲁ' => '�',
  34300. 'Ⲃ' => 'ⲃ',
  34301. 'Ⲅ' => 'ⲅ',
  34302. 'Ⲇ' => 'ⲇ',
  34303. 'Ⲉ' => 'ⲉ',
  34304. 'Ⲋ' => 'ⲋ',
  34305. 'Ⲍ' => '�',
  34306. 'Ⲏ' => '�',
  34307. '�' => 'ⲑ',
  34308. 'Ⲓ' => 'ⲓ',
  34309. 'Ⲕ' => 'ⲕ',
  34310. 'â²–' => 'â²—',
  34311. 'Ⲙ' => 'ⲙ',
  34312. 'Ⲛ' => 'ⲛ',
  34313. 'Ⲝ' => '�',
  34314. 'Ⲟ' => 'ⲟ',
  34315. 'Ⲡ' => 'ⲡ',
  34316. 'â²¢' => 'â²£',
  34317. 'Ⲥ' => 'ⲥ',
  34318. 'Ⲧ' => 'ⲧ',
  34319. 'Ⲩ' => 'ⲩ',
  34320. 'Ⲫ' => 'ⲫ',
  34321. 'Ⲭ' => 'ⲭ',
  34322. 'Ⲯ' => 'ⲯ',
  34323. 'â²°' => 'â²±',
  34324. 'â²²' => 'â²³',
  34325. 'â²´' => 'â²µ',
  34326. 'â²¶' => 'â²·',
  34327. 'Ⲹ' => 'ⲹ',
  34328. 'Ⲻ' => 'ⲻ',
  34329. 'â²¼' => 'â²½',
  34330. 'Ⲿ' => 'ⲿ',
  34331. 'Ⳁ' => '�',
  34332. 'Ⳃ' => 'ⳃ',
  34333. 'Ⳅ' => 'ⳅ',
  34334. 'Ⳇ' => 'ⳇ',
  34335. 'Ⳉ' => 'ⳉ',
  34336. 'Ⳋ' => 'ⳋ',
  34337. 'Ⳍ' => '�',
  34338. 'Ⳏ' => '�',
  34339. '�' => 'ⳑ',
  34340. 'Ⳓ' => 'ⳓ',
  34341. 'Ⳕ' => 'ⳕ',
  34342. 'â³–' => 'â³—',
  34343. 'Ⳙ' => 'ⳙ',
  34344. 'Ⳛ' => 'ⳛ',
  34345. 'Ⳝ' => '�',
  34346. 'Ⳟ' => 'ⳟ',
  34347. 'Ⳡ' => 'ⳡ',
  34348. 'â³¢' => 'â³£',
  34349. 'Ⳬ' => 'ⳬ',
  34350. 'â³­' => 'â³®',
  34351. 'â³²' => 'â³³',
  34352. 'Ꙁ' => '�',
  34353. 'Ꙃ' => 'ꙃ',
  34354. 'Ꙅ' => 'ꙅ',
  34355. 'Ꙇ' => 'ꙇ',
  34356. 'Ꙉ' => 'ꙉ',
  34357. 'Ꙋ' => 'ꙋ',
  34358. 'Ꙍ' => '�',
  34359. 'Ꙏ' => '�',
  34360. '�' => 'ꙑ',
  34361. 'Ꙓ' => 'ꙓ',
  34362. 'Ꙕ' => 'ꙕ',
  34363. 'ê™–' => 'ê™—',
  34364. 'Ꙙ' => 'ꙙ',
  34365. 'Ꙛ' => 'ꙛ',
  34366. 'Ꙝ' => '�',
  34367. 'Ꙟ' => 'ꙟ',
  34368. 'Ꙡ' => 'ꙡ',
  34369. 'Ꙣ' => 'ꙣ',
  34370. 'Ꙥ' => 'ꙥ',
  34371. 'Ꙧ' => 'ꙧ',
  34372. 'Ꙩ' => 'ꙩ',
  34373. 'Ꙫ' => 'ꙫ',
  34374. 'Ꙭ' => 'ꙭ',
  34375. 'Ꚁ' => '�',
  34376. 'Ꚃ' => 'ꚃ',
  34377. 'êš„' => 'êš…',
  34378. 'Ꚇ' => 'ꚇ',
  34379. 'Ꚉ' => 'ꚉ',
  34380. 'Ꚋ' => 'ꚋ',
  34381. 'Ꚍ' => '�',
  34382. 'Ꚏ' => '�',
  34383. '�' => 'ꚑ',
  34384. 'êš’' => 'êš“',
  34385. 'êš”' => 'êš•',
  34386. 'êš–' => 'êš—',
  34387. 'Ꚙ' => 'ꚙ',
  34388. 'êšš' => 'êš›',
  34389. 'Ꜣ' => 'ꜣ',
  34390. 'Ꜥ' => 'ꜥ',
  34391. 'Ꜧ' => 'ꜧ',
  34392. 'Ꜩ' => 'ꜩ',
  34393. 'Ꜫ' => 'ꜫ',
  34394. 'Ꜭ' => 'ꜭ',
  34395. 'Ꜯ' => 'ꜯ',
  34396. 'Ꜳ' => 'ꜳ',
  34397. 'Ꜵ' => 'ꜵ',
  34398. 'Ꜷ' => 'ꜷ',
  34399. 'Ꜹ' => 'ꜹ',
  34400. 'Ꜻ' => 'ꜻ',
  34401. 'Ꜽ' => 'ꜽ',
  34402. 'Ꜿ' => 'ꜿ',
  34403. '�' => '�',
  34404. '�' => '�',
  34405. '�' => '�',
  34406. '�' => '�',
  34407. '�' => '�',
  34408. '�' => '�',
  34409. '�' => '�',
  34410. '�' => '�',
  34411. '�' => '�',
  34412. '�' => '�',
  34413. '�' => '�',
  34414. '�' => '�',
  34415. '�' => '�',
  34416. '�' => '�',
  34417. '�' => '�',
  34418. '�' => '�',
  34419. '�' => '�',
  34420. '�' => '�',
  34421. '�' => '�',
  34422. '�' => '�',
  34423. '�' => '�',
  34424. '�' => '�',
  34425. '�' => '�',
  34426. '�' => '�',
  34427. '�' => '�',
  34428. '�' => '�',
  34429. '�' => 'ᵹ',
  34430. '�' => '�',
  34431. 'Ꞁ' => '�',
  34432. 'Ꞃ' => 'ꞃ',
  34433. 'êž„' => 'êž…',
  34434. 'Ꞇ' => 'ꞇ',
  34435. 'Ꞌ' => 'ꞌ',
  34436. '�' => 'ɥ',
  34437. '�' => 'ꞑ',
  34438. 'êž’' => 'êž“',
  34439. 'êž–' => 'êž—',
  34440. 'Ꞙ' => 'ꞙ',
  34441. 'êžš' => 'êž›',
  34442. 'Ꞝ' => '�',
  34443. 'Ꞟ' => 'ꞟ',
  34444. 'êž ' => 'êž¡',
  34445. 'Ꞣ' => 'ꞣ',
  34446. 'Ꞥ' => 'ꞥ',
  34447. 'Ꞧ' => 'ꞧ',
  34448. 'Ꞩ' => 'ꞩ',
  34449. 'Ɦ' => 'ɦ',
  34450. 'Ɜ' => 'ɜ',
  34451. 'Ɡ' => 'ɡ',
  34452. 'Ɬ' => 'ɬ',
  34453. 'êž°' => 'Êž',
  34454. 'Ʇ' => 'ʇ',
  34455. 'A' => '�',
  34456. 'B' => 'b',
  34457. 'C' => 'c',
  34458. 'D' => 'd',
  34459. 'ï¼¥' => 'ï½…',
  34460. 'F' => 'f',
  34461. 'G' => 'g',
  34462. 'H' => 'h',
  34463. 'I' => 'i',
  34464. 'J' => 'j',
  34465. 'K' => 'k',
  34466. 'L' => 'l',
  34467. 'M' => '�',
  34468. 'N' => 'n',
  34469. 'O' => '�',
  34470. 'P' => '�',
  34471. 'Q' => 'q',
  34472. 'ï¼²' => 'ï½’',
  34473. 'S' => 's',
  34474. 'ï¼´' => 'ï½”',
  34475. 'U' => 'u',
  34476. 'ï¼¶' => 'ï½–',
  34477. 'ï¼·' => 'ï½—',
  34478. 'X' => 'x',
  34479. 'ï¼¹' => 'ï½™',
  34480. 'Z' => 'z',
  34481. '�' => '�',
  34482. '�' => '�',
  34483. '�' => '�',
  34484. '�' => '�',
  34485. '�' => '�',
  34486. '�' => '�',
  34487. '�' => '�',
  34488. '�' => '�',
  34489. '�' => '�',
  34490. '�' => '�',
  34491. '�' => '�',
  34492. '�' => '�',
  34493. '�' => '�',
  34494. '�' => '�',
  34495. '�' => '�',
  34496. '�' => '�',
  34497. '�' => '�',
  34498. '�' => '�',
  34499. '�' => '�',
  34500. '�' => '�',
  34501. '�' => '�',
  34502. '�' => '�',
  34503. '�' => '�',
  34504. '�' => '�',
  34505. '�' => '�',
  34506. '�' => '�',
  34507. '�' => '�',
  34508. '�' => '�',
  34509. '�' => '�',
  34510. '�' => '�',
  34511. '�' => '�',
  34512. '�' => '�',
  34513. '�' => '�',
  34514. '�' => '�',
  34515. '�' => '�',
  34516. '�' => '�',
  34517. '�' => '�',
  34518. '�' => '�',
  34519. '�' => '�',
  34520. '�' => '�',
  34521. 'ð‘¢ ' => 'ð‘£€',
  34522. '𑢡' => '�',
  34523. '𑢢' => '𑣂',
  34524. '𑢣' => '𑣃',
  34525. '𑢤' => '𑣄',
  34526. 'ð‘¢¥' => 'ð‘£…',
  34527. '𑢦' => '𑣆',
  34528. '𑢧' => '𑣇',
  34529. '𑢨' => '𑣈',
  34530. '𑢩' => '𑣉',
  34531. '𑢪' => '𑣊',
  34532. '𑢫' => '𑣋',
  34533. '𑢬' => '𑣌',
  34534. '𑢭' => '�',
  34535. '𑢮' => '𑣎',
  34536. '𑢯' => '�',
  34537. '𑢰' => '�',
  34538. '𑢱' => '𑣑',
  34539. 'ð‘¢²' => 'ð‘£’',
  34540. '𑢳' => '𑣓',
  34541. 'ð‘¢´' => 'ð‘£”',
  34542. '𑢵' => '𑣕',
  34543. 'ð‘¢¶' => 'ð‘£–',
  34544. 'ð‘¢·' => 'ð‘£—',
  34545. '𑢸' => '𑣘',
  34546. 'ð‘¢¹' => 'ð‘£™',
  34547. '𑢺' => '𑣚',
  34548. 'ð‘¢»' => 'ð‘£›',
  34549. '𑢼' => '𑣜',
  34550. '𑢽' => '�',
  34551. '𑢾' => '𑣞',
  34552. '𑢿' => '𑣟',
  34553. );
  34554. $result =& $data;
  34555. unset($data);
  34556. return $result;
  34557. <?php
  34558. static $data = array (
  34559. 'a' => 'A',
  34560. 'b' => 'B',
  34561. 'c' => 'C',
  34562. 'd' => 'D',
  34563. 'e' => 'E',
  34564. 'f' => 'F',
  34565. 'g' => 'G',
  34566. 'h' => 'H',
  34567. 'i' => 'I',
  34568. 'j' => 'J',
  34569. 'k' => 'K',
  34570. 'l' => 'L',
  34571. 'm' => 'M',
  34572. 'n' => 'N',
  34573. 'o' => 'O',
  34574. 'p' => 'P',
  34575. 'q' => 'Q',
  34576. 'r' => 'R',
  34577. 's' => 'S',
  34578. 't' => 'T',
  34579. 'u' => 'U',
  34580. 'v' => 'V',
  34581. 'w' => 'W',
  34582. 'x' => 'X',
  34583. 'y' => 'Y',
  34584. 'z' => 'Z',
  34585. 'µ' => 'Μ',
  34586. 'à' => 'À',
  34587. 'á' => '�',
  34588. 'â' => 'Â',
  34589. 'ã' => 'Ã',
  34590. 'ä' => 'Ä',
  34591. 'Ã¥' => 'Ã…',
  34592. 'æ' => 'Æ',
  34593. 'ç' => 'Ç',
  34594. 'è' => 'È',
  34595. 'é' => 'É',
  34596. 'ê' => 'Ê',
  34597. 'ë' => 'Ë',
  34598. 'ì' => 'Ì',
  34599. 'í' => '�',
  34600. 'î' => 'Î',
  34601. 'ï' => '�',
  34602. 'ð' => '�',
  34603. 'ñ' => 'Ñ',
  34604. 'ò' => 'Ò',
  34605. 'ó' => 'Ó',
  34606. 'ô' => 'Ô',
  34607. 'õ' => 'Õ',
  34608. 'ö' => 'Ö',
  34609. 'ø' => 'Ø',
  34610. 'ù' => 'Ù',
  34611. 'ú' => 'Ú',
  34612. 'û' => 'Û',
  34613. 'ü' => 'Ü',
  34614. 'ý' => '�',
  34615. 'þ' => 'Þ',
  34616. 'ÿ' => 'Ÿ',
  34617. '�' => 'Ā',
  34618. 'ă' => 'Ă',
  34619. 'Ä…' => 'Ä„',
  34620. 'ć' => 'Ć',
  34621. 'ĉ' => 'Ĉ',
  34622. 'Ä‹' => 'ÄŠ',
  34623. '�' => 'Č',
  34624. '�' => 'Ď',
  34625. 'đ' => '�',
  34626. 'Ä“' => 'Ä’',
  34627. 'Ä•' => 'Ä”',
  34628. 'Ä—' => 'Ä–',
  34629. 'ę' => 'Ę',
  34630. 'Ä›' => 'Äš',
  34631. '�' => 'Ĝ',
  34632. 'ÄŸ' => 'Äž',
  34633. 'Ä¡' => 'Ä ',
  34634. 'Ä£' => 'Ä¢',
  34635. 'ĥ' => 'Ĥ',
  34636. 'ħ' => 'Ħ',
  34637. 'ĩ' => 'Ĩ',
  34638. 'ī' => 'Ī',
  34639. 'ĭ' => 'Ĭ',
  34640. 'į' => 'Į',
  34641. 'ı' => 'I',
  34642. 'ij' => 'IJ',
  34643. 'ĵ' => 'Ĵ',
  34644. 'ķ' => 'Ķ',
  34645. 'ĺ' => 'Ĺ',
  34646. 'ļ' => 'Ļ',
  34647. 'ľ' => 'Ľ',
  34648. 'Å€' => 'Ä¿',
  34649. 'ł' => '�',
  34650. 'ń' => 'Ń',
  34651. 'ņ' => 'Ņ',
  34652. 'ň' => 'Ň',
  34653. 'Å‹' => 'ÅŠ',
  34654. '�' => 'Ō',
  34655. '�' => 'Ŏ',
  34656. 'ő' => '�',
  34657. 'Å“' => 'Å’',
  34658. 'Å•' => 'Å”',
  34659. 'Å—' => 'Å–',
  34660. 'ř' => 'Ř',
  34661. 'Å›' => 'Åš',
  34662. '�' => 'Ŝ',
  34663. 'ÅŸ' => 'Åž',
  34664. 'Å¡' => 'Å ',
  34665. 'Å£' => 'Å¢',
  34666. 'ť' => 'Ť',
  34667. 'ŧ' => 'Ŧ',
  34668. 'ũ' => 'Ũ',
  34669. 'ū' => 'Ū',
  34670. 'ŭ' => 'Ŭ',
  34671. 'ů' => 'Ů',
  34672. 'ű' => 'Ű',
  34673. 'ų' => 'Ų',
  34674. 'ŵ' => 'Ŵ',
  34675. 'ŷ' => 'Ŷ',
  34676. 'ź' => 'Ź',
  34677. 'ż' => 'Ż',
  34678. 'ž' => 'Ž',
  34679. 'Å¿' => 'S',
  34680. 'ƀ' => 'Ƀ',
  34681. 'ƃ' => 'Ƃ',
  34682. 'Æ…' => 'Æ„',
  34683. 'ƈ' => 'Ƈ',
  34684. 'ƌ' => 'Ƌ',
  34685. 'Æ’' => 'Æ‘',
  34686. 'ƕ' => 'Ƕ',
  34687. 'ƙ' => 'Ƙ',
  34688. 'ƚ' => 'Ƚ',
  34689. 'Æž' => 'È ',
  34690. 'Æ¡' => 'Æ ',
  34691. 'Æ£' => 'Æ¢',
  34692. 'ƥ' => 'Ƥ',
  34693. 'ƨ' => 'Ƨ',
  34694. 'ƭ' => 'Ƭ',
  34695. 'ư' => 'Ư',
  34696. 'ƴ' => 'Ƴ',
  34697. 'ƶ' => 'Ƶ',
  34698. 'ƹ' => 'Ƹ',
  34699. 'ƽ' => 'Ƽ',
  34700. 'Æ¿' => 'Ç·',
  34701. 'Ç…' => 'Ç„',
  34702. 'dž' => 'DŽ',
  34703. 'Lj' => 'LJ',
  34704. 'lj' => 'LJ',
  34705. 'Ç‹' => 'ÇŠ',
  34706. 'nj' => 'NJ',
  34707. 'ǎ' => '�',
  34708. '�' => '�',
  34709. 'Ç’' => 'Ç‘',
  34710. 'Ç”' => 'Ç“',
  34711. 'Ç–' => 'Ç•',
  34712. 'ǘ' => 'Ǘ',
  34713. 'Çš' => 'Ç™',
  34714. 'ǜ' => 'Ǜ',
  34715. '�' => 'Ǝ',
  34716. 'ÇŸ' => 'Çž',
  34717. 'Ç¡' => 'Ç ',
  34718. 'Ç£' => 'Ç¢',
  34719. 'ǥ' => 'Ǥ',
  34720. 'ǧ' => 'Ǧ',
  34721. 'ǩ' => 'Ǩ',
  34722. 'ǫ' => 'Ǫ',
  34723. 'ǭ' => 'Ǭ',
  34724. 'ǯ' => 'Ǯ',
  34725. 'Dz' => 'DZ',
  34726. 'dz' => 'DZ',
  34727. 'ǵ' => 'Ǵ',
  34728. 'ǹ' => 'Ǹ',
  34729. 'ǻ' => 'Ǻ',
  34730. 'ǽ' => 'Ǽ',
  34731. 'ǿ' => 'Ǿ',
  34732. '�' => 'Ȁ',
  34733. 'ȃ' => 'Ȃ',
  34734. 'È…' => 'È„',
  34735. 'ȇ' => 'Ȇ',
  34736. 'ȉ' => 'Ȉ',
  34737. 'È‹' => 'ÈŠ',
  34738. '�' => 'Ȍ',
  34739. '�' => 'Ȏ',
  34740. 'ȑ' => '�',
  34741. 'È“' => 'È’',
  34742. 'È•' => 'È”',
  34743. 'È—' => 'È–',
  34744. 'ș' => 'Ș',
  34745. 'È›' => 'Èš',
  34746. '�' => 'Ȝ',
  34747. 'ÈŸ' => 'Èž',
  34748. 'È£' => 'È¢',
  34749. 'ȥ' => 'Ȥ',
  34750. 'ȧ' => 'Ȧ',
  34751. 'ȩ' => 'Ȩ',
  34752. 'ȫ' => 'Ȫ',
  34753. 'ȭ' => 'Ȭ',
  34754. 'ȯ' => 'Ȯ',
  34755. 'ȱ' => 'Ȱ',
  34756. 'ȳ' => 'Ȳ',
  34757. 'ȼ' => 'Ȼ',
  34758. 'È¿' => 'â±¾',
  34759. 'ɀ' => 'Ɀ',
  34760. 'ɂ' => '�',
  34761. 'ɇ' => 'Ɇ',
  34762. 'ɉ' => 'Ɉ',
  34763. 'É‹' => 'ÉŠ',
  34764. '�' => 'Ɍ',
  34765. '�' => 'Ɏ',
  34766. '�' => 'Ɐ',
  34767. 'É‘' => 'â±­',
  34768. 'É’' => 'â±°',
  34769. 'ɓ' => '�',
  34770. 'ɔ' => 'Ɔ',
  34771. 'ɖ' => 'Ɖ',
  34772. 'É—' => 'ÆŠ',
  34773. 'ə' => '�',
  34774. 'ɛ' => '�',
  34775. 'ɜ' => 'Ɜ',
  34776. 'É ' => 'Æ“',
  34777. 'ɡ' => 'Ɡ',
  34778. 'É£' => 'Æ”',
  34779. 'ɥ' => '�',
  34780. 'ɦ' => 'Ɦ',
  34781. 'ɨ' => 'Ɨ',
  34782. 'É©' => 'Æ–',
  34783. 'É«' => 'â±¢',
  34784. 'ɬ' => 'Ɬ',
  34785. 'ɯ' => 'Ɯ',
  34786. 'ɱ' => 'Ɱ',
  34787. 'ɲ' => '�',
  34788. 'ɵ' => 'Ɵ',
  34789. 'ɽ' => 'Ɽ',
  34790. 'ʀ' => 'Ʀ',
  34791. 'ʃ' => 'Ʃ',
  34792. 'ʇ' => 'Ʇ',
  34793. 'ʈ' => 'Ʈ',
  34794. 'ʉ' => 'Ʉ',
  34795. 'ʊ' => 'Ʊ',
  34796. 'ʋ' => 'Ʋ',
  34797. 'ʌ' => 'Ʌ',
  34798. 'Ê’' => 'Æ·',
  34799. 'Êž' => 'êž°',
  34800. 'ͅ' => 'Ι',
  34801. 'ͱ' => 'Ͱ',
  34802. 'ͳ' => 'Ͳ',
  34803. 'ͷ' => 'Ͷ',
  34804. 'ͻ' => 'Ͻ',
  34805. 'ͼ' => 'Ͼ',
  34806. 'ͽ' => 'Ͽ',
  34807. 'ά' => 'Ά',
  34808. 'έ' => 'Έ',
  34809. 'ή' => 'Ή',
  34810. 'ί' => 'Ί',
  34811. 'α' => 'Α',
  34812. 'β' => 'Β',
  34813. 'γ' => 'Γ',
  34814. 'δ' => 'Δ',
  34815. 'ε' => 'Ε',
  34816. 'ζ' => 'Ζ',
  34817. 'η' => 'Η',
  34818. 'θ' => 'Θ',
  34819. 'ι' => 'Ι',
  34820. 'κ' => 'Κ',
  34821. 'λ' => 'Λ',
  34822. 'μ' => 'Μ',
  34823. 'ν' => '�',
  34824. 'ξ' => 'Ξ',
  34825. 'ο' => 'Ο',
  34826. 'π' => 'Π',
  34827. '�' => 'Ρ',
  34828. 'ς' => 'Σ',
  34829. 'σ' => 'Σ',
  34830. 'τ' => 'Τ',
  34831. 'Ï…' => 'Î¥',
  34832. 'φ' => 'Φ',
  34833. 'χ' => 'Χ',
  34834. 'ψ' => 'Ψ',
  34835. 'ω' => 'Ω',
  34836. 'ϊ' => 'Ϊ',
  34837. 'ϋ' => 'Ϋ',
  34838. 'ό' => 'Ό',
  34839. '�' => 'Ύ',
  34840. 'ώ' => '�',
  34841. '�' => 'Β',
  34842. 'ϑ' => 'Θ',
  34843. 'ϕ' => 'Φ',
  34844. 'ϖ' => 'Π',
  34845. 'ϗ' => '�',
  34846. 'ϙ' => 'Ϙ',
  34847. 'Ï›' => 'Ïš',
  34848. '�' => 'Ϝ',
  34849. 'ÏŸ' => 'Ïž',
  34850. 'Ï¡' => 'Ï ',
  34851. 'Ï£' => 'Ï¢',
  34852. 'ϥ' => 'Ϥ',
  34853. 'ϧ' => 'Ϧ',
  34854. 'ϩ' => 'Ϩ',
  34855. 'ϫ' => 'Ϫ',
  34856. 'ϭ' => 'Ϭ',
  34857. 'ϯ' => 'Ϯ',
  34858. 'ϰ' => 'Κ',
  34859. 'ϱ' => 'Ρ',
  34860. 'ϲ' => 'Ϲ',
  34861. 'ϳ' => 'Ϳ',
  34862. 'ϵ' => 'Ε',
  34863. 'ϸ' => 'Ϸ',
  34864. 'ϻ' => 'Ϻ',
  34865. 'а' => '�',
  34866. 'б' => 'Б',
  34867. 'в' => 'В',
  34868. 'г' => 'Г',
  34869. 'д' => 'Д',
  34870. 'е' => 'Е',
  34871. 'ж' => 'Ж',
  34872. 'з' => 'З',
  34873. 'и' => 'И',
  34874. 'й' => 'Й',
  34875. 'к' => 'К',
  34876. 'л' => 'Л',
  34877. 'м' => 'М',
  34878. 'н' => '�',
  34879. 'о' => 'О',
  34880. 'п' => 'П',
  34881. 'р' => 'Р',
  34882. '�' => 'С',
  34883. 'т' => 'Т',
  34884. 'у' => 'У',
  34885. 'ф' => 'Ф',
  34886. 'Ñ…' => 'Ð¥',
  34887. 'ц' => 'Ц',
  34888. 'ч' => 'Ч',
  34889. 'ш' => 'Ш',
  34890. 'щ' => 'Щ',
  34891. 'ъ' => 'Ъ',
  34892. 'ы' => 'Ы',
  34893. 'ь' => 'Ь',
  34894. '�' => 'Э',
  34895. 'ю' => 'Ю',
  34896. '�' => 'Я',
  34897. '�' => 'Ѐ',
  34898. 'ё' => '�',
  34899. 'ђ' => 'Ђ',
  34900. 'ѓ' => 'Ѓ',
  34901. 'є' => 'Є',
  34902. 'Ñ•' => 'Ð…',
  34903. 'і' => 'І',
  34904. 'ї' => 'Ї',
  34905. 'ј' => 'Ј',
  34906. 'љ' => 'Љ',
  34907. 'њ' => 'Њ',
  34908. 'ћ' => 'Ћ',
  34909. 'ќ' => 'Ќ',
  34910. '�' => '�',
  34911. 'Ñž' => 'ÐŽ',
  34912. 'џ' => '�',
  34913. 'Ñ¡' => 'Ñ ',
  34914. 'Ñ£' => 'Ñ¢',
  34915. 'ѥ' => 'Ѥ',
  34916. 'ѧ' => 'Ѧ',
  34917. 'ѩ' => 'Ѩ',
  34918. 'ѫ' => 'Ѫ',
  34919. 'ѭ' => 'Ѭ',
  34920. 'ѯ' => 'Ѯ',
  34921. 'ѱ' => 'Ѱ',
  34922. 'ѳ' => 'Ѳ',
  34923. 'ѵ' => 'Ѵ',
  34924. 'ѷ' => 'Ѷ',
  34925. 'ѹ' => 'Ѹ',
  34926. 'ѻ' => 'Ѻ',
  34927. 'ѽ' => 'Ѽ',
  34928. 'ѿ' => 'Ѿ',
  34929. 'Ò�' => 'Ò€',
  34930. 'Ò‹' => 'ÒŠ',
  34931. '�' => 'Ҍ',
  34932. 'Ò�' => 'ÒŽ',
  34933. 'Ò‘' => 'Ò�',
  34934. 'Ò“' => 'Ò’',
  34935. 'Ò•' => 'Ò”',
  34936. 'Ò—' => 'Ò–',
  34937. 'Ò™' => 'Ò˜',
  34938. 'Ò›' => 'Òš',
  34939. '�' => 'Ҝ',
  34940. 'ÒŸ' => 'Òž',
  34941. 'Ò¡' => 'Ò ',
  34942. 'Ò£' => 'Ò¢',
  34943. 'Ò¥' => 'Ò¤',
  34944. 'Ò§' => 'Ò¦',
  34945. 'Ò©' => 'Ò¨',
  34946. 'Ò«' => 'Òª',
  34947. 'Ò­' => 'Ò¬',
  34948. 'Ò¯' => 'Ò®',
  34949. 'Ò±' => 'Ò°',
  34950. 'Ò³' => 'Ò²',
  34951. 'Òµ' => 'Ò´',
  34952. 'Ò·' => 'Ò¶',
  34953. 'Ò¹' => 'Ò¸',
  34954. 'Ò»' => 'Òº',
  34955. 'Ò½' => 'Ò¼',
  34956. 'Ò¿' => 'Ò¾',
  34957. 'Ó‚' => 'Ó�',
  34958. 'Ó„' => 'Óƒ',
  34959. 'Ó†' => 'Ó…',
  34960. 'Óˆ' => 'Ó‡',
  34961. 'ÓŠ' => 'Ó‰',
  34962. 'ӌ' => 'Ӌ',
  34963. 'ÓŽ' => 'Ó�',
  34964. 'Ó�' => 'Ó€',
  34965. 'Ó‘' => 'Ó�',
  34966. 'Ó“' => 'Ó’',
  34967. 'Ó•' => 'Ó”',
  34968. 'Ó—' => 'Ó–',
  34969. 'Ó™' => 'Ó˜',
  34970. 'Ó›' => 'Óš',
  34971. '�' => 'Ӝ',
  34972. 'ÓŸ' => 'Óž',
  34973. 'Ó¡' => 'Ó ',
  34974. 'Ó£' => 'Ó¢',
  34975. 'Ó¥' => 'Ó¤',
  34976. 'Ó§' => 'Ó¦',
  34977. 'Ó©' => 'Ó¨',
  34978. 'Ó«' => 'Óª',
  34979. 'Ó­' => 'Ó¬',
  34980. 'Ó¯' => 'Ó®',
  34981. 'Ó±' => 'Ó°',
  34982. 'Ó³' => 'Ó²',
  34983. 'Óµ' => 'Ó´',
  34984. 'Ó·' => 'Ó¶',
  34985. 'Ó¹' => 'Ó¸',
  34986. 'Ó»' => 'Óº',
  34987. 'Ó½' => 'Ó¼',
  34988. 'Ó¿' => 'Ó¾',
  34989. 'Ô�' => 'Ô€',
  34990. 'Ôƒ' => 'Ô‚',
  34991. 'Ô…' => 'Ô„',
  34992. 'Ô‡' => 'Ô†',
  34993. 'Ô‰' => 'Ôˆ',
  34994. 'Ô‹' => 'ÔŠ',
  34995. '�' => 'Ԍ',
  34996. 'Ô�' => 'ÔŽ',
  34997. 'Ô‘' => 'Ô�',
  34998. 'Ô“' => 'Ô’',
  34999. 'Ô•' => 'Ô”',
  35000. 'Ô—' => 'Ô–',
  35001. 'Ô™' => 'Ô˜',
  35002. 'Ô›' => 'Ôš',
  35003. '�' => 'Ԝ',
  35004. 'ÔŸ' => 'Ôž',
  35005. 'Ô¡' => 'Ô ',
  35006. 'Ô£' => 'Ô¢',
  35007. 'Ô¥' => 'Ô¤',
  35008. 'Ô§' => 'Ô¦',
  35009. 'Ô©' => 'Ô¨',
  35010. 'Ô«' => 'Ôª',
  35011. 'Ô­' => 'Ô¬',
  35012. 'Ô¯' => 'Ô®',
  35013. 'Õ¡' => 'Ô±',
  35014. 'Õ¢' => 'Ô²',
  35015. 'Õ£' => 'Ô³',
  35016. 'Õ¤' => 'Ô´',
  35017. 'Õ¥' => 'Ôµ',
  35018. 'Õ¦' => 'Ô¶',
  35019. 'Õ§' => 'Ô·',
  35020. 'Õ¨' => 'Ô¸',
  35021. 'Õ©' => 'Ô¹',
  35022. 'Õª' => 'Ôº',
  35023. 'Õ«' => 'Ô»',
  35024. 'Õ¬' => 'Ô¼',
  35025. 'Õ­' => 'Ô½',
  35026. 'Õ®' => 'Ô¾',
  35027. 'Õ¯' => 'Ô¿',
  35028. 'Õ°' => 'Õ€',
  35029. 'Õ±' => 'Õ�',
  35030. 'Õ²' => 'Õ‚',
  35031. 'Õ³' => 'Õƒ',
  35032. 'Õ´' => 'Õ„',
  35033. 'Õµ' => 'Õ…',
  35034. 'Õ¶' => 'Õ†',
  35035. 'Õ·' => 'Õ‡',
  35036. 'Õ¸' => 'Õˆ',
  35037. 'Õ¹' => 'Õ‰',
  35038. 'Õº' => 'ÕŠ',
  35039. 'Õ»' => 'Õ‹',
  35040. 'ռ' => 'Ռ',
  35041. 'Õ½' => 'Õ�',
  35042. 'Õ¾' => 'ÕŽ',
  35043. 'Õ¿' => 'Õ�',
  35044. 'Ö€' => 'Õ�',
  35045. 'Ö�' => 'Õ‘',
  35046. 'Ö‚' => 'Õ’',
  35047. 'Öƒ' => 'Õ“',
  35048. 'Ö„' => 'Õ”',
  35049. 'Ö…' => 'Õ•',
  35050. 'Ö†' => 'Õ–',
  35051. 'ᵹ' => '�',
  35052. 'áµ½' => 'â±£',
  35053. '�' => 'Ḁ',
  35054. 'ḃ' => 'Ḃ',
  35055. 'ḅ' => 'Ḅ',
  35056. 'ḇ' => 'Ḇ',
  35057. 'ḉ' => 'Ḉ',
  35058. 'ḋ' => 'Ḋ',
  35059. '�' => 'Ḍ',
  35060. '�' => 'Ḏ',
  35061. 'ḑ' => '�',
  35062. 'ḓ' => 'Ḓ',
  35063. 'ḕ' => 'Ḕ',
  35064. 'ḗ' => 'Ḗ',
  35065. 'ḙ' => 'Ḙ',
  35066. 'ḛ' => 'Ḛ',
  35067. '�' => 'Ḝ',
  35068. 'ḟ' => 'Ḟ',
  35069. 'ḡ' => 'Ḡ',
  35070. 'ḣ' => 'Ḣ',
  35071. 'ḥ' => 'Ḥ',
  35072. 'ḧ' => 'Ḧ',
  35073. 'ḩ' => 'Ḩ',
  35074. 'ḫ' => 'Ḫ',
  35075. 'ḭ' => 'Ḭ',
  35076. 'ḯ' => 'Ḯ',
  35077. 'ḱ' => 'Ḱ',
  35078. 'ḳ' => 'Ḳ',
  35079. 'ḵ' => 'Ḵ',
  35080. 'ḷ' => 'Ḷ',
  35081. 'ḹ' => 'Ḹ',
  35082. 'ḻ' => 'Ḻ',
  35083. 'ḽ' => 'Ḽ',
  35084. 'ḿ' => 'Ḿ',
  35085. '�' => 'Ṁ',
  35086. 'ṃ' => 'Ṃ',
  35087. 'ṅ' => 'Ṅ',
  35088. 'ṇ' => 'Ṇ',
  35089. 'ṉ' => 'Ṉ',
  35090. 'ṋ' => 'Ṋ',
  35091. '�' => 'Ṍ',
  35092. '�' => 'Ṏ',
  35093. 'ṑ' => '�',
  35094. 'ṓ' => 'Ṓ',
  35095. 'ṕ' => 'Ṕ',
  35096. 'á¹—' => 'á¹–',
  35097. 'ṙ' => 'Ṙ',
  35098. 'ṛ' => 'Ṛ',
  35099. '�' => 'Ṝ',
  35100. 'ṟ' => 'Ṟ',
  35101. 'ṡ' => 'Ṡ',
  35102. 'á¹£' => 'á¹¢',
  35103. 'ṥ' => 'Ṥ',
  35104. 'ṧ' => 'Ṧ',
  35105. 'ṩ' => 'Ṩ',
  35106. 'ṫ' => 'Ṫ',
  35107. 'ṭ' => 'Ṭ',
  35108. 'ṯ' => 'Ṯ',
  35109. 'á¹±' => 'á¹°',
  35110. 'á¹³' => 'á¹²',
  35111. 'á¹µ' => 'á¹´',
  35112. 'á¹·' => 'á¹¶',
  35113. 'ṹ' => 'Ṹ',
  35114. 'ṻ' => 'Ṻ',
  35115. 'á¹½' => 'á¹¼',
  35116. 'ṿ' => 'Ṿ',
  35117. '�' => 'Ẁ',
  35118. 'ẃ' => 'Ẃ',
  35119. 'ẅ' => 'Ẅ',
  35120. 'ẇ' => 'Ẇ',
  35121. 'ẉ' => 'Ẉ',
  35122. 'ẋ' => 'Ẋ',
  35123. '�' => 'Ẍ',
  35124. '�' => 'Ẏ',
  35125. 'ẑ' => '�',
  35126. 'ẓ' => 'Ẓ',
  35127. 'ẕ' => 'Ẕ',
  35128. 'ẛ' => 'Ṡ',
  35129. 'ạ' => 'Ạ',
  35130. 'ả' => 'Ả',
  35131. 'ấ' => 'Ấ',
  35132. 'ầ' => 'Ầ',
  35133. 'ẩ' => 'Ẩ',
  35134. 'ẫ' => 'Ẫ',
  35135. 'ậ' => 'Ậ',
  35136. 'ắ' => 'Ắ',
  35137. 'ằ' => 'Ằ',
  35138. 'ẳ' => 'Ẳ',
  35139. 'ẵ' => 'Ẵ',
  35140. 'ặ' => 'Ặ',
  35141. 'ẹ' => 'Ẹ',
  35142. 'ẻ' => 'Ẻ',
  35143. 'ẽ' => 'Ẽ',
  35144. 'ế' => 'Ế',
  35145. '�' => 'Ề',
  35146. 'ể' => 'Ể',
  35147. 'ễ' => 'Ễ',
  35148. 'ệ' => 'Ệ',
  35149. 'ỉ' => 'Ỉ',
  35150. 'ị' => 'Ị',
  35151. '�' => 'Ọ',
  35152. '�' => 'Ỏ',
  35153. 'ố' => '�',
  35154. 'ồ' => 'Ồ',
  35155. 'ổ' => 'Ổ',
  35156. 'á»—' => 'á»–',
  35157. 'ộ' => 'Ộ',
  35158. 'ớ' => 'Ớ',
  35159. '�' => 'Ờ',
  35160. 'ở' => 'Ở',
  35161. 'ỡ' => 'Ỡ',
  35162. 'ợ' => 'Ợ',
  35163. 'ụ' => 'Ụ',
  35164. 'ủ' => 'Ủ',
  35165. 'ứ' => 'Ứ',
  35166. 'ừ' => 'Ừ',
  35167. 'ử' => 'Ử',
  35168. 'ữ' => 'Ữ',
  35169. 'á»±' => 'á»°',
  35170. 'ỳ' => 'Ỳ',
  35171. 'ỵ' => 'Ỵ',
  35172. 'á»·' => 'á»¶',
  35173. 'ỹ' => 'Ỹ',
  35174. 'ỻ' => 'Ỻ',
  35175. 'ỽ' => 'Ỽ',
  35176. 'ỿ' => 'Ỿ',
  35177. 'ἀ' => 'Ἀ',
  35178. '�' => 'Ἁ',
  35179. 'ἂ' => 'Ἂ',
  35180. 'ἃ' => 'Ἃ',
  35181. 'ἄ' => 'Ἄ',
  35182. 'ἅ' => '�',
  35183. 'ἆ' => 'Ἆ',
  35184. 'ἇ' => '�',
  35185. '�' => 'Ἐ',
  35186. 'ἑ' => 'Ἑ',
  35187. 'ἒ' => 'Ἒ',
  35188. 'ἓ' => 'Ἓ',
  35189. 'ἔ' => 'Ἔ',
  35190. 'ἕ' => '�',
  35191. 'ἠ' => 'Ἠ',
  35192. 'ἡ' => 'Ἡ',
  35193. 'ἢ' => 'Ἢ',
  35194. 'ἣ' => 'Ἣ',
  35195. 'ἤ' => 'Ἤ',
  35196. 'á¼¥' => 'á¼­',
  35197. 'ἦ' => 'Ἦ',
  35198. 'ἧ' => 'Ἧ',
  35199. 'ἰ' => 'Ἰ',
  35200. 'á¼±' => 'á¼¹',
  35201. 'ἲ' => 'Ἲ',
  35202. 'á¼³' => 'á¼»',
  35203. 'á¼´' => 'á¼¼',
  35204. 'á¼µ' => 'á¼½',
  35205. 'á¼¶' => 'á¼¾',
  35206. 'ἷ' => 'Ἷ',
  35207. 'ὀ' => 'Ὀ',
  35208. '�' => 'Ὁ',
  35209. 'ὂ' => 'Ὂ',
  35210. 'ὃ' => 'Ὃ',
  35211. 'ὄ' => 'Ὄ',
  35212. 'ὅ' => '�',
  35213. 'ὑ' => 'Ὑ',
  35214. 'ὓ' => 'Ὓ',
  35215. 'ὕ' => '�',
  35216. 'ὗ' => 'Ὗ',
  35217. 'ὠ' => 'Ὠ',
  35218. 'ὡ' => 'Ὡ',
  35219. 'ὢ' => 'Ὢ',
  35220. 'ὣ' => 'Ὣ',
  35221. 'ὤ' => 'Ὤ',
  35222. 'á½¥' => 'á½­',
  35223. 'ὦ' => 'Ὦ',
  35224. 'ὧ' => 'Ὧ',
  35225. 'ὰ' => 'Ὰ',
  35226. 'á½±' => 'á¾»',
  35227. 'ὲ' => 'Ὲ',
  35228. 'έ' => 'Έ',
  35229. 'ὴ' => 'Ὴ',
  35230. 'á½µ' => 'á¿‹',
  35231. 'ὶ' => 'Ὶ',
  35232. 'á½·' => 'á¿›',
  35233. 'ὸ' => 'Ὸ',
  35234. 'ό' => 'Ό',
  35235. 'ὺ' => 'Ὺ',
  35236. 'á½»' => 'á¿«',
  35237. 'ὼ' => 'Ὼ',
  35238. 'á½½' => 'á¿»',
  35239. 'ᾀ' => 'ᾈ',
  35240. '�' => 'ᾉ',
  35241. 'ᾂ' => 'ᾊ',
  35242. 'ᾃ' => 'ᾋ',
  35243. 'ᾄ' => 'ᾌ',
  35244. 'ᾅ' => '�',
  35245. 'ᾆ' => 'ᾎ',
  35246. 'ᾇ' => '�',
  35247. '�' => 'ᾘ',
  35248. 'ᾑ' => 'ᾙ',
  35249. 'ᾒ' => 'ᾚ',
  35250. 'ᾓ' => 'ᾛ',
  35251. 'ᾔ' => 'ᾜ',
  35252. 'ᾕ' => '�',
  35253. 'ᾖ' => 'ᾞ',
  35254. 'ᾗ' => 'ᾟ',
  35255. 'ᾠ' => 'ᾨ',
  35256. 'ᾡ' => 'ᾩ',
  35257. 'ᾢ' => 'ᾪ',
  35258. 'ᾣ' => 'ᾫ',
  35259. 'ᾤ' => 'ᾬ',
  35260. 'á¾¥' => 'á¾­',
  35261. 'ᾦ' => 'ᾮ',
  35262. 'ᾧ' => 'ᾯ',
  35263. 'ᾰ' => 'Ᾰ',
  35264. 'á¾±' => 'á¾¹',
  35265. 'á¾³' => 'á¾¼',
  35266. 'ι' => 'Ι',
  35267. 'ῃ' => 'ῌ',
  35268. '�' => 'Ῐ',
  35269. 'á¿‘' => 'á¿™',
  35270. 'ῠ' => 'Ῠ',
  35271. 'á¿¡' => 'á¿©',
  35272. 'ῥ' => 'Ῥ',
  35273. 'ῳ' => 'ῼ',
  35274. 'ⅎ' => 'Ⅎ',
  35275. 'â…°' => 'â… ',
  35276. 'â…±' => 'â…¡',
  35277. 'â…²' => 'â…¢',
  35278. 'â…³' => 'â…£',
  35279. 'â…´' => 'â…¤',
  35280. 'â…µ' => 'â…¥',
  35281. 'â…¶' => 'â…¦',
  35282. 'â…·' => 'â…§',
  35283. 'â…¸' => 'â…¨',
  35284. 'â…¹' => 'â…©',
  35285. 'â…º' => 'â…ª',
  35286. 'â…»' => 'â…«',
  35287. 'â…¼' => 'â…¬',
  35288. 'â…½' => 'â…­',
  35289. 'â…¾' => 'â…®',
  35290. 'â…¿' => 'â…¯',
  35291. 'ↄ' => 'Ↄ',
  35292. '�' => 'Ⓐ',
  35293. 'â“‘' => 'â’·',
  35294. 'â“’' => 'â’¸',
  35295. 'â““' => 'â’¹',
  35296. 'â“”' => 'â’º',
  35297. 'â“•' => 'â’»',
  35298. 'â“–' => 'â’¼',
  35299. 'â“—' => 'â’½',
  35300. 'ⓘ' => 'Ⓘ',
  35301. 'â“™' => 'â’¿',
  35302. 'ⓚ' => 'Ⓚ',
  35303. 'ⓛ' => '�',
  35304. 'ⓜ' => 'Ⓜ',
  35305. '�' => 'Ⓝ',
  35306. 'ⓞ' => 'Ⓞ',
  35307. 'ⓟ' => 'Ⓟ',
  35308. 'ⓠ' => 'Ⓠ',
  35309. 'ⓡ' => 'Ⓡ',
  35310. 'ⓢ' => 'Ⓢ',
  35311. 'ⓣ' => 'Ⓣ',
  35312. 'ⓤ' => 'Ⓤ',
  35313. 'â“¥' => 'â“‹',
  35314. 'ⓦ' => 'Ⓦ',
  35315. 'ⓧ' => '�',
  35316. 'ⓨ' => 'Ⓨ',
  35317. 'ⓩ' => '�',
  35318. 'â°°' => 'â°€',
  35319. 'â°±' => 'â°�',
  35320. 'â°²' => 'â°‚',
  35321. 'â°³' => 'â°ƒ',
  35322. 'â°´' => 'â°„',
  35323. 'â°µ' => 'â°…',
  35324. 'â°¶' => 'â°†',
  35325. 'â°·' => 'â°‡',
  35326. 'â°¸' => 'â°ˆ',
  35327. 'â°¹' => 'â°‰',
  35328. 'â°º' => 'â°Š',
  35329. 'â°»' => 'â°‹',
  35330. 'ⰼ' => 'Ⰼ',
  35331. 'â°½' => 'â°�',
  35332. 'â°¾' => 'â°Ž',
  35333. 'â°¿' => 'â°�',
  35334. 'â±€' => 'â°�',
  35335. '�' => 'Ⱁ',
  35336. 'ⱂ' => 'Ⱂ',
  35337. 'ⱃ' => 'Ⱃ',
  35338. 'ⱄ' => 'Ⱄ',
  35339. 'â±…' => 'â°•',
  35340. 'ⱆ' => 'Ⱆ',
  35341. 'ⱇ' => 'Ⱇ',
  35342. 'ⱈ' => 'Ⱈ',
  35343. 'ⱉ' => 'Ⱉ',
  35344. 'ⱊ' => 'Ⱊ',
  35345. 'ⱋ' => 'Ⱋ',
  35346. 'ⱌ' => 'Ⱌ',
  35347. '�' => '�',
  35348. 'ⱎ' => 'Ⱎ',
  35349. '�' => 'Ⱏ',
  35350. '�' => 'Ⱐ',
  35351. 'ⱑ' => 'Ⱑ',
  35352. 'â±’' => 'â°¢',
  35353. 'ⱓ' => 'Ⱓ',
  35354. 'â±”' => 'â°¤',
  35355. 'ⱕ' => 'Ⱕ',
  35356. 'â±–' => 'â°¦',
  35357. 'â±—' => 'â°§',
  35358. 'ⱘ' => 'Ⱘ',
  35359. 'â±™' => 'â°©',
  35360. 'ⱚ' => 'Ⱚ',
  35361. 'â±›' => 'â°«',
  35362. 'ⱜ' => 'Ⱜ',
  35363. '�' => 'Ⱝ',
  35364. 'ⱞ' => 'Ⱞ',
  35365. 'ⱡ' => 'Ⱡ',
  35366. 'ⱥ' => 'Ⱥ',
  35367. 'ⱦ' => 'Ⱦ',
  35368. 'ⱨ' => 'Ⱨ',
  35369. 'ⱪ' => 'Ⱪ',
  35370. 'ⱬ' => 'Ⱬ',
  35371. 'â±³' => 'â±²',
  35372. 'â±¶' => 'â±µ',
  35373. '�' => 'Ⲁ',
  35374. 'ⲃ' => 'Ⲃ',
  35375. 'ⲅ' => 'Ⲅ',
  35376. 'ⲇ' => 'Ⲇ',
  35377. 'ⲉ' => 'Ⲉ',
  35378. 'ⲋ' => 'Ⲋ',
  35379. '�' => 'Ⲍ',
  35380. '�' => 'Ⲏ',
  35381. 'ⲑ' => '�',
  35382. 'ⲓ' => 'Ⲓ',
  35383. 'ⲕ' => 'Ⲕ',
  35384. 'â²—' => 'â²–',
  35385. 'ⲙ' => 'Ⲙ',
  35386. 'ⲛ' => 'Ⲛ',
  35387. '�' => 'Ⲝ',
  35388. 'ⲟ' => 'Ⲟ',
  35389. 'ⲡ' => 'Ⲡ',
  35390. 'â²£' => 'â²¢',
  35391. 'ⲥ' => 'Ⲥ',
  35392. 'ⲧ' => 'Ⲧ',
  35393. 'ⲩ' => 'Ⲩ',
  35394. 'ⲫ' => 'Ⲫ',
  35395. 'ⲭ' => 'Ⲭ',
  35396. 'ⲯ' => 'Ⲯ',
  35397. 'â²±' => 'â²°',
  35398. 'â²³' => 'â²²',
  35399. 'â²µ' => 'â²´',
  35400. 'â²·' => 'â²¶',
  35401. 'ⲹ' => 'Ⲹ',
  35402. 'ⲻ' => 'Ⲻ',
  35403. 'â²½' => 'â²¼',
  35404. 'ⲿ' => 'Ⲿ',
  35405. '�' => 'Ⳁ',
  35406. 'ⳃ' => 'Ⳃ',
  35407. 'ⳅ' => 'Ⳅ',
  35408. 'ⳇ' => 'Ⳇ',
  35409. 'ⳉ' => 'Ⳉ',
  35410. 'ⳋ' => 'Ⳋ',
  35411. '�' => 'Ⳍ',
  35412. '�' => 'Ⳏ',
  35413. 'ⳑ' => '�',
  35414. 'ⳓ' => 'Ⳓ',
  35415. 'ⳕ' => 'Ⳕ',
  35416. 'â³—' => 'â³–',
  35417. 'ⳙ' => 'Ⳙ',
  35418. 'ⳛ' => 'Ⳛ',
  35419. '�' => 'Ⳝ',
  35420. 'ⳟ' => 'Ⳟ',
  35421. 'ⳡ' => 'Ⳡ',
  35422. 'â³£' => 'â³¢',
  35423. 'ⳬ' => 'Ⳬ',
  35424. 'â³®' => 'â³­',
  35425. 'â³³' => 'â³²',
  35426. 'â´€' => 'á‚ ',
  35427. 'â´�' => 'á‚¡',
  35428. 'â´‚' => 'á‚¢',
  35429. 'â´ƒ' => 'á‚£',
  35430. 'ⴄ' => 'Ⴄ',
  35431. 'â´…' => 'á‚¥',
  35432. 'ⴆ' => 'Ⴆ',
  35433. 'â´‡' => 'á‚§',
  35434. 'ⴈ' => 'Ⴈ',
  35435. 'â´‰' => 'á‚©',
  35436. 'ⴊ' => 'Ⴊ',
  35437. 'â´‹' => 'á‚«',
  35438. 'ⴌ' => 'Ⴌ',
  35439. 'â´�' => 'á‚­',
  35440. 'â´Ž' => 'á‚®',
  35441. '�' => 'Ⴏ',
  35442. 'â´�' => 'á‚°',
  35443. 'ⴑ' => 'Ⴑ',
  35444. 'ⴒ' => 'Ⴒ',
  35445. 'ⴓ' => 'Ⴓ',
  35446. 'â´”' => 'á‚´',
  35447. 'ⴕ' => 'Ⴕ',
  35448. 'â´–' => 'á‚¶',
  35449. 'â´—' => 'á‚·',
  35450. 'ⴘ' => 'Ⴘ',
  35451. 'ⴙ' => 'Ⴙ',
  35452. 'ⴚ' => 'Ⴚ',
  35453. 'â´›' => 'á‚»',
  35454. 'ⴜ' => 'Ⴜ',
  35455. '�' => 'Ⴝ',
  35456. 'ⴞ' => 'Ⴞ',
  35457. 'â´Ÿ' => 'á‚¿',
  35458. 'ⴠ' => 'Ⴠ',
  35459. 'ⴡ' => '�',
  35460. 'ⴢ' => 'Ⴢ',
  35461. 'ⴣ' => 'Ⴣ',
  35462. 'ⴤ' => 'Ⴤ',
  35463. 'ⴥ' => 'Ⴥ',
  35464. 'ⴧ' => 'Ⴧ',
  35465. 'ⴭ' => '�',
  35466. '�' => 'Ꙁ',
  35467. 'ꙃ' => 'Ꙃ',
  35468. 'ꙅ' => 'Ꙅ',
  35469. 'ꙇ' => 'Ꙇ',
  35470. 'ꙉ' => 'Ꙉ',
  35471. 'ꙋ' => 'Ꙋ',
  35472. '�' => 'Ꙍ',
  35473. '�' => 'Ꙏ',
  35474. 'ꙑ' => '�',
  35475. 'ꙓ' => 'Ꙓ',
  35476. 'ꙕ' => 'Ꙕ',
  35477. 'ê™—' => 'ê™–',
  35478. 'ꙙ' => 'Ꙙ',
  35479. 'ꙛ' => 'Ꙛ',
  35480. '�' => 'Ꙝ',
  35481. 'ꙟ' => 'Ꙟ',
  35482. 'ꙡ' => 'Ꙡ',
  35483. 'ꙣ' => 'Ꙣ',
  35484. 'ꙥ' => 'Ꙥ',
  35485. 'ꙧ' => 'Ꙧ',
  35486. 'ꙩ' => 'Ꙩ',
  35487. 'ꙫ' => 'Ꙫ',
  35488. 'ꙭ' => 'Ꙭ',
  35489. '�' => 'Ꚁ',
  35490. 'ꚃ' => 'Ꚃ',
  35491. 'êš…' => 'êš„',
  35492. 'ꚇ' => 'Ꚇ',
  35493. 'ꚉ' => 'Ꚉ',
  35494. 'ꚋ' => 'Ꚋ',
  35495. '�' => 'Ꚍ',
  35496. '�' => 'Ꚏ',
  35497. 'ꚑ' => '�',
  35498. 'êš“' => 'êš’',
  35499. 'êš•' => 'êš”',
  35500. 'êš—' => 'êš–',
  35501. 'ꚙ' => 'Ꚙ',
  35502. 'êš›' => 'êšš',
  35503. 'ꜣ' => 'Ꜣ',
  35504. 'ꜥ' => 'Ꜥ',
  35505. 'ꜧ' => 'Ꜧ',
  35506. 'ꜩ' => 'Ꜩ',
  35507. 'ꜫ' => 'Ꜫ',
  35508. 'ꜭ' => 'Ꜭ',
  35509. 'ꜯ' => 'Ꜯ',
  35510. 'ꜳ' => 'Ꜳ',
  35511. 'ꜵ' => 'Ꜵ',
  35512. 'ꜷ' => 'Ꜷ',
  35513. 'ꜹ' => 'Ꜹ',
  35514. 'ꜻ' => 'Ꜻ',
  35515. 'ꜽ' => 'Ꜽ',
  35516. 'ꜿ' => 'Ꜿ',
  35517. '�' => '�',
  35518. '�' => '�',
  35519. '�' => '�',
  35520. '�' => '�',
  35521. '�' => '�',
  35522. '�' => '�',
  35523. '�' => '�',
  35524. '�' => '�',
  35525. '�' => '�',
  35526. '�' => '�',
  35527. '�' => '�',
  35528. '�' => '�',
  35529. '�' => '�',
  35530. '�' => '�',
  35531. '�' => '�',
  35532. '�' => '�',
  35533. '�' => '�',
  35534. '�' => '�',
  35535. '�' => '�',
  35536. '�' => '�',
  35537. '�' => '�',
  35538. '�' => '�',
  35539. '�' => '�',
  35540. '�' => '�',
  35541. '�' => '�',
  35542. '�' => '�',
  35543. '�' => '�',
  35544. '�' => 'Ꞁ',
  35545. 'ꞃ' => 'Ꞃ',
  35546. 'êž…' => 'êž„',
  35547. 'ꞇ' => 'Ꞇ',
  35548. 'ꞌ' => 'Ꞌ',
  35549. 'ꞑ' => '�',
  35550. 'êž“' => 'êž’',
  35551. 'êž—' => 'êž–',
  35552. 'ꞙ' => 'Ꞙ',
  35553. 'êž›' => 'êžš',
  35554. '�' => 'Ꞝ',
  35555. 'ꞟ' => 'Ꞟ',
  35556. 'êž¡' => 'êž ',
  35557. 'ꞣ' => 'Ꞣ',
  35558. 'ꞥ' => 'Ꞥ',
  35559. 'ꞧ' => 'Ꞧ',
  35560. 'ꞩ' => 'Ꞩ',
  35561. '�' => 'A',
  35562. 'b' => 'B',
  35563. 'c' => 'C',
  35564. 'd' => 'D',
  35565. 'ï½…' => 'ï¼¥',
  35566. 'f' => 'F',
  35567. 'g' => 'G',
  35568. 'h' => 'H',
  35569. 'i' => 'I',
  35570. 'j' => 'J',
  35571. 'k' => 'K',
  35572. 'l' => 'L',
  35573. '�' => 'M',
  35574. 'n' => 'N',
  35575. '�' => 'O',
  35576. '�' => 'P',
  35577. 'q' => 'Q',
  35578. 'ï½’' => 'ï¼²',
  35579. 's' => 'S',
  35580. 'ï½”' => 'ï¼´',
  35581. 'u' => 'U',
  35582. 'ï½–' => 'ï¼¶',
  35583. 'ï½—' => 'ï¼·',
  35584. 'x' => 'X',
  35585. 'ï½™' => 'ï¼¹',
  35586. 'z' => 'Z',
  35587. '�' => '�',
  35588. '�' => '�',
  35589. '�' => '�',
  35590. '�' => '�',
  35591. '�' => '�',
  35592. '�' => '�',
  35593. '�' => '�',
  35594. '�' => '�',
  35595. '�' => '�',
  35596. '�' => '�',
  35597. '�' => '�',
  35598. '�' => '�',
  35599. '�' => '�',
  35600. '�' => '�',
  35601. '�' => '�',
  35602. '�' => '�',
  35603. '�' => '�',
  35604. '�' => '�',
  35605. '�' => '�',
  35606. '�' => '�',
  35607. '�' => '�',
  35608. '�' => '�',
  35609. '�' => '�',
  35610. '�' => '�',
  35611. '�' => '�',
  35612. '�' => '�',
  35613. '�' => '�',
  35614. '�' => '�',
  35615. '�' => '�',
  35616. '�' => '�',
  35617. '�' => '�',
  35618. '�' => '�',
  35619. '�' => '�',
  35620. '�' => '�',
  35621. '�' => '�',
  35622. '�' => '�',
  35623. '�' => '�',
  35624. '�' => '�',
  35625. '�' => '�',
  35626. '�' => '�',
  35627. 'ð‘£€' => 'ð‘¢ ',
  35628. '�' => '𑢡',
  35629. '𑣂' => '𑢢',
  35630. '𑣃' => '𑢣',
  35631. '𑣄' => '𑢤',
  35632. 'ð‘£…' => 'ð‘¢¥',
  35633. '𑣆' => '𑢦',
  35634. '𑣇' => '𑢧',
  35635. '𑣈' => '𑢨',
  35636. '𑣉' => '𑢩',
  35637. '𑣊' => '𑢪',
  35638. '𑣋' => '𑢫',
  35639. '𑣌' => '𑢬',
  35640. '�' => '𑢭',
  35641. '𑣎' => '𑢮',
  35642. '�' => '𑢯',
  35643. '�' => '𑢰',
  35644. '𑣑' => '𑢱',
  35645. 'ð‘£’' => 'ð‘¢²',
  35646. '𑣓' => '𑢳',
  35647. 'ð‘£”' => 'ð‘¢´',
  35648. '𑣕' => '𑢵',
  35649. 'ð‘£–' => 'ð‘¢¶',
  35650. 'ð‘£—' => 'ð‘¢·',
  35651. '𑣘' => '𑢸',
  35652. 'ð‘£™' => 'ð‘¢¹',
  35653. '𑣚' => '𑢺',
  35654. 'ð‘£›' => 'ð‘¢»',
  35655. '𑣜' => '𑢼',
  35656. '�' => '𑢽',
  35657. '𑣞' => '𑢾',
  35658. '𑣟' => '𑢿',
  35659. );
  35660. $result =& $data;
  35661. unset($data);
  35662. return $result;
  35663. <?php
  35664. use Symfony\Polyfill\Mbstring as p;
  35665. if (!function_exists('mb_strlen')) {
  35666. define('MB_CASE_UPPER', 0);
  35667. define('MB_CASE_LOWER', 1);
  35668. define('MB_CASE_TITLE', 2);
  35669. function mb_convert_encoding($s, $to, $from = null) { return p\Mbstring::mb_convert_encoding($s, $to, $from); }
  35670. function mb_decode_mimeheader($s) { return p\Mbstring::mb_decode_mimeheader($s); }
  35671. function mb_encode_mimeheader($s, $charset = null, $transferEnc = null, $lf = null, $indent = null) { return p\Mbstring::mb_encode_mimeheader($s, $charset, $transferEnc, $lf, $indent); }
  35672. function mb_convert_case($s, $mode, $enc = null) { return p\Mbstring::mb_convert_case($s, $mode, $enc); }
  35673. function mb_internal_encoding($enc = null) { return p\Mbstring::mb_internal_encoding($enc); }
  35674. function mb_language($lang = null) { return p\Mbstring::mb_language($lang); }
  35675. function mb_list_encodings() { return p\Mbstring::mb_list_encodings(); }
  35676. function mb_encoding_aliases($encoding) { return p\Mbstring::mb_encoding_aliases($encoding); }
  35677. function mb_check_encoding($var = null, $encoding = null) { return p\Mbstring::mb_check_encoding($var, $encoding); }
  35678. function mb_detect_encoding($str, $encodingList = null, $strict = false) { return p\Mbstring::mb_detect_encoding($str, $encodingList, $strict); }
  35679. function mb_detect_order($encodingList = null) { return p\Mbstring::mb_detect_order($encodingList); }
  35680. function mb_parse_str($s, &$result = array()) { parse_str($s, $result); }
  35681. function mb_strlen($s, $enc = null) { return p\Mbstring::mb_strlen($s, $enc); }
  35682. function mb_strpos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strpos($s, $needle, $offset, $enc); }
  35683. function mb_strtolower($s, $enc = null) { return p\Mbstring::mb_strtolower($s, $enc); }
  35684. function mb_strtoupper($s, $enc = null) { return p\Mbstring::mb_strtoupper($s, $enc); }
  35685. function mb_substitute_character($char = null) { return p\Mbstring::mb_substitute_character($char); }
  35686. function mb_substr($s, $start, $length = 2147483647, $enc = null) { return p\Mbstring::mb_substr($s, $start, $length, $enc); }
  35687. function mb_stripos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_stripos($s, $needle, $offset, $enc); }
  35688. function mb_stristr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_stristr($s, $needle, $part, $enc); }
  35689. function mb_strrchr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strrchr($s, $needle, $part, $enc); }
  35690. function mb_strrichr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strrichr($s, $needle, $part, $enc); }
  35691. function mb_strripos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strripos($s, $needle, $offset, $enc); }
  35692. function mb_strrpos($s, $needle, $offset = 0, $enc = null) { return p\Mbstring::mb_strrpos($s, $needle, $offset, $enc); }
  35693. function mb_strstr($s, $needle, $part = false, $enc = null) { return p\Mbstring::mb_strstr($s, $needle, $part, $enc); }
  35694. function mb_get_info($type = 'all') { return p\Mbstring::mb_get_info($type); }
  35695. function mb_http_output($enc = null) { return p\Mbstring::mb_http_output($enc); }
  35696. function mb_strwidth($s, $enc = null) { return p\Mbstring::mb_strwidth($s, $enc); }
  35697. function mb_substr_count($haystack, $needle, $enc = null) { return p\Mbstring::mb_substr_count($haystack, $needle, $enc); }
  35698. function mb_output_handler($contents, $status) { return p\Mbstring::mb_output_handler($contents, $status); }
  35699. function mb_http_input($type = '') { return p\Mbstring::mb_http_input($type); }
  35700. function mb_convert_variables($toEncoding, $fromEncoding, &$a = null, &$b = null, &$c = null, &$d = null, &$e = null, &$f = null) { return p\Mbstring::mb_convert_variables($toEncoding, $fromEncoding, $a, $b, $c, $d, $e, $f); }
  35701. }
  35702. if (!function_exists('mb_chr')) {
  35703. function mb_ord($s, $enc = null) { return p\Mbstring::mb_ord($s, $enc); }
  35704. function mb_chr($code, $enc = null) { return p\Mbstring::mb_chr($code, $enc); }
  35705. function mb_scrub($s, $enc = null) { $enc = null === $enc ? mb_internal_encoding() : $enc; return mb_convert_encoding($s, $enc, $enc); }
  35706. }
  35707. <?php
  35708. namespace Symfony\Component\Debug;
  35709. use Psr\Log\AbstractLogger;
  35710. class BufferingLogger extends AbstractLogger
  35711. {
  35712. private $logs = array();
  35713. public function log($level, $message, array $context = array())
  35714. {
  35715. $this->logs[] = array($level, $message, $context);
  35716. }
  35717. public function cleanLogs()
  35718. {
  35719. $logs = $this->logs;
  35720. $this->logs = array();
  35721. return $logs;
  35722. }
  35723. }
  35724. <?php
  35725. namespace Symfony\Component\Debug;
  35726. class Debug
  35727. {
  35728. private static $enabled = false;
  35729. public static function enable($errorReportingLevel = E_ALL, $displayErrors = true)
  35730. {
  35731. if (static::$enabled) {
  35732. return;
  35733. }
  35734. static::$enabled = true;
  35735. if (null !== $errorReportingLevel) {
  35736. error_reporting($errorReportingLevel);
  35737. } else {
  35738. error_reporting(E_ALL);
  35739. }
  35740. if ('cli' !== PHP_SAPI) {
  35741. ini_set('display_errors', 0);
  35742. ExceptionHandler::register();
  35743. } elseif ($displayErrors && (!ini_get('log_errors') || ini_get('error_log'))) {
  35744. ini_set('display_errors', 1);
  35745. }
  35746. if ($displayErrors) {
  35747. ErrorHandler::register(new ErrorHandler(new BufferingLogger()));
  35748. } else {
  35749. ErrorHandler::register()->throwAt(0, true);
  35750. }
  35751. DebugClassLoader::enable();
  35752. }
  35753. }
  35754. <?php
  35755. namespace Symfony\Component\Debug;
  35756. class DebugClassLoader
  35757. {
  35758. private $classLoader;
  35759. private $isFinder;
  35760. private $loaded = array();
  35761. private static $caseCheck;
  35762. private static $checkedClasses = array();
  35763. private static $final = array();
  35764. private static $finalMethods = array();
  35765. private static $deprecated = array();
  35766. private static $internal = array();
  35767. private static $internalMethods = array();
  35768. private static $php7Reserved = array('int' => 1, 'float' => 1, 'bool' => 1, 'string' => 1, 'true' => 1, 'false' => 1, 'null' => 1);
  35769. private static $darwinCache = array('/' => array('/', array()));
  35770. public function __construct(callable $classLoader)
  35771. {
  35772. $this->classLoader = $classLoader;
  35773. $this->isFinder = is_array($classLoader) && method_exists($classLoader[0], 'findFile');
  35774. if (!isset(self::$caseCheck)) {
  35775. $file = file_exists(__FILE__) ? __FILE__ : rtrim(realpath('.'), DIRECTORY_SEPARATOR);
  35776. $i = strrpos($file, DIRECTORY_SEPARATOR);
  35777. $dir = substr($file, 0, 1 + $i);
  35778. $file = substr($file, 1 + $i);
  35779. $test = strtoupper($file) === $file ? strtolower($file) : strtoupper($file);
  35780. $test = realpath($dir.$test);
  35781. if (false === $test || false === $i) {
  35782. self::$caseCheck = 0;
  35783. } elseif (substr($test, -strlen($file)) === $file) {
  35784. self::$caseCheck = 1;
  35785. } elseif (false !== stripos(PHP_OS, 'darwin')) {
  35786. self::$caseCheck = 2;
  35787. } else {
  35788. self::$caseCheck = 0;
  35789. }
  35790. }
  35791. }
  35792. public function getClassLoader()
  35793. {
  35794. return $this->classLoader;
  35795. }
  35796. public static function enable()
  35797. {
  35798. class_exists('Symfony\Component\Debug\ErrorHandler');
  35799. class_exists('Psr\Log\LogLevel');
  35800. if (!is_array($functions = spl_autoload_functions())) {
  35801. return;
  35802. }
  35803. foreach ($functions as $function) {
  35804. spl_autoload_unregister($function);
  35805. }
  35806. foreach ($functions as $function) {
  35807. if (!is_array($function) || !$function[0] instanceof self) {
  35808. $function = array(new static($function), 'loadClass');
  35809. }
  35810. spl_autoload_register($function);
  35811. }
  35812. }
  35813. public static function disable()
  35814. {
  35815. if (!is_array($functions = spl_autoload_functions())) {
  35816. return;
  35817. }
  35818. foreach ($functions as $function) {
  35819. spl_autoload_unregister($function);
  35820. }
  35821. foreach ($functions as $function) {
  35822. if (is_array($function) && $function[0] instanceof self) {
  35823. $function = $function[0]->getClassLoader();
  35824. }
  35825. spl_autoload_register($function);
  35826. }
  35827. }
  35828. public function loadClass($class)
  35829. {
  35830. $e = error_reporting(error_reporting() | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
  35831. try {
  35832. if ($this->isFinder && !isset($this->loaded[$class])) {
  35833. $this->loaded[$class] = true;
  35834. if ($file = $this->classLoader[0]->findFile($class) ?: false) {
  35835. $wasCached = \function_exists('opcache_is_script_cached') && opcache_is_script_cached($file);
  35836. require $file;
  35837. if ($wasCached) {
  35838. return;
  35839. }
  35840. }
  35841. } else {
  35842. call_user_func($this->classLoader, $class);
  35843. $file = false;
  35844. }
  35845. } finally {
  35846. error_reporting($e);
  35847. }
  35848. $this->checkClass($class, $file);
  35849. }
  35850. private function checkClass($class, $file = null)
  35851. {
  35852. $exists = null === $file || \class_exists($class, false) || \interface_exists($class, false) || \trait_exists($class, false);
  35853. if (null !== $file && $class && '\\' === $class[0]) {
  35854. $class = substr($class, 1);
  35855. }
  35856. if ($exists) {
  35857. if (isset(self::$checkedClasses[$class])) {
  35858. return;
  35859. }
  35860. self::$checkedClasses[$class] = true;
  35861. $refl = new \ReflectionClass($class);
  35862. if (null === $file && $refl->isInternal()) {
  35863. return;
  35864. }
  35865. $name = $refl->getName();
  35866. if ($name !== $class && 0 === \strcasecmp($name, $class)) {
  35867. throw new \RuntimeException(sprintf('Case mismatch between loaded and declared class names: "%s" vs "%s".', $class, $name));
  35868. }
  35869. if (2 > $len = 1 + (\strpos($name, '\\') ?: \strpos($name, '_'))) {
  35870. $len = 0;
  35871. $ns = '';
  35872. } else {
  35873. $ns = \substr($name, 0, $len);
  35874. }
  35875. if (false !== $doc = $refl->getDocComment()) {
  35876. foreach (array('final', 'deprecated', 'internal') as $annotation) {
  35877. if (false !== \strpos($doc, $annotation) && preg_match('#\n \* @'.$annotation.'(?:( .+?)\.?)?\r?\n \*(?: @|/$)#s', $doc, $notice)) {
  35878. self::${$annotation}[$name] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
  35879. }
  35880. }
  35881. }
  35882. $parentAndTraits = \class_uses($name, false);
  35883. if ($parent = \get_parent_class($class)) {
  35884. $parentAndTraits[] = $parent;
  35885. if (!isset(self::$checkedClasses[$parent])) {
  35886. $this->checkClass($parent);
  35887. }
  35888. if (isset(self::$final[$parent])) {
  35889. @trigger_error(sprintf('The "%s" class is considered final%s. It may change without further notice as of its next major version. You should not extend it from "%s".', $parent, self::$final[$parent], $name), E_USER_DEPRECATED);
  35890. }
  35891. }
  35892. foreach ($parentAndTraits + $this->getOwnInterfaces($name, $parent) as $use) {
  35893. if (!isset(self::$checkedClasses[$use])) {
  35894. $this->checkClass($use);
  35895. }
  35896. if (isset(self::$deprecated[$use]) && \strncmp($ns, $use, $len)) {
  35897. $type = class_exists($name, false) ? 'class' : (interface_exists($name, false) ? 'interface' : 'trait');
  35898. $verb = class_exists($use, false) || interface_exists($name, false) ? 'extends' : (interface_exists($use, false) ? 'implements' : 'uses');
  35899. @trigger_error(sprintf('The "%s" %s %s "%s" that is deprecated%s.', $name, $type, $verb, $use, self::$deprecated[$use]), E_USER_DEPRECATED);
  35900. }
  35901. if (isset(self::$internal[$use]) && \strncmp($ns, $use, $len)) {
  35902. @trigger_error(sprintf('The "%s" %s is considered internal%s. It may change without further notice. You should not use it from "%s".', $use, class_exists($use, false) ? 'class' : (interface_exists($use, false) ? 'interface' : 'trait'), self::$internal[$use], $name), E_USER_DEPRECATED);
  35903. }
  35904. }
  35905. self::$finalMethods[$name] = array();
  35906. self::$internalMethods[$name] = array();
  35907. foreach ($parentAndTraits as $use) {
  35908. foreach (array('finalMethods', 'internalMethods') as $property) {
  35909. if (isset(self::${$property}[$use])) {
  35910. self::${$property}[$name] = self::${$property}[$name] ? self::${$property}[$use] + self::${$property}[$name] : self::${$property}[$use];
  35911. }
  35912. }
  35913. }
  35914. $isClass = \class_exists($name, false);
  35915. foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $method) {
  35916. if ($method->class !== $name) {
  35917. continue;
  35918. }
  35919. if ($method->getFilename() !== $refl->getFileName()) {
  35920. continue;
  35921. }
  35922. if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
  35923. list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
  35924. @trigger_error(sprintf('The "%s::%s()" method is considered final%s. It may change without further notice as of its next major version. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
  35925. }
  35926. foreach ($parentAndTraits as $use) {
  35927. if (isset(self::$internalMethods[$use][$method->name])) {
  35928. list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
  35929. if (\strncmp($ns, $declaringClass, $len)) {
  35930. @trigger_error(sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
  35931. }
  35932. }
  35933. }
  35934. if (false === $doc = $method->getDocComment()) {
  35935. continue;
  35936. }
  35937. foreach (array('final', 'internal') as $annotation) {
  35938. if (false !== \strpos($doc, $annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) {
  35939. $message = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
  35940. self::${$annotation.'Methods'}[$name][$method->name] = array($name, $message);
  35941. }
  35942. }
  35943. }
  35944. if (isset(self::$php7Reserved[\strtolower($refl->getShortName())])) {
  35945. @trigger_error(sprintf('The "%s" class uses the reserved name "%s", it will break on PHP 7 and higher', $name, $refl->getShortName()), E_USER_DEPRECATED);
  35946. }
  35947. }
  35948. if ($file) {
  35949. if (!$exists) {
  35950. if (false !== strpos($class, '/')) {
  35951. throw new \RuntimeException(sprintf('Trying to autoload a class with an invalid name "%s". Be careful that the namespace separator is "\" in PHP, not "/".', $class));
  35952. }
  35953. throw new \RuntimeException(sprintf('The autoloader expected class "%s" to be defined in file "%s". The file was found but the class was not in it, the class name or namespace probably has a typo.', $class, $file));
  35954. }
  35955. if (self::$caseCheck) {
  35956. $real = explode('\\', $class.strrchr($file, '.'));
  35957. $tail = explode(DIRECTORY_SEPARATOR, str_replace('/', DIRECTORY_SEPARATOR, $file));
  35958. $i = count($tail) - 1;
  35959. $j = count($real) - 1;
  35960. while (isset($tail[$i], $real[$j]) && $tail[$i] === $real[$j]) {
  35961. --$i;
  35962. --$j;
  35963. }
  35964. array_splice($tail, 0, $i + 1);
  35965. }
  35966. if (self::$caseCheck && $tail) {
  35967. $tail = DIRECTORY_SEPARATOR.implode(DIRECTORY_SEPARATOR, $tail);
  35968. $tailLen = strlen($tail);
  35969. $real = $refl->getFileName();
  35970. if (2 === self::$caseCheck) {
  35971. $i = 1 + strrpos($real, '/');
  35972. $file = substr($real, $i);
  35973. $real = substr($real, 0, $i);
  35974. if (isset(self::$darwinCache[$real])) {
  35975. $kDir = $real;
  35976. } else {
  35977. $kDir = strtolower($real);
  35978. if (isset(self::$darwinCache[$kDir])) {
  35979. $real = self::$darwinCache[$kDir][0];
  35980. } else {
  35981. $dir = getcwd();
  35982. chdir($real);
  35983. $real = getcwd().'/';
  35984. chdir($dir);
  35985. $dir = $real;
  35986. $k = $kDir;
  35987. $i = strlen($dir) - 1;
  35988. while (!isset(self::$darwinCache[$k])) {
  35989. self::$darwinCache[$k] = array($dir, array());
  35990. self::$darwinCache[$dir] = &self::$darwinCache[$k];
  35991. while ('/' !== $dir[--$i]) {
  35992. }
  35993. $k = substr($k, 0, ++$i);
  35994. $dir = substr($dir, 0, $i--);
  35995. }
  35996. }
  35997. }
  35998. $dirFiles = self::$darwinCache[$kDir][1];
  35999. if (isset($dirFiles[$file])) {
  36000. $kFile = $file;
  36001. } else {
  36002. $kFile = strtolower($file);
  36003. if (!isset($dirFiles[$kFile])) {
  36004. foreach (scandir($real, 2) as $f) {
  36005. if ('.' !== $f[0]) {
  36006. $dirFiles[$f] = $f;
  36007. if ($f === $file) {
  36008. $kFile = $k = $file;
  36009. } elseif ($f !== $k = strtolower($f)) {
  36010. $dirFiles[$k] = $f;
  36011. }
  36012. }
  36013. }
  36014. self::$darwinCache[$kDir][1] = $dirFiles;
  36015. }
  36016. }
  36017. $real .= $dirFiles[$kFile];
  36018. }
  36019. if (0 === substr_compare($real, $tail, -$tailLen, $tailLen, true)
  36020. && 0 !== substr_compare($real, $tail, -$tailLen, $tailLen, false)
  36021. ) {
  36022. throw new \RuntimeException(sprintf('Case mismatch between class and real file names: "%s" vs "%s" in "%s".', substr($tail, -$tailLen + 1), substr($real, -$tailLen + 1), substr($real, 0, -$tailLen + 1)));
  36023. }
  36024. }
  36025. }
  36026. }
  36027. private function getOwnInterfaces($class, $parent)
  36028. {
  36029. $ownInterfaces = class_implements($class, false);
  36030. if ($parent) {
  36031. foreach (class_implements($parent, false) as $interface) {
  36032. unset($ownInterfaces[$interface]);
  36033. }
  36034. }
  36035. foreach ($ownInterfaces as $interface) {
  36036. foreach (class_implements($interface) as $interface) {
  36037. unset($ownInterfaces[$interface]);
  36038. }
  36039. }
  36040. return $ownInterfaces;
  36041. }
  36042. }
  36043. <?php
  36044. namespace Symfony\Component\Debug;
  36045. use Psr\Log\LogLevel;
  36046. use Psr\Log\LoggerInterface;
  36047. use Symfony\Component\Debug\Exception\ContextErrorException;
  36048. use Symfony\Component\Debug\Exception\FatalErrorException;
  36049. use Symfony\Component\Debug\Exception\FatalThrowableError;
  36050. use Symfony\Component\Debug\Exception\OutOfMemoryException;
  36051. use Symfony\Component\Debug\Exception\SilencedErrorContext;
  36052. use Symfony\Component\Debug\FatalErrorHandler\UndefinedFunctionFatalErrorHandler;
  36053. use Symfony\Component\Debug\FatalErrorHandler\UndefinedMethodFatalErrorHandler;
  36054. use Symfony\Component\Debug\FatalErrorHandler\ClassNotFoundFatalErrorHandler;
  36055. use Symfony\Component\Debug\FatalErrorHandler\FatalErrorHandlerInterface;
  36056. class ErrorHandler
  36057. {
  36058. private $levels = array(
  36059. E_DEPRECATED => 'Deprecated',
  36060. E_USER_DEPRECATED => 'User Deprecated',
  36061. E_NOTICE => 'Notice',
  36062. E_USER_NOTICE => 'User Notice',
  36063. E_STRICT => 'Runtime Notice',
  36064. E_WARNING => 'Warning',
  36065. E_USER_WARNING => 'User Warning',
  36066. E_COMPILE_WARNING => 'Compile Warning',
  36067. E_CORE_WARNING => 'Core Warning',
  36068. E_USER_ERROR => 'User Error',
  36069. E_RECOVERABLE_ERROR => 'Catchable Fatal Error',
  36070. E_COMPILE_ERROR => 'Compile Error',
  36071. E_PARSE => 'Parse Error',
  36072. E_ERROR => 'Error',
  36073. E_CORE_ERROR => 'Core Error',
  36074. );
  36075. private $loggers = array(
  36076. E_DEPRECATED => array(null, LogLevel::INFO),
  36077. E_USER_DEPRECATED => array(null, LogLevel::INFO),
  36078. E_NOTICE => array(null, LogLevel::WARNING),
  36079. E_USER_NOTICE => array(null, LogLevel::WARNING),
  36080. E_STRICT => array(null, LogLevel::WARNING),
  36081. E_WARNING => array(null, LogLevel::WARNING),
  36082. E_USER_WARNING => array(null, LogLevel::WARNING),
  36083. E_COMPILE_WARNING => array(null, LogLevel::WARNING),
  36084. E_CORE_WARNING => array(null, LogLevel::WARNING),
  36085. E_USER_ERROR => array(null, LogLevel::CRITICAL),
  36086. E_RECOVERABLE_ERROR => array(null, LogLevel::CRITICAL),
  36087. E_COMPILE_ERROR => array(null, LogLevel::CRITICAL),
  36088. E_PARSE => array(null, LogLevel::CRITICAL),
  36089. E_ERROR => array(null, LogLevel::CRITICAL),
  36090. E_CORE_ERROR => array(null, LogLevel::CRITICAL),
  36091. );
  36092. private $thrownErrors = 0x1FFF;
  36093. private $scopedErrors = 0x1FFF;
  36094. private $tracedErrors = 0x77FB;
  36095. private $screamedErrors = 0x55;
  36096. private $loggedErrors = 0;
  36097. private $traceReflector;
  36098. private $isRecursive = 0;
  36099. private $isRoot = false;
  36100. private $exceptionHandler;
  36101. private $bootstrappingLogger;
  36102. private static $reservedMemory;
  36103. private static $stackedErrors = array();
  36104. private static $stackedErrorLevels = array();
  36105. private static $toStringException = null;
  36106. private static $silencedErrorCache = array();
  36107. private static $silencedErrorCount = 0;
  36108. private static $exitCode = 0;
  36109. public static function register(self $handler = null, $replace = true)
  36110. {
  36111. if (null === self::$reservedMemory) {
  36112. self::$reservedMemory = str_repeat('x', 10240);
  36113. register_shutdown_function(__CLASS__.'::handleFatalError');
  36114. }
  36115. if ($handlerIsNew = null === $handler) {
  36116. $handler = new static();
  36117. }
  36118. if (null === $prev = set_error_handler(array($handler, 'handleError'))) {
  36119. restore_error_handler();
  36120. set_error_handler(array($handler, 'handleError'), $handler->thrownErrors | $handler->loggedErrors);
  36121. $handler->isRoot = true;
  36122. }
  36123. if ($handlerIsNew && is_array($prev) && $prev[0] instanceof self) {
  36124. $handler = $prev[0];
  36125. $replace = false;
  36126. }
  36127. if ($replace || !$prev) {
  36128. $handler->setExceptionHandler(set_exception_handler(array($handler, 'handleException')));
  36129. } else {
  36130. restore_error_handler();
  36131. }
  36132. $handler->throwAt(E_ALL & $handler->thrownErrors, true);
  36133. return $handler;
  36134. }
  36135. public function __construct(BufferingLogger $bootstrappingLogger = null)
  36136. {
  36137. if ($bootstrappingLogger) {
  36138. $this->bootstrappingLogger = $bootstrappingLogger;
  36139. $this->setDefaultLogger($bootstrappingLogger);
  36140. }
  36141. $this->traceReflector = new \ReflectionProperty('Exception', 'trace');
  36142. $this->traceReflector->setAccessible(true);
  36143. }
  36144. public function setDefaultLogger(LoggerInterface $logger, $levels = E_ALL, $replace = false)
  36145. {
  36146. $loggers = array();
  36147. if (is_array($levels)) {
  36148. foreach ($levels as $type => $logLevel) {
  36149. if (empty($this->loggers[$type][0]) || $replace || $this->loggers[$type][0] === $this->bootstrappingLogger) {
  36150. $loggers[$type] = array($logger, $logLevel);
  36151. }
  36152. }
  36153. } else {
  36154. if (null === $levels) {
  36155. $levels = E_ALL;
  36156. }
  36157. foreach ($this->loggers as $type => $log) {
  36158. if (($type & $levels) && (empty($log[0]) || $replace || $log[0] === $this->bootstrappingLogger)) {
  36159. $log[0] = $logger;
  36160. $loggers[$type] = $log;
  36161. }
  36162. }
  36163. }
  36164. $this->setLoggers($loggers);
  36165. }
  36166. public function setLoggers(array $loggers)
  36167. {
  36168. $prevLogged = $this->loggedErrors;
  36169. $prev = $this->loggers;
  36170. $flush = array();
  36171. foreach ($loggers as $type => $log) {
  36172. if (!isset($prev[$type])) {
  36173. throw new \InvalidArgumentException('Unknown error type: '.$type);
  36174. }
  36175. if (!is_array($log)) {
  36176. $log = array($log);
  36177. } elseif (!array_key_exists(0, $log)) {
  36178. throw new \InvalidArgumentException('No logger provided');
  36179. }
  36180. if (null === $log[0]) {
  36181. $this->loggedErrors &= ~$type;
  36182. } elseif ($log[0] instanceof LoggerInterface) {
  36183. $this->loggedErrors |= $type;
  36184. } else {
  36185. throw new \InvalidArgumentException('Invalid logger provided');
  36186. }
  36187. $this->loggers[$type] = $log + $prev[$type];
  36188. if ($this->bootstrappingLogger && $prev[$type][0] === $this->bootstrappingLogger) {
  36189. $flush[$type] = $type;
  36190. }
  36191. }
  36192. $this->reRegister($prevLogged | $this->thrownErrors);
  36193. if ($flush) {
  36194. foreach ($this->bootstrappingLogger->cleanLogs() as $log) {
  36195. $type = $log[2]['exception'] instanceof \ErrorException ? $log[2]['exception']->getSeverity() : E_ERROR;
  36196. if (!isset($flush[$type])) {
  36197. $this->bootstrappingLogger->log($log[0], $log[1], $log[2]);
  36198. } elseif ($this->loggers[$type][0]) {
  36199. $this->loggers[$type][0]->log($this->loggers[$type][1], $log[1], $log[2]);
  36200. }
  36201. }
  36202. }
  36203. return $prev;
  36204. }
  36205. public function setExceptionHandler(callable $handler = null)
  36206. {
  36207. $prev = $this->exceptionHandler;
  36208. $this->exceptionHandler = $handler;
  36209. return $prev;
  36210. }
  36211. public function throwAt($levels, $replace = false)
  36212. {
  36213. $prev = $this->thrownErrors;
  36214. $this->thrownErrors = ($levels | E_RECOVERABLE_ERROR | E_USER_ERROR) & ~E_USER_DEPRECATED & ~E_DEPRECATED;
  36215. if (!$replace) {
  36216. $this->thrownErrors |= $prev;
  36217. }
  36218. $this->reRegister($prev | $this->loggedErrors);
  36219. return $prev;
  36220. }
  36221. public function scopeAt($levels, $replace = false)
  36222. {
  36223. $prev = $this->scopedErrors;
  36224. $this->scopedErrors = (int) $levels;
  36225. if (!$replace) {
  36226. $this->scopedErrors |= $prev;
  36227. }
  36228. return $prev;
  36229. }
  36230. public function traceAt($levels, $replace = false)
  36231. {
  36232. $prev = $this->tracedErrors;
  36233. $this->tracedErrors = (int) $levels;
  36234. if (!$replace) {
  36235. $this->tracedErrors |= $prev;
  36236. }
  36237. return $prev;
  36238. }
  36239. public function screamAt($levels, $replace = false)
  36240. {
  36241. $prev = $this->screamedErrors;
  36242. $this->screamedErrors = (int) $levels;
  36243. if (!$replace) {
  36244. $this->screamedErrors |= $prev;
  36245. }
  36246. return $prev;
  36247. }
  36248. private function reRegister($prev)
  36249. {
  36250. if ($prev !== $this->thrownErrors | $this->loggedErrors) {
  36251. $handler = set_error_handler('var_dump');
  36252. $handler = is_array($handler) ? $handler[0] : null;
  36253. restore_error_handler();
  36254. if ($handler === $this) {
  36255. restore_error_handler();
  36256. if ($this->isRoot) {
  36257. set_error_handler(array($this, 'handleError'), $this->thrownErrors | $this->loggedErrors);
  36258. } else {
  36259. set_error_handler(array($this, 'handleError'));
  36260. }
  36261. }
  36262. }
  36263. }
  36264. public function handleError($type, $message, $file, $line)
  36265. {
  36266. $level = error_reporting() | E_RECOVERABLE_ERROR | E_USER_ERROR | E_DEPRECATED | E_USER_DEPRECATED;
  36267. $log = $this->loggedErrors & $type;
  36268. $throw = $this->thrownErrors & $type & $level;
  36269. $type &= $level | $this->screamedErrors;
  36270. if (!$type || (!$log && !$throw)) {
  36271. return $type && $log;
  36272. }
  36273. $scope = $this->scopedErrors & $type;
  36274. if (4 < $numArgs = func_num_args()) {
  36275. $context = $scope ? (func_get_arg(4) ?: array()) : array();
  36276. $backtrace = 5 < $numArgs ? func_get_arg(5) : null;
  36277. } else {
  36278. $context = array();
  36279. $backtrace = null;
  36280. }
  36281. if (isset($context['GLOBALS']) && $scope) {
  36282. $e = $context;
  36283. unset($e['GLOBALS'], $context);
  36284. $context = $e;
  36285. }
  36286. if (null !== $backtrace && $type & E_ERROR) {
  36287. $this->handleFatalError(compact('type', 'message', 'file', 'line', 'backtrace'));
  36288. return true;
  36289. }
  36290. $logMessage = $this->levels[$type].': '.$message;
  36291. if (null !== self::$toStringException) {
  36292. $errorAsException = self::$toStringException;
  36293. self::$toStringException = null;
  36294. } elseif (!$throw && !($type & $level)) {
  36295. if (!isset(self::$silencedErrorCache[$id = $file.':'.$line])) {
  36296. $lightTrace = $this->tracedErrors & $type ? $this->cleanTrace(debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3), $type, $file, $line, false) : array();
  36297. $errorAsException = new SilencedErrorContext($type, $file, $line, $lightTrace);
  36298. } elseif (isset(self::$silencedErrorCache[$id][$message])) {
  36299. $lightTrace = null;
  36300. $errorAsException = self::$silencedErrorCache[$id][$message];
  36301. ++$errorAsException->count;
  36302. } else {
  36303. $lightTrace = array();
  36304. $errorAsException = null;
  36305. }
  36306. if (100 < ++self::$silencedErrorCount) {
  36307. self::$silencedErrorCache = $lightTrace = array();
  36308. self::$silencedErrorCount = 1;
  36309. }
  36310. if ($errorAsException) {
  36311. self::$silencedErrorCache[$id][$message] = $errorAsException;
  36312. }
  36313. if (null === $lightTrace) {
  36314. return;
  36315. }
  36316. } else {
  36317. if ($scope) {
  36318. $errorAsException = new ContextErrorException($logMessage, 0, $type, $file, $line, $context);
  36319. } else {
  36320. $errorAsException = new \ErrorException($logMessage, 0, $type, $file, $line);
  36321. }
  36322. if ($throw || $this->tracedErrors & $type) {
  36323. $backtrace = $backtrace ?: $errorAsException->getTrace();
  36324. $lightTrace = $this->cleanTrace($backtrace, $type, $file, $line, $throw);
  36325. $this->traceReflector->setValue($errorAsException, $lightTrace);
  36326. } else {
  36327. $this->traceReflector->setValue($errorAsException, array());
  36328. }
  36329. }
  36330. if ($throw) {
  36331. if (E_USER_ERROR & $type) {
  36332. for ($i = 1; isset($backtrace[$i]); ++$i) {
  36333. if (isset($backtrace[$i]['function'], $backtrace[$i]['type'], $backtrace[$i - 1]['function'])
  36334. && '__toString' === $backtrace[$i]['function']
  36335. && '->' === $backtrace[$i]['type']
  36336. && !isset($backtrace[$i - 1]['class'])
  36337. && ('trigger_error' === $backtrace[$i - 1]['function'] || 'user_error' === $backtrace[$i - 1]['function'])
  36338. ) {
  36339. foreach ($context as $e) {
  36340. if (($e instanceof \Exception || $e instanceof \Throwable) && $e->__toString() === $message) {
  36341. if (1 === $i) {
  36342. $errorAsException = $e;
  36343. break;
  36344. }
  36345. self::$toStringException = $e;
  36346. return true;
  36347. }
  36348. }
  36349. if (1 < $i) {
  36350. $this->handleException($errorAsException);
  36351. return false;
  36352. }
  36353. }
  36354. }
  36355. }
  36356. throw $errorAsException;
  36357. }
  36358. if ($this->isRecursive) {
  36359. $log = 0;
  36360. } elseif (self::$stackedErrorLevels) {
  36361. self::$stackedErrors[] = array(
  36362. $this->loggers[$type][0],
  36363. ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG,
  36364. $logMessage,
  36365. $errorAsException ? array('exception' => $errorAsException) : array(),
  36366. );
  36367. } else {
  36368. try {
  36369. $this->isRecursive = true;
  36370. $level = ($type & $level) ? $this->loggers[$type][1] : LogLevel::DEBUG;
  36371. $this->loggers[$type][0]->log($level, $logMessage, $errorAsException ? array('exception' => $errorAsException) : array());
  36372. } finally {
  36373. $this->isRecursive = false;
  36374. }
  36375. }
  36376. return $type && $log;
  36377. }
  36378. public function handleException($exception, array $error = null)
  36379. {
  36380. if (null === $error) {
  36381. self::$exitCode = 255;
  36382. }
  36383. if (!$exception instanceof \Exception) {
  36384. $exception = new FatalThrowableError($exception);
  36385. }
  36386. $type = $exception instanceof FatalErrorException ? $exception->getSeverity() : E_ERROR;
  36387. $handlerException = null;
  36388. if (($this->loggedErrors & $type) || $exception instanceof FatalThrowableError) {
  36389. if ($exception instanceof FatalErrorException) {
  36390. if ($exception instanceof FatalThrowableError) {
  36391. $error = array(
  36392. 'type' => $type,
  36393. 'message' => $message = $exception->getMessage(),
  36394. 'file' => $exception->getFile(),
  36395. 'line' => $exception->getLine(),
  36396. );
  36397. } else {
  36398. $message = 'Fatal '.$exception->getMessage();
  36399. }
  36400. } elseif ($exception instanceof \ErrorException) {
  36401. $message = 'Uncaught '.$exception->getMessage();
  36402. } else {
  36403. $message = 'Uncaught Exception: '.$exception->getMessage();
  36404. }
  36405. }
  36406. if ($this->loggedErrors & $type) {
  36407. try {
  36408. $this->loggers[$type][0]->log($this->loggers[$type][1], $message, array('exception' => $exception));
  36409. } catch (\Exception $handlerException) {
  36410. } catch (\Throwable $handlerException) {
  36411. }
  36412. }
  36413. if ($exception instanceof FatalErrorException && !$exception instanceof OutOfMemoryException && $error) {
  36414. foreach ($this->getFatalErrorHandlers() as $handler) {
  36415. if ($e = $handler->handleError($error, $exception)) {
  36416. $exception = $e;
  36417. break;
  36418. }
  36419. }
  36420. }
  36421. try {
  36422. if (null !== $this->exceptionHandler) {
  36423. return \call_user_func($this->exceptionHandler, $exception);
  36424. }
  36425. $handlerException = $handlerException ?: $exception;
  36426. } catch (\Exception $handlerException) {
  36427. } catch (\Throwable $handlerException) {
  36428. }
  36429. $this->exceptionHandler = null;
  36430. if ($exception === $handlerException) {
  36431. self::$reservedMemory = null;
  36432. throw $exception;
  36433. }
  36434. $this->handleException($handlerException);
  36435. }
  36436. public static function handleFatalError(array $error = null)
  36437. {
  36438. if (null === self::$reservedMemory) {
  36439. return;
  36440. }
  36441. $handler = self::$reservedMemory = null;
  36442. $handlers = array();
  36443. while (!is_array($handler) || !$handler[0] instanceof self) {
  36444. $handler = set_exception_handler('var_dump');
  36445. restore_exception_handler();
  36446. if (!$handler) {
  36447. break;
  36448. }
  36449. restore_exception_handler();
  36450. array_unshift($handlers, $handler);
  36451. }
  36452. foreach ($handlers as $h) {
  36453. set_exception_handler($h);
  36454. }
  36455. if (!$handler) {
  36456. return;
  36457. }
  36458. if ($handler !== $h) {
  36459. $handler[0]->setExceptionHandler($h);
  36460. }
  36461. $handler = $handler[0];
  36462. $handlers = array();
  36463. if ($exit = null === $error) {
  36464. $error = error_get_last();
  36465. }
  36466. try {
  36467. while (self::$stackedErrorLevels) {
  36468. static::unstackErrors();
  36469. }
  36470. } catch (\Exception $exception) {
  36471. } catch (\Throwable $exception) {
  36472. }
  36473. if ($error && $error['type'] &= E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR) {
  36474. $handler->throwAt(0, true);
  36475. $trace = isset($error['backtrace']) ? $error['backtrace'] : null;
  36476. if (0 === strpos($error['message'], 'Allowed memory') || 0 === strpos($error['message'], 'Out of memory')) {
  36477. $exception = new OutOfMemoryException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, false, $trace);
  36478. } else {
  36479. $exception = new FatalErrorException($handler->levels[$error['type']].': '.$error['message'], 0, $error['type'], $error['file'], $error['line'], 2, true, $trace);
  36480. }
  36481. }
  36482. try {
  36483. if (isset($exception)) {
  36484. self::$exitCode = 255;
  36485. $handler->handleException($exception, $error);
  36486. }
  36487. } catch (FatalErrorException $e) {
  36488. }
  36489. if ($exit && self::$exitCode) {
  36490. $exitCode = self::$exitCode;
  36491. register_shutdown_function('register_shutdown_function', function () use ($exitCode) { exit($exitCode); });
  36492. }
  36493. }
  36494. public static function stackErrors()
  36495. {
  36496. @trigger_error('Support for stacking errors is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
  36497. self::$stackedErrorLevels[] = error_reporting(error_reporting() | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR);
  36498. }
  36499. public static function unstackErrors()
  36500. {
  36501. @trigger_error('Support for unstacking errors is deprecated since Symfony 3.4 and will be removed in 4.0.', E_USER_DEPRECATED);
  36502. $level = array_pop(self::$stackedErrorLevels);
  36503. if (null !== $level) {
  36504. $errorReportingLevel = error_reporting($level);
  36505. if ($errorReportingLevel !== ($level | E_PARSE | E_ERROR | E_CORE_ERROR | E_COMPILE_ERROR)) {
  36506. error_reporting($errorReportingLevel);
  36507. }
  36508. }
  36509. if (empty(self::$stackedErrorLevels)) {
  36510. $errors = self::$stackedErrors;
  36511. self::$stackedErrors = array();
  36512. foreach ($errors as $error) {
  36513. $error[0]->log($error[1], $error[2], $error[3]);
  36514. }
  36515. }
  36516. }
  36517. protected function getFatalErrorHandlers()
  36518. {
  36519. return array(
  36520. new UndefinedFunctionFatalErrorHandler(),
  36521. new UndefinedMethodFatalErrorHandler(),
  36522. new ClassNotFoundFatalErrorHandler(),
  36523. );
  36524. }
  36525. private function cleanTrace($backtrace, $type, $file, $line, $throw)
  36526. {
  36527. $lightTrace = $backtrace;
  36528. for ($i = 0; isset($backtrace[$i]); ++$i) {
  36529. if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) {
  36530. $lightTrace = array_slice($lightTrace, 1 + $i);
  36531. break;
  36532. }
  36533. }
  36534. if (!($throw || $this->scopedErrors & $type)) {
  36535. for ($i = 0; isset($lightTrace[$i]); ++$i) {
  36536. unset($lightTrace[$i]['args'], $lightTrace[$i]['object']);
  36537. }
  36538. }
  36539. return $lightTrace;
  36540. }
  36541. }
  36542. <?php
  36543. namespace Symfony\Component\Debug\Exception;
  36544. class ClassNotFoundException extends FatalErrorException
  36545. {
  36546. public function __construct($message, \ErrorException $previous)
  36547. {
  36548. parent::__construct(
  36549. $message,
  36550. $previous->getCode(),
  36551. $previous->getSeverity(),
  36552. $previous->getFile(),
  36553. $previous->getLine(),
  36554. $previous->getPrevious()
  36555. );
  36556. $this->setTrace($previous->getTrace());
  36557. }
  36558. }
  36559. <?php
  36560. namespace Symfony\Component\Debug\Exception;
  36561. class ContextErrorException extends \ErrorException
  36562. {
  36563. private $context = array();
  36564. public function __construct($message, $code, $severity, $filename, $lineno, $context = array())
  36565. {
  36566. parent::__construct($message, $code, $severity, $filename, $lineno);
  36567. $this->context = $context;
  36568. }
  36569. public function getContext()
  36570. {
  36571. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0.', __CLASS__), E_USER_DEPRECATED);
  36572. return $this->context;
  36573. }
  36574. }
  36575. <?php
  36576. namespace Symfony\Component\Debug\Exception;
  36577. class FatalErrorException extends \ErrorException
  36578. {
  36579. public function __construct($message, $code, $severity, $filename, $lineno, $traceOffset = null, $traceArgs = true, array $trace = null)
  36580. {
  36581. parent::__construct($message, $code, $severity, $filename, $lineno);
  36582. if (null !== $trace) {
  36583. if (!$traceArgs) {
  36584. foreach ($trace as &$frame) {
  36585. unset($frame['args'], $frame['this'], $frame);
  36586. }
  36587. }
  36588. $this->setTrace($trace);
  36589. } elseif (null !== $traceOffset) {
  36590. if (function_exists('xdebug_get_function_stack')) {
  36591. $trace = xdebug_get_function_stack();
  36592. if (0 < $traceOffset) {
  36593. array_splice($trace, -$traceOffset);
  36594. }
  36595. foreach ($trace as &$frame) {
  36596. if (!isset($frame['type'])) {
  36597. if (isset($frame['class'])) {
  36598. $frame['type'] = '::';
  36599. }
  36600. } elseif ('dynamic' === $frame['type']) {
  36601. $frame['type'] = '->';
  36602. } elseif ('static' === $frame['type']) {
  36603. $frame['type'] = '::';
  36604. }
  36605. if (!$traceArgs) {
  36606. unset($frame['params'], $frame['args']);
  36607. } elseif (isset($frame['params']) && !isset($frame['args'])) {
  36608. $frame['args'] = $frame['params'];
  36609. unset($frame['params']);
  36610. }
  36611. }
  36612. unset($frame);
  36613. $trace = array_reverse($trace);
  36614. } elseif (function_exists('symfony_debug_backtrace')) {
  36615. $trace = symfony_debug_backtrace();
  36616. if (0 < $traceOffset) {
  36617. array_splice($trace, 0, $traceOffset);
  36618. }
  36619. } else {
  36620. $trace = array();
  36621. }
  36622. $this->setTrace($trace);
  36623. }
  36624. }
  36625. protected function setTrace($trace)
  36626. {
  36627. $traceReflector = new \ReflectionProperty('Exception', 'trace');
  36628. $traceReflector->setAccessible(true);
  36629. $traceReflector->setValue($this, $trace);
  36630. }
  36631. }
  36632. <?php
  36633. namespace Symfony\Component\Debug\Exception;
  36634. class FatalThrowableError extends FatalErrorException
  36635. {
  36636. public function __construct(\Throwable $e)
  36637. {
  36638. if ($e instanceof \ParseError) {
  36639. $message = 'Parse error: '.$e->getMessage();
  36640. $severity = E_PARSE;
  36641. } elseif ($e instanceof \TypeError) {
  36642. $message = 'Type error: '.$e->getMessage();
  36643. $severity = E_RECOVERABLE_ERROR;
  36644. } else {
  36645. $message = $e->getMessage();
  36646. $severity = E_ERROR;
  36647. }
  36648. \ErrorException::__construct(
  36649. $message,
  36650. $e->getCode(),
  36651. $severity,
  36652. $e->getFile(),
  36653. $e->getLine()
  36654. );
  36655. $this->setTrace($e->getTrace());
  36656. }
  36657. }
  36658. <?php
  36659. namespace Symfony\Component\Debug\Exception;
  36660. use Symfony\Component\HttpFoundation\Exception\RequestExceptionInterface;
  36661. use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
  36662. class FlattenException
  36663. {
  36664. private $message;
  36665. private $code;
  36666. private $previous;
  36667. private $trace;
  36668. private $class;
  36669. private $statusCode;
  36670. private $headers;
  36671. private $file;
  36672. private $line;
  36673. public static function create(\Exception $exception, $statusCode = null, array $headers = array())
  36674. {
  36675. $e = new static();
  36676. $e->setMessage($exception->getMessage());
  36677. $e->setCode($exception->getCode());
  36678. if ($exception instanceof HttpExceptionInterface) {
  36679. $statusCode = $exception->getStatusCode();
  36680. $headers = array_merge($headers, $exception->getHeaders());
  36681. } elseif ($exception instanceof RequestExceptionInterface) {
  36682. $statusCode = 400;
  36683. }
  36684. if (null === $statusCode) {
  36685. $statusCode = 500;
  36686. }
  36687. $e->setStatusCode($statusCode);
  36688. $e->setHeaders($headers);
  36689. $e->setTraceFromException($exception);
  36690. $e->setClass(get_class($exception));
  36691. $e->setFile($exception->getFile());
  36692. $e->setLine($exception->getLine());
  36693. $previous = $exception->getPrevious();
  36694. if ($previous instanceof \Exception) {
  36695. $e->setPrevious(static::create($previous));
  36696. } elseif ($previous instanceof \Throwable) {
  36697. $e->setPrevious(static::create(new FatalThrowableError($previous)));
  36698. }
  36699. return $e;
  36700. }
  36701. public function toArray()
  36702. {
  36703. $exceptions = array();
  36704. foreach (array_merge(array($this), $this->getAllPrevious()) as $exception) {
  36705. $exceptions[] = array(
  36706. 'message' => $exception->getMessage(),
  36707. 'class' => $exception->getClass(),
  36708. 'trace' => $exception->getTrace(),
  36709. );
  36710. }
  36711. return $exceptions;
  36712. }
  36713. public function getStatusCode()
  36714. {
  36715. return $this->statusCode;
  36716. }
  36717. public function setStatusCode($code)
  36718. {
  36719. $this->statusCode = $code;
  36720. }
  36721. public function getHeaders()
  36722. {
  36723. return $this->headers;
  36724. }
  36725. public function setHeaders(array $headers)
  36726. {
  36727. $this->headers = $headers;
  36728. }
  36729. public function getClass()
  36730. {
  36731. return $this->class;
  36732. }
  36733. public function setClass($class)
  36734. {
  36735. $this->class = $class;
  36736. }
  36737. public function getFile()
  36738. {
  36739. return $this->file;
  36740. }
  36741. public function setFile($file)
  36742. {
  36743. $this->file = $file;
  36744. }
  36745. public function getLine()
  36746. {
  36747. return $this->line;
  36748. }
  36749. public function setLine($line)
  36750. {
  36751. $this->line = $line;
  36752. }
  36753. public function getMessage()
  36754. {
  36755. return $this->message;
  36756. }
  36757. public function setMessage($message)
  36758. {
  36759. $this->message = $message;
  36760. }
  36761. public function getCode()
  36762. {
  36763. return $this->code;
  36764. }
  36765. public function setCode($code)
  36766. {
  36767. $this->code = $code;
  36768. }
  36769. public function getPrevious()
  36770. {
  36771. return $this->previous;
  36772. }
  36773. public function setPrevious(FlattenException $previous)
  36774. {
  36775. $this->previous = $previous;
  36776. }
  36777. public function getAllPrevious()
  36778. {
  36779. $exceptions = array();
  36780. $e = $this;
  36781. while ($e = $e->getPrevious()) {
  36782. $exceptions[] = $e;
  36783. }
  36784. return $exceptions;
  36785. }
  36786. public function getTrace()
  36787. {
  36788. return $this->trace;
  36789. }
  36790. public function setTraceFromException(\Exception $exception)
  36791. {
  36792. $this->setTrace($exception->getTrace(), $exception->getFile(), $exception->getLine());
  36793. }
  36794. public function setTrace($trace, $file, $line)
  36795. {
  36796. $this->trace = array();
  36797. $this->trace[] = array(
  36798. 'namespace' => '',
  36799. 'short_class' => '',
  36800. 'class' => '',
  36801. 'type' => '',
  36802. 'function' => '',
  36803. 'file' => $file,
  36804. 'line' => $line,
  36805. 'args' => array(),
  36806. );
  36807. foreach ($trace as $entry) {
  36808. $class = '';
  36809. $namespace = '';
  36810. if (isset($entry['class'])) {
  36811. $parts = explode('\\', $entry['class']);
  36812. $class = array_pop($parts);
  36813. $namespace = implode('\\', $parts);
  36814. }
  36815. $this->trace[] = array(
  36816. 'namespace' => $namespace,
  36817. 'short_class' => $class,
  36818. 'class' => isset($entry['class']) ? $entry['class'] : '',
  36819. 'type' => isset($entry['type']) ? $entry['type'] : '',
  36820. 'function' => isset($entry['function']) ? $entry['function'] : null,
  36821. 'file' => isset($entry['file']) ? $entry['file'] : null,
  36822. 'line' => isset($entry['line']) ? $entry['line'] : null,
  36823. 'args' => isset($entry['args']) ? $this->flattenArgs($entry['args']) : array(),
  36824. );
  36825. }
  36826. }
  36827. private function flattenArgs($args, $level = 0, &$count = 0)
  36828. {
  36829. $result = array();
  36830. foreach ($args as $key => $value) {
  36831. if (++$count > 1e4) {
  36832. return array('array', '*SKIPPED over 10000 entries*');
  36833. }
  36834. if ($value instanceof \__PHP_Incomplete_Class) {
  36835. $result[$key] = array('incomplete-object', $this->getClassNameFromIncomplete($value));
  36836. } elseif (is_object($value)) {
  36837. $result[$key] = array('object', get_class($value));
  36838. } elseif (is_array($value)) {
  36839. if ($level > 10) {
  36840. $result[$key] = array('array', '*DEEP NESTED ARRAY*');
  36841. } else {
  36842. $result[$key] = array('array', $this->flattenArgs($value, $level + 1, $count));
  36843. }
  36844. } elseif (null === $value) {
  36845. $result[$key] = array('null', null);
  36846. } elseif (is_bool($value)) {
  36847. $result[$key] = array('boolean', $value);
  36848. } elseif (is_int($value)) {
  36849. $result[$key] = array('integer', $value);
  36850. } elseif (is_float($value)) {
  36851. $result[$key] = array('float', $value);
  36852. } elseif (is_resource($value)) {
  36853. $result[$key] = array('resource', get_resource_type($value));
  36854. } else {
  36855. $result[$key] = array('string', (string) $value);
  36856. }
  36857. }
  36858. return $result;
  36859. }
  36860. private function getClassNameFromIncomplete(\__PHP_Incomplete_Class $value)
  36861. {
  36862. $array = new \ArrayObject($value);
  36863. return $array['__PHP_Incomplete_Class_Name'];
  36864. }
  36865. }
  36866. <?php
  36867. namespace Symfony\Component\Debug\Exception;
  36868. class OutOfMemoryException extends FatalErrorException
  36869. {
  36870. }
  36871. <?php
  36872. namespace Symfony\Component\Debug\Exception;
  36873. class SilencedErrorContext implements \JsonSerializable
  36874. {
  36875. public $count = 1;
  36876. private $severity;
  36877. private $file;
  36878. private $line;
  36879. private $trace;
  36880. public function __construct($severity, $file, $line, array $trace = array(), $count = 1)
  36881. {
  36882. $this->severity = $severity;
  36883. $this->file = $file;
  36884. $this->line = $line;
  36885. $this->trace = $trace;
  36886. $this->count = $count;
  36887. }
  36888. public function getSeverity()
  36889. {
  36890. return $this->severity;
  36891. }
  36892. public function getFile()
  36893. {
  36894. return $this->file;
  36895. }
  36896. public function getLine()
  36897. {
  36898. return $this->line;
  36899. }
  36900. public function getTrace()
  36901. {
  36902. return $this->trace;
  36903. }
  36904. public function JsonSerialize()
  36905. {
  36906. return array(
  36907. 'severity' => $this->severity,
  36908. 'file' => $this->file,
  36909. 'line' => $this->line,
  36910. 'trace' => $this->trace,
  36911. 'count' => $this->count,
  36912. );
  36913. }
  36914. }
  36915. <?php
  36916. namespace Symfony\Component\Debug\Exception;
  36917. class UndefinedFunctionException extends FatalErrorException
  36918. {
  36919. public function __construct($message, \ErrorException $previous)
  36920. {
  36921. parent::__construct(
  36922. $message,
  36923. $previous->getCode(),
  36924. $previous->getSeverity(),
  36925. $previous->getFile(),
  36926. $previous->getLine(),
  36927. $previous->getPrevious()
  36928. );
  36929. $this->setTrace($previous->getTrace());
  36930. }
  36931. }
  36932. <?php
  36933. namespace Symfony\Component\Debug\Exception;
  36934. class UndefinedMethodException extends FatalErrorException
  36935. {
  36936. public function __construct($message, \ErrorException $previous)
  36937. {
  36938. parent::__construct(
  36939. $message,
  36940. $previous->getCode(),
  36941. $previous->getSeverity(),
  36942. $previous->getFile(),
  36943. $previous->getLine(),
  36944. $previous->getPrevious()
  36945. );
  36946. $this->setTrace($previous->getTrace());
  36947. }
  36948. }
  36949. <?php
  36950. namespace Symfony\Component\Debug;
  36951. use Symfony\Component\Debug\Exception\FlattenException;
  36952. use Symfony\Component\Debug\Exception\OutOfMemoryException;
  36953. use Symfony\Component\HttpKernel\Debug\FileLinkFormatter;
  36954. class ExceptionHandler
  36955. {
  36956. private $debug;
  36957. private $charset;
  36958. private $handler;
  36959. private $caughtBuffer;
  36960. private $caughtLength;
  36961. private $fileLinkFormat;
  36962. public function __construct($debug = true, $charset = null, $fileLinkFormat = null)
  36963. {
  36964. $this->debug = $debug;
  36965. $this->charset = $charset ?: ini_get('default_charset') ?: 'UTF-8';
  36966. $this->fileLinkFormat = $fileLinkFormat ?: ini_get('xdebug.file_link_format') ?: get_cfg_var('xdebug.file_link_format');
  36967. }
  36968. public static function register($debug = true, $charset = null, $fileLinkFormat = null)
  36969. {
  36970. $handler = new static($debug, $charset, $fileLinkFormat);
  36971. $prev = set_exception_handler(array($handler, 'handle'));
  36972. if (is_array($prev) && $prev[0] instanceof ErrorHandler) {
  36973. restore_exception_handler();
  36974. $prev[0]->setExceptionHandler(array($handler, 'handle'));
  36975. }
  36976. return $handler;
  36977. }
  36978. public function setHandler(callable $handler = null)
  36979. {
  36980. $old = $this->handler;
  36981. $this->handler = $handler;
  36982. return $old;
  36983. }
  36984. public function setFileLinkFormat($fileLinkFormat)
  36985. {
  36986. $old = $this->fileLinkFormat;
  36987. $this->fileLinkFormat = $fileLinkFormat;
  36988. return $old;
  36989. }
  36990. public function handle(\Exception $exception)
  36991. {
  36992. if (null === $this->handler || $exception instanceof OutOfMemoryException) {
  36993. $this->sendPhpResponse($exception);
  36994. return;
  36995. }
  36996. $caughtLength = $this->caughtLength = 0;
  36997. ob_start(function ($buffer) {
  36998. $this->caughtBuffer = $buffer;
  36999. return '';
  37000. });
  37001. $this->sendPhpResponse($exception);
  37002. while (null === $this->caughtBuffer && ob_end_flush()) {
  37003. }
  37004. if (isset($this->caughtBuffer[0])) {
  37005. ob_start(function ($buffer) {
  37006. if ($this->caughtLength) {
  37007. $cleanBuffer = substr_replace($buffer, '', 0, $this->caughtLength);
  37008. if (isset($cleanBuffer[0])) {
  37009. $buffer = $cleanBuffer;
  37010. }
  37011. }
  37012. return $buffer;
  37013. });
  37014. echo $this->caughtBuffer;
  37015. $caughtLength = ob_get_length();
  37016. }
  37017. $this->caughtBuffer = null;
  37018. try {
  37019. call_user_func($this->handler, $exception);
  37020. $this->caughtLength = $caughtLength;
  37021. } catch (\Exception $e) {
  37022. if (!$caughtLength) {
  37023. throw $exception;
  37024. }
  37025. }
  37026. }
  37027. public function sendPhpResponse($exception)
  37028. {
  37029. if (!$exception instanceof FlattenException) {
  37030. $exception = FlattenException::create($exception);
  37031. }
  37032. if (!headers_sent()) {
  37033. header(sprintf('HTTP/1.0 %s', $exception->getStatusCode()));
  37034. foreach ($exception->getHeaders() as $name => $value) {
  37035. header($name.': '.$value, false);
  37036. }
  37037. header('Content-Type: text/html; charset='.$this->charset);
  37038. }
  37039. echo $this->decorate($this->getContent($exception), $this->getStylesheet($exception));
  37040. }
  37041. public function getHtml($exception)
  37042. {
  37043. if (!$exception instanceof FlattenException) {
  37044. $exception = FlattenException::create($exception);
  37045. }
  37046. return $this->decorate($this->getContent($exception), $this->getStylesheet($exception));
  37047. }
  37048. public function getContent(FlattenException $exception)
  37049. {
  37050. switch ($exception->getStatusCode()) {
  37051. case 404:
  37052. $title = 'Sorry, the page you are looking for could not be found.';
  37053. break;
  37054. default:
  37055. $title = 'Whoops, looks like something went wrong.';
  37056. }
  37057. $content = '';
  37058. if ($this->debug) {
  37059. try {
  37060. $count = count($exception->getAllPrevious());
  37061. $total = $count + 1;
  37062. foreach ($exception->toArray() as $position => $e) {
  37063. $ind = $count - $position + 1;
  37064. $class = $this->formatClass($e['class']);
  37065. $message = nl2br($this->escapeHtml($e['message']));
  37066. $content .= sprintf(<<<'EOF'
  37067. <div class="trace trace-as-html">
  37068. <table class="trace-details">
  37069. <thead class="trace-head"><tr><th>
  37070. <h3 class="trace-class">
  37071. <span class="text-muted">(%d/%d)</span>
  37072. <span class="exception_title">%s</span>
  37073. </h3>
  37074. <p class="break-long-words trace-message">%s</p>
  37075. </th></tr></thead>
  37076. <tbody>
  37077. EOF
  37078. , $ind, $total, $class, $message);
  37079. foreach ($e['trace'] as $trace) {
  37080. $content .= '<tr><td>';
  37081. if ($trace['function']) {
  37082. $content .= sprintf('at <span class="trace-class">%s</span><span class="trace-type">%s</span><span class="trace-method">%s</span>(<span class="trace-arguments">%s</span>)', $this->formatClass($trace['class']), $trace['type'], $trace['function'], $this->formatArgs($trace['args']));
  37083. }
  37084. if (isset($trace['file']) && isset($trace['line'])) {
  37085. $content .= $this->formatPath($trace['file'], $trace['line']);
  37086. }
  37087. $content .= "</td></tr>\n";
  37088. }
  37089. $content .= "</tbody>\n</table>\n</div>\n";
  37090. }
  37091. } catch (\Exception $e) {
  37092. if ($this->debug) {
  37093. $title = sprintf('Exception thrown when handling an exception (%s: %s)', get_class($e), $this->escapeHtml($e->getMessage()));
  37094. } else {
  37095. $title = 'Whoops, looks like something went wrong.';
  37096. }
  37097. }
  37098. }
  37099. $symfonyGhostImageContents = $this->getSymfonyGhostAsSvg();
  37100. return <<<EOF
  37101. <div class="exception-summary">
  37102. <div class="container">
  37103. <div class="exception-message-wrapper">
  37104. <h1 class="break-long-words exception-message">$title</h1>
  37105. <div class="exception-illustration hidden-xs-down">$symfonyGhostImageContents</div>
  37106. </div>
  37107. </div>
  37108. </div>
  37109. <div class="container">
  37110. $content
  37111. </div>
  37112. EOF;
  37113. }
  37114. public function getStylesheet(FlattenException $exception)
  37115. {
  37116. return <<<'EOF'
  37117. body { background-color: #F9F9F9; color: #222; font: 14px/1.4 Helvetica, Arial, sans-serif; margin: 0; padding-bottom: 45px; }
  37118. a { cursor: pointer; text-decoration: none; }
  37119. a:hover { text-decoration: underline; }
  37120. abbr[title] { border-bottom: none; cursor: help; text-decoration: none; }
  37121. code, pre { font: 13px/1.5 Consolas, Monaco, Menlo, "Ubuntu Mono", "Liberation Mono", monospace; }
  37122. table, tr, th, td { background: #FFF; border-collapse: collapse; vertical-align: top; }
  37123. table { background: #FFF; border: 1px solid #E0E0E0; box-shadow: 0px 0px 1px rgba(128, 128, 128, .2); margin: 1em 0; width: 100%; }
  37124. table th, table td { border: solid #E0E0E0; border-width: 1px 0; padding: 8px 10px; }
  37125. table th { background-color: #E0E0E0; font-weight: bold; text-align: left; }
  37126. .hidden-xs-down { display: none; }
  37127. .block { display: block; }
  37128. .break-long-words { -ms-word-break: break-all; word-break: break-all; word-break: break-word; -webkit-hyphens: auto; -moz-hyphens: auto; hyphens: auto; }
  37129. .text-muted { color: #999; }
  37130. .container { max-width: 1024px; margin: 0 auto; padding: 0 15px; }
  37131. .container::after { content: ""; display: table; clear: both; }
  37132. .exception-summary { background: #B0413E; border-bottom: 2px solid rgba(0, 0, 0, 0.1); border-top: 1px solid rgba(0, 0, 0, .3); flex: 0 0 auto; margin-bottom: 30px; }
  37133. .exception-message-wrapper { display: flex; align-items: center; min-height: 70px; }
  37134. .exception-message { flex-grow: 1; padding: 30px 0; }
  37135. .exception-message, .exception-message a { color: #FFF; font-size: 21px; font-weight: 400; margin: 0; }
  37136. .exception-message.long { font-size: 18px; }
  37137. .exception-message a { border-bottom: 1px solid rgba(255, 255, 255, 0.5); font-size: inherit; text-decoration: none; }
  37138. .exception-message a:hover { border-bottom-color: #ffffff; }
  37139. .exception-illustration { flex-basis: 111px; flex-shrink: 0; height: 66px; margin-left: 15px; opacity: .7; }
  37140. .trace + .trace { margin-top: 30px; }
  37141. .trace-head .trace-class { color: #222; font-size: 18px; font-weight: bold; line-height: 1.3; margin: 0; position: relative; }
  37142. .trace-message { font-size: 14px; font-weight: normal; margin: .5em 0 0; }
  37143. .trace-file-path, .trace-file-path a { color: #222; margin-top: 3px; font-size: 13px; }
  37144. .trace-class { color: #B0413E; }
  37145. .trace-type { padding: 0 2px; }
  37146. .trace-method { color: #B0413E; font-weight: bold; }
  37147. .trace-arguments { color: #777; font-weight: normal; padding-left: 2px; }
  37148. @media (min-width: 575px) {
  37149. .hidden-xs-down { display: initial; }
  37150. }
  37151. EOF;
  37152. }
  37153. private function decorate($content, $css)
  37154. {
  37155. return <<<EOF
  37156. <!DOCTYPE html>
  37157. <html>
  37158. <head>
  37159. <meta charset="{$this->charset}" />
  37160. <meta name="robots" content="noindex,nofollow" />
  37161. <style>$css</style>
  37162. </head>
  37163. <body>
  37164. $content
  37165. </body>
  37166. </html>
  37167. EOF;
  37168. }
  37169. private function formatClass($class)
  37170. {
  37171. $parts = explode('\\', $class);
  37172. return sprintf('<abbr title="%s">%s</abbr>', $class, array_pop($parts));
  37173. }
  37174. private function formatPath($path, $line)
  37175. {
  37176. $file = $this->escapeHtml(preg_match('#[^/\\\\]*+$#', $path, $file) ? $file[0] : $path);
  37177. $fmt = $this->fileLinkFormat;
  37178. if ($fmt && $link = is_string($fmt) ? strtr($fmt, array('%f' => $path, '%l' => $line)) : $fmt->format($path, $line)) {
  37179. return sprintf('<span class="block trace-file-path">in <a href="%s" title="Go to source">%s (line %d)</a></span>', $this->escapeHtml($link), $file, $line);
  37180. }
  37181. return sprintf('<span class="block trace-file-path">in <a title="%s line %3$d"><strong>%s</strong> (line %d)</a></span>', $this->escapeHtml($path), $file, $line);
  37182. }
  37183. private function formatArgs(array $args)
  37184. {
  37185. $result = array();
  37186. foreach ($args as $key => $item) {
  37187. if ('object' === $item[0]) {
  37188. $formattedValue = sprintf('<em>object</em>(%s)', $this->formatClass($item[1]));
  37189. } elseif ('array' === $item[0]) {
  37190. $formattedValue = sprintf('<em>array</em>(%s)', is_array($item[1]) ? $this->formatArgs($item[1]) : $item[1]);
  37191. } elseif ('null' === $item[0]) {
  37192. $formattedValue = '<em>null</em>';
  37193. } elseif ('boolean' === $item[0]) {
  37194. $formattedValue = '<em>'.strtolower(var_export($item[1], true)).'</em>';
  37195. } elseif ('resource' === $item[0]) {
  37196. $formattedValue = '<em>resource</em>';
  37197. } else {
  37198. $formattedValue = str_replace("\n", '', $this->escapeHtml(var_export($item[1], true)));
  37199. }
  37200. $result[] = is_int($key) ? $formattedValue : sprintf("'%s' => %s", $this->escapeHtml($key), $formattedValue);
  37201. }
  37202. return implode(', ', $result);
  37203. }
  37204. private function escapeHtml($str)
  37205. {
  37206. return htmlspecialchars($str, ENT_COMPAT | ENT_SUBSTITUTE, $this->charset);
  37207. }
  37208. private function getSymfonyGhostAsSvg()
  37209. {
  37210. return '<svg viewBox="0 0 136 81" xmlns="http://www.w3.org/2000/svg" fill-rule="evenodd" clip-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="1.414"><path d="M92.358 20.403a23.168 23.168 0 0 1 9.003 1.881 23.67 23.67 0 0 1 5.197 3.079 24.257 24.257 0 0 1 3.457 3.296 24.771 24.771 0 0 1 5.042 9.396c.486 1.72.78 3.492.895 5.28l.008.142.028.158.015.246v13.875c.116.034.232.065.348.098.193.054.383.116.577.168.487.125.989.191 1.49.215.338.016.689.023 1.021-.059.021-.005.032-.029.048-.044l.095-.1c.243-.265.461-.552.663-.851.277-.408.523-.837.746-1.279l.042-.087c-.066-.012-.131-.026-.197-.04l-.099-.023a5.536 5.536 0 0 1-.694-.242 5.649 5.649 0 0 1-2.374-1.845 5.694 5.694 0 0 1-.824-1.594 6.514 6.514 0 0 1-.267-2.781c.045-.394.126-.779.233-1.159.079-.278.162-.562.307-.812.094-.163.129-.196.247-.341l.79-.882c.143-.143.174-.186.34-.303.249-.174.536-.289.834-.333.074-.011.15-.014.224-.02l1.188-.037c.173.004.217-.002.388.028s.211.05.375.105l.018.007c.059.026.119.05.176.079.151.076.179.104.313.2l.006-.021c.073-.187.084-.238.187-.41.077-.129.167-.249.27-.357.051-.054.108-.103.162-.154l1.124-.95c.14-.107.172-.14.327-.224.155-.085.199-.094.363-.154l.019-.006c.169-.043.211-.06.385-.077.174-.016.218-.007.392.003l1.446.158c.193.033.244.033.43.098.278.097.534.259.744.47.053.053.1.112.149.167l.923 1.158.149.213.028.054.017-.014.184-.125c.196-.104.196-.104.402-.184l1.386-.451c.064-.018.126-.038.19-.052.129-.028.259-.042.39-.043.16-.002.321.017.478.047.364.069.711.21 1.032.396.162.094.316.199.469.308.088.063.176.132.27.188l.021.011c.19.123.245.146.409.305.185.178.336.393.443.63.035.079.061.162.091.243l.439 1.428c.045.175.062.219.081.4.02.193.006.381-.015.573a7.79 7.79 0 0 1-.101.645c-.09.455-.212.901-.365 1.339-.128.366-.273.73-.445 1.077-.658 1.335-1.652 2.512-2.917 3.265a6.399 6.399 0 0 1-1.019.489 6.097 6.097 0 0 1-.631.203c-.226.058-.455.1-.686.134l-.096.012-.061.007c-.01.176-.022.352-.036.528-.034.39-.082.778-.153 1.163a14.258 14.258 0 0 1-.574 2.114c-.229.654-.484 1.306-.806 1.918a9.16 9.16 0 0 1-.386.656c-.219.348-.451.686-.697 1.013-.448.594-.946 1.148-1.521 1.614-.255.207-.52.397-.808.553-.9.489-1.919.648-2.921.735-.493.038-.986.059-1.478.099-.162.015-.324.033-.486.049-.145.011-.289.022-.434.03a15.768 15.768 0 0 1-2.778-.118c0 1.416.007 2.832-.001 4.248a9.737 9.737 0 0 1-.684 3.479 9.615 9.615 0 0 1-1.72 2.804 9.326 9.326 0 0 1-3.04 2.279 9.046 9.046 0 0 1-5.33.715 9.064 9.064 0 0 1-2.988-1.079 9.363 9.363 0 0 1-2.761-2.429 10.078 10.078 0 0 1-1.05 1.16 9.281 9.281 0 0 1-1.871 1.358 9.033 9.033 0 0 1-2.495.926 9.04 9.04 0 0 1-6.462-1.072 9.395 9.395 0 0 1-2.602-2.292l-.062-.08a10.896 10.896 0 0 1-.53.635 9.266 9.266 0 0 1-2.671 2.032 9.028 9.028 0 0 1-6.044.751 9.048 9.048 0 0 1-2.436-.934 9.343 9.343 0 0 1-2.286-1.803 9.572 9.572 0 0 1-1.783-2.757 9.705 9.705 0 0 1-.773-3.693V67.244c-.157.024-.314.047-.472.067-.487.06-.977.103-1.469.109-.313.004-.627-.009-.94-.028-.426-.025-.85-.065-1.273-.125-1.833-.264-3.65-.92-5.109-2.117a8.172 8.172 0 0 1-1.064-1.049 10.155 10.155 0 0 1-.878-1.236 15.277 15.277 0 0 1-.7-1.274 20.835 20.835 0 0 1-1.889-6.194l-.018-.142-.008-.061a6.47 6.47 0 0 1-.99-.297 6.135 6.135 0 0 1-.61-.285 6.587 6.587 0 0 1-.889-.562c-1.228-.924-2.124-2.259-2.668-3.711a9.947 9.947 0 0 1-.307-.99 10.288 10.288 0 0 1-.318-1.923c-.009-.147-.011-.293-.015-.44v-.037c.008-.175.004-.22.037-.393.033-.173.053-.213.11-.378l.561-1.417c.031-.068.06-.139.095-.206a2.028 2.028 0 0 1 .771-.803c.093-.054.194-.095.289-.145l.311-.179c.352-.194.714-.358 1.107-.44.213-.044.426-.061.643-.061l.034.001c.177.014.223.01.396.052.174.041.214.065.379.132l1.347.635c.073.04.15.076.221.121.142.091.272.2.388.325.154.166.176.222.297.414l.022.047.722-.762.168-.158c.165-.122.202-.161.385-.253.206-.102.429-.168.656-.193.076-.008.152-.008.228-.011l1.46.013c.177.011.223.007.397.046.175.038.215.061.381.126l.018.008c.154.08.196.094.338.196.142.102.169.137.294.259l.853.912.152-.067.191-.063.019-.005.196-.042c.177-.019.222-.031.401-.022.066.003.133.013.199.02l1.185.182c.073.016.147.027.219.047.288.08.558.227.784.428.151.135.177.181.303.339l.714 1.004c.097.152.127.187.201.352.077.172.123.352.164.536.029.134.056.269.08.404.063.361.102.725.112 1.091.021.78-.08 1.566-.321 2.307a5.906 5.906 0 0 1-.532 1.183 5.463 5.463 0 0 1-3.257 2.489l-.03.008c.195.584.433 1.155.712 1.701.215.422.453.833.735 1.211.026.035.026.034.053.068l.058.072c.056.024.113.042.171.06.319.09.653.121.982.14.488.027.978.013 1.461-.06.167-.028.333-.062.499-.089.134-.022.267-.042.401-.066l.28-.056c.154-.023.308-.049.462-.076l.115-.021V43.881c.011-.203.006-.203.042-.404a26.66 26.66 0 0 1 .226-2.241 24.737 24.737 0 0 1 5.72-12.577 24.204 24.204 0 0 1 3.457-3.296 23.653 23.653 0 0 1 4.937-2.966 23.215 23.215 0 0 1 5.604-1.681 23.703 23.703 0 0 1 3.958-.313zm-.287 2.042a21.169 21.169 0 0 0-8.012 1.622 21.636 21.636 0 0 0-4.799 2.766 22.233 22.233 0 0 0-3.205 2.985 22.705 22.705 0 0 0-4.897 9.196 23.383 23.383 0 0 0-.737 4.867h-.025v15.744c-.258.053-.258.052-.517.101-.28.051-.56.1-.841.144-.211.04-.421.079-.632.115l-.232.037-.411.078c-.116.02-.233.035-.348.057-.305.056-.609.11-.917.14a9.929 9.929 0 0 1-1.883-.017c-.514-.056-1.044-.155-1.51-.397a1.762 1.762 0 0 1-.33-.218 1.925 1.925 0 0 1-.234-.252 5.248 5.248 0 0 1-.174-.22 8.97 8.97 0 0 1-.582-.883 13.806 13.806 0 0 1-.941-1.971 14.348 14.348 0 0 1-.608-1.954 14.04 14.04 0 0 1-.169-.86l-.015-.11-.015-.109c.161-.007.16-.007.321-.016a12.793 12.793 0 0 0 1.413-.182 4.43 4.43 0 0 0 .28-.074 3.56 3.56 0 0 0 1.199-.616c.309-.244.576-.543.786-.88.163-.261.292-.544.387-.838.123-.378.192-.774.214-1.172a5.102 5.102 0 0 0-.024-.865 7.192 7.192 0 0 0-.145-.799l-.714-1.005-1.184-.182-.019.005-.946.758-.12 1.229a4.953 4.953 0 0 1 .111.455c.032.181.052.36.043.544a1.04 1.04 0 0 1-.056.303c-.11.301-.419.451-.696.548-.402.142-.813.25-1.229.339l.07-.648c.022-.191.047-.381.08-.57.036-.207.079-.413.152-.61.077-.211.182-.412.296-.605.044-.074.092-.146.135-.222.029-.048.031-.047.055-.098.016-.033.031-.064.045-.098l-.026-1.551-1.042-1.116-.018-.008-1.459-.014-1.022 1.079c-.049.128-.08.258-.111.393a5.274 5.274 0 0 0-.1.651 5.55 5.55 0 0 0-.031.466c-.009.687.104 1.37.294 2.028.11.382.262.753.402 1.123-.115-.029-.228-.06-.342-.092a9.526 9.526 0 0 1-1.176-.446c-.108-.05-.111-.048-.191-.097a1.921 1.921 0 0 1-.327-.249c-.416-.4-.589-.986-.671-1.55a5.643 5.643 0 0 1-.057-.549c-.007-.143-.006-.286-.007-.429-.001-.186.005-.372.011-.558l.001-.039-.567-1.446-1.347-.634c-.316-.008-.599.144-.867.299-.109.063-.218.126-.33.185a2.058 2.058 0 0 1-.125.061l-.042.019-.561 1.416c0 .209.014.416.036.624.04.377.106.75.196 1.118.076.309.164.616.275.913.415 1.109 1.093 2.146 2.043 2.838.234.171.485.317.746.442.183.088.371.161.565.22.263.079.532.13.803.17.296.045.594.075.892.095l.108.007c.004.151.01.302.017.453.011.177.023.353.038.529a18.13 18.13 0 0 0 .762 3.752c.239.76.522 1.505.857 2.225.23.494.483.977.767 1.44.288.469.608.915.989 1.308 1.001 1.028 2.324 1.648 3.687 1.976.643.155 1.298.243 1.955.287.311.021.622.036.933.033.418-.006.835-.041 1.25-.094.238-.03.477-.064.713-.11.117-.023.232-.053.348-.081.196-.048.392-.097.586-.151.147-.041.291-.094.436-.144.204-.069.408-.139.608-.217l.006-.003c0 2.207-.013 4.414.001 6.62a7.942 7.942 0 0 0 .13 1.32 7.545 7.545 0 0 0 2.383 4.243 7.23 7.23 0 0 0 2.258 1.372 7.094 7.094 0 0 0 7.012-1.164 7.504 7.504 0 0 0 2.035-2.613 7.727 7.727 0 0 0 .676-2.401l.009-.088.038-.765a8.16 8.16 0 0 0 .113 1.324c.121.694.338 1.37.643 2.001a7.49 7.49 0 0 0 1.692 2.275 7.266 7.266 0 0 0 2.24 1.399 7.11 7.11 0 0 0 4.615.19 7.212 7.212 0 0 0 2.351-1.218 7.501 7.501 0 0 0 2.128-2.64 7.763 7.763 0 0 0 .702-2.39l.01-.088.009-.088.038-.765a9.339 9.339 0 0 0 .021.575 7.626 7.626 0 0 0 .621 2.504 7.507 7.507 0 0 0 2.35 2.972 7.1 7.1 0 0 0 7.026.881 7.275 7.275 0 0 0 2.268-1.515 7.525 7.525 0 0 0 1.612-2.338 7.58 7.58 0 0 0 .572-2.033c.048-.347.069-.696.071-1.046v-6.721c.136.051.271.101.408.148a12.153 12.153 0 0 0 1.976.443c.264.035.529.055.794.071.33.02.66.031.991.027.245-.002.49-.012.735-.031.245-.018.49-.048.735-.068.407-.03.814-.051 1.221-.079a9.493 9.493 0 0 0 1.384-.188c.315-.073.626-.174.912-.329a3.53 3.53 0 0 0 .586-.418c.46-.386.85-.85 1.205-1.337a12.178 12.178 0 0 0 .801-1.246c.122-.232.229-.471.33-.712a15.873 15.873 0 0 0 .681-1.988c.136-.525.23-1.058.282-1.598.035-.41.052-.822.088-1.232.03-.317.078-.632.121-.947l.018-.145.016-.145c.144.009.287.016.431.021.459.009.924.007 1.378-.07a4.456 4.456 0 0 0 1.353-.482c.989-.55 1.752-1.466 2.258-2.488.116-.235.214-.48.304-.727a7.58 7.58 0 0 0 .377-1.43c.016-.109.027-.218.039-.328l.001-.009-.438-1.428a5.206 5.206 0 0 1-.16-.096c-.158-.105-.311-.219-.467-.326a3.829 3.829 0 0 0-.159-.1 1.356 1.356 0 0 0-.509-.18l-.01-.001-1.386.452-.681 1.323c-.016.212-.023.424-.043.636a5.66 5.66 0 0 1-.139.873c-.118.494-.316.999-.702 1.338a1.865 1.865 0 0 1-.496.301l-.272.087a9.57 9.57 0 0 1-.83.205 8.797 8.797 0 0 1-.582.091l.229-.462c.079-.163.158-.325.229-.492.051-.118.096-.239.139-.36.036-.103.076-.209.103-.315.019-.075.031-.153.041-.229.017-.132.031-.263.043-.395.035-.368.06-.737.094-1.104.02-.187.048-.372.067-.559.015-.167.015-.336.012-.505a4.76 4.76 0 0 0-.074-.826c-.012-.065-.03-.13-.045-.194l-.003-.009-.923-1.157-1.446-.159-.019.006-1.124.95-.154 1.489c.011.034.024.066.037.099.044.115.107.221.161.331.046.096.088.193.13.29l.031.076c.013.033.017.07.023.105.012.096.022.191.031.287.031.364.047.73.081 1.093.013.102.028.202.04.303.014.145.027.29.033.435.014.28.016.561.023.841a9.588 9.588 0 0 1-.862-.323c-.063-.027-.128-.062-.193-.084a1.325 1.325 0 0 0-.067-.013c-.081-.01-.162-.017-.243-.025-.245-.02-.49-.037-.734-.061-.066-.007-.132-.014-.198-.028l-.017-.005c-.03-.013-.029-.014-.067-.038a1.614 1.614 0 0 1-.161-.108.863.863 0 0 1-.22-.242c-.089-.155-.102-.34-.09-.517.02-.299.117-.591.228-.866l.004-.009-.018-1.197-.874-.84-.018-.007-1.188.036-.79.882c-.037.112-.074.224-.106.338a4.756 4.756 0 0 0-.171 1.906c.039.329.115.654.233.963a3.542 3.542 0 0 0 1.263 1.636c.313.222.659.393 1.019.517.237.082.487.111.734.145.479.06.959.106 1.438.166.121.017.241.037.362.058l.158.026a12.12 12.12 0 0 1-.923 2.565 13.221 13.221 0 0 1-.829 1.474 9.474 9.474 0 0 1-.984 1.286c-.08.087-.163.17-.248.252a1.655 1.655 0 0 1-.329.262 2.376 2.376 0 0 1-.722.247c-.457.089-.927.093-1.39.071-.391-.018-.781-.06-1.168-.123a7.817 7.817 0 0 1-.609-.124c-.226-.056-.448-.124-.671-.191-.065-.019-.131-.035-.197-.054a14.75 14.75 0 0 1-.543-.165 23.384 23.384 0 0 1-.453-.128c-.196-.059-.195-.059-.39-.12l-.276-.077V43.881h-.025a34.633 34.633 0 0 0-.031-.557 23.606 23.606 0 0 0-.4-2.994 22.743 22.743 0 0 0-1.492-4.708 22.567 22.567 0 0 0-4.593-6.748 21.865 21.865 0 0 0-6.882-4.706 21.175 21.175 0 0 0-8.115-1.722l-.411-.001zm9.15 33.69c.109.015.214.038.315.085a1.012 1.012 0 0 1 .574.771c.021.132.013.268.009.4a8.38 8.38 0 0 1-.026.476 8.767 8.767 0 0 1-1.564 4.282c-.306.437-.65.846-1.024 1.222a10.09 10.09 0 0 1-4.612 2.627c-1.32.343-2.704.427-4.055.254a10.422 10.422 0 0 1-2.67-.709 9.917 9.917 0 0 1-3.57-2.503 9.312 9.312 0 0 1-.775-.984 8.933 8.933 0 0 1-.731-1.288 8.648 8.648 0 0 1-.795-3.377c-.003-.104-.008-.211 0-.316a1.042 1.042 0 0 1 .254-.609.98.98 0 0 1 1.337-.125 1.023 1.023 0 0 1 .385.719c.007.151.006.303.014.454a6.547 6.547 0 0 0 .524 2.217c.257.595.599 1.15 1.006 1.648.325.398.691.759 1.087 1.081.312.253.642.482.987.684 2.592 1.522 5.945 1.538 8.553.047a7.982 7.982 0 0 0 1.069-.731 7.619 7.619 0 0 0 1.142-1.15 6.949 6.949 0 0 0 1.018-1.741 6.538 6.538 0 0 0 .467-2.425l.004-.084a1.012 1.012 0 0 1 .672-.876c.08-.028.158-.04.241-.05.082-.003.082-.003.164.001zm-70.51-12.426c-15.5.93-28.544-5.922-30.126-16.443C-1.156 15.689 11.64 4.024 29.14 1.235c17.501-2.79 33.123 4.345 34.864 15.922 1.575 10.475-8.749 21.021-23.691 25.001l.001.099a31.185 31.185 0 0 0 .042.833c.007.094.019.188.021.282.006.178.013.356.024.534.011.16.024.32.039.48.017.154.038.306.058.459.036.273.077.544.144.811a4.723 4.723 0 0 0 .449 1.128c.192.332.434.628.702.898l.047.05c.151.139.302.275.461.403.24.192.492.367.748.537.474.314.962.6 1.457.877l.041.023.588.735-.729.586c-.376.112-.755.216-1.135.309a11.193 11.193 0 0 1-2.562.355 8.575 8.575 0 0 1-2.995-.486 8.461 8.461 0 0 1-.96-.413 11.194 11.194 0 0 1-1.836-1.152 13.345 13.345 0 0 1-1.07-.934c-.23-.221-.454-.448-.672-.681-.121-.129-.246-.258-.36-.395a23.448 23.448 0 0 1-1.328-1.773c-.051-.076-.049-.077-.095-.155l-.277-.477-.072-.13c-.081-.177-.159-.357-.238-.535l-.003-.01-.092-.707zm52.409-7.804c3.557 0 6.444 3.201 6.444 7.145 0 3.944-2.887 7.146-6.444 7.146s-6.444-3.202-6.444-7.146 2.887-7.145 6.444-7.145zm18.062 0c3.557 0 6.444 3.201 6.444 7.145 0 3.944-2.887 7.146-6.444 7.146s-6.444-3.202-6.444-7.146 2.887-7.145 6.444-7.145zM83.12 42.029c1.915 0 3.47 1.601 3.47 3.573s-1.555 3.573-3.47 3.573c-1.915 0-3.47-1.601-3.47-3.573s1.555-3.573 3.47-3.573zm17.846 0c1.915 0 3.47 1.601 3.47 3.573s-1.555 3.573-3.47 3.573c-1.915 0-3.47-1.601-3.47-3.573s1.555-3.573 3.47-3.573zM17.019 28c-.368 1.65-1.848 5.008-5.178 5.799-2.572.611-4.153-.815-4.544-2.559-.424-1.891.722-3.532 2.121-4.575a3.473 3.473 0 0 1-1.446-2.099c-.421-1.875.867-3.637 3.184-4.187 1.917-.455 3.185.248 3.462 1.482.265 1.184-.534 2.275-1.828 2.582-.878.209-1.574-.042-1.718-.683a1.4 1.4 0 0 1 .044-.704s.287.227.894.083c.751-.179 1.086-.709.972-1.219-.14-.625-.892-.827-1.739-.626-1.054.25-2.06 1.096-1.713 2.642.232 1.036.871 1.56 1.483 1.813.245-.11.481-.183.688-.233.943-.224 1.48-.005 1.587.472.092.411-.144.935-1.166 1.178a3.255 3.255 0 0 1-1.548.004c-.837.771-1.58 1.883-1.27 3.264.276 1.234 1.267 2.125 2.944 1.726 2.598-.617 3.861-3.638 4.277-4.883-.353-.574-.615-1.153-.732-1.676-.107-.477.145-1.005.863-1.175.48-.114.702.127.846.769a2.77 2.77 0 0 1-.03.995c.209.331.443.622.735.951.616-1.983 1.369-3.877 1.737-3.964.591-.141 1.492.65 1.492.65-.815.644-1.689 2.376-2.333 4.158.804.658 1.627 1.103 2.139.982.43-.102.735-.577.95-1.151-.323-2.226.975-4.331 2.31-4.648.703-.167 1.257.204 1.39.796.114.51-.044 1.379-.854 1.745-.236-1.053-.672-1.348-.944-1.283-.495.117-.844 1.413-.538 2.778.232 1.037.712 1.529 1.351 1.377.756-.179 1.333-1.176 1.699-2.128-.265-2.095.877-4.166 2.221-4.486.671-.159 1.214.162 1.391.952.332 1.48-.986 2.885-2.173 3.444.265.734.673 1.053 1.281.909.96-.229 1.578-1.465 1.923-2.506-.125-1.267-.26-2.385-.406-3.035l-.055-.247s1.568-.286 1.778.652l.019.082c.238-.663.67-1.216 1.309-1.368.83-.197 1.526.504 1.755 1.524.497 2.22-.556 4.428-1.834 4.732-.368.087-.642.066-.883-.033.121 1.288.292 2.651.542 3.77.126.559.272 1.061.448 1.47-.464.11-1.797.392-1.978-.414-.16-.716-.342-3.206-.554-5.612-.504 1.107-1.311 2.192-2.441 2.46-1.008.24-1.685-.303-2.055-1.182-.491 1.082-1.281 2.148-2.381 2.409-.817.194-1.554-.117-1.988-1.013-.36.843-.875 1.555-1.54 1.713-.639.152-1.53-.295-2.4-1.024-.239.888-.384 1.668-.39 2.241 0 0-.701.028-.804-.433-.096-.427.065-1.436.341-2.61a10.315 10.315 0 0 1-.713-.848zm38.163-17.803c.068.157.185.527.266.889.424 1.892.37 4.451.739 6.42-.065.61-.387 3.077-1.352 3.307-.192.045-.333-.06-.422-.454-.14-.626-.091-1.607-.293-2.512-.258-1.152-.782-1.686-1.517-1.511-.767.182-1.287 1.016-1.643 2.054-.022-.099-.053-.386-.093-.567-.211-.938-1.779-.652-1.779-.652a6.2 6.2 0 0 1 .457 1.364c.07.31.119.618.155.921-.246.495-.637.996-1.225 1.135-.064.015-.128.031-.195.029a6.977 6.977 0 0 0-.126-.784c-.258-1.152-.871-2.011-1.526-1.855a.712.712 0 0 0-.423.291c-1.337.317-2.358 2.107-2.118 3.919-.214.889-.551 1.757-1.059 1.877-.415.099-.724-.452-1.03-1.817-.059-.263-.09-.706-.122-1.149.142-.64.177-1.237.081-1.665-.107-.477-.417-.733-.816-.638-.715.17-.909 1.75-.52 3.801-.238.92-.639 1.915-1.278 2.067-.464.11-.835-.27-1.012-1.059-.158-.708-.196-1.929-.236-3.08 1.201-.424 1.911-1.009 1.775-1.617-.114-.51-.739-.743-.739-.743s-.124.722-1.064 1.258c-.029-.582-.064-1.111-.137-1.44-.137-.609-.458-.914-1.688-.622.158.327.274.698.359 1.076.103.46.162.949.189 1.445-.611.128-.947.052-.947.052s-.1.457-.041.72c.078.345.432.348 1.026.224.02 1.364-.067 2.701.143 3.639.306 1.365 1.231 1.89 2.046 1.697.907-.216 1.539-1.275 1.914-2.36.407 1.245 1.031 1.955 1.951 1.736.731-.174 1.261-1.142 1.587-2.195.431.765 1.15 1.129 1.983.931 1.214-.289 1.742-1.54 1.835-2.775 0 0 .147-.018.243-.04.526-.125.949-.488 1.26-.915.04.788.053 1.518.194 2.146.111.493.339.612.595.552.495-.118 1.081-.881 1.081-.881a3.93 3.93 0 0 1-.383-1.035c-.284-1.267.317-3.541.988-3.7.208-.049.377.257.492.767.057.255.092.504.115.751l.098 1.469c.024.246.059.496.116.751.158.707.63 1.236 1.381 1.058 1.317-.313 2.07-2.634 2.178-3.956.228.157.536.175.909.086-.505-2.253.089-6.136-.298-7.864-.1-.444-1.001-.58-1.607-.583l-.467.037zM33.729 22.293c.415-.099.711.246.885 1.02.287 1.283-.222 2.616-.797 2.753-.191.045-.695-.025-.961-1.21-.025-.115-.051-.23-.061-.349.05-1.277.439-2.097.934-2.214zm-5.187.955c.271-.065.511.104.588.449.137.609-.338 1.345-1.275 1.966-.255-1.36.159-2.29.687-2.415zm18.032-.403c-.607.144-1.062-.458-1.239-1.248-.217-.97.001-2.097.644-2.457.001.155.038.32.075.484.147.658.554 1.497 1.268 1.83-.017.749-.253 1.273-.748 1.391zm9.877-1.654c.103.461.496.714 1.039.585.799-.19.973-.993.847-1.553-.125-.559-.461-.93-.988-.805-.543.13-1.108.836-.898 1.773zm-14.21-5.442c-.104-.461-.497-.714-1.056-.581-.783.186-.972.993-.847 1.552.126.56.461.93.908.824.56-.133 1.172-1.006.995-1.795z" fill="#fff" fill-opacity=".6"></path></svg>';
  37211. }
  37212. }
  37213. <?php
  37214. namespace Symfony\Component\Debug\FatalErrorHandler;
  37215. use Symfony\Component\Debug\Exception\ClassNotFoundException;
  37216. use Symfony\Component\Debug\Exception\FatalErrorException;
  37217. use Symfony\Component\Debug\DebugClassLoader;
  37218. use Composer\Autoload\ClassLoader as ComposerClassLoader;
  37219. use Symfony\Component\ClassLoader\ClassLoader as SymfonyClassLoader;
  37220. class ClassNotFoundFatalErrorHandler implements FatalErrorHandlerInterface
  37221. {
  37222. public function handleError(array $error, FatalErrorException $exception)
  37223. {
  37224. $messageLen = strlen($error['message']);
  37225. $notFoundSuffix = '\' not found';
  37226. $notFoundSuffixLen = strlen($notFoundSuffix);
  37227. if ($notFoundSuffixLen > $messageLen) {
  37228. return;
  37229. }
  37230. if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
  37231. return;
  37232. }
  37233. foreach (array('class', 'interface', 'trait') as $typeName) {
  37234. $prefix = ucfirst($typeName).' \'';
  37235. $prefixLen = strlen($prefix);
  37236. if (0 !== strpos($error['message'], $prefix)) {
  37237. continue;
  37238. }
  37239. $fullyQualifiedClassName = substr($error['message'], $prefixLen, -$notFoundSuffixLen);
  37240. if (false !== $namespaceSeparatorIndex = strrpos($fullyQualifiedClassName, '\\')) {
  37241. $className = substr($fullyQualifiedClassName, $namespaceSeparatorIndex + 1);
  37242. $namespacePrefix = substr($fullyQualifiedClassName, 0, $namespaceSeparatorIndex);
  37243. $message = sprintf('Attempted to load %s "%s" from namespace "%s".', $typeName, $className, $namespacePrefix);
  37244. $tail = ' for another namespace?';
  37245. } else {
  37246. $className = $fullyQualifiedClassName;
  37247. $message = sprintf('Attempted to load %s "%s" from the global namespace.', $typeName, $className);
  37248. $tail = '?';
  37249. }
  37250. if ($candidates = $this->getClassCandidates($className)) {
  37251. $tail = array_pop($candidates).'"?';
  37252. if ($candidates) {
  37253. $tail = ' for e.g. "'.implode('", "', $candidates).'" or "'.$tail;
  37254. } else {
  37255. $tail = ' for "'.$tail;
  37256. }
  37257. }
  37258. $message .= "\nDid you forget a \"use\" statement".$tail;
  37259. return new ClassNotFoundException($message, $exception);
  37260. }
  37261. }
  37262. private function getClassCandidates($class)
  37263. {
  37264. if (!is_array($functions = spl_autoload_functions())) {
  37265. return array();
  37266. }
  37267. $classes = array();
  37268. foreach ($functions as $function) {
  37269. if (!is_array($function)) {
  37270. continue;
  37271. }
  37272. if ($function[0] instanceof DebugClassLoader) {
  37273. $function = $function[0]->getClassLoader();
  37274. if (!is_array($function)) {
  37275. continue;
  37276. }
  37277. }
  37278. if ($function[0] instanceof ComposerClassLoader || $function[0] instanceof SymfonyClassLoader) {
  37279. foreach ($function[0]->getPrefixes() as $prefix => $paths) {
  37280. foreach ($paths as $path) {
  37281. $classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix));
  37282. }
  37283. }
  37284. }
  37285. if ($function[0] instanceof ComposerClassLoader) {
  37286. foreach ($function[0]->getPrefixesPsr4() as $prefix => $paths) {
  37287. foreach ($paths as $path) {
  37288. $classes = array_merge($classes, $this->findClassInPath($path, $class, $prefix));
  37289. }
  37290. }
  37291. }
  37292. }
  37293. return array_unique($classes);
  37294. }
  37295. private function findClassInPath($path, $class, $prefix)
  37296. {
  37297. if (!$path = realpath($path.'/'.strtr($prefix, '\\_', '//')) ?: realpath($path.'/'.dirname(strtr($prefix, '\\_', '//'))) ?: realpath($path)) {
  37298. return array();
  37299. }
  37300. $classes = array();
  37301. $filename = $class.'.php';
  37302. foreach (new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::LEAVES_ONLY) as $file) {
  37303. if ($filename == $file->getFileName() && $class = $this->convertFileToClass($path, $file->getPathName(), $prefix)) {
  37304. $classes[] = $class;
  37305. }
  37306. }
  37307. return $classes;
  37308. }
  37309. private function convertFileToClass($path, $file, $prefix)
  37310. {
  37311. $candidates = array(
  37312. $namespacedClass = str_replace(array($path.DIRECTORY_SEPARATOR, '.php', '/'), array('', '', '\\'), $file),
  37313. $prefix.$namespacedClass,
  37314. $prefix.'\\'.$namespacedClass,
  37315. str_replace('\\', '_', $namespacedClass),
  37316. str_replace('\\', '_', $prefix.$namespacedClass),
  37317. str_replace('\\', '_', $prefix.'\\'.$namespacedClass),
  37318. );
  37319. if ($prefix) {
  37320. $candidates = array_filter($candidates, function ($candidate) use ($prefix) { return 0 === strpos($candidate, $prefix); });
  37321. }
  37322. foreach ($candidates as $candidate) {
  37323. if ($this->classExists($candidate)) {
  37324. return $candidate;
  37325. }
  37326. }
  37327. require_once $file;
  37328. foreach ($candidates as $candidate) {
  37329. if ($this->classExists($candidate)) {
  37330. return $candidate;
  37331. }
  37332. }
  37333. }
  37334. private function classExists($class)
  37335. {
  37336. return class_exists($class, false) || interface_exists($class, false) || trait_exists($class, false);
  37337. }
  37338. }
  37339. <?php
  37340. namespace Symfony\Component\Debug\FatalErrorHandler;
  37341. use Symfony\Component\Debug\Exception\FatalErrorException;
  37342. interface FatalErrorHandlerInterface
  37343. {
  37344. public function handleError(array $error, FatalErrorException $exception);
  37345. }
  37346. <?php
  37347. namespace Symfony\Component\Debug\FatalErrorHandler;
  37348. use Symfony\Component\Debug\Exception\UndefinedFunctionException;
  37349. use Symfony\Component\Debug\Exception\FatalErrorException;
  37350. class UndefinedFunctionFatalErrorHandler implements FatalErrorHandlerInterface
  37351. {
  37352. public function handleError(array $error, FatalErrorException $exception)
  37353. {
  37354. $messageLen = strlen($error['message']);
  37355. $notFoundSuffix = '()';
  37356. $notFoundSuffixLen = strlen($notFoundSuffix);
  37357. if ($notFoundSuffixLen > $messageLen) {
  37358. return;
  37359. }
  37360. if (0 !== substr_compare($error['message'], $notFoundSuffix, -$notFoundSuffixLen)) {
  37361. return;
  37362. }
  37363. $prefix = 'Call to undefined function ';
  37364. $prefixLen = strlen($prefix);
  37365. if (0 !== strpos($error['message'], $prefix)) {
  37366. return;
  37367. }
  37368. $fullyQualifiedFunctionName = substr($error['message'], $prefixLen, -$notFoundSuffixLen);
  37369. if (false !== $namespaceSeparatorIndex = strrpos($fullyQualifiedFunctionName, '\\')) {
  37370. $functionName = substr($fullyQualifiedFunctionName, $namespaceSeparatorIndex + 1);
  37371. $namespacePrefix = substr($fullyQualifiedFunctionName, 0, $namespaceSeparatorIndex);
  37372. $message = sprintf('Attempted to call function "%s" from namespace "%s".', $functionName, $namespacePrefix);
  37373. } else {
  37374. $functionName = $fullyQualifiedFunctionName;
  37375. $message = sprintf('Attempted to call function "%s" from the global namespace.', $functionName);
  37376. }
  37377. $candidates = array();
  37378. foreach (get_defined_functions() as $type => $definedFunctionNames) {
  37379. foreach ($definedFunctionNames as $definedFunctionName) {
  37380. if (false !== $namespaceSeparatorIndex = strrpos($definedFunctionName, '\\')) {
  37381. $definedFunctionNameBasename = substr($definedFunctionName, $namespaceSeparatorIndex + 1);
  37382. } else {
  37383. $definedFunctionNameBasename = $definedFunctionName;
  37384. }
  37385. if ($definedFunctionNameBasename === $functionName) {
  37386. $candidates[] = '\\'.$definedFunctionName;
  37387. }
  37388. }
  37389. }
  37390. if ($candidates) {
  37391. sort($candidates);
  37392. $last = array_pop($candidates).'"?';
  37393. if ($candidates) {
  37394. $candidates = 'e.g. "'.implode('", "', $candidates).'" or "'.$last;
  37395. } else {
  37396. $candidates = '"'.$last;
  37397. }
  37398. $message .= "\nDid you mean to call ".$candidates;
  37399. }
  37400. return new UndefinedFunctionException($message, $exception);
  37401. }
  37402. }
  37403. <?php
  37404. namespace Symfony\Component\Debug\FatalErrorHandler;
  37405. use Symfony\Component\Debug\Exception\FatalErrorException;
  37406. use Symfony\Component\Debug\Exception\UndefinedMethodException;
  37407. class UndefinedMethodFatalErrorHandler implements FatalErrorHandlerInterface
  37408. {
  37409. public function handleError(array $error, FatalErrorException $exception)
  37410. {
  37411. preg_match('/^Call to undefined method (.*)::(.*)\(\)$/', $error['message'], $matches);
  37412. if (!$matches) {
  37413. return;
  37414. }
  37415. $className = $matches[1];
  37416. $methodName = $matches[2];
  37417. $message = sprintf('Attempted to call an undefined method named "%s" of class "%s".', $methodName, $className);
  37418. if (!class_exists($className) || null === $methods = get_class_methods($className)) {
  37419. return new UndefinedMethodException($message, $exception);
  37420. }
  37421. $candidates = array();
  37422. foreach ($methods as $definedMethodName) {
  37423. $lev = levenshtein($methodName, $definedMethodName);
  37424. if ($lev <= strlen($methodName) / 3 || false !== strpos($definedMethodName, $methodName)) {
  37425. $candidates[] = $definedMethodName;
  37426. }
  37427. }
  37428. if ($candidates) {
  37429. sort($candidates);
  37430. $last = array_pop($candidates).'"?';
  37431. if ($candidates) {
  37432. $candidates = 'e.g. "'.implode('", "', $candidates).'" or "'.$last;
  37433. } else {
  37434. $candidates = '"'.$last;
  37435. }
  37436. $message .= "\nDid you mean to call ".$candidates;
  37437. }
  37438. return new UndefinedMethodException($message, $exception);
  37439. }
  37440. }
  37441. <?php
  37442. namespace Symfony\Component\Console;
  37443. use Symfony\Component\Console\CommandLoader\CommandLoaderInterface;
  37444. use Symfony\Component\Console\Exception\ExceptionInterface;
  37445. use Symfony\Component\Console\Formatter\OutputFormatter;
  37446. use Symfony\Component\Console\Helper\DebugFormatterHelper;
  37447. use Symfony\Component\Console\Helper\Helper;
  37448. use Symfony\Component\Console\Helper\ProcessHelper;
  37449. use Symfony\Component\Console\Helper\QuestionHelper;
  37450. use Symfony\Component\Console\Input\InputInterface;
  37451. use Symfony\Component\Console\Input\StreamableInputInterface;
  37452. use Symfony\Component\Console\Input\ArgvInput;
  37453. use Symfony\Component\Console\Input\ArrayInput;
  37454. use Symfony\Component\Console\Input\InputDefinition;
  37455. use Symfony\Component\Console\Input\InputOption;
  37456. use Symfony\Component\Console\Input\InputArgument;
  37457. use Symfony\Component\Console\Input\InputAwareInterface;
  37458. use Symfony\Component\Console\Output\OutputInterface;
  37459. use Symfony\Component\Console\Output\ConsoleOutput;
  37460. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  37461. use Symfony\Component\Console\Command\Command;
  37462. use Symfony\Component\Console\Command\HelpCommand;
  37463. use Symfony\Component\Console\Command\ListCommand;
  37464. use Symfony\Component\Console\Helper\HelperSet;
  37465. use Symfony\Component\Console\Helper\FormatterHelper;
  37466. use Symfony\Component\Console\Event\ConsoleCommandEvent;
  37467. use Symfony\Component\Console\Event\ConsoleErrorEvent;
  37468. use Symfony\Component\Console\Event\ConsoleExceptionEvent;
  37469. use Symfony\Component\Console\Event\ConsoleTerminateEvent;
  37470. use Symfony\Component\Console\Exception\CommandNotFoundException;
  37471. use Symfony\Component\Console\Exception\LogicException;
  37472. use Symfony\Component\Debug\ErrorHandler;
  37473. use Symfony\Component\Debug\Exception\FatalThrowableError;
  37474. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  37475. class Application
  37476. {
  37477. private $commands = array();
  37478. private $wantHelps = false;
  37479. private $runningCommand;
  37480. private $name;
  37481. private $version;
  37482. private $commandLoader;
  37483. private $catchExceptions = true;
  37484. private $autoExit = true;
  37485. private $definition;
  37486. private $helperSet;
  37487. private $dispatcher;
  37488. private $terminal;
  37489. private $defaultCommand;
  37490. private $singleCommand;
  37491. private $initialized;
  37492. public function __construct($name = 'UNKNOWN', $version = 'UNKNOWN')
  37493. {
  37494. $this->name = $name;
  37495. $this->version = $version;
  37496. $this->terminal = new Terminal();
  37497. $this->defaultCommand = 'list';
  37498. }
  37499. public function setDispatcher(EventDispatcherInterface $dispatcher)
  37500. {
  37501. $this->dispatcher = $dispatcher;
  37502. }
  37503. public function setCommandLoader(CommandLoaderInterface $commandLoader)
  37504. {
  37505. $this->commandLoader = $commandLoader;
  37506. }
  37507. public function run(InputInterface $input = null, OutputInterface $output = null)
  37508. {
  37509. putenv('LINES='.$this->terminal->getHeight());
  37510. putenv('COLUMNS='.$this->terminal->getWidth());
  37511. if (null === $input) {
  37512. $input = new ArgvInput();
  37513. }
  37514. if (null === $output) {
  37515. $output = new ConsoleOutput();
  37516. }
  37517. $renderException = function ($e) use ($output) {
  37518. if (!$e instanceof \Exception) {
  37519. $e = class_exists(FatalThrowableError::class) ? new FatalThrowableError($e) : new \ErrorException($e->getMessage(), $e->getCode(), E_ERROR, $e->getFile(), $e->getLine());
  37520. }
  37521. if ($output instanceof ConsoleOutputInterface) {
  37522. $this->renderException($e, $output->getErrorOutput());
  37523. } else {
  37524. $this->renderException($e, $output);
  37525. }
  37526. };
  37527. if ($phpHandler = set_exception_handler($renderException)) {
  37528. restore_exception_handler();
  37529. if (!is_array($phpHandler) || !$phpHandler[0] instanceof ErrorHandler) {
  37530. $debugHandler = true;
  37531. } elseif ($debugHandler = $phpHandler[0]->setExceptionHandler($renderException)) {
  37532. $phpHandler[0]->setExceptionHandler($debugHandler);
  37533. }
  37534. }
  37535. if (null !== $this->dispatcher && $this->dispatcher->hasListeners(ConsoleEvents::EXCEPTION)) {
  37536. @trigger_error(sprintf('The "ConsoleEvents::EXCEPTION" event is deprecated since Symfony 3.3 and will be removed in 4.0. Listen to the "ConsoleEvents::ERROR" event instead.'), E_USER_DEPRECATED);
  37537. }
  37538. $this->configureIO($input, $output);
  37539. try {
  37540. $exitCode = $this->doRun($input, $output);
  37541. } catch (\Exception $e) {
  37542. if (!$this->catchExceptions) {
  37543. throw $e;
  37544. }
  37545. $renderException($e);
  37546. $exitCode = $e->getCode();
  37547. if (is_numeric($exitCode)) {
  37548. $exitCode = (int) $exitCode;
  37549. if (0 === $exitCode) {
  37550. $exitCode = 1;
  37551. }
  37552. } else {
  37553. $exitCode = 1;
  37554. }
  37555. } finally {
  37556. if (!$phpHandler) {
  37557. restore_exception_handler();
  37558. } elseif (!$debugHandler) {
  37559. $phpHandler[0]->setExceptionHandler(null);
  37560. }
  37561. }
  37562. if ($this->autoExit) {
  37563. if ($exitCode > 255) {
  37564. $exitCode = 255;
  37565. }
  37566. exit($exitCode);
  37567. }
  37568. return $exitCode;
  37569. }
  37570. public function doRun(InputInterface $input, OutputInterface $output)
  37571. {
  37572. if (true === $input->hasParameterOption(array('--version', '-V'), true)) {
  37573. $output->writeln($this->getLongVersion());
  37574. return 0;
  37575. }
  37576. $name = $this->getCommandName($input);
  37577. if (true === $input->hasParameterOption(array('--help', '-h'), true)) {
  37578. if (!$name) {
  37579. $name = 'help';
  37580. $input = new ArrayInput(array('command_name' => $this->defaultCommand));
  37581. } else {
  37582. $this->wantHelps = true;
  37583. }
  37584. }
  37585. if (!$name) {
  37586. $name = $this->defaultCommand;
  37587. $definition = $this->getDefinition();
  37588. $definition->setArguments(array_merge(
  37589. $definition->getArguments(),
  37590. array(
  37591. 'command' => new InputArgument('command', InputArgument::OPTIONAL, $definition->getArgument('command')->getDescription(), $name),
  37592. )
  37593. ));
  37594. }
  37595. try {
  37596. $e = $this->runningCommand = null;
  37597. $command = $this->find($name);
  37598. } catch (\Exception $e) {
  37599. } catch (\Throwable $e) {
  37600. }
  37601. if (null !== $e) {
  37602. if (null !== $this->dispatcher) {
  37603. $event = new ConsoleErrorEvent($input, $output, $e);
  37604. $this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
  37605. $e = $event->getError();
  37606. if (0 === $event->getExitCode()) {
  37607. return 0;
  37608. }
  37609. }
  37610. throw $e;
  37611. }
  37612. $this->runningCommand = $command;
  37613. $exitCode = $this->doRunCommand($command, $input, $output);
  37614. $this->runningCommand = null;
  37615. return $exitCode;
  37616. }
  37617. public function setHelperSet(HelperSet $helperSet)
  37618. {
  37619. $this->helperSet = $helperSet;
  37620. }
  37621. public function getHelperSet()
  37622. {
  37623. if (!$this->helperSet) {
  37624. $this->helperSet = $this->getDefaultHelperSet();
  37625. }
  37626. return $this->helperSet;
  37627. }
  37628. public function setDefinition(InputDefinition $definition)
  37629. {
  37630. $this->definition = $definition;
  37631. }
  37632. public function getDefinition()
  37633. {
  37634. if (!$this->definition) {
  37635. $this->definition = $this->getDefaultInputDefinition();
  37636. }
  37637. if ($this->singleCommand) {
  37638. $inputDefinition = $this->definition;
  37639. $inputDefinition->setArguments();
  37640. return $inputDefinition;
  37641. }
  37642. return $this->definition;
  37643. }
  37644. public function getHelp()
  37645. {
  37646. return $this->getLongVersion();
  37647. }
  37648. public function areExceptionsCaught()
  37649. {
  37650. return $this->catchExceptions;
  37651. }
  37652. public function setCatchExceptions($boolean)
  37653. {
  37654. $this->catchExceptions = (bool) $boolean;
  37655. }
  37656. public function isAutoExitEnabled()
  37657. {
  37658. return $this->autoExit;
  37659. }
  37660. public function setAutoExit($boolean)
  37661. {
  37662. $this->autoExit = (bool) $boolean;
  37663. }
  37664. public function getName()
  37665. {
  37666. return $this->name;
  37667. }
  37668. public function setName($name)
  37669. {
  37670. $this->name = $name;
  37671. }
  37672. public function getVersion()
  37673. {
  37674. return $this->version;
  37675. }
  37676. public function setVersion($version)
  37677. {
  37678. $this->version = $version;
  37679. }
  37680. public function getLongVersion()
  37681. {
  37682. if ('UNKNOWN' !== $this->getName()) {
  37683. if ('UNKNOWN' !== $this->getVersion()) {
  37684. return sprintf('%s <info>%s</info>', $this->getName(), $this->getVersion());
  37685. }
  37686. return $this->getName();
  37687. }
  37688. return 'Console Tool';
  37689. }
  37690. public function register($name)
  37691. {
  37692. return $this->add(new Command($name));
  37693. }
  37694. public function addCommands(array $commands)
  37695. {
  37696. foreach ($commands as $command) {
  37697. $this->add($command);
  37698. }
  37699. }
  37700. public function add(Command $command)
  37701. {
  37702. $this->init();
  37703. $command->setApplication($this);
  37704. if (!$command->isEnabled()) {
  37705. $command->setApplication(null);
  37706. return;
  37707. }
  37708. if (null === $command->getDefinition()) {
  37709. throw new LogicException(sprintf('Command class "%s" is not correctly initialized. You probably forgot to call the parent constructor.', get_class($command)));
  37710. }
  37711. if (!$command->getName()) {
  37712. throw new LogicException(sprintf('The command defined in "%s" cannot have an empty name.', get_class($command)));
  37713. }
  37714. $this->commands[$command->getName()] = $command;
  37715. foreach ($command->getAliases() as $alias) {
  37716. $this->commands[$alias] = $command;
  37717. }
  37718. return $command;
  37719. }
  37720. public function get($name)
  37721. {
  37722. $this->init();
  37723. if (!$this->has($name)) {
  37724. throw new CommandNotFoundException(sprintf('The command "%s" does not exist.', $name));
  37725. }
  37726. $command = $this->commands[$name];
  37727. if ($this->wantHelps) {
  37728. $this->wantHelps = false;
  37729. $helpCommand = $this->get('help');
  37730. $helpCommand->setCommand($command);
  37731. return $helpCommand;
  37732. }
  37733. return $command;
  37734. }
  37735. public function has($name)
  37736. {
  37737. $this->init();
  37738. return isset($this->commands[$name]) || ($this->commandLoader && $this->commandLoader->has($name) && $this->add($this->commandLoader->get($name)));
  37739. }
  37740. public function getNamespaces()
  37741. {
  37742. $namespaces = array();
  37743. foreach ($this->all() as $command) {
  37744. $namespaces = array_merge($namespaces, $this->extractAllNamespaces($command->getName()));
  37745. foreach ($command->getAliases() as $alias) {
  37746. $namespaces = array_merge($namespaces, $this->extractAllNamespaces($alias));
  37747. }
  37748. }
  37749. return array_values(array_unique(array_filter($namespaces)));
  37750. }
  37751. public function findNamespace($namespace)
  37752. {
  37753. $allNamespaces = $this->getNamespaces();
  37754. $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $namespace);
  37755. $namespaces = preg_grep('{^'.$expr.'}', $allNamespaces);
  37756. if (empty($namespaces)) {
  37757. $message = sprintf('There are no commands defined in the "%s" namespace.', $namespace);
  37758. if ($alternatives = $this->findAlternatives($namespace, $allNamespaces)) {
  37759. if (1 == count($alternatives)) {
  37760. $message .= "\n\nDid you mean this?\n ";
  37761. } else {
  37762. $message .= "\n\nDid you mean one of these?\n ";
  37763. }
  37764. $message .= implode("\n ", $alternatives);
  37765. }
  37766. throw new CommandNotFoundException($message, $alternatives);
  37767. }
  37768. $exact = in_array($namespace, $namespaces, true);
  37769. if (count($namespaces) > 1 && !$exact) {
  37770. throw new CommandNotFoundException(sprintf("The namespace \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $namespace, $this->getAbbreviationSuggestions(array_values($namespaces))), array_values($namespaces));
  37771. }
  37772. return $exact ? $namespace : reset($namespaces);
  37773. }
  37774. public function find($name)
  37775. {
  37776. $this->init();
  37777. $aliases = array();
  37778. $allCommands = $this->commandLoader ? array_merge($this->commandLoader->getNames(), array_keys($this->commands)) : array_keys($this->commands);
  37779. $expr = preg_replace_callback('{([^:]+|)}', function ($matches) { return preg_quote($matches[1]).'[^:]*'; }, $name);
  37780. $commands = preg_grep('{^'.$expr.'}', $allCommands);
  37781. if (empty($commands)) {
  37782. $commands = preg_grep('{^'.$expr.'}i', $allCommands);
  37783. }
  37784. if (empty($commands) || count(preg_grep('{^'.$expr.'$}i', $commands)) < 1) {
  37785. if (false !== $pos = strrpos($name, ':')) {
  37786. $this->findNamespace(substr($name, 0, $pos));
  37787. }
  37788. $message = sprintf('Command "%s" is not defined.', $name);
  37789. if ($alternatives = $this->findAlternatives($name, $allCommands)) {
  37790. if (1 == count($alternatives)) {
  37791. $message .= "\n\nDid you mean this?\n ";
  37792. } else {
  37793. $message .= "\n\nDid you mean one of these?\n ";
  37794. }
  37795. $message .= implode("\n ", $alternatives);
  37796. }
  37797. throw new CommandNotFoundException($message, $alternatives);
  37798. }
  37799. if (count($commands) > 1) {
  37800. $commandList = $this->commandLoader ? array_merge(array_flip($this->commandLoader->getNames()), $this->commands) : $this->commands;
  37801. $commands = array_unique(array_filter($commands, function ($nameOrAlias) use ($commandList, $commands, &$aliases) {
  37802. $commandName = $commandList[$nameOrAlias] instanceof Command ? $commandList[$nameOrAlias]->getName() : $nameOrAlias;
  37803. $aliases[$nameOrAlias] = $commandName;
  37804. return $commandName === $nameOrAlias || !in_array($commandName, $commands);
  37805. }));
  37806. }
  37807. $exact = in_array($name, $commands, true) || isset($aliases[$name]);
  37808. if (count($commands) > 1 && !$exact) {
  37809. $usableWidth = $this->terminal->getWidth() - 10;
  37810. $abbrevs = array_values($commands);
  37811. $maxLen = 0;
  37812. foreach ($abbrevs as $abbrev) {
  37813. $maxLen = max(Helper::strlen($abbrev), $maxLen);
  37814. }
  37815. $abbrevs = array_map(function ($cmd) use ($commandList, $usableWidth, $maxLen) {
  37816. if (!$commandList[$cmd] instanceof Command) {
  37817. return $cmd;
  37818. }
  37819. $abbrev = str_pad($cmd, $maxLen, ' ').' '.$commandList[$cmd]->getDescription();
  37820. return Helper::strlen($abbrev) > $usableWidth ? Helper::substr($abbrev, 0, $usableWidth - 3).'...' : $abbrev;
  37821. }, array_values($commands));
  37822. $suggestions = $this->getAbbreviationSuggestions($abbrevs);
  37823. throw new CommandNotFoundException(sprintf("Command \"%s\" is ambiguous.\nDid you mean one of these?\n%s", $name, $suggestions), array_values($commands));
  37824. }
  37825. return $this->get($exact ? $name : reset($commands));
  37826. }
  37827. public function all($namespace = null)
  37828. {
  37829. $this->init();
  37830. if (null === $namespace) {
  37831. if (!$this->commandLoader) {
  37832. return $this->commands;
  37833. }
  37834. $commands = $this->commands;
  37835. foreach ($this->commandLoader->getNames() as $name) {
  37836. if (!isset($commands[$name]) && $this->has($name)) {
  37837. $commands[$name] = $this->get($name);
  37838. }
  37839. }
  37840. return $commands;
  37841. }
  37842. $commands = array();
  37843. foreach ($this->commands as $name => $command) {
  37844. if ($namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1)) {
  37845. $commands[$name] = $command;
  37846. }
  37847. }
  37848. if ($this->commandLoader) {
  37849. foreach ($this->commandLoader->getNames() as $name) {
  37850. if (!isset($commands[$name]) && $namespace === $this->extractNamespace($name, substr_count($namespace, ':') + 1) && $this->has($name)) {
  37851. $commands[$name] = $this->get($name);
  37852. }
  37853. }
  37854. }
  37855. return $commands;
  37856. }
  37857. public static function getAbbreviations($names)
  37858. {
  37859. $abbrevs = array();
  37860. foreach ($names as $name) {
  37861. for ($len = strlen($name); $len > 0; --$len) {
  37862. $abbrev = substr($name, 0, $len);
  37863. $abbrevs[$abbrev][] = $name;
  37864. }
  37865. }
  37866. return $abbrevs;
  37867. }
  37868. public function renderException(\Exception $e, OutputInterface $output)
  37869. {
  37870. $output->writeln('', OutputInterface::VERBOSITY_QUIET);
  37871. $this->doRenderException($e, $output);
  37872. if (null !== $this->runningCommand) {
  37873. $output->writeln(sprintf('<info>%s</info>', sprintf($this->runningCommand->getSynopsis(), $this->getName())), OutputInterface::VERBOSITY_QUIET);
  37874. $output->writeln('', OutputInterface::VERBOSITY_QUIET);
  37875. }
  37876. }
  37877. protected function doRenderException(\Exception $e, OutputInterface $output)
  37878. {
  37879. do {
  37880. $message = trim($e->getMessage());
  37881. if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
  37882. $title = sprintf(' [%s%s] ', get_class($e), 0 !== ($code = $e->getCode()) ? ' ('.$code.')' : '');
  37883. $len = Helper::strlen($title);
  37884. } else {
  37885. $len = 0;
  37886. }
  37887. $width = $this->terminal->getWidth() ? $this->terminal->getWidth() - 1 : PHP_INT_MAX;
  37888. if (defined('HHVM_VERSION') && $width > 1 << 31) {
  37889. $width = 1 << 31;
  37890. }
  37891. $lines = array();
  37892. foreach ('' !== $message ? preg_split('/\r?\n/', $message) : array() as $line) {
  37893. foreach ($this->splitStringByWidth($line, $width - 4) as $line) {
  37894. $lineLength = Helper::strlen($line) + 4;
  37895. $lines[] = array($line, $lineLength);
  37896. $len = max($lineLength, $len);
  37897. }
  37898. }
  37899. $messages = array();
  37900. if (!$e instanceof ExceptionInterface || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
  37901. $messages[] = sprintf('<comment>%s</comment>', OutputFormatter::escape(sprintf('In %s line %s:', basename($e->getFile()) ?: 'n/a', $e->getLine() ?: 'n/a')));
  37902. }
  37903. $messages[] = $emptyLine = sprintf('<error>%s</error>', str_repeat(' ', $len));
  37904. if ('' === $message || OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
  37905. $messages[] = sprintf('<error>%s%s</error>', $title, str_repeat(' ', max(0, $len - Helper::strlen($title))));
  37906. }
  37907. foreach ($lines as $line) {
  37908. $messages[] = sprintf('<error> %s %s</error>', OutputFormatter::escape($line[0]), str_repeat(' ', $len - $line[1]));
  37909. }
  37910. $messages[] = $emptyLine;
  37911. $messages[] = '';
  37912. $output->writeln($messages, OutputInterface::VERBOSITY_QUIET);
  37913. if (OutputInterface::VERBOSITY_VERBOSE <= $output->getVerbosity()) {
  37914. $output->writeln('<comment>Exception trace:</comment>', OutputInterface::VERBOSITY_QUIET);
  37915. $trace = $e->getTrace();
  37916. for ($i = 0, $count = count($trace); $i < $count; ++$i) {
  37917. $class = isset($trace[$i]['class']) ? $trace[$i]['class'] : '';
  37918. $type = isset($trace[$i]['type']) ? $trace[$i]['type'] : '';
  37919. $function = $trace[$i]['function'];
  37920. $file = isset($trace[$i]['file']) ? $trace[$i]['file'] : 'n/a';
  37921. $line = isset($trace[$i]['line']) ? $trace[$i]['line'] : 'n/a';
  37922. $output->writeln(sprintf(' %s%s%s() at <info>%s:%s</info>', $class, $type, $function, $file, $line), OutputInterface::VERBOSITY_QUIET);
  37923. }
  37924. $output->writeln('', OutputInterface::VERBOSITY_QUIET);
  37925. }
  37926. } while ($e = $e->getPrevious());
  37927. }
  37928. protected function getTerminalWidth()
  37929. {
  37930. @trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Create a Terminal instance instead.', __METHOD__), E_USER_DEPRECATED);
  37931. return $this->terminal->getWidth();
  37932. }
  37933. protected function getTerminalHeight()
  37934. {
  37935. @trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Create a Terminal instance instead.', __METHOD__), E_USER_DEPRECATED);
  37936. return $this->terminal->getHeight();
  37937. }
  37938. public function getTerminalDimensions()
  37939. {
  37940. @trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Create a Terminal instance instead.', __METHOD__), E_USER_DEPRECATED);
  37941. return array($this->terminal->getWidth(), $this->terminal->getHeight());
  37942. }
  37943. public function setTerminalDimensions($width, $height)
  37944. {
  37945. @trigger_error(sprintf('%s is deprecated as of 3.2 and will be removed in 4.0. Set the COLUMNS and LINES env vars instead.', __METHOD__), E_USER_DEPRECATED);
  37946. putenv('COLUMNS='.$width);
  37947. putenv('LINES='.$height);
  37948. return $this;
  37949. }
  37950. protected function configureIO(InputInterface $input, OutputInterface $output)
  37951. {
  37952. if (true === $input->hasParameterOption(array('--ansi'), true)) {
  37953. $output->setDecorated(true);
  37954. } elseif (true === $input->hasParameterOption(array('--no-ansi'), true)) {
  37955. $output->setDecorated(false);
  37956. }
  37957. if (true === $input->hasParameterOption(array('--no-interaction', '-n'), true)) {
  37958. $input->setInteractive(false);
  37959. } elseif (function_exists('posix_isatty')) {
  37960. $inputStream = null;
  37961. if ($input instanceof StreamableInputInterface) {
  37962. $inputStream = $input->getStream();
  37963. }
  37964. if (!$inputStream && $this->getHelperSet()->has('question')) {
  37965. $inputStream = $this->getHelperSet()->get('question')->getInputStream(false);
  37966. }
  37967. if (!@posix_isatty($inputStream) && false === getenv('SHELL_INTERACTIVE')) {
  37968. $input->setInteractive(false);
  37969. }
  37970. }
  37971. switch ($shellVerbosity = (int) getenv('SHELL_VERBOSITY')) {
  37972. case -1: $output->setVerbosity(OutputInterface::VERBOSITY_QUIET); break;
  37973. case 1: $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE); break;
  37974. case 2: $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE); break;
  37975. case 3: $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG); break;
  37976. default: $shellVerbosity = 0; break;
  37977. }
  37978. if (true === $input->hasParameterOption(array('--quiet', '-q'), true)) {
  37979. $output->setVerbosity(OutputInterface::VERBOSITY_QUIET);
  37980. $shellVerbosity = -1;
  37981. } else {
  37982. if ($input->hasParameterOption('-vvv', true) || $input->hasParameterOption('--verbose=3', true) || 3 === $input->getParameterOption('--verbose', false, true)) {
  37983. $output->setVerbosity(OutputInterface::VERBOSITY_DEBUG);
  37984. $shellVerbosity = 3;
  37985. } elseif ($input->hasParameterOption('-vv', true) || $input->hasParameterOption('--verbose=2', true) || 2 === $input->getParameterOption('--verbose', false, true)) {
  37986. $output->setVerbosity(OutputInterface::VERBOSITY_VERY_VERBOSE);
  37987. $shellVerbosity = 2;
  37988. } elseif ($input->hasParameterOption('-v', true) || $input->hasParameterOption('--verbose=1', true) || $input->hasParameterOption('--verbose', true) || $input->getParameterOption('--verbose', false, true)) {
  37989. $output->setVerbosity(OutputInterface::VERBOSITY_VERBOSE);
  37990. $shellVerbosity = 1;
  37991. }
  37992. }
  37993. if (-1 === $shellVerbosity) {
  37994. $input->setInteractive(false);
  37995. }
  37996. putenv('SHELL_VERBOSITY='.$shellVerbosity);
  37997. $_ENV['SHELL_VERBOSITY'] = $shellVerbosity;
  37998. $_SERVER['SHELL_VERBOSITY'] = $shellVerbosity;
  37999. }
  38000. protected function doRunCommand(Command $command, InputInterface $input, OutputInterface $output)
  38001. {
  38002. foreach ($command->getHelperSet() as $helper) {
  38003. if ($helper instanceof InputAwareInterface) {
  38004. $helper->setInput($input);
  38005. }
  38006. }
  38007. if (null === $this->dispatcher) {
  38008. return $command->run($input, $output);
  38009. }
  38010. try {
  38011. $command->mergeApplicationDefinition();
  38012. $input->bind($command->getDefinition());
  38013. } catch (ExceptionInterface $e) {
  38014. }
  38015. $event = new ConsoleCommandEvent($command, $input, $output);
  38016. $e = null;
  38017. try {
  38018. $this->dispatcher->dispatch(ConsoleEvents::COMMAND, $event);
  38019. if ($event->commandShouldRun()) {
  38020. $exitCode = $command->run($input, $output);
  38021. } else {
  38022. $exitCode = ConsoleCommandEvent::RETURN_CODE_DISABLED;
  38023. }
  38024. } catch (\Exception $e) {
  38025. } catch (\Throwable $e) {
  38026. }
  38027. if (null !== $e) {
  38028. if ($this->dispatcher->hasListeners(ConsoleEvents::EXCEPTION)) {
  38029. $x = $e instanceof \Exception ? $e : new FatalThrowableError($e);
  38030. $event = new ConsoleExceptionEvent($command, $input, $output, $x, $x->getCode());
  38031. $this->dispatcher->dispatch(ConsoleEvents::EXCEPTION, $event);
  38032. if ($x !== $event->getException()) {
  38033. $e = $event->getException();
  38034. }
  38035. }
  38036. $event = new ConsoleErrorEvent($input, $output, $e, $command);
  38037. $this->dispatcher->dispatch(ConsoleEvents::ERROR, $event);
  38038. $e = $event->getError();
  38039. if (0 === $exitCode = $event->getExitCode()) {
  38040. $e = null;
  38041. }
  38042. }
  38043. $event = new ConsoleTerminateEvent($command, $input, $output, $exitCode);
  38044. $this->dispatcher->dispatch(ConsoleEvents::TERMINATE, $event);
  38045. if (null !== $e) {
  38046. throw $e;
  38047. }
  38048. return $event->getExitCode();
  38049. }
  38050. protected function getCommandName(InputInterface $input)
  38051. {
  38052. return $this->singleCommand ? $this->defaultCommand : $input->getFirstArgument();
  38053. }
  38054. protected function getDefaultInputDefinition()
  38055. {
  38056. return new InputDefinition(array(
  38057. new InputArgument('command', InputArgument::REQUIRED, 'The command to execute'),
  38058. new InputOption('--help', '-h', InputOption::VALUE_NONE, 'Display this help message'),
  38059. new InputOption('--quiet', '-q', InputOption::VALUE_NONE, 'Do not output any message'),
  38060. new InputOption('--verbose', '-v|vv|vvv', InputOption::VALUE_NONE, 'Increase the verbosity of messages: 1 for normal output, 2 for more verbose output and 3 for debug'),
  38061. new InputOption('--version', '-V', InputOption::VALUE_NONE, 'Display this application version'),
  38062. new InputOption('--ansi', '', InputOption::VALUE_NONE, 'Force ANSI output'),
  38063. new InputOption('--no-ansi', '', InputOption::VALUE_NONE, 'Disable ANSI output'),
  38064. new InputOption('--no-interaction', '-n', InputOption::VALUE_NONE, 'Do not ask any interactive question'),
  38065. ));
  38066. }
  38067. protected function getDefaultCommands()
  38068. {
  38069. return array(new HelpCommand(), new ListCommand());
  38070. }
  38071. protected function getDefaultHelperSet()
  38072. {
  38073. return new HelperSet(array(
  38074. new FormatterHelper(),
  38075. new DebugFormatterHelper(),
  38076. new ProcessHelper(),
  38077. new QuestionHelper(),
  38078. ));
  38079. }
  38080. private function getAbbreviationSuggestions($abbrevs)
  38081. {
  38082. return ' '.implode("\n ", $abbrevs);
  38083. }
  38084. public function extractNamespace($name, $limit = null)
  38085. {
  38086. $parts = explode(':', $name);
  38087. array_pop($parts);
  38088. return implode(':', null === $limit ? $parts : array_slice($parts, 0, $limit));
  38089. }
  38090. private function findAlternatives($name, $collection)
  38091. {
  38092. $threshold = 1e3;
  38093. $alternatives = array();
  38094. $collectionParts = array();
  38095. foreach ($collection as $item) {
  38096. $collectionParts[$item] = explode(':', $item);
  38097. }
  38098. foreach (explode(':', $name) as $i => $subname) {
  38099. foreach ($collectionParts as $collectionName => $parts) {
  38100. $exists = isset($alternatives[$collectionName]);
  38101. if (!isset($parts[$i]) && $exists) {
  38102. $alternatives[$collectionName] += $threshold;
  38103. continue;
  38104. } elseif (!isset($parts[$i])) {
  38105. continue;
  38106. }
  38107. $lev = levenshtein($subname, $parts[$i]);
  38108. if ($lev <= strlen($subname) / 3 || '' !== $subname && false !== strpos($parts[$i], $subname)) {
  38109. $alternatives[$collectionName] = $exists ? $alternatives[$collectionName] + $lev : $lev;
  38110. } elseif ($exists) {
  38111. $alternatives[$collectionName] += $threshold;
  38112. }
  38113. }
  38114. }
  38115. foreach ($collection as $item) {
  38116. $lev = levenshtein($name, $item);
  38117. if ($lev <= strlen($name) / 3 || false !== strpos($item, $name)) {
  38118. $alternatives[$item] = isset($alternatives[$item]) ? $alternatives[$item] - $lev : $lev;
  38119. }
  38120. }
  38121. $alternatives = array_filter($alternatives, function ($lev) use ($threshold) { return $lev < 2 * $threshold; });
  38122. ksort($alternatives, SORT_NATURAL | SORT_FLAG_CASE);
  38123. return array_keys($alternatives);
  38124. }
  38125. public function setDefaultCommand($commandName, $isSingleCommand = false)
  38126. {
  38127. $this->defaultCommand = $commandName;
  38128. if ($isSingleCommand) {
  38129. $this->find($commandName);
  38130. $this->singleCommand = true;
  38131. }
  38132. return $this;
  38133. }
  38134. private function splitStringByWidth($string, $width)
  38135. {
  38136. if (false === $encoding = mb_detect_encoding($string, null, true)) {
  38137. return str_split($string, $width);
  38138. }
  38139. $utf8String = mb_convert_encoding($string, 'utf8', $encoding);
  38140. $lines = array();
  38141. $line = '';
  38142. foreach (preg_split('//u', $utf8String) as $char) {
  38143. if (mb_strwidth($line.$char, 'utf8') <= $width) {
  38144. $line .= $char;
  38145. continue;
  38146. }
  38147. $lines[] = str_pad($line, $width);
  38148. $line = $char;
  38149. }
  38150. $lines[] = count($lines) ? str_pad($line, $width) : $line;
  38151. mb_convert_variables($encoding, 'utf8', $lines);
  38152. return $lines;
  38153. }
  38154. private function extractAllNamespaces($name)
  38155. {
  38156. $parts = explode(':', $name, -1);
  38157. $namespaces = array();
  38158. foreach ($parts as $part) {
  38159. if (count($namespaces)) {
  38160. $namespaces[] = end($namespaces).':'.$part;
  38161. } else {
  38162. $namespaces[] = $part;
  38163. }
  38164. }
  38165. return $namespaces;
  38166. }
  38167. private function init()
  38168. {
  38169. if ($this->initialized) {
  38170. return;
  38171. }
  38172. $this->initialized = true;
  38173. foreach ($this->getDefaultCommands() as $command) {
  38174. $this->add($command);
  38175. }
  38176. }
  38177. }
  38178. <?php
  38179. namespace Symfony\Component\Console\Command;
  38180. use Symfony\Component\Console\Exception\ExceptionInterface;
  38181. use Symfony\Component\Console\Input\InputDefinition;
  38182. use Symfony\Component\Console\Input\InputOption;
  38183. use Symfony\Component\Console\Input\InputArgument;
  38184. use Symfony\Component\Console\Input\InputInterface;
  38185. use Symfony\Component\Console\Output\OutputInterface;
  38186. use Symfony\Component\Console\Application;
  38187. use Symfony\Component\Console\Helper\HelperSet;
  38188. use Symfony\Component\Console\Exception\InvalidArgumentException;
  38189. use Symfony\Component\Console\Exception\LogicException;
  38190. class Command
  38191. {
  38192. protected static $defaultName;
  38193. private $application;
  38194. private $name;
  38195. private $processTitle;
  38196. private $aliases = array();
  38197. private $definition;
  38198. private $hidden = false;
  38199. private $help;
  38200. private $description;
  38201. private $ignoreValidationErrors = false;
  38202. private $applicationDefinitionMerged = false;
  38203. private $applicationDefinitionMergedWithArgs = false;
  38204. private $code;
  38205. private $synopsis = array();
  38206. private $usages = array();
  38207. private $helperSet;
  38208. public static function getDefaultName()
  38209. {
  38210. $class = get_called_class();
  38211. $r = new \ReflectionProperty($class, 'defaultName');
  38212. return $class === $r->class ? static::$defaultName : null;
  38213. }
  38214. public function __construct($name = null)
  38215. {
  38216. $this->definition = new InputDefinition();
  38217. if (null !== $name || null !== $name = static::getDefaultName()) {
  38218. $this->setName($name);
  38219. }
  38220. $this->configure();
  38221. }
  38222. public function ignoreValidationErrors()
  38223. {
  38224. $this->ignoreValidationErrors = true;
  38225. }
  38226. public function setApplication(Application $application = null)
  38227. {
  38228. $this->application = $application;
  38229. if ($application) {
  38230. $this->setHelperSet($application->getHelperSet());
  38231. } else {
  38232. $this->helperSet = null;
  38233. }
  38234. }
  38235. public function setHelperSet(HelperSet $helperSet)
  38236. {
  38237. $this->helperSet = $helperSet;
  38238. }
  38239. public function getHelperSet()
  38240. {
  38241. return $this->helperSet;
  38242. }
  38243. public function getApplication()
  38244. {
  38245. return $this->application;
  38246. }
  38247. public function isEnabled()
  38248. {
  38249. return true;
  38250. }
  38251. protected function configure()
  38252. {
  38253. }
  38254. protected function execute(InputInterface $input, OutputInterface $output)
  38255. {
  38256. throw new LogicException('You must override the execute() method in the concrete command class.');
  38257. }
  38258. protected function interact(InputInterface $input, OutputInterface $output)
  38259. {
  38260. }
  38261. protected function initialize(InputInterface $input, OutputInterface $output)
  38262. {
  38263. }
  38264. public function run(InputInterface $input, OutputInterface $output)
  38265. {
  38266. $this->getSynopsis(true);
  38267. $this->getSynopsis(false);
  38268. $this->mergeApplicationDefinition();
  38269. try {
  38270. $input->bind($this->definition);
  38271. } catch (ExceptionInterface $e) {
  38272. if (!$this->ignoreValidationErrors) {
  38273. throw $e;
  38274. }
  38275. }
  38276. $this->initialize($input, $output);
  38277. if (null !== $this->processTitle) {
  38278. if (function_exists('cli_set_process_title')) {
  38279. if (false === @cli_set_process_title($this->processTitle)) {
  38280. if ('Darwin' === PHP_OS) {
  38281. $output->writeln('<comment>Running "cli_get_process_title" as an unprivileged user is not supported on MacOS.</comment>');
  38282. } else {
  38283. $error = error_get_last();
  38284. trigger_error($error['message'], E_USER_WARNING);
  38285. }
  38286. }
  38287. } elseif (function_exists('setproctitle')) {
  38288. setproctitle($this->processTitle);
  38289. } elseif (OutputInterface::VERBOSITY_VERY_VERBOSE === $output->getVerbosity()) {
  38290. $output->writeln('<comment>Install the proctitle PECL to be able to change the process title.</comment>');
  38291. }
  38292. }
  38293. if ($input->isInteractive()) {
  38294. $this->interact($input, $output);
  38295. }
  38296. if ($input->hasArgument('command') && null === $input->getArgument('command')) {
  38297. $input->setArgument('command', $this->getName());
  38298. }
  38299. $input->validate();
  38300. if ($this->code) {
  38301. $statusCode = call_user_func($this->code, $input, $output);
  38302. } else {
  38303. $statusCode = $this->execute($input, $output);
  38304. }
  38305. return is_numeric($statusCode) ? (int) $statusCode : 0;
  38306. }
  38307. public function setCode(callable $code)
  38308. {
  38309. if ($code instanceof \Closure) {
  38310. $r = new \ReflectionFunction($code);
  38311. if (null === $r->getClosureThis()) {
  38312. if (\PHP_VERSION_ID < 70000) {
  38313. $code = @\Closure::bind($code, $this);
  38314. } else {
  38315. $code = \Closure::bind($code, $this);
  38316. }
  38317. }
  38318. }
  38319. $this->code = $code;
  38320. return $this;
  38321. }
  38322. public function mergeApplicationDefinition($mergeArgs = true)
  38323. {
  38324. if (null === $this->application || (true === $this->applicationDefinitionMerged && ($this->applicationDefinitionMergedWithArgs || !$mergeArgs))) {
  38325. return;
  38326. }
  38327. $this->definition->addOptions($this->application->getDefinition()->getOptions());
  38328. if ($mergeArgs) {
  38329. $currentArguments = $this->definition->getArguments();
  38330. $this->definition->setArguments($this->application->getDefinition()->getArguments());
  38331. $this->definition->addArguments($currentArguments);
  38332. }
  38333. $this->applicationDefinitionMerged = true;
  38334. if ($mergeArgs) {
  38335. $this->applicationDefinitionMergedWithArgs = true;
  38336. }
  38337. }
  38338. public function setDefinition($definition)
  38339. {
  38340. if ($definition instanceof InputDefinition) {
  38341. $this->definition = $definition;
  38342. } else {
  38343. $this->definition->setDefinition($definition);
  38344. }
  38345. $this->applicationDefinitionMerged = false;
  38346. return $this;
  38347. }
  38348. public function getDefinition()
  38349. {
  38350. return $this->definition;
  38351. }
  38352. public function getNativeDefinition()
  38353. {
  38354. return $this->getDefinition();
  38355. }
  38356. public function addArgument($name, $mode = null, $description = '', $default = null)
  38357. {
  38358. $this->definition->addArgument(new InputArgument($name, $mode, $description, $default));
  38359. return $this;
  38360. }
  38361. public function addOption($name, $shortcut = null, $mode = null, $description = '', $default = null)
  38362. {
  38363. $this->definition->addOption(new InputOption($name, $shortcut, $mode, $description, $default));
  38364. return $this;
  38365. }
  38366. public function setName($name)
  38367. {
  38368. $this->validateName($name);
  38369. $this->name = $name;
  38370. return $this;
  38371. }
  38372. public function setProcessTitle($title)
  38373. {
  38374. $this->processTitle = $title;
  38375. return $this;
  38376. }
  38377. public function getName()
  38378. {
  38379. return $this->name;
  38380. }
  38381. public function setHidden($hidden)
  38382. {
  38383. $this->hidden = (bool) $hidden;
  38384. return $this;
  38385. }
  38386. public function isHidden()
  38387. {
  38388. return $this->hidden;
  38389. }
  38390. public function setDescription($description)
  38391. {
  38392. $this->description = $description;
  38393. return $this;
  38394. }
  38395. public function getDescription()
  38396. {
  38397. return $this->description;
  38398. }
  38399. public function setHelp($help)
  38400. {
  38401. $this->help = $help;
  38402. return $this;
  38403. }
  38404. public function getHelp()
  38405. {
  38406. return $this->help;
  38407. }
  38408. public function getProcessedHelp()
  38409. {
  38410. $name = $this->name;
  38411. $placeholders = array(
  38412. '%command.name%',
  38413. '%command.full_name%',
  38414. );
  38415. $replacements = array(
  38416. $name,
  38417. $_SERVER['PHP_SELF'].' '.$name,
  38418. );
  38419. return str_replace($placeholders, $replacements, $this->getHelp() ?: $this->getDescription());
  38420. }
  38421. public function setAliases($aliases)
  38422. {
  38423. if (!is_array($aliases) && !$aliases instanceof \Traversable) {
  38424. throw new InvalidArgumentException('$aliases must be an array or an instance of \Traversable');
  38425. }
  38426. foreach ($aliases as $alias) {
  38427. $this->validateName($alias);
  38428. }
  38429. $this->aliases = $aliases;
  38430. return $this;
  38431. }
  38432. public function getAliases()
  38433. {
  38434. return $this->aliases;
  38435. }
  38436. public function getSynopsis($short = false)
  38437. {
  38438. $key = $short ? 'short' : 'long';
  38439. if (!isset($this->synopsis[$key])) {
  38440. $this->synopsis[$key] = trim(sprintf('%s %s', $this->name, $this->definition->getSynopsis($short)));
  38441. }
  38442. return $this->synopsis[$key];
  38443. }
  38444. public function addUsage($usage)
  38445. {
  38446. if (0 !== strpos($usage, $this->name)) {
  38447. $usage = sprintf('%s %s', $this->name, $usage);
  38448. }
  38449. $this->usages[] = $usage;
  38450. return $this;
  38451. }
  38452. public function getUsages()
  38453. {
  38454. return $this->usages;
  38455. }
  38456. public function getHelper($name)
  38457. {
  38458. if (null === $this->helperSet) {
  38459. throw new LogicException(sprintf('Cannot retrieve helper "%s" because there is no HelperSet defined. Did you forget to add your command to the application or to set the application on the command using the setApplication() method? You can also set the HelperSet directly using the setHelperSet() method.', $name));
  38460. }
  38461. return $this->helperSet->get($name);
  38462. }
  38463. private function validateName($name)
  38464. {
  38465. if (!preg_match('/^[^\:]++(\:[^\:]++)*$/', $name)) {
  38466. throw new InvalidArgumentException(sprintf('Command name "%s" is invalid.', $name));
  38467. }
  38468. }
  38469. }
  38470. <?php
  38471. namespace Symfony\Component\Console\Command;
  38472. use Symfony\Component\Console\Helper\DescriptorHelper;
  38473. use Symfony\Component\Console\Input\InputArgument;
  38474. use Symfony\Component\Console\Input\InputOption;
  38475. use Symfony\Component\Console\Input\InputInterface;
  38476. use Symfony\Component\Console\Output\OutputInterface;
  38477. class HelpCommand extends Command
  38478. {
  38479. private $command;
  38480. protected function configure()
  38481. {
  38482. $this->ignoreValidationErrors();
  38483. $this
  38484. ->setName('help')
  38485. ->setDefinition(array(
  38486. new InputArgument('command_name', InputArgument::OPTIONAL, 'The command name', 'help'),
  38487. new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
  38488. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command help'),
  38489. ))
  38490. ->setDescription('Displays help for a command')
  38491. ->setHelp(<<<'EOF'
  38492. The <info>%command.name%</info> command displays help for a given command:
  38493. <info>php %command.full_name% list</info>
  38494. You can also output the help in other formats by using the <comment>--format</comment> option:
  38495. <info>php %command.full_name% --format=xml list</info>
  38496. To display the list of available commands, please use the <info>list</info> command.
  38497. EOF
  38498. )
  38499. ;
  38500. }
  38501. public function setCommand(Command $command)
  38502. {
  38503. $this->command = $command;
  38504. }
  38505. protected function execute(InputInterface $input, OutputInterface $output)
  38506. {
  38507. if (null === $this->command) {
  38508. $this->command = $this->getApplication()->find($input->getArgument('command_name'));
  38509. }
  38510. $helper = new DescriptorHelper();
  38511. $helper->describe($output, $this->command, array(
  38512. 'format' => $input->getOption('format'),
  38513. 'raw_text' => $input->getOption('raw'),
  38514. ));
  38515. $this->command = null;
  38516. }
  38517. }
  38518. <?php
  38519. namespace Symfony\Component\Console\Command;
  38520. use Symfony\Component\Console\Helper\DescriptorHelper;
  38521. use Symfony\Component\Console\Input\InputArgument;
  38522. use Symfony\Component\Console\Input\InputOption;
  38523. use Symfony\Component\Console\Input\InputInterface;
  38524. use Symfony\Component\Console\Output\OutputInterface;
  38525. use Symfony\Component\Console\Input\InputDefinition;
  38526. class ListCommand extends Command
  38527. {
  38528. protected function configure()
  38529. {
  38530. $this
  38531. ->setName('list')
  38532. ->setDefinition($this->createDefinition())
  38533. ->setDescription('Lists commands')
  38534. ->setHelp(<<<'EOF'
  38535. The <info>%command.name%</info> command lists all commands:
  38536. <info>php %command.full_name%</info>
  38537. You can also display the commands for a specific namespace:
  38538. <info>php %command.full_name% test</info>
  38539. You can also output the information in other formats by using the <comment>--format</comment> option:
  38540. <info>php %command.full_name% --format=xml</info>
  38541. It's also possible to get raw list of commands (useful for embedding command runner):
  38542. <info>php %command.full_name% --raw</info>
  38543. EOF
  38544. )
  38545. ;
  38546. }
  38547. public function getNativeDefinition()
  38548. {
  38549. return $this->createDefinition();
  38550. }
  38551. protected function execute(InputInterface $input, OutputInterface $output)
  38552. {
  38553. $helper = new DescriptorHelper();
  38554. $helper->describe($output, $this->getApplication(), array(
  38555. 'format' => $input->getOption('format'),
  38556. 'raw_text' => $input->getOption('raw'),
  38557. 'namespace' => $input->getArgument('namespace'),
  38558. ));
  38559. }
  38560. private function createDefinition()
  38561. {
  38562. return new InputDefinition(array(
  38563. new InputArgument('namespace', InputArgument::OPTIONAL, 'The namespace name'),
  38564. new InputOption('raw', null, InputOption::VALUE_NONE, 'To output raw command list'),
  38565. new InputOption('format', null, InputOption::VALUE_REQUIRED, 'The output format (txt, xml, json, or md)', 'txt'),
  38566. ));
  38567. }
  38568. }
  38569. <?php
  38570. namespace Symfony\Component\Console\Command;
  38571. use Symfony\Component\Console\Exception\LogicException;
  38572. use Symfony\Component\Console\Exception\RuntimeException;
  38573. use Symfony\Component\Lock\Factory;
  38574. use Symfony\Component\Lock\Lock;
  38575. use Symfony\Component\Lock\Store\FlockStore;
  38576. use Symfony\Component\Lock\Store\SemaphoreStore;
  38577. trait LockableTrait
  38578. {
  38579. private $lock;
  38580. private function lock($name = null, $blocking = false)
  38581. {
  38582. if (!class_exists(SemaphoreStore::class)) {
  38583. throw new RuntimeException('To enable the locking feature you must install the symfony/lock component.');
  38584. }
  38585. if (null !== $this->lock) {
  38586. throw new LogicException('A lock is already in place.');
  38587. }
  38588. if (SemaphoreStore::isSupported($blocking)) {
  38589. $store = new SemaphoreStore();
  38590. } else {
  38591. $store = new FlockStore();
  38592. }
  38593. $this->lock = (new Factory($store))->createLock($name ?: $this->getName());
  38594. if (!$this->lock->acquire($blocking)) {
  38595. $this->lock = null;
  38596. return false;
  38597. }
  38598. return true;
  38599. }
  38600. private function release()
  38601. {
  38602. if ($this->lock) {
  38603. $this->lock->release();
  38604. $this->lock = null;
  38605. }
  38606. }
  38607. }
  38608. <?php
  38609. namespace Symfony\Component\Console\CommandLoader;
  38610. use Symfony\Component\Console\Command\Command;
  38611. use Symfony\Component\Console\Exception\CommandNotFoundException;
  38612. interface CommandLoaderInterface
  38613. {
  38614. public function get($name);
  38615. public function has($name);
  38616. public function getNames();
  38617. }
  38618. <?php
  38619. namespace Symfony\Component\Console\CommandLoader;
  38620. use Psr\Container\ContainerInterface;
  38621. use Symfony\Component\Console\Exception\CommandNotFoundException;
  38622. class ContainerCommandLoader implements CommandLoaderInterface
  38623. {
  38624. private $container;
  38625. private $commandMap;
  38626. public function __construct(ContainerInterface $container, array $commandMap)
  38627. {
  38628. $this->container = $container;
  38629. $this->commandMap = $commandMap;
  38630. }
  38631. public function get($name)
  38632. {
  38633. if (!$this->has($name)) {
  38634. throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
  38635. }
  38636. return $this->container->get($this->commandMap[$name]);
  38637. }
  38638. public function has($name)
  38639. {
  38640. return isset($this->commandMap[$name]) && $this->container->has($this->commandMap[$name]);
  38641. }
  38642. public function getNames()
  38643. {
  38644. return array_keys($this->commandMap);
  38645. }
  38646. }
  38647. <?php
  38648. namespace Symfony\Component\Console\CommandLoader;
  38649. use Symfony\Component\Console\Exception\CommandNotFoundException;
  38650. class FactoryCommandLoader implements CommandLoaderInterface
  38651. {
  38652. private $factories;
  38653. public function __construct(array $factories)
  38654. {
  38655. $this->factories = $factories;
  38656. }
  38657. public function has($name)
  38658. {
  38659. return isset($this->factories[$name]);
  38660. }
  38661. public function get($name)
  38662. {
  38663. if (!isset($this->factories[$name])) {
  38664. throw new CommandNotFoundException(sprintf('Command "%s" does not exist.', $name));
  38665. }
  38666. $factory = $this->factories[$name];
  38667. return $factory();
  38668. }
  38669. public function getNames()
  38670. {
  38671. return array_keys($this->factories);
  38672. }
  38673. }
  38674. <?php
  38675. namespace Symfony\Component\Console;
  38676. final class ConsoleEvents
  38677. {
  38678. const COMMAND = 'console.command';
  38679. const TERMINATE = 'console.terminate';
  38680. const EXCEPTION = 'console.exception';
  38681. const ERROR = 'console.error';
  38682. }
  38683. <?php
  38684. namespace Symfony\Component\Console\DependencyInjection;
  38685. use Symfony\Component\Console\Command\Command;
  38686. use Symfony\Component\Console\CommandLoader\ContainerCommandLoader;
  38687. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  38688. use Symfony\Component\DependencyInjection\Compiler\ServiceLocatorTagPass;
  38689. use Symfony\Component\DependencyInjection\ContainerBuilder;
  38690. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  38691. use Symfony\Component\DependencyInjection\TypedReference;
  38692. class AddConsoleCommandPass implements CompilerPassInterface
  38693. {
  38694. private $commandLoaderServiceId;
  38695. private $commandTag;
  38696. public function __construct($commandLoaderServiceId = 'console.command_loader', $commandTag = 'console.command')
  38697. {
  38698. $this->commandLoaderServiceId = $commandLoaderServiceId;
  38699. $this->commandTag = $commandTag;
  38700. }
  38701. public function process(ContainerBuilder $container)
  38702. {
  38703. $commandServices = $container->findTaggedServiceIds($this->commandTag, true);
  38704. $lazyCommandMap = array();
  38705. $lazyCommandRefs = array();
  38706. $serviceIds = array();
  38707. $lazyServiceIds = array();
  38708. foreach ($commandServices as $id => $tags) {
  38709. $definition = $container->getDefinition($id);
  38710. $class = $container->getParameterBag()->resolveValue($definition->getClass());
  38711. $commandId = 'console.command.'.strtolower(str_replace('\\', '_', $class));
  38712. if (isset($tags[0]['command'])) {
  38713. $commandName = $tags[0]['command'];
  38714. } else {
  38715. if (!$r = $container->getReflectionClass($class)) {
  38716. throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
  38717. }
  38718. if (!$r->isSubclassOf(Command::class)) {
  38719. throw new InvalidArgumentException(sprintf('The service "%s" tagged "%s" must be a subclass of "%s".', $id, $this->commandTag, Command::class));
  38720. }
  38721. $commandName = $class::getDefaultName();
  38722. }
  38723. if (null === $commandName) {
  38724. if (isset($serviceIds[$commandId]) || $container->hasAlias($commandId)) {
  38725. $commandId = $commandId.'_'.$id;
  38726. }
  38727. if (!$definition->isPublic() || $definition->isPrivate()) {
  38728. $container->setAlias($commandId, $id)->setPublic(true);
  38729. $id = $commandId;
  38730. }
  38731. $serviceIds[$commandId] = $id;
  38732. continue;
  38733. }
  38734. $serviceIds[$commandId] = $id;
  38735. $lazyServiceIds[$id] = true;
  38736. unset($tags[0]);
  38737. $lazyCommandMap[$commandName] = $id;
  38738. $lazyCommandRefs[$id] = new TypedReference($id, $class);
  38739. $aliases = array();
  38740. foreach ($tags as $tag) {
  38741. if (isset($tag['command'])) {
  38742. $aliases[] = $tag['command'];
  38743. $lazyCommandMap[$tag['command']] = $id;
  38744. }
  38745. }
  38746. $definition->addMethodCall('setName', array($commandName));
  38747. if ($aliases) {
  38748. $definition->addMethodCall('setAliases', array($aliases));
  38749. }
  38750. }
  38751. $container
  38752. ->register($this->commandLoaderServiceId, ContainerCommandLoader::class)
  38753. ->setPublic(true)
  38754. ->setArguments(array(ServiceLocatorTagPass::register($container, $lazyCommandRefs), $lazyCommandMap));
  38755. $container->setParameter('console.command.ids', $serviceIds);
  38756. $container->setParameter('console.lazy_command.ids', $lazyServiceIds);
  38757. }
  38758. }
  38759. <?php
  38760. namespace Symfony\Component\Console\Descriptor;
  38761. use Symfony\Component\Console\Application;
  38762. use Symfony\Component\Console\Command\Command;
  38763. use Symfony\Component\Console\Exception\CommandNotFoundException;
  38764. class ApplicationDescription
  38765. {
  38766. const GLOBAL_NAMESPACE = '_global';
  38767. private $application;
  38768. private $namespace;
  38769. private $showHidden;
  38770. private $namespaces;
  38771. private $commands;
  38772. private $aliases;
  38773. public function __construct(Application $application, $namespace = null, $showHidden = false)
  38774. {
  38775. $this->application = $application;
  38776. $this->namespace = $namespace;
  38777. $this->showHidden = $showHidden;
  38778. }
  38779. public function getNamespaces()
  38780. {
  38781. if (null === $this->namespaces) {
  38782. $this->inspectApplication();
  38783. }
  38784. return $this->namespaces;
  38785. }
  38786. public function getCommands()
  38787. {
  38788. if (null === $this->commands) {
  38789. $this->inspectApplication();
  38790. }
  38791. return $this->commands;
  38792. }
  38793. public function getCommand($name)
  38794. {
  38795. if (!isset($this->commands[$name]) && !isset($this->aliases[$name])) {
  38796. throw new CommandNotFoundException(sprintf('Command %s does not exist.', $name));
  38797. }
  38798. return isset($this->commands[$name]) ? $this->commands[$name] : $this->aliases[$name];
  38799. }
  38800. private function inspectApplication()
  38801. {
  38802. $this->commands = array();
  38803. $this->namespaces = array();
  38804. $all = $this->application->all($this->namespace ? $this->application->findNamespace($this->namespace) : null);
  38805. foreach ($this->sortCommands($all) as $namespace => $commands) {
  38806. $names = array();
  38807. foreach ($commands as $name => $command) {
  38808. if (!$command->getName() || (!$this->showHidden && $command->isHidden())) {
  38809. continue;
  38810. }
  38811. if ($command->getName() === $name) {
  38812. $this->commands[$name] = $command;
  38813. } else {
  38814. $this->aliases[$name] = $command;
  38815. }
  38816. $names[] = $name;
  38817. }
  38818. $this->namespaces[$namespace] = array('id' => $namespace, 'commands' => $names);
  38819. }
  38820. }
  38821. private function sortCommands(array $commands)
  38822. {
  38823. $namespacedCommands = array();
  38824. $globalCommands = array();
  38825. foreach ($commands as $name => $command) {
  38826. $key = $this->application->extractNamespace($name, 1);
  38827. if (!$key) {
  38828. $globalCommands['_global'][$name] = $command;
  38829. } else {
  38830. $namespacedCommands[$key][$name] = $command;
  38831. }
  38832. }
  38833. ksort($namespacedCommands);
  38834. $namespacedCommands = array_merge($globalCommands, $namespacedCommands);
  38835. foreach ($namespacedCommands as &$commandsSet) {
  38836. ksort($commandsSet);
  38837. }
  38838. unset($commandsSet);
  38839. return $namespacedCommands;
  38840. }
  38841. }
  38842. <?php
  38843. namespace Symfony\Component\Console\Descriptor;
  38844. use Symfony\Component\Console\Application;
  38845. use Symfony\Component\Console\Command\Command;
  38846. use Symfony\Component\Console\Input\InputArgument;
  38847. use Symfony\Component\Console\Input\InputDefinition;
  38848. use Symfony\Component\Console\Input\InputOption;
  38849. use Symfony\Component\Console\Output\OutputInterface;
  38850. use Symfony\Component\Console\Exception\InvalidArgumentException;
  38851. abstract class Descriptor implements DescriptorInterface
  38852. {
  38853. protected $output;
  38854. public function describe(OutputInterface $output, $object, array $options = array())
  38855. {
  38856. $this->output = $output;
  38857. switch (true) {
  38858. case $object instanceof InputArgument:
  38859. $this->describeInputArgument($object, $options);
  38860. break;
  38861. case $object instanceof InputOption:
  38862. $this->describeInputOption($object, $options);
  38863. break;
  38864. case $object instanceof InputDefinition:
  38865. $this->describeInputDefinition($object, $options);
  38866. break;
  38867. case $object instanceof Command:
  38868. $this->describeCommand($object, $options);
  38869. break;
  38870. case $object instanceof Application:
  38871. $this->describeApplication($object, $options);
  38872. break;
  38873. default:
  38874. throw new InvalidArgumentException(sprintf('Object of type "%s" is not describable.', get_class($object)));
  38875. }
  38876. }
  38877. protected function write($content, $decorated = false)
  38878. {
  38879. $this->output->write($content, false, $decorated ? OutputInterface::OUTPUT_NORMAL : OutputInterface::OUTPUT_RAW);
  38880. }
  38881. abstract protected function describeInputArgument(InputArgument $argument, array $options = array());
  38882. abstract protected function describeInputOption(InputOption $option, array $options = array());
  38883. abstract protected function describeInputDefinition(InputDefinition $definition, array $options = array());
  38884. abstract protected function describeCommand(Command $command, array $options = array());
  38885. abstract protected function describeApplication(Application $application, array $options = array());
  38886. }
  38887. <?php
  38888. namespace Symfony\Component\Console\Descriptor;
  38889. use Symfony\Component\Console\Output\OutputInterface;
  38890. interface DescriptorInterface
  38891. {
  38892. public function describe(OutputInterface $output, $object, array $options = array());
  38893. }
  38894. <?php
  38895. namespace Symfony\Component\Console\Descriptor;
  38896. use Symfony\Component\Console\Application;
  38897. use Symfony\Component\Console\Command\Command;
  38898. use Symfony\Component\Console\Input\InputArgument;
  38899. use Symfony\Component\Console\Input\InputDefinition;
  38900. use Symfony\Component\Console\Input\InputOption;
  38901. class JsonDescriptor extends Descriptor
  38902. {
  38903. protected function describeInputArgument(InputArgument $argument, array $options = array())
  38904. {
  38905. $this->writeData($this->getInputArgumentData($argument), $options);
  38906. }
  38907. protected function describeInputOption(InputOption $option, array $options = array())
  38908. {
  38909. $this->writeData($this->getInputOptionData($option), $options);
  38910. }
  38911. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  38912. {
  38913. $this->writeData($this->getInputDefinitionData($definition), $options);
  38914. }
  38915. protected function describeCommand(Command $command, array $options = array())
  38916. {
  38917. $this->writeData($this->getCommandData($command), $options);
  38918. }
  38919. protected function describeApplication(Application $application, array $options = array())
  38920. {
  38921. $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  38922. $description = new ApplicationDescription($application, $describedNamespace, true);
  38923. $commands = array();
  38924. foreach ($description->getCommands() as $command) {
  38925. $commands[] = $this->getCommandData($command);
  38926. }
  38927. $data = array();
  38928. if ('UNKNOWN' !== $application->getName()) {
  38929. $data['application']['name'] = $application->getName();
  38930. if ('UNKNOWN' !== $application->getVersion()) {
  38931. $data['application']['version'] = $application->getVersion();
  38932. }
  38933. }
  38934. $data['commands'] = $commands;
  38935. if ($describedNamespace) {
  38936. $data['namespace'] = $describedNamespace;
  38937. } else {
  38938. $data['namespaces'] = array_values($description->getNamespaces());
  38939. }
  38940. $this->writeData($data, $options);
  38941. }
  38942. private function writeData(array $data, array $options)
  38943. {
  38944. $this->write(json_encode($data, isset($options['json_encoding']) ? $options['json_encoding'] : 0));
  38945. }
  38946. private function getInputArgumentData(InputArgument $argument)
  38947. {
  38948. return array(
  38949. 'name' => $argument->getName(),
  38950. 'is_required' => $argument->isRequired(),
  38951. 'is_array' => $argument->isArray(),
  38952. 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $argument->getDescription()),
  38953. 'default' => INF === $argument->getDefault() ? 'INF' : $argument->getDefault(),
  38954. );
  38955. }
  38956. private function getInputOptionData(InputOption $option)
  38957. {
  38958. return array(
  38959. 'name' => '--'.$option->getName(),
  38960. 'shortcut' => $option->getShortcut() ? '-'.implode('|-', explode('|', $option->getShortcut())) : '',
  38961. 'accept_value' => $option->acceptValue(),
  38962. 'is_value_required' => $option->isValueRequired(),
  38963. 'is_multiple' => $option->isArray(),
  38964. 'description' => preg_replace('/\s*[\r\n]\s*/', ' ', $option->getDescription()),
  38965. 'default' => INF === $option->getDefault() ? 'INF' : $option->getDefault(),
  38966. );
  38967. }
  38968. private function getInputDefinitionData(InputDefinition $definition)
  38969. {
  38970. $inputArguments = array();
  38971. foreach ($definition->getArguments() as $name => $argument) {
  38972. $inputArguments[$name] = $this->getInputArgumentData($argument);
  38973. }
  38974. $inputOptions = array();
  38975. foreach ($definition->getOptions() as $name => $option) {
  38976. $inputOptions[$name] = $this->getInputOptionData($option);
  38977. }
  38978. return array('arguments' => $inputArguments, 'options' => $inputOptions);
  38979. }
  38980. private function getCommandData(Command $command)
  38981. {
  38982. $command->getSynopsis();
  38983. $command->mergeApplicationDefinition(false);
  38984. return array(
  38985. 'name' => $command->getName(),
  38986. 'usage' => array_merge(array($command->getSynopsis()), $command->getUsages(), $command->getAliases()),
  38987. 'description' => $command->getDescription(),
  38988. 'help' => $command->getProcessedHelp(),
  38989. 'definition' => $this->getInputDefinitionData($command->getNativeDefinition()),
  38990. 'hidden' => $command->isHidden(),
  38991. );
  38992. }
  38993. }
  38994. <?php
  38995. namespace Symfony\Component\Console\Descriptor;
  38996. use Symfony\Component\Console\Application;
  38997. use Symfony\Component\Console\Command\Command;
  38998. use Symfony\Component\Console\Helper\Helper;
  38999. use Symfony\Component\Console\Input\InputArgument;
  39000. use Symfony\Component\Console\Input\InputDefinition;
  39001. use Symfony\Component\Console\Input\InputOption;
  39002. use Symfony\Component\Console\Output\OutputInterface;
  39003. class MarkdownDescriptor extends Descriptor
  39004. {
  39005. public function describe(OutputInterface $output, $object, array $options = array())
  39006. {
  39007. $decorated = $output->isDecorated();
  39008. $output->setDecorated(false);
  39009. parent::describe($output, $object, $options);
  39010. $output->setDecorated($decorated);
  39011. }
  39012. protected function write($content, $decorated = true)
  39013. {
  39014. parent::write($content, $decorated);
  39015. }
  39016. protected function describeInputArgument(InputArgument $argument, array $options = array())
  39017. {
  39018. $this->write(
  39019. '#### `'.($argument->getName() ?: '<none>')."`\n\n"
  39020. .($argument->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $argument->getDescription())."\n\n" : '')
  39021. .'* Is required: '.($argument->isRequired() ? 'yes' : 'no')."\n"
  39022. .'* Is array: '.($argument->isArray() ? 'yes' : 'no')."\n"
  39023. .'* Default: `'.str_replace("\n", '', var_export($argument->getDefault(), true)).'`'
  39024. );
  39025. }
  39026. protected function describeInputOption(InputOption $option, array $options = array())
  39027. {
  39028. $name = '--'.$option->getName();
  39029. if ($option->getShortcut()) {
  39030. $name .= '|-'.implode('|-', explode('|', $option->getShortcut())).'';
  39031. }
  39032. $this->write(
  39033. '#### `'.$name.'`'."\n\n"
  39034. .($option->getDescription() ? preg_replace('/\s*[\r\n]\s*/', "\n", $option->getDescription())."\n\n" : '')
  39035. .'* Accept value: '.($option->acceptValue() ? 'yes' : 'no')."\n"
  39036. .'* Is value required: '.($option->isValueRequired() ? 'yes' : 'no')."\n"
  39037. .'* Is multiple: '.($option->isArray() ? 'yes' : 'no')."\n"
  39038. .'* Default: `'.str_replace("\n", '', var_export($option->getDefault(), true)).'`'
  39039. );
  39040. }
  39041. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  39042. {
  39043. if ($showArguments = count($definition->getArguments()) > 0) {
  39044. $this->write('### Arguments');
  39045. foreach ($definition->getArguments() as $argument) {
  39046. $this->write("\n\n");
  39047. $this->write($this->describeInputArgument($argument));
  39048. }
  39049. }
  39050. if (count($definition->getOptions()) > 0) {
  39051. if ($showArguments) {
  39052. $this->write("\n\n");
  39053. }
  39054. $this->write('### Options');
  39055. foreach ($definition->getOptions() as $option) {
  39056. $this->write("\n\n");
  39057. $this->write($this->describeInputOption($option));
  39058. }
  39059. }
  39060. }
  39061. protected function describeCommand(Command $command, array $options = array())
  39062. {
  39063. $command->getSynopsis();
  39064. $command->mergeApplicationDefinition(false);
  39065. $this->write(
  39066. '`'.$command->getName()."`\n"
  39067. .str_repeat('-', Helper::strlen($command->getName()) + 2)."\n\n"
  39068. .($command->getDescription() ? $command->getDescription()."\n\n" : '')
  39069. .'### Usage'."\n\n"
  39070. .array_reduce(array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()), function ($carry, $usage) {
  39071. return $carry.'* `'.$usage.'`'."\n";
  39072. })
  39073. );
  39074. if ($help = $command->getProcessedHelp()) {
  39075. $this->write("\n");
  39076. $this->write($help);
  39077. }
  39078. if ($command->getNativeDefinition()) {
  39079. $this->write("\n\n");
  39080. $this->describeInputDefinition($command->getNativeDefinition());
  39081. }
  39082. }
  39083. protected function describeApplication(Application $application, array $options = array())
  39084. {
  39085. $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  39086. $description = new ApplicationDescription($application, $describedNamespace);
  39087. $title = $this->getApplicationTitle($application);
  39088. $this->write($title."\n".str_repeat('=', Helper::strlen($title)));
  39089. foreach ($description->getNamespaces() as $namespace) {
  39090. if (ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
  39091. $this->write("\n\n");
  39092. $this->write('**'.$namespace['id'].':**');
  39093. }
  39094. $this->write("\n\n");
  39095. $this->write(implode("\n", array_map(function ($commandName) use ($description) {
  39096. return sprintf('* [`%s`](#%s)', $commandName, str_replace(':', '', $description->getCommand($commandName)->getName()));
  39097. }, $namespace['commands'])));
  39098. }
  39099. foreach ($description->getCommands() as $command) {
  39100. $this->write("\n\n");
  39101. $this->write($this->describeCommand($command));
  39102. }
  39103. }
  39104. private function getApplicationTitle(Application $application)
  39105. {
  39106. if ('UNKNOWN' !== $application->getName()) {
  39107. if ('UNKNOWN' !== $application->getVersion()) {
  39108. return sprintf('%s %s', $application->getName(), $application->getVersion());
  39109. }
  39110. return $application->getName();
  39111. }
  39112. return 'Console Tool';
  39113. }
  39114. }
  39115. <?php
  39116. namespace Symfony\Component\Console\Descriptor;
  39117. use Symfony\Component\Console\Application;
  39118. use Symfony\Component\Console\Command\Command;
  39119. use Symfony\Component\Console\Formatter\OutputFormatter;
  39120. use Symfony\Component\Console\Helper\Helper;
  39121. use Symfony\Component\Console\Input\InputArgument;
  39122. use Symfony\Component\Console\Input\InputDefinition;
  39123. use Symfony\Component\Console\Input\InputOption;
  39124. class TextDescriptor extends Descriptor
  39125. {
  39126. protected function describeInputArgument(InputArgument $argument, array $options = array())
  39127. {
  39128. if (null !== $argument->getDefault() && (!is_array($argument->getDefault()) || count($argument->getDefault()))) {
  39129. $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($argument->getDefault()));
  39130. } else {
  39131. $default = '';
  39132. }
  39133. $totalWidth = isset($options['total_width']) ? $options['total_width'] : Helper::strlen($argument->getName());
  39134. $spacingWidth = $totalWidth - strlen($argument->getName());
  39135. $this->writeText(sprintf(' <info>%s</info> %s%s%s',
  39136. $argument->getName(),
  39137. str_repeat(' ', $spacingWidth),
  39138. preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $argument->getDescription()),
  39139. $default
  39140. ), $options);
  39141. }
  39142. protected function describeInputOption(InputOption $option, array $options = array())
  39143. {
  39144. if ($option->acceptValue() && null !== $option->getDefault() && (!is_array($option->getDefault()) || count($option->getDefault()))) {
  39145. $default = sprintf('<comment> [default: %s]</comment>', $this->formatDefaultValue($option->getDefault()));
  39146. } else {
  39147. $default = '';
  39148. }
  39149. $value = '';
  39150. if ($option->acceptValue()) {
  39151. $value = '='.strtoupper($option->getName());
  39152. if ($option->isValueOptional()) {
  39153. $value = '['.$value.']';
  39154. }
  39155. }
  39156. $totalWidth = isset($options['total_width']) ? $options['total_width'] : $this->calculateTotalWidthForOptions(array($option));
  39157. $synopsis = sprintf('%s%s',
  39158. $option->getShortcut() ? sprintf('-%s, ', $option->getShortcut()) : ' ',
  39159. sprintf('--%s%s', $option->getName(), $value)
  39160. );
  39161. $spacingWidth = $totalWidth - Helper::strlen($synopsis);
  39162. $this->writeText(sprintf(' <info>%s</info> %s%s%s%s',
  39163. $synopsis,
  39164. str_repeat(' ', $spacingWidth),
  39165. preg_replace('/\s*[\r\n]\s*/', "\n".str_repeat(' ', $totalWidth + 4), $option->getDescription()),
  39166. $default,
  39167. $option->isArray() ? '<comment> (multiple values allowed)</comment>' : ''
  39168. ), $options);
  39169. }
  39170. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  39171. {
  39172. $totalWidth = $this->calculateTotalWidthForOptions($definition->getOptions());
  39173. foreach ($definition->getArguments() as $argument) {
  39174. $totalWidth = max($totalWidth, Helper::strlen($argument->getName()));
  39175. }
  39176. if ($definition->getArguments()) {
  39177. $this->writeText('<comment>Arguments:</comment>', $options);
  39178. $this->writeText("\n");
  39179. foreach ($definition->getArguments() as $argument) {
  39180. $this->describeInputArgument($argument, array_merge($options, array('total_width' => $totalWidth)));
  39181. $this->writeText("\n");
  39182. }
  39183. }
  39184. if ($definition->getArguments() && $definition->getOptions()) {
  39185. $this->writeText("\n");
  39186. }
  39187. if ($definition->getOptions()) {
  39188. $laterOptions = array();
  39189. $this->writeText('<comment>Options:</comment>', $options);
  39190. foreach ($definition->getOptions() as $option) {
  39191. if (strlen($option->getShortcut()) > 1) {
  39192. $laterOptions[] = $option;
  39193. continue;
  39194. }
  39195. $this->writeText("\n");
  39196. $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
  39197. }
  39198. foreach ($laterOptions as $option) {
  39199. $this->writeText("\n");
  39200. $this->describeInputOption($option, array_merge($options, array('total_width' => $totalWidth)));
  39201. }
  39202. }
  39203. }
  39204. protected function describeCommand(Command $command, array $options = array())
  39205. {
  39206. $command->getSynopsis(true);
  39207. $command->getSynopsis(false);
  39208. $command->mergeApplicationDefinition(false);
  39209. $this->writeText('<comment>Usage:</comment>', $options);
  39210. foreach (array_merge(array($command->getSynopsis(true)), $command->getAliases(), $command->getUsages()) as $usage) {
  39211. $this->writeText("\n");
  39212. $this->writeText(' '.OutputFormatter::escape($usage), $options);
  39213. }
  39214. $this->writeText("\n");
  39215. $definition = $command->getNativeDefinition();
  39216. if ($definition->getOptions() || $definition->getArguments()) {
  39217. $this->writeText("\n");
  39218. $this->describeInputDefinition($definition, $options);
  39219. $this->writeText("\n");
  39220. }
  39221. if ($help = $command->getProcessedHelp()) {
  39222. $this->writeText("\n");
  39223. $this->writeText('<comment>Help:</comment>', $options);
  39224. $this->writeText("\n");
  39225. $this->writeText(' '.str_replace("\n", "\n ", $help), $options);
  39226. $this->writeText("\n");
  39227. }
  39228. }
  39229. protected function describeApplication(Application $application, array $options = array())
  39230. {
  39231. $describedNamespace = isset($options['namespace']) ? $options['namespace'] : null;
  39232. $description = new ApplicationDescription($application, $describedNamespace);
  39233. if (isset($options['raw_text']) && $options['raw_text']) {
  39234. $width = $this->getColumnWidth($description->getCommands());
  39235. foreach ($description->getCommands() as $command) {
  39236. $this->writeText(sprintf("%-{$width}s %s", $command->getName(), $command->getDescription()), $options);
  39237. $this->writeText("\n");
  39238. }
  39239. } else {
  39240. if ('' != $help = $application->getHelp()) {
  39241. $this->writeText("$help\n\n", $options);
  39242. }
  39243. $this->writeText("<comment>Usage:</comment>\n", $options);
  39244. $this->writeText(" command [options] [arguments]\n\n", $options);
  39245. $this->describeInputDefinition(new InputDefinition($application->getDefinition()->getOptions()), $options);
  39246. $this->writeText("\n");
  39247. $this->writeText("\n");
  39248. $commands = $description->getCommands();
  39249. $namespaces = $description->getNamespaces();
  39250. if ($describedNamespace && $namespaces) {
  39251. $describedNamespaceInfo = reset($namespaces);
  39252. foreach ($describedNamespaceInfo['commands'] as $name) {
  39253. $commands[$name] = $description->getCommand($name);
  39254. }
  39255. }
  39256. $width = $this->getColumnWidth(call_user_func_array('array_merge', array_map(function ($namespace) use ($commands) {
  39257. return array_intersect($namespace['commands'], array_keys($commands));
  39258. }, $namespaces)));
  39259. if ($describedNamespace) {
  39260. $this->writeText(sprintf('<comment>Available commands for the "%s" namespace:</comment>', $describedNamespace), $options);
  39261. } else {
  39262. $this->writeText('<comment>Available commands:</comment>', $options);
  39263. }
  39264. foreach ($namespaces as $namespace) {
  39265. $namespace['commands'] = array_filter($namespace['commands'], function ($name) use ($commands) {
  39266. return isset($commands[$name]);
  39267. });
  39268. if (!$namespace['commands']) {
  39269. continue;
  39270. }
  39271. if (!$describedNamespace && ApplicationDescription::GLOBAL_NAMESPACE !== $namespace['id']) {
  39272. $this->writeText("\n");
  39273. $this->writeText(' <comment>'.$namespace['id'].'</comment>', $options);
  39274. }
  39275. foreach ($namespace['commands'] as $name) {
  39276. $this->writeText("\n");
  39277. $spacingWidth = $width - Helper::strlen($name);
  39278. $command = $commands[$name];
  39279. $commandAliases = $name === $command->getName() ? $this->getCommandAliasesText($command) : '';
  39280. $this->writeText(sprintf(' <info>%s</info>%s%s', $name, str_repeat(' ', $spacingWidth), $commandAliases.$command->getDescription()), $options);
  39281. }
  39282. }
  39283. $this->writeText("\n");
  39284. }
  39285. }
  39286. private function writeText($content, array $options = array())
  39287. {
  39288. $this->write(
  39289. isset($options['raw_text']) && $options['raw_text'] ? strip_tags($content) : $content,
  39290. isset($options['raw_output']) ? !$options['raw_output'] : true
  39291. );
  39292. }
  39293. private function getCommandAliasesText(Command $command)
  39294. {
  39295. $text = '';
  39296. $aliases = $command->getAliases();
  39297. if ($aliases) {
  39298. $text = '['.implode('|', $aliases).'] ';
  39299. }
  39300. return $text;
  39301. }
  39302. private function formatDefaultValue($default)
  39303. {
  39304. if (INF === $default) {
  39305. return 'INF';
  39306. }
  39307. if (is_string($default)) {
  39308. $default = OutputFormatter::escape($default);
  39309. } elseif (is_array($default)) {
  39310. foreach ($default as $key => $value) {
  39311. if (is_string($value)) {
  39312. $default[$key] = OutputFormatter::escape($value);
  39313. }
  39314. }
  39315. }
  39316. return str_replace('\\\\', '\\', json_encode($default, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE));
  39317. }
  39318. private function getColumnWidth(array $commands)
  39319. {
  39320. $widths = array();
  39321. foreach ($commands as $command) {
  39322. if ($command instanceof Command) {
  39323. $widths[] = Helper::strlen($command->getName());
  39324. foreach ($command->getAliases() as $alias) {
  39325. $widths[] = Helper::strlen($alias);
  39326. }
  39327. } else {
  39328. $widths[] = Helper::strlen($command);
  39329. }
  39330. }
  39331. return $widths ? max($widths) + 2 : 0;
  39332. }
  39333. private function calculateTotalWidthForOptions(array $options)
  39334. {
  39335. $totalWidth = 0;
  39336. foreach ($options as $option) {
  39337. $nameLength = 1 + max(Helper::strlen($option->getShortcut()), 1) + 4 + Helper::strlen($option->getName());
  39338. if ($option->acceptValue()) {
  39339. $valueLength = 1 + Helper::strlen($option->getName());
  39340. $valueLength += $option->isValueOptional() ? 2 : 0;
  39341. $nameLength += $valueLength;
  39342. }
  39343. $totalWidth = max($totalWidth, $nameLength);
  39344. }
  39345. return $totalWidth;
  39346. }
  39347. }
  39348. <?php
  39349. namespace Symfony\Component\Console\Descriptor;
  39350. use Symfony\Component\Console\Application;
  39351. use Symfony\Component\Console\Command\Command;
  39352. use Symfony\Component\Console\Input\InputArgument;
  39353. use Symfony\Component\Console\Input\InputDefinition;
  39354. use Symfony\Component\Console\Input\InputOption;
  39355. class XmlDescriptor extends Descriptor
  39356. {
  39357. public function getInputDefinitionDocument(InputDefinition $definition)
  39358. {
  39359. $dom = new \DOMDocument('1.0', 'UTF-8');
  39360. $dom->appendChild($definitionXML = $dom->createElement('definition'));
  39361. $definitionXML->appendChild($argumentsXML = $dom->createElement('arguments'));
  39362. foreach ($definition->getArguments() as $argument) {
  39363. $this->appendDocument($argumentsXML, $this->getInputArgumentDocument($argument));
  39364. }
  39365. $definitionXML->appendChild($optionsXML = $dom->createElement('options'));
  39366. foreach ($definition->getOptions() as $option) {
  39367. $this->appendDocument($optionsXML, $this->getInputOptionDocument($option));
  39368. }
  39369. return $dom;
  39370. }
  39371. public function getCommandDocument(Command $command)
  39372. {
  39373. $dom = new \DOMDocument('1.0', 'UTF-8');
  39374. $dom->appendChild($commandXML = $dom->createElement('command'));
  39375. $command->getSynopsis();
  39376. $command->mergeApplicationDefinition(false);
  39377. $commandXML->setAttribute('id', $command->getName());
  39378. $commandXML->setAttribute('name', $command->getName());
  39379. $commandXML->setAttribute('hidden', $command->isHidden() ? 1 : 0);
  39380. $commandXML->appendChild($usagesXML = $dom->createElement('usages'));
  39381. foreach (array_merge(array($command->getSynopsis()), $command->getAliases(), $command->getUsages()) as $usage) {
  39382. $usagesXML->appendChild($dom->createElement('usage', $usage));
  39383. }
  39384. $commandXML->appendChild($descriptionXML = $dom->createElement('description'));
  39385. $descriptionXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getDescription())));
  39386. $commandXML->appendChild($helpXML = $dom->createElement('help'));
  39387. $helpXML->appendChild($dom->createTextNode(str_replace("\n", "\n ", $command->getProcessedHelp())));
  39388. $definitionXML = $this->getInputDefinitionDocument($command->getNativeDefinition());
  39389. $this->appendDocument($commandXML, $definitionXML->getElementsByTagName('definition')->item(0));
  39390. return $dom;
  39391. }
  39392. public function getApplicationDocument(Application $application, $namespace = null)
  39393. {
  39394. $dom = new \DOMDocument('1.0', 'UTF-8');
  39395. $dom->appendChild($rootXml = $dom->createElement('symfony'));
  39396. if ('UNKNOWN' !== $application->getName()) {
  39397. $rootXml->setAttribute('name', $application->getName());
  39398. if ('UNKNOWN' !== $application->getVersion()) {
  39399. $rootXml->setAttribute('version', $application->getVersion());
  39400. }
  39401. }
  39402. $rootXml->appendChild($commandsXML = $dom->createElement('commands'));
  39403. $description = new ApplicationDescription($application, $namespace, true);
  39404. if ($namespace) {
  39405. $commandsXML->setAttribute('namespace', $namespace);
  39406. }
  39407. foreach ($description->getCommands() as $command) {
  39408. $this->appendDocument($commandsXML, $this->getCommandDocument($command));
  39409. }
  39410. if (!$namespace) {
  39411. $rootXml->appendChild($namespacesXML = $dom->createElement('namespaces'));
  39412. foreach ($description->getNamespaces() as $namespaceDescription) {
  39413. $namespacesXML->appendChild($namespaceArrayXML = $dom->createElement('namespace'));
  39414. $namespaceArrayXML->setAttribute('id', $namespaceDescription['id']);
  39415. foreach ($namespaceDescription['commands'] as $name) {
  39416. $namespaceArrayXML->appendChild($commandXML = $dom->createElement('command'));
  39417. $commandXML->appendChild($dom->createTextNode($name));
  39418. }
  39419. }
  39420. }
  39421. return $dom;
  39422. }
  39423. protected function describeInputArgument(InputArgument $argument, array $options = array())
  39424. {
  39425. $this->writeDocument($this->getInputArgumentDocument($argument));
  39426. }
  39427. protected function describeInputOption(InputOption $option, array $options = array())
  39428. {
  39429. $this->writeDocument($this->getInputOptionDocument($option));
  39430. }
  39431. protected function describeInputDefinition(InputDefinition $definition, array $options = array())
  39432. {
  39433. $this->writeDocument($this->getInputDefinitionDocument($definition));
  39434. }
  39435. protected function describeCommand(Command $command, array $options = array())
  39436. {
  39437. $this->writeDocument($this->getCommandDocument($command));
  39438. }
  39439. protected function describeApplication(Application $application, array $options = array())
  39440. {
  39441. $this->writeDocument($this->getApplicationDocument($application, isset($options['namespace']) ? $options['namespace'] : null));
  39442. }
  39443. private function appendDocument(\DOMNode $parentNode, \DOMNode $importedParent)
  39444. {
  39445. foreach ($importedParent->childNodes as $childNode) {
  39446. $parentNode->appendChild($parentNode->ownerDocument->importNode($childNode, true));
  39447. }
  39448. }
  39449. private function writeDocument(\DOMDocument $dom)
  39450. {
  39451. $dom->formatOutput = true;
  39452. $this->write($dom->saveXML());
  39453. }
  39454. private function getInputArgumentDocument(InputArgument $argument)
  39455. {
  39456. $dom = new \DOMDocument('1.0', 'UTF-8');
  39457. $dom->appendChild($objectXML = $dom->createElement('argument'));
  39458. $objectXML->setAttribute('name', $argument->getName());
  39459. $objectXML->setAttribute('is_required', $argument->isRequired() ? 1 : 0);
  39460. $objectXML->setAttribute('is_array', $argument->isArray() ? 1 : 0);
  39461. $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
  39462. $descriptionXML->appendChild($dom->createTextNode($argument->getDescription()));
  39463. $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
  39464. $defaults = is_array($argument->getDefault()) ? $argument->getDefault() : (is_bool($argument->getDefault()) ? array(var_export($argument->getDefault(), true)) : ($argument->getDefault() ? array($argument->getDefault()) : array()));
  39465. foreach ($defaults as $default) {
  39466. $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
  39467. $defaultXML->appendChild($dom->createTextNode($default));
  39468. }
  39469. return $dom;
  39470. }
  39471. private function getInputOptionDocument(InputOption $option)
  39472. {
  39473. $dom = new \DOMDocument('1.0', 'UTF-8');
  39474. $dom->appendChild($objectXML = $dom->createElement('option'));
  39475. $objectXML->setAttribute('name', '--'.$option->getName());
  39476. $pos = strpos($option->getShortcut(), '|');
  39477. if (false !== $pos) {
  39478. $objectXML->setAttribute('shortcut', '-'.substr($option->getShortcut(), 0, $pos));
  39479. $objectXML->setAttribute('shortcuts', '-'.implode('|-', explode('|', $option->getShortcut())));
  39480. } else {
  39481. $objectXML->setAttribute('shortcut', $option->getShortcut() ? '-'.$option->getShortcut() : '');
  39482. }
  39483. $objectXML->setAttribute('accept_value', $option->acceptValue() ? 1 : 0);
  39484. $objectXML->setAttribute('is_value_required', $option->isValueRequired() ? 1 : 0);
  39485. $objectXML->setAttribute('is_multiple', $option->isArray() ? 1 : 0);
  39486. $objectXML->appendChild($descriptionXML = $dom->createElement('description'));
  39487. $descriptionXML->appendChild($dom->createTextNode($option->getDescription()));
  39488. if ($option->acceptValue()) {
  39489. $defaults = is_array($option->getDefault()) ? $option->getDefault() : (is_bool($option->getDefault()) ? array(var_export($option->getDefault(), true)) : ($option->getDefault() ? array($option->getDefault()) : array()));
  39490. $objectXML->appendChild($defaultsXML = $dom->createElement('defaults'));
  39491. if (!empty($defaults)) {
  39492. foreach ($defaults as $default) {
  39493. $defaultsXML->appendChild($defaultXML = $dom->createElement('default'));
  39494. $defaultXML->appendChild($dom->createTextNode($default));
  39495. }
  39496. }
  39497. }
  39498. return $dom;
  39499. }
  39500. }
  39501. <?php
  39502. namespace Symfony\Component\Console\Event;
  39503. class ConsoleCommandEvent extends ConsoleEvent
  39504. {
  39505. const RETURN_CODE_DISABLED = 113;
  39506. private $commandShouldRun = true;
  39507. public function disableCommand()
  39508. {
  39509. return $this->commandShouldRun = false;
  39510. }
  39511. public function enableCommand()
  39512. {
  39513. return $this->commandShouldRun = true;
  39514. }
  39515. public function commandShouldRun()
  39516. {
  39517. return $this->commandShouldRun;
  39518. }
  39519. }
  39520. <?php
  39521. namespace Symfony\Component\Console\Event;
  39522. use Symfony\Component\Console\Command\Command;
  39523. use Symfony\Component\Console\Exception\InvalidArgumentException;
  39524. use Symfony\Component\Console\Input\InputInterface;
  39525. use Symfony\Component\Console\Output\OutputInterface;
  39526. final class ConsoleErrorEvent extends ConsoleEvent
  39527. {
  39528. private $error;
  39529. private $exitCode;
  39530. public function __construct(InputInterface $input, OutputInterface $output, $error, Command $command = null)
  39531. {
  39532. parent::__construct($command, $input, $output);
  39533. $this->setError($error);
  39534. }
  39535. public function getError()
  39536. {
  39537. return $this->error;
  39538. }
  39539. public function setError($error)
  39540. {
  39541. if (!$error instanceof \Throwable && !$error instanceof \Exception) {
  39542. throw new InvalidArgumentException(sprintf('The error passed to ConsoleErrorEvent must be an instance of \Throwable or \Exception, "%s" was passed instead.', is_object($error) ? get_class($error) : gettype($error)));
  39543. }
  39544. $this->error = $error;
  39545. }
  39546. public function setExitCode($exitCode)
  39547. {
  39548. $this->exitCode = (int) $exitCode;
  39549. $r = new \ReflectionProperty($this->error, 'code');
  39550. $r->setAccessible(true);
  39551. $r->setValue($this->error, $this->exitCode);
  39552. }
  39553. public function getExitCode()
  39554. {
  39555. return null !== $this->exitCode ? $this->exitCode : (is_int($this->error->getCode()) && 0 !== $this->error->getCode() ? $this->error->getCode() : 1);
  39556. }
  39557. }
  39558. <?php
  39559. namespace Symfony\Component\Console\Event;
  39560. use Symfony\Component\Console\Command\Command;
  39561. use Symfony\Component\Console\Input\InputInterface;
  39562. use Symfony\Component\Console\Output\OutputInterface;
  39563. use Symfony\Component\EventDispatcher\Event;
  39564. class ConsoleEvent extends Event
  39565. {
  39566. protected $command;
  39567. private $input;
  39568. private $output;
  39569. public function __construct(Command $command = null, InputInterface $input, OutputInterface $output)
  39570. {
  39571. $this->command = $command;
  39572. $this->input = $input;
  39573. $this->output = $output;
  39574. }
  39575. public function getCommand()
  39576. {
  39577. return $this->command;
  39578. }
  39579. public function getInput()
  39580. {
  39581. return $this->input;
  39582. }
  39583. public function getOutput()
  39584. {
  39585. return $this->output;
  39586. }
  39587. }
  39588. <?php
  39589. namespace Symfony\Component\Console\Event;
  39590. @trigger_error(sprintf('The "%s" class is deprecated since Symfony 3.3 and will be removed in 4.0. Use the ConsoleErrorEvent instead.', ConsoleExceptionEvent::class), E_USER_DEPRECATED);
  39591. use Symfony\Component\Console\Command\Command;
  39592. use Symfony\Component\Console\Input\InputInterface;
  39593. use Symfony\Component\Console\Output\OutputInterface;
  39594. class ConsoleExceptionEvent extends ConsoleEvent
  39595. {
  39596. private $exception;
  39597. private $exitCode;
  39598. public function __construct(Command $command, InputInterface $input, OutputInterface $output, \Exception $exception, $exitCode)
  39599. {
  39600. parent::__construct($command, $input, $output);
  39601. $this->setException($exception);
  39602. $this->exitCode = (int) $exitCode;
  39603. }
  39604. public function getException()
  39605. {
  39606. return $this->exception;
  39607. }
  39608. public function setException(\Exception $exception)
  39609. {
  39610. $this->exception = $exception;
  39611. }
  39612. public function getExitCode()
  39613. {
  39614. return $this->exitCode;
  39615. }
  39616. }
  39617. <?php
  39618. namespace Symfony\Component\Console\Event;
  39619. use Symfony\Component\Console\Command\Command;
  39620. use Symfony\Component\Console\Input\InputInterface;
  39621. use Symfony\Component\Console\Output\OutputInterface;
  39622. class ConsoleTerminateEvent extends ConsoleEvent
  39623. {
  39624. private $exitCode;
  39625. public function __construct(Command $command, InputInterface $input, OutputInterface $output, $exitCode)
  39626. {
  39627. parent::__construct($command, $input, $output);
  39628. $this->setExitCode($exitCode);
  39629. }
  39630. public function setExitCode($exitCode)
  39631. {
  39632. $this->exitCode = (int) $exitCode;
  39633. }
  39634. public function getExitCode()
  39635. {
  39636. return $this->exitCode;
  39637. }
  39638. }
  39639. <?php
  39640. namespace Symfony\Component\Console\EventListener;
  39641. use Psr\Log\LoggerInterface;
  39642. use Symfony\Component\Console\ConsoleEvents;
  39643. use Symfony\Component\Console\Event\ConsoleErrorEvent;
  39644. use Symfony\Component\Console\Event\ConsoleEvent;
  39645. use Symfony\Component\Console\Event\ConsoleTerminateEvent;
  39646. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  39647. class ErrorListener implements EventSubscriberInterface
  39648. {
  39649. private $logger;
  39650. public function __construct(LoggerInterface $logger = null)
  39651. {
  39652. $this->logger = $logger;
  39653. }
  39654. public function onConsoleError(ConsoleErrorEvent $event)
  39655. {
  39656. if (null === $this->logger) {
  39657. return;
  39658. }
  39659. $error = $event->getError();
  39660. if (!$inputString = $this->getInputString($event)) {
  39661. return $this->logger->error('An error occurred while using the console. Message: "{message}"', array('error' => $error, 'message' => $error->getMessage()));
  39662. }
  39663. $this->logger->error('Error thrown while running command "{command}". Message: "{message}"', array('error' => $error, 'command' => $inputString, 'message' => $error->getMessage()));
  39664. }
  39665. public function onConsoleTerminate(ConsoleTerminateEvent $event)
  39666. {
  39667. if (null === $this->logger) {
  39668. return;
  39669. }
  39670. $exitCode = $event->getExitCode();
  39671. if (0 === $exitCode) {
  39672. return;
  39673. }
  39674. if (!$inputString = $this->getInputString($event)) {
  39675. return $this->logger->debug('The console exited with code "{code}"', array('code' => $exitCode));
  39676. }
  39677. $this->logger->debug('Command "{command}" exited with code "{code}"', array('command' => $inputString, 'code' => $exitCode));
  39678. }
  39679. public static function getSubscribedEvents()
  39680. {
  39681. return array(
  39682. ConsoleEvents::ERROR => array('onConsoleError', -128),
  39683. ConsoleEvents::TERMINATE => array('onConsoleTerminate', -128),
  39684. );
  39685. }
  39686. private static function getInputString(ConsoleEvent $event)
  39687. {
  39688. $commandName = $event->getCommand() ? $event->getCommand()->getName() : null;
  39689. $input = $event->getInput();
  39690. if (method_exists($input, '__toString')) {
  39691. if ($commandName) {
  39692. return str_replace(array("'$commandName'", "\"$commandName\""), $commandName, (string) $input);
  39693. }
  39694. return (string) $input;
  39695. }
  39696. return $commandName;
  39697. }
  39698. }
  39699. <?php
  39700. namespace Symfony\Component\Console\Exception;
  39701. class CommandNotFoundException extends \InvalidArgumentException implements ExceptionInterface
  39702. {
  39703. private $alternatives;
  39704. public function __construct($message, array $alternatives = array(), $code = 0, \Exception $previous = null)
  39705. {
  39706. parent::__construct($message, $code, $previous);
  39707. $this->alternatives = $alternatives;
  39708. }
  39709. public function getAlternatives()
  39710. {
  39711. return $this->alternatives;
  39712. }
  39713. }
  39714. <?php
  39715. namespace Symfony\Component\Console\Exception;
  39716. interface ExceptionInterface
  39717. {
  39718. }
  39719. <?php
  39720. namespace Symfony\Component\Console\Exception;
  39721. class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
  39722. {
  39723. }
  39724. <?php
  39725. namespace Symfony\Component\Console\Exception;
  39726. class InvalidOptionException extends \InvalidArgumentException implements ExceptionInterface
  39727. {
  39728. }
  39729. <?php
  39730. namespace Symfony\Component\Console\Exception;
  39731. class LogicException extends \LogicException implements ExceptionInterface
  39732. {
  39733. }
  39734. <?php
  39735. namespace Symfony\Component\Console\Exception;
  39736. class RuntimeException extends \RuntimeException implements ExceptionInterface
  39737. {
  39738. }
  39739. <?php
  39740. namespace Symfony\Component\Console\Formatter;
  39741. use Symfony\Component\Console\Exception\InvalidArgumentException;
  39742. class OutputFormatter implements OutputFormatterInterface
  39743. {
  39744. private $decorated;
  39745. private $styles = array();
  39746. private $styleStack;
  39747. public static function escape($text)
  39748. {
  39749. $text = preg_replace('/([^\\\\]?)</', '$1\\<', $text);
  39750. return self::escapeTrailingBackslash($text);
  39751. }
  39752. public static function escapeTrailingBackslash($text)
  39753. {
  39754. if ('\\' === substr($text, -1)) {
  39755. $len = strlen($text);
  39756. $text = rtrim($text, '\\');
  39757. $text = str_replace("\0", '', $text);
  39758. $text .= str_repeat("\0", $len - strlen($text));
  39759. }
  39760. return $text;
  39761. }
  39762. public function __construct($decorated = false, array $styles = array())
  39763. {
  39764. $this->decorated = (bool) $decorated;
  39765. $this->setStyle('error', new OutputFormatterStyle('white', 'red'));
  39766. $this->setStyle('info', new OutputFormatterStyle('green'));
  39767. $this->setStyle('comment', new OutputFormatterStyle('yellow'));
  39768. $this->setStyle('question', new OutputFormatterStyle('black', 'cyan'));
  39769. foreach ($styles as $name => $style) {
  39770. $this->setStyle($name, $style);
  39771. }
  39772. $this->styleStack = new OutputFormatterStyleStack();
  39773. }
  39774. public function setDecorated($decorated)
  39775. {
  39776. $this->decorated = (bool) $decorated;
  39777. }
  39778. public function isDecorated()
  39779. {
  39780. return $this->decorated;
  39781. }
  39782. public function setStyle($name, OutputFormatterStyleInterface $style)
  39783. {
  39784. $this->styles[strtolower($name)] = $style;
  39785. }
  39786. public function hasStyle($name)
  39787. {
  39788. return isset($this->styles[strtolower($name)]);
  39789. }
  39790. public function getStyle($name)
  39791. {
  39792. if (!$this->hasStyle($name)) {
  39793. throw new InvalidArgumentException(sprintf('Undefined style: %s', $name));
  39794. }
  39795. return $this->styles[strtolower($name)];
  39796. }
  39797. public function format($message)
  39798. {
  39799. $message = (string) $message;
  39800. $offset = 0;
  39801. $output = '';
  39802. $tagRegex = '[a-z][a-z0-9,_=;-]*+';
  39803. preg_match_all("#<(($tagRegex) | /($tagRegex)?)>#ix", $message, $matches, PREG_OFFSET_CAPTURE);
  39804. foreach ($matches[0] as $i => $match) {
  39805. $pos = $match[1];
  39806. $text = $match[0];
  39807. if (0 != $pos && '\\' == $message[$pos - 1]) {
  39808. continue;
  39809. }
  39810. $output .= $this->applyCurrentStyle(substr($message, $offset, $pos - $offset));
  39811. $offset = $pos + strlen($text);
  39812. if ($open = '/' != $text[1]) {
  39813. $tag = $matches[1][$i][0];
  39814. } else {
  39815. $tag = isset($matches[3][$i][0]) ? $matches[3][$i][0] : '';
  39816. }
  39817. if (!$open && !$tag) {
  39818. $this->styleStack->pop();
  39819. } elseif (false === $style = $this->createStyleFromString(strtolower($tag))) {
  39820. $output .= $this->applyCurrentStyle($text);
  39821. } elseif ($open) {
  39822. $this->styleStack->push($style);
  39823. } else {
  39824. $this->styleStack->pop($style);
  39825. }
  39826. }
  39827. $output .= $this->applyCurrentStyle(substr($message, $offset));
  39828. if (false !== strpos($output, "\0")) {
  39829. return strtr($output, array("\0" => '\\', '\\<' => '<'));
  39830. }
  39831. return str_replace('\\<', '<', $output);
  39832. }
  39833. public function getStyleStack()
  39834. {
  39835. return $this->styleStack;
  39836. }
  39837. private function createStyleFromString($string)
  39838. {
  39839. if (isset($this->styles[$string])) {
  39840. return $this->styles[$string];
  39841. }
  39842. if (!preg_match_all('/([^=]+)=([^;]+)(;|$)/', $string, $matches, PREG_SET_ORDER)) {
  39843. return false;
  39844. }
  39845. $style = new OutputFormatterStyle();
  39846. foreach ($matches as $match) {
  39847. array_shift($match);
  39848. if ('fg' == $match[0]) {
  39849. $style->setForeground($match[1]);
  39850. } elseif ('bg' == $match[0]) {
  39851. $style->setBackground($match[1]);
  39852. } elseif ('options' === $match[0]) {
  39853. preg_match_all('([^,;]+)', $match[1], $options);
  39854. $options = array_shift($options);
  39855. foreach ($options as $option) {
  39856. try {
  39857. $style->setOption($option);
  39858. } catch (\InvalidArgumentException $e) {
  39859. @trigger_error(sprintf('Unknown style options are deprecated since Symfony 3.2 and will be removed in 4.0. Exception "%s".', $e->getMessage()), E_USER_DEPRECATED);
  39860. return false;
  39861. }
  39862. }
  39863. } else {
  39864. return false;
  39865. }
  39866. }
  39867. return $style;
  39868. }
  39869. private function applyCurrentStyle($text)
  39870. {
  39871. return $this->isDecorated() && strlen($text) > 0 ? $this->styleStack->getCurrent()->apply($text) : $text;
  39872. }
  39873. }
  39874. <?php
  39875. namespace Symfony\Component\Console\Formatter;
  39876. interface OutputFormatterInterface
  39877. {
  39878. public function setDecorated($decorated);
  39879. public function isDecorated();
  39880. public function setStyle($name, OutputFormatterStyleInterface $style);
  39881. public function hasStyle($name);
  39882. public function getStyle($name);
  39883. public function format($message);
  39884. }
  39885. <?php
  39886. namespace Symfony\Component\Console\Formatter;
  39887. use Symfony\Component\Console\Exception\InvalidArgumentException;
  39888. class OutputFormatterStyle implements OutputFormatterStyleInterface
  39889. {
  39890. private static $availableForegroundColors = array(
  39891. 'black' => array('set' => 30, 'unset' => 39),
  39892. 'red' => array('set' => 31, 'unset' => 39),
  39893. 'green' => array('set' => 32, 'unset' => 39),
  39894. 'yellow' => array('set' => 33, 'unset' => 39),
  39895. 'blue' => array('set' => 34, 'unset' => 39),
  39896. 'magenta' => array('set' => 35, 'unset' => 39),
  39897. 'cyan' => array('set' => 36, 'unset' => 39),
  39898. 'white' => array('set' => 37, 'unset' => 39),
  39899. 'default' => array('set' => 39, 'unset' => 39),
  39900. );
  39901. private static $availableBackgroundColors = array(
  39902. 'black' => array('set' => 40, 'unset' => 49),
  39903. 'red' => array('set' => 41, 'unset' => 49),
  39904. 'green' => array('set' => 42, 'unset' => 49),
  39905. 'yellow' => array('set' => 43, 'unset' => 49),
  39906. 'blue' => array('set' => 44, 'unset' => 49),
  39907. 'magenta' => array('set' => 45, 'unset' => 49),
  39908. 'cyan' => array('set' => 46, 'unset' => 49),
  39909. 'white' => array('set' => 47, 'unset' => 49),
  39910. 'default' => array('set' => 49, 'unset' => 49),
  39911. );
  39912. private static $availableOptions = array(
  39913. 'bold' => array('set' => 1, 'unset' => 22),
  39914. 'underscore' => array('set' => 4, 'unset' => 24),
  39915. 'blink' => array('set' => 5, 'unset' => 25),
  39916. 'reverse' => array('set' => 7, 'unset' => 27),
  39917. 'conceal' => array('set' => 8, 'unset' => 28),
  39918. );
  39919. private $foreground;
  39920. private $background;
  39921. private $options = array();
  39922. public function __construct($foreground = null, $background = null, array $options = array())
  39923. {
  39924. if (null !== $foreground) {
  39925. $this->setForeground($foreground);
  39926. }
  39927. if (null !== $background) {
  39928. $this->setBackground($background);
  39929. }
  39930. if (count($options)) {
  39931. $this->setOptions($options);
  39932. }
  39933. }
  39934. public function setForeground($color = null)
  39935. {
  39936. if (null === $color) {
  39937. $this->foreground = null;
  39938. return;
  39939. }
  39940. if (!isset(static::$availableForegroundColors[$color])) {
  39941. throw new InvalidArgumentException(sprintf(
  39942. 'Invalid foreground color specified: "%s". Expected one of (%s)',
  39943. $color,
  39944. implode(', ', array_keys(static::$availableForegroundColors))
  39945. ));
  39946. }
  39947. $this->foreground = static::$availableForegroundColors[$color];
  39948. }
  39949. public function setBackground($color = null)
  39950. {
  39951. if (null === $color) {
  39952. $this->background = null;
  39953. return;
  39954. }
  39955. if (!isset(static::$availableBackgroundColors[$color])) {
  39956. throw new InvalidArgumentException(sprintf(
  39957. 'Invalid background color specified: "%s". Expected one of (%s)',
  39958. $color,
  39959. implode(', ', array_keys(static::$availableBackgroundColors))
  39960. ));
  39961. }
  39962. $this->background = static::$availableBackgroundColors[$color];
  39963. }
  39964. public function setOption($option)
  39965. {
  39966. if (!isset(static::$availableOptions[$option])) {
  39967. throw new InvalidArgumentException(sprintf(
  39968. 'Invalid option specified: "%s". Expected one of (%s)',
  39969. $option,
  39970. implode(', ', array_keys(static::$availableOptions))
  39971. ));
  39972. }
  39973. if (!in_array(static::$availableOptions[$option], $this->options)) {
  39974. $this->options[] = static::$availableOptions[$option];
  39975. }
  39976. }
  39977. public function unsetOption($option)
  39978. {
  39979. if (!isset(static::$availableOptions[$option])) {
  39980. throw new InvalidArgumentException(sprintf(
  39981. 'Invalid option specified: "%s". Expected one of (%s)',
  39982. $option,
  39983. implode(', ', array_keys(static::$availableOptions))
  39984. ));
  39985. }
  39986. $pos = array_search(static::$availableOptions[$option], $this->options);
  39987. if (false !== $pos) {
  39988. unset($this->options[$pos]);
  39989. }
  39990. }
  39991. public function setOptions(array $options)
  39992. {
  39993. $this->options = array();
  39994. foreach ($options as $option) {
  39995. $this->setOption($option);
  39996. }
  39997. }
  39998. public function apply($text)
  39999. {
  40000. $setCodes = array();
  40001. $unsetCodes = array();
  40002. if (null !== $this->foreground) {
  40003. $setCodes[] = $this->foreground['set'];
  40004. $unsetCodes[] = $this->foreground['unset'];
  40005. }
  40006. if (null !== $this->background) {
  40007. $setCodes[] = $this->background['set'];
  40008. $unsetCodes[] = $this->background['unset'];
  40009. }
  40010. if (count($this->options)) {
  40011. foreach ($this->options as $option) {
  40012. $setCodes[] = $option['set'];
  40013. $unsetCodes[] = $option['unset'];
  40014. }
  40015. }
  40016. if (0 === count($setCodes)) {
  40017. return $text;
  40018. }
  40019. return sprintf("\033[%sm%s\033[%sm", implode(';', $setCodes), $text, implode(';', $unsetCodes));
  40020. }
  40021. }
  40022. <?php
  40023. namespace Symfony\Component\Console\Formatter;
  40024. interface OutputFormatterStyleInterface
  40025. {
  40026. public function setForeground($color = null);
  40027. public function setBackground($color = null);
  40028. public function setOption($option);
  40029. public function unsetOption($option);
  40030. public function setOptions(array $options);
  40031. public function apply($text);
  40032. }
  40033. <?php
  40034. namespace Symfony\Component\Console\Formatter;
  40035. use Symfony\Component\Console\Exception\InvalidArgumentException;
  40036. class OutputFormatterStyleStack
  40037. {
  40038. private $styles;
  40039. private $emptyStyle;
  40040. public function __construct(OutputFormatterStyleInterface $emptyStyle = null)
  40041. {
  40042. $this->emptyStyle = $emptyStyle ?: new OutputFormatterStyle();
  40043. $this->reset();
  40044. }
  40045. public function reset()
  40046. {
  40047. $this->styles = array();
  40048. }
  40049. public function push(OutputFormatterStyleInterface $style)
  40050. {
  40051. $this->styles[] = $style;
  40052. }
  40053. public function pop(OutputFormatterStyleInterface $style = null)
  40054. {
  40055. if (empty($this->styles)) {
  40056. return $this->emptyStyle;
  40057. }
  40058. if (null === $style) {
  40059. return array_pop($this->styles);
  40060. }
  40061. foreach (array_reverse($this->styles, true) as $index => $stackedStyle) {
  40062. if ($style->apply('') === $stackedStyle->apply('')) {
  40063. $this->styles = array_slice($this->styles, 0, $index);
  40064. return $stackedStyle;
  40065. }
  40066. }
  40067. throw new InvalidArgumentException('Incorrectly nested style tag found.');
  40068. }
  40069. public function getCurrent()
  40070. {
  40071. if (empty($this->styles)) {
  40072. return $this->emptyStyle;
  40073. }
  40074. return $this->styles[count($this->styles) - 1];
  40075. }
  40076. public function setEmptyStyle(OutputFormatterStyleInterface $emptyStyle)
  40077. {
  40078. $this->emptyStyle = $emptyStyle;
  40079. return $this;
  40080. }
  40081. public function getEmptyStyle()
  40082. {
  40083. return $this->emptyStyle;
  40084. }
  40085. }
  40086. <?php
  40087. namespace Symfony\Component\Console\Helper;
  40088. class DebugFormatterHelper extends Helper
  40089. {
  40090. private $colors = array('black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'default');
  40091. private $started = array();
  40092. private $count = -1;
  40093. public function start($id, $message, $prefix = 'RUN')
  40094. {
  40095. $this->started[$id] = array('border' => ++$this->count % count($this->colors));
  40096. return sprintf("%s<bg=blue;fg=white> %s </> <fg=blue>%s</>\n", $this->getBorder($id), $prefix, $message);
  40097. }
  40098. public function progress($id, $buffer, $error = false, $prefix = 'OUT', $errorPrefix = 'ERR')
  40099. {
  40100. $message = '';
  40101. if ($error) {
  40102. if (isset($this->started[$id]['out'])) {
  40103. $message .= "\n";
  40104. unset($this->started[$id]['out']);
  40105. }
  40106. if (!isset($this->started[$id]['err'])) {
  40107. $message .= sprintf('%s<bg=red;fg=white> %s </> ', $this->getBorder($id), $errorPrefix);
  40108. $this->started[$id]['err'] = true;
  40109. }
  40110. $message .= str_replace("\n", sprintf("\n%s<bg=red;fg=white> %s </> ", $this->getBorder($id), $errorPrefix), $buffer);
  40111. } else {
  40112. if (isset($this->started[$id]['err'])) {
  40113. $message .= "\n";
  40114. unset($this->started[$id]['err']);
  40115. }
  40116. if (!isset($this->started[$id]['out'])) {
  40117. $message .= sprintf('%s<bg=green;fg=white> %s </> ', $this->getBorder($id), $prefix);
  40118. $this->started[$id]['out'] = true;
  40119. }
  40120. $message .= str_replace("\n", sprintf("\n%s<bg=green;fg=white> %s </> ", $this->getBorder($id), $prefix), $buffer);
  40121. }
  40122. return $message;
  40123. }
  40124. public function stop($id, $message, $successful, $prefix = 'RES')
  40125. {
  40126. $trailingEOL = isset($this->started[$id]['out']) || isset($this->started[$id]['err']) ? "\n" : '';
  40127. if ($successful) {
  40128. return sprintf("%s%s<bg=green;fg=white> %s </> <fg=green>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
  40129. }
  40130. $message = sprintf("%s%s<bg=red;fg=white> %s </> <fg=red>%s</>\n", $trailingEOL, $this->getBorder($id), $prefix, $message);
  40131. unset($this->started[$id]['out'], $this->started[$id]['err']);
  40132. return $message;
  40133. }
  40134. private function getBorder($id)
  40135. {
  40136. return sprintf('<bg=%s> </>', $this->colors[$this->started[$id]['border']]);
  40137. }
  40138. public function getName()
  40139. {
  40140. return 'debug_formatter';
  40141. }
  40142. }
  40143. <?php
  40144. namespace Symfony\Component\Console\Helper;
  40145. use Symfony\Component\Console\Descriptor\DescriptorInterface;
  40146. use Symfony\Component\Console\Descriptor\JsonDescriptor;
  40147. use Symfony\Component\Console\Descriptor\MarkdownDescriptor;
  40148. use Symfony\Component\Console\Descriptor\TextDescriptor;
  40149. use Symfony\Component\Console\Descriptor\XmlDescriptor;
  40150. use Symfony\Component\Console\Output\OutputInterface;
  40151. use Symfony\Component\Console\Exception\InvalidArgumentException;
  40152. class DescriptorHelper extends Helper
  40153. {
  40154. private $descriptors = array();
  40155. public function __construct()
  40156. {
  40157. $this
  40158. ->register('txt', new TextDescriptor())
  40159. ->register('xml', new XmlDescriptor())
  40160. ->register('json', new JsonDescriptor())
  40161. ->register('md', new MarkdownDescriptor())
  40162. ;
  40163. }
  40164. public function describe(OutputInterface $output, $object, array $options = array())
  40165. {
  40166. $options = array_merge(array(
  40167. 'raw_text' => false,
  40168. 'format' => 'txt',
  40169. ), $options);
  40170. if (!isset($this->descriptors[$options['format']])) {
  40171. throw new InvalidArgumentException(sprintf('Unsupported format "%s".', $options['format']));
  40172. }
  40173. $descriptor = $this->descriptors[$options['format']];
  40174. $descriptor->describe($output, $object, $options);
  40175. }
  40176. public function register($format, DescriptorInterface $descriptor)
  40177. {
  40178. $this->descriptors[$format] = $descriptor;
  40179. return $this;
  40180. }
  40181. public function getName()
  40182. {
  40183. return 'descriptor';
  40184. }
  40185. }
  40186. <?php
  40187. namespace Symfony\Component\Console\Helper;
  40188. use Symfony\Component\Console\Formatter\OutputFormatter;
  40189. class FormatterHelper extends Helper
  40190. {
  40191. public function formatSection($section, $message, $style = 'info')
  40192. {
  40193. return sprintf('<%s>[%s]</%s> %s', $style, $section, $style, $message);
  40194. }
  40195. public function formatBlock($messages, $style, $large = false)
  40196. {
  40197. if (!is_array($messages)) {
  40198. $messages = array($messages);
  40199. }
  40200. $len = 0;
  40201. $lines = array();
  40202. foreach ($messages as $message) {
  40203. $message = OutputFormatter::escape($message);
  40204. $lines[] = sprintf($large ? ' %s ' : ' %s ', $message);
  40205. $len = max($this->strlen($message) + ($large ? 4 : 2), $len);
  40206. }
  40207. $messages = $large ? array(str_repeat(' ', $len)) : array();
  40208. for ($i = 0; isset($lines[$i]); ++$i) {
  40209. $messages[] = $lines[$i].str_repeat(' ', $len - $this->strlen($lines[$i]));
  40210. }
  40211. if ($large) {
  40212. $messages[] = str_repeat(' ', $len);
  40213. }
  40214. for ($i = 0; isset($messages[$i]); ++$i) {
  40215. $messages[$i] = sprintf('<%s>%s</%s>', $style, $messages[$i], $style);
  40216. }
  40217. return implode("\n", $messages);
  40218. }
  40219. public function truncate($message, $length, $suffix = '...')
  40220. {
  40221. $computedLength = $length - $this->strlen($suffix);
  40222. if ($computedLength > $this->strlen($message)) {
  40223. return $message;
  40224. }
  40225. if (false === $encoding = mb_detect_encoding($message, null, true)) {
  40226. return substr($message, 0, $length).$suffix;
  40227. }
  40228. return mb_substr($message, 0, $length, $encoding).$suffix;
  40229. }
  40230. public function getName()
  40231. {
  40232. return 'formatter';
  40233. }
  40234. }
  40235. <?php
  40236. namespace Symfony\Component\Console\Helper;
  40237. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  40238. abstract class Helper implements HelperInterface
  40239. {
  40240. protected $helperSet = null;
  40241. public function setHelperSet(HelperSet $helperSet = null)
  40242. {
  40243. $this->helperSet = $helperSet;
  40244. }
  40245. public function getHelperSet()
  40246. {
  40247. return $this->helperSet;
  40248. }
  40249. public static function strlen($string)
  40250. {
  40251. if (false === $encoding = mb_detect_encoding($string, null, true)) {
  40252. return strlen($string);
  40253. }
  40254. return mb_strwidth($string, $encoding);
  40255. }
  40256. public static function substr($string, $from, $length = null)
  40257. {
  40258. if (false === $encoding = mb_detect_encoding($string, null, true)) {
  40259. return substr($string, $from, $length);
  40260. }
  40261. return mb_substr($string, $from, $length, $encoding);
  40262. }
  40263. public static function formatTime($secs)
  40264. {
  40265. static $timeFormats = array(
  40266. array(0, '< 1 sec'),
  40267. array(1, '1 sec'),
  40268. array(2, 'secs', 1),
  40269. array(60, '1 min'),
  40270. array(120, 'mins', 60),
  40271. array(3600, '1 hr'),
  40272. array(7200, 'hrs', 3600),
  40273. array(86400, '1 day'),
  40274. array(172800, 'days', 86400),
  40275. );
  40276. foreach ($timeFormats as $index => $format) {
  40277. if ($secs >= $format[0]) {
  40278. if ((isset($timeFormats[$index + 1]) && $secs < $timeFormats[$index + 1][0])
  40279. || $index == count($timeFormats) - 1
  40280. ) {
  40281. if (2 == count($format)) {
  40282. return $format[1];
  40283. }
  40284. return floor($secs / $format[2]).' '.$format[1];
  40285. }
  40286. }
  40287. }
  40288. }
  40289. public static function formatMemory($memory)
  40290. {
  40291. if ($memory >= 1024 * 1024 * 1024) {
  40292. return sprintf('%.1f GiB', $memory / 1024 / 1024 / 1024);
  40293. }
  40294. if ($memory >= 1024 * 1024) {
  40295. return sprintf('%.1f MiB', $memory / 1024 / 1024);
  40296. }
  40297. if ($memory >= 1024) {
  40298. return sprintf('%d KiB', $memory / 1024);
  40299. }
  40300. return sprintf('%d B', $memory);
  40301. }
  40302. public static function strlenWithoutDecoration(OutputFormatterInterface $formatter, $string)
  40303. {
  40304. return self::strlen(self::removeDecoration($formatter, $string));
  40305. }
  40306. public static function removeDecoration(OutputFormatterInterface $formatter, $string)
  40307. {
  40308. $isDecorated = $formatter->isDecorated();
  40309. $formatter->setDecorated(false);
  40310. $string = $formatter->format($string);
  40311. $string = preg_replace("/\033\[[^m]*m/", '', $string);
  40312. $formatter->setDecorated($isDecorated);
  40313. return $string;
  40314. }
  40315. }
  40316. <?php
  40317. namespace Symfony\Component\Console\Helper;
  40318. interface HelperInterface
  40319. {
  40320. public function setHelperSet(HelperSet $helperSet = null);
  40321. public function getHelperSet();
  40322. public function getName();
  40323. }
  40324. <?php
  40325. namespace Symfony\Component\Console\Helper;
  40326. use Symfony\Component\Console\Command\Command;
  40327. use Symfony\Component\Console\Exception\InvalidArgumentException;
  40328. class HelperSet implements \IteratorAggregate
  40329. {
  40330. private $helpers = array();
  40331. private $command;
  40332. public function __construct(array $helpers = array())
  40333. {
  40334. foreach ($helpers as $alias => $helper) {
  40335. $this->set($helper, is_int($alias) ? null : $alias);
  40336. }
  40337. }
  40338. public function set(HelperInterface $helper, $alias = null)
  40339. {
  40340. $this->helpers[$helper->getName()] = $helper;
  40341. if (null !== $alias) {
  40342. $this->helpers[$alias] = $helper;
  40343. }
  40344. $helper->setHelperSet($this);
  40345. }
  40346. public function has($name)
  40347. {
  40348. return isset($this->helpers[$name]);
  40349. }
  40350. public function get($name)
  40351. {
  40352. if (!$this->has($name)) {
  40353. throw new InvalidArgumentException(sprintf('The helper "%s" is not defined.', $name));
  40354. }
  40355. return $this->helpers[$name];
  40356. }
  40357. public function setCommand(Command $command = null)
  40358. {
  40359. $this->command = $command;
  40360. }
  40361. public function getCommand()
  40362. {
  40363. return $this->command;
  40364. }
  40365. public function getIterator()
  40366. {
  40367. return new \ArrayIterator($this->helpers);
  40368. }
  40369. }
  40370. <?php
  40371. namespace Symfony\Component\Console\Helper;
  40372. use Symfony\Component\Console\Input\InputInterface;
  40373. use Symfony\Component\Console\Input\InputAwareInterface;
  40374. abstract class InputAwareHelper extends Helper implements InputAwareInterface
  40375. {
  40376. protected $input;
  40377. public function setInput(InputInterface $input)
  40378. {
  40379. $this->input = $input;
  40380. }
  40381. }
  40382. <?php
  40383. namespace Symfony\Component\Console\Helper;
  40384. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  40385. use Symfony\Component\Console\Output\OutputInterface;
  40386. use Symfony\Component\Process\Exception\ProcessFailedException;
  40387. use Symfony\Component\Process\Process;
  40388. class ProcessHelper extends Helper
  40389. {
  40390. public function run(OutputInterface $output, $cmd, $error = null, callable $callback = null, $verbosity = OutputInterface::VERBOSITY_VERY_VERBOSE)
  40391. {
  40392. if ($output instanceof ConsoleOutputInterface) {
  40393. $output = $output->getErrorOutput();
  40394. }
  40395. $formatter = $this->getHelperSet()->get('debug_formatter');
  40396. if ($cmd instanceof Process) {
  40397. $process = $cmd;
  40398. } else {
  40399. $process = new Process($cmd);
  40400. }
  40401. if ($verbosity <= $output->getVerbosity()) {
  40402. $output->write($formatter->start(spl_object_hash($process), $this->escapeString($process->getCommandLine())));
  40403. }
  40404. if ($output->isDebug()) {
  40405. $callback = $this->wrapCallback($output, $process, $callback);
  40406. }
  40407. $process->run($callback);
  40408. if ($verbosity <= $output->getVerbosity()) {
  40409. $message = $process->isSuccessful() ? 'Command ran successfully' : sprintf('%s Command did not run successfully', $process->getExitCode());
  40410. $output->write($formatter->stop(spl_object_hash($process), $message, $process->isSuccessful()));
  40411. }
  40412. if (!$process->isSuccessful() && null !== $error) {
  40413. $output->writeln(sprintf('<error>%s</error>', $this->escapeString($error)));
  40414. }
  40415. return $process;
  40416. }
  40417. public function mustRun(OutputInterface $output, $cmd, $error = null, callable $callback = null)
  40418. {
  40419. $process = $this->run($output, $cmd, $error, $callback);
  40420. if (!$process->isSuccessful()) {
  40421. throw new ProcessFailedException($process);
  40422. }
  40423. return $process;
  40424. }
  40425. public function wrapCallback(OutputInterface $output, Process $process, callable $callback = null)
  40426. {
  40427. if ($output instanceof ConsoleOutputInterface) {
  40428. $output = $output->getErrorOutput();
  40429. }
  40430. $formatter = $this->getHelperSet()->get('debug_formatter');
  40431. return function ($type, $buffer) use ($output, $process, $callback, $formatter) {
  40432. $output->write($formatter->progress(spl_object_hash($process), $this->escapeString($buffer), Process::ERR === $type));
  40433. if (null !== $callback) {
  40434. call_user_func($callback, $type, $buffer);
  40435. }
  40436. };
  40437. }
  40438. private function escapeString($str)
  40439. {
  40440. return str_replace('<', '\\<', $str);
  40441. }
  40442. public function getName()
  40443. {
  40444. return 'process';
  40445. }
  40446. }
  40447. <?php
  40448. namespace Symfony\Component\Console\Helper;
  40449. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  40450. use Symfony\Component\Console\Output\OutputInterface;
  40451. use Symfony\Component\Console\Exception\LogicException;
  40452. use Symfony\Component\Console\Terminal;
  40453. final class ProgressBar
  40454. {
  40455. private $barWidth = 28;
  40456. private $barChar;
  40457. private $emptyBarChar = '-';
  40458. private $progressChar = '>';
  40459. private $format;
  40460. private $internalFormat;
  40461. private $redrawFreq = 1;
  40462. private $output;
  40463. private $step = 0;
  40464. private $max;
  40465. private $startTime;
  40466. private $stepWidth;
  40467. private $percent = 0.0;
  40468. private $formatLineCount;
  40469. private $messages = array();
  40470. private $overwrite = true;
  40471. private $terminal;
  40472. private $firstRun = true;
  40473. private static $formatters;
  40474. private static $formats;
  40475. public function __construct(OutputInterface $output, $max = 0)
  40476. {
  40477. if ($output instanceof ConsoleOutputInterface) {
  40478. $output = $output->getErrorOutput();
  40479. }
  40480. $this->output = $output;
  40481. $this->setMaxSteps($max);
  40482. $this->terminal = new Terminal();
  40483. if (!$this->output->isDecorated()) {
  40484. $this->overwrite = false;
  40485. $this->setRedrawFrequency($max / 10);
  40486. }
  40487. $this->startTime = time();
  40488. }
  40489. public static function setPlaceholderFormatterDefinition($name, callable $callable)
  40490. {
  40491. if (!self::$formatters) {
  40492. self::$formatters = self::initPlaceholderFormatters();
  40493. }
  40494. self::$formatters[$name] = $callable;
  40495. }
  40496. public static function getPlaceholderFormatterDefinition($name)
  40497. {
  40498. if (!self::$formatters) {
  40499. self::$formatters = self::initPlaceholderFormatters();
  40500. }
  40501. return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
  40502. }
  40503. public static function setFormatDefinition($name, $format)
  40504. {
  40505. if (!self::$formats) {
  40506. self::$formats = self::initFormats();
  40507. }
  40508. self::$formats[$name] = $format;
  40509. }
  40510. public static function getFormatDefinition($name)
  40511. {
  40512. if (!self::$formats) {
  40513. self::$formats = self::initFormats();
  40514. }
  40515. return isset(self::$formats[$name]) ? self::$formats[$name] : null;
  40516. }
  40517. public function setMessage($message, $name = 'message')
  40518. {
  40519. $this->messages[$name] = $message;
  40520. }
  40521. public function getMessage($name = 'message')
  40522. {
  40523. return $this->messages[$name];
  40524. }
  40525. public function getStartTime()
  40526. {
  40527. return $this->startTime;
  40528. }
  40529. public function getMaxSteps()
  40530. {
  40531. return $this->max;
  40532. }
  40533. public function getProgress()
  40534. {
  40535. return $this->step;
  40536. }
  40537. private function getStepWidth()
  40538. {
  40539. return $this->stepWidth;
  40540. }
  40541. public function getProgressPercent()
  40542. {
  40543. return $this->percent;
  40544. }
  40545. public function setBarWidth($size)
  40546. {
  40547. $this->barWidth = max(1, (int) $size);
  40548. }
  40549. public function getBarWidth()
  40550. {
  40551. return $this->barWidth;
  40552. }
  40553. public function setBarCharacter($char)
  40554. {
  40555. $this->barChar = $char;
  40556. }
  40557. public function getBarCharacter()
  40558. {
  40559. if (null === $this->barChar) {
  40560. return $this->max ? '=' : $this->emptyBarChar;
  40561. }
  40562. return $this->barChar;
  40563. }
  40564. public function setEmptyBarCharacter($char)
  40565. {
  40566. $this->emptyBarChar = $char;
  40567. }
  40568. public function getEmptyBarCharacter()
  40569. {
  40570. return $this->emptyBarChar;
  40571. }
  40572. public function setProgressCharacter($char)
  40573. {
  40574. $this->progressChar = $char;
  40575. }
  40576. public function getProgressCharacter()
  40577. {
  40578. return $this->progressChar;
  40579. }
  40580. public function setFormat($format)
  40581. {
  40582. $this->format = null;
  40583. $this->internalFormat = $format;
  40584. }
  40585. public function setRedrawFrequency($freq)
  40586. {
  40587. $this->redrawFreq = max((int) $freq, 1);
  40588. }
  40589. public function start($max = null)
  40590. {
  40591. $this->startTime = time();
  40592. $this->step = 0;
  40593. $this->percent = 0.0;
  40594. if (null !== $max) {
  40595. $this->setMaxSteps($max);
  40596. }
  40597. $this->display();
  40598. }
  40599. public function advance($step = 1)
  40600. {
  40601. $this->setProgress($this->step + $step);
  40602. }
  40603. public function setOverwrite($overwrite)
  40604. {
  40605. $this->overwrite = (bool) $overwrite;
  40606. }
  40607. public function setProgress($step)
  40608. {
  40609. $step = (int) $step;
  40610. if ($this->max && $step > $this->max) {
  40611. $this->max = $step;
  40612. } elseif ($step < 0) {
  40613. $step = 0;
  40614. }
  40615. $prevPeriod = (int) ($this->step / $this->redrawFreq);
  40616. $currPeriod = (int) ($step / $this->redrawFreq);
  40617. $this->step = $step;
  40618. $this->percent = $this->max ? (float) $this->step / $this->max : 0;
  40619. if ($prevPeriod !== $currPeriod || $this->max === $step) {
  40620. $this->display();
  40621. }
  40622. }
  40623. public function finish()
  40624. {
  40625. if (!$this->max) {
  40626. $this->max = $this->step;
  40627. }
  40628. if ($this->step === $this->max && !$this->overwrite) {
  40629. return;
  40630. }
  40631. $this->setProgress($this->max);
  40632. }
  40633. public function display()
  40634. {
  40635. if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
  40636. return;
  40637. }
  40638. if (null === $this->format) {
  40639. $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat());
  40640. }
  40641. $this->overwrite($this->buildLine());
  40642. }
  40643. public function clear()
  40644. {
  40645. if (!$this->overwrite) {
  40646. return;
  40647. }
  40648. if (null === $this->format) {
  40649. $this->setRealFormat($this->internalFormat ?: $this->determineBestFormat());
  40650. }
  40651. $this->overwrite('');
  40652. }
  40653. private function setRealFormat($format)
  40654. {
  40655. if (!$this->max && null !== self::getFormatDefinition($format.'_nomax')) {
  40656. $this->format = self::getFormatDefinition($format.'_nomax');
  40657. } elseif (null !== self::getFormatDefinition($format)) {
  40658. $this->format = self::getFormatDefinition($format);
  40659. } else {
  40660. $this->format = $format;
  40661. }
  40662. $this->formatLineCount = substr_count($this->format, "\n");
  40663. }
  40664. private function setMaxSteps($max)
  40665. {
  40666. $this->max = max(0, (int) $max);
  40667. $this->stepWidth = $this->max ? Helper::strlen($this->max) : 4;
  40668. }
  40669. private function overwrite($message)
  40670. {
  40671. if ($this->overwrite) {
  40672. if (!$this->firstRun) {
  40673. $this->output->write("\x0D");
  40674. $this->output->write("\x1B[2K");
  40675. if ($this->formatLineCount > 0) {
  40676. $this->output->write(str_repeat("\x1B[1A\x1B[2K", $this->formatLineCount));
  40677. }
  40678. }
  40679. } elseif ($this->step > 0) {
  40680. $this->output->writeln('');
  40681. }
  40682. $this->firstRun = false;
  40683. $this->output->write($message);
  40684. }
  40685. private function determineBestFormat()
  40686. {
  40687. switch ($this->output->getVerbosity()) {
  40688. case OutputInterface::VERBOSITY_VERBOSE:
  40689. return $this->max ? 'verbose' : 'verbose_nomax';
  40690. case OutputInterface::VERBOSITY_VERY_VERBOSE:
  40691. return $this->max ? 'very_verbose' : 'very_verbose_nomax';
  40692. case OutputInterface::VERBOSITY_DEBUG:
  40693. return $this->max ? 'debug' : 'debug_nomax';
  40694. default:
  40695. return $this->max ? 'normal' : 'normal_nomax';
  40696. }
  40697. }
  40698. private static function initPlaceholderFormatters()
  40699. {
  40700. return array(
  40701. 'bar' => function (ProgressBar $bar, OutputInterface $output) {
  40702. $completeBars = floor($bar->getMaxSteps() > 0 ? $bar->getProgressPercent() * $bar->getBarWidth() : $bar->getProgress() % $bar->getBarWidth());
  40703. $display = str_repeat($bar->getBarCharacter(), $completeBars);
  40704. if ($completeBars < $bar->getBarWidth()) {
  40705. $emptyBars = $bar->getBarWidth() - $completeBars - Helper::strlenWithoutDecoration($output->getFormatter(), $bar->getProgressCharacter());
  40706. $display .= $bar->getProgressCharacter().str_repeat($bar->getEmptyBarCharacter(), $emptyBars);
  40707. }
  40708. return $display;
  40709. },
  40710. 'elapsed' => function (ProgressBar $bar) {
  40711. return Helper::formatTime(time() - $bar->getStartTime());
  40712. },
  40713. 'remaining' => function (ProgressBar $bar) {
  40714. if (!$bar->getMaxSteps()) {
  40715. throw new LogicException('Unable to display the remaining time if the maximum number of steps is not set.');
  40716. }
  40717. if (!$bar->getProgress()) {
  40718. $remaining = 0;
  40719. } else {
  40720. $remaining = round((time() - $bar->getStartTime()) / $bar->getProgress() * ($bar->getMaxSteps() - $bar->getProgress()));
  40721. }
  40722. return Helper::formatTime($remaining);
  40723. },
  40724. 'estimated' => function (ProgressBar $bar) {
  40725. if (!$bar->getMaxSteps()) {
  40726. throw new LogicException('Unable to display the estimated time if the maximum number of steps is not set.');
  40727. }
  40728. if (!$bar->getProgress()) {
  40729. $estimated = 0;
  40730. } else {
  40731. $estimated = round((time() - $bar->getStartTime()) / $bar->getProgress() * $bar->getMaxSteps());
  40732. }
  40733. return Helper::formatTime($estimated);
  40734. },
  40735. 'memory' => function (ProgressBar $bar) {
  40736. return Helper::formatMemory(memory_get_usage(true));
  40737. },
  40738. 'current' => function (ProgressBar $bar) {
  40739. return str_pad($bar->getProgress(), $bar->getStepWidth(), ' ', STR_PAD_LEFT);
  40740. },
  40741. 'max' => function (ProgressBar $bar) {
  40742. return $bar->getMaxSteps();
  40743. },
  40744. 'percent' => function (ProgressBar $bar) {
  40745. return floor($bar->getProgressPercent() * 100);
  40746. },
  40747. );
  40748. }
  40749. private static function initFormats()
  40750. {
  40751. return array(
  40752. 'normal' => ' %current%/%max% [%bar%] %percent:3s%%',
  40753. 'normal_nomax' => ' %current% [%bar%]',
  40754. 'verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%',
  40755. 'verbose_nomax' => ' %current% [%bar%] %elapsed:6s%',
  40756. 'very_verbose' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s%',
  40757. 'very_verbose_nomax' => ' %current% [%bar%] %elapsed:6s%',
  40758. 'debug' => ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%',
  40759. 'debug_nomax' => ' %current% [%bar%] %elapsed:6s% %memory:6s%',
  40760. );
  40761. }
  40762. private function buildLine()
  40763. {
  40764. $regex = "{%([a-z\-_]+)(?:\:([^%]+))?%}i";
  40765. $callback = function ($matches) {
  40766. if ($formatter = $this::getPlaceholderFormatterDefinition($matches[1])) {
  40767. $text = call_user_func($formatter, $this, $this->output);
  40768. } elseif (isset($this->messages[$matches[1]])) {
  40769. $text = $this->messages[$matches[1]];
  40770. } else {
  40771. return $matches[0];
  40772. }
  40773. if (isset($matches[2])) {
  40774. $text = sprintf('%'.$matches[2], $text);
  40775. }
  40776. return $text;
  40777. };
  40778. $line = preg_replace_callback($regex, $callback, $this->format);
  40779. $linesLength = array_map(function ($subLine) {
  40780. return Helper::strlenWithoutDecoration($this->output->getFormatter(), rtrim($subLine, "\r"));
  40781. }, explode("\n", $line));
  40782. $linesWidth = max($linesLength);
  40783. $terminalWidth = $this->terminal->getWidth();
  40784. if ($linesWidth <= $terminalWidth) {
  40785. return $line;
  40786. }
  40787. $this->setBarWidth($this->barWidth - $linesWidth + $terminalWidth);
  40788. return preg_replace_callback($regex, $callback, $this->format);
  40789. }
  40790. }
  40791. <?php
  40792. namespace Symfony\Component\Console\Helper;
  40793. use Symfony\Component\Console\Exception\InvalidArgumentException;
  40794. use Symfony\Component\Console\Exception\LogicException;
  40795. use Symfony\Component\Console\Output\OutputInterface;
  40796. class ProgressIndicator
  40797. {
  40798. private $output;
  40799. private $startTime;
  40800. private $format;
  40801. private $message;
  40802. private $indicatorValues;
  40803. private $indicatorCurrent;
  40804. private $indicatorChangeInterval;
  40805. private $indicatorUpdateTime;
  40806. private $started = false;
  40807. private static $formatters;
  40808. private static $formats;
  40809. public function __construct(OutputInterface $output, $format = null, $indicatorChangeInterval = 100, $indicatorValues = null)
  40810. {
  40811. $this->output = $output;
  40812. if (null === $format) {
  40813. $format = $this->determineBestFormat();
  40814. }
  40815. if (null === $indicatorValues) {
  40816. $indicatorValues = array('-', '\\', '|', '/');
  40817. }
  40818. $indicatorValues = array_values($indicatorValues);
  40819. if (2 > count($indicatorValues)) {
  40820. throw new InvalidArgumentException('Must have at least 2 indicator value characters.');
  40821. }
  40822. $this->format = self::getFormatDefinition($format);
  40823. $this->indicatorChangeInterval = $indicatorChangeInterval;
  40824. $this->indicatorValues = $indicatorValues;
  40825. $this->startTime = time();
  40826. }
  40827. public function setMessage($message)
  40828. {
  40829. $this->message = $message;
  40830. $this->display();
  40831. }
  40832. public function start($message)
  40833. {
  40834. if ($this->started) {
  40835. throw new LogicException('Progress indicator already started.');
  40836. }
  40837. $this->message = $message;
  40838. $this->started = true;
  40839. $this->startTime = time();
  40840. $this->indicatorUpdateTime = $this->getCurrentTimeInMilliseconds() + $this->indicatorChangeInterval;
  40841. $this->indicatorCurrent = 0;
  40842. $this->display();
  40843. }
  40844. public function advance()
  40845. {
  40846. if (!$this->started) {
  40847. throw new LogicException('Progress indicator has not yet been started.');
  40848. }
  40849. if (!$this->output->isDecorated()) {
  40850. return;
  40851. }
  40852. $currentTime = $this->getCurrentTimeInMilliseconds();
  40853. if ($currentTime < $this->indicatorUpdateTime) {
  40854. return;
  40855. }
  40856. $this->indicatorUpdateTime = $currentTime + $this->indicatorChangeInterval;
  40857. ++$this->indicatorCurrent;
  40858. $this->display();
  40859. }
  40860. public function finish($message)
  40861. {
  40862. if (!$this->started) {
  40863. throw new LogicException('Progress indicator has not yet been started.');
  40864. }
  40865. $this->message = $message;
  40866. $this->display();
  40867. $this->output->writeln('');
  40868. $this->started = false;
  40869. }
  40870. public static function getFormatDefinition($name)
  40871. {
  40872. if (!self::$formats) {
  40873. self::$formats = self::initFormats();
  40874. }
  40875. return isset(self::$formats[$name]) ? self::$formats[$name] : null;
  40876. }
  40877. public static function setPlaceholderFormatterDefinition($name, $callable)
  40878. {
  40879. if (!self::$formatters) {
  40880. self::$formatters = self::initPlaceholderFormatters();
  40881. }
  40882. self::$formatters[$name] = $callable;
  40883. }
  40884. public static function getPlaceholderFormatterDefinition($name)
  40885. {
  40886. if (!self::$formatters) {
  40887. self::$formatters = self::initPlaceholderFormatters();
  40888. }
  40889. return isset(self::$formatters[$name]) ? self::$formatters[$name] : null;
  40890. }
  40891. private function display()
  40892. {
  40893. if (OutputInterface::VERBOSITY_QUIET === $this->output->getVerbosity()) {
  40894. return;
  40895. }
  40896. $self = $this;
  40897. $this->overwrite(preg_replace_callback("{%([a-z\-_]+)(?:\:([^%]+))?%}i", function ($matches) use ($self) {
  40898. if ($formatter = $self::getPlaceholderFormatterDefinition($matches[1])) {
  40899. return call_user_func($formatter, $self);
  40900. }
  40901. return $matches[0];
  40902. }, $this->format));
  40903. }
  40904. private function determineBestFormat()
  40905. {
  40906. switch ($this->output->getVerbosity()) {
  40907. case OutputInterface::VERBOSITY_VERBOSE:
  40908. return $this->output->isDecorated() ? 'verbose' : 'verbose_no_ansi';
  40909. case OutputInterface::VERBOSITY_VERY_VERBOSE:
  40910. case OutputInterface::VERBOSITY_DEBUG:
  40911. return $this->output->isDecorated() ? 'very_verbose' : 'very_verbose_no_ansi';
  40912. default:
  40913. return $this->output->isDecorated() ? 'normal' : 'normal_no_ansi';
  40914. }
  40915. }
  40916. private function overwrite($message)
  40917. {
  40918. if ($this->output->isDecorated()) {
  40919. $this->output->write("\x0D\x1B[2K");
  40920. $this->output->write($message);
  40921. } else {
  40922. $this->output->writeln($message);
  40923. }
  40924. }
  40925. private function getCurrentTimeInMilliseconds()
  40926. {
  40927. return round(microtime(true) * 1000);
  40928. }
  40929. private static function initPlaceholderFormatters()
  40930. {
  40931. return array(
  40932. 'indicator' => function (ProgressIndicator $indicator) {
  40933. return $indicator->indicatorValues[$indicator->indicatorCurrent % count($indicator->indicatorValues)];
  40934. },
  40935. 'message' => function (ProgressIndicator $indicator) {
  40936. return $indicator->message;
  40937. },
  40938. 'elapsed' => function (ProgressIndicator $indicator) {
  40939. return Helper::formatTime(time() - $indicator->startTime);
  40940. },
  40941. 'memory' => function () {
  40942. return Helper::formatMemory(memory_get_usage(true));
  40943. },
  40944. );
  40945. }
  40946. private static function initFormats()
  40947. {
  40948. return array(
  40949. 'normal' => ' %indicator% %message%',
  40950. 'normal_no_ansi' => ' %message%',
  40951. 'verbose' => ' %indicator% %message% (%elapsed:6s%)',
  40952. 'verbose_no_ansi' => ' %message% (%elapsed:6s%)',
  40953. 'very_verbose' => ' %indicator% %message% (%elapsed:6s%, %memory:6s%)',
  40954. 'very_verbose_no_ansi' => ' %message% (%elapsed:6s%, %memory:6s%)',
  40955. );
  40956. }
  40957. }
  40958. <?php
  40959. namespace Symfony\Component\Console\Helper;
  40960. use Symfony\Component\Console\Exception\InvalidArgumentException;
  40961. use Symfony\Component\Console\Exception\RuntimeException;
  40962. use Symfony\Component\Console\Formatter\OutputFormatter;
  40963. use Symfony\Component\Console\Formatter\OutputFormatterStyle;
  40964. use Symfony\Component\Console\Input\InputInterface;
  40965. use Symfony\Component\Console\Input\StreamableInputInterface;
  40966. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  40967. use Symfony\Component\Console\Output\OutputInterface;
  40968. use Symfony\Component\Console\Question\Question;
  40969. use Symfony\Component\Console\Question\ChoiceQuestion;
  40970. class QuestionHelper extends Helper
  40971. {
  40972. private $inputStream;
  40973. private static $shell;
  40974. private static $stty;
  40975. public function ask(InputInterface $input, OutputInterface $output, Question $question)
  40976. {
  40977. if ($output instanceof ConsoleOutputInterface) {
  40978. $output = $output->getErrorOutput();
  40979. }
  40980. if (!$input->isInteractive()) {
  40981. if ($question instanceof ChoiceQuestion) {
  40982. $choices = $question->getChoices();
  40983. return $choices[$question->getDefault()];
  40984. }
  40985. return $question->getDefault();
  40986. }
  40987. if ($input instanceof StreamableInputInterface && $stream = $input->getStream()) {
  40988. $this->inputStream = $stream;
  40989. }
  40990. if (!$question->getValidator()) {
  40991. return $this->doAsk($output, $question);
  40992. }
  40993. $interviewer = function () use ($output, $question) {
  40994. return $this->doAsk($output, $question);
  40995. };
  40996. return $this->validateAttempts($interviewer, $output, $question);
  40997. }
  40998. public function setInputStream($stream)
  40999. {
  41000. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use %s::setStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED);
  41001. if (!is_resource($stream)) {
  41002. throw new InvalidArgumentException('Input stream must be a valid resource.');
  41003. }
  41004. $this->inputStream = $stream;
  41005. }
  41006. public function getInputStream()
  41007. {
  41008. if (0 === func_num_args() || func_get_arg(0)) {
  41009. @trigger_error(sprintf('The %s() method is deprecated since Symfony 3.2 and will be removed in 4.0. Use %s::getStream() instead.', __METHOD__, StreamableInputInterface::class), E_USER_DEPRECATED);
  41010. }
  41011. return $this->inputStream;
  41012. }
  41013. public function getName()
  41014. {
  41015. return 'question';
  41016. }
  41017. public static function disableStty()
  41018. {
  41019. self::$stty = false;
  41020. }
  41021. private function doAsk(OutputInterface $output, Question $question)
  41022. {
  41023. $this->writePrompt($output, $question);
  41024. $inputStream = $this->inputStream ?: STDIN;
  41025. $autocomplete = $question->getAutocompleterValues();
  41026. if (null === $autocomplete || !$this->hasSttyAvailable()) {
  41027. $ret = false;
  41028. if ($question->isHidden()) {
  41029. try {
  41030. $ret = trim($this->getHiddenResponse($output, $inputStream));
  41031. } catch (RuntimeException $e) {
  41032. if (!$question->isHiddenFallback()) {
  41033. throw $e;
  41034. }
  41035. }
  41036. }
  41037. if (false === $ret) {
  41038. $ret = fgets($inputStream, 4096);
  41039. if (false === $ret) {
  41040. throw new RuntimeException('Aborted');
  41041. }
  41042. $ret = trim($ret);
  41043. }
  41044. } else {
  41045. $ret = trim($this->autocomplete($output, $question, $inputStream, is_array($autocomplete) ? $autocomplete : iterator_to_array($autocomplete, false)));
  41046. }
  41047. $ret = strlen($ret) > 0 ? $ret : $question->getDefault();
  41048. if ($normalizer = $question->getNormalizer()) {
  41049. return $normalizer($ret);
  41050. }
  41051. return $ret;
  41052. }
  41053. protected function writePrompt(OutputInterface $output, Question $question)
  41054. {
  41055. $message = $question->getQuestion();
  41056. if ($question instanceof ChoiceQuestion) {
  41057. $maxWidth = max(array_map(array($this, 'strlen'), array_keys($question->getChoices())));
  41058. $messages = (array) $question->getQuestion();
  41059. foreach ($question->getChoices() as $key => $value) {
  41060. $width = $maxWidth - $this->strlen($key);
  41061. $messages[] = ' [<info>'.$key.str_repeat(' ', $width).'</info>] '.$value;
  41062. }
  41063. $output->writeln($messages);
  41064. $message = $question->getPrompt();
  41065. }
  41066. $output->write($message);
  41067. }
  41068. protected function writeError(OutputInterface $output, \Exception $error)
  41069. {
  41070. if (null !== $this->getHelperSet() && $this->getHelperSet()->has('formatter')) {
  41071. $message = $this->getHelperSet()->get('formatter')->formatBlock($error->getMessage(), 'error');
  41072. } else {
  41073. $message = '<error>'.$error->getMessage().'</error>';
  41074. }
  41075. $output->writeln($message);
  41076. }
  41077. private function autocomplete(OutputInterface $output, Question $question, $inputStream, array $autocomplete)
  41078. {
  41079. $ret = '';
  41080. $i = 0;
  41081. $ofs = -1;
  41082. $matches = $autocomplete;
  41083. $numMatches = count($matches);
  41084. $sttyMode = shell_exec('stty -g');
  41085. shell_exec('stty -icanon -echo');
  41086. $output->getFormatter()->setStyle('hl', new OutputFormatterStyle('black', 'white'));
  41087. while (!feof($inputStream)) {
  41088. $c = fread($inputStream, 1);
  41089. if ("\177" === $c) {
  41090. if (0 === $numMatches && 0 !== $i) {
  41091. --$i;
  41092. $output->write("\033[1D");
  41093. }
  41094. if (0 === $i) {
  41095. $ofs = -1;
  41096. $matches = $autocomplete;
  41097. $numMatches = count($matches);
  41098. } else {
  41099. $numMatches = 0;
  41100. }
  41101. $ret = substr($ret, 0, $i);
  41102. } elseif ("\033" === $c) {
  41103. $c .= fread($inputStream, 2);
  41104. if (isset($c[2]) && ('A' === $c[2] || 'B' === $c[2])) {
  41105. if ('A' === $c[2] && -1 === $ofs) {
  41106. $ofs = 0;
  41107. }
  41108. if (0 === $numMatches) {
  41109. continue;
  41110. }
  41111. $ofs += ('A' === $c[2]) ? -1 : 1;
  41112. $ofs = ($numMatches + $ofs) % $numMatches;
  41113. }
  41114. } elseif (ord($c) < 32) {
  41115. if ("\t" === $c || "\n" === $c) {
  41116. if ($numMatches > 0 && -1 !== $ofs) {
  41117. $ret = $matches[$ofs];
  41118. $output->write(substr($ret, $i));
  41119. $i = strlen($ret);
  41120. }
  41121. if ("\n" === $c) {
  41122. $output->write($c);
  41123. break;
  41124. }
  41125. $numMatches = 0;
  41126. }
  41127. continue;
  41128. } else {
  41129. $output->write($c);
  41130. $ret .= $c;
  41131. ++$i;
  41132. $numMatches = 0;
  41133. $ofs = 0;
  41134. foreach ($autocomplete as $value) {
  41135. if (0 === strpos($value, $ret) && $i !== strlen($value)) {
  41136. $matches[$numMatches++] = $value;
  41137. }
  41138. }
  41139. }
  41140. $output->write("\033[K");
  41141. if ($numMatches > 0 && -1 !== $ofs) {
  41142. $output->write("\0337");
  41143. $output->write('<hl>'.OutputFormatter::escapeTrailingBackslash(substr($matches[$ofs], $i)).'</hl>');
  41144. $output->write("\0338");
  41145. }
  41146. }
  41147. shell_exec(sprintf('stty %s', $sttyMode));
  41148. return $ret;
  41149. }
  41150. private function getHiddenResponse(OutputInterface $output, $inputStream)
  41151. {
  41152. if ('\\' === DIRECTORY_SEPARATOR) {
  41153. $exe = __DIR__.'/../Resources/bin/hiddeninput.exe';
  41154. if ('phar:' === substr(__FILE__, 0, 5)) {
  41155. $tmpExe = sys_get_temp_dir().'/hiddeninput.exe';
  41156. copy($exe, $tmpExe);
  41157. $exe = $tmpExe;
  41158. }
  41159. $value = rtrim(shell_exec($exe));
  41160. $output->writeln('');
  41161. if (isset($tmpExe)) {
  41162. unlink($tmpExe);
  41163. }
  41164. return $value;
  41165. }
  41166. if ($this->hasSttyAvailable()) {
  41167. $sttyMode = shell_exec('stty -g');
  41168. shell_exec('stty -echo');
  41169. $value = fgets($inputStream, 4096);
  41170. shell_exec(sprintf('stty %s', $sttyMode));
  41171. if (false === $value) {
  41172. throw new RuntimeException('Aborted');
  41173. }
  41174. $value = trim($value);
  41175. $output->writeln('');
  41176. return $value;
  41177. }
  41178. if (false !== $shell = $this->getShell()) {
  41179. $readCmd = 'csh' === $shell ? 'set mypassword = $<' : 'read -r mypassword';
  41180. $command = sprintf("/usr/bin/env %s -c 'stty -echo; %s; stty echo; echo \$mypassword'", $shell, $readCmd);
  41181. $value = rtrim(shell_exec($command));
  41182. $output->writeln('');
  41183. return $value;
  41184. }
  41185. throw new RuntimeException('Unable to hide the response.');
  41186. }
  41187. private function validateAttempts(callable $interviewer, OutputInterface $output, Question $question)
  41188. {
  41189. $error = null;
  41190. $attempts = $question->getMaxAttempts();
  41191. while (null === $attempts || $attempts--) {
  41192. if (null !== $error) {
  41193. $this->writeError($output, $error);
  41194. }
  41195. try {
  41196. return call_user_func($question->getValidator(), $interviewer());
  41197. } catch (RuntimeException $e) {
  41198. throw $e;
  41199. } catch (\Exception $error) {
  41200. }
  41201. }
  41202. throw $error;
  41203. }
  41204. private function getShell()
  41205. {
  41206. if (null !== self::$shell) {
  41207. return self::$shell;
  41208. }
  41209. self::$shell = false;
  41210. if (file_exists('/usr/bin/env')) {
  41211. $test = "/usr/bin/env %s -c 'echo OK' 2> /dev/null";
  41212. foreach (array('bash', 'zsh', 'ksh', 'csh') as $sh) {
  41213. if ('OK' === rtrim(shell_exec(sprintf($test, $sh)))) {
  41214. self::$shell = $sh;
  41215. break;
  41216. }
  41217. }
  41218. }
  41219. return self::$shell;
  41220. }
  41221. private function hasSttyAvailable()
  41222. {
  41223. if (null !== self::$stty) {
  41224. return self::$stty;
  41225. }
  41226. exec('stty 2>&1', $output, $exitcode);
  41227. return self::$stty = 0 === $exitcode;
  41228. }
  41229. }
  41230. <?php
  41231. namespace Symfony\Component\Console\Helper;
  41232. use Symfony\Component\Console\Exception\LogicException;
  41233. use Symfony\Component\Console\Input\InputInterface;
  41234. use Symfony\Component\Console\Output\OutputInterface;
  41235. use Symfony\Component\Console\Question\ChoiceQuestion;
  41236. use Symfony\Component\Console\Question\ConfirmationQuestion;
  41237. use Symfony\Component\Console\Question\Question;
  41238. use Symfony\Component\Console\Style\SymfonyStyle;
  41239. use Symfony\Component\Console\Formatter\OutputFormatter;
  41240. class SymfonyQuestionHelper extends QuestionHelper
  41241. {
  41242. public function ask(InputInterface $input, OutputInterface $output, Question $question)
  41243. {
  41244. $validator = $question->getValidator();
  41245. $question->setValidator(function ($value) use ($validator) {
  41246. if (null !== $validator) {
  41247. $value = $validator($value);
  41248. } else {
  41249. if (!is_array($value) && !is_bool($value) && 0 === strlen($value)) {
  41250. @trigger_error('The default question validator is deprecated since Symfony 3.3 and will not be used anymore in version 4.0. Set a custom question validator if needed.', E_USER_DEPRECATED);
  41251. throw new LogicException('A value is required.');
  41252. }
  41253. }
  41254. return $value;
  41255. });
  41256. return parent::ask($input, $output, $question);
  41257. }
  41258. protected function writePrompt(OutputInterface $output, Question $question)
  41259. {
  41260. $text = OutputFormatter::escapeTrailingBackslash($question->getQuestion());
  41261. $default = $question->getDefault();
  41262. switch (true) {
  41263. case null === $default:
  41264. $text = sprintf(' <info>%s</info>:', $text);
  41265. break;
  41266. case $question instanceof ConfirmationQuestion:
  41267. $text = sprintf(' <info>%s (yes/no)</info> [<comment>%s</comment>]:', $text, $default ? 'yes' : 'no');
  41268. break;
  41269. case $question instanceof ChoiceQuestion && $question->isMultiselect():
  41270. $choices = $question->getChoices();
  41271. $default = explode(',', $default);
  41272. foreach ($default as $key => $value) {
  41273. $default[$key] = $choices[trim($value)];
  41274. }
  41275. $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape(implode(', ', $default)));
  41276. break;
  41277. case $question instanceof ChoiceQuestion:
  41278. $choices = $question->getChoices();
  41279. $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($choices[$default]));
  41280. break;
  41281. default:
  41282. $text = sprintf(' <info>%s</info> [<comment>%s</comment>]:', $text, OutputFormatter::escape($default));
  41283. }
  41284. $output->writeln($text);
  41285. if ($question instanceof ChoiceQuestion) {
  41286. $width = max(array_map('strlen', array_keys($question->getChoices())));
  41287. foreach ($question->getChoices() as $key => $value) {
  41288. $output->writeln(sprintf(" [<comment>%-${width}s</comment>] %s", $key, $value));
  41289. }
  41290. }
  41291. $output->write(' > ');
  41292. }
  41293. protected function writeError(OutputInterface $output, \Exception $error)
  41294. {
  41295. if ($output instanceof SymfonyStyle) {
  41296. $output->newLine();
  41297. $output->error($error->getMessage());
  41298. return;
  41299. }
  41300. parent::writeError($output, $error);
  41301. }
  41302. }
  41303. <?php
  41304. namespace Symfony\Component\Console\Helper;
  41305. use Symfony\Component\Console\Output\OutputInterface;
  41306. use Symfony\Component\Console\Exception\InvalidArgumentException;
  41307. class Table
  41308. {
  41309. private $headers = array();
  41310. private $rows = array();
  41311. private $effectiveColumnWidths = array();
  41312. private $numberOfColumns;
  41313. private $output;
  41314. private $style;
  41315. private $columnStyles = array();
  41316. private $columnWidths = array();
  41317. private static $styles;
  41318. public function __construct(OutputInterface $output)
  41319. {
  41320. $this->output = $output;
  41321. if (!self::$styles) {
  41322. self::$styles = self::initStyles();
  41323. }
  41324. $this->setStyle('default');
  41325. }
  41326. public static function setStyleDefinition($name, TableStyle $style)
  41327. {
  41328. if (!self::$styles) {
  41329. self::$styles = self::initStyles();
  41330. }
  41331. self::$styles[$name] = $style;
  41332. }
  41333. public static function getStyleDefinition($name)
  41334. {
  41335. if (!self::$styles) {
  41336. self::$styles = self::initStyles();
  41337. }
  41338. if (isset(self::$styles[$name])) {
  41339. return self::$styles[$name];
  41340. }
  41341. throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
  41342. }
  41343. public function setStyle($name)
  41344. {
  41345. $this->style = $this->resolveStyle($name);
  41346. return $this;
  41347. }
  41348. public function getStyle()
  41349. {
  41350. return $this->style;
  41351. }
  41352. public function setColumnStyle($columnIndex, $name)
  41353. {
  41354. $columnIndex = (int) $columnIndex;
  41355. $this->columnStyles[$columnIndex] = $this->resolveStyle($name);
  41356. return $this;
  41357. }
  41358. public function getColumnStyle($columnIndex)
  41359. {
  41360. if (isset($this->columnStyles[$columnIndex])) {
  41361. return $this->columnStyles[$columnIndex];
  41362. }
  41363. return $this->getStyle();
  41364. }
  41365. public function setColumnWidth($columnIndex, $width)
  41366. {
  41367. $this->columnWidths[(int) $columnIndex] = (int) $width;
  41368. return $this;
  41369. }
  41370. public function setColumnWidths(array $widths)
  41371. {
  41372. $this->columnWidths = array();
  41373. foreach ($widths as $index => $width) {
  41374. $this->setColumnWidth($index, $width);
  41375. }
  41376. return $this;
  41377. }
  41378. public function setHeaders(array $headers)
  41379. {
  41380. $headers = array_values($headers);
  41381. if (!empty($headers) && !is_array($headers[0])) {
  41382. $headers = array($headers);
  41383. }
  41384. $this->headers = $headers;
  41385. return $this;
  41386. }
  41387. public function setRows(array $rows)
  41388. {
  41389. $this->rows = array();
  41390. return $this->addRows($rows);
  41391. }
  41392. public function addRows(array $rows)
  41393. {
  41394. foreach ($rows as $row) {
  41395. $this->addRow($row);
  41396. }
  41397. return $this;
  41398. }
  41399. public function addRow($row)
  41400. {
  41401. if ($row instanceof TableSeparator) {
  41402. $this->rows[] = $row;
  41403. return $this;
  41404. }
  41405. if (!is_array($row)) {
  41406. throw new InvalidArgumentException('A row must be an array or a TableSeparator instance.');
  41407. }
  41408. $this->rows[] = array_values($row);
  41409. return $this;
  41410. }
  41411. public function setRow($column, array $row)
  41412. {
  41413. $this->rows[$column] = $row;
  41414. return $this;
  41415. }
  41416. public function render()
  41417. {
  41418. $this->calculateNumberOfColumns();
  41419. $rows = $this->buildTableRows($this->rows);
  41420. $headers = $this->buildTableRows($this->headers);
  41421. $this->calculateColumnsWidth(array_merge($headers, $rows));
  41422. $this->renderRowSeparator();
  41423. if (!empty($headers)) {
  41424. foreach ($headers as $header) {
  41425. $this->renderRow($header, $this->style->getCellHeaderFormat());
  41426. $this->renderRowSeparator();
  41427. }
  41428. }
  41429. foreach ($rows as $row) {
  41430. if ($row instanceof TableSeparator) {
  41431. $this->renderRowSeparator();
  41432. } else {
  41433. $this->renderRow($row, $this->style->getCellRowFormat());
  41434. }
  41435. }
  41436. if (!empty($rows)) {
  41437. $this->renderRowSeparator();
  41438. }
  41439. $this->cleanup();
  41440. }
  41441. private function renderRowSeparator()
  41442. {
  41443. if (0 === $count = $this->numberOfColumns) {
  41444. return;
  41445. }
  41446. if (!$this->style->getHorizontalBorderChar() && !$this->style->getCrossingChar()) {
  41447. return;
  41448. }
  41449. $markup = $this->style->getCrossingChar();
  41450. for ($column = 0; $column < $count; ++$column) {
  41451. $markup .= str_repeat($this->style->getHorizontalBorderChar(), $this->effectiveColumnWidths[$column]).$this->style->getCrossingChar();
  41452. }
  41453. $this->output->writeln(sprintf($this->style->getBorderFormat(), $markup));
  41454. }
  41455. private function renderColumnSeparator()
  41456. {
  41457. return sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar());
  41458. }
  41459. private function renderRow(array $row, $cellFormat)
  41460. {
  41461. if (empty($row)) {
  41462. return;
  41463. }
  41464. $rowContent = $this->renderColumnSeparator();
  41465. foreach ($this->getRowColumns($row) as $column) {
  41466. $rowContent .= $this->renderCell($row, $column, $cellFormat);
  41467. $rowContent .= $this->renderColumnSeparator();
  41468. }
  41469. $this->output->writeln($rowContent);
  41470. }
  41471. private function renderCell(array $row, $column, $cellFormat)
  41472. {
  41473. $cell = isset($row[$column]) ? $row[$column] : '';
  41474. $width = $this->effectiveColumnWidths[$column];
  41475. if ($cell instanceof TableCell && $cell->getColspan() > 1) {
  41476. foreach (range($column + 1, $column + $cell->getColspan() - 1) as $nextColumn) {
  41477. $width += $this->getColumnSeparatorWidth() + $this->effectiveColumnWidths[$nextColumn];
  41478. }
  41479. }
  41480. if (false !== $encoding = mb_detect_encoding($cell, null, true)) {
  41481. $width += strlen($cell) - mb_strwidth($cell, $encoding);
  41482. }
  41483. $style = $this->getColumnStyle($column);
  41484. if ($cell instanceof TableSeparator) {
  41485. return sprintf($style->getBorderFormat(), str_repeat($style->getHorizontalBorderChar(), $width));
  41486. }
  41487. $width += Helper::strlen($cell) - Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
  41488. $content = sprintf($style->getCellRowContentFormat(), $cell);
  41489. return sprintf($cellFormat, str_pad($content, $width, $style->getPaddingChar(), $style->getPadType()));
  41490. }
  41491. private function calculateNumberOfColumns()
  41492. {
  41493. if (null !== $this->numberOfColumns) {
  41494. return;
  41495. }
  41496. $columns = array(0);
  41497. foreach (array_merge($this->headers, $this->rows) as $row) {
  41498. if ($row instanceof TableSeparator) {
  41499. continue;
  41500. }
  41501. $columns[] = $this->getNumberOfColumns($row);
  41502. }
  41503. $this->numberOfColumns = max($columns);
  41504. }
  41505. private function buildTableRows($rows)
  41506. {
  41507. $unmergedRows = array();
  41508. for ($rowKey = 0; $rowKey < count($rows); ++$rowKey) {
  41509. $rows = $this->fillNextRows($rows, $rowKey);
  41510. foreach ($rows[$rowKey] as $column => $cell) {
  41511. if (!strstr($cell, "\n")) {
  41512. continue;
  41513. }
  41514. $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
  41515. foreach ($lines as $lineKey => $line) {
  41516. if ($cell instanceof TableCell) {
  41517. $line = new TableCell($line, array('colspan' => $cell->getColspan()));
  41518. }
  41519. if (0 === $lineKey) {
  41520. $rows[$rowKey][$column] = $line;
  41521. } else {
  41522. $unmergedRows[$rowKey][$lineKey][$column] = $line;
  41523. }
  41524. }
  41525. }
  41526. }
  41527. $tableRows = array();
  41528. foreach ($rows as $rowKey => $row) {
  41529. $tableRows[] = $this->fillCells($row);
  41530. if (isset($unmergedRows[$rowKey])) {
  41531. $tableRows = array_merge($tableRows, $unmergedRows[$rowKey]);
  41532. }
  41533. }
  41534. return $tableRows;
  41535. }
  41536. private function fillNextRows(array $rows, $line)
  41537. {
  41538. $unmergedRows = array();
  41539. foreach ($rows[$line] as $column => $cell) {
  41540. if ($cell instanceof TableCell && $cell->getRowspan() > 1) {
  41541. $nbLines = $cell->getRowspan() - 1;
  41542. $lines = array($cell);
  41543. if (strstr($cell, "\n")) {
  41544. $lines = explode("\n", str_replace("\n", "<fg=default;bg=default>\n</>", $cell));
  41545. $nbLines = count($lines) > $nbLines ? substr_count($cell, "\n") : $nbLines;
  41546. $rows[$line][$column] = new TableCell($lines[0], array('colspan' => $cell->getColspan()));
  41547. unset($lines[0]);
  41548. }
  41549. $unmergedRows = array_replace_recursive(array_fill($line + 1, $nbLines, array()), $unmergedRows);
  41550. foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
  41551. $value = isset($lines[$unmergedRowKey - $line]) ? $lines[$unmergedRowKey - $line] : '';
  41552. $unmergedRows[$unmergedRowKey][$column] = new TableCell($value, array('colspan' => $cell->getColspan()));
  41553. if ($nbLines === $unmergedRowKey - $line) {
  41554. break;
  41555. }
  41556. }
  41557. }
  41558. }
  41559. foreach ($unmergedRows as $unmergedRowKey => $unmergedRow) {
  41560. if (isset($rows[$unmergedRowKey]) && is_array($rows[$unmergedRowKey]) && ($this->getNumberOfColumns($rows[$unmergedRowKey]) + $this->getNumberOfColumns($unmergedRows[$unmergedRowKey]) <= $this->numberOfColumns)) {
  41561. foreach ($unmergedRow as $cellKey => $cell) {
  41562. array_splice($rows[$unmergedRowKey], $cellKey, 0, array($cell));
  41563. }
  41564. } else {
  41565. $row = $this->copyRow($rows, $unmergedRowKey - 1);
  41566. foreach ($unmergedRow as $column => $cell) {
  41567. if (!empty($cell)) {
  41568. $row[$column] = $unmergedRow[$column];
  41569. }
  41570. }
  41571. array_splice($rows, $unmergedRowKey, 0, array($row));
  41572. }
  41573. }
  41574. return $rows;
  41575. }
  41576. private function fillCells($row)
  41577. {
  41578. $newRow = array();
  41579. foreach ($row as $column => $cell) {
  41580. $newRow[] = $cell;
  41581. if ($cell instanceof TableCell && $cell->getColspan() > 1) {
  41582. foreach (range($column + 1, $column + $cell->getColspan() - 1) as $position) {
  41583. $newRow[] = '';
  41584. }
  41585. }
  41586. }
  41587. return $newRow ?: $row;
  41588. }
  41589. private function copyRow(array $rows, $line)
  41590. {
  41591. $row = $rows[$line];
  41592. foreach ($row as $cellKey => $cellValue) {
  41593. $row[$cellKey] = '';
  41594. if ($cellValue instanceof TableCell) {
  41595. $row[$cellKey] = new TableCell('', array('colspan' => $cellValue->getColspan()));
  41596. }
  41597. }
  41598. return $row;
  41599. }
  41600. private function getNumberOfColumns(array $row)
  41601. {
  41602. $columns = count($row);
  41603. foreach ($row as $column) {
  41604. $columns += $column instanceof TableCell ? ($column->getColspan() - 1) : 0;
  41605. }
  41606. return $columns;
  41607. }
  41608. private function getRowColumns(array $row)
  41609. {
  41610. $columns = range(0, $this->numberOfColumns - 1);
  41611. foreach ($row as $cellKey => $cell) {
  41612. if ($cell instanceof TableCell && $cell->getColspan() > 1) {
  41613. $columns = array_diff($columns, range($cellKey + 1, $cellKey + $cell->getColspan() - 1));
  41614. }
  41615. }
  41616. return $columns;
  41617. }
  41618. private function calculateColumnsWidth(array $rows)
  41619. {
  41620. for ($column = 0; $column < $this->numberOfColumns; ++$column) {
  41621. $lengths = array();
  41622. foreach ($rows as $row) {
  41623. if ($row instanceof TableSeparator) {
  41624. continue;
  41625. }
  41626. foreach ($row as $i => $cell) {
  41627. if ($cell instanceof TableCell) {
  41628. $textContent = Helper::removeDecoration($this->output->getFormatter(), $cell);
  41629. $textLength = Helper::strlen($textContent);
  41630. if ($textLength > 0) {
  41631. $contentColumns = str_split($textContent, ceil($textLength / $cell->getColspan()));
  41632. foreach ($contentColumns as $position => $content) {
  41633. $row[$i + $position] = $content;
  41634. }
  41635. }
  41636. }
  41637. }
  41638. $lengths[] = $this->getCellWidth($row, $column);
  41639. }
  41640. $this->effectiveColumnWidths[$column] = max($lengths) + strlen($this->style->getCellRowContentFormat()) - 2;
  41641. }
  41642. }
  41643. private function getColumnSeparatorWidth()
  41644. {
  41645. return strlen(sprintf($this->style->getBorderFormat(), $this->style->getVerticalBorderChar()));
  41646. }
  41647. private function getCellWidth(array $row, $column)
  41648. {
  41649. $cellWidth = 0;
  41650. if (isset($row[$column])) {
  41651. $cell = $row[$column];
  41652. $cellWidth = Helper::strlenWithoutDecoration($this->output->getFormatter(), $cell);
  41653. }
  41654. $columnWidth = isset($this->columnWidths[$column]) ? $this->columnWidths[$column] : 0;
  41655. return max($cellWidth, $columnWidth);
  41656. }
  41657. private function cleanup()
  41658. {
  41659. $this->effectiveColumnWidths = array();
  41660. $this->numberOfColumns = null;
  41661. }
  41662. private static function initStyles()
  41663. {
  41664. $borderless = new TableStyle();
  41665. $borderless
  41666. ->setHorizontalBorderChar('=')
  41667. ->setVerticalBorderChar(' ')
  41668. ->setCrossingChar(' ')
  41669. ;
  41670. $compact = new TableStyle();
  41671. $compact
  41672. ->setHorizontalBorderChar('')
  41673. ->setVerticalBorderChar(' ')
  41674. ->setCrossingChar('')
  41675. ->setCellRowContentFormat('%s')
  41676. ;
  41677. $styleGuide = new TableStyle();
  41678. $styleGuide
  41679. ->setHorizontalBorderChar('-')
  41680. ->setVerticalBorderChar(' ')
  41681. ->setCrossingChar(' ')
  41682. ->setCellHeaderFormat('%s')
  41683. ;
  41684. return array(
  41685. 'default' => new TableStyle(),
  41686. 'borderless' => $borderless,
  41687. 'compact' => $compact,
  41688. 'symfony-style-guide' => $styleGuide,
  41689. );
  41690. }
  41691. private function resolveStyle($name)
  41692. {
  41693. if ($name instanceof TableStyle) {
  41694. return $name;
  41695. }
  41696. if (isset(self::$styles[$name])) {
  41697. return self::$styles[$name];
  41698. }
  41699. throw new InvalidArgumentException(sprintf('Style "%s" is not defined.', $name));
  41700. }
  41701. }
  41702. <?php
  41703. namespace Symfony\Component\Console\Helper;
  41704. use Symfony\Component\Console\Exception\InvalidArgumentException;
  41705. class TableCell
  41706. {
  41707. private $value;
  41708. private $options = array(
  41709. 'rowspan' => 1,
  41710. 'colspan' => 1,
  41711. );
  41712. public function __construct($value = '', array $options = array())
  41713. {
  41714. if (is_numeric($value) && !is_string($value)) {
  41715. $value = (string) $value;
  41716. }
  41717. $this->value = $value;
  41718. if ($diff = array_diff(array_keys($options), array_keys($this->options))) {
  41719. throw new InvalidArgumentException(sprintf('The TableCell does not support the following options: \'%s\'.', implode('\', \'', $diff)));
  41720. }
  41721. $this->options = array_merge($this->options, $options);
  41722. }
  41723. public function __toString()
  41724. {
  41725. return $this->value;
  41726. }
  41727. public function getColspan()
  41728. {
  41729. return (int) $this->options['colspan'];
  41730. }
  41731. public function getRowspan()
  41732. {
  41733. return (int) $this->options['rowspan'];
  41734. }
  41735. }
  41736. <?php
  41737. namespace Symfony\Component\Console\Helper;
  41738. class TableSeparator extends TableCell
  41739. {
  41740. public function __construct(array $options = array())
  41741. {
  41742. parent::__construct('', $options);
  41743. }
  41744. }
  41745. <?php
  41746. namespace Symfony\Component\Console\Helper;
  41747. use Symfony\Component\Console\Exception\InvalidArgumentException;
  41748. use Symfony\Component\Console\Exception\LogicException;
  41749. class TableStyle
  41750. {
  41751. private $paddingChar = ' ';
  41752. private $horizontalBorderChar = '-';
  41753. private $verticalBorderChar = '|';
  41754. private $crossingChar = '+';
  41755. private $cellHeaderFormat = '<info>%s</info>';
  41756. private $cellRowFormat = '%s';
  41757. private $cellRowContentFormat = ' %s ';
  41758. private $borderFormat = '%s';
  41759. private $padType = STR_PAD_RIGHT;
  41760. public function setPaddingChar($paddingChar)
  41761. {
  41762. if (!$paddingChar) {
  41763. throw new LogicException('The padding char must not be empty');
  41764. }
  41765. $this->paddingChar = $paddingChar;
  41766. return $this;
  41767. }
  41768. public function getPaddingChar()
  41769. {
  41770. return $this->paddingChar;
  41771. }
  41772. public function setHorizontalBorderChar($horizontalBorderChar)
  41773. {
  41774. $this->horizontalBorderChar = $horizontalBorderChar;
  41775. return $this;
  41776. }
  41777. public function getHorizontalBorderChar()
  41778. {
  41779. return $this->horizontalBorderChar;
  41780. }
  41781. public function setVerticalBorderChar($verticalBorderChar)
  41782. {
  41783. $this->verticalBorderChar = $verticalBorderChar;
  41784. return $this;
  41785. }
  41786. public function getVerticalBorderChar()
  41787. {
  41788. return $this->verticalBorderChar;
  41789. }
  41790. public function setCrossingChar($crossingChar)
  41791. {
  41792. $this->crossingChar = $crossingChar;
  41793. return $this;
  41794. }
  41795. public function getCrossingChar()
  41796. {
  41797. return $this->crossingChar;
  41798. }
  41799. public function setCellHeaderFormat($cellHeaderFormat)
  41800. {
  41801. $this->cellHeaderFormat = $cellHeaderFormat;
  41802. return $this;
  41803. }
  41804. public function getCellHeaderFormat()
  41805. {
  41806. return $this->cellHeaderFormat;
  41807. }
  41808. public function setCellRowFormat($cellRowFormat)
  41809. {
  41810. $this->cellRowFormat = $cellRowFormat;
  41811. return $this;
  41812. }
  41813. public function getCellRowFormat()
  41814. {
  41815. return $this->cellRowFormat;
  41816. }
  41817. public function setCellRowContentFormat($cellRowContentFormat)
  41818. {
  41819. $this->cellRowContentFormat = $cellRowContentFormat;
  41820. return $this;
  41821. }
  41822. public function getCellRowContentFormat()
  41823. {
  41824. return $this->cellRowContentFormat;
  41825. }
  41826. public function setBorderFormat($borderFormat)
  41827. {
  41828. $this->borderFormat = $borderFormat;
  41829. return $this;
  41830. }
  41831. public function getBorderFormat()
  41832. {
  41833. return $this->borderFormat;
  41834. }
  41835. public function setPadType($padType)
  41836. {
  41837. if (!in_array($padType, array(STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH), true)) {
  41838. throw new InvalidArgumentException('Invalid padding type. Expected one of (STR_PAD_LEFT, STR_PAD_RIGHT, STR_PAD_BOTH).');
  41839. }
  41840. $this->padType = $padType;
  41841. return $this;
  41842. }
  41843. public function getPadType()
  41844. {
  41845. return $this->padType;
  41846. }
  41847. }
  41848. <?php
  41849. namespace Symfony\Component\Console\Input;
  41850. use Symfony\Component\Console\Exception\RuntimeException;
  41851. class ArgvInput extends Input
  41852. {
  41853. private $tokens;
  41854. private $parsed;
  41855. public function __construct(array $argv = null, InputDefinition $definition = null)
  41856. {
  41857. if (null === $argv) {
  41858. $argv = $_SERVER['argv'];
  41859. }
  41860. array_shift($argv);
  41861. $this->tokens = $argv;
  41862. parent::__construct($definition);
  41863. }
  41864. protected function setTokens(array $tokens)
  41865. {
  41866. $this->tokens = $tokens;
  41867. }
  41868. protected function parse()
  41869. {
  41870. $parseOptions = true;
  41871. $this->parsed = $this->tokens;
  41872. while (null !== $token = array_shift($this->parsed)) {
  41873. if ($parseOptions && '' == $token) {
  41874. $this->parseArgument($token);
  41875. } elseif ($parseOptions && '--' == $token) {
  41876. $parseOptions = false;
  41877. } elseif ($parseOptions && 0 === strpos($token, '--')) {
  41878. $this->parseLongOption($token);
  41879. } elseif ($parseOptions && '-' === $token[0] && '-' !== $token) {
  41880. $this->parseShortOption($token);
  41881. } else {
  41882. $this->parseArgument($token);
  41883. }
  41884. }
  41885. }
  41886. private function parseShortOption($token)
  41887. {
  41888. $name = substr($token, 1);
  41889. if (strlen($name) > 1) {
  41890. if ($this->definition->hasShortcut($name[0]) && $this->definition->getOptionForShortcut($name[0])->acceptValue()) {
  41891. $this->addShortOption($name[0], substr($name, 1));
  41892. } else {
  41893. $this->parseShortOptionSet($name);
  41894. }
  41895. } else {
  41896. $this->addShortOption($name, null);
  41897. }
  41898. }
  41899. private function parseShortOptionSet($name)
  41900. {
  41901. $len = strlen($name);
  41902. for ($i = 0; $i < $len; ++$i) {
  41903. if (!$this->definition->hasShortcut($name[$i])) {
  41904. throw new RuntimeException(sprintf('The "-%s" option does not exist.', $name[$i]));
  41905. }
  41906. $option = $this->definition->getOptionForShortcut($name[$i]);
  41907. if ($option->acceptValue()) {
  41908. $this->addLongOption($option->getName(), $i === $len - 1 ? null : substr($name, $i + 1));
  41909. break;
  41910. } else {
  41911. $this->addLongOption($option->getName(), null);
  41912. }
  41913. }
  41914. }
  41915. private function parseLongOption($token)
  41916. {
  41917. $name = substr($token, 2);
  41918. if (false !== $pos = strpos($name, '=')) {
  41919. if (0 === strlen($value = substr($name, $pos + 1))) {
  41920. if (\PHP_VERSION_ID < 70000 && false === $value) {
  41921. $value = '';
  41922. }
  41923. array_unshift($this->parsed, $value);
  41924. }
  41925. $this->addLongOption(substr($name, 0, $pos), $value);
  41926. } else {
  41927. $this->addLongOption($name, null);
  41928. }
  41929. }
  41930. private function parseArgument($token)
  41931. {
  41932. $c = count($this->arguments);
  41933. if ($this->definition->hasArgument($c)) {
  41934. $arg = $this->definition->getArgument($c);
  41935. $this->arguments[$arg->getName()] = $arg->isArray() ? array($token) : $token;
  41936. } elseif ($this->definition->hasArgument($c - 1) && $this->definition->getArgument($c - 1)->isArray()) {
  41937. $arg = $this->definition->getArgument($c - 1);
  41938. $this->arguments[$arg->getName()][] = $token;
  41939. } else {
  41940. $all = $this->definition->getArguments();
  41941. if (count($all)) {
  41942. throw new RuntimeException(sprintf('Too many arguments, expected arguments "%s".', implode('" "', array_keys($all))));
  41943. }
  41944. throw new RuntimeException(sprintf('No arguments expected, got "%s".', $token));
  41945. }
  41946. }
  41947. private function addShortOption($shortcut, $value)
  41948. {
  41949. if (!$this->definition->hasShortcut($shortcut)) {
  41950. throw new RuntimeException(sprintf('The "-%s" option does not exist.', $shortcut));
  41951. }
  41952. $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
  41953. }
  41954. private function addLongOption($name, $value)
  41955. {
  41956. if (!$this->definition->hasOption($name)) {
  41957. throw new RuntimeException(sprintf('The "--%s" option does not exist.', $name));
  41958. }
  41959. $option = $this->definition->getOption($name);
  41960. if (null !== $value && !$option->acceptValue()) {
  41961. throw new RuntimeException(sprintf('The "--%s" option does not accept a value.', $name));
  41962. }
  41963. if (in_array($value, array('', null), true) && $option->acceptValue() && count($this->parsed)) {
  41964. $next = array_shift($this->parsed);
  41965. if ((isset($next[0]) && '-' !== $next[0]) || in_array($next, array('', null), true)) {
  41966. $value = $next;
  41967. } else {
  41968. array_unshift($this->parsed, $next);
  41969. }
  41970. }
  41971. if (null === $value) {
  41972. if ($option->isValueRequired()) {
  41973. throw new RuntimeException(sprintf('The "--%s" option requires a value.', $name));
  41974. }
  41975. if (!$option->isArray() && !$option->isValueOptional()) {
  41976. $value = true;
  41977. }
  41978. }
  41979. if ($option->isArray()) {
  41980. $this->options[$name][] = $value;
  41981. } else {
  41982. $this->options[$name] = $value;
  41983. }
  41984. }
  41985. public function getFirstArgument()
  41986. {
  41987. foreach ($this->tokens as $token) {
  41988. if ($token && '-' === $token[0]) {
  41989. continue;
  41990. }
  41991. return $token;
  41992. }
  41993. }
  41994. public function hasParameterOption($values, $onlyParams = false)
  41995. {
  41996. $values = (array) $values;
  41997. foreach ($this->tokens as $token) {
  41998. if ($onlyParams && '--' === $token) {
  41999. return false;
  42000. }
  42001. foreach ($values as $value) {
  42002. if ($token === $value || 0 === strpos($token, $value.'=')) {
  42003. return true;
  42004. }
  42005. if (0 === strpos($token, '-') && 0 !== strpos($token, '--')) {
  42006. $noValue = explode('=', $token);
  42007. $token = $noValue[0];
  42008. $searchableToken = str_replace('-', '', $token);
  42009. $searchableValue = str_replace('-', '', $value);
  42010. if ('' !== $searchableToken && '' !== $searchableValue && false !== strpos($searchableToken, $searchableValue)) {
  42011. return true;
  42012. }
  42013. }
  42014. }
  42015. }
  42016. return false;
  42017. }
  42018. public function getParameterOption($values, $default = false, $onlyParams = false)
  42019. {
  42020. $values = (array) $values;
  42021. $tokens = $this->tokens;
  42022. while (0 < count($tokens)) {
  42023. $token = array_shift($tokens);
  42024. if ($onlyParams && '--' === $token) {
  42025. return false;
  42026. }
  42027. foreach ($values as $value) {
  42028. if ($token === $value || 0 === strpos($token, $value.'=')) {
  42029. if (false !== $pos = strpos($token, '=')) {
  42030. return substr($token, $pos + 1);
  42031. }
  42032. return array_shift($tokens);
  42033. }
  42034. }
  42035. }
  42036. return $default;
  42037. }
  42038. public function __toString()
  42039. {
  42040. $tokens = array_map(function ($token) {
  42041. if (preg_match('{^(-[^=]+=)(.+)}', $token, $match)) {
  42042. return $match[1].$this->escapeToken($match[2]);
  42043. }
  42044. if ($token && '-' !== $token[0]) {
  42045. return $this->escapeToken($token);
  42046. }
  42047. return $token;
  42048. }, $this->tokens);
  42049. return implode(' ', $tokens);
  42050. }
  42051. }
  42052. <?php
  42053. namespace Symfony\Component\Console\Input;
  42054. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42055. use Symfony\Component\Console\Exception\InvalidOptionException;
  42056. class ArrayInput extends Input
  42057. {
  42058. private $parameters;
  42059. public function __construct(array $parameters, InputDefinition $definition = null)
  42060. {
  42061. $this->parameters = $parameters;
  42062. parent::__construct($definition);
  42063. }
  42064. public function getFirstArgument()
  42065. {
  42066. foreach ($this->parameters as $key => $value) {
  42067. if ($key && '-' === $key[0]) {
  42068. continue;
  42069. }
  42070. return $value;
  42071. }
  42072. }
  42073. public function hasParameterOption($values, $onlyParams = false)
  42074. {
  42075. $values = (array) $values;
  42076. foreach ($this->parameters as $k => $v) {
  42077. if (!is_int($k)) {
  42078. $v = $k;
  42079. }
  42080. if ($onlyParams && '--' === $v) {
  42081. return false;
  42082. }
  42083. if (in_array($v, $values)) {
  42084. return true;
  42085. }
  42086. }
  42087. return false;
  42088. }
  42089. public function getParameterOption($values, $default = false, $onlyParams = false)
  42090. {
  42091. $values = (array) $values;
  42092. foreach ($this->parameters as $k => $v) {
  42093. if ($onlyParams && ('--' === $k || (is_int($k) && '--' === $v))) {
  42094. return false;
  42095. }
  42096. if (is_int($k)) {
  42097. if (in_array($v, $values)) {
  42098. return true;
  42099. }
  42100. } elseif (in_array($k, $values)) {
  42101. return $v;
  42102. }
  42103. }
  42104. return $default;
  42105. }
  42106. public function __toString()
  42107. {
  42108. $params = array();
  42109. foreach ($this->parameters as $param => $val) {
  42110. if ($param && '-' === $param[0]) {
  42111. if (is_array($val)) {
  42112. foreach ($val as $v) {
  42113. $params[] = $param.('' != $v ? '='.$this->escapeToken($v) : '');
  42114. }
  42115. } else {
  42116. $params[] = $param.('' != $val ? '='.$this->escapeToken($val) : '');
  42117. }
  42118. } else {
  42119. $params[] = is_array($val) ? array_map(array($this, 'escapeToken'), $val) : $this->escapeToken($val);
  42120. }
  42121. }
  42122. return implode(' ', $params);
  42123. }
  42124. protected function parse()
  42125. {
  42126. foreach ($this->parameters as $key => $value) {
  42127. if ('--' === $key) {
  42128. return;
  42129. }
  42130. if (0 === strpos($key, '--')) {
  42131. $this->addLongOption(substr($key, 2), $value);
  42132. } elseif ('-' === $key[0]) {
  42133. $this->addShortOption(substr($key, 1), $value);
  42134. } else {
  42135. $this->addArgument($key, $value);
  42136. }
  42137. }
  42138. }
  42139. private function addShortOption($shortcut, $value)
  42140. {
  42141. if (!$this->definition->hasShortcut($shortcut)) {
  42142. throw new InvalidOptionException(sprintf('The "-%s" option does not exist.', $shortcut));
  42143. }
  42144. $this->addLongOption($this->definition->getOptionForShortcut($shortcut)->getName(), $value);
  42145. }
  42146. private function addLongOption($name, $value)
  42147. {
  42148. if (!$this->definition->hasOption($name)) {
  42149. throw new InvalidOptionException(sprintf('The "--%s" option does not exist.', $name));
  42150. }
  42151. $option = $this->definition->getOption($name);
  42152. if (null === $value) {
  42153. if ($option->isValueRequired()) {
  42154. throw new InvalidOptionException(sprintf('The "--%s" option requires a value.', $name));
  42155. }
  42156. if (!$option->isValueOptional()) {
  42157. $value = true;
  42158. }
  42159. }
  42160. $this->options[$name] = $value;
  42161. }
  42162. private function addArgument($name, $value)
  42163. {
  42164. if (!$this->definition->hasArgument($name)) {
  42165. throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  42166. }
  42167. $this->arguments[$name] = $value;
  42168. }
  42169. }
  42170. <?php
  42171. namespace Symfony\Component\Console\Input;
  42172. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42173. use Symfony\Component\Console\Exception\RuntimeException;
  42174. abstract class Input implements InputInterface, StreamableInputInterface
  42175. {
  42176. protected $definition;
  42177. protected $stream;
  42178. protected $options = array();
  42179. protected $arguments = array();
  42180. protected $interactive = true;
  42181. public function __construct(InputDefinition $definition = null)
  42182. {
  42183. if (null === $definition) {
  42184. $this->definition = new InputDefinition();
  42185. } else {
  42186. $this->bind($definition);
  42187. $this->validate();
  42188. }
  42189. }
  42190. public function bind(InputDefinition $definition)
  42191. {
  42192. $this->arguments = array();
  42193. $this->options = array();
  42194. $this->definition = $definition;
  42195. $this->parse();
  42196. }
  42197. abstract protected function parse();
  42198. public function validate()
  42199. {
  42200. $definition = $this->definition;
  42201. $givenArguments = $this->arguments;
  42202. $missingArguments = array_filter(array_keys($definition->getArguments()), function ($argument) use ($definition, $givenArguments) {
  42203. return !array_key_exists($argument, $givenArguments) && $definition->getArgument($argument)->isRequired();
  42204. });
  42205. if (count($missingArguments) > 0) {
  42206. throw new RuntimeException(sprintf('Not enough arguments (missing: "%s").', implode(', ', $missingArguments)));
  42207. }
  42208. }
  42209. public function isInteractive()
  42210. {
  42211. return $this->interactive;
  42212. }
  42213. public function setInteractive($interactive)
  42214. {
  42215. $this->interactive = (bool) $interactive;
  42216. }
  42217. public function getArguments()
  42218. {
  42219. return array_merge($this->definition->getArgumentDefaults(), $this->arguments);
  42220. }
  42221. public function getArgument($name)
  42222. {
  42223. if (!$this->definition->hasArgument($name)) {
  42224. throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  42225. }
  42226. return isset($this->arguments[$name]) ? $this->arguments[$name] : $this->definition->getArgument($name)->getDefault();
  42227. }
  42228. public function setArgument($name, $value)
  42229. {
  42230. if (!$this->definition->hasArgument($name)) {
  42231. throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  42232. }
  42233. $this->arguments[$name] = $value;
  42234. }
  42235. public function hasArgument($name)
  42236. {
  42237. return $this->definition->hasArgument($name);
  42238. }
  42239. public function getOptions()
  42240. {
  42241. return array_merge($this->definition->getOptionDefaults(), $this->options);
  42242. }
  42243. public function getOption($name)
  42244. {
  42245. if (!$this->definition->hasOption($name)) {
  42246. throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
  42247. }
  42248. return array_key_exists($name, $this->options) ? $this->options[$name] : $this->definition->getOption($name)->getDefault();
  42249. }
  42250. public function setOption($name, $value)
  42251. {
  42252. if (!$this->definition->hasOption($name)) {
  42253. throw new InvalidArgumentException(sprintf('The "%s" option does not exist.', $name));
  42254. }
  42255. $this->options[$name] = $value;
  42256. }
  42257. public function hasOption($name)
  42258. {
  42259. return $this->definition->hasOption($name);
  42260. }
  42261. public function escapeToken($token)
  42262. {
  42263. return preg_match('{^[\w-]+$}', $token) ? $token : escapeshellarg($token);
  42264. }
  42265. public function setStream($stream)
  42266. {
  42267. $this->stream = $stream;
  42268. }
  42269. public function getStream()
  42270. {
  42271. return $this->stream;
  42272. }
  42273. }
  42274. <?php
  42275. namespace Symfony\Component\Console\Input;
  42276. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42277. use Symfony\Component\Console\Exception\LogicException;
  42278. class InputArgument
  42279. {
  42280. const REQUIRED = 1;
  42281. const OPTIONAL = 2;
  42282. const IS_ARRAY = 4;
  42283. private $name;
  42284. private $mode;
  42285. private $default;
  42286. private $description;
  42287. public function __construct($name, $mode = null, $description = '', $default = null)
  42288. {
  42289. if (null === $mode) {
  42290. $mode = self::OPTIONAL;
  42291. } elseif (!is_int($mode) || $mode > 7 || $mode < 1) {
  42292. throw new InvalidArgumentException(sprintf('Argument mode "%s" is not valid.', $mode));
  42293. }
  42294. $this->name = $name;
  42295. $this->mode = $mode;
  42296. $this->description = $description;
  42297. $this->setDefault($default);
  42298. }
  42299. public function getName()
  42300. {
  42301. return $this->name;
  42302. }
  42303. public function isRequired()
  42304. {
  42305. return self::REQUIRED === (self::REQUIRED & $this->mode);
  42306. }
  42307. public function isArray()
  42308. {
  42309. return self::IS_ARRAY === (self::IS_ARRAY & $this->mode);
  42310. }
  42311. public function setDefault($default = null)
  42312. {
  42313. if (self::REQUIRED === $this->mode && null !== $default) {
  42314. throw new LogicException('Cannot set a default value except for InputArgument::OPTIONAL mode.');
  42315. }
  42316. if ($this->isArray()) {
  42317. if (null === $default) {
  42318. $default = array();
  42319. } elseif (!is_array($default)) {
  42320. throw new LogicException('A default value for an array argument must be an array.');
  42321. }
  42322. }
  42323. $this->default = $default;
  42324. }
  42325. public function getDefault()
  42326. {
  42327. return $this->default;
  42328. }
  42329. public function getDescription()
  42330. {
  42331. return $this->description;
  42332. }
  42333. }
  42334. <?php
  42335. namespace Symfony\Component\Console\Input;
  42336. interface InputAwareInterface
  42337. {
  42338. public function setInput(InputInterface $input);
  42339. }
  42340. <?php
  42341. namespace Symfony\Component\Console\Input;
  42342. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42343. use Symfony\Component\Console\Exception\LogicException;
  42344. class InputDefinition
  42345. {
  42346. private $arguments;
  42347. private $requiredCount;
  42348. private $hasAnArrayArgument = false;
  42349. private $hasOptional;
  42350. private $options;
  42351. private $shortcuts;
  42352. public function __construct(array $definition = array())
  42353. {
  42354. $this->setDefinition($definition);
  42355. }
  42356. public function setDefinition(array $definition)
  42357. {
  42358. $arguments = array();
  42359. $options = array();
  42360. foreach ($definition as $item) {
  42361. if ($item instanceof InputOption) {
  42362. $options[] = $item;
  42363. } else {
  42364. $arguments[] = $item;
  42365. }
  42366. }
  42367. $this->setArguments($arguments);
  42368. $this->setOptions($options);
  42369. }
  42370. public function setArguments($arguments = array())
  42371. {
  42372. $this->arguments = array();
  42373. $this->requiredCount = 0;
  42374. $this->hasOptional = false;
  42375. $this->hasAnArrayArgument = false;
  42376. $this->addArguments($arguments);
  42377. }
  42378. public function addArguments($arguments = array())
  42379. {
  42380. if (null !== $arguments) {
  42381. foreach ($arguments as $argument) {
  42382. $this->addArgument($argument);
  42383. }
  42384. }
  42385. }
  42386. public function addArgument(InputArgument $argument)
  42387. {
  42388. if (isset($this->arguments[$argument->getName()])) {
  42389. throw new LogicException(sprintf('An argument with name "%s" already exists.', $argument->getName()));
  42390. }
  42391. if ($this->hasAnArrayArgument) {
  42392. throw new LogicException('Cannot add an argument after an array argument.');
  42393. }
  42394. if ($argument->isRequired() && $this->hasOptional) {
  42395. throw new LogicException('Cannot add a required argument after an optional one.');
  42396. }
  42397. if ($argument->isArray()) {
  42398. $this->hasAnArrayArgument = true;
  42399. }
  42400. if ($argument->isRequired()) {
  42401. ++$this->requiredCount;
  42402. } else {
  42403. $this->hasOptional = true;
  42404. }
  42405. $this->arguments[$argument->getName()] = $argument;
  42406. }
  42407. public function getArgument($name)
  42408. {
  42409. if (!$this->hasArgument($name)) {
  42410. throw new InvalidArgumentException(sprintf('The "%s" argument does not exist.', $name));
  42411. }
  42412. $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
  42413. return $arguments[$name];
  42414. }
  42415. public function hasArgument($name)
  42416. {
  42417. $arguments = is_int($name) ? array_values($this->arguments) : $this->arguments;
  42418. return isset($arguments[$name]);
  42419. }
  42420. public function getArguments()
  42421. {
  42422. return $this->arguments;
  42423. }
  42424. public function getArgumentCount()
  42425. {
  42426. return $this->hasAnArrayArgument ? PHP_INT_MAX : count($this->arguments);
  42427. }
  42428. public function getArgumentRequiredCount()
  42429. {
  42430. return $this->requiredCount;
  42431. }
  42432. public function getArgumentDefaults()
  42433. {
  42434. $values = array();
  42435. foreach ($this->arguments as $argument) {
  42436. $values[$argument->getName()] = $argument->getDefault();
  42437. }
  42438. return $values;
  42439. }
  42440. public function setOptions($options = array())
  42441. {
  42442. $this->options = array();
  42443. $this->shortcuts = array();
  42444. $this->addOptions($options);
  42445. }
  42446. public function addOptions($options = array())
  42447. {
  42448. foreach ($options as $option) {
  42449. $this->addOption($option);
  42450. }
  42451. }
  42452. public function addOption(InputOption $option)
  42453. {
  42454. if (isset($this->options[$option->getName()]) && !$option->equals($this->options[$option->getName()])) {
  42455. throw new LogicException(sprintf('An option named "%s" already exists.', $option->getName()));
  42456. }
  42457. if ($option->getShortcut()) {
  42458. foreach (explode('|', $option->getShortcut()) as $shortcut) {
  42459. if (isset($this->shortcuts[$shortcut]) && !$option->equals($this->options[$this->shortcuts[$shortcut]])) {
  42460. throw new LogicException(sprintf('An option with shortcut "%s" already exists.', $shortcut));
  42461. }
  42462. }
  42463. }
  42464. $this->options[$option->getName()] = $option;
  42465. if ($option->getShortcut()) {
  42466. foreach (explode('|', $option->getShortcut()) as $shortcut) {
  42467. $this->shortcuts[$shortcut] = $option->getName();
  42468. }
  42469. }
  42470. }
  42471. public function getOption($name)
  42472. {
  42473. if (!$this->hasOption($name)) {
  42474. throw new InvalidArgumentException(sprintf('The "--%s" option does not exist.', $name));
  42475. }
  42476. return $this->options[$name];
  42477. }
  42478. public function hasOption($name)
  42479. {
  42480. return isset($this->options[$name]);
  42481. }
  42482. public function getOptions()
  42483. {
  42484. return $this->options;
  42485. }
  42486. public function hasShortcut($name)
  42487. {
  42488. return isset($this->shortcuts[$name]);
  42489. }
  42490. public function getOptionForShortcut($shortcut)
  42491. {
  42492. return $this->getOption($this->shortcutToName($shortcut));
  42493. }
  42494. public function getOptionDefaults()
  42495. {
  42496. $values = array();
  42497. foreach ($this->options as $option) {
  42498. $values[$option->getName()] = $option->getDefault();
  42499. }
  42500. return $values;
  42501. }
  42502. private function shortcutToName($shortcut)
  42503. {
  42504. if (!isset($this->shortcuts[$shortcut])) {
  42505. throw new InvalidArgumentException(sprintf('The "-%s" option does not exist.', $shortcut));
  42506. }
  42507. return $this->shortcuts[$shortcut];
  42508. }
  42509. public function getSynopsis($short = false)
  42510. {
  42511. $elements = array();
  42512. if ($short && $this->getOptions()) {
  42513. $elements[] = '[options]';
  42514. } elseif (!$short) {
  42515. foreach ($this->getOptions() as $option) {
  42516. $value = '';
  42517. if ($option->acceptValue()) {
  42518. $value = sprintf(
  42519. ' %s%s%s',
  42520. $option->isValueOptional() ? '[' : '',
  42521. strtoupper($option->getName()),
  42522. $option->isValueOptional() ? ']' : ''
  42523. );
  42524. }
  42525. $shortcut = $option->getShortcut() ? sprintf('-%s|', $option->getShortcut()) : '';
  42526. $elements[] = sprintf('[%s--%s%s]', $shortcut, $option->getName(), $value);
  42527. }
  42528. }
  42529. if (count($elements) && $this->getArguments()) {
  42530. $elements[] = '[--]';
  42531. }
  42532. foreach ($this->getArguments() as $argument) {
  42533. $element = '<'.$argument->getName().'>';
  42534. if (!$argument->isRequired()) {
  42535. $element = '['.$element.']';
  42536. } elseif ($argument->isArray()) {
  42537. $element = $element.' ('.$element.')';
  42538. }
  42539. if ($argument->isArray()) {
  42540. $element .= '...';
  42541. }
  42542. $elements[] = $element;
  42543. }
  42544. return implode(' ', $elements);
  42545. }
  42546. }
  42547. <?php
  42548. namespace Symfony\Component\Console\Input;
  42549. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42550. use Symfony\Component\Console\Exception\RuntimeException;
  42551. interface InputInterface
  42552. {
  42553. public function getFirstArgument();
  42554. public function hasParameterOption($values, $onlyParams = false);
  42555. public function getParameterOption($values, $default = false, $onlyParams = false);
  42556. public function bind(InputDefinition $definition);
  42557. public function validate();
  42558. public function getArguments();
  42559. public function getArgument($name);
  42560. public function setArgument($name, $value);
  42561. public function hasArgument($name);
  42562. public function getOptions();
  42563. public function getOption($name);
  42564. public function setOption($name, $value);
  42565. public function hasOption($name);
  42566. public function isInteractive();
  42567. public function setInteractive($interactive);
  42568. }
  42569. <?php
  42570. namespace Symfony\Component\Console\Input;
  42571. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42572. use Symfony\Component\Console\Exception\LogicException;
  42573. class InputOption
  42574. {
  42575. const VALUE_NONE = 1;
  42576. const VALUE_REQUIRED = 2;
  42577. const VALUE_OPTIONAL = 4;
  42578. const VALUE_IS_ARRAY = 8;
  42579. private $name;
  42580. private $shortcut;
  42581. private $mode;
  42582. private $default;
  42583. private $description;
  42584. public function __construct($name, $shortcut = null, $mode = null, $description = '', $default = null)
  42585. {
  42586. if (0 === strpos($name, '--')) {
  42587. $name = substr($name, 2);
  42588. }
  42589. if (empty($name)) {
  42590. throw new InvalidArgumentException('An option name cannot be empty.');
  42591. }
  42592. if (empty($shortcut)) {
  42593. $shortcut = null;
  42594. }
  42595. if (null !== $shortcut) {
  42596. if (is_array($shortcut)) {
  42597. $shortcut = implode('|', $shortcut);
  42598. }
  42599. $shortcuts = preg_split('{(\|)-?}', ltrim($shortcut, '-'));
  42600. $shortcuts = array_filter($shortcuts);
  42601. $shortcut = implode('|', $shortcuts);
  42602. if (empty($shortcut)) {
  42603. throw new InvalidArgumentException('An option shortcut cannot be empty.');
  42604. }
  42605. }
  42606. if (null === $mode) {
  42607. $mode = self::VALUE_NONE;
  42608. } elseif (!is_int($mode) || $mode > 15 || $mode < 1) {
  42609. throw new InvalidArgumentException(sprintf('Option mode "%s" is not valid.', $mode));
  42610. }
  42611. $this->name = $name;
  42612. $this->shortcut = $shortcut;
  42613. $this->mode = $mode;
  42614. $this->description = $description;
  42615. if ($this->isArray() && !$this->acceptValue()) {
  42616. throw new InvalidArgumentException('Impossible to have an option mode VALUE_IS_ARRAY if the option does not accept a value.');
  42617. }
  42618. $this->setDefault($default);
  42619. }
  42620. public function getShortcut()
  42621. {
  42622. return $this->shortcut;
  42623. }
  42624. public function getName()
  42625. {
  42626. return $this->name;
  42627. }
  42628. public function acceptValue()
  42629. {
  42630. return $this->isValueRequired() || $this->isValueOptional();
  42631. }
  42632. public function isValueRequired()
  42633. {
  42634. return self::VALUE_REQUIRED === (self::VALUE_REQUIRED & $this->mode);
  42635. }
  42636. public function isValueOptional()
  42637. {
  42638. return self::VALUE_OPTIONAL === (self::VALUE_OPTIONAL & $this->mode);
  42639. }
  42640. public function isArray()
  42641. {
  42642. return self::VALUE_IS_ARRAY === (self::VALUE_IS_ARRAY & $this->mode);
  42643. }
  42644. public function setDefault($default = null)
  42645. {
  42646. if (self::VALUE_NONE === (self::VALUE_NONE & $this->mode) && null !== $default) {
  42647. throw new LogicException('Cannot set a default value when using InputOption::VALUE_NONE mode.');
  42648. }
  42649. if ($this->isArray()) {
  42650. if (null === $default) {
  42651. $default = array();
  42652. } elseif (!is_array($default)) {
  42653. throw new LogicException('A default value for an array option must be an array.');
  42654. }
  42655. }
  42656. $this->default = $this->acceptValue() ? $default : false;
  42657. }
  42658. public function getDefault()
  42659. {
  42660. return $this->default;
  42661. }
  42662. public function getDescription()
  42663. {
  42664. return $this->description;
  42665. }
  42666. public function equals(InputOption $option)
  42667. {
  42668. return $option->getName() === $this->getName()
  42669. && $option->getShortcut() === $this->getShortcut()
  42670. && $option->getDefault() === $this->getDefault()
  42671. && $option->isArray() === $this->isArray()
  42672. && $option->isValueRequired() === $this->isValueRequired()
  42673. && $option->isValueOptional() === $this->isValueOptional()
  42674. ;
  42675. }
  42676. }
  42677. <?php
  42678. namespace Symfony\Component\Console\Input;
  42679. interface StreamableInputInterface extends InputInterface
  42680. {
  42681. public function setStream($stream);
  42682. public function getStream();
  42683. }
  42684. <?php
  42685. namespace Symfony\Component\Console\Input;
  42686. use Symfony\Component\Console\Exception\InvalidArgumentException;
  42687. class StringInput extends ArgvInput
  42688. {
  42689. const REGEX_STRING = '([^\s]+?)(?:\s|(?<!\\\\)"|(?<!\\\\)\'|$)';
  42690. const REGEX_QUOTED_STRING = '(?:"([^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'([^\'\\\\]*(?:\\\\.[^\'\\\\]*)*)\')';
  42691. public function __construct($input)
  42692. {
  42693. parent::__construct(array());
  42694. $this->setTokens($this->tokenize($input));
  42695. }
  42696. private function tokenize($input)
  42697. {
  42698. $tokens = array();
  42699. $length = strlen($input);
  42700. $cursor = 0;
  42701. while ($cursor < $length) {
  42702. if (preg_match('/\s+/A', $input, $match, null, $cursor)) {
  42703. } elseif (preg_match('/([^="\'\s]+?)(=?)('.self::REGEX_QUOTED_STRING.'+)/A', $input, $match, null, $cursor)) {
  42704. $tokens[] = $match[1].$match[2].stripcslashes(str_replace(array('"\'', '\'"', '\'\'', '""'), '', substr($match[3], 1, strlen($match[3]) - 2)));
  42705. } elseif (preg_match('/'.self::REGEX_QUOTED_STRING.'/A', $input, $match, null, $cursor)) {
  42706. $tokens[] = stripcslashes(substr($match[0], 1, strlen($match[0]) - 2));
  42707. } elseif (preg_match('/'.self::REGEX_STRING.'/A', $input, $match, null, $cursor)) {
  42708. $tokens[] = stripcslashes($match[1]);
  42709. } else {
  42710. throw new InvalidArgumentException(sprintf('Unable to parse input near "... %s ..."', substr($input, $cursor, 10)));
  42711. }
  42712. $cursor += strlen($match[0]);
  42713. }
  42714. return $tokens;
  42715. }
  42716. }
  42717. <?php
  42718. namespace Symfony\Component\Console\Logger;
  42719. use Psr\Log\AbstractLogger;
  42720. use Psr\Log\InvalidArgumentException;
  42721. use Psr\Log\LogLevel;
  42722. use Symfony\Component\Console\Output\OutputInterface;
  42723. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  42724. class ConsoleLogger extends AbstractLogger
  42725. {
  42726. const INFO = 'info';
  42727. const ERROR = 'error';
  42728. private $output;
  42729. private $verbosityLevelMap = array(
  42730. LogLevel::EMERGENCY => OutputInterface::VERBOSITY_NORMAL,
  42731. LogLevel::ALERT => OutputInterface::VERBOSITY_NORMAL,
  42732. LogLevel::CRITICAL => OutputInterface::VERBOSITY_NORMAL,
  42733. LogLevel::ERROR => OutputInterface::VERBOSITY_NORMAL,
  42734. LogLevel::WARNING => OutputInterface::VERBOSITY_NORMAL,
  42735. LogLevel::NOTICE => OutputInterface::VERBOSITY_VERBOSE,
  42736. LogLevel::INFO => OutputInterface::VERBOSITY_VERY_VERBOSE,
  42737. LogLevel::DEBUG => OutputInterface::VERBOSITY_DEBUG,
  42738. );
  42739. private $formatLevelMap = array(
  42740. LogLevel::EMERGENCY => self::ERROR,
  42741. LogLevel::ALERT => self::ERROR,
  42742. LogLevel::CRITICAL => self::ERROR,
  42743. LogLevel::ERROR => self::ERROR,
  42744. LogLevel::WARNING => self::INFO,
  42745. LogLevel::NOTICE => self::INFO,
  42746. LogLevel::INFO => self::INFO,
  42747. LogLevel::DEBUG => self::INFO,
  42748. );
  42749. private $errored = false;
  42750. public function __construct(OutputInterface $output, array $verbosityLevelMap = array(), array $formatLevelMap = array())
  42751. {
  42752. $this->output = $output;
  42753. $this->verbosityLevelMap = $verbosityLevelMap + $this->verbosityLevelMap;
  42754. $this->formatLevelMap = $formatLevelMap + $this->formatLevelMap;
  42755. }
  42756. public function log($level, $message, array $context = array())
  42757. {
  42758. if (!isset($this->verbosityLevelMap[$level])) {
  42759. throw new InvalidArgumentException(sprintf('The log level "%s" does not exist.', $level));
  42760. }
  42761. $output = $this->output;
  42762. if (self::ERROR === $this->formatLevelMap[$level]) {
  42763. if ($this->output instanceof ConsoleOutputInterface) {
  42764. $output = $output->getErrorOutput();
  42765. }
  42766. $this->errored = true;
  42767. }
  42768. if ($output->getVerbosity() >= $this->verbosityLevelMap[$level]) {
  42769. $output->writeln(sprintf('<%1$s>[%2$s] %3$s</%1$s>', $this->formatLevelMap[$level], $level, $this->interpolate($message, $context)), $this->verbosityLevelMap[$level]);
  42770. }
  42771. }
  42772. public function hasErrored()
  42773. {
  42774. return $this->errored;
  42775. }
  42776. private function interpolate($message, array $context)
  42777. {
  42778. if (false === strpos($message, '{')) {
  42779. return $message;
  42780. }
  42781. $replacements = array();
  42782. foreach ($context as $key => $val) {
  42783. if (null === $val || is_scalar($val) || (\is_object($val) && method_exists($val, '__toString'))) {
  42784. $replacements["{{$key}}"] = $val;
  42785. } elseif ($val instanceof \DateTimeInterface) {
  42786. $replacements["{{$key}}"] = $val->format(\DateTime::RFC3339);
  42787. } elseif (\is_object($val)) {
  42788. $replacements["{{$key}}"] = '[object '.\get_class($val).']';
  42789. } else {
  42790. $replacements["{{$key}}"] = '['.\gettype($val).']';
  42791. }
  42792. }
  42793. return strtr($message, $replacements);
  42794. }
  42795. }
  42796. <?php
  42797. namespace Symfony\Component\Console\Output;
  42798. class BufferedOutput extends Output
  42799. {
  42800. private $buffer = '';
  42801. public function fetch()
  42802. {
  42803. $content = $this->buffer;
  42804. $this->buffer = '';
  42805. return $content;
  42806. }
  42807. protected function doWrite($message, $newline)
  42808. {
  42809. $this->buffer .= $message;
  42810. if ($newline) {
  42811. $this->buffer .= PHP_EOL;
  42812. }
  42813. }
  42814. }
  42815. <?php
  42816. namespace Symfony\Component\Console\Output;
  42817. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  42818. class ConsoleOutput extends StreamOutput implements ConsoleOutputInterface
  42819. {
  42820. private $stderr;
  42821. public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  42822. {
  42823. parent::__construct($this->openOutputStream(), $verbosity, $decorated, $formatter);
  42824. $actualDecorated = $this->isDecorated();
  42825. $this->stderr = new StreamOutput($this->openErrorStream(), $verbosity, $decorated, $this->getFormatter());
  42826. if (null === $decorated) {
  42827. $this->setDecorated($actualDecorated && $this->stderr->isDecorated());
  42828. }
  42829. }
  42830. public function setDecorated($decorated)
  42831. {
  42832. parent::setDecorated($decorated);
  42833. $this->stderr->setDecorated($decorated);
  42834. }
  42835. public function setFormatter(OutputFormatterInterface $formatter)
  42836. {
  42837. parent::setFormatter($formatter);
  42838. $this->stderr->setFormatter($formatter);
  42839. }
  42840. public function setVerbosity($level)
  42841. {
  42842. parent::setVerbosity($level);
  42843. $this->stderr->setVerbosity($level);
  42844. }
  42845. public function getErrorOutput()
  42846. {
  42847. return $this->stderr;
  42848. }
  42849. public function setErrorOutput(OutputInterface $error)
  42850. {
  42851. $this->stderr = $error;
  42852. }
  42853. protected function hasStdoutSupport()
  42854. {
  42855. return false === $this->isRunningOS400();
  42856. }
  42857. protected function hasStderrSupport()
  42858. {
  42859. return false === $this->isRunningOS400();
  42860. }
  42861. private function isRunningOS400()
  42862. {
  42863. $checks = array(
  42864. function_exists('php_uname') ? php_uname('s') : '',
  42865. getenv('OSTYPE'),
  42866. PHP_OS,
  42867. );
  42868. return false !== stripos(implode(';', $checks), 'OS400');
  42869. }
  42870. private function openOutputStream()
  42871. {
  42872. if (!$this->hasStdoutSupport()) {
  42873. return fopen('php://output', 'w');
  42874. }
  42875. return @fopen('php://stdout', 'w') ?: fopen('php://output', 'w');
  42876. }
  42877. private function openErrorStream()
  42878. {
  42879. return fopen($this->hasStderrSupport() ? 'php://stderr' : 'php://output', 'w');
  42880. }
  42881. }
  42882. <?php
  42883. namespace Symfony\Component\Console\Output;
  42884. interface ConsoleOutputInterface extends OutputInterface
  42885. {
  42886. public function getErrorOutput();
  42887. public function setErrorOutput(OutputInterface $error);
  42888. }
  42889. <?php
  42890. namespace Symfony\Component\Console\Output;
  42891. use Symfony\Component\Console\Formatter\OutputFormatter;
  42892. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  42893. class NullOutput implements OutputInterface
  42894. {
  42895. public function setFormatter(OutputFormatterInterface $formatter)
  42896. {
  42897. }
  42898. public function getFormatter()
  42899. {
  42900. return new OutputFormatter();
  42901. }
  42902. public function setDecorated($decorated)
  42903. {
  42904. }
  42905. public function isDecorated()
  42906. {
  42907. return false;
  42908. }
  42909. public function setVerbosity($level)
  42910. {
  42911. }
  42912. public function getVerbosity()
  42913. {
  42914. return self::VERBOSITY_QUIET;
  42915. }
  42916. public function isQuiet()
  42917. {
  42918. return true;
  42919. }
  42920. public function isVerbose()
  42921. {
  42922. return false;
  42923. }
  42924. public function isVeryVerbose()
  42925. {
  42926. return false;
  42927. }
  42928. public function isDebug()
  42929. {
  42930. return false;
  42931. }
  42932. public function writeln($messages, $options = self::OUTPUT_NORMAL)
  42933. {
  42934. }
  42935. public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
  42936. {
  42937. }
  42938. }
  42939. <?php
  42940. namespace Symfony\Component\Console\Output;
  42941. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  42942. use Symfony\Component\Console\Formatter\OutputFormatter;
  42943. abstract class Output implements OutputInterface
  42944. {
  42945. private $verbosity;
  42946. private $formatter;
  42947. public function __construct($verbosity = self::VERBOSITY_NORMAL, $decorated = false, OutputFormatterInterface $formatter = null)
  42948. {
  42949. $this->verbosity = null === $verbosity ? self::VERBOSITY_NORMAL : $verbosity;
  42950. $this->formatter = $formatter ?: new OutputFormatter();
  42951. $this->formatter->setDecorated($decorated);
  42952. }
  42953. public function setFormatter(OutputFormatterInterface $formatter)
  42954. {
  42955. $this->formatter = $formatter;
  42956. }
  42957. public function getFormatter()
  42958. {
  42959. return $this->formatter;
  42960. }
  42961. public function setDecorated($decorated)
  42962. {
  42963. $this->formatter->setDecorated($decorated);
  42964. }
  42965. public function isDecorated()
  42966. {
  42967. return $this->formatter->isDecorated();
  42968. }
  42969. public function setVerbosity($level)
  42970. {
  42971. $this->verbosity = (int) $level;
  42972. }
  42973. public function getVerbosity()
  42974. {
  42975. return $this->verbosity;
  42976. }
  42977. public function isQuiet()
  42978. {
  42979. return self::VERBOSITY_QUIET === $this->verbosity;
  42980. }
  42981. public function isVerbose()
  42982. {
  42983. return self::VERBOSITY_VERBOSE <= $this->verbosity;
  42984. }
  42985. public function isVeryVerbose()
  42986. {
  42987. return self::VERBOSITY_VERY_VERBOSE <= $this->verbosity;
  42988. }
  42989. public function isDebug()
  42990. {
  42991. return self::VERBOSITY_DEBUG <= $this->verbosity;
  42992. }
  42993. public function writeln($messages, $options = self::OUTPUT_NORMAL)
  42994. {
  42995. $this->write($messages, true, $options);
  42996. }
  42997. public function write($messages, $newline = false, $options = self::OUTPUT_NORMAL)
  42998. {
  42999. $messages = (array) $messages;
  43000. $types = self::OUTPUT_NORMAL | self::OUTPUT_RAW | self::OUTPUT_PLAIN;
  43001. $type = $types & $options ?: self::OUTPUT_NORMAL;
  43002. $verbosities = self::VERBOSITY_QUIET | self::VERBOSITY_NORMAL | self::VERBOSITY_VERBOSE | self::VERBOSITY_VERY_VERBOSE | self::VERBOSITY_DEBUG;
  43003. $verbosity = $verbosities & $options ?: self::VERBOSITY_NORMAL;
  43004. if ($verbosity > $this->getVerbosity()) {
  43005. return;
  43006. }
  43007. foreach ($messages as $message) {
  43008. switch ($type) {
  43009. case OutputInterface::OUTPUT_NORMAL:
  43010. $message = $this->formatter->format($message);
  43011. break;
  43012. case OutputInterface::OUTPUT_RAW:
  43013. break;
  43014. case OutputInterface::OUTPUT_PLAIN:
  43015. $message = strip_tags($this->formatter->format($message));
  43016. break;
  43017. }
  43018. $this->doWrite($message, $newline);
  43019. }
  43020. }
  43021. abstract protected function doWrite($message, $newline);
  43022. }
  43023. <?php
  43024. namespace Symfony\Component\Console\Output;
  43025. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  43026. interface OutputInterface
  43027. {
  43028. const VERBOSITY_QUIET = 16;
  43029. const VERBOSITY_NORMAL = 32;
  43030. const VERBOSITY_VERBOSE = 64;
  43031. const VERBOSITY_VERY_VERBOSE = 128;
  43032. const VERBOSITY_DEBUG = 256;
  43033. const OUTPUT_NORMAL = 1;
  43034. const OUTPUT_RAW = 2;
  43035. const OUTPUT_PLAIN = 4;
  43036. public function write($messages, $newline = false, $options = 0);
  43037. public function writeln($messages, $options = 0);
  43038. public function setVerbosity($level);
  43039. public function getVerbosity();
  43040. public function isQuiet();
  43041. public function isVerbose();
  43042. public function isVeryVerbose();
  43043. public function isDebug();
  43044. public function setDecorated($decorated);
  43045. public function isDecorated();
  43046. public function setFormatter(OutputFormatterInterface $formatter);
  43047. public function getFormatter();
  43048. }
  43049. <?php
  43050. namespace Symfony\Component\Console\Output;
  43051. use Symfony\Component\Console\Exception\InvalidArgumentException;
  43052. use Symfony\Component\Console\Exception\RuntimeException;
  43053. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  43054. class StreamOutput extends Output
  43055. {
  43056. private $stream;
  43057. public function __construct($stream, $verbosity = self::VERBOSITY_NORMAL, $decorated = null, OutputFormatterInterface $formatter = null)
  43058. {
  43059. if (!is_resource($stream) || 'stream' !== get_resource_type($stream)) {
  43060. throw new InvalidArgumentException('The StreamOutput class needs a stream as its first argument.');
  43061. }
  43062. $this->stream = $stream;
  43063. if (null === $decorated) {
  43064. $decorated = $this->hasColorSupport();
  43065. }
  43066. parent::__construct($verbosity, $decorated, $formatter);
  43067. }
  43068. public function getStream()
  43069. {
  43070. return $this->stream;
  43071. }
  43072. protected function doWrite($message, $newline)
  43073. {
  43074. if (false === @fwrite($this->stream, $message) || ($newline && (false === @fwrite($this->stream, PHP_EOL)))) {
  43075. throw new RuntimeException('Unable to write output.');
  43076. }
  43077. fflush($this->stream);
  43078. }
  43079. protected function hasColorSupport()
  43080. {
  43081. if (DIRECTORY_SEPARATOR === '\\') {
  43082. return
  43083. '10.0.10586' === PHP_WINDOWS_VERSION_MAJOR.'.'.PHP_WINDOWS_VERSION_MINOR.'.'.PHP_WINDOWS_VERSION_BUILD
  43084. || false !== getenv('ANSICON')
  43085. || 'ON' === getenv('ConEmuANSI')
  43086. || 'xterm' === getenv('TERM');
  43087. }
  43088. return function_exists('posix_isatty') && @posix_isatty($this->stream);
  43089. }
  43090. }
  43091. <?php
  43092. namespace Symfony\Component\Console\Question;
  43093. use Symfony\Component\Console\Exception\InvalidArgumentException;
  43094. class ChoiceQuestion extends Question
  43095. {
  43096. private $choices;
  43097. private $multiselect = false;
  43098. private $prompt = ' > ';
  43099. private $errorMessage = 'Value "%s" is invalid';
  43100. public function __construct($question, array $choices, $default = null)
  43101. {
  43102. if (!$choices) {
  43103. throw new \LogicException('Choice question must have at least 1 choice available.');
  43104. }
  43105. parent::__construct($question, $default);
  43106. $this->choices = $choices;
  43107. $this->setValidator($this->getDefaultValidator());
  43108. $this->setAutocompleterValues($choices);
  43109. }
  43110. public function getChoices()
  43111. {
  43112. return $this->choices;
  43113. }
  43114. public function setMultiselect($multiselect)
  43115. {
  43116. $this->multiselect = $multiselect;
  43117. $this->setValidator($this->getDefaultValidator());
  43118. return $this;
  43119. }
  43120. public function isMultiselect()
  43121. {
  43122. return $this->multiselect;
  43123. }
  43124. public function getPrompt()
  43125. {
  43126. return $this->prompt;
  43127. }
  43128. public function setPrompt($prompt)
  43129. {
  43130. $this->prompt = $prompt;
  43131. return $this;
  43132. }
  43133. public function setErrorMessage($errorMessage)
  43134. {
  43135. $this->errorMessage = $errorMessage;
  43136. $this->setValidator($this->getDefaultValidator());
  43137. return $this;
  43138. }
  43139. private function getDefaultValidator()
  43140. {
  43141. $choices = $this->choices;
  43142. $errorMessage = $this->errorMessage;
  43143. $multiselect = $this->multiselect;
  43144. $isAssoc = $this->isAssoc($choices);
  43145. return function ($selected) use ($choices, $errorMessage, $multiselect, $isAssoc) {
  43146. $selectedChoices = str_replace(' ', '', $selected);
  43147. if ($multiselect) {
  43148. if (!preg_match('/^[^,]+(?:,[^,]+)*$/', $selectedChoices, $matches)) {
  43149. throw new InvalidArgumentException(sprintf($errorMessage, $selected));
  43150. }
  43151. $selectedChoices = explode(',', $selectedChoices);
  43152. } else {
  43153. $selectedChoices = array($selected);
  43154. }
  43155. $multiselectChoices = array();
  43156. foreach ($selectedChoices as $value) {
  43157. $results = array();
  43158. foreach ($choices as $key => $choice) {
  43159. if ($choice === $value) {
  43160. $results[] = $key;
  43161. }
  43162. }
  43163. if (count($results) > 1) {
  43164. throw new InvalidArgumentException(sprintf('The provided answer is ambiguous. Value should be one of %s.', implode(' or ', $results)));
  43165. }
  43166. $result = array_search($value, $choices);
  43167. if (!$isAssoc) {
  43168. if (false !== $result) {
  43169. $result = $choices[$result];
  43170. } elseif (isset($choices[$value])) {
  43171. $result = $choices[$value];
  43172. }
  43173. } elseif (false === $result && isset($choices[$value])) {
  43174. $result = $value;
  43175. }
  43176. if (false === $result) {
  43177. throw new InvalidArgumentException(sprintf($errorMessage, $value));
  43178. }
  43179. $multiselectChoices[] = (string) $result;
  43180. }
  43181. if ($multiselect) {
  43182. return $multiselectChoices;
  43183. }
  43184. return current($multiselectChoices);
  43185. };
  43186. }
  43187. }
  43188. <?php
  43189. namespace Symfony\Component\Console\Question;
  43190. class ConfirmationQuestion extends Question
  43191. {
  43192. private $trueAnswerRegex;
  43193. public function __construct($question, $default = true, $trueAnswerRegex = '/^y/i')
  43194. {
  43195. parent::__construct($question, (bool) $default);
  43196. $this->trueAnswerRegex = $trueAnswerRegex;
  43197. $this->setNormalizer($this->getDefaultNormalizer());
  43198. }
  43199. private function getDefaultNormalizer()
  43200. {
  43201. $default = $this->getDefault();
  43202. $regex = $this->trueAnswerRegex;
  43203. return function ($answer) use ($default, $regex) {
  43204. if (is_bool($answer)) {
  43205. return $answer;
  43206. }
  43207. $answerIsTrue = (bool) preg_match($regex, $answer);
  43208. if (false === $default) {
  43209. return $answer && $answerIsTrue;
  43210. }
  43211. return !$answer || $answerIsTrue;
  43212. };
  43213. }
  43214. }
  43215. <?php
  43216. namespace Symfony\Component\Console\Question;
  43217. use Symfony\Component\Console\Exception\InvalidArgumentException;
  43218. use Symfony\Component\Console\Exception\LogicException;
  43219. class Question
  43220. {
  43221. private $question;
  43222. private $attempts;
  43223. private $hidden = false;
  43224. private $hiddenFallback = true;
  43225. private $autocompleterValues;
  43226. private $validator;
  43227. private $default;
  43228. private $normalizer;
  43229. public function __construct($question, $default = null)
  43230. {
  43231. $this->question = $question;
  43232. $this->default = $default;
  43233. }
  43234. public function getQuestion()
  43235. {
  43236. return $this->question;
  43237. }
  43238. public function getDefault()
  43239. {
  43240. return $this->default;
  43241. }
  43242. public function isHidden()
  43243. {
  43244. return $this->hidden;
  43245. }
  43246. public function setHidden($hidden)
  43247. {
  43248. if ($this->autocompleterValues) {
  43249. throw new LogicException('A hidden question cannot use the autocompleter.');
  43250. }
  43251. $this->hidden = (bool) $hidden;
  43252. return $this;
  43253. }
  43254. public function isHiddenFallback()
  43255. {
  43256. return $this->hiddenFallback;
  43257. }
  43258. public function setHiddenFallback($fallback)
  43259. {
  43260. $this->hiddenFallback = (bool) $fallback;
  43261. return $this;
  43262. }
  43263. public function getAutocompleterValues()
  43264. {
  43265. return $this->autocompleterValues;
  43266. }
  43267. public function setAutocompleterValues($values)
  43268. {
  43269. if (is_array($values)) {
  43270. $values = $this->isAssoc($values) ? array_merge(array_keys($values), array_values($values)) : array_values($values);
  43271. }
  43272. if (null !== $values && !is_array($values) && !$values instanceof \Traversable) {
  43273. throw new InvalidArgumentException('Autocompleter values can be either an array, `null` or a `Traversable` object.');
  43274. }
  43275. if ($this->hidden) {
  43276. throw new LogicException('A hidden question cannot use the autocompleter.');
  43277. }
  43278. $this->autocompleterValues = $values;
  43279. return $this;
  43280. }
  43281. public function setValidator(callable $validator = null)
  43282. {
  43283. $this->validator = $validator;
  43284. return $this;
  43285. }
  43286. public function getValidator()
  43287. {
  43288. return $this->validator;
  43289. }
  43290. public function setMaxAttempts($attempts)
  43291. {
  43292. if (null !== $attempts && $attempts < 1) {
  43293. throw new InvalidArgumentException('Maximum number of attempts must be a positive value.');
  43294. }
  43295. $this->attempts = $attempts;
  43296. return $this;
  43297. }
  43298. public function getMaxAttempts()
  43299. {
  43300. return $this->attempts;
  43301. }
  43302. public function setNormalizer(callable $normalizer)
  43303. {
  43304. $this->normalizer = $normalizer;
  43305. return $this;
  43306. }
  43307. public function getNormalizer()
  43308. {
  43309. return $this->normalizer;
  43310. }
  43311. protected function isAssoc($array)
  43312. {
  43313. return (bool) count(array_filter(array_keys($array), 'is_string'));
  43314. }
  43315. }
  43316. <?php
  43317. namespace Symfony\Component\Console\Style;
  43318. use Symfony\Component\Console\Formatter\OutputFormatterInterface;
  43319. use Symfony\Component\Console\Helper\ProgressBar;
  43320. use Symfony\Component\Console\Output\OutputInterface;
  43321. use Symfony\Component\Console\Output\ConsoleOutputInterface;
  43322. abstract class OutputStyle implements OutputInterface, StyleInterface
  43323. {
  43324. private $output;
  43325. public function __construct(OutputInterface $output)
  43326. {
  43327. $this->output = $output;
  43328. }
  43329. public function newLine($count = 1)
  43330. {
  43331. $this->output->write(str_repeat(PHP_EOL, $count));
  43332. }
  43333. public function createProgressBar($max = 0)
  43334. {
  43335. return new ProgressBar($this->output, $max);
  43336. }
  43337. public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
  43338. {
  43339. $this->output->write($messages, $newline, $type);
  43340. }
  43341. public function writeln($messages, $type = self::OUTPUT_NORMAL)
  43342. {
  43343. $this->output->writeln($messages, $type);
  43344. }
  43345. public function setVerbosity($level)
  43346. {
  43347. $this->output->setVerbosity($level);
  43348. }
  43349. public function getVerbosity()
  43350. {
  43351. return $this->output->getVerbosity();
  43352. }
  43353. public function setDecorated($decorated)
  43354. {
  43355. $this->output->setDecorated($decorated);
  43356. }
  43357. public function isDecorated()
  43358. {
  43359. return $this->output->isDecorated();
  43360. }
  43361. public function setFormatter(OutputFormatterInterface $formatter)
  43362. {
  43363. $this->output->setFormatter($formatter);
  43364. }
  43365. public function getFormatter()
  43366. {
  43367. return $this->output->getFormatter();
  43368. }
  43369. public function isQuiet()
  43370. {
  43371. return $this->output->isQuiet();
  43372. }
  43373. public function isVerbose()
  43374. {
  43375. return $this->output->isVerbose();
  43376. }
  43377. public function isVeryVerbose()
  43378. {
  43379. return $this->output->isVeryVerbose();
  43380. }
  43381. public function isDebug()
  43382. {
  43383. return $this->output->isDebug();
  43384. }
  43385. protected function getErrorOutput()
  43386. {
  43387. if (!$this->output instanceof ConsoleOutputInterface) {
  43388. return $this->output;
  43389. }
  43390. return $this->output->getErrorOutput();
  43391. }
  43392. }
  43393. <?php
  43394. namespace Symfony\Component\Console\Style;
  43395. interface StyleInterface
  43396. {
  43397. public function title($message);
  43398. public function section($message);
  43399. public function listing(array $elements);
  43400. public function text($message);
  43401. public function success($message);
  43402. public function error($message);
  43403. public function warning($message);
  43404. public function note($message);
  43405. public function caution($message);
  43406. public function table(array $headers, array $rows);
  43407. public function ask($question, $default = null, $validator = null);
  43408. public function askHidden($question, $validator = null);
  43409. public function confirm($question, $default = true);
  43410. public function choice($question, array $choices, $default = null);
  43411. public function newLine($count = 1);
  43412. public function progressStart($max = 0);
  43413. public function progressAdvance($step = 1);
  43414. public function progressFinish();
  43415. }
  43416. <?php
  43417. namespace Symfony\Component\Console\Style;
  43418. use Symfony\Component\Console\Exception\RuntimeException;
  43419. use Symfony\Component\Console\Formatter\OutputFormatter;
  43420. use Symfony\Component\Console\Helper\Helper;
  43421. use Symfony\Component\Console\Helper\ProgressBar;
  43422. use Symfony\Component\Console\Helper\SymfonyQuestionHelper;
  43423. use Symfony\Component\Console\Helper\Table;
  43424. use Symfony\Component\Console\Input\InputInterface;
  43425. use Symfony\Component\Console\Output\BufferedOutput;
  43426. use Symfony\Component\Console\Output\OutputInterface;
  43427. use Symfony\Component\Console\Question\ChoiceQuestion;
  43428. use Symfony\Component\Console\Question\ConfirmationQuestion;
  43429. use Symfony\Component\Console\Question\Question;
  43430. use Symfony\Component\Console\Terminal;
  43431. class SymfonyStyle extends OutputStyle
  43432. {
  43433. const MAX_LINE_LENGTH = 120;
  43434. private $input;
  43435. private $questionHelper;
  43436. private $progressBar;
  43437. private $lineLength;
  43438. private $bufferedOutput;
  43439. public function __construct(InputInterface $input, OutputInterface $output)
  43440. {
  43441. $this->input = $input;
  43442. $this->bufferedOutput = new BufferedOutput($output->getVerbosity(), false, clone $output->getFormatter());
  43443. $width = (new Terminal())->getWidth() ?: self::MAX_LINE_LENGTH;
  43444. $this->lineLength = min($width - (int) (DIRECTORY_SEPARATOR === '\\'), self::MAX_LINE_LENGTH);
  43445. parent::__construct($output);
  43446. }
  43447. public function block($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = true)
  43448. {
  43449. $messages = is_array($messages) ? array_values($messages) : array($messages);
  43450. $this->autoPrependBlock();
  43451. $this->writeln($this->createBlock($messages, $type, $style, $prefix, $padding, $escape));
  43452. $this->newLine();
  43453. }
  43454. public function title($message)
  43455. {
  43456. $this->autoPrependBlock();
  43457. $this->writeln(array(
  43458. sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
  43459. sprintf('<comment>%s</>', str_repeat('=', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
  43460. ));
  43461. $this->newLine();
  43462. }
  43463. public function section($message)
  43464. {
  43465. $this->autoPrependBlock();
  43466. $this->writeln(array(
  43467. sprintf('<comment>%s</>', OutputFormatter::escapeTrailingBackslash($message)),
  43468. sprintf('<comment>%s</>', str_repeat('-', Helper::strlenWithoutDecoration($this->getFormatter(), $message))),
  43469. ));
  43470. $this->newLine();
  43471. }
  43472. public function listing(array $elements)
  43473. {
  43474. $this->autoPrependText();
  43475. $elements = array_map(function ($element) {
  43476. return sprintf(' * %s', $element);
  43477. }, $elements);
  43478. $this->writeln($elements);
  43479. $this->newLine();
  43480. }
  43481. public function text($message)
  43482. {
  43483. $this->autoPrependText();
  43484. $messages = is_array($message) ? array_values($message) : array($message);
  43485. foreach ($messages as $message) {
  43486. $this->writeln(sprintf(' %s', $message));
  43487. }
  43488. }
  43489. public function comment($message)
  43490. {
  43491. $this->block($message, null, null, '<fg=default;bg=default> // </>', false, false);
  43492. }
  43493. public function success($message)
  43494. {
  43495. $this->block($message, 'OK', 'fg=black;bg=green', ' ', true);
  43496. }
  43497. public function error($message)
  43498. {
  43499. $this->block($message, 'ERROR', 'fg=white;bg=red', ' ', true);
  43500. }
  43501. public function warning($message)
  43502. {
  43503. $this->block($message, 'WARNING', 'fg=white;bg=red', ' ', true);
  43504. }
  43505. public function note($message)
  43506. {
  43507. $this->block($message, 'NOTE', 'fg=yellow', ' ! ');
  43508. }
  43509. public function caution($message)
  43510. {
  43511. $this->block($message, 'CAUTION', 'fg=white;bg=red', ' ! ', true);
  43512. }
  43513. public function table(array $headers, array $rows)
  43514. {
  43515. $style = clone Table::getStyleDefinition('symfony-style-guide');
  43516. $style->setCellHeaderFormat('<info>%s</info>');
  43517. $table = new Table($this);
  43518. $table->setHeaders($headers);
  43519. $table->setRows($rows);
  43520. $table->setStyle($style);
  43521. $table->render();
  43522. $this->newLine();
  43523. }
  43524. public function ask($question, $default = null, $validator = null)
  43525. {
  43526. $question = new Question($question, $default);
  43527. $question->setValidator($validator);
  43528. return $this->askQuestion($question);
  43529. }
  43530. public function askHidden($question, $validator = null)
  43531. {
  43532. $question = new Question($question);
  43533. $question->setHidden(true);
  43534. $question->setValidator($validator);
  43535. return $this->askQuestion($question);
  43536. }
  43537. public function confirm($question, $default = true)
  43538. {
  43539. return $this->askQuestion(new ConfirmationQuestion($question, $default));
  43540. }
  43541. public function choice($question, array $choices, $default = null)
  43542. {
  43543. if (null !== $default) {
  43544. $values = array_flip($choices);
  43545. $default = $values[$default];
  43546. }
  43547. return $this->askQuestion(new ChoiceQuestion($question, $choices, $default));
  43548. }
  43549. public function progressStart($max = 0)
  43550. {
  43551. $this->progressBar = $this->createProgressBar($max);
  43552. $this->progressBar->start();
  43553. }
  43554. public function progressAdvance($step = 1)
  43555. {
  43556. $this->getProgressBar()->advance($step);
  43557. }
  43558. public function progressFinish()
  43559. {
  43560. $this->getProgressBar()->finish();
  43561. $this->newLine(2);
  43562. $this->progressBar = null;
  43563. }
  43564. public function createProgressBar($max = 0)
  43565. {
  43566. $progressBar = parent::createProgressBar($max);
  43567. if ('\\' !== DIRECTORY_SEPARATOR) {
  43568. $progressBar->setEmptyBarCharacter('â–‘');
  43569. $progressBar->setProgressCharacter('');
  43570. $progressBar->setBarCharacter('â–“');
  43571. }
  43572. return $progressBar;
  43573. }
  43574. public function askQuestion(Question $question)
  43575. {
  43576. if ($this->input->isInteractive()) {
  43577. $this->autoPrependBlock();
  43578. }
  43579. if (!$this->questionHelper) {
  43580. $this->questionHelper = new SymfonyQuestionHelper();
  43581. }
  43582. $answer = $this->questionHelper->ask($this->input, $this, $question);
  43583. if ($this->input->isInteractive()) {
  43584. $this->newLine();
  43585. $this->bufferedOutput->write("\n");
  43586. }
  43587. return $answer;
  43588. }
  43589. public function writeln($messages, $type = self::OUTPUT_NORMAL)
  43590. {
  43591. parent::writeln($messages, $type);
  43592. $this->bufferedOutput->writeln($this->reduceBuffer($messages), $type);
  43593. }
  43594. public function write($messages, $newline = false, $type = self::OUTPUT_NORMAL)
  43595. {
  43596. parent::write($messages, $newline, $type);
  43597. $this->bufferedOutput->write($this->reduceBuffer($messages), $newline, $type);
  43598. }
  43599. public function newLine($count = 1)
  43600. {
  43601. parent::newLine($count);
  43602. $this->bufferedOutput->write(str_repeat("\n", $count));
  43603. }
  43604. public function getErrorStyle()
  43605. {
  43606. return new self($this->input, $this->getErrorOutput());
  43607. }
  43608. private function getProgressBar()
  43609. {
  43610. if (!$this->progressBar) {
  43611. throw new RuntimeException('The ProgressBar is not started.');
  43612. }
  43613. return $this->progressBar;
  43614. }
  43615. private function autoPrependBlock()
  43616. {
  43617. $chars = substr(str_replace(PHP_EOL, "\n", $this->bufferedOutput->fetch()), -2);
  43618. if (!isset($chars[0])) {
  43619. return $this->newLine();
  43620. }
  43621. $this->newLine(2 - substr_count($chars, "\n"));
  43622. }
  43623. private function autoPrependText()
  43624. {
  43625. $fetched = $this->bufferedOutput->fetch();
  43626. if ("\n" !== substr($fetched, -1)) {
  43627. $this->newLine();
  43628. }
  43629. }
  43630. private function reduceBuffer($messages)
  43631. {
  43632. return array_map(function ($value) {
  43633. return substr($value, -4);
  43634. }, array_merge(array($this->bufferedOutput->fetch()), (array) $messages));
  43635. }
  43636. private function createBlock($messages, $type = null, $style = null, $prefix = ' ', $padding = false, $escape = false)
  43637. {
  43638. $indentLength = 0;
  43639. $prefixLength = Helper::strlenWithoutDecoration($this->getFormatter(), $prefix);
  43640. $lines = array();
  43641. if (null !== $type) {
  43642. $type = sprintf('[%s] ', $type);
  43643. $indentLength = strlen($type);
  43644. $lineIndentation = str_repeat(' ', $indentLength);
  43645. }
  43646. foreach ($messages as $key => $message) {
  43647. if ($escape) {
  43648. $message = OutputFormatter::escape($message);
  43649. }
  43650. $lines = array_merge($lines, explode(PHP_EOL, wordwrap($message, $this->lineLength - $prefixLength - $indentLength, PHP_EOL, true)));
  43651. if (count($messages) > 1 && $key < count($messages) - 1) {
  43652. $lines[] = '';
  43653. }
  43654. }
  43655. $firstLineIndex = 0;
  43656. if ($padding && $this->isDecorated()) {
  43657. $firstLineIndex = 1;
  43658. array_unshift($lines, '');
  43659. $lines[] = '';
  43660. }
  43661. foreach ($lines as $i => &$line) {
  43662. if (null !== $type) {
  43663. $line = $firstLineIndex === $i ? $type.$line : $lineIndentation.$line;
  43664. }
  43665. $line = $prefix.$line;
  43666. $line .= str_repeat(' ', $this->lineLength - Helper::strlenWithoutDecoration($this->getFormatter(), $line));
  43667. if ($style) {
  43668. $line = sprintf('<%s>%s</>', $style, $line);
  43669. }
  43670. }
  43671. return $lines;
  43672. }
  43673. }
  43674. <?php
  43675. namespace Symfony\Component\Console;
  43676. class Terminal
  43677. {
  43678. private static $width;
  43679. private static $height;
  43680. public function getWidth()
  43681. {
  43682. $width = getenv('COLUMNS');
  43683. if (false !== $width) {
  43684. return (int) trim($width);
  43685. }
  43686. if (null === self::$width) {
  43687. self::initDimensions();
  43688. }
  43689. return self::$width ?: 80;
  43690. }
  43691. public function getHeight()
  43692. {
  43693. $height = getenv('LINES');
  43694. if (false !== $height) {
  43695. return (int) trim($height);
  43696. }
  43697. if (null === self::$height) {
  43698. self::initDimensions();
  43699. }
  43700. return self::$height ?: 50;
  43701. }
  43702. private static function initDimensions()
  43703. {
  43704. if ('\\' === DIRECTORY_SEPARATOR) {
  43705. if (preg_match('/^(\d+)x(\d+)(?: \((\d+)x(\d+)\))?$/', trim(getenv('ANSICON')), $matches)) {
  43706. self::$width = (int) $matches[1];
  43707. self::$height = isset($matches[4]) ? (int) $matches[4] : (int) $matches[2];
  43708. } elseif (null !== $dimensions = self::getConsoleMode()) {
  43709. self::$width = (int) $dimensions[0];
  43710. self::$height = (int) $dimensions[1];
  43711. }
  43712. } elseif ($sttyString = self::getSttyColumns()) {
  43713. if (preg_match('/rows.(\d+);.columns.(\d+);/i', $sttyString, $matches)) {
  43714. self::$width = (int) $matches[2];
  43715. self::$height = (int) $matches[1];
  43716. } elseif (preg_match('/;.(\d+).rows;.(\d+).columns/i', $sttyString, $matches)) {
  43717. self::$width = (int) $matches[2];
  43718. self::$height = (int) $matches[1];
  43719. }
  43720. }
  43721. }
  43722. private static function getConsoleMode()
  43723. {
  43724. if (!function_exists('proc_open')) {
  43725. return;
  43726. }
  43727. $descriptorspec = array(
  43728. 1 => array('pipe', 'w'),
  43729. 2 => array('pipe', 'w'),
  43730. );
  43731. $process = proc_open('mode CON', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
  43732. if (is_resource($process)) {
  43733. $info = stream_get_contents($pipes[1]);
  43734. fclose($pipes[1]);
  43735. fclose($pipes[2]);
  43736. proc_close($process);
  43737. if (preg_match('/--------+\r?\n.+?(\d+)\r?\n.+?(\d+)\r?\n/', $info, $matches)) {
  43738. return array((int) $matches[2], (int) $matches[1]);
  43739. }
  43740. }
  43741. }
  43742. private static function getSttyColumns()
  43743. {
  43744. if (!function_exists('proc_open')) {
  43745. return;
  43746. }
  43747. $descriptorspec = array(
  43748. 1 => array('pipe', 'w'),
  43749. 2 => array('pipe', 'w'),
  43750. );
  43751. $process = proc_open('stty -a | grep columns', $descriptorspec, $pipes, null, null, array('suppress_errors' => true));
  43752. if (is_resource($process)) {
  43753. $info = stream_get_contents($pipes[1]);
  43754. fclose($pipes[1]);
  43755. fclose($pipes[2]);
  43756. proc_close($process);
  43757. return $info;
  43758. }
  43759. }
  43760. }
  43761. <?php
  43762. namespace Symfony\Component\Console\Tester;
  43763. use Symfony\Component\Console\Application;
  43764. use Symfony\Component\Console\Input\ArrayInput;
  43765. use Symfony\Component\Console\Input\InputInterface;
  43766. use Symfony\Component\Console\Output\ConsoleOutput;
  43767. use Symfony\Component\Console\Output\OutputInterface;
  43768. use Symfony\Component\Console\Output\StreamOutput;
  43769. class ApplicationTester
  43770. {
  43771. private $application;
  43772. private $input;
  43773. private $statusCode;
  43774. private $output;
  43775. private $captureStreamsIndependently = false;
  43776. public function __construct(Application $application)
  43777. {
  43778. $this->application = $application;
  43779. }
  43780. public function run(array $input, $options = array())
  43781. {
  43782. $this->input = new ArrayInput($input);
  43783. if (isset($options['interactive'])) {
  43784. $this->input->setInteractive($options['interactive']);
  43785. }
  43786. $this->captureStreamsIndependently = array_key_exists('capture_stderr_separately', $options) && $options['capture_stderr_separately'];
  43787. if (!$this->captureStreamsIndependently) {
  43788. $this->output = new StreamOutput(fopen('php://memory', 'w', false));
  43789. if (isset($options['decorated'])) {
  43790. $this->output->setDecorated($options['decorated']);
  43791. }
  43792. if (isset($options['verbosity'])) {
  43793. $this->output->setVerbosity($options['verbosity']);
  43794. }
  43795. } else {
  43796. $this->output = new ConsoleOutput(
  43797. isset($options['verbosity']) ? $options['verbosity'] : ConsoleOutput::VERBOSITY_NORMAL,
  43798. isset($options['decorated']) ? $options['decorated'] : null
  43799. );
  43800. $errorOutput = new StreamOutput(fopen('php://memory', 'w', false));
  43801. $errorOutput->setFormatter($this->output->getFormatter());
  43802. $errorOutput->setVerbosity($this->output->getVerbosity());
  43803. $errorOutput->setDecorated($this->output->isDecorated());
  43804. $reflectedOutput = new \ReflectionObject($this->output);
  43805. $strErrProperty = $reflectedOutput->getProperty('stderr');
  43806. $strErrProperty->setAccessible(true);
  43807. $strErrProperty->setValue($this->output, $errorOutput);
  43808. $reflectedParent = $reflectedOutput->getParentClass();
  43809. $streamProperty = $reflectedParent->getProperty('stream');
  43810. $streamProperty->setAccessible(true);
  43811. $streamProperty->setValue($this->output, fopen('php://memory', 'w', false));
  43812. }
  43813. return $this->statusCode = $this->application->run($this->input, $this->output);
  43814. }
  43815. public function getDisplay($normalize = false)
  43816. {
  43817. rewind($this->output->getStream());
  43818. $display = stream_get_contents($this->output->getStream());
  43819. if ($normalize) {
  43820. $display = str_replace(PHP_EOL, "\n", $display);
  43821. }
  43822. return $display;
  43823. }
  43824. public function getErrorOutput($normalize = false)
  43825. {
  43826. if (!$this->captureStreamsIndependently) {
  43827. throw new \LogicException('The error output is not available when the tester is run without "capture_stderr_separately" option set.');
  43828. }
  43829. rewind($this->output->getErrorOutput()->getStream());
  43830. $display = stream_get_contents($this->output->getErrorOutput()->getStream());
  43831. if ($normalize) {
  43832. $display = str_replace(PHP_EOL, "\n", $display);
  43833. }
  43834. return $display;
  43835. }
  43836. public function getInput()
  43837. {
  43838. return $this->input;
  43839. }
  43840. public function getOutput()
  43841. {
  43842. return $this->output;
  43843. }
  43844. public function getStatusCode()
  43845. {
  43846. return $this->statusCode;
  43847. }
  43848. }
  43849. <?php
  43850. namespace Symfony\Component\Console\Tester;
  43851. use Symfony\Component\Console\Command\Command;
  43852. use Symfony\Component\Console\Input\ArrayInput;
  43853. use Symfony\Component\Console\Output\StreamOutput;
  43854. use Symfony\Component\Console\Input\InputInterface;
  43855. use Symfony\Component\Console\Output\OutputInterface;
  43856. class CommandTester
  43857. {
  43858. private $command;
  43859. private $input;
  43860. private $output;
  43861. private $inputs = array();
  43862. private $statusCode;
  43863. public function __construct(Command $command)
  43864. {
  43865. $this->command = $command;
  43866. }
  43867. public function execute(array $input, array $options = array())
  43868. {
  43869. if (!isset($input['command'])
  43870. && (null !== $application = $this->command->getApplication())
  43871. && $application->getDefinition()->hasArgument('command')
  43872. ) {
  43873. $input = array_merge(array('command' => $this->command->getName()), $input);
  43874. }
  43875. $this->input = new ArrayInput($input);
  43876. if ($this->inputs) {
  43877. $this->input->setStream(self::createStream($this->inputs));
  43878. }
  43879. if (isset($options['interactive'])) {
  43880. $this->input->setInteractive($options['interactive']);
  43881. }
  43882. $this->output = new StreamOutput(fopen('php://memory', 'w', false));
  43883. $this->output->setDecorated(isset($options['decorated']) ? $options['decorated'] : false);
  43884. if (isset($options['verbosity'])) {
  43885. $this->output->setVerbosity($options['verbosity']);
  43886. }
  43887. return $this->statusCode = $this->command->run($this->input, $this->output);
  43888. }
  43889. public function getDisplay($normalize = false)
  43890. {
  43891. rewind($this->output->getStream());
  43892. $display = stream_get_contents($this->output->getStream());
  43893. if ($normalize) {
  43894. $display = str_replace(PHP_EOL, "\n", $display);
  43895. }
  43896. return $display;
  43897. }
  43898. public function getInput()
  43899. {
  43900. return $this->input;
  43901. }
  43902. public function getOutput()
  43903. {
  43904. return $this->output;
  43905. }
  43906. public function getStatusCode()
  43907. {
  43908. return $this->statusCode;
  43909. }
  43910. public function setInputs(array $inputs)
  43911. {
  43912. $this->inputs = $inputs;
  43913. return $this;
  43914. }
  43915. private static function createStream(array $inputs)
  43916. {
  43917. $stream = fopen('php://memory', 'r+', false);
  43918. fwrite($stream, implode(PHP_EOL, $inputs));
  43919. rewind($stream);
  43920. return $stream;
  43921. }
  43922. }
  43923. <?php
  43924. namespace Symfony\Component\Filesystem\Exception;
  43925. interface ExceptionInterface
  43926. {
  43927. }
  43928. <?php
  43929. namespace Symfony\Component\Filesystem\Exception;
  43930. class FileNotFoundException extends IOException
  43931. {
  43932. public function __construct($message = null, $code = 0, \Exception $previous = null, $path = null)
  43933. {
  43934. if (null === $message) {
  43935. if (null === $path) {
  43936. $message = 'File could not be found.';
  43937. } else {
  43938. $message = sprintf('File "%s" could not be found.', $path);
  43939. }
  43940. }
  43941. parent::__construct($message, $code, $previous, $path);
  43942. }
  43943. }
  43944. <?php
  43945. namespace Symfony\Component\Filesystem\Exception;
  43946. class IOException extends \RuntimeException implements IOExceptionInterface
  43947. {
  43948. private $path;
  43949. public function __construct($message, $code = 0, \Exception $previous = null, $path = null)
  43950. {
  43951. $this->path = $path;
  43952. parent::__construct($message, $code, $previous);
  43953. }
  43954. public function getPath()
  43955. {
  43956. return $this->path;
  43957. }
  43958. }
  43959. <?php
  43960. namespace Symfony\Component\Filesystem\Exception;
  43961. interface IOExceptionInterface extends ExceptionInterface
  43962. {
  43963. public function getPath();
  43964. }
  43965. <?php
  43966. namespace Symfony\Component\Filesystem;
  43967. use Symfony\Component\Filesystem\Exception\IOException;
  43968. use Symfony\Component\Filesystem\Exception\FileNotFoundException;
  43969. class Filesystem
  43970. {
  43971. public function copy($originFile, $targetFile, $overwriteNewerFiles = false)
  43972. {
  43973. $originIsLocal = stream_is_local($originFile) || 0 === stripos($originFile, 'file://');
  43974. if ($originIsLocal && !is_file($originFile)) {
  43975. throw new FileNotFoundException(sprintf('Failed to copy "%s" because file does not exist.', $originFile), 0, null, $originFile);
  43976. }
  43977. $this->mkdir(dirname($targetFile));
  43978. $doCopy = true;
  43979. if (!$overwriteNewerFiles && null === parse_url($originFile, PHP_URL_HOST) && is_file($targetFile)) {
  43980. $doCopy = filemtime($originFile) > filemtime($targetFile);
  43981. }
  43982. if ($doCopy) {
  43983. if (false === $source = @fopen($originFile, 'r')) {
  43984. throw new IOException(sprintf('Failed to copy "%s" to "%s" because source file could not be opened for reading.', $originFile, $targetFile), 0, null, $originFile);
  43985. }
  43986. if (false === $target = @fopen($targetFile, 'w', null, stream_context_create(array('ftp' => array('overwrite' => true))))) {
  43987. throw new IOException(sprintf('Failed to copy "%s" to "%s" because target file could not be opened for writing.', $originFile, $targetFile), 0, null, $originFile);
  43988. }
  43989. $bytesCopied = stream_copy_to_stream($source, $target);
  43990. fclose($source);
  43991. fclose($target);
  43992. unset($source, $target);
  43993. if (!is_file($targetFile)) {
  43994. throw new IOException(sprintf('Failed to copy "%s" to "%s".', $originFile, $targetFile), 0, null, $originFile);
  43995. }
  43996. if ($originIsLocal) {
  43997. @chmod($targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111));
  43998. if ($bytesCopied !== $bytesOrigin = filesize($originFile)) {
  43999. throw new IOException(sprintf('Failed to copy the whole content of "%s" to "%s" (%g of %g bytes copied).', $originFile, $targetFile, $bytesCopied, $bytesOrigin), 0, null, $originFile);
  44000. }
  44001. }
  44002. }
  44003. }
  44004. public function mkdir($dirs, $mode = 0777)
  44005. {
  44006. foreach ($this->toIterable($dirs) as $dir) {
  44007. if (is_dir($dir)) {
  44008. continue;
  44009. }
  44010. if (true !== @mkdir($dir, $mode, true)) {
  44011. $error = error_get_last();
  44012. if (!is_dir($dir)) {
  44013. if ($error) {
  44014. throw new IOException(sprintf('Failed to create "%s": %s.', $dir, $error['message']), 0, null, $dir);
  44015. }
  44016. throw new IOException(sprintf('Failed to create "%s"', $dir), 0, null, $dir);
  44017. }
  44018. }
  44019. }
  44020. }
  44021. public function exists($files)
  44022. {
  44023. $maxPathLength = PHP_MAXPATHLEN - 2;
  44024. foreach ($this->toIterable($files) as $file) {
  44025. if (strlen($file) > $maxPathLength) {
  44026. throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
  44027. }
  44028. if (!file_exists($file)) {
  44029. return false;
  44030. }
  44031. }
  44032. return true;
  44033. }
  44034. public function touch($files, $time = null, $atime = null)
  44035. {
  44036. foreach ($this->toIterable($files) as $file) {
  44037. $touch = $time ? @touch($file, $time, $atime) : @touch($file);
  44038. if (true !== $touch) {
  44039. throw new IOException(sprintf('Failed to touch "%s".', $file), 0, null, $file);
  44040. }
  44041. }
  44042. }
  44043. public function remove($files)
  44044. {
  44045. if ($files instanceof \Traversable) {
  44046. $files = iterator_to_array($files, false);
  44047. } elseif (!is_array($files)) {
  44048. $files = array($files);
  44049. }
  44050. $files = array_reverse($files);
  44051. foreach ($files as $file) {
  44052. if (is_link($file)) {
  44053. if (!@(unlink($file) || '\\' !== DIRECTORY_SEPARATOR || rmdir($file)) && file_exists($file)) {
  44054. $error = error_get_last();
  44055. throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message']));
  44056. }
  44057. } elseif (is_dir($file)) {
  44058. $this->remove(new \FilesystemIterator($file, \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::SKIP_DOTS));
  44059. if (!@rmdir($file) && file_exists($file)) {
  44060. $error = error_get_last();
  44061. throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message']));
  44062. }
  44063. } elseif (!@unlink($file) && file_exists($file)) {
  44064. $error = error_get_last();
  44065. throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message']));
  44066. }
  44067. }
  44068. }
  44069. public function chmod($files, $mode, $umask = 0000, $recursive = false)
  44070. {
  44071. foreach ($this->toIterable($files) as $file) {
  44072. if (true !== @chmod($file, $mode & ~$umask)) {
  44073. throw new IOException(sprintf('Failed to chmod file "%s".', $file), 0, null, $file);
  44074. }
  44075. if ($recursive && is_dir($file) && !is_link($file)) {
  44076. $this->chmod(new \FilesystemIterator($file), $mode, $umask, true);
  44077. }
  44078. }
  44079. }
  44080. public function chown($files, $user, $recursive = false)
  44081. {
  44082. foreach ($this->toIterable($files) as $file) {
  44083. if ($recursive && is_dir($file) && !is_link($file)) {
  44084. $this->chown(new \FilesystemIterator($file), $user, true);
  44085. }
  44086. if (is_link($file) && function_exists('lchown')) {
  44087. if (true !== @lchown($file, $user)) {
  44088. throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
  44089. }
  44090. } else {
  44091. if (true !== @chown($file, $user)) {
  44092. throw new IOException(sprintf('Failed to chown file "%s".', $file), 0, null, $file);
  44093. }
  44094. }
  44095. }
  44096. }
  44097. public function chgrp($files, $group, $recursive = false)
  44098. {
  44099. foreach ($this->toIterable($files) as $file) {
  44100. if ($recursive && is_dir($file) && !is_link($file)) {
  44101. $this->chgrp(new \FilesystemIterator($file), $group, true);
  44102. }
  44103. if (is_link($file) && function_exists('lchgrp')) {
  44104. if (true !== @lchgrp($file, $group) || (defined('HHVM_VERSION') && !posix_getgrnam($group))) {
  44105. throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
  44106. }
  44107. } else {
  44108. if (true !== @chgrp($file, $group)) {
  44109. throw new IOException(sprintf('Failed to chgrp file "%s".', $file), 0, null, $file);
  44110. }
  44111. }
  44112. }
  44113. }
  44114. public function rename($origin, $target, $overwrite = false)
  44115. {
  44116. if (!$overwrite && $this->isReadable($target)) {
  44117. throw new IOException(sprintf('Cannot rename because the target "%s" already exists.', $target), 0, null, $target);
  44118. }
  44119. if (true !== @rename($origin, $target)) {
  44120. if (is_dir($origin)) {
  44121. $this->mirror($origin, $target, null, array('override' => $overwrite, 'delete' => $overwrite));
  44122. $this->remove($origin);
  44123. return;
  44124. }
  44125. throw new IOException(sprintf('Cannot rename "%s" to "%s".', $origin, $target), 0, null, $target);
  44126. }
  44127. }
  44128. private function isReadable($filename)
  44129. {
  44130. $maxPathLength = PHP_MAXPATHLEN - 2;
  44131. if (strlen($filename) > $maxPathLength) {
  44132. throw new IOException(sprintf('Could not check if file is readable because path length exceeds %d characters.', $maxPathLength), 0, null, $filename);
  44133. }
  44134. return is_readable($filename);
  44135. }
  44136. public function symlink($originDir, $targetDir, $copyOnWindows = false)
  44137. {
  44138. if ('\\' === DIRECTORY_SEPARATOR) {
  44139. $originDir = strtr($originDir, '/', '\\');
  44140. $targetDir = strtr($targetDir, '/', '\\');
  44141. if ($copyOnWindows) {
  44142. $this->mirror($originDir, $targetDir);
  44143. return;
  44144. }
  44145. }
  44146. $this->mkdir(dirname($targetDir));
  44147. $ok = false;
  44148. if (is_link($targetDir)) {
  44149. if (readlink($targetDir) != $originDir) {
  44150. $this->remove($targetDir);
  44151. } else {
  44152. $ok = true;
  44153. }
  44154. }
  44155. if (!$ok && true !== @symlink($originDir, $targetDir)) {
  44156. $this->linkException($originDir, $targetDir, 'symbolic');
  44157. }
  44158. }
  44159. public function hardlink($originFile, $targetFiles)
  44160. {
  44161. if (!$this->exists($originFile)) {
  44162. throw new FileNotFoundException(null, 0, null, $originFile);
  44163. }
  44164. if (!is_file($originFile)) {
  44165. throw new FileNotFoundException(sprintf('Origin file "%s" is not a file', $originFile));
  44166. }
  44167. foreach ($this->toIterable($targetFiles) as $targetFile) {
  44168. if (is_file($targetFile)) {
  44169. if (fileinode($originFile) === fileinode($targetFile)) {
  44170. continue;
  44171. }
  44172. $this->remove($targetFile);
  44173. }
  44174. if (true !== @link($originFile, $targetFile)) {
  44175. $this->linkException($originFile, $targetFile, 'hard');
  44176. }
  44177. }
  44178. }
  44179. private function linkException($origin, $target, $linkType)
  44180. {
  44181. $report = error_get_last();
  44182. if (is_array($report)) {
  44183. if ('\\' === DIRECTORY_SEPARATOR && false !== strpos($report['message'], 'error code(1314)')) {
  44184. throw new IOException(sprintf('Unable to create %s link due to error code 1314: \'A required privilege is not held by the client\'. Do you have the required Administrator-rights?', $linkType), 0, null, $target);
  44185. }
  44186. }
  44187. throw new IOException(sprintf('Failed to create %s link from "%s" to "%s".', $linkType, $origin, $target), 0, null, $target);
  44188. }
  44189. public function readlink($path, $canonicalize = false)
  44190. {
  44191. if (!$canonicalize && !is_link($path)) {
  44192. return;
  44193. }
  44194. if ($canonicalize) {
  44195. if (!$this->exists($path)) {
  44196. return;
  44197. }
  44198. if ('\\' === DIRECTORY_SEPARATOR) {
  44199. $path = readlink($path);
  44200. }
  44201. return realpath($path);
  44202. }
  44203. if ('\\' === DIRECTORY_SEPARATOR) {
  44204. return realpath($path);
  44205. }
  44206. return readlink($path);
  44207. }
  44208. public function makePathRelative($endPath, $startPath)
  44209. {
  44210. if (!$this->isAbsolutePath($endPath) || !$this->isAbsolutePath($startPath)) {
  44211. @trigger_error(sprintf('Support for passing relative paths to %s() is deprecated since Symfony 3.4 and will be removed in 4.0.', __METHOD__), E_USER_DEPRECATED);
  44212. }
  44213. if ('\\' === DIRECTORY_SEPARATOR) {
  44214. $endPath = str_replace('\\', '/', $endPath);
  44215. $startPath = str_replace('\\', '/', $startPath);
  44216. }
  44217. $stripDriveLetter = function ($path) {
  44218. if (strlen($path) > 2 && ':' === $path[1] && '/' === $path[2] && ctype_alpha($path[0])) {
  44219. return substr($path, 2);
  44220. }
  44221. return $path;
  44222. };
  44223. $endPath = $stripDriveLetter($endPath);
  44224. $startPath = $stripDriveLetter($startPath);
  44225. $startPathArr = explode('/', trim($startPath, '/'));
  44226. $endPathArr = explode('/', trim($endPath, '/'));
  44227. $normalizePathArray = function ($pathSegments, $absolute) {
  44228. $result = array();
  44229. foreach ($pathSegments as $segment) {
  44230. if ('..' === $segment && ($absolute || count($result))) {
  44231. array_pop($result);
  44232. } elseif ('.' !== $segment) {
  44233. $result[] = $segment;
  44234. }
  44235. }
  44236. return $result;
  44237. };
  44238. $startPathArr = $normalizePathArray($startPathArr, static::isAbsolutePath($startPath));
  44239. $endPathArr = $normalizePathArray($endPathArr, static::isAbsolutePath($endPath));
  44240. $index = 0;
  44241. while (isset($startPathArr[$index]) && isset($endPathArr[$index]) && $startPathArr[$index] === $endPathArr[$index]) {
  44242. ++$index;
  44243. }
  44244. if (1 === count($startPathArr) && '' === $startPathArr[0]) {
  44245. $depth = 0;
  44246. } else {
  44247. $depth = count($startPathArr) - $index;
  44248. }
  44249. $traverser = str_repeat('../', $depth);
  44250. $endPathRemainder = implode('/', array_slice($endPathArr, $index));
  44251. $relativePath = $traverser.('' !== $endPathRemainder ? $endPathRemainder.'/' : '');
  44252. return '' === $relativePath ? './' : $relativePath;
  44253. }
  44254. public function mirror($originDir, $targetDir, \Traversable $iterator = null, $options = array())
  44255. {
  44256. $targetDir = rtrim($targetDir, '/\\');
  44257. $originDir = rtrim($originDir, '/\\');
  44258. $originDirLen = strlen($originDir);
  44259. if ($this->exists($targetDir) && isset($options['delete']) && $options['delete']) {
  44260. $deleteIterator = $iterator;
  44261. if (null === $deleteIterator) {
  44262. $flags = \FilesystemIterator::SKIP_DOTS;
  44263. $deleteIterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($targetDir, $flags), \RecursiveIteratorIterator::CHILD_FIRST);
  44264. }
  44265. $targetDirLen = strlen($targetDir);
  44266. foreach ($deleteIterator as $file) {
  44267. $origin = $originDir.substr($file->getPathname(), $targetDirLen);
  44268. if (!$this->exists($origin)) {
  44269. $this->remove($file);
  44270. }
  44271. }
  44272. }
  44273. $copyOnWindows = false;
  44274. if (isset($options['copy_on_windows'])) {
  44275. $copyOnWindows = $options['copy_on_windows'];
  44276. }
  44277. if (null === $iterator) {
  44278. $flags = $copyOnWindows ? \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::FOLLOW_SYMLINKS : \FilesystemIterator::SKIP_DOTS;
  44279. $iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($originDir, $flags), \RecursiveIteratorIterator::SELF_FIRST);
  44280. }
  44281. if ($this->exists($originDir)) {
  44282. $this->mkdir($targetDir);
  44283. }
  44284. foreach ($iterator as $file) {
  44285. $target = $targetDir.substr($file->getPathname(), $originDirLen);
  44286. if ($copyOnWindows) {
  44287. if (is_file($file)) {
  44288. $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
  44289. } elseif (is_dir($file)) {
  44290. $this->mkdir($target);
  44291. } else {
  44292. throw new IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
  44293. }
  44294. } else {
  44295. if (is_link($file)) {
  44296. $this->symlink($file->getLinkTarget(), $target);
  44297. } elseif (is_dir($file)) {
  44298. $this->mkdir($target);
  44299. } elseif (is_file($file)) {
  44300. $this->copy($file, $target, isset($options['override']) ? $options['override'] : false);
  44301. } else {
  44302. throw new IOException(sprintf('Unable to guess "%s" file type.', $file), 0, null, $file);
  44303. }
  44304. }
  44305. }
  44306. }
  44307. public function isAbsolutePath($file)
  44308. {
  44309. return strspn($file, '/\\', 0, 1)
  44310. || (strlen($file) > 3 && ctype_alpha($file[0])
  44311. && ':' === $file[1]
  44312. && strspn($file, '/\\', 2, 1)
  44313. )
  44314. || null !== parse_url($file, PHP_URL_SCHEME)
  44315. ;
  44316. }
  44317. public function tempnam($dir, $prefix)
  44318. {
  44319. list($scheme, $hierarchy) = $this->getSchemeAndHierarchy($dir);
  44320. if (null === $scheme || 'file' === $scheme || 'gs' === $scheme) {
  44321. $tmpFile = @tempnam($hierarchy, $prefix);
  44322. if (false !== $tmpFile) {
  44323. if (null !== $scheme && 'gs' !== $scheme) {
  44324. return $scheme.'://'.$tmpFile;
  44325. }
  44326. return $tmpFile;
  44327. }
  44328. throw new IOException('A temporary file could not be created.');
  44329. }
  44330. for ($i = 0; $i < 10; ++$i) {
  44331. $tmpFile = $dir.'/'.$prefix.uniqid(mt_rand(), true);
  44332. $handle = @fopen($tmpFile, 'x+');
  44333. if (false === $handle) {
  44334. continue;
  44335. }
  44336. @fclose($handle);
  44337. return $tmpFile;
  44338. }
  44339. throw new IOException('A temporary file could not be created.');
  44340. }
  44341. public function dumpFile($filename, $content)
  44342. {
  44343. $dir = dirname($filename);
  44344. if (!is_dir($dir)) {
  44345. $this->mkdir($dir);
  44346. }
  44347. if (!is_writable($dir)) {
  44348. throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
  44349. }
  44350. $tmpFile = $this->tempnam($dir, basename($filename));
  44351. if (false === @file_put_contents($tmpFile, $content)) {
  44352. throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
  44353. }
  44354. @chmod($tmpFile, file_exists($filename) ? fileperms($filename) : 0666 & ~umask());
  44355. $this->rename($tmpFile, $filename, true);
  44356. }
  44357. public function appendToFile($filename, $content)
  44358. {
  44359. $dir = dirname($filename);
  44360. if (!is_dir($dir)) {
  44361. $this->mkdir($dir);
  44362. }
  44363. if (!is_writable($dir)) {
  44364. throw new IOException(sprintf('Unable to write to the "%s" directory.', $dir), 0, null, $dir);
  44365. }
  44366. if (false === @file_put_contents($filename, $content, FILE_APPEND)) {
  44367. throw new IOException(sprintf('Failed to write file "%s".', $filename), 0, null, $filename);
  44368. }
  44369. }
  44370. private function toIterable($files)
  44371. {
  44372. return is_array($files) || $files instanceof \Traversable ? $files : array($files);
  44373. }
  44374. private function getSchemeAndHierarchy($filename)
  44375. {
  44376. $components = explode('://', $filename, 2);
  44377. return 2 === count($components) ? array($components[0], $components[1]) : array(null, $components[0]);
  44378. }
  44379. }
  44380. <?php
  44381. namespace Symfony\Component\Filesystem;
  44382. use Symfony\Component\Filesystem\Exception\IOException;
  44383. use Symfony\Component\Lock\Store\FlockStore;
  44384. use Symfony\Component\Lock\Store\SemaphoreStore;
  44385. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.4 and will be removed in 4.0. Use %s or %s instead.', LockHandler::class, SemaphoreStore::class, FlockStore::class), E_USER_DEPRECATED);
  44386. class LockHandler
  44387. {
  44388. private $file;
  44389. private $handle;
  44390. public function __construct($name, $lockPath = null)
  44391. {
  44392. $lockPath = $lockPath ?: sys_get_temp_dir();
  44393. if (!is_dir($lockPath)) {
  44394. $fs = new Filesystem();
  44395. $fs->mkdir($lockPath);
  44396. }
  44397. if (!is_writable($lockPath)) {
  44398. throw new IOException(sprintf('The directory "%s" is not writable.', $lockPath), 0, null, $lockPath);
  44399. }
  44400. $this->file = sprintf('%s/sf.%s.%s.lock', $lockPath, preg_replace('/[^a-z0-9\._-]+/i', '-', $name), hash('sha256', $name));
  44401. }
  44402. public function lock($blocking = false)
  44403. {
  44404. if ($this->handle) {
  44405. return true;
  44406. }
  44407. $error = null;
  44408. set_error_handler(function ($errno, $msg) use (&$error) {
  44409. $error = $msg;
  44410. });
  44411. if (!$this->handle = fopen($this->file, 'r')) {
  44412. if ($this->handle = fopen($this->file, 'x')) {
  44413. chmod($this->file, 0444);
  44414. } elseif (!$this->handle = fopen($this->file, 'r')) {
  44415. usleep(100);
  44416. $this->handle = fopen($this->file, 'r');
  44417. }
  44418. }
  44419. restore_error_handler();
  44420. if (!$this->handle) {
  44421. throw new IOException($error, 0, null, $this->file);
  44422. }
  44423. if (!flock($this->handle, LOCK_EX | ($blocking ? 0 : LOCK_NB))) {
  44424. fclose($this->handle);
  44425. $this->handle = null;
  44426. return false;
  44427. }
  44428. return true;
  44429. }
  44430. public function release()
  44431. {
  44432. if ($this->handle) {
  44433. flock($this->handle, LOCK_UN | LOCK_NB);
  44434. fclose($this->handle);
  44435. $this->handle = null;
  44436. }
  44437. }
  44438. }
  44439. <?php
  44440. namespace Symfony\Component\EventDispatcher;
  44441. use Symfony\Component\DependencyInjection\ContainerInterface;
  44442. class ContainerAwareEventDispatcher extends EventDispatcher
  44443. {
  44444. private $container;
  44445. private $listenerIds = array();
  44446. private $listeners = array();
  44447. public function __construct(ContainerInterface $container)
  44448. {
  44449. $this->container = $container;
  44450. $class = get_class($this);
  44451. if ($this instanceof \PHPUnit_Framework_MockObject_MockObject || $this instanceof \Prophecy\Doubler\DoubleInterface) {
  44452. $class = get_parent_class($class);
  44453. }
  44454. if (__CLASS__ !== $class) {
  44455. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED);
  44456. }
  44457. }
  44458. public function addListenerService($eventName, $callback, $priority = 0)
  44459. {
  44460. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED);
  44461. if (!is_array($callback) || 2 !== count($callback)) {
  44462. throw new \InvalidArgumentException('Expected an array("service", "method") argument');
  44463. }
  44464. $this->listenerIds[$eventName][] = array($callback[0], $callback[1], $priority);
  44465. }
  44466. public function removeListener($eventName, $listener)
  44467. {
  44468. $this->lazyLoad($eventName);
  44469. if (isset($this->listenerIds[$eventName])) {
  44470. foreach ($this->listenerIds[$eventName] as $i => list($serviceId, $method)) {
  44471. $key = $serviceId.'.'.$method;
  44472. if (isset($this->listeners[$eventName][$key]) && $listener === array($this->listeners[$eventName][$key], $method)) {
  44473. unset($this->listeners[$eventName][$key]);
  44474. if (empty($this->listeners[$eventName])) {
  44475. unset($this->listeners[$eventName]);
  44476. }
  44477. unset($this->listenerIds[$eventName][$i]);
  44478. if (empty($this->listenerIds[$eventName])) {
  44479. unset($this->listenerIds[$eventName]);
  44480. }
  44481. }
  44482. }
  44483. }
  44484. parent::removeListener($eventName, $listener);
  44485. }
  44486. public function hasListeners($eventName = null)
  44487. {
  44488. if (null === $eventName) {
  44489. return $this->listenerIds || $this->listeners || parent::hasListeners();
  44490. }
  44491. if (isset($this->listenerIds[$eventName])) {
  44492. return true;
  44493. }
  44494. return parent::hasListeners($eventName);
  44495. }
  44496. public function getListeners($eventName = null)
  44497. {
  44498. if (null === $eventName) {
  44499. foreach ($this->listenerIds as $serviceEventName => $args) {
  44500. $this->lazyLoad($serviceEventName);
  44501. }
  44502. } else {
  44503. $this->lazyLoad($eventName);
  44504. }
  44505. return parent::getListeners($eventName);
  44506. }
  44507. public function getListenerPriority($eventName, $listener)
  44508. {
  44509. $this->lazyLoad($eventName);
  44510. return parent::getListenerPriority($eventName, $listener);
  44511. }
  44512. public function addSubscriberService($serviceId, $class)
  44513. {
  44514. @trigger_error(sprintf('The %s class is deprecated since Symfony 3.3 and will be removed in 4.0. Use EventDispatcher with closure factories instead.', __CLASS__), E_USER_DEPRECATED);
  44515. foreach ($class::getSubscribedEvents() as $eventName => $params) {
  44516. if (is_string($params)) {
  44517. $this->listenerIds[$eventName][] = array($serviceId, $params, 0);
  44518. } elseif (is_string($params[0])) {
  44519. $this->listenerIds[$eventName][] = array($serviceId, $params[0], isset($params[1]) ? $params[1] : 0);
  44520. } else {
  44521. foreach ($params as $listener) {
  44522. $this->listenerIds[$eventName][] = array($serviceId, $listener[0], isset($listener[1]) ? $listener[1] : 0);
  44523. }
  44524. }
  44525. }
  44526. }
  44527. public function getContainer()
  44528. {
  44529. @trigger_error('The '.__METHOD__.'() method is deprecated since Symfony 3.3 as its class will be removed in 4.0. Inject the container or the services you need in your listeners/subscribers instead.', E_USER_DEPRECATED);
  44530. return $this->container;
  44531. }
  44532. protected function lazyLoad($eventName)
  44533. {
  44534. if (isset($this->listenerIds[$eventName])) {
  44535. foreach ($this->listenerIds[$eventName] as list($serviceId, $method, $priority)) {
  44536. $listener = $this->container->get($serviceId);
  44537. $key = $serviceId.'.'.$method;
  44538. if (!isset($this->listeners[$eventName][$key])) {
  44539. $this->addListener($eventName, array($listener, $method), $priority);
  44540. } elseif ($this->listeners[$eventName][$key] !== $listener) {
  44541. parent::removeListener($eventName, array($this->listeners[$eventName][$key], $method));
  44542. $this->addListener($eventName, array($listener, $method), $priority);
  44543. }
  44544. $this->listeners[$eventName][$key] = $listener;
  44545. }
  44546. }
  44547. }
  44548. }
  44549. <?php
  44550. namespace Symfony\Component\EventDispatcher\Debug;
  44551. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  44552. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  44553. use Symfony\Component\EventDispatcher\Event;
  44554. use Symfony\Component\Stopwatch\Stopwatch;
  44555. use Psr\Log\LoggerInterface;
  44556. class TraceableEventDispatcher implements TraceableEventDispatcherInterface
  44557. {
  44558. protected $logger;
  44559. protected $stopwatch;
  44560. private $called;
  44561. private $dispatcher;
  44562. private $wrappedListeners;
  44563. public function __construct(EventDispatcherInterface $dispatcher, Stopwatch $stopwatch, LoggerInterface $logger = null)
  44564. {
  44565. $this->dispatcher = $dispatcher;
  44566. $this->stopwatch = $stopwatch;
  44567. $this->logger = $logger;
  44568. $this->called = array();
  44569. $this->wrappedListeners = array();
  44570. }
  44571. public function addListener($eventName, $listener, $priority = 0)
  44572. {
  44573. $this->dispatcher->addListener($eventName, $listener, $priority);
  44574. }
  44575. public function addSubscriber(EventSubscriberInterface $subscriber)
  44576. {
  44577. $this->dispatcher->addSubscriber($subscriber);
  44578. }
  44579. public function removeListener($eventName, $listener)
  44580. {
  44581. if (isset($this->wrappedListeners[$eventName])) {
  44582. foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
  44583. if ($wrappedListener->getWrappedListener() === $listener) {
  44584. $listener = $wrappedListener;
  44585. unset($this->wrappedListeners[$eventName][$index]);
  44586. break;
  44587. }
  44588. }
  44589. }
  44590. return $this->dispatcher->removeListener($eventName, $listener);
  44591. }
  44592. public function removeSubscriber(EventSubscriberInterface $subscriber)
  44593. {
  44594. return $this->dispatcher->removeSubscriber($subscriber);
  44595. }
  44596. public function getListeners($eventName = null)
  44597. {
  44598. return $this->dispatcher->getListeners($eventName);
  44599. }
  44600. public function getListenerPriority($eventName, $listener)
  44601. {
  44602. if (isset($this->wrappedListeners[$eventName])) {
  44603. foreach ($this->wrappedListeners[$eventName] as $index => $wrappedListener) {
  44604. if ($wrappedListener->getWrappedListener() === $listener) {
  44605. return $this->dispatcher->getListenerPriority($eventName, $wrappedListener);
  44606. }
  44607. }
  44608. }
  44609. return $this->dispatcher->getListenerPriority($eventName, $listener);
  44610. }
  44611. public function hasListeners($eventName = null)
  44612. {
  44613. return $this->dispatcher->hasListeners($eventName);
  44614. }
  44615. public function dispatch($eventName, Event $event = null)
  44616. {
  44617. if (null === $event) {
  44618. $event = new Event();
  44619. }
  44620. if (null !== $this->logger && $event->isPropagationStopped()) {
  44621. $this->logger->debug(sprintf('The "%s" event is already stopped. No listeners have been called.', $eventName));
  44622. }
  44623. $this->preProcess($eventName);
  44624. $this->preDispatch($eventName, $event);
  44625. $e = $this->stopwatch->start($eventName, 'section');
  44626. $this->dispatcher->dispatch($eventName, $event);
  44627. if ($e->isStarted()) {
  44628. $e->stop();
  44629. }
  44630. $this->postDispatch($eventName, $event);
  44631. $this->postProcess($eventName);
  44632. return $event;
  44633. }
  44634. public function getCalledListeners()
  44635. {
  44636. $called = array();
  44637. foreach ($this->called as $eventName => $listeners) {
  44638. foreach ($listeners as $listener) {
  44639. $called[$eventName.'.'.$listener->getPretty()] = $listener->getInfo($eventName);
  44640. }
  44641. }
  44642. return $called;
  44643. }
  44644. public function getNotCalledListeners()
  44645. {
  44646. try {
  44647. $allListeners = $this->getListeners();
  44648. } catch (\Exception $e) {
  44649. if (null !== $this->logger) {
  44650. $this->logger->info('An exception was thrown while getting the uncalled listeners.', array('exception' => $e));
  44651. }
  44652. return array();
  44653. }
  44654. $notCalled = array();
  44655. foreach ($allListeners as $eventName => $listeners) {
  44656. foreach ($listeners as $listener) {
  44657. $called = false;
  44658. if (isset($this->called[$eventName])) {
  44659. foreach ($this->called[$eventName] as $l) {
  44660. if ($l->getWrappedListener() === $listener) {
  44661. $called = true;
  44662. break;
  44663. }
  44664. }
  44665. }
  44666. if (!$called) {
  44667. if (!$listener instanceof WrappedListener) {
  44668. $listener = new WrappedListener($listener, null, $this->stopwatch, $this);
  44669. }
  44670. $notCalled[$eventName.'.'.$listener->getPretty()] = $listener->getInfo($eventName);
  44671. }
  44672. }
  44673. }
  44674. uasort($notCalled, array($this, 'sortListenersByPriority'));
  44675. return $notCalled;
  44676. }
  44677. public function reset()
  44678. {
  44679. $this->called = array();
  44680. }
  44681. public function __call($method, $arguments)
  44682. {
  44683. return call_user_func_array(array($this->dispatcher, $method), $arguments);
  44684. }
  44685. protected function preDispatch($eventName, Event $event)
  44686. {
  44687. }
  44688. protected function postDispatch($eventName, Event $event)
  44689. {
  44690. }
  44691. private function preProcess($eventName)
  44692. {
  44693. foreach ($this->dispatcher->getListeners($eventName) as $listener) {
  44694. $priority = $this->getListenerPriority($eventName, $listener);
  44695. $wrappedListener = new WrappedListener($listener, null, $this->stopwatch, $this);
  44696. $this->wrappedListeners[$eventName][] = $wrappedListener;
  44697. $this->dispatcher->removeListener($eventName, $listener);
  44698. $this->dispatcher->addListener($eventName, $wrappedListener, $priority);
  44699. }
  44700. }
  44701. private function postProcess($eventName)
  44702. {
  44703. unset($this->wrappedListeners[$eventName]);
  44704. $skipped = false;
  44705. foreach ($this->dispatcher->getListeners($eventName) as $listener) {
  44706. if (!$listener instanceof WrappedListener) {
  44707. continue;
  44708. }
  44709. $priority = $this->getListenerPriority($eventName, $listener);
  44710. $this->dispatcher->removeListener($eventName, $listener);
  44711. $this->dispatcher->addListener($eventName, $listener->getWrappedListener(), $priority);
  44712. if (null !== $this->logger) {
  44713. $context = array('event' => $eventName, 'listener' => $listener->getPretty());
  44714. }
  44715. if ($listener->wasCalled()) {
  44716. if (null !== $this->logger) {
  44717. $this->logger->debug('Notified event "{event}" to listener "{listener}".', $context);
  44718. }
  44719. if (!isset($this->called[$eventName])) {
  44720. $this->called[$eventName] = new \SplObjectStorage();
  44721. }
  44722. $this->called[$eventName]->attach($listener);
  44723. }
  44724. if (null !== $this->logger && $skipped) {
  44725. $this->logger->debug('Listener "{listener}" was not called for event "{event}".', $context);
  44726. }
  44727. if ($listener->stoppedPropagation()) {
  44728. if (null !== $this->logger) {
  44729. $this->logger->debug('Listener "{listener}" stopped propagation of the event "{event}".', $context);
  44730. }
  44731. $skipped = true;
  44732. }
  44733. }
  44734. }
  44735. private function sortListenersByPriority($a, $b)
  44736. {
  44737. if (is_int($a['priority']) && !is_int($b['priority'])) {
  44738. return 1;
  44739. }
  44740. if (!is_int($a['priority']) && is_int($b['priority'])) {
  44741. return -1;
  44742. }
  44743. if ($a['priority'] === $b['priority']) {
  44744. return 0;
  44745. }
  44746. if ($a['priority'] > $b['priority']) {
  44747. return -1;
  44748. }
  44749. return 1;
  44750. }
  44751. }
  44752. <?php
  44753. namespace Symfony\Component\EventDispatcher\Debug;
  44754. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  44755. interface TraceableEventDispatcherInterface extends EventDispatcherInterface
  44756. {
  44757. public function getCalledListeners();
  44758. public function getNotCalledListeners();
  44759. }
  44760. <?php
  44761. namespace Symfony\Component\EventDispatcher\Debug;
  44762. use Symfony\Component\Stopwatch\Stopwatch;
  44763. use Symfony\Component\EventDispatcher\Event;
  44764. use Symfony\Component\EventDispatcher\EventDispatcherInterface;
  44765. use Symfony\Component\VarDumper\Caster\ClassStub;
  44766. class WrappedListener
  44767. {
  44768. private $listener;
  44769. private $name;
  44770. private $called;
  44771. private $stoppedPropagation;
  44772. private $stopwatch;
  44773. private $dispatcher;
  44774. private $pretty;
  44775. private $stub;
  44776. private static $hasClassStub;
  44777. public function __construct($listener, $name, Stopwatch $stopwatch, EventDispatcherInterface $dispatcher = null)
  44778. {
  44779. $this->listener = $listener;
  44780. $this->name = $name;
  44781. $this->stopwatch = $stopwatch;
  44782. $this->dispatcher = $dispatcher;
  44783. $this->called = false;
  44784. $this->stoppedPropagation = false;
  44785. if (is_array($listener)) {
  44786. $this->name = is_object($listener[0]) ? get_class($listener[0]) : $listener[0];
  44787. $this->pretty = $this->name.'::'.$listener[1];
  44788. } elseif ($listener instanceof \Closure) {
  44789. $this->pretty = $this->name = 'closure';
  44790. } elseif (is_string($listener)) {
  44791. $this->pretty = $this->name = $listener;
  44792. } else {
  44793. $this->name = get_class($listener);
  44794. $this->pretty = $this->name.'::__invoke';
  44795. }
  44796. if (null !== $name) {
  44797. $this->name = $name;
  44798. }
  44799. if (null === self::$hasClassStub) {
  44800. self::$hasClassStub = class_exists(ClassStub::class);
  44801. }
  44802. }
  44803. public function getWrappedListener()
  44804. {
  44805. return $this->listener;
  44806. }
  44807. public function wasCalled()
  44808. {
  44809. return $this->called;
  44810. }
  44811. public function stoppedPropagation()
  44812. {
  44813. return $this->stoppedPropagation;
  44814. }
  44815. public function getPretty()
  44816. {
  44817. return $this->pretty;
  44818. }
  44819. public function getInfo($eventName)
  44820. {
  44821. if (null === $this->stub) {
  44822. $this->stub = self::$hasClassStub ? new ClassStub($this->pretty.'()', $this->listener) : $this->pretty.'()';
  44823. }
  44824. return array(
  44825. 'event' => $eventName,
  44826. 'priority' => null !== $this->dispatcher ? $this->dispatcher->getListenerPriority($eventName, $this->listener) : null,
  44827. 'pretty' => $this->pretty,
  44828. 'stub' => $this->stub,
  44829. );
  44830. }
  44831. public function __invoke(Event $event, $eventName, EventDispatcherInterface $dispatcher)
  44832. {
  44833. $this->called = true;
  44834. $e = $this->stopwatch->start($this->name, 'event_listener');
  44835. call_user_func($this->listener, $event, $eventName, $this->dispatcher ?: $dispatcher);
  44836. if ($e->isStarted()) {
  44837. $e->stop();
  44838. }
  44839. if ($event->isPropagationStopped()) {
  44840. $this->stoppedPropagation = true;
  44841. }
  44842. }
  44843. }
  44844. <?php
  44845. namespace Symfony\Component\EventDispatcher\DependencyInjection;
  44846. use Symfony\Component\DependencyInjection\Argument\ServiceClosureArgument;
  44847. use Symfony\Component\DependencyInjection\ContainerBuilder;
  44848. use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
  44849. use Symfony\Component\DependencyInjection\Exception\InvalidArgumentException;
  44850. use Symfony\Component\DependencyInjection\Reference;
  44851. use Symfony\Component\EventDispatcher\EventDispatcher;
  44852. use Symfony\Component\EventDispatcher\EventSubscriberInterface;
  44853. class RegisterListenersPass implements CompilerPassInterface
  44854. {
  44855. protected $dispatcherService;
  44856. protected $listenerTag;
  44857. protected $subscriberTag;
  44858. private $hotPathEvents = array();
  44859. private $hotPathTagName;
  44860. public function __construct($dispatcherService = 'event_dispatcher', $listenerTag = 'kernel.event_listener', $subscriberTag = 'kernel.event_subscriber')
  44861. {
  44862. $this->dispatcherService = $dispatcherService;
  44863. $this->listenerTag = $listenerTag;
  44864. $this->subscriberTag = $subscriberTag;
  44865. }
  44866. public function setHotPathEvents(array $hotPathEvents, $tagName = 'container.hot_path')
  44867. {
  44868. $this->hotPathEvents = array_flip($hotPathEvents);
  44869. $this->hotPathTagName = $tagName;
  44870. return $this;
  44871. }
  44872. public function process(ContainerBuilder $container)
  44873. {
  44874. if (!$container->hasDefinition($this->dispatcherService) && !$container->hasAlias($this->dispatcherService)) {
  44875. return;
  44876. }
  44877. $definition = $container->findDefinition($this->dispatcherService);
  44878. foreach ($container->findTaggedServiceIds($this->listenerTag, true) as $id => $events) {
  44879. foreach ($events as $event) {
  44880. $priority = isset($event['priority']) ? $event['priority'] : 0;
  44881. if (!isset($event['event'])) {
  44882. throw new InvalidArgumentException(sprintf('Service "%s" must define the "event" attribute on "%s" tags.', $id, $this->listenerTag));
  44883. }
  44884. if (!isset($event['method'])) {
  44885. $event['method'] = 'on'.preg_replace_callback(array(
  44886. '/(?<=\b)[a-z]/i',
  44887. '/[^a-z0-9]/i',
  44888. ), function ($matches) { return strtoupper($matches[0]); }, $event['event']);
  44889. $event['method'] = preg_replace('/[^a-z0-9]/i', '', $event['method']);
  44890. }
  44891. $definition->addMethodCall('addListener', array($event['event'], array(new ServiceClosureArgument(new Reference($id)), $event['method']), $priority));
  44892. if (isset($this->hotPathEvents[$event['event']])) {
  44893. $container->getDefinition($id)->addTag($this->hotPathTagName);
  44894. }
  44895. }
  44896. }
  44897. $extractingDispatcher = new ExtractingEventDispatcher();
  44898. foreach ($container->findTaggedServiceIds($this->subscriberTag, true) as $id => $attributes) {
  44899. $def = $container->getDefinition($id);
  44900. $class = $container->getParameterBag()->resolveValue($def->getClass());
  44901. $interface = 'Symfony\Component\EventDispatcher\EventSubscriberInterface';
  44902. if (!is_subclass_of($class, $interface)) {
  44903. if (!class_exists($class, false)) {
  44904. throw new InvalidArgumentException(sprintf('Class "%s" used for service "%s" cannot be found.', $class, $id));
  44905. }
  44906. throw new InvalidArgumentException(sprintf('Service "%s" must implement interface "%s".', $id, $interface));
  44907. }
  44908. $container->addObjectResource($class);
  44909. ExtractingEventDispatcher::$subscriber = $class;
  44910. $extractingDispatcher->addSubscriber($extractingDispatcher);
  44911. foreach ($extractingDispatcher->listeners as $args) {
  44912. $args[1] = array(new ServiceClosureArgument(new Reference($id)), $args[1]);
  44913. $definition->addMethodCall('addListener', $args);
  44914. if (isset($this->hotPathEvents[$args[0]])) {
  44915. $container->getDefinition($id)->addTag('container.hot_path');
  44916. }
  44917. }
  44918. $extractingDispatcher->listeners = array();
  44919. }
  44920. }
  44921. }
  44922. class ExtractingEventDispatcher extends EventDispatcher implements EventSubscriberInterface
  44923. {
  44924. public $listeners = array();
  44925. public static $subscriber;
  44926. public function addListener($eventName, $listener, $priority = 0)
  44927. {
  44928. $this->listeners[] = array($eventName, $listener[1], $priority);
  44929. }
  44930. public static function getSubscribedEvents()
  44931. {
  44932. $callback = array(self::$subscriber, 'getSubscribedEvents');
  44933. return $callback();
  44934. }
  44935. }
  44936. <?php
  44937. namespace Symfony\Component\EventDispatcher;
  44938. class Event
  44939. {
  44940. private $propagationStopped = false;
  44941. public function isPropagationStopped()
  44942. {
  44943. return $this->propagationStopped;
  44944. }
  44945. public function stopPropagation()
  44946. {
  44947. $this->propagationStopped = true;
  44948. }
  44949. }
  44950. <?php
  44951. namespace Symfony\Component\EventDispatcher;
  44952. class EventDispatcher implements EventDispatcherInterface
  44953. {
  44954. private $listeners = array();
  44955. private $sorted = array();
  44956. public function dispatch($eventName, Event $event = null)
  44957. {
  44958. if (null === $event) {
  44959. $event = new Event();
  44960. }
  44961. if ($listeners = $this->getListeners($eventName)) {
  44962. $this->doDispatch($listeners, $eventName, $event);
  44963. }
  44964. return $event;
  44965. }
  44966. public function getListeners($eventName = null)
  44967. {
  44968. if (null !== $eventName) {
  44969. if (empty($this->listeners[$eventName])) {
  44970. return array();
  44971. }
  44972. if (!isset($this->sorted[$eventName])) {
  44973. $this->sortListeners($eventName);
  44974. }
  44975. return $this->sorted[$eventName];
  44976. }
  44977. foreach ($this->listeners as $eventName => $eventListeners) {
  44978. if (!isset($this->sorted[$eventName])) {
  44979. $this->sortListeners($eventName);
  44980. }
  44981. }
  44982. return array_filter($this->sorted);
  44983. }
  44984. public function getListenerPriority($eventName, $listener)
  44985. {
  44986. if (empty($this->listeners[$eventName])) {
  44987. return;
  44988. }
  44989. if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
  44990. $listener[0] = $listener[0]();
  44991. }
  44992. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  44993. foreach ($listeners as $k => $v) {
  44994. if ($v !== $listener && is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) {
  44995. $v[0] = $v[0]();
  44996. $this->listeners[$eventName][$priority][$k] = $v;
  44997. }
  44998. if ($v === $listener) {
  44999. return $priority;
  45000. }
  45001. }
  45002. }
  45003. }
  45004. public function hasListeners($eventName = null)
  45005. {
  45006. if (null !== $eventName) {
  45007. return !empty($this->listeners[$eventName]);
  45008. }
  45009. foreach ($this->listeners as $eventListeners) {
  45010. if ($eventListeners) {
  45011. return true;
  45012. }
  45013. }
  45014. return false;
  45015. }
  45016. public function addListener($eventName, $listener, $priority = 0)
  45017. {
  45018. $this->listeners[$eventName][$priority][] = $listener;
  45019. unset($this->sorted[$eventName]);
  45020. }
  45021. public function removeListener($eventName, $listener)
  45022. {
  45023. if (empty($this->listeners[$eventName])) {
  45024. return;
  45025. }
  45026. if (is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
  45027. $listener[0] = $listener[0]();
  45028. }
  45029. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  45030. foreach ($listeners as $k => $v) {
  45031. if ($v !== $listener && is_array($v) && isset($v[0]) && $v[0] instanceof \Closure) {
  45032. $v[0] = $v[0]();
  45033. }
  45034. if ($v === $listener) {
  45035. unset($listeners[$k], $this->sorted[$eventName]);
  45036. } else {
  45037. $listeners[$k] = $v;
  45038. }
  45039. }
  45040. if ($listeners) {
  45041. $this->listeners[$eventName][$priority] = $listeners;
  45042. } else {
  45043. unset($this->listeners[$eventName][$priority]);
  45044. }
  45045. }
  45046. }
  45047. public function addSubscriber(EventSubscriberInterface $subscriber)
  45048. {
  45049. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  45050. if (is_string($params)) {
  45051. $this->addListener($eventName, array($subscriber, $params));
  45052. } elseif (is_string($params[0])) {
  45053. $this->addListener($eventName, array($subscriber, $params[0]), isset($params[1]) ? $params[1] : 0);
  45054. } else {
  45055. foreach ($params as $listener) {
  45056. $this->addListener($eventName, array($subscriber, $listener[0]), isset($listener[1]) ? $listener[1] : 0);
  45057. }
  45058. }
  45059. }
  45060. }
  45061. public function removeSubscriber(EventSubscriberInterface $subscriber)
  45062. {
  45063. foreach ($subscriber->getSubscribedEvents() as $eventName => $params) {
  45064. if (is_array($params) && is_array($params[0])) {
  45065. foreach ($params as $listener) {
  45066. $this->removeListener($eventName, array($subscriber, $listener[0]));
  45067. }
  45068. } else {
  45069. $this->removeListener($eventName, array($subscriber, is_string($params) ? $params : $params[0]));
  45070. }
  45071. }
  45072. }
  45073. protected function doDispatch($listeners, $eventName, Event $event)
  45074. {
  45075. foreach ($listeners as $listener) {
  45076. if ($event->isPropagationStopped()) {
  45077. break;
  45078. }
  45079. \call_user_func($listener, $event, $eventName, $this);
  45080. }
  45081. }
  45082. private function sortListeners($eventName)
  45083. {
  45084. krsort($this->listeners[$eventName]);
  45085. $this->sorted[$eventName] = array();
  45086. foreach ($this->listeners[$eventName] as $priority => $listeners) {
  45087. foreach ($listeners as $k => $listener) {
  45088. if (\is_array($listener) && isset($listener[0]) && $listener[0] instanceof \Closure) {
  45089. $listener[0] = $listener[0]();
  45090. $this->listeners[$eventName][$priority][$k] = $listener;
  45091. }
  45092. $this->sorted[$eventName][] = $listener;
  45093. }
  45094. }
  45095. }
  45096. }
  45097. <?php
  45098. namespace Symfony\Component\EventDispatcher;
  45099. interface EventDispatcherInterface
  45100. {
  45101. public function dispatch($eventName, Event $event = null);
  45102. public function addListener($eventName, $listener, $priority = 0);
  45103. public function addSubscriber(EventSubscriberInterface $subscriber);
  45104. public function removeListener($eventName, $listener);
  45105. public function removeSubscriber(EventSubscriberInterface $subscriber);
  45106. public function getListeners($eventName = null);
  45107. public function getListenerPriority($eventName, $listener);
  45108. public function hasListeners($eventName = null);
  45109. }
  45110. <?php
  45111. namespace Symfony\Component\EventDispatcher;
  45112. interface EventSubscriberInterface
  45113. {
  45114. public static function getSubscribedEvents();
  45115. }
  45116. <?php
  45117. namespace Symfony\Component\EventDispatcher;
  45118. class GenericEvent extends Event implements \ArrayAccess, \IteratorAggregate
  45119. {
  45120. protected $subject;
  45121. protected $arguments;
  45122. public function __construct($subject = null, array $arguments = array())
  45123. {
  45124. $this->subject = $subject;
  45125. $this->arguments = $arguments;
  45126. }
  45127. public function getSubject()
  45128. {
  45129. return $this->subject;
  45130. }
  45131. public function getArgument($key)
  45132. {
  45133. if ($this->hasArgument($key)) {
  45134. return $this->arguments[$key];
  45135. }
  45136. throw new \InvalidArgumentException(sprintf('Argument "%s" not found.', $key));
  45137. }
  45138. public function setArgument($key, $value)
  45139. {
  45140. $this->arguments[$key] = $value;
  45141. return $this;
  45142. }
  45143. public function getArguments()
  45144. {
  45145. return $this->arguments;
  45146. }
  45147. public function setArguments(array $args = array())
  45148. {
  45149. $this->arguments = $args;
  45150. return $this;
  45151. }
  45152. public function hasArgument($key)
  45153. {
  45154. return array_key_exists($key, $this->arguments);
  45155. }
  45156. public function offsetGet($key)
  45157. {
  45158. return $this->getArgument($key);
  45159. }
  45160. public function offsetSet($key, $value)
  45161. {
  45162. $this->setArgument($key, $value);
  45163. }
  45164. public function offsetUnset($key)
  45165. {
  45166. if ($this->hasArgument($key)) {
  45167. unset($this->arguments[$key]);
  45168. }
  45169. }
  45170. public function offsetExists($key)
  45171. {
  45172. return $this->hasArgument($key);
  45173. }
  45174. public function getIterator()
  45175. {
  45176. return new \ArrayIterator($this->arguments);
  45177. }
  45178. }
  45179. <?php
  45180. namespace Symfony\Component\EventDispatcher;
  45181. class ImmutableEventDispatcher implements EventDispatcherInterface
  45182. {
  45183. private $dispatcher;
  45184. public function __construct(EventDispatcherInterface $dispatcher)
  45185. {
  45186. $this->dispatcher = $dispatcher;
  45187. }
  45188. public function dispatch($eventName, Event $event = null)
  45189. {
  45190. return $this->dispatcher->dispatch($eventName, $event);
  45191. }
  45192. public function addListener($eventName, $listener, $priority = 0)
  45193. {
  45194. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  45195. }
  45196. public function addSubscriber(EventSubscriberInterface $subscriber)
  45197. {
  45198. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  45199. }
  45200. public function removeListener($eventName, $listener)
  45201. {
  45202. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  45203. }
  45204. public function removeSubscriber(EventSubscriberInterface $subscriber)
  45205. {
  45206. throw new \BadMethodCallException('Unmodifiable event dispatchers must not be modified.');
  45207. }
  45208. public function getListeners($eventName = null)
  45209. {
  45210. return $this->dispatcher->getListeners($eventName);
  45211. }
  45212. public function getListenerPriority($eventName, $listener)
  45213. {
  45214. return $this->dispatcher->getListenerPriority($eventName, $listener);
  45215. }
  45216. public function hasListeners($eventName = null)
  45217. {
  45218. return $this->dispatcher->hasListeners($eventName);
  45219. }
  45220. }
  45221. <?php
  45222. namespace Symfony\Component\Finder\Comparator;
  45223. class Comparator
  45224. {
  45225. private $target;
  45226. private $operator = '==';
  45227. public function getTarget()
  45228. {
  45229. return $this->target;
  45230. }
  45231. public function setTarget($target)
  45232. {
  45233. $this->target = $target;
  45234. }
  45235. public function getOperator()
  45236. {
  45237. return $this->operator;
  45238. }
  45239. public function setOperator($operator)
  45240. {
  45241. if (!$operator) {
  45242. $operator = '==';
  45243. }
  45244. if (!in_array($operator, array('>', '<', '>=', '<=', '==', '!='))) {
  45245. throw new \InvalidArgumentException(sprintf('Invalid operator "%s".', $operator));
  45246. }
  45247. $this->operator = $operator;
  45248. }
  45249. public function test($test)
  45250. {
  45251. switch ($this->operator) {
  45252. case '>':
  45253. return $test > $this->target;
  45254. case '>=':
  45255. return $test >= $this->target;
  45256. case '<':
  45257. return $test < $this->target;
  45258. case '<=':
  45259. return $test <= $this->target;
  45260. case '!=':
  45261. return $test != $this->target;
  45262. }
  45263. return $test == $this->target;
  45264. }
  45265. }
  45266. <?php
  45267. namespace Symfony\Component\Finder\Comparator;
  45268. class DateComparator extends Comparator
  45269. {
  45270. public function __construct($test)
  45271. {
  45272. if (!preg_match('#^\s*(==|!=|[<>]=?|after|since|before|until)?\s*(.+?)\s*$#i', $test, $matches)) {
  45273. throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a date test.', $test));
  45274. }
  45275. try {
  45276. $date = new \DateTime($matches[2]);
  45277. $target = $date->format('U');
  45278. } catch (\Exception $e) {
  45279. throw new \InvalidArgumentException(sprintf('"%s" is not a valid date.', $matches[2]));
  45280. }
  45281. $operator = isset($matches[1]) ? $matches[1] : '==';
  45282. if ('since' === $operator || 'after' === $operator) {
  45283. $operator = '>';
  45284. }
  45285. if ('until' === $operator || 'before' === $operator) {
  45286. $operator = '<';
  45287. }
  45288. $this->setOperator($operator);
  45289. $this->setTarget($target);
  45290. }
  45291. }
  45292. <?php
  45293. namespace Symfony\Component\Finder\Comparator;
  45294. class NumberComparator extends Comparator
  45295. {
  45296. public function __construct($test)
  45297. {
  45298. if (!preg_match('#^\s*(==|!=|[<>]=?)?\s*([0-9\.]+)\s*([kmg]i?)?\s*$#i', $test, $matches)) {
  45299. throw new \InvalidArgumentException(sprintf('Don\'t understand "%s" as a number test.', $test));
  45300. }
  45301. $target = $matches[2];
  45302. if (!is_numeric($target)) {
  45303. throw new \InvalidArgumentException(sprintf('Invalid number "%s".', $target));
  45304. }
  45305. if (isset($matches[3])) {
  45306. switch (strtolower($matches[3])) {
  45307. case 'k':
  45308. $target *= 1000;
  45309. break;
  45310. case 'ki':
  45311. $target *= 1024;
  45312. break;
  45313. case 'm':
  45314. $target *= 1000000;
  45315. break;
  45316. case 'mi':
  45317. $target *= 1024 * 1024;
  45318. break;
  45319. case 'g':
  45320. $target *= 1000000000;
  45321. break;
  45322. case 'gi':
  45323. $target *= 1024 * 1024 * 1024;
  45324. break;
  45325. }
  45326. }
  45327. $this->setTarget($target);
  45328. $this->setOperator(isset($matches[1]) ? $matches[1] : '==');
  45329. }
  45330. }
  45331. <?php
  45332. namespace Symfony\Component\Finder\Exception;
  45333. class AccessDeniedException extends \UnexpectedValueException
  45334. {
  45335. }
  45336. <?php
  45337. namespace Symfony\Component\Finder\Exception;
  45338. interface ExceptionInterface
  45339. {
  45340. public function getAdapter();
  45341. }
  45342. <?php
  45343. namespace Symfony\Component\Finder;
  45344. use Symfony\Component\Finder\Comparator\DateComparator;
  45345. use Symfony\Component\Finder\Comparator\NumberComparator;
  45346. use Symfony\Component\Finder\Iterator\CustomFilterIterator;
  45347. use Symfony\Component\Finder\Iterator\DateRangeFilterIterator;
  45348. use Symfony\Component\Finder\Iterator\DepthRangeFilterIterator;
  45349. use Symfony\Component\Finder\Iterator\ExcludeDirectoryFilterIterator;
  45350. use Symfony\Component\Finder\Iterator\FilecontentFilterIterator;
  45351. use Symfony\Component\Finder\Iterator\FilenameFilterIterator;
  45352. use Symfony\Component\Finder\Iterator\SizeRangeFilterIterator;
  45353. use Symfony\Component\Finder\Iterator\SortableIterator;
  45354. class Finder implements \IteratorAggregate, \Countable
  45355. {
  45356. const IGNORE_VCS_FILES = 1;
  45357. const IGNORE_DOT_FILES = 2;
  45358. private $mode = 0;
  45359. private $names = array();
  45360. private $notNames = array();
  45361. private $exclude = array();
  45362. private $filters = array();
  45363. private $depths = array();
  45364. private $sizes = array();
  45365. private $followLinks = false;
  45366. private $sort = false;
  45367. private $ignore = 0;
  45368. private $dirs = array();
  45369. private $dates = array();
  45370. private $iterators = array();
  45371. private $contains = array();
  45372. private $notContains = array();
  45373. private $paths = array();
  45374. private $notPaths = array();
  45375. private $ignoreUnreadableDirs = false;
  45376. private static $vcsPatterns = array('.svn', '_svn', 'CVS', '_darcs', '.arch-params', '.monotone', '.bzr', '.git', '.hg');
  45377. public function __construct()
  45378. {
  45379. $this->ignore = static::IGNORE_VCS_FILES | static::IGNORE_DOT_FILES;
  45380. }
  45381. public static function create()
  45382. {
  45383. return new static();
  45384. }
  45385. public function directories()
  45386. {
  45387. $this->mode = Iterator\FileTypeFilterIterator::ONLY_DIRECTORIES;
  45388. return $this;
  45389. }
  45390. public function files()
  45391. {
  45392. $this->mode = Iterator\FileTypeFilterIterator::ONLY_FILES;
  45393. return $this;
  45394. }
  45395. public function depth($level)
  45396. {
  45397. $this->depths[] = new Comparator\NumberComparator($level);
  45398. return $this;
  45399. }
  45400. public function date($date)
  45401. {
  45402. $this->dates[] = new Comparator\DateComparator($date);
  45403. return $this;
  45404. }
  45405. public function name($pattern)
  45406. {
  45407. $this->names[] = $pattern;
  45408. return $this;
  45409. }
  45410. public function notName($pattern)
  45411. {
  45412. $this->notNames[] = $pattern;
  45413. return $this;
  45414. }
  45415. public function contains($pattern)
  45416. {
  45417. $this->contains[] = $pattern;
  45418. return $this;
  45419. }
  45420. public function notContains($pattern)
  45421. {
  45422. $this->notContains[] = $pattern;
  45423. return $this;
  45424. }
  45425. public function path($pattern)
  45426. {
  45427. $this->paths[] = $pattern;
  45428. return $this;
  45429. }
  45430. public function notPath($pattern)
  45431. {
  45432. $this->notPaths[] = $pattern;
  45433. return $this;
  45434. }
  45435. public function size($size)
  45436. {
  45437. $this->sizes[] = new Comparator\NumberComparator($size);
  45438. return $this;
  45439. }
  45440. public function exclude($dirs)
  45441. {
  45442. $this->exclude = array_merge($this->exclude, (array) $dirs);
  45443. return $this;
  45444. }
  45445. public function ignoreDotFiles($ignoreDotFiles)
  45446. {
  45447. if ($ignoreDotFiles) {
  45448. $this->ignore |= static::IGNORE_DOT_FILES;
  45449. } else {
  45450. $this->ignore &= ~static::IGNORE_DOT_FILES;
  45451. }
  45452. return $this;
  45453. }
  45454. public function ignoreVCS($ignoreVCS)
  45455. {
  45456. if ($ignoreVCS) {
  45457. $this->ignore |= static::IGNORE_VCS_FILES;
  45458. } else {
  45459. $this->ignore &= ~static::IGNORE_VCS_FILES;
  45460. }
  45461. return $this;
  45462. }
  45463. public static function addVCSPattern($pattern)
  45464. {
  45465. foreach ((array) $pattern as $p) {
  45466. self::$vcsPatterns[] = $p;
  45467. }
  45468. self::$vcsPatterns = array_unique(self::$vcsPatterns);
  45469. }
  45470. public function sort(\Closure $closure)
  45471. {
  45472. $this->sort = $closure;
  45473. return $this;
  45474. }
  45475. public function sortByName()
  45476. {
  45477. $this->sort = Iterator\SortableIterator::SORT_BY_NAME;
  45478. return $this;
  45479. }
  45480. public function sortByType()
  45481. {
  45482. $this->sort = Iterator\SortableIterator::SORT_BY_TYPE;
  45483. return $this;
  45484. }
  45485. public function sortByAccessedTime()
  45486. {
  45487. $this->sort = Iterator\SortableIterator::SORT_BY_ACCESSED_TIME;
  45488. return $this;
  45489. }
  45490. public function sortByChangedTime()
  45491. {
  45492. $this->sort = Iterator\SortableIterator::SORT_BY_CHANGED_TIME;
  45493. return $this;
  45494. }
  45495. public function sortByModifiedTime()
  45496. {
  45497. $this->sort = Iterator\SortableIterator::SORT_BY_MODIFIED_TIME;
  45498. return $this;
  45499. }
  45500. public function filter(\Closure $closure)
  45501. {
  45502. $this->filters[] = $closure;
  45503. return $this;
  45504. }
  45505. public function followLinks()
  45506. {
  45507. $this->followLinks = true;
  45508. return $this;
  45509. }
  45510. public function ignoreUnreadableDirs($ignore = true)
  45511. {
  45512. $this->ignoreUnreadableDirs = (bool) $ignore;
  45513. return $this;
  45514. }
  45515. public function in($dirs)
  45516. {
  45517. $resolvedDirs = array();
  45518. foreach ((array) $dirs as $dir) {
  45519. if (is_dir($dir)) {
  45520. $resolvedDirs[] = $dir;
  45521. } elseif ($glob = glob($dir, (defined('GLOB_BRACE') ? GLOB_BRACE : 0) | GLOB_ONLYDIR)) {
  45522. $resolvedDirs = array_merge($resolvedDirs, $glob);
  45523. } else {
  45524. throw new \InvalidArgumentException(sprintf('The "%s" directory does not exist.', $dir));
  45525. }
  45526. }
  45527. $this->dirs = array_merge($this->dirs, $resolvedDirs);
  45528. return $this;
  45529. }
  45530. public function getIterator()
  45531. {
  45532. if (0 === count($this->dirs) && 0 === count($this->iterators)) {
  45533. throw new \LogicException('You must call one of in() or append() methods before iterating over a Finder.');
  45534. }
  45535. if (1 === count($this->dirs) && 0 === count($this->iterators)) {
  45536. return $this->searchInDirectory($this->dirs[0]);
  45537. }
  45538. $iterator = new \AppendIterator();
  45539. foreach ($this->dirs as $dir) {
  45540. $iterator->append($this->searchInDirectory($dir));
  45541. }
  45542. foreach ($this->iterators as $it) {
  45543. $iterator->append($it);
  45544. }
  45545. return $iterator;
  45546. }
  45547. public function append($iterator)
  45548. {
  45549. if ($iterator instanceof \IteratorAggregate) {
  45550. $this->iterators[] = $iterator->getIterator();
  45551. } elseif ($iterator instanceof \Iterator) {
  45552. $this->iterators[] = $iterator;
  45553. } elseif ($iterator instanceof \Traversable || is_array($iterator)) {
  45554. $it = new \ArrayIterator();
  45555. foreach ($iterator as $file) {
  45556. $it->append($file instanceof \SplFileInfo ? $file : new \SplFileInfo($file));
  45557. }
  45558. $this->iterators[] = $it;
  45559. } else {
  45560. throw new \InvalidArgumentException('Finder::append() method wrong argument type.');
  45561. }
  45562. return $this;
  45563. }
  45564. public function hasResults()
  45565. {
  45566. foreach ($this->getIterator() as $_) {
  45567. return true;
  45568. }
  45569. return false;
  45570. }
  45571. public function count()
  45572. {
  45573. return iterator_count($this->getIterator());
  45574. }
  45575. private function searchInDirectory($dir)
  45576. {
  45577. if (static::IGNORE_VCS_FILES === (static::IGNORE_VCS_FILES & $this->ignore)) {
  45578. $this->exclude = array_merge($this->exclude, self::$vcsPatterns);
  45579. }
  45580. if (static::IGNORE_DOT_FILES === (static::IGNORE_DOT_FILES & $this->ignore)) {
  45581. $this->notPaths[] = '#(^|/)\..+(/|$)#';
  45582. }
  45583. $minDepth = 0;
  45584. $maxDepth = PHP_INT_MAX;
  45585. foreach ($this->depths as $comparator) {
  45586. switch ($comparator->getOperator()) {
  45587. case '>':
  45588. $minDepth = $comparator->getTarget() + 1;
  45589. break;
  45590. case '>=':
  45591. $minDepth = $comparator->getTarget();
  45592. break;
  45593. case '<':
  45594. $maxDepth = $comparator->getTarget() - 1;
  45595. break;
  45596. case '<=':
  45597. $maxDepth = $comparator->getTarget();
  45598. break;
  45599. default:
  45600. $minDepth = $maxDepth = $comparator->getTarget();
  45601. }
  45602. }
  45603. $flags = \RecursiveDirectoryIterator::SKIP_DOTS;
  45604. if ($this->followLinks) {
  45605. $flags |= \RecursiveDirectoryIterator::FOLLOW_SYMLINKS;
  45606. }
  45607. $iterator = new Iterator\RecursiveDirectoryIterator($dir, $flags, $this->ignoreUnreadableDirs);
  45608. if ($this->exclude) {
  45609. $iterator = new Iterator\ExcludeDirectoryFilterIterator($iterator, $this->exclude);
  45610. }
  45611. $iterator = new \RecursiveIteratorIterator($iterator, \RecursiveIteratorIterator::SELF_FIRST);
  45612. if ($minDepth > 0 || $maxDepth < PHP_INT_MAX) {
  45613. $iterator = new Iterator\DepthRangeFilterIterator($iterator, $minDepth, $maxDepth);
  45614. }
  45615. if ($this->mode) {
  45616. $iterator = new Iterator\FileTypeFilterIterator($iterator, $this->mode);
  45617. }
  45618. if ($this->names || $this->notNames) {
  45619. $iterator = new Iterator\FilenameFilterIterator($iterator, $this->names, $this->notNames);
  45620. }
  45621. if ($this->contains || $this->notContains) {
  45622. $iterator = new Iterator\FilecontentFilterIterator($iterator, $this->contains, $this->notContains);
  45623. }
  45624. if ($this->sizes) {
  45625. $iterator = new Iterator\SizeRangeFilterIterator($iterator, $this->sizes);
  45626. }
  45627. if ($this->dates) {
  45628. $iterator = new Iterator\DateRangeFilterIterator($iterator, $this->dates);
  45629. }
  45630. if ($this->filters) {
  45631. $iterator = new Iterator\CustomFilterIterator($iterator, $this->filters);
  45632. }
  45633. if ($this->paths || $this->notPaths) {
  45634. $iterator = new Iterator\PathFilterIterator($iterator, $this->paths, $this->notPaths);
  45635. }
  45636. if ($this->sort) {
  45637. $iteratorAggregate = new Iterator\SortableIterator($iterator, $this->sort);
  45638. $iterator = $iteratorAggregate->getIterator();
  45639. }
  45640. return $iterator;
  45641. }
  45642. }
  45643. <?php
  45644. namespace Symfony\Component\Finder;
  45645. class Glob
  45646. {
  45647. public static function toRegex($glob, $strictLeadingDot = true, $strictWildcardSlash = true, $delimiter = '#')
  45648. {
  45649. $firstByte = true;
  45650. $escaping = false;
  45651. $inCurlies = 0;
  45652. $regex = '';
  45653. $sizeGlob = strlen($glob);
  45654. for ($i = 0; $i < $sizeGlob; ++$i) {
  45655. $car = $glob[$i];
  45656. if ($firstByte && $strictLeadingDot && '.' !== $car) {
  45657. $regex .= '(?=[^\.])';
  45658. }
  45659. $firstByte = '/' === $car;
  45660. if ($firstByte && $strictWildcardSlash && isset($glob[$i + 2]) && '**' === $glob[$i + 1].$glob[$i + 2] && (!isset($glob[$i + 3]) || '/' === $glob[$i + 3])) {
  45661. $car = '[^/]++/';
  45662. if (!isset($glob[$i + 3])) {
  45663. $car .= '?';
  45664. }
  45665. if ($strictLeadingDot) {
  45666. $car = '(?=[^\.])'.$car;
  45667. }
  45668. $car = '/(?:'.$car.')*';
  45669. $i += 2 + isset($glob[$i + 3]);
  45670. if ('/' === $delimiter) {
  45671. $car = str_replace('/', '\\/', $car);
  45672. }
  45673. }
  45674. if ($delimiter === $car || '.' === $car || '(' === $car || ')' === $car || '|' === $car || '+' === $car || '^' === $car || '$' === $car) {
  45675. $regex .= "\\$car";
  45676. } elseif ('*' === $car) {
  45677. $regex .= $escaping ? '\\*' : ($strictWildcardSlash ? '[^/]*' : '.*');
  45678. } elseif ('?' === $car) {
  45679. $regex .= $escaping ? '\\?' : ($strictWildcardSlash ? '[^/]' : '.');
  45680. } elseif ('{' === $car) {
  45681. $regex .= $escaping ? '\\{' : '(';
  45682. if (!$escaping) {
  45683. ++$inCurlies;
  45684. }
  45685. } elseif ('}' === $car && $inCurlies) {
  45686. $regex .= $escaping ? '}' : ')';
  45687. if (!$escaping) {
  45688. --$inCurlies;
  45689. }
  45690. } elseif (',' === $car && $inCurlies) {
  45691. $regex .= $escaping ? ',' : '|';
  45692. } elseif ('\\' === $car) {
  45693. if ($escaping) {
  45694. $regex .= '\\\\';
  45695. $escaping = false;
  45696. } else {
  45697. $escaping = true;
  45698. }
  45699. continue;
  45700. } else {
  45701. $regex .= $car;
  45702. }
  45703. $escaping = false;
  45704. }
  45705. return $delimiter.'^'.$regex.'$'.$delimiter;
  45706. }
  45707. }
  45708. <?php
  45709. namespace Symfony\Component\Finder\Iterator;
  45710. class CustomFilterIterator extends FilterIterator
  45711. {
  45712. private $filters = array();
  45713. public function __construct(\Iterator $iterator, array $filters)
  45714. {
  45715. foreach ($filters as $filter) {
  45716. if (!is_callable($filter)) {
  45717. throw new \InvalidArgumentException('Invalid PHP callback.');
  45718. }
  45719. }
  45720. $this->filters = $filters;
  45721. parent::__construct($iterator);
  45722. }
  45723. public function accept()
  45724. {
  45725. $fileinfo = $this->current();
  45726. foreach ($this->filters as $filter) {
  45727. if (false === call_user_func($filter, $fileinfo)) {
  45728. return false;
  45729. }
  45730. }
  45731. return true;
  45732. }
  45733. }
  45734. <?php
  45735. namespace Symfony\Component\Finder\Iterator;
  45736. use Symfony\Component\Finder\Comparator\DateComparator;
  45737. class DateRangeFilterIterator extends FilterIterator
  45738. {
  45739. private $comparators = array();
  45740. public function __construct(\Iterator $iterator, array $comparators)
  45741. {
  45742. $this->comparators = $comparators;
  45743. parent::__construct($iterator);
  45744. }
  45745. public function accept()
  45746. {
  45747. $fileinfo = $this->current();
  45748. if (!file_exists($fileinfo->getPathname())) {
  45749. return false;
  45750. }
  45751. $filedate = $fileinfo->getMTime();
  45752. foreach ($this->comparators as $compare) {
  45753. if (!$compare->test($filedate)) {
  45754. return false;
  45755. }
  45756. }
  45757. return true;
  45758. }
  45759. }
  45760. <?php
  45761. namespace Symfony\Component\Finder\Iterator;
  45762. class DepthRangeFilterIterator extends FilterIterator
  45763. {
  45764. private $minDepth = 0;
  45765. public function __construct(\RecursiveIteratorIterator $iterator, $minDepth = 0, $maxDepth = PHP_INT_MAX)
  45766. {
  45767. $this->minDepth = $minDepth;
  45768. $iterator->setMaxDepth(PHP_INT_MAX === $maxDepth ? -1 : $maxDepth);
  45769. parent::__construct($iterator);
  45770. }
  45771. public function accept()
  45772. {
  45773. return $this->getInnerIterator()->getDepth() >= $this->minDepth;
  45774. }
  45775. }
  45776. <?php
  45777. namespace Symfony\Component\Finder\Iterator;
  45778. class ExcludeDirectoryFilterIterator extends FilterIterator implements \RecursiveIterator
  45779. {
  45780. private $iterator;
  45781. private $isRecursive;
  45782. private $excludedDirs = array();
  45783. private $excludedPattern;
  45784. public function __construct(\Iterator $iterator, array $directories)
  45785. {
  45786. $this->iterator = $iterator;
  45787. $this->isRecursive = $iterator instanceof \RecursiveIterator;
  45788. $patterns = array();
  45789. foreach ($directories as $directory) {
  45790. $directory = rtrim($directory, '/');
  45791. if (!$this->isRecursive || false !== strpos($directory, '/')) {
  45792. $patterns[] = preg_quote($directory, '#');
  45793. } else {
  45794. $this->excludedDirs[$directory] = true;
  45795. }
  45796. }
  45797. if ($patterns) {
  45798. $this->excludedPattern = '#(?:^|/)(?:'.implode('|', $patterns).')(?:/|$)#';
  45799. }
  45800. parent::__construct($iterator);
  45801. }
  45802. public function accept()
  45803. {
  45804. if ($this->isRecursive && isset($this->excludedDirs[$this->getFilename()]) && $this->isDir()) {
  45805. return false;
  45806. }
  45807. if ($this->excludedPattern) {
  45808. $path = $this->isDir() ? $this->current()->getRelativePathname() : $this->current()->getRelativePath();
  45809. $path = str_replace('\\', '/', $path);
  45810. return !preg_match($this->excludedPattern, $path);
  45811. }
  45812. return true;
  45813. }
  45814. public function hasChildren()
  45815. {
  45816. return $this->isRecursive && $this->iterator->hasChildren();
  45817. }
  45818. public function getChildren()
  45819. {
  45820. $children = new self($this->iterator->getChildren(), array());
  45821. $children->excludedDirs = $this->excludedDirs;
  45822. $children->excludedPattern = $this->excludedPattern;
  45823. return $children;
  45824. }
  45825. }
  45826. <?php
  45827. namespace Symfony\Component\Finder\Iterator;
  45828. class FileTypeFilterIterator extends FilterIterator
  45829. {
  45830. const ONLY_FILES = 1;
  45831. const ONLY_DIRECTORIES = 2;
  45832. private $mode;
  45833. public function __construct(\Iterator $iterator, $mode)
  45834. {
  45835. $this->mode = $mode;
  45836. parent::__construct($iterator);
  45837. }
  45838. public function accept()
  45839. {
  45840. $fileinfo = $this->current();
  45841. if (self::ONLY_DIRECTORIES === (self::ONLY_DIRECTORIES & $this->mode) && $fileinfo->isFile()) {
  45842. return false;
  45843. } elseif (self::ONLY_FILES === (self::ONLY_FILES & $this->mode) && $fileinfo->isDir()) {
  45844. return false;
  45845. }
  45846. return true;
  45847. }
  45848. }
  45849. <?php
  45850. namespace Symfony\Component\Finder\Iterator;
  45851. class FilecontentFilterIterator extends MultiplePcreFilterIterator
  45852. {
  45853. public function accept()
  45854. {
  45855. if (!$this->matchRegexps && !$this->noMatchRegexps) {
  45856. return true;
  45857. }
  45858. $fileinfo = $this->current();
  45859. if ($fileinfo->isDir() || !$fileinfo->isReadable()) {
  45860. return false;
  45861. }
  45862. $content = $fileinfo->getContents();
  45863. if (!$content) {
  45864. return false;
  45865. }
  45866. return $this->isAccepted($content);
  45867. }
  45868. protected function toRegex($str)
  45869. {
  45870. return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
  45871. }
  45872. }
  45873. <?php
  45874. namespace Symfony\Component\Finder\Iterator;
  45875. use Symfony\Component\Finder\Glob;
  45876. class FilenameFilterIterator extends MultiplePcreFilterIterator
  45877. {
  45878. public function accept()
  45879. {
  45880. return $this->isAccepted($this->current()->getFilename());
  45881. }
  45882. protected function toRegex($str)
  45883. {
  45884. return $this->isRegex($str) ? $str : Glob::toRegex($str);
  45885. }
  45886. }
  45887. <?php
  45888. namespace Symfony\Component\Finder\Iterator;
  45889. abstract class FilterIterator extends \FilterIterator
  45890. {
  45891. public function rewind()
  45892. {
  45893. if (\PHP_VERSION_ID > 50607 || (\PHP_VERSION_ID > 50523 && \PHP_VERSION_ID < 50600)) {
  45894. parent::rewind();
  45895. return;
  45896. }
  45897. $iterator = $this;
  45898. while ($iterator instanceof \OuterIterator) {
  45899. $innerIterator = $iterator->getInnerIterator();
  45900. if ($innerIterator instanceof RecursiveDirectoryIterator) {
  45901. if ($innerIterator->isRewindable()) {
  45902. $innerIterator->next();
  45903. $innerIterator->rewind();
  45904. }
  45905. } elseif ($innerIterator instanceof \FilesystemIterator) {
  45906. $innerIterator->next();
  45907. $innerIterator->rewind();
  45908. }
  45909. $iterator = $innerIterator;
  45910. }
  45911. parent::rewind();
  45912. }
  45913. }
  45914. <?php
  45915. namespace Symfony\Component\Finder\Iterator;
  45916. abstract class MultiplePcreFilterIterator extends FilterIterator
  45917. {
  45918. protected $matchRegexps = array();
  45919. protected $noMatchRegexps = array();
  45920. public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
  45921. {
  45922. foreach ($matchPatterns as $pattern) {
  45923. $this->matchRegexps[] = $this->toRegex($pattern);
  45924. }
  45925. foreach ($noMatchPatterns as $pattern) {
  45926. $this->noMatchRegexps[] = $this->toRegex($pattern);
  45927. }
  45928. parent::__construct($iterator);
  45929. }
  45930. protected function isAccepted($string)
  45931. {
  45932. foreach ($this->noMatchRegexps as $regex) {
  45933. if (preg_match($regex, $string)) {
  45934. return false;
  45935. }
  45936. }
  45937. if ($this->matchRegexps) {
  45938. foreach ($this->matchRegexps as $regex) {
  45939. if (preg_match($regex, $string)) {
  45940. return true;
  45941. }
  45942. }
  45943. return false;
  45944. }
  45945. return true;
  45946. }
  45947. protected function isRegex($str)
  45948. {
  45949. if (preg_match('/^(.{3,}?)[imsxuADU]*$/', $str, $m)) {
  45950. $start = substr($m[1], 0, 1);
  45951. $end = substr($m[1], -1);
  45952. if ($start === $end) {
  45953. return !preg_match('/[*?[:alnum:] \\\\]/', $start);
  45954. }
  45955. foreach (array(array('{', '}'), array('(', ')'), array('[', ']'), array('<', '>')) as $delimiters) {
  45956. if ($start === $delimiters[0] && $end === $delimiters[1]) {
  45957. return true;
  45958. }
  45959. }
  45960. }
  45961. return false;
  45962. }
  45963. abstract protected function toRegex($str);
  45964. }
  45965. <?php
  45966. namespace Symfony\Component\Finder\Iterator;
  45967. class PathFilterIterator extends MultiplePcreFilterIterator
  45968. {
  45969. public function accept()
  45970. {
  45971. $filename = $this->current()->getRelativePathname();
  45972. if ('\\' === DIRECTORY_SEPARATOR) {
  45973. $filename = str_replace('\\', '/', $filename);
  45974. }
  45975. return $this->isAccepted($filename);
  45976. }
  45977. protected function toRegex($str)
  45978. {
  45979. return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
  45980. }
  45981. }
  45982. <?php
  45983. namespace Symfony\Component\Finder\Iterator;
  45984. use Symfony\Component\Finder\Exception\AccessDeniedException;
  45985. use Symfony\Component\Finder\SplFileInfo;
  45986. class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
  45987. {
  45988. private $ignoreUnreadableDirs;
  45989. private $rewindable;
  45990. private $rootPath;
  45991. private $subPath;
  45992. private $directorySeparator = '/';
  45993. public function __construct($path, $flags, $ignoreUnreadableDirs = false)
  45994. {
  45995. if ($flags & (self::CURRENT_AS_PATHNAME | self::CURRENT_AS_SELF)) {
  45996. throw new \RuntimeException('This iterator only support returning current as fileinfo.');
  45997. }
  45998. parent::__construct($path, $flags);
  45999. $this->ignoreUnreadableDirs = $ignoreUnreadableDirs;
  46000. $this->rootPath = $path;
  46001. if ('/' !== DIRECTORY_SEPARATOR && !($flags & self::UNIX_PATHS)) {
  46002. $this->directorySeparator = DIRECTORY_SEPARATOR;
  46003. }
  46004. }
  46005. public function current()
  46006. {
  46007. if (null === $subPathname = $this->subPath) {
  46008. $subPathname = $this->subPath = (string) $this->getSubPath();
  46009. }
  46010. if ('' !== $subPathname) {
  46011. $subPathname .= $this->directorySeparator;
  46012. }
  46013. $subPathname .= $this->getFilename();
  46014. return new SplFileInfo($this->rootPath.$this->directorySeparator.$subPathname, $this->subPath, $subPathname);
  46015. }
  46016. public function getChildren()
  46017. {
  46018. try {
  46019. $children = parent::getChildren();
  46020. if ($children instanceof self) {
  46021. $children->ignoreUnreadableDirs = $this->ignoreUnreadableDirs;
  46022. $children->rewindable = &$this->rewindable;
  46023. $children->rootPath = $this->rootPath;
  46024. }
  46025. return $children;
  46026. } catch (\UnexpectedValueException $e) {
  46027. if ($this->ignoreUnreadableDirs) {
  46028. return new \RecursiveArrayIterator(array());
  46029. } else {
  46030. throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
  46031. }
  46032. }
  46033. }
  46034. public function rewind()
  46035. {
  46036. if (false === $this->isRewindable()) {
  46037. return;
  46038. }
  46039. if (\PHP_VERSION_ID < 50523 || \PHP_VERSION_ID >= 50600 && \PHP_VERSION_ID < 50607) {
  46040. parent::next();
  46041. }
  46042. parent::rewind();
  46043. }
  46044. public function isRewindable()
  46045. {
  46046. if (null !== $this->rewindable) {
  46047. return $this->rewindable;
  46048. }
  46049. if ('' === $this->getPath()) {
  46050. return $this->rewindable = false;
  46051. }
  46052. if (false !== $stream = @opendir($this->getPath())) {
  46053. $infos = stream_get_meta_data($stream);
  46054. closedir($stream);
  46055. if ($infos['seekable']) {
  46056. return $this->rewindable = true;
  46057. }
  46058. }
  46059. return $this->rewindable = false;
  46060. }
  46061. }
  46062. <?php
  46063. namespace Symfony\Component\Finder\Iterator;
  46064. use Symfony\Component\Finder\Comparator\NumberComparator;
  46065. class SizeRangeFilterIterator extends FilterIterator
  46066. {
  46067. private $comparators = array();
  46068. public function __construct(\Iterator $iterator, array $comparators)
  46069. {
  46070. $this->comparators = $comparators;
  46071. parent::__construct($iterator);
  46072. }
  46073. public function accept()
  46074. {
  46075. $fileinfo = $this->current();
  46076. if (!$fileinfo->isFile()) {
  46077. return true;
  46078. }
  46079. $filesize = $fileinfo->getSize();
  46080. foreach ($this->comparators as $compare) {
  46081. if (!$compare->test($filesize)) {
  46082. return false;
  46083. }
  46084. }
  46085. return true;
  46086. }
  46087. }
  46088. <?php
  46089. namespace Symfony\Component\Finder\Iterator;
  46090. class SortableIterator implements \IteratorAggregate
  46091. {
  46092. const SORT_BY_NAME = 1;
  46093. const SORT_BY_TYPE = 2;
  46094. const SORT_BY_ACCESSED_TIME = 3;
  46095. const SORT_BY_CHANGED_TIME = 4;
  46096. const SORT_BY_MODIFIED_TIME = 5;
  46097. private $iterator;
  46098. private $sort;
  46099. public function __construct(\Traversable $iterator, $sort)
  46100. {
  46101. $this->iterator = $iterator;
  46102. if (self::SORT_BY_NAME === $sort) {
  46103. $this->sort = function ($a, $b) {
  46104. return strcmp($a->getRealpath() ?: $a->getPathname(), $b->getRealpath() ?: $b->getPathname());
  46105. };
  46106. } elseif (self::SORT_BY_TYPE === $sort) {
  46107. $this->sort = function ($a, $b) {
  46108. if ($a->isDir() && $b->isFile()) {
  46109. return -1;
  46110. } elseif ($a->isFile() && $b->isDir()) {
  46111. return 1;
  46112. }
  46113. return strcmp($a->getRealpath() ?: $a->getPathname(), $b->getRealpath() ?: $b->getPathname());
  46114. };
  46115. } elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
  46116. $this->sort = function ($a, $b) {
  46117. return $a->getATime() - $b->getATime();
  46118. };
  46119. } elseif (self::SORT_BY_CHANGED_TIME === $sort) {
  46120. $this->sort = function ($a, $b) {
  46121. return $a->getCTime() - $b->getCTime();
  46122. };
  46123. } elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
  46124. $this->sort = function ($a, $b) {
  46125. return $a->getMTime() - $b->getMTime();
  46126. };
  46127. } elseif (is_callable($sort)) {
  46128. $this->sort = $sort;
  46129. } else {
  46130. throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
  46131. }
  46132. }
  46133. public function getIterator()
  46134. {
  46135. $array = iterator_to_array($this->iterator, true);
  46136. uasort($array, $this->sort);
  46137. return new \ArrayIterator($array);
  46138. }
  46139. }
  46140. <?php
  46141. namespace Symfony\Component\Finder;
  46142. class SplFileInfo extends \SplFileInfo
  46143. {
  46144. private $relativePath;
  46145. private $relativePathname;
  46146. public function __construct($file, $relativePath, $relativePathname)
  46147. {
  46148. parent::__construct($file);
  46149. $this->relativePath = $relativePath;
  46150. $this->relativePathname = $relativePathname;
  46151. }
  46152. public function getRelativePath()
  46153. {
  46154. return $this->relativePath;
  46155. }
  46156. public function getRelativePathname()
  46157. {
  46158. return $this->relativePathname;
  46159. }
  46160. public function getContents()
  46161. {
  46162. $level = error_reporting(0);
  46163. $content = file_get_contents($this->getPathname());
  46164. error_reporting($level);
  46165. if (false === $content) {
  46166. $error = error_get_last();
  46167. throw new \RuntimeException($error['message']);
  46168. }
  46169. return $content;
  46170. }
  46171. }
  46172. <?php
  46173. namespace Symfony\Component\OptionsResolver\Debug;
  46174. use Symfony\Component\OptionsResolver\Exception\NoConfigurationException;
  46175. use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
  46176. use Symfony\Component\OptionsResolver\OptionsResolver;
  46177. class OptionsResolverIntrospector
  46178. {
  46179. private $get;
  46180. public function __construct(OptionsResolver $optionsResolver)
  46181. {
  46182. $this->get = \Closure::bind(function ($property, $option, $message) {
  46183. if (!$this->isDefined($option)) {
  46184. throw new UndefinedOptionsException(sprintf('The option "%s" does not exist.', $option));
  46185. }
  46186. if (!array_key_exists($option, $this->{$property})) {
  46187. throw new NoConfigurationException($message);
  46188. }
  46189. return $this->{$property}[$option];
  46190. }, $optionsResolver, $optionsResolver);
  46191. }
  46192. public function getDefault($option)
  46193. {
  46194. return call_user_func($this->get, 'defaults', $option, sprintf('No default value was set for the "%s" option.', $option));
  46195. }
  46196. public function getLazyClosures($option)
  46197. {
  46198. return call_user_func($this->get, 'lazy', $option, sprintf('No lazy closures were set for the "%s" option.', $option));
  46199. }
  46200. public function getAllowedTypes($option)
  46201. {
  46202. return call_user_func($this->get, 'allowedTypes', $option, sprintf('No allowed types were set for the "%s" option.', $option));
  46203. }
  46204. public function getAllowedValues($option)
  46205. {
  46206. return call_user_func($this->get, 'allowedValues', $option, sprintf('No allowed values were set for the "%s" option.', $option));
  46207. }
  46208. public function getNormalizer($option)
  46209. {
  46210. return call_user_func($this->get, 'normalizers', $option, sprintf('No normalizer was set for the "%s" option.', $option));
  46211. }
  46212. }
  46213. <?php
  46214. namespace Symfony\Component\OptionsResolver\Exception;
  46215. class AccessException extends \LogicException implements ExceptionInterface
  46216. {
  46217. }
  46218. <?php
  46219. namespace Symfony\Component\OptionsResolver\Exception;
  46220. interface ExceptionInterface
  46221. {
  46222. }
  46223. <?php
  46224. namespace Symfony\Component\OptionsResolver\Exception;
  46225. class InvalidArgumentException extends \InvalidArgumentException implements ExceptionInterface
  46226. {
  46227. }
  46228. <?php
  46229. namespace Symfony\Component\OptionsResolver\Exception;
  46230. class InvalidOptionsException extends InvalidArgumentException
  46231. {
  46232. }
  46233. <?php
  46234. namespace Symfony\Component\OptionsResolver\Exception;
  46235. class MissingOptionsException extends InvalidArgumentException
  46236. {
  46237. }
  46238. <?php
  46239. namespace Symfony\Component\OptionsResolver\Exception;
  46240. use Symfony\Component\OptionsResolver\Debug\OptionsResolverIntrospector;
  46241. class NoConfigurationException extends \RuntimeException implements ExceptionInterface
  46242. {
  46243. }
  46244. <?php
  46245. namespace Symfony\Component\OptionsResolver\Exception;
  46246. class NoSuchOptionException extends \OutOfBoundsException implements ExceptionInterface
  46247. {
  46248. }
  46249. <?php
  46250. namespace Symfony\Component\OptionsResolver\Exception;
  46251. class OptionDefinitionException extends \LogicException implements ExceptionInterface
  46252. {
  46253. }
  46254. <?php
  46255. namespace Symfony\Component\OptionsResolver\Exception;
  46256. class UndefinedOptionsException extends InvalidArgumentException
  46257. {
  46258. }
  46259. <?php
  46260. namespace Symfony\Component\OptionsResolver;
  46261. interface Options extends \ArrayAccess, \Countable
  46262. {
  46263. }
  46264. <?php
  46265. namespace Symfony\Component\OptionsResolver;
  46266. use Symfony\Component\OptionsResolver\Exception\AccessException;
  46267. use Symfony\Component\OptionsResolver\Exception\InvalidOptionsException;
  46268. use Symfony\Component\OptionsResolver\Exception\MissingOptionsException;
  46269. use Symfony\Component\OptionsResolver\Exception\NoSuchOptionException;
  46270. use Symfony\Component\OptionsResolver\Exception\OptionDefinitionException;
  46271. use Symfony\Component\OptionsResolver\Exception\UndefinedOptionsException;
  46272. class OptionsResolver implements Options
  46273. {
  46274. private $defined = array();
  46275. private $defaults = array();
  46276. private $required = array();
  46277. private $resolved = array();
  46278. private $normalizers = array();
  46279. private $allowedValues = array();
  46280. private $allowedTypes = array();
  46281. private $lazy = array();
  46282. private $calling = array();
  46283. private $locked = false;
  46284. private static $typeAliases = array(
  46285. 'boolean' => 'bool',
  46286. 'integer' => 'int',
  46287. 'double' => 'float',
  46288. );
  46289. public function setDefault($option, $value)
  46290. {
  46291. if ($this->locked) {
  46292. throw new AccessException('Default values cannot be set from a lazy option or normalizer.');
  46293. }
  46294. if ($value instanceof \Closure) {
  46295. $reflClosure = new \ReflectionFunction($value);
  46296. $params = $reflClosure->getParameters();
  46297. if (isset($params[0]) && null !== ($class = $params[0]->getClass()) && Options::class === $class->name) {
  46298. if (!isset($this->defaults[$option])) {
  46299. $this->defaults[$option] = null;
  46300. }
  46301. if (!isset($this->lazy[$option]) || !isset($params[1])) {
  46302. $this->lazy[$option] = array();
  46303. }
  46304. $this->lazy[$option][] = $value;
  46305. $this->defined[$option] = true;
  46306. unset($this->resolved[$option]);
  46307. return $this;
  46308. }
  46309. }
  46310. unset($this->lazy[$option]);
  46311. if (!isset($this->defined[$option]) || array_key_exists($option, $this->resolved)) {
  46312. $this->resolved[$option] = $value;
  46313. }
  46314. $this->defaults[$option] = $value;
  46315. $this->defined[$option] = true;
  46316. return $this;
  46317. }
  46318. public function setDefaults(array $defaults)
  46319. {
  46320. foreach ($defaults as $option => $value) {
  46321. $this->setDefault($option, $value);
  46322. }
  46323. return $this;
  46324. }
  46325. public function hasDefault($option)
  46326. {
  46327. return array_key_exists($option, $this->defaults);
  46328. }
  46329. public function setRequired($optionNames)
  46330. {
  46331. if ($this->locked) {
  46332. throw new AccessException('Options cannot be made required from a lazy option or normalizer.');
  46333. }
  46334. foreach ((array) $optionNames as $option) {
  46335. $this->defined[$option] = true;
  46336. $this->required[$option] = true;
  46337. }
  46338. return $this;
  46339. }
  46340. public function isRequired($option)
  46341. {
  46342. return isset($this->required[$option]);
  46343. }
  46344. public function getRequiredOptions()
  46345. {
  46346. return array_keys($this->required);
  46347. }
  46348. public function isMissing($option)
  46349. {
  46350. return isset($this->required[$option]) && !array_key_exists($option, $this->defaults);
  46351. }
  46352. public function getMissingOptions()
  46353. {
  46354. return array_keys(array_diff_key($this->required, $this->defaults));
  46355. }
  46356. public function setDefined($optionNames)
  46357. {
  46358. if ($this->locked) {
  46359. throw new AccessException('Options cannot be defined from a lazy option or normalizer.');
  46360. }
  46361. foreach ((array) $optionNames as $option) {
  46362. $this->defined[$option] = true;
  46363. }
  46364. return $this;
  46365. }
  46366. public function isDefined($option)
  46367. {
  46368. return isset($this->defined[$option]);
  46369. }
  46370. public function getDefinedOptions()
  46371. {
  46372. return array_keys($this->defined);
  46373. }
  46374. public function setNormalizer($option, \Closure $normalizer)
  46375. {
  46376. if ($this->locked) {
  46377. throw new AccessException('Normalizers cannot be set from a lazy option or normalizer.');
  46378. }
  46379. if (!isset($this->defined[$option])) {
  46380. throw new UndefinedOptionsException(sprintf(
  46381. 'The option "%s" does not exist. Defined options are: "%s".',
  46382. $option,
  46383. implode('", "', array_keys($this->defined))
  46384. ));
  46385. }
  46386. $this->normalizers[$option] = $normalizer;
  46387. unset($this->resolved[$option]);
  46388. return $this;
  46389. }
  46390. public function setAllowedValues($option, $allowedValues)
  46391. {
  46392. if ($this->locked) {
  46393. throw new AccessException('Allowed values cannot be set from a lazy option or normalizer.');
  46394. }
  46395. if (!isset($this->defined[$option])) {
  46396. throw new UndefinedOptionsException(sprintf(
  46397. 'The option "%s" does not exist. Defined options are: "%s".',
  46398. $option,
  46399. implode('", "', array_keys($this->defined))
  46400. ));
  46401. }
  46402. $this->allowedValues[$option] = is_array($allowedValues) ? $allowedValues : array($allowedValues);
  46403. unset($this->resolved[$option]);
  46404. return $this;
  46405. }
  46406. public function addAllowedValues($option, $allowedValues)
  46407. {
  46408. if ($this->locked) {
  46409. throw new AccessException('Allowed values cannot be added from a lazy option or normalizer.');
  46410. }
  46411. if (!isset($this->defined[$option])) {
  46412. throw new UndefinedOptionsException(sprintf(
  46413. 'The option "%s" does not exist. Defined options are: "%s".',
  46414. $option,
  46415. implode('", "', array_keys($this->defined))
  46416. ));
  46417. }
  46418. if (!is_array($allowedValues)) {
  46419. $allowedValues = array($allowedValues);
  46420. }
  46421. if (!isset($this->allowedValues[$option])) {
  46422. $this->allowedValues[$option] = $allowedValues;
  46423. } else {
  46424. $this->allowedValues[$option] = array_merge($this->allowedValues[$option], $allowedValues);
  46425. }
  46426. unset($this->resolved[$option]);
  46427. return $this;
  46428. }
  46429. public function setAllowedTypes($option, $allowedTypes)
  46430. {
  46431. if ($this->locked) {
  46432. throw new AccessException('Allowed types cannot be set from a lazy option or normalizer.');
  46433. }
  46434. if (!isset($this->defined[$option])) {
  46435. throw new UndefinedOptionsException(sprintf(
  46436. 'The option "%s" does not exist. Defined options are: "%s".',
  46437. $option,
  46438. implode('", "', array_keys($this->defined))
  46439. ));
  46440. }
  46441. $this->allowedTypes[$option] = (array) $allowedTypes;
  46442. unset($this->resolved[$option]);
  46443. return $this;
  46444. }
  46445. public function addAllowedTypes($option, $allowedTypes)
  46446. {
  46447. if ($this->locked) {
  46448. throw new AccessException('Allowed types cannot be added from a lazy option or normalizer.');
  46449. }
  46450. if (!isset($this->defined[$option])) {
  46451. throw new UndefinedOptionsException(sprintf(
  46452. 'The option "%s" does not exist. Defined options are: "%s".',
  46453. $option,
  46454. implode('", "', array_keys($this->defined))
  46455. ));
  46456. }
  46457. if (!isset($this->allowedTypes[$option])) {
  46458. $this->allowedTypes[$option] = (array) $allowedTypes;
  46459. } else {
  46460. $this->allowedTypes[$option] = array_merge($this->allowedTypes[$option], (array) $allowedTypes);
  46461. }
  46462. unset($this->resolved[$option]);
  46463. return $this;
  46464. }
  46465. public function remove($optionNames)
  46466. {
  46467. if ($this->locked) {
  46468. throw new AccessException('Options cannot be removed from a lazy option or normalizer.');
  46469. }
  46470. foreach ((array) $optionNames as $option) {
  46471. unset($this->defined[$option], $this->defaults[$option], $this->required[$option], $this->resolved[$option]);
  46472. unset($this->lazy[$option], $this->normalizers[$option], $this->allowedTypes[$option], $this->allowedValues[$option]);
  46473. }
  46474. return $this;
  46475. }
  46476. public function clear()
  46477. {
  46478. if ($this->locked) {
  46479. throw new AccessException('Options cannot be cleared from a lazy option or normalizer.');
  46480. }
  46481. $this->defined = array();
  46482. $this->defaults = array();
  46483. $this->required = array();
  46484. $this->resolved = array();
  46485. $this->lazy = array();
  46486. $this->normalizers = array();
  46487. $this->allowedTypes = array();
  46488. $this->allowedValues = array();
  46489. return $this;
  46490. }
  46491. public function resolve(array $options = array())
  46492. {
  46493. if ($this->locked) {
  46494. throw new AccessException('Options cannot be resolved from a lazy option or normalizer.');
  46495. }
  46496. $clone = clone $this;
  46497. $diff = array_diff_key($options, $clone->defined);
  46498. if (count($diff) > 0) {
  46499. ksort($clone->defined);
  46500. ksort($diff);
  46501. throw new UndefinedOptionsException(sprintf(
  46502. (count($diff) > 1 ? 'The options "%s" do not exist.' : 'The option "%s" does not exist.').' Defined options are: "%s".',
  46503. implode('", "', array_keys($diff)),
  46504. implode('", "', array_keys($clone->defined))
  46505. ));
  46506. }
  46507. foreach ($options as $option => $value) {
  46508. $clone->defaults[$option] = $value;
  46509. unset($clone->resolved[$option], $clone->lazy[$option]);
  46510. }
  46511. $diff = array_diff_key($clone->required, $clone->defaults);
  46512. if (count($diff) > 0) {
  46513. ksort($diff);
  46514. throw new MissingOptionsException(sprintf(
  46515. count($diff) > 1 ? 'The required options "%s" are missing.' : 'The required option "%s" is missing.',
  46516. implode('", "', array_keys($diff))
  46517. ));
  46518. }
  46519. $clone->locked = true;
  46520. foreach ($clone->defaults as $option => $_) {
  46521. $clone->offsetGet($option);
  46522. }
  46523. return $clone->resolved;
  46524. }
  46525. public function offsetGet($option)
  46526. {
  46527. if (!$this->locked) {
  46528. throw new AccessException('Array access is only supported within closures of lazy options and normalizers.');
  46529. }
  46530. if (array_key_exists($option, $this->resolved)) {
  46531. return $this->resolved[$option];
  46532. }
  46533. if (!array_key_exists($option, $this->defaults)) {
  46534. if (!isset($this->defined[$option])) {
  46535. throw new NoSuchOptionException(sprintf(
  46536. 'The option "%s" does not exist. Defined options are: "%s".',
  46537. $option,
  46538. implode('", "', array_keys($this->defined))
  46539. ));
  46540. }
  46541. throw new NoSuchOptionException(sprintf(
  46542. 'The optional option "%s" has no value set. You should make sure it is set with "isset" before reading it.',
  46543. $option
  46544. ));
  46545. }
  46546. $value = $this->defaults[$option];
  46547. if (isset($this->lazy[$option])) {
  46548. if (isset($this->calling[$option])) {
  46549. throw new OptionDefinitionException(sprintf(
  46550. 'The options "%s" have a cyclic dependency.',
  46551. implode('", "', array_keys($this->calling))
  46552. ));
  46553. }
  46554. $this->calling[$option] = true;
  46555. try {
  46556. foreach ($this->lazy[$option] as $closure) {
  46557. $value = $closure($this, $value);
  46558. }
  46559. } finally {
  46560. unset($this->calling[$option]);
  46561. }
  46562. }
  46563. if (isset($this->allowedTypes[$option])) {
  46564. $valid = false;
  46565. $invalidTypes = array();
  46566. foreach ($this->allowedTypes[$option] as $type) {
  46567. $type = isset(self::$typeAliases[$type]) ? self::$typeAliases[$type] : $type;
  46568. if ($valid = $this->verifyTypes($type, $value, $invalidTypes)) {
  46569. break;
  46570. }
  46571. }
  46572. if (!$valid) {
  46573. throw new InvalidOptionsException(sprintf(
  46574. 'The option "%s" with value %s is expected to be of type '.
  46575. '"%s", but is of type "%s".',
  46576. $option,
  46577. $this->formatValue($value),
  46578. implode('" or "', $this->allowedTypes[$option]),
  46579. implode('|', array_keys($invalidTypes))
  46580. ));
  46581. }
  46582. }
  46583. if (isset($this->allowedValues[$option])) {
  46584. $success = false;
  46585. $printableAllowedValues = array();
  46586. foreach ($this->allowedValues[$option] as $allowedValue) {
  46587. if ($allowedValue instanceof \Closure) {
  46588. if ($allowedValue($value)) {
  46589. $success = true;
  46590. break;
  46591. }
  46592. continue;
  46593. } elseif ($value === $allowedValue) {
  46594. $success = true;
  46595. break;
  46596. }
  46597. $printableAllowedValues[] = $allowedValue;
  46598. }
  46599. if (!$success) {
  46600. $message = sprintf(
  46601. 'The option "%s" with value %s is invalid.',
  46602. $option,
  46603. $this->formatValue($value)
  46604. );
  46605. if (count($printableAllowedValues) > 0) {
  46606. $message .= sprintf(
  46607. ' Accepted values are: %s.',
  46608. $this->formatValues($printableAllowedValues)
  46609. );
  46610. }
  46611. throw new InvalidOptionsException($message);
  46612. }
  46613. }
  46614. if (isset($this->normalizers[$option])) {
  46615. if (isset($this->calling[$option])) {
  46616. throw new OptionDefinitionException(sprintf(
  46617. 'The options "%s" have a cyclic dependency.',
  46618. implode('", "', array_keys($this->calling))
  46619. ));
  46620. }
  46621. $normalizer = $this->normalizers[$option];
  46622. $this->calling[$option] = true;
  46623. try {
  46624. $value = $normalizer($this, $value);
  46625. } finally {
  46626. unset($this->calling[$option]);
  46627. }
  46628. }
  46629. $this->resolved[$option] = $value;
  46630. return $value;
  46631. }
  46632. private function verifyTypes($type, $value, array &$invalidTypes)
  46633. {
  46634. if ('[]' === substr($type, -2) && is_array($value)) {
  46635. $originalType = $type;
  46636. $type = substr($type, 0, -2);
  46637. $invalidValues = array_filter(
  46638. $value,
  46639. function ($value) use ($type) {
  46640. return (function_exists($isFunction = 'is_'.$type) && !$isFunction($value)) || !$value instanceof $type;
  46641. }
  46642. );
  46643. if (!$invalidValues) {
  46644. return true;
  46645. }
  46646. $invalidTypes[$this->formatTypeOf($value, $originalType)] = true;
  46647. return false;
  46648. }
  46649. if ((function_exists($isFunction = 'is_'.$type) && $isFunction($value)) || $value instanceof $type) {
  46650. return true;
  46651. }
  46652. if (!$invalidTypes) {
  46653. $invalidTypes[$this->formatTypeOf($value, null)] = true;
  46654. }
  46655. return false;
  46656. }
  46657. public function offsetExists($option)
  46658. {
  46659. if (!$this->locked) {
  46660. throw new AccessException('Array access is only supported within closures of lazy options and normalizers.');
  46661. }
  46662. return array_key_exists($option, $this->defaults);
  46663. }
  46664. public function offsetSet($option, $value)
  46665. {
  46666. throw new AccessException('Setting options via array access is not supported. Use setDefault() instead.');
  46667. }
  46668. public function offsetUnset($option)
  46669. {
  46670. throw new AccessException('Removing options via array access is not supported. Use remove() instead.');
  46671. }
  46672. public function count()
  46673. {
  46674. if (!$this->locked) {
  46675. throw new AccessException('Counting is only supported within closures of lazy options and normalizers.');
  46676. }
  46677. return count($this->defaults);
  46678. }
  46679. private function formatTypeOf($value, $type)
  46680. {
  46681. $suffix = '';
  46682. if ('[]' === substr($type, -2)) {
  46683. $suffix = '[]';
  46684. $type = substr($type, 0, -2);
  46685. while ('[]' === substr($type, -2)) {
  46686. $type = substr($type, 0, -2);
  46687. $value = array_shift($value);
  46688. if (!is_array($value)) {
  46689. break;
  46690. }
  46691. $suffix .= '[]';
  46692. }
  46693. if (is_array($value)) {
  46694. $subTypes = array();
  46695. foreach ($value as $val) {
  46696. $subTypes[$this->formatTypeOf($val, null)] = true;
  46697. }
  46698. return implode('|', array_keys($subTypes)).$suffix;
  46699. }
  46700. }
  46701. return (is_object($value) ? get_class($value) : gettype($value)).$suffix;
  46702. }
  46703. private function formatValue($value)
  46704. {
  46705. if (is_object($value)) {
  46706. return get_class($value);
  46707. }
  46708. if (is_array($value)) {
  46709. return 'array';
  46710. }
  46711. if (is_string($value)) {
  46712. return '"'.$value.'"';
  46713. }
  46714. if (is_resource($value)) {
  46715. return 'resource';
  46716. }
  46717. if (null === $value) {
  46718. return 'null';
  46719. }
  46720. if (false === $value) {
  46721. return 'false';
  46722. }
  46723. if (true === $value) {
  46724. return 'true';
  46725. }
  46726. return (string) $value;
  46727. }
  46728. private function formatValues(array $values)
  46729. {
  46730. foreach ($values as $key => $value) {
  46731. $values[$key] = $this->formatValue($value);
  46732. }
  46733. return implode(', ', $values);
  46734. }
  46735. }
  46736. <?php
  46737. namespace Symfony\Polyfill\Php70;
  46738. final class Php70
  46739. {
  46740. public static function intdiv($dividend, $divisor)
  46741. {
  46742. $dividend = self::intArg($dividend, __FUNCTION__, 1);
  46743. $divisor = self::intArg($divisor, __FUNCTION__, 2);
  46744. if (0 === $divisor) {
  46745. throw new \DivisionByZeroError('Division by zero');
  46746. }
  46747. if (-1 === $divisor && ~PHP_INT_MAX === $dividend) {
  46748. throw new \ArithmeticError('Division of PHP_INT_MIN by -1 is not an integer');
  46749. }
  46750. return ($dividend - ($dividend % $divisor)) / $divisor;
  46751. }
  46752. public static function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0)
  46753. {
  46754. $count = 0;
  46755. $result = ''.$subject;
  46756. if (0 === $limit = self::intArg($limit, __FUNCTION__, 3)) {
  46757. return $result;
  46758. }
  46759. foreach ($patterns as $pattern => $callback) {
  46760. $result = preg_replace_callback($pattern, $callback, $result, $limit, $c);
  46761. $count += $c;
  46762. }
  46763. return $result;
  46764. }
  46765. public static function error_clear_last()
  46766. {
  46767. static $handler;
  46768. if (!$handler) {
  46769. $handler = function() { return false; };
  46770. }
  46771. set_error_handler($handler);
  46772. @trigger_error('');
  46773. restore_error_handler();
  46774. }
  46775. public static function intArg($value, $caller, $pos)
  46776. {
  46777. if (is_int($value)) {
  46778. return $value;
  46779. }
  46780. if (!is_numeric($value) || PHP_INT_MAX <= ($value += 0) || ~PHP_INT_MAX >= $value) {
  46781. throw new \TypeError(sprintf('%s() expects parameter %d to be integer, %s given', $caller, $pos, gettype($value)));
  46782. }
  46783. return (int) $value;
  46784. }
  46785. }
  46786. <?php
  46787. class ArithmeticError extends Error
  46788. {
  46789. }
  46790. <?php
  46791. class AssertionError extends Error
  46792. {
  46793. }
  46794. <?php
  46795. class DivisionByZeroError extends Error
  46796. {
  46797. }
  46798. <?php
  46799. class Error extends Exception
  46800. {
  46801. }
  46802. <?php
  46803. class ParseError extends Error
  46804. {
  46805. }
  46806. <?php
  46807. interface SessionUpdateTimestampHandlerInterface
  46808. {
  46809. public function validateId($key);
  46810. public function updateTimestamp($key, $val);
  46811. }
  46812. <?php
  46813. class TypeError extends Error
  46814. {
  46815. }
  46816. <?php
  46817. use Symfony\Polyfill\Php70 as p;
  46818. if (PHP_VERSION_ID < 70000) {
  46819. if (!defined('PHP_INT_MIN')) {
  46820. define('PHP_INT_MIN', ~PHP_INT_MAX);
  46821. }
  46822. if (!function_exists('intdiv')) {
  46823. function intdiv($dividend, $divisor) { return p\Php70::intdiv($dividend, $divisor); }
  46824. }
  46825. if (!function_exists('preg_replace_callback_array')) {
  46826. function preg_replace_callback_array(array $patterns, $subject, $limit = -1, &$count = 0) { return p\Php70::preg_replace_callback_array($patterns, $subject, $limit, $count); }
  46827. }
  46828. if (!function_exists('error_clear_last')) {
  46829. function error_clear_last() { return p\Php70::error_clear_last(); }
  46830. }
  46831. }
  46832. <?php
  46833. namespace Symfony\Polyfill\Php72;
  46834. final class Php72
  46835. {
  46836. private static $hashMask;
  46837. public static function utf8_encode($s)
  46838. {
  46839. $s .= $s;
  46840. $len = strlen($s);
  46841. for ($i = $len >> 1, $j = 0; $i < $len; ++$i, ++$j) {
  46842. switch (true) {
  46843. case $s[$i] < "\x80": $s[$j] = $s[$i]; break;
  46844. case $s[$i] < "\xC0": $s[$j] = "\xC2"; $s[++$j] = $s[$i]; break;
  46845. default: $s[$j] = "\xC3"; $s[++$j] = chr(ord($s[$i]) - 64); break;
  46846. }
  46847. }
  46848. return substr($s, 0, $j);
  46849. }
  46850. public static function utf8_decode($s)
  46851. {
  46852. $s .= '';
  46853. $len = strlen($s);
  46854. for ($i = 0, $j = 0; $i < $len; ++$i, ++$j) {
  46855. switch ($s[$i] & "\xF0") {
  46856. case "\xC0":
  46857. case "\xD0":
  46858. $c = (ord($s[$i] & "\x1F") << 6) | ord($s[++$i] & "\x3F");
  46859. $s[$j] = $c < 256 ? chr($c) : '?';
  46860. break;
  46861. case "\xF0": ++$i;
  46862. case "\xE0":
  46863. $s[$j] = '?';
  46864. $i += 2;
  46865. break;
  46866. default:
  46867. $s[$j] = $s[$i];
  46868. }
  46869. }
  46870. return substr($s, 0, $j);
  46871. }
  46872. public static function php_os_family()
  46873. {
  46874. if ('\\' === DIRECTORY_SEPARATOR) {
  46875. return 'Windows';
  46876. }
  46877. $map = array(
  46878. 'Darwin' => 'Darwin',
  46879. 'DragonFly' => 'BSD',
  46880. 'FreeBSD' => 'BSD',
  46881. 'NetBSD' => 'BSD',
  46882. 'OpenBSD' => 'BSD',
  46883. 'Linux' => 'Linux',
  46884. 'SunOS' => 'Solaris',
  46885. );
  46886. return isset($map[PHP_OS]) ? $map[PHP_OS] : 'Unknown';
  46887. }
  46888. public static function spl_object_id($object)
  46889. {
  46890. if (null === self::$hashMask) {
  46891. self::initHashMask();
  46892. }
  46893. if (null === $hash = spl_object_hash($object)) {
  46894. return;
  46895. }
  46896. return self::$hashMask ^ hexdec(substr($hash, 16 - \PHP_INT_SIZE, \PHP_INT_SIZE));
  46897. }
  46898. private static function initHashMask()
  46899. {
  46900. $obj = (object) array();
  46901. self::$hashMask = -1;
  46902. $obFuncs = array('ob_clean', 'ob_end_clean', 'ob_flush', 'ob_end_flush', 'ob_get_contents', 'ob_get_flush');
  46903. foreach (debug_backtrace(\PHP_VERSION_ID >= 50400 ? DEBUG_BACKTRACE_IGNORE_ARGS : false) as $frame) {
  46904. if (isset($frame['function'][0]) && !isset($frame['class']) && 'o' === $frame['function'][0] && in_array($frame['function'], $obFuncs)) {
  46905. $frame['line'] = 0;
  46906. break;
  46907. }
  46908. }
  46909. if (!empty($frame['line'])) {
  46910. ob_start();
  46911. debug_zval_dump($obj);
  46912. self::$hashMask = (int) substr(ob_get_clean(), 17);
  46913. }
  46914. self::$hashMask ^= hexdec(substr(spl_object_hash($obj), 16 - \PHP_INT_SIZE, \PHP_INT_SIZE));
  46915. }
  46916. }
  46917. <?php
  46918. use Symfony\Polyfill\Php72 as p;
  46919. if (PHP_VERSION_ID < 70200) {
  46920. if ('\\' === DIRECTORY_SEPARATOR && !function_exists('sapi_windows_vt100_support')) {
  46921. function sapi_windows_vt100_support() { return false; }
  46922. }
  46923. if (!function_exists('stream_isatty')) {
  46924. function stream_isatty($stream) { return function_exists('posix_isatty') && @posix_isatty($stream); }
  46925. }
  46926. if (!function_exists('utf8_encode')) {
  46927. function utf8_encode($s) { return p\Php72::utf8_encode($s); }
  46928. function utf8_decode($s) { return p\Php72::utf8_decode($s); }
  46929. }
  46930. if (!function_exists('spl_object_id')) {
  46931. function spl_object_id($s) { return p\Php72::spl_object_id($s); }
  46932. }
  46933. if (!defined('PHP_OS_FAMILY')) {
  46934. define('PHP_OS_FAMILY', p\Php72::php_os_family());
  46935. }
  46936. }
  46937. <?php
  46938. namespace Psr\Log;
  46939. abstract class AbstractLogger implements LoggerInterface
  46940. {
  46941. public function emergency($message, array $context = array())
  46942. {
  46943. $this->log(LogLevel::EMERGENCY, $message, $context);
  46944. }
  46945. public function alert($message, array $context = array())
  46946. {
  46947. $this->log(LogLevel::ALERT, $message, $context);
  46948. }
  46949. public function critical($message, array $context = array())
  46950. {
  46951. $this->log(LogLevel::CRITICAL, $message, $context);
  46952. }
  46953. public function error($message, array $context = array())
  46954. {
  46955. $this->log(LogLevel::ERROR, $message, $context);
  46956. }
  46957. public function warning($message, array $context = array())
  46958. {
  46959. $this->log(LogLevel::WARNING, $message, $context);
  46960. }
  46961. public function notice($message, array $context = array())
  46962. {
  46963. $this->log(LogLevel::NOTICE, $message, $context);
  46964. }
  46965. public function info($message, array $context = array())
  46966. {
  46967. $this->log(LogLevel::INFO, $message, $context);
  46968. }
  46969. public function debug($message, array $context = array())
  46970. {
  46971. $this->log(LogLevel::DEBUG, $message, $context);
  46972. }
  46973. }
  46974. <?php
  46975. namespace Psr\Log;
  46976. class InvalidArgumentException extends \InvalidArgumentException
  46977. {
  46978. }
  46979. <?php
  46980. namespace Psr\Log;
  46981. class LogLevel
  46982. {
  46983. const EMERGENCY = 'emergency';
  46984. const ALERT = 'alert';
  46985. const CRITICAL = 'critical';
  46986. const ERROR = 'error';
  46987. const WARNING = 'warning';
  46988. const NOTICE = 'notice';
  46989. const INFO = 'info';
  46990. const DEBUG = 'debug';
  46991. }
  46992. <?php
  46993. namespace Psr\Log;
  46994. interface LoggerAwareInterface
  46995. {
  46996. public function setLogger(LoggerInterface $logger);
  46997. }
  46998. <?php
  46999. namespace Psr\Log;
  47000. trait LoggerAwareTrait
  47001. {
  47002. protected $logger;
  47003. public function setLogger(LoggerInterface $logger)
  47004. {
  47005. $this->logger = $logger;
  47006. }
  47007. }
  47008. <?php
  47009. namespace Psr\Log;
  47010. interface LoggerInterface
  47011. {
  47012. public function emergency($message, array $context = array());
  47013. public function alert($message, array $context = array());
  47014. public function critical($message, array $context = array());
  47015. public function error($message, array $context = array());
  47016. public function warning($message, array $context = array());
  47017. public function notice($message, array $context = array());
  47018. public function info($message, array $context = array());
  47019. public function debug($message, array $context = array());
  47020. public function log($level, $message, array $context = array());
  47021. }
  47022. <?php
  47023. namespace Psr\Log;
  47024. trait LoggerTrait
  47025. {
  47026. public function emergency($message, array $context = array())
  47027. {
  47028. $this->log(LogLevel::EMERGENCY, $message, $context);
  47029. }
  47030. public function alert($message, array $context = array())
  47031. {
  47032. $this->log(LogLevel::ALERT, $message, $context);
  47033. }
  47034. public function critical($message, array $context = array())
  47035. {
  47036. $this->log(LogLevel::CRITICAL, $message, $context);
  47037. }
  47038. public function error($message, array $context = array())
  47039. {
  47040. $this->log(LogLevel::ERROR, $message, $context);
  47041. }
  47042. public function warning($message, array $context = array())
  47043. {
  47044. $this->log(LogLevel::WARNING, $message, $context);
  47045. }
  47046. public function notice($message, array $context = array())
  47047. {
  47048. $this->log(LogLevel::NOTICE, $message, $context);
  47049. }
  47050. public function info($message, array $context = array())
  47051. {
  47052. $this->log(LogLevel::INFO, $message, $context);
  47053. }
  47054. public function debug($message, array $context = array())
  47055. {
  47056. $this->log(LogLevel::DEBUG, $message, $context);
  47057. }
  47058. abstract public function log($level, $message, array $context = array());
  47059. }
  47060. <?php
  47061. namespace Psr\Log;
  47062. class NullLogger extends AbstractLogger
  47063. {
  47064. public function log($level, $message, array $context = array())
  47065. {
  47066. }
  47067. }
  47068. <?php
  47069. namespace Doctrine\Common\Lexer;
  47070. abstract class AbstractLexer
  47071. {
  47072. private $input;
  47073. private $tokens = array();
  47074. private $position = 0;
  47075. private $peek = 0;
  47076. public $lookahead;
  47077. public $token;
  47078. public function setInput($input)
  47079. {
  47080. $this->input = $input;
  47081. $this->tokens = array();
  47082. $this->reset();
  47083. $this->scan($input);
  47084. }
  47085. public function reset()
  47086. {
  47087. $this->lookahead = null;
  47088. $this->token = null;
  47089. $this->peek = 0;
  47090. $this->position = 0;
  47091. }
  47092. public function resetPeek()
  47093. {
  47094. $this->peek = 0;
  47095. }
  47096. public function resetPosition($position = 0)
  47097. {
  47098. $this->position = $position;
  47099. }
  47100. public function getInputUntilPosition($position)
  47101. {
  47102. return substr($this->input, 0, $position);
  47103. }
  47104. public function isNextToken($token)
  47105. {
  47106. return null !== $this->lookahead && $this->lookahead['type'] === $token;
  47107. }
  47108. public function isNextTokenAny(array $tokens)
  47109. {
  47110. return null !== $this->lookahead && in_array($this->lookahead['type'], $tokens, true);
  47111. }
  47112. public function moveNext()
  47113. {
  47114. $this->peek = 0;
  47115. $this->token = $this->lookahead;
  47116. $this->lookahead = (isset($this->tokens[$this->position]))
  47117. ? $this->tokens[$this->position++] : null;
  47118. return $this->lookahead !== null;
  47119. }
  47120. public function skipUntil($type)
  47121. {
  47122. while ($this->lookahead !== null && $this->lookahead['type'] !== $type) {
  47123. $this->moveNext();
  47124. }
  47125. }
  47126. public function isA($value, $token)
  47127. {
  47128. return $this->getType($value) === $token;
  47129. }
  47130. public function peek()
  47131. {
  47132. if (isset($this->tokens[$this->position + $this->peek])) {
  47133. return $this->tokens[$this->position + $this->peek++];
  47134. } else {
  47135. return null;
  47136. }
  47137. }
  47138. public function glimpse()
  47139. {
  47140. $peek = $this->peek();
  47141. $this->peek = 0;
  47142. return $peek;
  47143. }
  47144. protected function scan($input)
  47145. {
  47146. static $regex;
  47147. if ( ! isset($regex)) {
  47148. $regex = sprintf(
  47149. '/(%s)|%s/%s',
  47150. implode(')|(', $this->getCatchablePatterns()),
  47151. implode('|', $this->getNonCatchablePatterns()),
  47152. $this->getModifiers()
  47153. );
  47154. }
  47155. $flags = PREG_SPLIT_NO_EMPTY | PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_OFFSET_CAPTURE;
  47156. $matches = preg_split($regex, $input, -1, $flags);
  47157. foreach ($matches as $match) {
  47158. $type = $this->getType($match[0]);
  47159. $this->tokens[] = array(
  47160. 'value' => $match[0],
  47161. 'type' => $type,
  47162. 'position' => $match[1],
  47163. );
  47164. }
  47165. }
  47166. public function getLiteral($token)
  47167. {
  47168. $className = get_class($this);
  47169. $reflClass = new \ReflectionClass($className);
  47170. $constants = $reflClass->getConstants();
  47171. foreach ($constants as $name => $value) {
  47172. if ($value === $token) {
  47173. return $className . '::' . $name;
  47174. }
  47175. }
  47176. return $token;
  47177. }
  47178. protected function getModifiers()
  47179. {
  47180. return 'i';
  47181. }
  47182. abstract protected function getCatchablePatterns();
  47183. abstract protected function getNonCatchablePatterns();
  47184. abstract protected function getType(&$value);
  47185. }
  47186. <?php
  47187. namespace Doctrine\Common\Annotations;
  47188. class Annotation
  47189. {
  47190. public $value;
  47191. public final function __construct(array $data)
  47192. {
  47193. foreach ($data as $key => $value) {
  47194. $this->$key = $value;
  47195. }
  47196. }
  47197. public function __get($name)
  47198. {
  47199. throw new \BadMethodCallException(
  47200. sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
  47201. );
  47202. }
  47203. public function __set($name, $value)
  47204. {
  47205. throw new \BadMethodCallException(
  47206. sprintf("Unknown property '%s' on annotation '%s'.", $name, get_class($this))
  47207. );
  47208. }
  47209. }
  47210. <?php
  47211. namespace Doctrine\Common\Annotations\Annotation;
  47212. final class Attribute
  47213. {
  47214. public $name;
  47215. public $type;
  47216. public $required = false;
  47217. }
  47218. <?php
  47219. namespace Doctrine\Common\Annotations\Annotation;
  47220. final class Attributes
  47221. {
  47222. public $value;
  47223. }
  47224. <?php
  47225. namespace Doctrine\Common\Annotations\Annotation;
  47226. final class Enum
  47227. {
  47228. public $value;
  47229. public $literal;
  47230. public function __construct(array $values)
  47231. {
  47232. if ( ! isset($values['literal'])) {
  47233. $values['literal'] = array();
  47234. }
  47235. foreach ($values['value'] as $var) {
  47236. if( ! is_scalar($var)) {
  47237. throw new \InvalidArgumentException(sprintf(
  47238. '@Enum supports only scalar values "%s" given.',
  47239. is_object($var) ? get_class($var) : gettype($var)
  47240. ));
  47241. }
  47242. }
  47243. foreach ($values['literal'] as $key => $var) {
  47244. if( ! in_array($key, $values['value'])) {
  47245. throw new \InvalidArgumentException(sprintf(
  47246. 'Undefined enumerator value "%s" for literal "%s".',
  47247. $key , $var
  47248. ));
  47249. }
  47250. }
  47251. $this->value = $values['value'];
  47252. $this->literal = $values['literal'];
  47253. }
  47254. }
  47255. <?php
  47256. namespace Doctrine\Common\Annotations\Annotation;
  47257. final class IgnoreAnnotation
  47258. {
  47259. public $names;
  47260. public function __construct(array $values)
  47261. {
  47262. if (is_string($values['value'])) {
  47263. $values['value'] = array($values['value']);
  47264. }
  47265. if (!is_array($values['value'])) {
  47266. throw new \RuntimeException(sprintf('@IgnoreAnnotation expects either a string name, or an array of strings, but got %s.', json_encode($values['value'])));
  47267. }
  47268. $this->names = $values['value'];
  47269. }
  47270. }
  47271. <?php
  47272. namespace Doctrine\Common\Annotations\Annotation;
  47273. final class Required
  47274. {
  47275. }
  47276. <?php
  47277. namespace Doctrine\Common\Annotations\Annotation;
  47278. final class Target
  47279. {
  47280. const TARGET_CLASS = 1;
  47281. const TARGET_METHOD = 2;
  47282. const TARGET_PROPERTY = 4;
  47283. const TARGET_ANNOTATION = 8;
  47284. const TARGET_ALL = 15;
  47285. private static $map = array(
  47286. 'ALL' => self::TARGET_ALL,
  47287. 'CLASS' => self::TARGET_CLASS,
  47288. 'METHOD' => self::TARGET_METHOD,
  47289. 'PROPERTY' => self::TARGET_PROPERTY,
  47290. 'ANNOTATION' => self::TARGET_ANNOTATION,
  47291. );
  47292. public $value;
  47293. public $targets;
  47294. public $literal;
  47295. public function __construct(array $values)
  47296. {
  47297. if (!isset($values['value'])){
  47298. $values['value'] = null;
  47299. }
  47300. if (is_string($values['value'])){
  47301. $values['value'] = array($values['value']);
  47302. }
  47303. if (!is_array($values['value'])){
  47304. throw new \InvalidArgumentException(
  47305. sprintf('@Target expects either a string value, or an array of strings, "%s" given.',
  47306. is_object($values['value']) ? get_class($values['value']) : gettype($values['value'])
  47307. )
  47308. );
  47309. }
  47310. $bitmask = 0;
  47311. foreach ($values['value'] as $literal) {
  47312. if(!isset(self::$map[$literal])){
  47313. throw new \InvalidArgumentException(
  47314. sprintf('Invalid Target "%s". Available targets: [%s]',
  47315. $literal, implode(', ', array_keys(self::$map)))
  47316. );
  47317. }
  47318. $bitmask |= self::$map[$literal];
  47319. }
  47320. $this->targets = $bitmask;
  47321. $this->value = $values['value'];
  47322. $this->literal = implode(', ', $this->value);
  47323. }
  47324. }
  47325. <?php
  47326. namespace Doctrine\Common\Annotations;
  47327. class AnnotationException extends \Exception
  47328. {
  47329. public static function syntaxError($message)
  47330. {
  47331. return new self('[Syntax Error] ' . $message);
  47332. }
  47333. public static function semanticalError($message)
  47334. {
  47335. return new self('[Semantical Error] ' . $message);
  47336. }
  47337. public static function creationError($message)
  47338. {
  47339. return new self('[Creation Error] ' . $message);
  47340. }
  47341. public static function typeError($message)
  47342. {
  47343. return new self('[Type Error] ' . $message);
  47344. }
  47345. public static function semanticalErrorConstants($identifier, $context = null)
  47346. {
  47347. return self::semanticalError(sprintf(
  47348. "Couldn't find constant %s%s.",
  47349. $identifier,
  47350. $context ? ', ' . $context : ''
  47351. ));
  47352. }
  47353. public static function attributeTypeError($attributeName, $annotationName, $context, $expected, $actual)
  47354. {
  47355. return self::typeError(sprintf(
  47356. 'Attribute "%s" of @%s declared on %s expects %s, but got %s.',
  47357. $attributeName,
  47358. $annotationName,
  47359. $context,
  47360. $expected,
  47361. is_object($actual) ? 'an instance of ' . get_class($actual) : gettype($actual)
  47362. ));
  47363. }
  47364. public static function requiredError($attributeName, $annotationName, $context, $expected)
  47365. {
  47366. return self::typeError(sprintf(
  47367. 'Attribute "%s" of @%s declared on %s expects %s. This value should not be null.',
  47368. $attributeName,
  47369. $annotationName,
  47370. $context,
  47371. $expected
  47372. ));
  47373. }
  47374. public static function enumeratorError($attributeName, $annotationName, $context, $available, $given)
  47375. {
  47376. return new self(sprintf(
  47377. '[Enum Error] Attribute "%s" of @%s declared on %s accept only [%s], but got %s.',
  47378. $attributeName,
  47379. $annotationName,
  47380. $context,
  47381. implode(', ', $available),
  47382. is_object($given) ? get_class($given) : $given
  47383. ));
  47384. }
  47385. public static function optimizerPlusSaveComments()
  47386. {
  47387. return new self(
  47388. "You have to enable opcache.save_comments=1 or zend_optimizerplus.save_comments=1."
  47389. );
  47390. }
  47391. public static function optimizerPlusLoadComments()
  47392. {
  47393. return new self(
  47394. "You have to enable opcache.load_comments=1 or zend_optimizerplus.load_comments=1."
  47395. );
  47396. }
  47397. }
  47398. <?php
  47399. namespace Doctrine\Common\Annotations;
  47400. use Doctrine\Common\Annotations\Annotation\IgnoreAnnotation;
  47401. use Doctrine\Common\Annotations\Annotation\Target;
  47402. use ReflectionClass;
  47403. use ReflectionMethod;
  47404. use ReflectionProperty;
  47405. class AnnotationReader implements Reader
  47406. {
  47407. private static $globalImports = array(
  47408. 'ignoreannotation' => 'Doctrine\Common\Annotations\Annotation\IgnoreAnnotation',
  47409. );
  47410. private static $globalIgnoredNames = array(
  47411. 'Annotation' => true, 'Attribute' => true, 'Attributes' => true,
  47412. 'Required' => true,
  47413. 'Target' => true,
  47414. 'fix' => true , 'fixme' => true,
  47415. 'override' => true,
  47416. 'abstract'=> true, 'access'=> true,
  47417. 'code' => true,
  47418. 'deprec'=> true,
  47419. 'endcode' => true, 'exception'=> true,
  47420. 'final'=> true,
  47421. 'ingroup' => true, 'inheritdoc'=> true, 'inheritDoc'=> true,
  47422. 'magic' => true,
  47423. 'name'=> true,
  47424. 'toc' => true, 'tutorial'=> true,
  47425. 'private' => true,
  47426. 'static'=> true, 'staticvar'=> true, 'staticVar'=> true,
  47427. 'throw' => true,
  47428. 'api' => true, 'author'=> true,
  47429. 'category'=> true, 'copyright'=> true,
  47430. 'deprecated'=> true,
  47431. 'example'=> true,
  47432. 'filesource'=> true,
  47433. 'global'=> true,
  47434. 'ignore'=> true, 'internal'=> true,
  47435. 'license'=> true, 'link'=> true,
  47436. 'method' => true,
  47437. 'package'=> true, 'param'=> true, 'property' => true, 'property-read' => true, 'property-write' => true,
  47438. 'return'=> true,
  47439. 'see'=> true, 'since'=> true, 'source' => true, 'subpackage'=> true,
  47440. 'throws'=> true, 'todo'=> true, 'TODO'=> true,
  47441. 'usedby'=> true, 'uses' => true,
  47442. 'var'=> true, 'version'=> true,
  47443. 'codeCoverageIgnore' => true, 'codeCoverageIgnoreStart' => true, 'codeCoverageIgnoreEnd' => true,
  47444. 'SuppressWarnings' => true,
  47445. 'noinspection' => true,
  47446. 'package_version' => true,
  47447. 'startuml' => true, 'enduml' => true,
  47448. );
  47449. private static $globalIgnoredNamespaces = array();
  47450. static public function addGlobalIgnoredName($name)
  47451. {
  47452. self::$globalIgnoredNames[$name] = true;
  47453. }
  47454. static public function addGlobalIgnoredNamespace($namespace)
  47455. {
  47456. self::$globalIgnoredNamespaces[$namespace] = true;
  47457. }
  47458. private $parser;
  47459. private $preParser;
  47460. private $phpParser;
  47461. private $imports = array();
  47462. private $ignoredAnnotationNames = array();
  47463. public function __construct(DocParser $parser = null)
  47464. {
  47465. if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.save_comments') === "0" || ini_get('opcache.save_comments') === "0")) {
  47466. throw AnnotationException::optimizerPlusSaveComments();
  47467. }
  47468. if (extension_loaded('Zend OPcache') && ini_get('opcache.save_comments') == 0) {
  47469. throw AnnotationException::optimizerPlusSaveComments();
  47470. }
  47471. if (PHP_VERSION_ID < 70000) {
  47472. if (extension_loaded('Zend Optimizer+') && (ini_get('zend_optimizerplus.load_comments') === "0" || ini_get('opcache.load_comments') === "0")) {
  47473. throw AnnotationException::optimizerPlusLoadComments();
  47474. }
  47475. if (extension_loaded('Zend OPcache') && ini_get('opcache.load_comments') == 0) {
  47476. throw AnnotationException::optimizerPlusLoadComments();
  47477. }
  47478. }
  47479. AnnotationRegistry::registerFile(__DIR__ . '/Annotation/IgnoreAnnotation.php');
  47480. $this->parser = $parser ?: new DocParser();
  47481. $this->preParser = new DocParser;
  47482. $this->preParser->setImports(self::$globalImports);
  47483. $this->preParser->setIgnoreNotImportedAnnotations(true);
  47484. $this->phpParser = new PhpParser;
  47485. }
  47486. public function getClassAnnotations(ReflectionClass $class)
  47487. {
  47488. $this->parser->setTarget(Target::TARGET_CLASS);
  47489. $this->parser->setImports($this->getClassImports($class));
  47490. $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
  47491. $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
  47492. return $this->parser->parse($class->getDocComment(), 'class ' . $class->getName());
  47493. }
  47494. public function getClassAnnotation(ReflectionClass $class, $annotationName)
  47495. {
  47496. $annotations = $this->getClassAnnotations($class);
  47497. foreach ($annotations as $annotation) {
  47498. if ($annotation instanceof $annotationName) {
  47499. return $annotation;
  47500. }
  47501. }
  47502. return null;
  47503. }
  47504. public function getPropertyAnnotations(ReflectionProperty $property)
  47505. {
  47506. $class = $property->getDeclaringClass();
  47507. $context = 'property ' . $class->getName() . "::\$" . $property->getName();
  47508. $this->parser->setTarget(Target::TARGET_PROPERTY);
  47509. $this->parser->setImports($this->getPropertyImports($property));
  47510. $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
  47511. $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
  47512. return $this->parser->parse($property->getDocComment(), $context);
  47513. }
  47514. public function getPropertyAnnotation(ReflectionProperty $property, $annotationName)
  47515. {
  47516. $annotations = $this->getPropertyAnnotations($property);
  47517. foreach ($annotations as $annotation) {
  47518. if ($annotation instanceof $annotationName) {
  47519. return $annotation;
  47520. }
  47521. }
  47522. return null;
  47523. }
  47524. public function getMethodAnnotations(ReflectionMethod $method)
  47525. {
  47526. $class = $method->getDeclaringClass();
  47527. $context = 'method ' . $class->getName() . '::' . $method->getName() . '()';
  47528. $this->parser->setTarget(Target::TARGET_METHOD);
  47529. $this->parser->setImports($this->getMethodImports($method));
  47530. $this->parser->setIgnoredAnnotationNames($this->getIgnoredAnnotationNames($class));
  47531. $this->parser->setIgnoredAnnotationNamespaces(self::$globalIgnoredNamespaces);
  47532. return $this->parser->parse($method->getDocComment(), $context);
  47533. }
  47534. public function getMethodAnnotation(ReflectionMethod $method, $annotationName)
  47535. {
  47536. $annotations = $this->getMethodAnnotations($method);
  47537. foreach ($annotations as $annotation) {
  47538. if ($annotation instanceof $annotationName) {
  47539. return $annotation;
  47540. }
  47541. }
  47542. return null;
  47543. }
  47544. private function getIgnoredAnnotationNames(ReflectionClass $class)
  47545. {
  47546. $name = $class->getName();
  47547. if (isset($this->ignoredAnnotationNames[$name])) {
  47548. return $this->ignoredAnnotationNames[$name];
  47549. }
  47550. $this->collectParsingMetadata($class);
  47551. return $this->ignoredAnnotationNames[$name];
  47552. }
  47553. private function getClassImports(ReflectionClass $class)
  47554. {
  47555. $name = $class->getName();
  47556. if (isset($this->imports[$name])) {
  47557. return $this->imports[$name];
  47558. }
  47559. $this->collectParsingMetadata($class);
  47560. return $this->imports[$name];
  47561. }
  47562. private function getMethodImports(ReflectionMethod $method)
  47563. {
  47564. $class = $method->getDeclaringClass();
  47565. $classImports = $this->getClassImports($class);
  47566. if (!method_exists($class, 'getTraits')) {
  47567. return $classImports;
  47568. }
  47569. $traitImports = array();
  47570. foreach ($class->getTraits() as $trait) {
  47571. if ($trait->hasMethod($method->getName())
  47572. && $trait->getFileName() === $method->getFileName()
  47573. ) {
  47574. $traitImports = array_merge($traitImports, $this->phpParser->parseClass($trait));
  47575. }
  47576. }
  47577. return array_merge($classImports, $traitImports);
  47578. }
  47579. private function getPropertyImports(ReflectionProperty $property)
  47580. {
  47581. $class = $property->getDeclaringClass();
  47582. $classImports = $this->getClassImports($class);
  47583. if (!method_exists($class, 'getTraits')) {
  47584. return $classImports;
  47585. }
  47586. $traitImports = array();
  47587. foreach ($class->getTraits() as $trait) {
  47588. if ($trait->hasProperty($property->getName())) {
  47589. $traitImports = array_merge($traitImports, $this->phpParser->parseClass($trait));
  47590. }
  47591. }
  47592. return array_merge($classImports, $traitImports);
  47593. }
  47594. private function collectParsingMetadata(ReflectionClass $class)
  47595. {
  47596. $ignoredAnnotationNames = self::$globalIgnoredNames;
  47597. $annotations = $this->preParser->parse($class->getDocComment(), 'class ' . $class->name);
  47598. foreach ($annotations as $annotation) {
  47599. if ($annotation instanceof IgnoreAnnotation) {
  47600. foreach ($annotation->names AS $annot) {
  47601. $ignoredAnnotationNames[$annot] = true;
  47602. }
  47603. }
  47604. }
  47605. $name = $class->getName();
  47606. $this->imports[$name] = array_merge(
  47607. self::$globalImports,
  47608. $this->phpParser->parseClass($class),
  47609. array('__NAMESPACE__' => $class->getNamespaceName())
  47610. );
  47611. $this->ignoredAnnotationNames[$name] = $ignoredAnnotationNames;
  47612. }
  47613. }
  47614. <?php
  47615. namespace Doctrine\Common\Annotations;
  47616. final class AnnotationRegistry
  47617. {
  47618. static private $autoloadNamespaces = array();
  47619. static private $loaders = array();
  47620. static public function reset()
  47621. {
  47622. self::$autoloadNamespaces = array();
  47623. self::$loaders = array();
  47624. }
  47625. static public function registerFile($file)
  47626. {
  47627. require_once $file;
  47628. }
  47629. static public function registerAutoloadNamespace($namespace, $dirs = null)
  47630. {
  47631. self::$autoloadNamespaces[$namespace] = $dirs;
  47632. }
  47633. static public function registerAutoloadNamespaces(array $namespaces)
  47634. {
  47635. self::$autoloadNamespaces = array_merge(self::$autoloadNamespaces, $namespaces);
  47636. }
  47637. static public function registerLoader($callable)
  47638. {
  47639. if (!is_callable($callable)) {
  47640. throw new \InvalidArgumentException("A callable is expected in AnnotationRegistry::registerLoader().");
  47641. }
  47642. self::$loaders[] = $callable;
  47643. }
  47644. static public function loadAnnotationClass($class)
  47645. {
  47646. foreach (self::$autoloadNamespaces AS $namespace => $dirs) {
  47647. if (strpos($class, $namespace) === 0) {
  47648. $file = str_replace("\\", DIRECTORY_SEPARATOR, $class) . ".php";
  47649. if ($dirs === null) {
  47650. if ($path = stream_resolve_include_path($file)) {
  47651. require $path;
  47652. return true;
  47653. }
  47654. } else {
  47655. foreach((array)$dirs AS $dir) {
  47656. if (is_file($dir . DIRECTORY_SEPARATOR . $file)) {
  47657. require $dir . DIRECTORY_SEPARATOR . $file;
  47658. return true;
  47659. }
  47660. }
  47661. }
  47662. }
  47663. }
  47664. foreach (self::$loaders AS $loader) {
  47665. if (call_user_func($loader, $class) === true) {
  47666. return true;
  47667. }
  47668. }
  47669. return false;
  47670. }
  47671. }
  47672. <?php
  47673. namespace Doctrine\Common\Annotations;
  47674. use Doctrine\Common\Cache\Cache;
  47675. use ReflectionClass;
  47676. final class CachedReader implements Reader
  47677. {
  47678. private $delegate;
  47679. private $cache;
  47680. private $debug;
  47681. private $loadedAnnotations = array();
  47682. public function __construct(Reader $reader, Cache $cache, $debug = false)
  47683. {
  47684. $this->delegate = $reader;
  47685. $this->cache = $cache;
  47686. $this->debug = (boolean) $debug;
  47687. }
  47688. public function getClassAnnotations(ReflectionClass $class)
  47689. {
  47690. $cacheKey = $class->getName();
  47691. if (isset($this->loadedAnnotations[$cacheKey])) {
  47692. return $this->loadedAnnotations[$cacheKey];
  47693. }
  47694. if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
  47695. $annots = $this->delegate->getClassAnnotations($class);
  47696. $this->saveToCache($cacheKey, $annots);
  47697. }
  47698. return $this->loadedAnnotations[$cacheKey] = $annots;
  47699. }
  47700. public function getClassAnnotation(ReflectionClass $class, $annotationName)
  47701. {
  47702. foreach ($this->getClassAnnotations($class) as $annot) {
  47703. if ($annot instanceof $annotationName) {
  47704. return $annot;
  47705. }
  47706. }
  47707. return null;
  47708. }
  47709. public function getPropertyAnnotations(\ReflectionProperty $property)
  47710. {
  47711. $class = $property->getDeclaringClass();
  47712. $cacheKey = $class->getName().'$'.$property->getName();
  47713. if (isset($this->loadedAnnotations[$cacheKey])) {
  47714. return $this->loadedAnnotations[$cacheKey];
  47715. }
  47716. if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
  47717. $annots = $this->delegate->getPropertyAnnotations($property);
  47718. $this->saveToCache($cacheKey, $annots);
  47719. }
  47720. return $this->loadedAnnotations[$cacheKey] = $annots;
  47721. }
  47722. public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
  47723. {
  47724. foreach ($this->getPropertyAnnotations($property) as $annot) {
  47725. if ($annot instanceof $annotationName) {
  47726. return $annot;
  47727. }
  47728. }
  47729. return null;
  47730. }
  47731. public function getMethodAnnotations(\ReflectionMethod $method)
  47732. {
  47733. $class = $method->getDeclaringClass();
  47734. $cacheKey = $class->getName().'#'.$method->getName();
  47735. if (isset($this->loadedAnnotations[$cacheKey])) {
  47736. return $this->loadedAnnotations[$cacheKey];
  47737. }
  47738. if (false === ($annots = $this->fetchFromCache($cacheKey, $class))) {
  47739. $annots = $this->delegate->getMethodAnnotations($method);
  47740. $this->saveToCache($cacheKey, $annots);
  47741. }
  47742. return $this->loadedAnnotations[$cacheKey] = $annots;
  47743. }
  47744. public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
  47745. {
  47746. foreach ($this->getMethodAnnotations($method) as $annot) {
  47747. if ($annot instanceof $annotationName) {
  47748. return $annot;
  47749. }
  47750. }
  47751. return null;
  47752. }
  47753. public function clearLoadedAnnotations()
  47754. {
  47755. $this->loadedAnnotations = array();
  47756. }
  47757. private function fetchFromCache($cacheKey, ReflectionClass $class)
  47758. {
  47759. if (($data = $this->cache->fetch($cacheKey)) !== false) {
  47760. if (!$this->debug || $this->isCacheFresh($cacheKey, $class)) {
  47761. return $data;
  47762. }
  47763. }
  47764. return false;
  47765. }
  47766. private function saveToCache($cacheKey, $value)
  47767. {
  47768. $this->cache->save($cacheKey, $value);
  47769. if ($this->debug) {
  47770. $this->cache->save('[C]'.$cacheKey, time());
  47771. }
  47772. }
  47773. private function isCacheFresh($cacheKey, ReflectionClass $class)
  47774. {
  47775. if (null === $lastModification = $this->getLastModification($class)) {
  47776. return true;
  47777. }
  47778. return $this->cache->fetch('[C]'.$cacheKey) >= $lastModification;
  47779. }
  47780. private function getLastModification(ReflectionClass $class)
  47781. {
  47782. $filename = $class->getFileName();
  47783. $parent = $class->getParentClass();
  47784. return max(array_merge(
  47785. [$filename ? filemtime($filename) : 0],
  47786. array_map([$this, 'getTraitLastModificationTime'], $class->getTraits()),
  47787. array_map([$this, 'getLastModification'], $class->getInterfaces()),
  47788. $parent ? [$this->getLastModification($parent)] : []
  47789. ));
  47790. }
  47791. private function getTraitLastModificationTime(ReflectionClass $reflectionTrait)
  47792. {
  47793. $fileName = $reflectionTrait->getFileName();
  47794. return max(array_merge(
  47795. [$fileName ? filemtime($fileName) : 0],
  47796. array_map([$this, 'getTraitLastModificationTime'], $reflectionTrait->getTraits())
  47797. ));
  47798. }
  47799. }
  47800. <?php
  47801. namespace Doctrine\Common\Annotations;
  47802. use Doctrine\Common\Lexer\AbstractLexer;
  47803. final class DocLexer extends AbstractLexer
  47804. {
  47805. const T_NONE = 1;
  47806. const T_INTEGER = 2;
  47807. const T_STRING = 3;
  47808. const T_FLOAT = 4;
  47809. const T_IDENTIFIER = 100;
  47810. const T_AT = 101;
  47811. const T_CLOSE_CURLY_BRACES = 102;
  47812. const T_CLOSE_PARENTHESIS = 103;
  47813. const T_COMMA = 104;
  47814. const T_EQUALS = 105;
  47815. const T_FALSE = 106;
  47816. const T_NAMESPACE_SEPARATOR = 107;
  47817. const T_OPEN_CURLY_BRACES = 108;
  47818. const T_OPEN_PARENTHESIS = 109;
  47819. const T_TRUE = 110;
  47820. const T_NULL = 111;
  47821. const T_COLON = 112;
  47822. protected $noCase = array(
  47823. '@' => self::T_AT,
  47824. ',' => self::T_COMMA,
  47825. '(' => self::T_OPEN_PARENTHESIS,
  47826. ')' => self::T_CLOSE_PARENTHESIS,
  47827. '{' => self::T_OPEN_CURLY_BRACES,
  47828. '}' => self::T_CLOSE_CURLY_BRACES,
  47829. '=' => self::T_EQUALS,
  47830. ':' => self::T_COLON,
  47831. '\\' => self::T_NAMESPACE_SEPARATOR
  47832. );
  47833. protected $withCase = array(
  47834. 'true' => self::T_TRUE,
  47835. 'false' => self::T_FALSE,
  47836. 'null' => self::T_NULL
  47837. );
  47838. protected function getCatchablePatterns()
  47839. {
  47840. return array(
  47841. '[a-z_\\\][a-z0-9_\:\\\]*[a-z_][a-z0-9_]*',
  47842. '(?:[+-]?[0-9]+(?:[\.][0-9]+)*)(?:[eE][+-]?[0-9]+)?',
  47843. '"(?:""|[^"])*+"',
  47844. );
  47845. }
  47846. protected function getNonCatchablePatterns()
  47847. {
  47848. return array('\s+', '\*+', '(.)');
  47849. }
  47850. protected function getType(&$value)
  47851. {
  47852. $type = self::T_NONE;
  47853. if ($value[0] === '"') {
  47854. $value = str_replace('""', '"', substr($value, 1, strlen($value) - 2));
  47855. return self::T_STRING;
  47856. }
  47857. if (isset($this->noCase[$value])) {
  47858. return $this->noCase[$value];
  47859. }
  47860. if ($value[0] === '_' || $value[0] === '\\' || ctype_alpha($value[0])) {
  47861. return self::T_IDENTIFIER;
  47862. }
  47863. $lowerValue = strtolower($value);
  47864. if (isset($this->withCase[$lowerValue])) {
  47865. return $this->withCase[$lowerValue];
  47866. }
  47867. if (is_numeric($value)) {
  47868. return (strpos($value, '.') !== false || stripos($value, 'e') !== false)
  47869. ? self::T_FLOAT : self::T_INTEGER;
  47870. }
  47871. return $type;
  47872. }
  47873. }
  47874. <?php
  47875. namespace Doctrine\Common\Annotations;
  47876. use Doctrine\Common\Annotations\Annotation\Attribute;
  47877. use ReflectionClass;
  47878. use Doctrine\Common\Annotations\Annotation\Enum;
  47879. use Doctrine\Common\Annotations\Annotation\Target;
  47880. use Doctrine\Common\Annotations\Annotation\Attributes;
  47881. final class DocParser
  47882. {
  47883. private static $classIdentifiers = array(
  47884. DocLexer::T_IDENTIFIER,
  47885. DocLexer::T_TRUE,
  47886. DocLexer::T_FALSE,
  47887. DocLexer::T_NULL
  47888. );
  47889. private $lexer;
  47890. private $target;
  47891. private static $metadataParser;
  47892. private $isNestedAnnotation = false;
  47893. private $imports = array();
  47894. private $classExists = array();
  47895. private $ignoreNotImportedAnnotations = false;
  47896. private $namespaces = array();
  47897. private $ignoredAnnotationNames = array();
  47898. private $ignoredAnnotationNamespaces = array();
  47899. private $context = '';
  47900. private static $annotationMetadata = array(
  47901. 'Doctrine\Common\Annotations\Annotation\Target' => array(
  47902. 'is_annotation' => true,
  47903. 'has_constructor' => true,
  47904. 'properties' => array(),
  47905. 'targets_literal' => 'ANNOTATION_CLASS',
  47906. 'targets' => Target::TARGET_CLASS,
  47907. 'default_property' => 'value',
  47908. 'attribute_types' => array(
  47909. 'value' => array(
  47910. 'required' => false,
  47911. 'type' =>'array',
  47912. 'array_type'=>'string',
  47913. 'value' =>'array<string>'
  47914. )
  47915. ),
  47916. ),
  47917. 'Doctrine\Common\Annotations\Annotation\Attribute' => array(
  47918. 'is_annotation' => true,
  47919. 'has_constructor' => false,
  47920. 'targets_literal' => 'ANNOTATION_ANNOTATION',
  47921. 'targets' => Target::TARGET_ANNOTATION,
  47922. 'default_property' => 'name',
  47923. 'properties' => array(
  47924. 'name' => 'name',
  47925. 'type' => 'type',
  47926. 'required' => 'required'
  47927. ),
  47928. 'attribute_types' => array(
  47929. 'value' => array(
  47930. 'required' => true,
  47931. 'type' =>'string',
  47932. 'value' =>'string'
  47933. ),
  47934. 'type' => array(
  47935. 'required' =>true,
  47936. 'type' =>'string',
  47937. 'value' =>'string'
  47938. ),
  47939. 'required' => array(
  47940. 'required' =>false,
  47941. 'type' =>'boolean',
  47942. 'value' =>'boolean'
  47943. )
  47944. ),
  47945. ),
  47946. 'Doctrine\Common\Annotations\Annotation\Attributes' => array(
  47947. 'is_annotation' => true,
  47948. 'has_constructor' => false,
  47949. 'targets_literal' => 'ANNOTATION_CLASS',
  47950. 'targets' => Target::TARGET_CLASS,
  47951. 'default_property' => 'value',
  47952. 'properties' => array(
  47953. 'value' => 'value'
  47954. ),
  47955. 'attribute_types' => array(
  47956. 'value' => array(
  47957. 'type' =>'array',
  47958. 'required' =>true,
  47959. 'array_type'=>'Doctrine\Common\Annotations\Annotation\Attribute',
  47960. 'value' =>'array<Doctrine\Common\Annotations\Annotation\Attribute>'
  47961. )
  47962. ),
  47963. ),
  47964. 'Doctrine\Common\Annotations\Annotation\Enum' => array(
  47965. 'is_annotation' => true,
  47966. 'has_constructor' => true,
  47967. 'targets_literal' => 'ANNOTATION_PROPERTY',
  47968. 'targets' => Target::TARGET_PROPERTY,
  47969. 'default_property' => 'value',
  47970. 'properties' => array(
  47971. 'value' => 'value'
  47972. ),
  47973. 'attribute_types' => array(
  47974. 'value' => array(
  47975. 'type' => 'array',
  47976. 'required' => true,
  47977. ),
  47978. 'literal' => array(
  47979. 'type' => 'array',
  47980. 'required' => false,
  47981. ),
  47982. ),
  47983. ),
  47984. );
  47985. private static $typeMap = array(
  47986. 'float' => 'double',
  47987. 'bool' => 'boolean',
  47988. 'Boolean' => 'boolean',
  47989. 'int' => 'integer',
  47990. );
  47991. public function __construct()
  47992. {
  47993. $this->lexer = new DocLexer;
  47994. }
  47995. public function setIgnoredAnnotationNames(array $names)
  47996. {
  47997. $this->ignoredAnnotationNames = $names;
  47998. }
  47999. public function setIgnoredAnnotationNamespaces($ignoredAnnotationNamespaces)
  48000. {
  48001. $this->ignoredAnnotationNamespaces = $ignoredAnnotationNamespaces;
  48002. }
  48003. public function setIgnoreNotImportedAnnotations($bool)
  48004. {
  48005. $this->ignoreNotImportedAnnotations = (boolean) $bool;
  48006. }
  48007. public function addNamespace($namespace)
  48008. {
  48009. if ($this->imports) {
  48010. throw new \RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
  48011. }
  48012. $this->namespaces[] = $namespace;
  48013. }
  48014. public function setImports(array $imports)
  48015. {
  48016. if ($this->namespaces) {
  48017. throw new \RuntimeException('You must either use addNamespace(), or setImports(), but not both.');
  48018. }
  48019. $this->imports = $imports;
  48020. }
  48021. public function setTarget($target)
  48022. {
  48023. $this->target = $target;
  48024. }
  48025. public function parse($input, $context = '')
  48026. {
  48027. $pos = $this->findInitialTokenPosition($input);
  48028. if ($pos === null) {
  48029. return array();
  48030. }
  48031. $this->context = $context;
  48032. $this->lexer->setInput(trim(substr($input, $pos), '* /'));
  48033. $this->lexer->moveNext();
  48034. return $this->Annotations();
  48035. }
  48036. private function findInitialTokenPosition($input)
  48037. {
  48038. $pos = 0;
  48039. while (($pos = strpos($input, '@', $pos)) !== false) {
  48040. $preceding = substr($input, $pos - 1, 1);
  48041. if ($pos === 0 || $preceding === ' ' || $preceding === '*' || $preceding === "\t") {
  48042. return $pos;
  48043. }
  48044. $pos++;
  48045. }
  48046. return null;
  48047. }
  48048. private function match($token)
  48049. {
  48050. if ( ! $this->lexer->isNextToken($token) ) {
  48051. $this->syntaxError($this->lexer->getLiteral($token));
  48052. }
  48053. return $this->lexer->moveNext();
  48054. }
  48055. private function matchAny(array $tokens)
  48056. {
  48057. if ( ! $this->lexer->isNextTokenAny($tokens)) {
  48058. $this->syntaxError(implode(' or ', array_map(array($this->lexer, 'getLiteral'), $tokens)));
  48059. }
  48060. return $this->lexer->moveNext();
  48061. }
  48062. private function syntaxError($expected, $token = null)
  48063. {
  48064. if ($token === null) {
  48065. $token = $this->lexer->lookahead;
  48066. }
  48067. $message = sprintf('Expected %s, got ', $expected);
  48068. $message .= ($this->lexer->lookahead === null)
  48069. ? 'end of string'
  48070. : sprintf("'%s' at position %s", $token['value'], $token['position']);
  48071. if (strlen($this->context)) {
  48072. $message .= ' in ' . $this->context;
  48073. }
  48074. $message .= '.';
  48075. throw AnnotationException::syntaxError($message);
  48076. }
  48077. private function classExists($fqcn)
  48078. {
  48079. if (isset($this->classExists[$fqcn])) {
  48080. return $this->classExists[$fqcn];
  48081. }
  48082. if (class_exists($fqcn, false)) {
  48083. return $this->classExists[$fqcn] = true;
  48084. }
  48085. return $this->classExists[$fqcn] = AnnotationRegistry::loadAnnotationClass($fqcn);
  48086. }
  48087. private function collectAnnotationMetadata($name)
  48088. {
  48089. if (self::$metadataParser === null) {
  48090. self::$metadataParser = new self();
  48091. self::$metadataParser->setIgnoreNotImportedAnnotations(true);
  48092. self::$metadataParser->setIgnoredAnnotationNames($this->ignoredAnnotationNames);
  48093. self::$metadataParser->setImports(array(
  48094. 'enum' => 'Doctrine\Common\Annotations\Annotation\Enum',
  48095. 'target' => 'Doctrine\Common\Annotations\Annotation\Target',
  48096. 'attribute' => 'Doctrine\Common\Annotations\Annotation\Attribute',
  48097. 'attributes' => 'Doctrine\Common\Annotations\Annotation\Attributes'
  48098. ));
  48099. AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Enum.php');
  48100. AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Target.php');
  48101. AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attribute.php');
  48102. AnnotationRegistry::registerFile(__DIR__ . '/Annotation/Attributes.php');
  48103. }
  48104. $class = new \ReflectionClass($name);
  48105. $docComment = $class->getDocComment();
  48106. $metadata = array(
  48107. 'default_property' => null,
  48108. 'has_constructor' => (null !== $constructor = $class->getConstructor()) && $constructor->getNumberOfParameters() > 0,
  48109. 'properties' => array(),
  48110. 'property_types' => array(),
  48111. 'attribute_types' => array(),
  48112. 'targets_literal' => null,
  48113. 'targets' => Target::TARGET_ALL,
  48114. 'is_annotation' => false !== strpos($docComment, '@Annotation'),
  48115. );
  48116. if ($metadata['is_annotation']) {
  48117. self::$metadataParser->setTarget(Target::TARGET_CLASS);
  48118. foreach (self::$metadataParser->parse($docComment, 'class @' . $name) as $annotation) {
  48119. if ($annotation instanceof Target) {
  48120. $metadata['targets'] = $annotation->targets;
  48121. $metadata['targets_literal'] = $annotation->literal;
  48122. continue;
  48123. }
  48124. if ($annotation instanceof Attributes) {
  48125. foreach ($annotation->value as $attribute) {
  48126. $this->collectAttributeTypeMetadata($metadata, $attribute);
  48127. }
  48128. }
  48129. }
  48130. if (false === $metadata['has_constructor']) {
  48131. foreach ($class->getProperties(\ReflectionProperty::IS_PUBLIC) as $property) {
  48132. $metadata['properties'][$property->name] = $property->name;
  48133. if (false === ($propertyComment = $property->getDocComment())) {
  48134. continue;
  48135. }
  48136. $attribute = new Attribute();
  48137. $attribute->required = (false !== strpos($propertyComment, '@Required'));
  48138. $attribute->name = $property->name;
  48139. $attribute->type = (false !== strpos($propertyComment, '@var') && preg_match('/@var\s+([^\s]+)/',$propertyComment, $matches))
  48140. ? $matches[1]
  48141. : 'mixed';
  48142. $this->collectAttributeTypeMetadata($metadata, $attribute);
  48143. if (false !== strpos($propertyComment, '@Enum')) {
  48144. $context = 'property ' . $class->name . "::\$" . $property->name;
  48145. self::$metadataParser->setTarget(Target::TARGET_PROPERTY);
  48146. foreach (self::$metadataParser->parse($propertyComment, $context) as $annotation) {
  48147. if ( ! $annotation instanceof Enum) {
  48148. continue;
  48149. }
  48150. $metadata['enum'][$property->name]['value'] = $annotation->value;
  48151. $metadata['enum'][$property->name]['literal'] = ( ! empty($annotation->literal))
  48152. ? $annotation->literal
  48153. : $annotation->value;
  48154. }
  48155. }
  48156. }
  48157. $metadata['default_property'] = reset($metadata['properties']);
  48158. }
  48159. }
  48160. self::$annotationMetadata[$name] = $metadata;
  48161. }
  48162. private function collectAttributeTypeMetadata(&$metadata, Attribute $attribute)
  48163. {
  48164. $type = isset(self::$typeMap[$attribute->type])
  48165. ? self::$typeMap[$attribute->type]
  48166. : $attribute->type;
  48167. if ('mixed' === $type) {
  48168. return;
  48169. }
  48170. switch (true) {
  48171. case (false !== $pos = strpos($type, '<')):
  48172. $arrayType = substr($type, $pos + 1, -1);
  48173. $type = 'array';
  48174. if (isset(self::$typeMap[$arrayType])) {
  48175. $arrayType = self::$typeMap[$arrayType];
  48176. }
  48177. $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
  48178. break;
  48179. case (false !== $pos = strrpos($type, '[')):
  48180. $arrayType = substr($type, 0, $pos);
  48181. $type = 'array';
  48182. if (isset(self::$typeMap[$arrayType])) {
  48183. $arrayType = self::$typeMap[$arrayType];
  48184. }
  48185. $metadata['attribute_types'][$attribute->name]['array_type'] = $arrayType;
  48186. break;
  48187. }
  48188. $metadata['attribute_types'][$attribute->name]['type'] = $type;
  48189. $metadata['attribute_types'][$attribute->name]['value'] = $attribute->type;
  48190. $metadata['attribute_types'][$attribute->name]['required'] = $attribute->required;
  48191. }
  48192. private function Annotations()
  48193. {
  48194. $annotations = array();
  48195. while (null !== $this->lexer->lookahead) {
  48196. if (DocLexer::T_AT !== $this->lexer->lookahead['type']) {
  48197. $this->lexer->moveNext();
  48198. continue;
  48199. }
  48200. if (null !== $this->lexer->token && $this->lexer->lookahead['position'] === $this->lexer->token['position'] + strlen($this->lexer->token['value'])) {
  48201. $this->lexer->moveNext();
  48202. continue;
  48203. }
  48204. if ((null === $peek = $this->lexer->glimpse())
  48205. || (DocLexer::T_NAMESPACE_SEPARATOR !== $peek['type'] && !in_array($peek['type'], self::$classIdentifiers, true))
  48206. || $peek['position'] !== $this->lexer->lookahead['position'] + 1) {
  48207. $this->lexer->moveNext();
  48208. continue;
  48209. }
  48210. $this->isNestedAnnotation = false;
  48211. if (false !== $annot = $this->Annotation()) {
  48212. $annotations[] = $annot;
  48213. }
  48214. }
  48215. return $annotations;
  48216. }
  48217. private function Annotation()
  48218. {
  48219. $this->match(DocLexer::T_AT);
  48220. $name = $this->Identifier();
  48221. $originalName = $name;
  48222. if ('\\' !== $name[0]) {
  48223. $pos = strpos($name, '\\');
  48224. $alias = (false === $pos)? $name : substr($name, 0, $pos);
  48225. $found = false;
  48226. $loweredAlias = strtolower($alias);
  48227. if ($this->namespaces) {
  48228. foreach ($this->namespaces as $namespace) {
  48229. if ($this->classExists($namespace.'\\'.$name)) {
  48230. $name = $namespace.'\\'.$name;
  48231. $found = true;
  48232. break;
  48233. }
  48234. }
  48235. } elseif (isset($this->imports[$loweredAlias])) {
  48236. $found = true;
  48237. $name = (false !== $pos)
  48238. ? $this->imports[$loweredAlias] . substr($name, $pos)
  48239. : $this->imports[$loweredAlias];
  48240. } elseif ( ! isset($this->ignoredAnnotationNames[$name])
  48241. && isset($this->imports['__NAMESPACE__'])
  48242. && $this->classExists($this->imports['__NAMESPACE__'] . '\\' . $name)
  48243. ) {
  48244. $name = $this->imports['__NAMESPACE__'].'\\'.$name;
  48245. $found = true;
  48246. } elseif (! isset($this->ignoredAnnotationNames[$name]) && $this->classExists($name)) {
  48247. $found = true;
  48248. }
  48249. if ( ! $found) {
  48250. if ($this->isIgnoredAnnotation($name)) {
  48251. return false;
  48252. }
  48253. throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s was never imported. Did you maybe forget to add a "use" statement for this annotation?', $name, $this->context));
  48254. }
  48255. }
  48256. $name = ltrim($name,'\\');
  48257. if ( ! $this->classExists($name)) {
  48258. throw AnnotationException::semanticalError(sprintf('The annotation "@%s" in %s does not exist, or could not be auto-loaded.', $name, $this->context));
  48259. }
  48260. if ( ! isset(self::$annotationMetadata[$name])) {
  48261. $this->collectAnnotationMetadata($name);
  48262. }
  48263. if (self::$annotationMetadata[$name]['is_annotation'] === false) {
  48264. if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$originalName])) {
  48265. return false;
  48266. }
  48267. throw AnnotationException::semanticalError(sprintf('The class "%s" is not annotated with @Annotation. Are you sure this class can be used as annotation? If so, then you need to add @Annotation to the _class_ doc comment of "%s". If it is indeed no annotation, then you need to add @IgnoreAnnotation("%s") to the _class_ doc comment of %s.', $name, $name, $originalName, $this->context));
  48268. }
  48269. $target = $this->isNestedAnnotation ? Target::TARGET_ANNOTATION : $this->target;
  48270. $this->isNestedAnnotation = true;
  48271. if (0 === (self::$annotationMetadata[$name]['targets'] & $target) && $target) {
  48272. throw AnnotationException::semanticalError(
  48273. sprintf('Annotation @%s is not allowed to be declared on %s. You may only use this annotation on these code elements: %s.',
  48274. $originalName, $this->context, self::$annotationMetadata[$name]['targets_literal'])
  48275. );
  48276. }
  48277. $values = $this->MethodCall();
  48278. if (isset(self::$annotationMetadata[$name]['enum'])) {
  48279. foreach (self::$annotationMetadata[$name]['enum'] as $property => $enum) {
  48280. if (isset($values[$property]) && ! in_array($values[$property], $enum['value'])) {
  48281. throw AnnotationException::enumeratorError($property, $name, $this->context, $enum['literal'], $values[$property]);
  48282. }
  48283. }
  48284. }
  48285. foreach (self::$annotationMetadata[$name]['attribute_types'] as $property => $type) {
  48286. if ($property === self::$annotationMetadata[$name]['default_property']
  48287. && !isset($values[$property]) && isset($values['value'])) {
  48288. $property = 'value';
  48289. }
  48290. if (!isset($values[$property])) {
  48291. if ($type['required']) {
  48292. throw AnnotationException::requiredError($property, $originalName, $this->context, 'a(n) '.$type['value']);
  48293. }
  48294. continue;
  48295. }
  48296. if ($type['type'] === 'array') {
  48297. if ( ! is_array($values[$property])) {
  48298. $values[$property] = array($values[$property]);
  48299. }
  48300. if (isset($type['array_type'])) {
  48301. foreach ($values[$property] as $item) {
  48302. if (gettype($item) !== $type['array_type'] && !$item instanceof $type['array_type']) {
  48303. throw AnnotationException::attributeTypeError($property, $originalName, $this->context, 'either a(n) '.$type['array_type'].', or an array of '.$type['array_type'].'s', $item);
  48304. }
  48305. }
  48306. }
  48307. } elseif (gettype($values[$property]) !== $type['type'] && !$values[$property] instanceof $type['type']) {
  48308. throw AnnotationException::attributeTypeError($property, $originalName, $this->context, 'a(n) '.$type['value'], $values[$property]);
  48309. }
  48310. }
  48311. if (self::$annotationMetadata[$name]['has_constructor'] === true) {
  48312. return new $name($values);
  48313. }
  48314. $instance = new $name();
  48315. foreach ($values as $property => $value) {
  48316. if (!isset(self::$annotationMetadata[$name]['properties'][$property])) {
  48317. if ('value' !== $property) {
  48318. throw AnnotationException::creationError(sprintf('The annotation @%s declared on %s does not have a property named "%s". Available properties: %s', $originalName, $this->context, $property, implode(', ', self::$annotationMetadata[$name]['properties'])));
  48319. }
  48320. if ( ! $property = self::$annotationMetadata[$name]['default_property']) {
  48321. throw AnnotationException::creationError(sprintf('The annotation @%s declared on %s does not accept any values, but got %s.', $originalName, $this->context, json_encode($values)));
  48322. }
  48323. }
  48324. $instance->{$property} = $value;
  48325. }
  48326. return $instance;
  48327. }
  48328. private function MethodCall()
  48329. {
  48330. $values = array();
  48331. if ( ! $this->lexer->isNextToken(DocLexer::T_OPEN_PARENTHESIS)) {
  48332. return $values;
  48333. }
  48334. $this->match(DocLexer::T_OPEN_PARENTHESIS);
  48335. if ( ! $this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
  48336. $values = $this->Values();
  48337. }
  48338. $this->match(DocLexer::T_CLOSE_PARENTHESIS);
  48339. return $values;
  48340. }
  48341. private function Values()
  48342. {
  48343. $values = array($this->Value());
  48344. while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
  48345. $this->match(DocLexer::T_COMMA);
  48346. if ($this->lexer->isNextToken(DocLexer::T_CLOSE_PARENTHESIS)) {
  48347. break;
  48348. }
  48349. $token = $this->lexer->lookahead;
  48350. $value = $this->Value();
  48351. if ( ! is_object($value) && ! is_array($value)) {
  48352. $this->syntaxError('Value', $token);
  48353. }
  48354. $values[] = $value;
  48355. }
  48356. foreach ($values as $k => $value) {
  48357. if (is_object($value) && $value instanceof \stdClass) {
  48358. $values[$value->name] = $value->value;
  48359. } else if ( ! isset($values['value'])){
  48360. $values['value'] = $value;
  48361. } else {
  48362. if ( ! is_array($values['value'])) {
  48363. $values['value'] = array($values['value']);
  48364. }
  48365. $values['value'][] = $value;
  48366. }
  48367. unset($values[$k]);
  48368. }
  48369. return $values;
  48370. }
  48371. private function Constant()
  48372. {
  48373. $identifier = $this->Identifier();
  48374. if ( ! defined($identifier) && false !== strpos($identifier, '::') && '\\' !== $identifier[0]) {
  48375. list($className, $const) = explode('::', $identifier);
  48376. $pos = strpos($className, '\\');
  48377. $alias = (false === $pos) ? $className : substr($className, 0, $pos);
  48378. $found = false;
  48379. $loweredAlias = strtolower($alias);
  48380. switch (true) {
  48381. case !empty ($this->namespaces):
  48382. foreach ($this->namespaces as $ns) {
  48383. if (class_exists($ns.'\\'.$className) || interface_exists($ns.'\\'.$className)) {
  48384. $className = $ns.'\\'.$className;
  48385. $found = true;
  48386. break;
  48387. }
  48388. }
  48389. break;
  48390. case isset($this->imports[$loweredAlias]):
  48391. $found = true;
  48392. $className = (false !== $pos)
  48393. ? $this->imports[$loweredAlias] . substr($className, $pos)
  48394. : $this->imports[$loweredAlias];
  48395. break;
  48396. default:
  48397. if(isset($this->imports['__NAMESPACE__'])) {
  48398. $ns = $this->imports['__NAMESPACE__'];
  48399. if (class_exists($ns.'\\'.$className) || interface_exists($ns.'\\'.$className)) {
  48400. $className = $ns.'\\'.$className;
  48401. $found = true;
  48402. }
  48403. }
  48404. break;
  48405. }
  48406. if ($found) {
  48407. $identifier = $className . '::' . $const;
  48408. }
  48409. }
  48410. $classPos = stripos($identifier, '::class');
  48411. if ($classPos === strlen($identifier) - 7) {
  48412. return substr($identifier, 0, $classPos);
  48413. }
  48414. if (!defined($identifier)) {
  48415. throw AnnotationException::semanticalErrorConstants($identifier, $this->context);
  48416. }
  48417. return constant($identifier);
  48418. }
  48419. private function Identifier()
  48420. {
  48421. if ( ! $this->lexer->isNextTokenAny(self::$classIdentifiers)) {
  48422. $this->syntaxError('namespace separator or identifier');
  48423. }
  48424. $this->lexer->moveNext();
  48425. $className = $this->lexer->token['value'];
  48426. while ($this->lexer->lookahead['position'] === ($this->lexer->token['position'] + strlen($this->lexer->token['value']))
  48427. && $this->lexer->isNextToken(DocLexer::T_NAMESPACE_SEPARATOR)) {
  48428. $this->match(DocLexer::T_NAMESPACE_SEPARATOR);
  48429. $this->matchAny(self::$classIdentifiers);
  48430. $className .= '\\' . $this->lexer->token['value'];
  48431. }
  48432. return $className;
  48433. }
  48434. private function Value()
  48435. {
  48436. $peek = $this->lexer->glimpse();
  48437. if (DocLexer::T_EQUALS === $peek['type']) {
  48438. return $this->FieldAssignment();
  48439. }
  48440. return $this->PlainValue();
  48441. }
  48442. private function PlainValue()
  48443. {
  48444. if ($this->lexer->isNextToken(DocLexer::T_OPEN_CURLY_BRACES)) {
  48445. return $this->Arrayx();
  48446. }
  48447. if ($this->lexer->isNextToken(DocLexer::T_AT)) {
  48448. return $this->Annotation();
  48449. }
  48450. if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
  48451. return $this->Constant();
  48452. }
  48453. switch ($this->lexer->lookahead['type']) {
  48454. case DocLexer::T_STRING:
  48455. $this->match(DocLexer::T_STRING);
  48456. return $this->lexer->token['value'];
  48457. case DocLexer::T_INTEGER:
  48458. $this->match(DocLexer::T_INTEGER);
  48459. return (int)$this->lexer->token['value'];
  48460. case DocLexer::T_FLOAT:
  48461. $this->match(DocLexer::T_FLOAT);
  48462. return (float)$this->lexer->token['value'];
  48463. case DocLexer::T_TRUE:
  48464. $this->match(DocLexer::T_TRUE);
  48465. return true;
  48466. case DocLexer::T_FALSE:
  48467. $this->match(DocLexer::T_FALSE);
  48468. return false;
  48469. case DocLexer::T_NULL:
  48470. $this->match(DocLexer::T_NULL);
  48471. return null;
  48472. default:
  48473. $this->syntaxError('PlainValue');
  48474. }
  48475. }
  48476. private function FieldAssignment()
  48477. {
  48478. $this->match(DocLexer::T_IDENTIFIER);
  48479. $fieldName = $this->lexer->token['value'];
  48480. $this->match(DocLexer::T_EQUALS);
  48481. $item = new \stdClass();
  48482. $item->name = $fieldName;
  48483. $item->value = $this->PlainValue();
  48484. return $item;
  48485. }
  48486. private function Arrayx()
  48487. {
  48488. $array = $values = array();
  48489. $this->match(DocLexer::T_OPEN_CURLY_BRACES);
  48490. if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
  48491. $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
  48492. return $array;
  48493. }
  48494. $values[] = $this->ArrayEntry();
  48495. while ($this->lexer->isNextToken(DocLexer::T_COMMA)) {
  48496. $this->match(DocLexer::T_COMMA);
  48497. if ($this->lexer->isNextToken(DocLexer::T_CLOSE_CURLY_BRACES)) {
  48498. break;
  48499. }
  48500. $values[] = $this->ArrayEntry();
  48501. }
  48502. $this->match(DocLexer::T_CLOSE_CURLY_BRACES);
  48503. foreach ($values as $value) {
  48504. list ($key, $val) = $value;
  48505. if ($key !== null) {
  48506. $array[$key] = $val;
  48507. } else {
  48508. $array[] = $val;
  48509. }
  48510. }
  48511. return $array;
  48512. }
  48513. private function ArrayEntry()
  48514. {
  48515. $peek = $this->lexer->glimpse();
  48516. if (DocLexer::T_EQUALS === $peek['type']
  48517. || DocLexer::T_COLON === $peek['type']) {
  48518. if ($this->lexer->isNextToken(DocLexer::T_IDENTIFIER)) {
  48519. $key = $this->Constant();
  48520. } else {
  48521. $this->matchAny(array(DocLexer::T_INTEGER, DocLexer::T_STRING));
  48522. $key = $this->lexer->token['value'];
  48523. }
  48524. $this->matchAny(array(DocLexer::T_EQUALS, DocLexer::T_COLON));
  48525. return array($key, $this->PlainValue());
  48526. }
  48527. return array(null, $this->Value());
  48528. }
  48529. private function isIgnoredAnnotation($name)
  48530. {
  48531. if ($this->ignoreNotImportedAnnotations || isset($this->ignoredAnnotationNames[$name])) {
  48532. return true;
  48533. }
  48534. foreach (array_keys($this->ignoredAnnotationNamespaces) as $ignoredAnnotationNamespace) {
  48535. $ignoredAnnotationNamespace = rtrim($ignoredAnnotationNamespace, '\\') . '\\';
  48536. if (0 === stripos(rtrim($name, '\\') . '\\', $ignoredAnnotationNamespace)) {
  48537. return true;
  48538. }
  48539. }
  48540. return false;
  48541. }
  48542. }
  48543. <?php
  48544. namespace Doctrine\Common\Annotations;
  48545. class FileCacheReader implements Reader
  48546. {
  48547. private $reader;
  48548. private $dir;
  48549. private $debug;
  48550. private $loadedAnnotations = array();
  48551. private $classNameHashes = array();
  48552. private $umask;
  48553. public function __construct(Reader $reader, $cacheDir, $debug = false, $umask = 0002)
  48554. {
  48555. if ( ! is_int($umask)) {
  48556. throw new \InvalidArgumentException(sprintf(
  48557. 'The parameter umask must be an integer, was: %s',
  48558. gettype($umask)
  48559. ));
  48560. }
  48561. $this->reader = $reader;
  48562. $this->umask = $umask;
  48563. if (!is_dir($cacheDir) && !@mkdir($cacheDir, 0777 & (~$this->umask), true)) {
  48564. throw new \InvalidArgumentException(sprintf('The directory "%s" does not exist and could not be created.', $cacheDir));
  48565. }
  48566. $this->dir = rtrim($cacheDir, '\\/');
  48567. $this->debug = $debug;
  48568. }
  48569. public function getClassAnnotations(\ReflectionClass $class)
  48570. {
  48571. if ( ! isset($this->classNameHashes[$class->name])) {
  48572. $this->classNameHashes[$class->name] = sha1($class->name);
  48573. }
  48574. $key = $this->classNameHashes[$class->name];
  48575. if (isset($this->loadedAnnotations[$key])) {
  48576. return $this->loadedAnnotations[$key];
  48577. }
  48578. $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
  48579. if (!is_file($path)) {
  48580. $annot = $this->reader->getClassAnnotations($class);
  48581. $this->saveCacheFile($path, $annot);
  48582. return $this->loadedAnnotations[$key] = $annot;
  48583. }
  48584. if ($this->debug
  48585. && (false !== $filename = $class->getFileName())
  48586. && filemtime($path) < filemtime($filename)) {
  48587. @unlink($path);
  48588. $annot = $this->reader->getClassAnnotations($class);
  48589. $this->saveCacheFile($path, $annot);
  48590. return $this->loadedAnnotations[$key] = $annot;
  48591. }
  48592. return $this->loadedAnnotations[$key] = include $path;
  48593. }
  48594. public function getPropertyAnnotations(\ReflectionProperty $property)
  48595. {
  48596. $class = $property->getDeclaringClass();
  48597. if ( ! isset($this->classNameHashes[$class->name])) {
  48598. $this->classNameHashes[$class->name] = sha1($class->name);
  48599. }
  48600. $key = $this->classNameHashes[$class->name].'$'.$property->getName();
  48601. if (isset($this->loadedAnnotations[$key])) {
  48602. return $this->loadedAnnotations[$key];
  48603. }
  48604. $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
  48605. if (!is_file($path)) {
  48606. $annot = $this->reader->getPropertyAnnotations($property);
  48607. $this->saveCacheFile($path, $annot);
  48608. return $this->loadedAnnotations[$key] = $annot;
  48609. }
  48610. if ($this->debug
  48611. && (false !== $filename = $class->getFilename())
  48612. && filemtime($path) < filemtime($filename)) {
  48613. @unlink($path);
  48614. $annot = $this->reader->getPropertyAnnotations($property);
  48615. $this->saveCacheFile($path, $annot);
  48616. return $this->loadedAnnotations[$key] = $annot;
  48617. }
  48618. return $this->loadedAnnotations[$key] = include $path;
  48619. }
  48620. public function getMethodAnnotations(\ReflectionMethod $method)
  48621. {
  48622. $class = $method->getDeclaringClass();
  48623. if ( ! isset($this->classNameHashes[$class->name])) {
  48624. $this->classNameHashes[$class->name] = sha1($class->name);
  48625. }
  48626. $key = $this->classNameHashes[$class->name].'#'.$method->getName();
  48627. if (isset($this->loadedAnnotations[$key])) {
  48628. return $this->loadedAnnotations[$key];
  48629. }
  48630. $path = $this->dir.'/'.strtr($key, '\\', '-').'.cache.php';
  48631. if (!is_file($path)) {
  48632. $annot = $this->reader->getMethodAnnotations($method);
  48633. $this->saveCacheFile($path, $annot);
  48634. return $this->loadedAnnotations[$key] = $annot;
  48635. }
  48636. if ($this->debug
  48637. && (false !== $filename = $class->getFilename())
  48638. && filemtime($path) < filemtime($filename)) {
  48639. @unlink($path);
  48640. $annot = $this->reader->getMethodAnnotations($method);
  48641. $this->saveCacheFile($path, $annot);
  48642. return $this->loadedAnnotations[$key] = $annot;
  48643. }
  48644. return $this->loadedAnnotations[$key] = include $path;
  48645. }
  48646. private function saveCacheFile($path, $data)
  48647. {
  48648. if (!is_writable($this->dir)) {
  48649. throw new \InvalidArgumentException(sprintf('The directory "%s" is not writable. Both, the webserver and the console user need access. You can manage access rights for multiple users with "chmod +a". If your system does not support this, check out the acl package.', $this->dir));
  48650. }
  48651. $tempfile = tempnam($this->dir, uniqid('', true));
  48652. if (false === $tempfile) {
  48653. throw new \RuntimeException(sprintf('Unable to create tempfile in directory: %s', $this->dir));
  48654. }
  48655. @chmod($tempfile, 0666 & (~$this->umask));
  48656. $written = file_put_contents($tempfile, '<?php return unserialize('.var_export(serialize($data), true).');');
  48657. if (false === $written) {
  48658. throw new \RuntimeException(sprintf('Unable to write cached file to: %s', $tempfile));
  48659. }
  48660. @chmod($tempfile, 0666 & (~$this->umask));
  48661. if (false === rename($tempfile, $path)) {
  48662. @unlink($tempfile);
  48663. throw new \RuntimeException(sprintf('Unable to rename %s to %s', $tempfile, $path));
  48664. }
  48665. }
  48666. public function getClassAnnotation(\ReflectionClass $class, $annotationName)
  48667. {
  48668. $annotations = $this->getClassAnnotations($class);
  48669. foreach ($annotations as $annotation) {
  48670. if ($annotation instanceof $annotationName) {
  48671. return $annotation;
  48672. }
  48673. }
  48674. return null;
  48675. }
  48676. public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
  48677. {
  48678. $annotations = $this->getMethodAnnotations($method);
  48679. foreach ($annotations as $annotation) {
  48680. if ($annotation instanceof $annotationName) {
  48681. return $annotation;
  48682. }
  48683. }
  48684. return null;
  48685. }
  48686. public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
  48687. {
  48688. $annotations = $this->getPropertyAnnotations($property);
  48689. foreach ($annotations as $annotation) {
  48690. if ($annotation instanceof $annotationName) {
  48691. return $annotation;
  48692. }
  48693. }
  48694. return null;
  48695. }
  48696. public function clearLoadedAnnotations()
  48697. {
  48698. $this->loadedAnnotations = array();
  48699. }
  48700. }
  48701. <?php
  48702. namespace Doctrine\Common\Annotations;
  48703. class IndexedReader implements Reader
  48704. {
  48705. private $delegate;
  48706. public function __construct(Reader $reader)
  48707. {
  48708. $this->delegate = $reader;
  48709. }
  48710. public function getClassAnnotations(\ReflectionClass $class)
  48711. {
  48712. $annotations = array();
  48713. foreach ($this->delegate->getClassAnnotations($class) as $annot) {
  48714. $annotations[get_class($annot)] = $annot;
  48715. }
  48716. return $annotations;
  48717. }
  48718. public function getClassAnnotation(\ReflectionClass $class, $annotation)
  48719. {
  48720. return $this->delegate->getClassAnnotation($class, $annotation);
  48721. }
  48722. public function getMethodAnnotations(\ReflectionMethod $method)
  48723. {
  48724. $annotations = array();
  48725. foreach ($this->delegate->getMethodAnnotations($method) as $annot) {
  48726. $annotations[get_class($annot)] = $annot;
  48727. }
  48728. return $annotations;
  48729. }
  48730. public function getMethodAnnotation(\ReflectionMethod $method, $annotation)
  48731. {
  48732. return $this->delegate->getMethodAnnotation($method, $annotation);
  48733. }
  48734. public function getPropertyAnnotations(\ReflectionProperty $property)
  48735. {
  48736. $annotations = array();
  48737. foreach ($this->delegate->getPropertyAnnotations($property) as $annot) {
  48738. $annotations[get_class($annot)] = $annot;
  48739. }
  48740. return $annotations;
  48741. }
  48742. public function getPropertyAnnotation(\ReflectionProperty $property, $annotation)
  48743. {
  48744. return $this->delegate->getPropertyAnnotation($property, $annotation);
  48745. }
  48746. public function __call($method, $args)
  48747. {
  48748. return call_user_func_array(array($this->delegate, $method), $args);
  48749. }
  48750. }
  48751. <?php
  48752. namespace Doctrine\Common\Annotations;
  48753. use SplFileObject;
  48754. final class PhpParser
  48755. {
  48756. public function parseClass(\ReflectionClass $class)
  48757. {
  48758. if (method_exists($class, 'getUseStatements')) {
  48759. return $class->getUseStatements();
  48760. }
  48761. if (false === $filename = $class->getFileName()) {
  48762. return array();
  48763. }
  48764. $content = $this->getFileContent($filename, $class->getStartLine());
  48765. if (null === $content) {
  48766. return array();
  48767. }
  48768. $namespace = preg_quote($class->getNamespaceName());
  48769. $content = preg_replace('/^.*?(\bnamespace\s+' . $namespace . '\s*[;{].*)$/s', '\\1', $content);
  48770. $tokenizer = new TokenParser('<?php ' . $content);
  48771. $statements = $tokenizer->parseUseStatements($class->getNamespaceName());
  48772. return $statements;
  48773. }
  48774. private function getFileContent($filename, $lineNumber)
  48775. {
  48776. if ( ! is_file($filename)) {
  48777. return null;
  48778. }
  48779. $content = '';
  48780. $lineCnt = 0;
  48781. $file = new SplFileObject($filename);
  48782. while (!$file->eof()) {
  48783. if ($lineCnt++ == $lineNumber) {
  48784. break;
  48785. }
  48786. $content .= $file->fgets();
  48787. }
  48788. return $content;
  48789. }
  48790. }
  48791. <?php
  48792. namespace Doctrine\Common\Annotations;
  48793. interface Reader
  48794. {
  48795. function getClassAnnotations(\ReflectionClass $class);
  48796. function getClassAnnotation(\ReflectionClass $class, $annotationName);
  48797. function getMethodAnnotations(\ReflectionMethod $method);
  48798. function getMethodAnnotation(\ReflectionMethod $method, $annotationName);
  48799. function getPropertyAnnotations(\ReflectionProperty $property);
  48800. function getPropertyAnnotation(\ReflectionProperty $property, $annotationName);
  48801. }
  48802. <?php
  48803. namespace Doctrine\Common\Annotations;
  48804. class SimpleAnnotationReader implements Reader
  48805. {
  48806. private $parser;
  48807. public function __construct()
  48808. {
  48809. $this->parser = new DocParser();
  48810. $this->parser->setIgnoreNotImportedAnnotations(true);
  48811. }
  48812. public function addNamespace($namespace)
  48813. {
  48814. $this->parser->addNamespace($namespace);
  48815. }
  48816. public function getClassAnnotations(\ReflectionClass $class)
  48817. {
  48818. return $this->parser->parse($class->getDocComment(), 'class '.$class->getName());
  48819. }
  48820. public function getMethodAnnotations(\ReflectionMethod $method)
  48821. {
  48822. return $this->parser->parse($method->getDocComment(), 'method '.$method->getDeclaringClass()->name.'::'.$method->getName().'()');
  48823. }
  48824. public function getPropertyAnnotations(\ReflectionProperty $property)
  48825. {
  48826. return $this->parser->parse($property->getDocComment(), 'property '.$property->getDeclaringClass()->name.'::$'.$property->getName());
  48827. }
  48828. public function getClassAnnotation(\ReflectionClass $class, $annotationName)
  48829. {
  48830. foreach ($this->getClassAnnotations($class) as $annot) {
  48831. if ($annot instanceof $annotationName) {
  48832. return $annot;
  48833. }
  48834. }
  48835. return null;
  48836. }
  48837. public function getMethodAnnotation(\ReflectionMethod $method, $annotationName)
  48838. {
  48839. foreach ($this->getMethodAnnotations($method) as $annot) {
  48840. if ($annot instanceof $annotationName) {
  48841. return $annot;
  48842. }
  48843. }
  48844. return null;
  48845. }
  48846. public function getPropertyAnnotation(\ReflectionProperty $property, $annotationName)
  48847. {
  48848. foreach ($this->getPropertyAnnotations($property) as $annot) {
  48849. if ($annot instanceof $annotationName) {
  48850. return $annot;
  48851. }
  48852. }
  48853. return null;
  48854. }
  48855. }
  48856. <?php
  48857. namespace Doctrine\Common\Annotations;
  48858. class TokenParser
  48859. {
  48860. private $tokens;
  48861. private $numTokens;
  48862. private $pointer = 0;
  48863. public function __construct($contents)
  48864. {
  48865. $this->tokens = token_get_all($contents);
  48866. token_get_all("<?php\n/**\n *\n */");
  48867. $this->numTokens = count($this->tokens);
  48868. }
  48869. public function next($docCommentIsComment = TRUE)
  48870. {
  48871. for ($i = $this->pointer; $i < $this->numTokens; $i++) {
  48872. $this->pointer++;
  48873. if ($this->tokens[$i][0] === T_WHITESPACE ||
  48874. $this->tokens[$i][0] === T_COMMENT ||
  48875. ($docCommentIsComment && $this->tokens[$i][0] === T_DOC_COMMENT)) {
  48876. continue;
  48877. }
  48878. return $this->tokens[$i];
  48879. }
  48880. return null;
  48881. }
  48882. public function parseUseStatement()
  48883. {
  48884. $groupRoot = '';
  48885. $class = '';
  48886. $alias = '';
  48887. $statements = array();
  48888. $explicitAlias = false;
  48889. while (($token = $this->next())) {
  48890. $isNameToken = $token[0] === T_STRING || $token[0] === T_NS_SEPARATOR;
  48891. if (!$explicitAlias && $isNameToken) {
  48892. $class .= $token[1];
  48893. $alias = $token[1];
  48894. } else if ($explicitAlias && $isNameToken) {
  48895. $alias .= $token[1];
  48896. } else if ($token[0] === T_AS) {
  48897. $explicitAlias = true;
  48898. $alias = '';
  48899. } else if ($token === ',') {
  48900. $statements[strtolower($alias)] = $groupRoot . $class;
  48901. $class = '';
  48902. $alias = '';
  48903. $explicitAlias = false;
  48904. } else if ($token === ';') {
  48905. $statements[strtolower($alias)] = $groupRoot . $class;
  48906. break;
  48907. } else if ($token === '{' ) {
  48908. $groupRoot = $class;
  48909. $class = '';
  48910. } else if ($token === '}' ) {
  48911. continue;
  48912. } else {
  48913. break;
  48914. }
  48915. }
  48916. return $statements;
  48917. }
  48918. public function parseUseStatements($namespaceName)
  48919. {
  48920. $statements = array();
  48921. while (($token = $this->next())) {
  48922. if ($token[0] === T_USE) {
  48923. $statements = array_merge($statements, $this->parseUseStatement());
  48924. continue;
  48925. }
  48926. if ($token[0] !== T_NAMESPACE || $this->parseNamespace() != $namespaceName) {
  48927. continue;
  48928. }
  48929. $statements = array();
  48930. }
  48931. return $statements;
  48932. }
  48933. public function parseNamespace()
  48934. {
  48935. $name = '';
  48936. while (($token = $this->next()) && ($token[0] === T_STRING || $token[0] === T_NS_SEPARATOR)) {
  48937. $name .= $token[1];
  48938. }
  48939. return $name;
  48940. }
  48941. public function parseClass()
  48942. {
  48943. return $this->parseNamespace();
  48944. }
  48945. }
  48946. <?php
  48947. namespace GeckoPackages\PHPUnit\Asserts;
  48948. final class AssertHelper
  48949. {
  48950. public static function assertMethodDependency($class, $trait, $method, array $methodDependencies)
  48951. {
  48952. $missing = array();
  48953. foreach ($methodDependencies as $methodDependency) {
  48954. if (!method_exists($class, $methodDependency)) {
  48955. $missing[] = sprintf('"%s"', $methodDependency);
  48956. }
  48957. }
  48958. if (0 === count($missing)) {
  48959. return;
  48960. }
  48961. throw self::createException(
  48962. $trait,
  48963. $method,
  48964. sprintf('Relies on missing %s %s', count($missing) > 1 ? 'methods' : 'method', implode(', ', $missing))
  48965. );
  48966. }
  48967. public static function createArgumentException($trait, $method, $expectedTypeForArgument, $valueOfArgument, $index = 1)
  48968. {
  48969. if (is_object($valueOfArgument)) {
  48970. $valueOfArgument = sprintf('%s#%s', get_class($valueOfArgument), method_exists($valueOfArgument, '__toString') ? $valueOfArgument->__toString() : '');
  48971. } elseif (null === $valueOfArgument) {
  48972. $valueOfArgument = 'null';
  48973. } else {
  48974. $valueOfArgument = gettype($valueOfArgument).'#'.$valueOfArgument;
  48975. }
  48976. return new \PHPUnit_Framework_Exception(
  48977. sprintf(
  48978. 'Argument #%d (%s) of %s::%s() must be %s.',
  48979. $index,
  48980. $valueOfArgument,
  48981. substr($trait, strrpos($trait, '\\') + 1),
  48982. $method,
  48983. (in_array($expectedTypeForArgument[0], array('a', 'e', 'i', 'o', 'u'), true) ? 'an' : 'a').' '.$expectedTypeForArgument
  48984. )
  48985. );
  48986. }
  48987. public static function createException($trait, $method, $message)
  48988. {
  48989. return new \PHPUnit_Framework_Exception(
  48990. sprintf(
  48991. '%s::%s() %s.',
  48992. substr($trait, strrpos($trait, '\\') + 1),
  48993. $method,
  48994. $message
  48995. )
  48996. );
  48997. }
  48998. }
  48999. <?php
  49000. namespace GeckoPackages\PHPUnit\Asserts;
  49001. use GeckoPackages\PHPUnit\Constraints\FileExistsConstraint;
  49002. trait FileExistsAssertTrait
  49003. {
  49004. public static function assertFileExists($filename, $message = '')
  49005. {
  49006. self::assertFileExisting($filename, $message, 'assertFileExists', new FileExistsConstraint());
  49007. }
  49008. public static function assertFileNotExists($filename, $message = '')
  49009. {
  49010. self::assertFileExisting($filename, $message, 'assertFileNotExists', new \PHPUnit_Framework_Constraint_Not(new FileExistsConstraint()));
  49011. }
  49012. private static function assertFileExisting($filename, $message, $method, \PHPUnit_Framework_Constraint $constraint)
  49013. {
  49014. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, $method, array('assertThat'));
  49015. self::assertThat($filename, $constraint, $message);
  49016. }
  49017. }
  49018. <?php
  49019. namespace GeckoPackages\PHPUnit\Asserts;
  49020. use GeckoPackages\PHPUnit\Constraints\DirectoryEmptyConstraint;
  49021. use GeckoPackages\PHPUnit\Constraints\DirectoryExistsConstraint;
  49022. use GeckoPackages\PHPUnit\Constraints\FileIsLinkConstraint;
  49023. use GeckoPackages\PHPUnit\Constraints\FileIsValidLinkConstraint;
  49024. use GeckoPackages\PHPUnit\Constraints\FilePermissionsIsIdenticalConstraint;
  49025. use GeckoPackages\PHPUnit\Constraints\FilePermissionsMaskConstraint;
  49026. trait FileSystemAssertTrait
  49027. {
  49028. public static function assertDirectoryEmpty($filename, $message = '')
  49029. {
  49030. self::assertThatConstraint($filename, $message, 'assertDirectoryEmpty', new DirectoryEmptyConstraint());
  49031. }
  49032. public static function assertDirectoryExists($filename, $message = '')
  49033. {
  49034. self::assertThatConstraint($filename, $message, 'assertDirectoryExists', new DirectoryExistsConstraint());
  49035. }
  49036. public static function assertDirectoryNotEmpty($filename, $message = '')
  49037. {
  49038. self::assertThatConstraint($filename, $message, 'assertDirectoryNotEmpty', new \PHPUnit_Framework_Constraint_Not(new DirectoryEmptyConstraint()));
  49039. }
  49040. public static function assertDirectoryNotExists($filename, $message = '')
  49041. {
  49042. self::assertThatConstraint($filename, $message, 'assertDirectoryNotExists', new \PHPUnit_Framework_Constraint_Not(new DirectoryExistsConstraint()));
  49043. }
  49044. public static function assertFileHasPermissions($permissions, $filename, $message = '')
  49045. {
  49046. if (!is_string($permissions) && !(is_int($permissions) && $permissions >= 0)) {
  49047. throw AssertHelper::createArgumentException(__TRAIT__, 'assertFileHasPermissions', 'int (>= 0) or string', $permissions);
  49048. }
  49049. try {
  49050. $constraint = new FilePermissionsIsIdenticalConstraint($permissions);
  49051. } catch (\InvalidArgumentException $e) {
  49052. throw AssertHelper::createException(__TRAIT__, 'assertFileHasPermissions', substr($e->getMessage(), 0, -1));
  49053. }
  49054. self::assertThatConstraint($filename, $message, 'assertFileHasPermissions', $constraint);
  49055. }
  49056. public static function assertFileIsLink($filename, $message = '')
  49057. {
  49058. self::assertThatConstraint($filename, $message, 'assertFileIsLink', new FileIsLinkConstraint());
  49059. }
  49060. public static function assertFileIsNotLink($filename, $message = '')
  49061. {
  49062. self::assertThatConstraint($filename, $message, 'assertFileIsNotLink', new \PHPUnit_Framework_Constraint_Not(new FileIsLinkConstraint()));
  49063. }
  49064. public static function assertFileIsValidLink($filename, $message = '')
  49065. {
  49066. self::assertThatConstraint($filename, $message, 'assertFileIsValidLink', new FileIsValidLinkConstraint());
  49067. }
  49068. public static function assertFilePermissionMask($permissionMask, $filename, $message = '')
  49069. {
  49070. self::filePermissionMask($permissionMask, $filename, 'assertFilePermissionMask', true, $message);
  49071. }
  49072. public static function assertFilePermissionNotMask($permissionMask, $filename, $message = '')
  49073. {
  49074. self::filePermissionMask($permissionMask, $filename, 'assertFilePermissionNotMask', false, $message);
  49075. }
  49076. private static function assertThatConstraint($input, $message, $method, \PHPUnit_Framework_Constraint $constraint)
  49077. {
  49078. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, $method, array('assertThat'));
  49079. self::assertThat($input, $constraint, $message);
  49080. }
  49081. private static function filePermissionMask($permissionMask, $filename, $method, $positive, $message = '')
  49082. {
  49083. if (!is_int($permissionMask)) {
  49084. throw AssertHelper::createArgumentException(__TRAIT__, $method, 'int', $permissionMask);
  49085. }
  49086. $constraint = new FilePermissionsMaskConstraint($permissionMask);
  49087. self::assertThatConstraint($filename, $message, $method, $positive ? $constraint : new \PHPUnit_Framework_Constraint_Not($constraint));
  49088. }
  49089. }
  49090. <?php
  49091. namespace GeckoPackages\PHPUnit\Asserts;
  49092. use GeckoPackages\PHPUnit\Constraints\NumberRangeConstraint;
  49093. use GeckoPackages\PHPUnit\Constraints\UnsignedIntConstraint;
  49094. trait RangeAssertTrait
  49095. {
  49096. public static function assertNumberInRange($lowerBoundary, $upperBoundary, $actual, $message = '')
  49097. {
  49098. self::assertNumberRangeMatch($lowerBoundary, $upperBoundary, $actual, $message, 'assertNumberInRange', false, false);
  49099. }
  49100. public static function assertNumberNotInRange($lowerBoundary, $upperBoundary, $actual, $message = '')
  49101. {
  49102. self::assertNumberRangeMatch($lowerBoundary, $upperBoundary, $actual, $message, 'assertNumberNotInRange', false, true);
  49103. }
  49104. public static function assertNumberNotOnRange($lowerBoundary, $upperBoundary, $actual, $message = '')
  49105. {
  49106. self::assertNumberRangeMatch($lowerBoundary, $upperBoundary, $actual, $message, 'assertNumberNotOnRange', true, true);
  49107. }
  49108. public static function assertNumberOnRange($lowerBoundary, $upperBoundary, $actual, $message = '')
  49109. {
  49110. self::assertNumberRangeMatch($lowerBoundary, $upperBoundary, $actual, $message, 'assertNumberOnRange', true, false);
  49111. }
  49112. public function assertUnsignedInt($actual, $message = '')
  49113. {
  49114. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertUnsignedInt', array('assertThat'));
  49115. self::assertThat($actual, new UnsignedIntConstraint(), $message);
  49116. }
  49117. private static function assertNumberRangeMatch(
  49118. $lowerBoundary,
  49119. $upperBoundary,
  49120. $actual,
  49121. $message,
  49122. $method,
  49123. $onBoundary,
  49124. $negative
  49125. ) {
  49126. if (!is_int($lowerBoundary) && !is_float($lowerBoundary)) {
  49127. throw AssertHelper::createArgumentException(__TRAIT__, $method, 'float or int', $lowerBoundary);
  49128. }
  49129. if (!is_int($upperBoundary) && !is_float($upperBoundary)) {
  49130. throw AssertHelper::createArgumentException(__TRAIT__, $method, 'float or int', $upperBoundary, 2);
  49131. }
  49132. if ($lowerBoundary >= $upperBoundary) {
  49133. $message = sprintf(
  49134. 'lower boundary %s must be smaller than upper boundary %s',
  49135. is_int($lowerBoundary) ? '%d' : '%.3f',
  49136. is_int($upperBoundary) ? '%d' : '%.3f'
  49137. );
  49138. throw AssertHelper::createException(
  49139. __TRAIT__,
  49140. $method,
  49141. sprintf($message, $lowerBoundary, $upperBoundary)
  49142. );
  49143. }
  49144. $rangeConstraint = new NumberRangeConstraint($lowerBoundary, $upperBoundary, $onBoundary);
  49145. if ($negative) {
  49146. $rangeConstraint = new \PHPUnit_Framework_Constraint_Not($rangeConstraint);
  49147. }
  49148. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, $method, array('assertThat'));
  49149. self::assertThat($actual, $rangeConstraint, $message);
  49150. }
  49151. }
  49152. <?php
  49153. namespace GeckoPackages\PHPUnit\Asserts;
  49154. use GeckoPackages\PHPUnit\Constraints\ScalarConstraint;
  49155. trait ScalarAssertTrait
  49156. {
  49157. public static function assertArray($actual, $message = '')
  49158. {
  49159. self::assertTypeOfScalar($actual, $message, 'assertArray', new ScalarConstraint(ScalarConstraint::TYPE_ARRAY));
  49160. }
  49161. public static function assertBool($actual, $message = '')
  49162. {
  49163. self::assertTypeOfScalar($actual, $message, 'assertBool', new ScalarConstraint(ScalarConstraint::TYPE_BOOL));
  49164. }
  49165. public static function assertFloat($actual, $message = '')
  49166. {
  49167. self::assertTypeOfScalar($actual, $message, 'assertFloat', new ScalarConstraint(ScalarConstraint::TYPE_FLOAT));
  49168. }
  49169. public static function assertInt($actual, $message = '')
  49170. {
  49171. self::assertTypeOfScalar($actual, $message, 'assertInt', new ScalarConstraint(ScalarConstraint::TYPE_INT));
  49172. }
  49173. public static function assertScalar($actual, $message = '')
  49174. {
  49175. self::assertTypeOfScalar($actual, $message, 'assertScalar', new ScalarConstraint(ScalarConstraint::TYPE_SCALAR));
  49176. }
  49177. public static function assertString($actual, $message = '')
  49178. {
  49179. self::assertTypeOfScalar($actual, $message, 'assertString', new ScalarConstraint(ScalarConstraint::TYPE_STRING));
  49180. }
  49181. public static function assertNotArray($actual, $message = '')
  49182. {
  49183. self::assertTypeOfScalar($actual, $message, 'assertNotArray', new \PHPUnit_Framework_Constraint_Not(new ScalarConstraint(ScalarConstraint::TYPE_ARRAY)));
  49184. }
  49185. public static function assertNotBool($actual, $message = '')
  49186. {
  49187. self::assertTypeOfScalar($actual, $message, 'assertNotBool', new \PHPUnit_Framework_Constraint_Not(new ScalarConstraint(ScalarConstraint::TYPE_BOOL)));
  49188. }
  49189. public static function assertNotFloat($actual, $message = '')
  49190. {
  49191. self::assertTypeOfScalar($actual, $message, 'assertNotFloat', new \PHPUnit_Framework_Constraint_Not(new ScalarConstraint(ScalarConstraint::TYPE_FLOAT)));
  49192. }
  49193. public static function assertNotInt($actual, $message = '')
  49194. {
  49195. self::assertTypeOfScalar($actual, $message, 'assertNotInt', new \PHPUnit_Framework_Constraint_Not(new ScalarConstraint(ScalarConstraint::TYPE_INT)));
  49196. }
  49197. public static function assertNotScalar($actual, $message = '')
  49198. {
  49199. self::assertTypeOfScalar($actual, $message, 'assertNotScalar', new \PHPUnit_Framework_Constraint_Not(new ScalarConstraint(ScalarConstraint::TYPE_SCALAR)));
  49200. }
  49201. public static function assertNotString($actual, $message = '')
  49202. {
  49203. self::assertTypeOfScalar($actual, $message, 'assertNotString', new \PHPUnit_Framework_Constraint_Not(new ScalarConstraint(ScalarConstraint::TYPE_STRING)));
  49204. }
  49205. private static function assertTypeOfScalar($actual, $message, $method, \PHPUnit_Framework_Constraint $constraint)
  49206. {
  49207. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, $method, array('assertThat'));
  49208. self::assertThat($actual, $constraint, $message);
  49209. }
  49210. }
  49211. <?php
  49212. namespace GeckoPackages\PHPUnit\Asserts;
  49213. use GeckoPackages\PHPUnit\Constraints\SameStringsConstraint;
  49214. trait StringsAssertTrait
  49215. {
  49216. public static function assertNotSameStrings($expected, $actual, $message = '')
  49217. {
  49218. self::assertStringsIdentity($actual, $message, __FUNCTION__, new \PHPUnit_Framework_Constraint_Not(new SameStringsConstraint($expected)));
  49219. }
  49220. public static function assertSameStrings($expected, $actual, $message = '')
  49221. {
  49222. self::assertStringsIdentity($actual, $message, __FUNCTION__, new SameStringsConstraint($expected));
  49223. }
  49224. public static function assertStringIsEmpty($actual, $message = '')
  49225. {
  49226. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertStringIsEmpty', array('assertThat', 'assertEmpty'));
  49227. self::assertThat($actual, new \PHPUnit_Framework_Constraint_IsType('string'), $message);
  49228. self::assertEmpty($actual, $message);
  49229. }
  49230. public static function assertStringIsNotEmpty($actual, $message = '')
  49231. {
  49232. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertStringIsNotEmpty', array('assertThat', 'assertNotEmpty'));
  49233. self::assertThat($actual, new \PHPUnit_Framework_Constraint_IsType('string'), $message);
  49234. self::assertNotEmpty($actual, $message);
  49235. }
  49236. public static function assertStringIsNotWhiteSpace($actual, $message = '')
  49237. {
  49238. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertStringIsNotWhiteSpace', array('assertThat', 'assertNotEmpty'));
  49239. self::assertThat($actual, new \PHPUnit_Framework_Constraint_IsType('string'), $message);
  49240. self::assertNotEmpty(trim($actual), $message);
  49241. }
  49242. public static function assertStringIsWhiteSpace($actual, $message = '')
  49243. {
  49244. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertStringIsWhiteSpace', array('assertThat', 'assertEmpty'));
  49245. self::assertThat($actual, new \PHPUnit_Framework_Constraint_IsType('string'), $message);
  49246. self::assertEmpty(trim($actual), $message);
  49247. }
  49248. private static function assertStringsIdentity($actual, $message, $method, \PHPUnit_Framework_Constraint $constraint)
  49249. {
  49250. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, $method, array('assertThat'));
  49251. self::assertThat($actual, $constraint, $message);
  49252. }
  49253. }
  49254. <?php
  49255. namespace GeckoPackages\PHPUnit\Asserts;
  49256. use GeckoPackages\PHPUnit\Constraints\XML\XMLMatchesXSDConstraint;
  49257. use GeckoPackages\PHPUnit\Constraints\XML\XMLValidConstraint;
  49258. trait XMLAssertTrait
  49259. {
  49260. public static function assertXMLMatchesXSD($XSD, $XML, $message = '')
  49261. {
  49262. if (!is_string($XSD)) {
  49263. throw AssertHelper::createArgumentException(__TRAIT__, 'assertXMLMatchesXSD', 'string', $XSD);
  49264. }
  49265. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertXMLMatchesXSD', array('assertThat'));
  49266. self::assertThat($XML, new XMLMatchesXSDConstraint($XSD), $message);
  49267. }
  49268. public static function assertXMLValid($XML, $message = '')
  49269. {
  49270. AssertHelper::assertMethodDependency(__CLASS__, __TRAIT__, 'assertXMLValid', array('assertThat'));
  49271. self::assertThat($XML, new XMLValidConstraint(), $message);
  49272. }
  49273. }
  49274. <?php
  49275. namespace GeckoPackages\PHPUnit\Constraints;
  49276. final class DirectoryEmptyConstraint extends \PHPUnit_Framework_Constraint
  49277. {
  49278. protected function matches($other)
  49279. {
  49280. if (!is_string($other) || !is_dir($other)) {
  49281. return false;
  49282. }
  49283. foreach (new \DirectoryIterator($other) as $file) {
  49284. if ($file->isDot()) {
  49285. continue;
  49286. }
  49287. return false;
  49288. }
  49289. return true;
  49290. }
  49291. protected function failureDescription($other)
  49292. {
  49293. if (is_object($other)) {
  49294. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49295. } elseif (null === $other) {
  49296. $type = 'null';
  49297. } elseif (!is_string($other)) {
  49298. $type = gettype($other).'#'.$other;
  49299. } elseif (is_link($other)) {
  49300. $type = 'link to file#'.$other;
  49301. } elseif (is_file($other)) {
  49302. $type = 'file#'.$other;
  49303. } elseif (is_dir($other)) {
  49304. $type = 'directory#'.$other;
  49305. } else {
  49306. $type = $other;
  49307. }
  49308. return $type.' is an empty directory';
  49309. }
  49310. public function toString()
  49311. {
  49312. return 'is an empty directory';
  49313. }
  49314. }
  49315. <?php
  49316. namespace GeckoPackages\PHPUnit\Constraints;
  49317. final class DirectoryExistsConstraint extends \PHPUnit_Framework_Constraint
  49318. {
  49319. protected function matches($other)
  49320. {
  49321. return is_string($other) && is_dir($other);
  49322. }
  49323. protected function failureDescription($other)
  49324. {
  49325. if (is_object($other)) {
  49326. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49327. } elseif (null === $other) {
  49328. $type = 'null';
  49329. } elseif (!is_string($other)) {
  49330. $type = gettype($other).'#'.$other;
  49331. } elseif (is_link($other)) {
  49332. $type = 'link to file#'.$other;
  49333. } elseif (is_file($other)) {
  49334. $type = 'file#'.$other;
  49335. } else {
  49336. $type = $other;
  49337. }
  49338. return $type.' '.$this->toString();
  49339. }
  49340. public function toString()
  49341. {
  49342. return 'is a directory';
  49343. }
  49344. }
  49345. <?php
  49346. namespace GeckoPackages\PHPUnit\Constraints;
  49347. final class FileExistsConstraint extends \PHPUnit_Framework_Constraint
  49348. {
  49349. protected function matches($other)
  49350. {
  49351. return is_string($other) && is_file($other);
  49352. }
  49353. protected function failureDescription($other)
  49354. {
  49355. if (is_object($other)) {
  49356. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49357. } elseif (null === $other) {
  49358. $type = 'null';
  49359. } elseif (!is_string($other)) {
  49360. $type = gettype($other).'#'.$other;
  49361. } elseif (is_link($other)) {
  49362. $type = 'link to directory#'.$other;
  49363. } elseif (is_dir($other)) {
  49364. $type = 'directory#'.$other;
  49365. } else {
  49366. $type = $other;
  49367. }
  49368. return $type.' '.$this->toString();
  49369. }
  49370. public function toString()
  49371. {
  49372. return 'is a file';
  49373. }
  49374. }
  49375. <?php
  49376. namespace GeckoPackages\PHPUnit\Constraints;
  49377. final class FileIsLinkConstraint extends \PHPUnit_Framework_Constraint
  49378. {
  49379. protected function matches($other)
  49380. {
  49381. return is_string($other) && is_link($other);
  49382. }
  49383. protected function failureDescription($other)
  49384. {
  49385. if (is_object($other)) {
  49386. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49387. } elseif (null === $other) {
  49388. $type = 'null';
  49389. } elseif (!is_string($other)) {
  49390. $type = gettype($other).'#'.$other;
  49391. } elseif (is_file($other)) {
  49392. $type = 'file#'.$other;
  49393. } elseif (is_dir($other)) {
  49394. $type = 'directory#'.$other;
  49395. } else {
  49396. $type = $other;
  49397. }
  49398. return $type.' '.$this->toString();
  49399. }
  49400. public function toString()
  49401. {
  49402. return 'is a link';
  49403. }
  49404. }
  49405. <?php
  49406. namespace GeckoPackages\PHPUnit\Constraints;
  49407. final class FileIsValidLinkConstraint extends \PHPUnit_Framework_Constraint
  49408. {
  49409. protected function matches($other)
  49410. {
  49411. return is_string($other) && is_link($other) && file_exists($other);
  49412. }
  49413. protected function failureDescription($other)
  49414. {
  49415. if (is_object($other)) {
  49416. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49417. } elseif (null === $other) {
  49418. $type = 'null';
  49419. } elseif (!is_string($other)) {
  49420. $type = gettype($other).'#'.$other;
  49421. } elseif (!file_exists($other)) {
  49422. if (is_link($other)) {
  49423. $type = 'link#'.$other;
  49424. } else {
  49425. $type = 'string#'.$other;
  49426. }
  49427. } elseif (is_dir($other)) {
  49428. $type = 'directory#'.$other;
  49429. } elseif (is_file($other)) {
  49430. $type = 'file#'.$other;
  49431. } else {
  49432. $type = 'string#'.$other;
  49433. }
  49434. return $type.' '.$this->toString();
  49435. }
  49436. public function toString()
  49437. {
  49438. return 'is a valid link';
  49439. }
  49440. }
  49441. <?php
  49442. namespace GeckoPackages\PHPUnit\Constraints;
  49443. final class FilePermissionsIsIdenticalConstraint extends \PHPUnit_Framework_Constraint
  49444. {
  49445. private $permissions;
  49446. private static $permissionFormat = '#^[slbdcpu\-]([r-][w-][sxS-]){2}[r-][w-][txT-]$#';
  49447. public function __construct($permissions)
  49448. {
  49449. parent::__construct();
  49450. if (is_string($permissions)) {
  49451. if (preg_match('#^\d+$#', $permissions)) {
  49452. $this->permissions = '0' === $permissions[0]
  49453. ? intval($permissions, 8)
  49454. : (int) $permissions
  49455. ;
  49456. return;
  49457. }
  49458. if (1 === preg_match(self::$permissionFormat, $permissions)) {
  49459. $this->permissions = $permissions;
  49460. return;
  49461. }
  49462. throw new \InvalidArgumentException(sprintf('Permission to match "%s" is not formatted correctly.', $permissions));
  49463. }
  49464. if (!is_int($permissions)) {
  49465. if (is_object($permissions)) {
  49466. $type = sprintf('%s#%s', get_class($permissions), method_exists($permissions, '__toString') ? $permissions->__toString() : '');
  49467. } elseif (null === $permissions) {
  49468. $type = 'null';
  49469. } else {
  49470. $type = gettype($permissions).'#'.$permissions;
  49471. }
  49472. throw new \InvalidArgumentException(sprintf('Invalid value for permission to match "%s", expected int >= 0 or string.', $type));
  49473. }
  49474. if ($permissions < 0) {
  49475. throw new \InvalidArgumentException(sprintf('Invalid value for permission to match "%d", expected int >= 0 or string.', $permissions));
  49476. }
  49477. $this->permissions = $permissions;
  49478. }
  49479. protected function matches($other)
  49480. {
  49481. if (!is_string($other) || !file_exists($other)) {
  49482. return false;
  49483. }
  49484. if (is_link($other)) {
  49485. $perms = lstat($other);
  49486. $perms = $perms['mode'];
  49487. } else {
  49488. $perms = fileperms($other);
  49489. }
  49490. if (is_string($this->permissions)) {
  49491. return self::getFilePermissionsAsString($perms) === $this->permissions;
  49492. }
  49493. if ($this->permissions < 1412) {
  49494. $comp = (int) sprintf('%o', $this->permissions);
  49495. $filePerm = (int) substr(sprintf('%o', $perms), -3);
  49496. } else {
  49497. $comp = $this->permissions;
  49498. $filePerm = (int) sprintf('%o', $perms);
  49499. }
  49500. return $filePerm === $comp;
  49501. }
  49502. protected function failureDescription($other)
  49503. {
  49504. if (!is_string($other)) {
  49505. if (is_object($other)) {
  49506. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49507. } elseif (null === $other) {
  49508. $type = 'null';
  49509. } else {
  49510. $type = gettype($other).'#'.$other;
  49511. }
  49512. return $type.' '.$this->toString();
  49513. }
  49514. if (!file_exists($other)) {
  49515. return 'not file or directory#'.$other.' '.$this->toString();
  49516. }
  49517. if (is_link($other)) {
  49518. $perms = lstat($other);
  49519. $perms = $perms['mode'];
  49520. $type = 'link';
  49521. } else {
  49522. $perms = fileperms($other);
  49523. $type = is_file($other) ? 'file' : (is_dir($other) ? 'directory' : 'other');
  49524. }
  49525. if (is_string($this->permissions)) {
  49526. return sprintf('%s#%s %s %s to %s', $type, $other, self::getFilePermissionsAsString($perms), $this->toString(), $this->permissions);
  49527. }
  49528. if ($this->permissions < 1412) {
  49529. $comp = (int) sprintf('%o', $this->permissions);
  49530. $perms = (int) substr(sprintf('%o', $perms), -3);
  49531. } else {
  49532. $comp = $this->permissions;
  49533. $perms = (int) sprintf('%o', $perms);
  49534. }
  49535. return sprintf('%s#%s 0%d %s to 0%d', $type, $other, $perms, $this->toString(), $comp);
  49536. }
  49537. public function toString()
  49538. {
  49539. return 'permissions are equal';
  49540. }
  49541. private static function getFilePermissionsAsString($perms)
  49542. {
  49543. if (($perms & 0xC000) === 0xC000) {
  49544. $info = 's';
  49545. } elseif (($perms & 0xA000) === 0xA000) {
  49546. $info = 'l';
  49547. } elseif (($perms & 0x8000) === 0x8000) {
  49548. $info = '-';
  49549. } elseif (($perms & 0x6000) === 0x6000) {
  49550. $info = 'b';
  49551. } elseif (($perms & 0x4000) === 0x4000) {
  49552. $info = 'd';
  49553. } elseif (($perms & 0x2000) === 0x2000) {
  49554. $info = 'c';
  49555. } elseif (($perms & 0x1000) === 0x1000) {
  49556. $info = 'p';
  49557. } else {
  49558. $info = 'u';
  49559. }
  49560. $info .= (($perms & 0x0100) ? 'r' : '-');
  49561. $info .= (($perms & 0x0080) ? 'w' : '-');
  49562. $info .= (($perms & 0x0040) ?
  49563. (($perms & 0x0800) ? 's' : 'x') :
  49564. (($perms & 0x0800) ? 'S' : '-'));
  49565. $info .= (($perms & 0x0020) ? 'r' : '-');
  49566. $info .= (($perms & 0x0010) ? 'w' : '-');
  49567. $info .= (($perms & 0x0008) ?
  49568. (($perms & 0x0400) ? 's' : 'x') :
  49569. (($perms & 0x0400) ? 'S' : '-'));
  49570. $info .= (($perms & 0x0004) ? 'r' : '-');
  49571. $info .= (($perms & 0x0002) ? 'w' : '-');
  49572. $info .= (($perms & 0x0001) ?
  49573. (($perms & 0x0200) ? 't' : 'x') :
  49574. (($perms & 0x0200) ? 'T' : '-'));
  49575. return $info;
  49576. }
  49577. }
  49578. <?php
  49579. namespace GeckoPackages\PHPUnit\Constraints;
  49580. final class FilePermissionsMaskConstraint extends \PHPUnit_Framework_Constraint
  49581. {
  49582. private $mask;
  49583. public function __construct($mask)
  49584. {
  49585. parent::__construct();
  49586. $this->mask = $mask;
  49587. }
  49588. protected function matches($other)
  49589. {
  49590. if (!is_string($other) || !file_exists($other)) {
  49591. return false;
  49592. }
  49593. if (is_link($other)) {
  49594. $perms = lstat($other);
  49595. $perms = $perms['mode'];
  49596. } else {
  49597. $perms = fileperms($other);
  49598. }
  49599. return ($perms & $this->mask) === $this->mask;
  49600. }
  49601. protected function failureDescription($other)
  49602. {
  49603. if (!is_string($other)) {
  49604. if (is_object($other)) {
  49605. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49606. } elseif (null === $other) {
  49607. $type = 'null';
  49608. } else {
  49609. $type = gettype($other).'#'.$other;
  49610. }
  49611. return $type.' '.$this->toString();
  49612. }
  49613. if (!file_exists($other)) {
  49614. return 'not file or directory#'.$other.' '.$this->toString();
  49615. }
  49616. if (is_link($other)) {
  49617. $type = 'link';
  49618. $perms = lstat($other);
  49619. $perms = $perms['mode'];
  49620. } else {
  49621. $type = is_file($other) ? 'file' : (is_dir($other) ? 'directory' : 'other');
  49622. $perms = fileperms($other);
  49623. }
  49624. return sprintf('%s#%s %o %s %o', $type, $other, $perms, $this->toString(), $this->mask);
  49625. }
  49626. public function toString()
  49627. {
  49628. return 'permissions matches mask';
  49629. }
  49630. }
  49631. <?php
  49632. namespace GeckoPackages\PHPUnit\Constraints;
  49633. final class NumberRangeConstraint extends \PHPUnit_Framework_Constraint
  49634. {
  49635. private $lowerBoundary;
  49636. private $upperBoundary;
  49637. private $onBoundary;
  49638. public function __construct($lowerBoundary, $upperBoundary, $onBoundary)
  49639. {
  49640. parent::__construct();
  49641. $this->lowerBoundary = $lowerBoundary;
  49642. $this->upperBoundary = $upperBoundary;
  49643. $this->onBoundary = $onBoundary;
  49644. }
  49645. public function toString()
  49646. {
  49647. return sprintf('is %s range', $this->onBoundary ? 'in' : 'within');
  49648. }
  49649. protected function matches($other)
  49650. {
  49651. if ($this->onBoundary) {
  49652. return $other >= $this->lowerBoundary && $other <= $this->upperBoundary;
  49653. }
  49654. return $other > $this->lowerBoundary && $other < $this->upperBoundary;
  49655. }
  49656. protected function failureDescription($other)
  49657. {
  49658. return sprintf(
  49659. sprintf(
  49660. '%%%s %%s %s%%%s, %%%s%s',
  49661. is_int($other) ? 'd' : '.3f',
  49662. $this->onBoundary ? '[' : '(',
  49663. is_int($this->lowerBoundary) ? 'd' : '.3f',
  49664. is_int($this->upperBoundary) ? 'd' : '.3f',
  49665. $this->onBoundary ? ']' : ')'
  49666. ),
  49667. $other,
  49668. $this->toString(),
  49669. $this->lowerBoundary,
  49670. $this->upperBoundary
  49671. );
  49672. }
  49673. }
  49674. <?php
  49675. namespace GeckoPackages\PHPUnit\Constraints;
  49676. final class SameStringsConstraint extends \PHPUnit_Framework_Constraint_IsIdentical
  49677. {
  49678. protected function additionalFailureDescription($other)
  49679. {
  49680. if (
  49681. $other === $this->value
  49682. || preg_replace('/(\r\n|\n\r|\r)/', "\n", $other) !== preg_replace('/(\r\n|\n\r|\r)/', "\n", $this->value)
  49683. ) {
  49684. return '';
  49685. }
  49686. return ' #Warning: Strings contain different line endings! Debug using remapping ["\r" => "R", "\n" => "N", "\t" => "T"]:'
  49687. ."\n"
  49688. .' -'.str_replace(array("\r", "\n", "\t"), array('R', 'N', 'T'), $other)
  49689. ."\n"
  49690. .' +'.str_replace(array("\r", "\n", "\t"), array('R', 'N', 'T'), $this->value);
  49691. }
  49692. }
  49693. <?php
  49694. namespace GeckoPackages\PHPUnit\Constraints;
  49695. final class ScalarConstraint extends \PHPUnit_Framework_Constraint
  49696. {
  49697. const TYPE_SCALAR = 1;
  49698. const TYPE_BOOL = 2;
  49699. const TYPE_INT = 3;
  49700. const TYPE_STRING = 4;
  49701. const TYPE_FLOAT = 5;
  49702. const TYPE_ARRAY = 6;
  49703. private $testFunction;
  49704. private $type;
  49705. public function __construct($type)
  49706. {
  49707. parent::__construct();
  49708. switch ($type) {
  49709. case self::TYPE_BOOL:
  49710. $this->testFunction = 'is_bool';
  49711. $this->type = 'bool';
  49712. break;
  49713. case self::TYPE_INT:
  49714. $this->testFunction = 'is_int';
  49715. $this->type = 'int';
  49716. break;
  49717. case self::TYPE_STRING:
  49718. $this->testFunction = 'is_string';
  49719. $this->type = 'string';
  49720. break;
  49721. case self::TYPE_FLOAT:
  49722. $this->testFunction = 'is_float';
  49723. $this->type = 'float';
  49724. break;
  49725. case self::TYPE_ARRAY:
  49726. $this->testFunction = 'is_array';
  49727. $this->type = 'array';
  49728. break;
  49729. case self::TYPE_SCALAR:
  49730. $this->testFunction = 'is_scalar';
  49731. $this->type = 'scalar';
  49732. break;
  49733. default:
  49734. throw new \InvalidArgumentException(sprintf(
  49735. 'Unknown ScalarConstraint type "%s" provided.',
  49736. is_object($type) ? get_class($type) : (null === $type ? 'null' : gettype($type).'#'.$type)
  49737. ));
  49738. }
  49739. }
  49740. protected function matches($other)
  49741. {
  49742. $m = $this->testFunction;
  49743. return $m($other);
  49744. }
  49745. protected function failureDescription($other)
  49746. {
  49747. if (is_object($other)) {
  49748. $input = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49749. } elseif (null === $other) {
  49750. $input = 'null';
  49751. } else {
  49752. $input = gettype($other).'#'.$other;
  49753. }
  49754. return sprintf('%s is of type %s', $input, $this->type);
  49755. }
  49756. public function toString()
  49757. {
  49758. return sprintf('is of type "%s".', $this->type);
  49759. }
  49760. }
  49761. <?php
  49762. namespace GeckoPackages\PHPUnit\Constraints;
  49763. final class UnsignedIntConstraint extends \PHPUnit_Framework_Constraint
  49764. {
  49765. public function toString()
  49766. {
  49767. return 'is unsigned int';
  49768. }
  49769. protected function matches($other)
  49770. {
  49771. return is_int($other) && $other >= 0;
  49772. }
  49773. }
  49774. <?php
  49775. namespace GeckoPackages\PHPUnit\Constraints\XML;
  49776. abstract class AbstractXMLConstraint extends \PHPUnit_Framework_Constraint
  49777. {
  49778. protected $XMLConstraintErrors = array();
  49779. protected function matches($other)
  49780. {
  49781. if (!is_string($other)) {
  49782. return false;
  49783. }
  49784. return $this->stringMatches($other);
  49785. }
  49786. abstract protected function stringMatches($other);
  49787. protected function setXMLConstraintErrors()
  49788. {
  49789. foreach (libxml_get_errors() as $error) {
  49790. switch ($error->level) {
  49791. case LIBXML_ERR_WARNING:
  49792. $level = 'warning ';
  49793. break;
  49794. case LIBXML_ERR_ERROR:
  49795. $level = 'error ';
  49796. break;
  49797. case LIBXML_ERR_FATAL:
  49798. $level = 'fatal ';
  49799. break;
  49800. default:
  49801. $level = '';
  49802. break;
  49803. }
  49804. $this->XMLConstraintErrors[] = sprintf('[%s%s] %s (line %d, column %d).', $level, $error->code, trim($error->message), $error->line, $error->column);
  49805. }
  49806. }
  49807. protected function failureDescription($other)
  49808. {
  49809. if (!is_string($other)) {
  49810. if (is_object($other)) {
  49811. $type = sprintf('%s#%s', get_class($other), method_exists($other, '__toString') ? $other->__toString() : '');
  49812. } elseif (null === $other) {
  49813. $type = 'null';
  49814. } else {
  49815. $type = gettype($other).'#'.$other;
  49816. }
  49817. return $type.' '.$this->toString();
  49818. }
  49819. return sprintf("%s %s.\n%s", $other, $this->toString(), implode("\n", $this->XMLConstraintErrors));
  49820. }
  49821. }
  49822. <?php
  49823. namespace GeckoPackages\PHPUnit\Constraints\XML;
  49824. final class XMLMatchesXSDConstraint extends AbstractXMLConstraint
  49825. {
  49826. private $XSD;
  49827. public function __construct($XSD)
  49828. {
  49829. parent::__construct();
  49830. $this->XSD = str_replace('http://www.w3.org/2001/xml.xsd', 'file:////'.__DIR__.'/schema/xml.xsd', $XSD);
  49831. }
  49832. protected function stringMatches($other)
  49833. {
  49834. $internalErrors = libxml_use_internal_errors(true);
  49835. $disableEntities = libxml_disable_entity_loader(true);
  49836. libxml_clear_errors();
  49837. $dom = new \DOMDocument();
  49838. $dom->preserveWhiteSpace = false;
  49839. $dom->validateOnParse = true;
  49840. if (!@$dom->loadXML($other, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
  49841. libxml_disable_entity_loader($disableEntities);
  49842. $this->setXMLConstraintErrors();
  49843. libxml_clear_errors();
  49844. libxml_use_internal_errors($internalErrors);
  49845. return false;
  49846. }
  49847. $dom->normalizeDocument();
  49848. libxml_disable_entity_loader($disableEntities);
  49849. libxml_clear_errors();
  49850. if (false === $result = @$dom->schemaValidateSource($this->XSD)) {
  49851. $this->setXMLConstraintErrors();
  49852. }
  49853. libxml_clear_errors();
  49854. libxml_use_internal_errors($internalErrors);
  49855. return $result;
  49856. }
  49857. public function toString()
  49858. {
  49859. return 'matches XSD';
  49860. }
  49861. }
  49862. <?php
  49863. namespace GeckoPackages\PHPUnit\Constraints\XML;
  49864. final class XMLValidConstraint extends AbstractXMLConstraint
  49865. {
  49866. protected function stringMatches($other)
  49867. {
  49868. $internalErrors = libxml_use_internal_errors(true);
  49869. $disableEntities = libxml_disable_entity_loader(true);
  49870. libxml_clear_errors();
  49871. $dom = new \DOMDocument();
  49872. $dom->preserveWhiteSpace = false;
  49873. $dom->validateOnParse = true;
  49874. if (!@$dom->loadXML($other, LIBXML_NONET | (defined('LIBXML_COMPACT') ? LIBXML_COMPACT : 0))) {
  49875. libxml_disable_entity_loader($disableEntities);
  49876. $this->setXMLConstraintErrors();
  49877. libxml_clear_errors();
  49878. libxml_use_internal_errors($internalErrors);
  49879. return false;
  49880. }
  49881. libxml_disable_entity_loader($disableEntities);
  49882. libxml_clear_errors();
  49883. return true;
  49884. }
  49885. public function toString()
  49886. {
  49887. return 'is valid XML';
  49888. }
  49889. }
  49890. <?php
  49891. if (!is_callable('RandomCompat_strlen')) {
  49892. if (
  49893. defined('MB_OVERLOAD_STRING') &&
  49894. ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
  49895. ) {
  49896. function RandomCompat_strlen($binary_string)
  49897. {
  49898. if (!is_string($binary_string)) {
  49899. throw new TypeError(
  49900. 'RandomCompat_strlen() expects a string'
  49901. );
  49902. }
  49903. return (int) mb_strlen($binary_string, '8bit');
  49904. }
  49905. } else {
  49906. function RandomCompat_strlen($binary_string)
  49907. {
  49908. if (!is_string($binary_string)) {
  49909. throw new TypeError(
  49910. 'RandomCompat_strlen() expects a string'
  49911. );
  49912. }
  49913. return (int) strlen($binary_string);
  49914. }
  49915. }
  49916. }
  49917. if (!is_callable('RandomCompat_substr')) {
  49918. if (
  49919. defined('MB_OVERLOAD_STRING')
  49920. &&
  49921. ini_get('mbstring.func_overload') & MB_OVERLOAD_STRING
  49922. ) {
  49923. function RandomCompat_substr($binary_string, $start, $length = null)
  49924. {
  49925. if (!is_string($binary_string)) {
  49926. throw new TypeError(
  49927. 'RandomCompat_substr(): First argument should be a string'
  49928. );
  49929. }
  49930. if (!is_int($start)) {
  49931. throw new TypeError(
  49932. 'RandomCompat_substr(): Second argument should be an integer'
  49933. );
  49934. }
  49935. if ($length === null) {
  49936. $length = RandomCompat_strlen($binary_string) - $start;
  49937. } elseif (!is_int($length)) {
  49938. throw new TypeError(
  49939. 'RandomCompat_substr(): Third argument should be an integer, or omitted'
  49940. );
  49941. }
  49942. if ($start === RandomCompat_strlen($binary_string) && $length === 0) {
  49943. return '';
  49944. }
  49945. if ($start > RandomCompat_strlen($binary_string)) {
  49946. return '';
  49947. }
  49948. return (string) mb_substr($binary_string, $start, $length, '8bit');
  49949. }
  49950. } else {
  49951. function RandomCompat_substr($binary_string, $start, $length = null)
  49952. {
  49953. if (!is_string($binary_string)) {
  49954. throw new TypeError(
  49955. 'RandomCompat_substr(): First argument should be a string'
  49956. );
  49957. }
  49958. if (!is_int($start)) {
  49959. throw new TypeError(
  49960. 'RandomCompat_substr(): Second argument should be an integer'
  49961. );
  49962. }
  49963. if ($length !== null) {
  49964. if (!is_int($length)) {
  49965. throw new TypeError(
  49966. 'RandomCompat_substr(): Third argument should be an integer, or omitted'
  49967. );
  49968. }
  49969. return (string) substr($binary_string, $start, $length);
  49970. }
  49971. return (string) substr($binary_string, $start);
  49972. }
  49973. }
  49974. }
  49975. <?php
  49976. if (!is_callable('RandomCompat_intval')) {
  49977. function RandomCompat_intval($number, $fail_open = false)
  49978. {
  49979. if (is_int($number) || is_float($number)) {
  49980. $number += 0;
  49981. } elseif (is_numeric($number)) {
  49982. $number += 0;
  49983. }
  49984. if (
  49985. is_float($number)
  49986. &&
  49987. $number > ~PHP_INT_MAX
  49988. &&
  49989. $number < PHP_INT_MAX
  49990. ) {
  49991. $number = (int) $number;
  49992. }
  49993. if (is_int($number)) {
  49994. return (int) $number;
  49995. } elseif (!$fail_open) {
  49996. throw new TypeError(
  49997. 'Expected an integer.'
  49998. );
  49999. }
  50000. return $number;
  50001. }
  50002. }
  50003. <?php
  50004. if (!class_exists('Error', false)) {
  50005. class Error extends Exception
  50006. {
  50007. }
  50008. }
  50009. if (!class_exists('TypeError', false)) {
  50010. if (is_subclass_of('Error', 'Exception')) {
  50011. class TypeError extends Error
  50012. {
  50013. }
  50014. } else {
  50015. class TypeError extends Exception
  50016. {
  50017. }
  50018. }
  50019. }
  50020. <?php
  50021. if (!defined('PHP_VERSION_ID')) {
  50022. $RandomCompatversion = array_map('intval', explode('.', PHP_VERSION));
  50023. define(
  50024. 'PHP_VERSION_ID',
  50025. $RandomCompatversion[0] * 10000
  50026. + $RandomCompatversion[1] * 100
  50027. + $RandomCompatversion[2]
  50028. );
  50029. $RandomCompatversion = null;
  50030. }
  50031. if (PHP_VERSION_ID >= 70000) {
  50032. return;
  50033. }
  50034. if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
  50035. define('RANDOM_COMPAT_READ_BUFFER', 8);
  50036. }
  50037. $RandomCompatDIR = dirname(__FILE__);
  50038. require_once $RandomCompatDIR . '/byte_safe_strings.php';
  50039. require_once $RandomCompatDIR . '/cast_to_int.php';
  50040. require_once $RandomCompatDIR . '/error_polyfill.php';
  50041. if (!is_callable('random_bytes')) {
  50042. if (extension_loaded('libsodium')) {
  50043. if (PHP_VERSION_ID >= 50300 && is_callable('\\Sodium\\randombytes_buf')) {
  50044. require_once $RandomCompatDIR . '/random_bytes_libsodium.php';
  50045. } elseif (method_exists('Sodium', 'randombytes_buf')) {
  50046. require_once $RandomCompatDIR . '/random_bytes_libsodium_legacy.php';
  50047. }
  50048. }
  50049. if (DIRECTORY_SEPARATOR === '/') {
  50050. $RandomCompatUrandom = true;
  50051. $RandomCompat_basedir = ini_get('open_basedir');
  50052. if (!empty($RandomCompat_basedir)) {
  50053. $RandomCompat_open_basedir = explode(
  50054. PATH_SEPARATOR,
  50055. strtolower($RandomCompat_basedir)
  50056. );
  50057. $RandomCompatUrandom = (array() !== array_intersect(
  50058. array('/dev', '/dev/', '/dev/urandom'),
  50059. $RandomCompat_open_basedir
  50060. ));
  50061. $RandomCompat_open_basedir = null;
  50062. }
  50063. if (
  50064. !is_callable('random_bytes')
  50065. &&
  50066. $RandomCompatUrandom
  50067. &&
  50068. @is_readable('/dev/urandom')
  50069. ) {
  50070. require_once $RandomCompatDIR . '/random_bytes_dev_urandom.php';
  50071. }
  50072. $RandomCompat_basedir = null;
  50073. } else {
  50074. $RandomCompatUrandom = false;
  50075. }
  50076. if (
  50077. !is_callable('random_bytes')
  50078. &&
  50079. (DIRECTORY_SEPARATOR === '/' || PHP_VERSION_ID >= 50307)
  50080. &&
  50081. (
  50082. DIRECTORY_SEPARATOR !== '/' ||
  50083. (PHP_VERSION_ID <= 50609 || PHP_VERSION_ID >= 50613)
  50084. )
  50085. &&
  50086. extension_loaded('mcrypt')
  50087. ) {
  50088. require_once $RandomCompatDIR . '/random_bytes_mcrypt.php';
  50089. }
  50090. $RandomCompatUrandom = null;
  50091. if (
  50092. !is_callable('random_bytes')
  50093. &&
  50094. extension_loaded('com_dotnet')
  50095. &&
  50096. class_exists('COM')
  50097. ) {
  50098. $RandomCompat_disabled_classes = preg_split(
  50099. '#\s*,\s*#',
  50100. strtolower(ini_get('disable_classes'))
  50101. );
  50102. if (!in_array('com', $RandomCompat_disabled_classes)) {
  50103. try {
  50104. $RandomCompatCOMtest = new COM('CAPICOM.Utilities.1');
  50105. if (method_exists($RandomCompatCOMtest, 'GetRandom')) {
  50106. require_once $RandomCompatDIR . '/random_bytes_com_dotnet.php';
  50107. }
  50108. } catch (com_exception $e) {
  50109. }
  50110. }
  50111. $RandomCompat_disabled_classes = null;
  50112. $RandomCompatCOMtest = null;
  50113. }
  50114. if (!is_callable('random_bytes')) {
  50115. function random_bytes($length)
  50116. {
  50117. unset($length);
  50118. throw new Exception(
  50119. 'There is no suitable CSPRNG installed on your system'
  50120. );
  50121. }
  50122. }
  50123. }
  50124. if (!is_callable('random_int')) {
  50125. require_once $RandomCompatDIR . '/random_int.php';
  50126. }
  50127. $RandomCompatDIR = null;
  50128. <?php
  50129. if (!is_callable('random_bytes')) {
  50130. function random_bytes($bytes)
  50131. {
  50132. try {
  50133. $bytes = RandomCompat_intval($bytes);
  50134. } catch (TypeError $ex) {
  50135. throw new TypeError(
  50136. 'random_bytes(): $bytes must be an integer'
  50137. );
  50138. }
  50139. if ($bytes < 1) {
  50140. throw new Error(
  50141. 'Length must be greater than 0'
  50142. );
  50143. }
  50144. $buf = '';
  50145. if (!class_exists('COM')) {
  50146. throw new Error(
  50147. 'COM does not exist'
  50148. );
  50149. }
  50150. $util = new COM('CAPICOM.Utilities.1');
  50151. $execCount = 0;
  50152. do {
  50153. $buf .= base64_decode($util->GetRandom($bytes, 0));
  50154. if (RandomCompat_strlen($buf) >= $bytes) {
  50155. return RandomCompat_substr($buf, 0, $bytes);
  50156. }
  50157. ++$execCount;
  50158. } while ($execCount < $bytes);
  50159. throw new Exception(
  50160. 'Could not gather sufficient random data'
  50161. );
  50162. }
  50163. }<?php
  50164. if (!defined('RANDOM_COMPAT_READ_BUFFER')) {
  50165. define('RANDOM_COMPAT_READ_BUFFER', 8);
  50166. }
  50167. if (!is_callable('random_bytes')) {
  50168. function random_bytes($bytes)
  50169. {
  50170. static $fp = null;
  50171. if (empty($fp)) {
  50172. $fp = fopen('/dev/urandom', 'rb');
  50173. if (!empty($fp)) {
  50174. $st = fstat($fp);
  50175. if (($st['mode'] & 0170000) !== 020000) {
  50176. fclose($fp);
  50177. $fp = false;
  50178. }
  50179. }
  50180. if (!empty($fp)) {
  50181. if (is_callable('stream_set_read_buffer')) {
  50182. stream_set_read_buffer($fp, RANDOM_COMPAT_READ_BUFFER);
  50183. }
  50184. if (is_callable('stream_set_chunk_size')) {
  50185. stream_set_chunk_size($fp, RANDOM_COMPAT_READ_BUFFER);
  50186. }
  50187. }
  50188. }
  50189. try {
  50190. $bytes = RandomCompat_intval($bytes);
  50191. } catch (TypeError $ex) {
  50192. throw new TypeError(
  50193. 'random_bytes(): $bytes must be an integer'
  50194. );
  50195. }
  50196. if ($bytes < 1) {
  50197. throw new Error(
  50198. 'Length must be greater than 0'
  50199. );
  50200. }
  50201. if (!empty($fp)) {
  50202. $remaining = $bytes;
  50203. $buf = '';
  50204. do {
  50205. $read = fread($fp, $remaining);
  50206. if (!is_string($read)) {
  50207. if ($read === false) {
  50208. $buf = false;
  50209. break;
  50210. }
  50211. }
  50212. $remaining -= RandomCompat_strlen($read);
  50213. $buf = $buf . $read;
  50214. } while ($remaining > 0);
  50215. if (is_string($buf)) {
  50216. if (RandomCompat_strlen($buf) === $bytes) {
  50217. return $buf;
  50218. }
  50219. }
  50220. }
  50221. throw new Exception(
  50222. 'Error reading from source device'
  50223. );
  50224. }
  50225. }
  50226. <?php
  50227. if (!is_callable('random_bytes')) {
  50228. function random_bytes($bytes)
  50229. {
  50230. try {
  50231. $bytes = RandomCompat_intval($bytes);
  50232. } catch (TypeError $ex) {
  50233. throw new TypeError(
  50234. 'random_bytes(): $bytes must be an integer'
  50235. );
  50236. }
  50237. if ($bytes < 1) {
  50238. throw new Error(
  50239. 'Length must be greater than 0'
  50240. );
  50241. }
  50242. if ($bytes > 2147483647) {
  50243. $buf = '';
  50244. for ($i = 0; $i < $bytes; $i += 1073741824) {
  50245. $n = ($bytes - $i) > 1073741824
  50246. ? 1073741824
  50247. : $bytes - $i;
  50248. $buf .= \Sodium\randombytes_buf($n);
  50249. }
  50250. } else {
  50251. $buf = \Sodium\randombytes_buf($bytes);
  50252. }
  50253. if ($buf !== false) {
  50254. if (RandomCompat_strlen($buf) === $bytes) {
  50255. return $buf;
  50256. }
  50257. }
  50258. throw new Exception(
  50259. 'Could not gather sufficient random data'
  50260. );
  50261. }
  50262. }
  50263. <?php
  50264. if (!is_callable('random_bytes')) {
  50265. function random_bytes($bytes)
  50266. {
  50267. try {
  50268. $bytes = RandomCompat_intval($bytes);
  50269. } catch (TypeError $ex) {
  50270. throw new TypeError(
  50271. 'random_bytes(): $bytes must be an integer'
  50272. );
  50273. }
  50274. if ($bytes < 1) {
  50275. throw new Error(
  50276. 'Length must be greater than 0'
  50277. );
  50278. }
  50279. $buf = '';
  50280. if ($bytes > 2147483647) {
  50281. for ($i = 0; $i < $bytes; $i += 1073741824) {
  50282. $n = ($bytes - $i) > 1073741824
  50283. ? 1073741824
  50284. : $bytes - $i;
  50285. $buf .= Sodium::randombytes_buf((int) $n);
  50286. }
  50287. } else {
  50288. $buf .= Sodium::randombytes_buf((int) $bytes);
  50289. }
  50290. if (is_string($buf)) {
  50291. if (RandomCompat_strlen($buf) === $bytes) {
  50292. return $buf;
  50293. }
  50294. }
  50295. throw new Exception(
  50296. 'Could not gather sufficient random data'
  50297. );
  50298. }
  50299. }
  50300. <?php
  50301. if (!is_callable('random_bytes')) {
  50302. function random_bytes($bytes)
  50303. {
  50304. try {
  50305. $bytes = RandomCompat_intval($bytes);
  50306. } catch (TypeError $ex) {
  50307. throw new TypeError(
  50308. 'random_bytes(): $bytes must be an integer'
  50309. );
  50310. }
  50311. if ($bytes < 1) {
  50312. throw new Error(
  50313. 'Length must be greater than 0'
  50314. );
  50315. }
  50316. $buf = @mcrypt_create_iv($bytes, MCRYPT_DEV_URANDOM);
  50317. if (
  50318. $buf !== false
  50319. &&
  50320. RandomCompat_strlen($buf) === $bytes
  50321. ) {
  50322. return $buf;
  50323. }
  50324. throw new Exception(
  50325. 'Could not gather sufficient random data'
  50326. );
  50327. }
  50328. }
  50329. <?php
  50330. if (!is_callable('random_int')) {
  50331. function random_int($min, $max)
  50332. {
  50333. try {
  50334. $min = RandomCompat_intval($min);
  50335. } catch (TypeError $ex) {
  50336. throw new TypeError(
  50337. 'random_int(): $min must be an integer'
  50338. );
  50339. }
  50340. try {
  50341. $max = RandomCompat_intval($max);
  50342. } catch (TypeError $ex) {
  50343. throw new TypeError(
  50344. 'random_int(): $max must be an integer'
  50345. );
  50346. }
  50347. if ($min > $max) {
  50348. throw new Error(
  50349. 'Minimum value must be less than or equal to the maximum value'
  50350. );
  50351. }
  50352. if ($max === $min) {
  50353. return (int) $min;
  50354. }
  50355. $attempts = $bits = $bytes = $mask = $valueShift = 0;
  50356. $range = $max - $min;
  50357. if (!is_int($range)) {
  50358. $bytes = PHP_INT_SIZE;
  50359. $mask = ~0;
  50360. } else {
  50361. while ($range > 0) {
  50362. if ($bits % 8 === 0) {
  50363. ++$bytes;
  50364. }
  50365. ++$bits;
  50366. $range >>= 1;
  50367. $mask = $mask << 1 | 1;
  50368. }
  50369. $valueShift = $min;
  50370. }
  50371. $val = 0;
  50372. do {
  50373. if ($attempts > 128) {
  50374. throw new Exception(
  50375. 'random_int: RNG is broken - too many rejections'
  50376. );
  50377. }
  50378. $randomByteString = random_bytes($bytes);
  50379. $val &= 0;
  50380. for ($i = 0; $i < $bytes; ++$i) {
  50381. $val |= ord($randomByteString[$i]) << ($i * 8);
  50382. }
  50383. $val &= $mask;
  50384. $val += $valueShift;
  50385. ++$attempts;
  50386. } while (!is_int($val) || $val > $max || $val < $min);
  50387. return (int) $val;
  50388. }
  50389. }
  50390. <?php
  50391. $dist = dirname(__DIR__).'/dist';
  50392. if (!is_dir($dist)) {
  50393. mkdir($dist, 0755);
  50394. }
  50395. if (file_exists($dist.'/random_compat.phar')) {
  50396. unlink($dist.'/random_compat.phar');
  50397. }
  50398. $phar = new Phar(
  50399. $dist.'/random_compat.phar',
  50400. FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::KEY_AS_FILENAME,
  50401. 'random_compat.phar'
  50402. );
  50403. rename(
  50404. dirname(__DIR__).'/lib/random.php',
  50405. dirname(__DIR__).'/lib/index.php'
  50406. );
  50407. $phar->buildFromDirectory(dirname(__DIR__).'/lib');
  50408. rename(
  50409. dirname(__DIR__).'/lib/index.php',
  50410. dirname(__DIR__).'/lib/random.php'
  50411. );
  50412. if ($argc > 1) {
  50413. if (!@is_readable($argv[1])) {
  50414. echo 'Could not read the private key file:', $argv[1], "\n";
  50415. exit(255);
  50416. }
  50417. $pkeyFile = file_get_contents($argv[1]);
  50418. $private = openssl_get_privatekey($pkeyFile);
  50419. if ($private !== false) {
  50420. $pkey = '';
  50421. openssl_pkey_export($private, $pkey);
  50422. $phar->setSignatureAlgorithm(Phar::OPENSSL, $pkey);
  50423. if (!@is_readable($dist.'/random_compat.phar.pubkey')) {
  50424. $details = openssl_pkey_get_details($private);
  50425. file_put_contents(
  50426. $dist.'/random_compat.phar.pubkey',
  50427. $details['key']
  50428. );
  50429. }
  50430. } else {
  50431. echo 'An error occurred reading the private key from OpenSSL.', "\n";
  50432. exit(255);
  50433. }
  50434. }
  50435. <?php
  50436. require_once 'lib/byte_safe_strings.php';
  50437. require_once 'lib/cast_to_int.php';
  50438. require_once 'lib/error_polyfill.php';
  50439. require_once 'other/ide_stubs/libsodium.php';
  50440. require_once 'lib/random.php';
  50441. $int = random_int(0, 65536);
  50442. <?php
  50443. require_once __DIR__ . '/composer/autoload_real.php';
  50444. return ComposerAutoloaderInit1d283854a5726c702db972976066d6a2::getLoader();
  50445. Copyright (c) 2012-2018 Fabien Potencier
  50446. Dariusz Rumiński
  50447. Permission is hereby granted, free of charge, to any person obtaining a copy
  50448. of this software and associated documentation files (the "Software"), to deal
  50449. in the Software without restriction, including without limitation the rights
  50450. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  50451. copies of the Software, and to permit persons to whom the Software is furnished
  50452. to do so, subject to the following conditions:
  50453. The above copyright notice and this permission notice shall be included in all
  50454. copies or substantial portions of the Software.
  50455. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  50456. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  50457. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  50458. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  50459. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  50460. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  50461. THE SOFTWARE.
  50462. ¢Ç4mñ�ÕñÄÑÓo~aõë���GBMB