2424 */
2525class Parser
2626{
27-
2827 const OPTION_STATE_DEFAULT = 0 ;
2928 const OPTION_STATE_TAGNAME = 1 ;
3029 const OPTION_STATE_KEY = 2 ;
@@ -103,7 +102,8 @@ public function addCodeDefinition(CodeDefinition $definition)
103102 *
104103 * @return Parser
105104 */
106- public function addCodeDefinitionSet (CodeDefinitionSet $ set ) {
105+ public function addCodeDefinitionSet (CodeDefinitionSet $ set )
106+ {
107107 foreach ($ set ->getCodeDefinitions () as $ def ) {
108108 $ this ->addCodeDefinition ($ def );
109109 }
@@ -233,7 +233,7 @@ public function codeExists($tagName, $usesOption = false)
233233 */
234234 public function getCode ($ tagName , $ usesOption = false )
235235 {
236- if ($ this ->codeExists ($ tagName , $ usesOption )) {
236+ if ($ this ->codeExists ($ tagName , $ usesOption )) {
237237 return $ this ->bbcodes [strtolower ($ tagName )][$ usesOption ];
238238 }
239239
@@ -297,8 +297,7 @@ protected function parseStartState(ElementNode $parent, Tokenizer $tokenizer)
297297
298298 if ('[ ' == $ next ) {
299299 return $ this ->parseTagOpen ($ parent , $ tokenizer );
300- }
301- else {
300+ } else {
302301 $ this ->createTextNode ($ parent , $ next );
303302 /* Drop back into the main parse loop which will call this
304303 * same method again. */
@@ -317,7 +316,6 @@ protected function parseStartState(ElementNode $parent, Tokenizer $tokenizer)
317316 */
318317 protected function parseTagOpen (ElementNode $ parent , Tokenizer $ tokenizer )
319318 {
320-
321319 if (!$ tokenizer ->hasNext ()) {
322320 /* The [ that sent us to this state was just a trailing [, not the
323321 * opening for a new tag. Treat it as such. */
@@ -350,8 +348,7 @@ protected function parseTagOpen(ElementNode $parent, Tokenizer $tokenizer)
350348 $ after_next = $ tokenizer ->next ();
351349 $ tokenizer ->stepBack ();
352350
353- if ($ after_next != '] ' )
354- {
351+ if ($ after_next != '] ' ) {
355352 $ this ->createTextNode ($ parent , '[ ' .$ next );
356353 return $ parent ;
357354 }
@@ -380,20 +377,20 @@ protected function parseOptions($tagContent)
380377 $ done = false ;
381378 $ idx = 0 ;
382379
383- try {
384- while (!$ done ){
380+ try {
381+ while (!$ done ) {
385382 $ char = $ idx < $ len ? $ tagContent [$ idx ]:null ;
386- switch ($ state ){
383+ switch ($ state ) {
387384 case static ::OPTION_STATE_TAGNAME :
388- switch ($ char ){
385+ switch ($ char ) {
389386 case '= ' :
390387 $ state = static ::OPTION_STATE_VALUE ;
391388 $ tagName = $ buffer ;
392389 $ keys [] = $ tagName ;
393390 $ buffer = "" ;
394391 break ;
395392 case ' ' :
396- if ($ buffer ) {
393+ if ($ buffer ) {
397394 $ state = static ::OPTION_STATE_DEFAULT ;
398395 $ tagName = $ buffer ;
399396 $ buffer = '' ;
@@ -415,7 +412,7 @@ protected function parseOptions($tagContent)
415412 break ;
416413
417414 case static ::OPTION_STATE_DEFAULT :
418- switch ($ char ){
415+ switch ($ char ) {
419416 case ' ' :
420417 // do nothing
421418 default :
@@ -425,7 +422,7 @@ protected function parseOptions($tagContent)
425422 break ;
426423
427424 case static ::OPTION_STATE_VALUE :
428- switch ($ char ){
425+ switch ($ char ) {
429426 case '" ' :
430427 $ state = static ::OPTION_STATE_QUOTED_VALUE ;
431428 break ;
@@ -436,7 +433,7 @@ protected function parseOptions($tagContent)
436433 $ state = static ::OPTION_STATE_KEY ;
437434 break ;
438435 case ": " :
439- if ($ buffer =="javascript " ){
436+ if ($ buffer =="javascript " ) {
440437 $ state = static ::OPTION_STATE_JAVASCRIPT ;
441438 }
442439 $ buffer .= $ char ;
@@ -448,7 +445,7 @@ protected function parseOptions($tagContent)
448445 break ;
449446
450447 case static ::OPTION_STATE_JAVASCRIPT :
451- switch ($ char ){
448+ switch ($ char ) {
452449 case "; " :
453450 $ buffer .= $ char ;
454451 $ values [] = $ buffer ;
@@ -462,7 +459,7 @@ protected function parseOptions($tagContent)
462459 break ;
463460
464461 case static ::OPTION_STATE_KEY :
465- switch ($ char ){
462+ switch ($ char ) {
466463 case '= ' :
467464 $ state = static ::OPTION_STATE_VALUE ;
468465 $ keys [] = trim ($ buffer );
@@ -477,15 +474,15 @@ protected function parseOptions($tagContent)
477474 break ;
478475
479476 case static ::OPTION_STATE_QUOTED_VALUE :
480- switch ($ char ){
477+ switch ($ char ) {
481478 case null :
482479 case '" ' :
483480 $ state = static ::OPTION_STATE_KEY ;
484481 $ values [] = $ buffer ;
485482 $ buffer = '' ;
486483
487484 // peek ahead. If the next character is not a space or a closing brace, we have a bad tag and need to abort
488- if (isset ($ tagContent [$ idx +1 ]) && $ tagContent [$ idx +1 ]!=" " && $ tagContent [$ idx +1 ]!="] " ) {
485+ if (isset ($ tagContent [$ idx +1 ]) && $ tagContent [$ idx +1 ]!=" " && $ tagContent [$ idx +1 ]!="] " ) {
489486 throw new \DomainException ("Badly formed attribute: $ tagContent " );
490487 }
491488 break ;
@@ -495,26 +492,25 @@ protected function parseOptions($tagContent)
495492 }
496493 break ;
497494 default :
498- if (!empty ($ char )){
495+ if (!empty ($ char )) {
499496 $ state = static ::OPTION_STATE_KEY ;
500497 }
501498
502499 }
503- if ($ idx >= $ len ){
500+ if ($ idx >= $ len ) {
504501 $ done = true ;
505502 }
506503 $ idx ++;
507504 }
508505
509- if (!empty ($ keys ) && !empty ($ values )){
510- if (count ($ keys )==(count ($ values )+1 )){
506+ if (!empty ($ keys ) && !empty ($ values )) {
507+ if (count ($ keys )==(count ($ values )+1 )) {
511508 array_unshift ($ values , "" );
512509 }
513510
514511 $ options = array_combine ($ keys , $ values );
515512 }
516- }
517- catch (\DomainException $ e ){
513+ } catch (\DomainException $ e ) {
518514 // if we're in this state, then something evidently went wrong. We'll consider everything that came after the tagname to be the attribute for that keyname
519515 $ options [$ tagName ]= substr ($ tagContent , strpos ($ tagContent , "= " )+1 );
520516 }
@@ -641,5 +637,4 @@ protected function parseAsTextUntilClose(ElementNode $parent, Tokenizer $tokeniz
641637 $ curr = $ tokenizer ->next ();
642638 }
643639 }
644-
645640}
0 commit comments