Balancer style tweaks
authorTim Starling <tstarling@wikimedia.org>
Mon, 1 Aug 2016 06:27:09 +0000 (16:27 +1000)
committerCscott <cananian@wikimedia.org>
Thu, 4 Aug 2016 22:06:09 +0000 (22:06 +0000)
* Use for loops where appropriate, instead of while
* De-indent a large block which was unnecessarily indented
* Use camel case for variable names, per the style guide

Change-Id: I0b2c37fdcab7f7238db0393085c43297e7a03ab2

includes/tidy/Balancer.php

index 21acdb3..f84e038 100644 (file)
@@ -1150,34 +1150,28 @@ class BalanceStack implements IteratorAggregate {
                        return true; // no more handling required
                }
 
-               // Let outer loop counter be zero.
-               $outer = 0;
-
                // Outer loop: If outer loop counter is greater than or
                // equal to eight, then abort these steps.
-               while ( $outer < 8 ) {
-                       // Increment outer loop counter by one.
-                       $outer++;
-
+               for ( $outer = 0; $outer < 8; $outer++ ) {
                        // Let the formatting element be the last element in the list
                        // of active formatting elements that: is between the end of
                        // the list and the last scope marker in the list, if any, or
                        // the start of the list otherwise, and has the same tag name
                        // as the token.
-                       $fmtelt = $afe->findElementByTag( $tag );
+                       $fmtElt = $afe->findElementByTag( $tag );
 
                        // If there is no such node, then abort these steps and instead
                        // act as described in the "any other end tag" entry below.
-                       if ( !$fmtelt ) {
+                       if ( !$fmtElt ) {
                                return false; // false means handle by the default case
                        }
 
                        // Otherwise, if there is such a node, but that node is not in
                        // the stack of open elements, then this is a parse error;
                        // remove the element from the list, and abort these steps.
-                       $index = $this->indexOf( $fmtelt );
+                       $index = $this->indexOf( $fmtElt );
                        if ( $index < 0 ) {
-                               $afe->remove( $fmtelt );
+                               $afe->remove( $fmtElt );
                                return true;   // true means no more handling required
                        }
 
@@ -1185,7 +1179,7 @@ class BalanceStack implements IteratorAggregate {
                        // the stack of open elements, but the element is not in scope,
                        // then this is a parse error; ignore the token, and abort
                        // these steps.
-                       if ( !$this->inScope( $fmtelt ) ) {
+                       if ( !$this->inScope( $fmtElt ) ) {
                                return true;
                        }
 
@@ -1193,13 +1187,13 @@ class BalanceStack implements IteratorAggregate {
                        // open elements that is lower in the stack than the formatting
                        // element, and is an element in the special category. There
                        // might not be one.
-                       $furthestblock = null;
-                       $furthestblockindex = -1;
-                       $stacklen = $this->length();
-                       for ( $i = $index+1; $i < $stacklen; $i++ ) {
+                       $furthestBlock = null;
+                       $furthestBlockIndex = -1;
+                       $stackLength = $this->length();
+                       for ( $i = $index+1; $i < $stackLength; $i++ ) {
                                if ( $this->node( $i )->isA( BalanceSets::$specialSet ) ) {
-                                       $furthestblock = $this->node( $i );
-                                       $furthestblockindex = $i;
+                                       $furthestBlock = $this->node( $i );
+                                       $furthestBlockIndex = $i;
                                        break;
                                }
                        }
@@ -1210,140 +1204,134 @@ class BalanceStack implements IteratorAggregate {
                        // up to and including the formatting element, and remove the
                        // formatting element from the list of active formatting
                        // elements.
-                       if ( !$furthestblock ) {
-                               $this->popTag( $fmtelt );
-                               $afe->remove( $fmtelt );
-                               return true;
-                       } else {
-                               // Let the common ancestor be the element immediately above
-                               // the formatting element in the stack of open elements.
-                               $ancestor = $this->node( $index-1 );
-
-                               // Let a bookmark note the position of the formatting
-                               // element in the list of active formatting elements
-                               // relative to the elements on either side of it in the
-                               // list.
-                               $BOOKMARK = new BalanceElement( '[bookmark]', '[bookmark]', [] );
-                               $afe->insertAfter( $fmtelt, $BOOKMARK );
-
-                               // Let node and last node be the furthest block.
-                               $node = $furthestblock;
-                               $lastnode = $furthestblock;
-                               $nodeindex = $furthestblockindex;
-                               $isAFE = false;
-
-                               // Let inner loop counter be zero.
-                               $inner = 0;
-
-                               while ( true ) {
-
-                                       // Increment inner loop counter by one.
-                                       $inner++;
-
-                                       // Let node be the element immediately above node in
-                                       // the stack of open elements, or if node is no longer
-                                       // in the stack of open elements (e.g. because it got
-                                       // removed by this algorithm), the element that was
-                                       // immediately above node in the stack of open elements
-                                       // before node was removed.
-                                       $node = $this->node( --$nodeindex );
-
-                                       // If node is the formatting element, then go
-                                       // to the next step in the overall algorithm.
-                                       if ( $node === $fmtelt ) break;
-
-                                       // If the inner loop counter is greater than three and node
-                                       // is in the list of active formatting elements, then remove
-                                       // node from the list of active formatting elements.
-                                       $isAFE = $afe->isInList( $node );
-                                       if ( $inner > 3 && $isAFE ) {
-                                               $afe->remove( $node );
-                                               $isAFE = false;
-                                       }
-
-                                       // If node is not in the list of active formatting
-                                       // elements, then remove node from the stack of open
-                                       // elements and then go back to the step labeled inner
-                                       // loop.
-                                       if ( !$isAFE ) {
-                                               // Don't flatten here, since we're about to relocate
-                                               // parts of this $node.
-                                               $this->removeElement( $node, false );
-                                               continue;
-                                       }
-
-                                       // Create an element for the token for which the
-                                       // element node was created with common ancestor as
-                                       // the intended parent, replace the entry for node
-                                       // in the list of active formatting elements with an
-                                       // entry for the new element, replace the entry for
-                                       // node in the stack of open elements with an entry for
-                                       // the new element, and let node be the new element.
-                                       $newelt = new BalanceElement(
-                                               $node->namespaceURI, $node->localName, $node->attribs );
-                                       $afe->replace( $node, $newelt );
-                                       $this->replaceAt( $nodeindex, $newelt );
-                                       $node = $newelt;
-
-                                       // If last node is the furthest block, then move the
-                                       // aforementioned bookmark to be immediately after the
-                                       // new node in the list of active formatting elements.
-                                       if ( $lastnode === $furthestblock ) {
-                                               $afe->remove( $BOOKMARK );
-                                               $afe->insertAfter( $newelt, $BOOKMARK );
-                                       }
-
-                                       // Insert last node into node, first removing it from
-                                       // its previous parent node if any.
-                                       $node->appendChild( $lastnode );
-
-                                       // Let last node be node.
-                                       $lastnode = $node;
-                               }
-
-                               // If the common ancestor node is a table, tbody, tfoot,
-                               // thead, or tr element, then, foster parent whatever last
-                               // node ended up being in the previous step, first removing
-                               // it from its previous parent node if any.
-                               if (
-                                       $this->fosterParentMode &&
-                                       $ancestor->isA( BalanceSets::$tableSectionRowSet )
-                               ) {
-                                       $this->fosterParent( $lastnode );
-                               } else {
-                                       // Otherwise, append whatever last node ended up being in
-                                       // the previous step to the common ancestor node, first
-                                       // removing it from its previous parent node if any.
-                                       $ancestor->appendChild( $lastnode );
+                       if ( !$furthestBlock ) {
+                               $this->popTag( $fmtElt );
+                               $afe->remove( $fmtElt );
+                               return true;
+                       }
+
+                       // Let the common ancestor be the element immediately above
+                       // the formatting element in the stack of open elements.
+                       $ancestor = $this->node( $index-1 );
+
+                       // Let a bookmark note the position of the formatting
+                       // element in the list of active formatting elements
+                       // relative to the elements on either side of it in the
+                       // list.
+                       $BOOKMARK = new BalanceElement( '[bookmark]', '[bookmark]', [] );
+                       $afe->insertAfter( $fmtElt, $BOOKMARK );
+
+                       // Let node and last node be the furthest block.
+                       $node = $furthestBlock;
+                       $lastNode = $furthestBlock;
+                       $nodeIndex = $furthestBlockIndex;
+                       $isAFE = false;
+
+                       // Inner loop
+                       for ( $inner = 1; true; $inner++ ) {
+                               // Let node be the element immediately above node in
+                               // the stack of open elements, or if node is no longer
+                               // in the stack of open elements (e.g. because it got
+                               // removed by this algorithm), the element that was
+                               // immediately above node in the stack of open elements
+                               // before node was removed.
+                               $node = $this->node( --$nodeIndex );
+
+                               // If node is the formatting element, then go
+                               // to the next step in the overall algorithm.
+                               if ( $node === $fmtElt ) break;
+
+                               // If the inner loop counter is greater than three and node
+                               // is in the list of active formatting elements, then remove
+                               // node from the list of active formatting elements.
+                               $isAFE = $afe->isInList( $node );
+                               if ( $inner > 3 && $isAFE ) {
+                                       $afe->remove( $node );
+                                       $isAFE = false;
+                               }
+
+                               // If node is not in the list of active formatting
+                               // elements, then remove node from the stack of open
+                               // elements and then go back to the step labeled inner
+                               // loop.
+                               if ( !$isAFE ) {
+                                       // Don't flatten here, since we're about to relocate
+                                       // parts of this $node.
+                                       $this->removeElement( $node, false );
+                                       continue;
                                }
 
                                // Create an element for the token for which the
-                               // formatting element was created, with furthest block
-                               // as the intended parent.
-                               $newelt2 = new BalanceElement(
-                                       $fmtelt->namespaceURI, $fmtelt->localName, $fmtelt->attribs );
+                               // element node was created with common ancestor as
+                               // the intended parent, replace the entry for node
+                               // in the list of active formatting elements with an
+                               // entry for the new element, replace the entry for
+                               // node in the stack of open elements with an entry for
+                               // the new element, and let node be the new element.
+                               $newElt = new BalanceElement(
+                                       $node->namespaceURI, $node->localName, $node->attribs );
+                               $afe->replace( $node, $newElt );
+                               $this->replaceAt( $nodeIndex, $newElt );
+                               $node = $newElt;
+
+                               // If last node is the furthest block, then move the
+                               // aforementioned bookmark to be immediately after the
+                               // new node in the list of active formatting elements.
+                               if ( $lastNode === $furthestBlock ) {
+                                       $afe->remove( $BOOKMARK );
+                                       $afe->insertAfter( $newElt, $BOOKMARK );
+                               }
+
+                               // Insert last node into node, first removing it from
+                               // its previous parent node if any.
+                               $node->appendChild( $lastNode );
+
+                               // Let last node be node.
+                               $lastNode = $node;
+                       }
+
+                       // If the common ancestor node is a table, tbody, tfoot,
+                       // thead, or tr element, then, foster parent whatever last
+                       // node ended up being in the previous step, first removing
+                       // it from its previous parent node if any.
+                       if (
+                               $this->fosterParentMode &&
+                               $ancestor->isA( BalanceSets::$tableSectionRowSet )
+                       ) {
+                               $this->fosterParent( $lastNode );
+                       } else {
+                               // Otherwise, append whatever last node ended up being in
+                               // the previous step to the common ancestor node, first
+                               // removing it from its previous parent node if any.
+                               $ancestor->appendChild( $lastNode );
+                       }
 
-                               // Take all of the child nodes of the furthest block and
-                               // append them to the element created in the last step.
-                               $newelt2->adoptChildren( $furthestblock );
+                       // Create an element for the token for which the
+                       // formatting element was created, with furthest block
+                       // as the intended parent.
+                       $newElt2 = new BalanceElement(
+                               $fmtElt->namespaceURI, $fmtElt->localName, $fmtElt->attribs );
 
-                               // Append that new element to the furthest block.
-                               $furthestblock->appendChild( $newelt2 );
+                       // Take all of the child nodes of the furthest block and
+                       // append them to the element created in the last step.
+                       $newElt2->adoptChildren( $furthestBlock );
 
-                               // Remove the formatting element from the list of active
-                               // formatting elements, and insert the new element into the
-                               // list of active formatting elements at the position of
-                               // the aforementioned bookmark.
-                               $afe->remove( $fmtelt );
-                               $afe->replace( $BOOKMARK, $newelt2 );
+                       // Append that new element to the furthest block.
+                       $furthestBlock->appendChild( $newElt2 );
 
-                               // Remove the formatting element from the stack of open
-                               // elements, and insert the new element into the stack of
-                               // open elements immediately below the position of the
-                               // furthest block in that stack.
-                               $this->removeElement( $fmtelt );
-                               $this->insertAfter( $furthestblock, $newelt2 );
-                       }
+                       // Remove the formatting element from the list of active
+                       // formatting elements, and insert the new element into the
+                       // list of active formatting elements at the position of
+                       // the aforementioned bookmark.
+                       $afe->remove( $fmtElt );
+                       $afe->replace( $BOOKMARK, $newElt2 );
+
+                       // Remove the formatting element from the stack of open
+                       // elements, and insert the new element into the stack of
+                       // open elements immediately below the position of the
+                       // furthest block in that stack.
+                       $this->removeElement( $fmtElt );
+                       $this->insertAfter( $furthestBlock, $newElt2 );
                }
 
                return true;
@@ -1676,11 +1664,11 @@ class BalanceActiveFormattingElements {
 
                // Loop backward through the list until we find a marker or an
                // open element
-               $foundit = false;
+               $foundIt = false;
                while ( $entry->prevAFE ) {
                        $entry = $entry->prevAFE;
                        if ( $entry instanceof BalanceMarker || $stack->indexOf( $entry ) >= 0 ) {
-                               $foundit = true;
+                               $foundIt = true;
                                break;
                        }
                }
@@ -1689,7 +1677,7 @@ class BalanceActiveFormattingElements {
                // the first element if we didn't find a marker or open element),
                // recreating formatting elements and pushing them back onto the list
                // of open elements.
-               if ( $foundit ) {
+               if ( $foundIt ) {
                        $entry = $entry->nextAFE;
                }
                do {
@@ -1950,7 +1938,7 @@ class Balancer {
         * Pass a token to the tree builder.  The $token will be one of the
         * strings "tag", "endtag", or "text".
         */
-       private function insertToken( $token, $value, $attribs = null, $selfclose = false ) {
+       private function insertToken( $token, $value, $attribs = null, $selfClose = false ) {
                // validate tags against $unsupportedSet
                if ( $token === 'tag' || $token === 'endtag' ) {
                        if ( isset( BalanceSets::$unsupportedSet[BalanceSets::HTML_NAMESPACE][$value] ) ) {
@@ -2011,14 +1999,14 @@ class Balancer {
                        $isForeign = false;
                }
                if ( $isForeign ) {
-                       return $this->insertForeignToken( $token, $value, $attribs, $selfclose );
+                       return $this->insertForeignToken( $token, $value, $attribs, $selfClose );
                } else {
                        $func = $this->parseMode;
-                       return $this->$func( $token, $value, $attribs, $selfclose );
+                       return $this->$func( $token, $value, $attribs, $selfClose );
                }
        }
 
-       private function insertForeignToken( $token, $value, $attribs = null, $selfclose = false ) {
+       private function insertForeignToken( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        $this->stack->insertText( $value );
                        return true;
@@ -2090,7 +2078,7 @@ class Balancer {
                                                break;
                                        }
                                }
-                               return $this->insertToken( $token, $value, $attribs, $selfclose );
+                               return $this->insertToken( $token, $value, $attribs, $selfClose );
                        }
                        // "Any other start tag"
                        $adjusted = ( $this->fragmentContext && $this->stack->length()===1 ) ?
@@ -2098,7 +2086,7 @@ class Balancer {
                        $this->stack->insertForeignElement(
                                $adjusted->namespaceURI, $value, $attribs
                        );
-                       if ( $selfclose ) {
+                       if ( $selfClose ) {
                                $this->stack->pop();
                        }
                        return true;
@@ -2108,7 +2096,7 @@ class Balancer {
                                if ( $node->isHtml() && !$first ) {
                                        // process the end tag as HTML
                                        $func = $this->parseMode;
-                                       return $this->$func( $token, $value, $attribs, $selfclose );
+                                       return $this->$func( $token, $value, $attribs, $selfClose );
                                } elseif ( $i === 0 ) {
                                        return true;
                                } elseif ( $node->localName === $value ) {
@@ -2166,13 +2154,13 @@ class Balancer {
                        );
                        $slash = $t = $attribStr = $brace = $rest = null;
                }
-               $goodtag = $t;
+               $goodTag = $t;
                if ( $this->inRCDATA ) {
                        if ( $slash && $t === $this->inRCDATA ) {
                                $this->inRCDATA = false;
                        } else {
                                // No tags allowed; this emulates the "rcdata" tokenizer mode.
-                               $goodtag = false;
+                               $goodTag = false;
                        }
                }
                if ( $this->inRAWTEXT ) {
@@ -2180,33 +2168,33 @@ class Balancer {
                                $this->inRAWTEXT = false;
                        } else {
                                // No tags allowed, no entity-escaping done.
-                               $goodtag = false;
+                               $goodTag = false;
                        }
                }
                $sanitize = $this->allowedHtmlElements !== null;
                if ( $sanitize ) {
-                       $goodtag = $t && isset( $this->allowedHtmlElements[$t] );
+                       $goodTag = $t && isset( $this->allowedHtmlElements[$t] );
                }
-               if ( $goodtag ) {
+               if ( $goodTag ) {
                        if ( is_callable( $this->processingCallback ) ) {
                                call_user_func_array( $this->processingCallback, [ &$attribStr, $this->processingArgs ] );
                        }
                        if ( $sanitize ) {
-                               $goodtag = Sanitizer::validateTag( $attribStr, $t );
+                               $goodTag = Sanitizer::validateTag( $attribStr, $t );
                        }
                }
-               if ( $goodtag ) {
+               if ( $goodTag ) {
                        if ( $sanitize ) {
                                $attribs = Sanitizer::decodeTagAttributes( $attribStr );
                                $attribs = Sanitizer::validateTagAttributes( $attribs, $t );
                        } else {
                                $attribs = Sanitizer::decodeTagAttributes( $attribStr );
                        }
-                       $goodtag = $this->insertToken(
+                       $goodTag = $this->insertToken(
                                $slash ? 'endtag' : 'tag', $t, $attribs, $brace === '/>'
                        );
                }
-               if ( $goodtag ) {
+               if ( $goodTag ) {
                        $rest = str_replace( '>', '&gt;', $rest );
                        $this->insertToken( 'text', str_replace( '>', '&gt;', $rest ) );
                } elseif ( $this->inRAWTEXT ) {
@@ -2226,9 +2214,9 @@ class Balancer {
                return $oldMode;
        }
 
-       private function switchModeAndReprocess( $mode, $token, $value, $attribs, $selfclose ) {
+       private function switchModeAndReprocess( $mode, $token, $value, $attribs, $selfClose ) {
                $this->switchMode( $mode );
-               return $this->insertToken( $token, $value, $attribs, $selfclose );
+               return $this->insertToken( $token, $value, $attribs, $selfClose );
        }
 
        private function resetInsertionMode() {
@@ -2243,9 +2231,9 @@ class Balancer {
                        if ( $node->isHtml() ) {
                                switch ( $node->localName ) {
                                case 'select':
-                                       $stacklen = $this->stack->length();
-                                       for ( $j = $i + 1; $j < $stacklen-1; $j++ ) {
-                                               $ancestor = $this->stack->node( $stacklen-$j-1 );
+                                       $stackLength = $this->stack->length();
+                                       for ( $j = $i + 1; $j < $stackLength-1; $j++ ) {
+                                               $ancestor = $this->stack->node( $stackLength-$j-1 );
                                                if ( $ancestor->isHtmlNamed( 'template' ) ) {
                                                        break;
                                                }
@@ -2321,14 +2309,14 @@ class Balancer {
                return true;
        }
 
-       private function inTextMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inTextMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        $this->stack->insertText( $value );
                        return true;
                } elseif ( $token === 'eof' ) {
                        $this->stack->pop();
                        return $this->switchModeAndReprocess(
-                               $this->originalInsertionMode, $token, $value, $attribs, $selfclose
+                               $this->originalInsertionMode, $token, $value, $attribs, $selfClose
                        );
                } elseif ( $token === 'endtag' ) {
                        $this->stack->pop();
@@ -2338,7 +2326,7 @@ class Balancer {
                return true;
        }
 
-       private function inHeadMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inHeadMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        if ( preg_match( '/^[\x09\x0A\x0C\x0D\x20]+/', $value, $matches ) ) {
                                $this->stack->insertText( $matches[0] );
@@ -2405,17 +2393,17 @@ class Balancer {
                // If not handled above
                $this->inHeadMode( 'endtag', 'head' ); // synthetic </head>
                // Then redo this one
-               return $this->insertToken( $token, $value, $attribs, $selfclose );
+               return $this->insertToken( $token, $value, $attribs, $selfClose );
        }
 
-       private function inBodyMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inBodyMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        $this->afe->reconstruct( $this->stack );
                        $this->stack->insertText( $value );
                        return true;
                } elseif ( $token === 'eof' ) {
                        if ( !empty( $this->templateInsertionModes ) ) {
-                               return $this->inTemplateMode( $token, $value, $attribs, $selfclose );
+                               return $this->inTemplateMode( $token, $value, $attribs, $selfClose );
                        }
                        $this->stopParsing();
                        return true;
@@ -2432,7 +2420,7 @@ class Balancer {
                        case 'style':
                        case 'template':
                        // OMITTED: <title>
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        // OMITTED: <body>
                        // OMITTED: <frameset>
 
@@ -2557,7 +2545,7 @@ class Balancer {
                        case 'button':
                                if ( $this->stack->inScope( 'button' ) ) {
                                        $this->inBodyMode( 'endtag', 'button' );
-                                       return $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       return $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                $this->afe->reconstruct( $this->stack );
                                $this->stack->insertHTMLElement( $value, $attribs );
@@ -2659,7 +2647,7 @@ class Balancer {
 
                        case 'image':
                                // warts!
-                               return $this->inBodyMode( $token, 'img', $attribs, $selfclose );
+                               return $this->inBodyMode( $token, 'img', $attribs, $selfClose );
 
                        // OMITTED: <isindex>
 
@@ -2725,7 +2713,7 @@ class Balancer {
                                $this->stack->insertForeignElement(
                                        BalanceSets::MATHML_NAMESPACE, $value, $attribs
                                );
-                               if ( $selfclose ) {
+                               if ( $selfClose ) {
                                        // emit explicit </math> tag.
                                        $this->stack->pop();
                                }
@@ -2740,7 +2728,7 @@ class Balancer {
                                $this->stack->insertForeignElement(
                                        BalanceSets::SVG_NAMESPACE, $value, $attribs
                                );
-                               if ( $selfclose ) {
+                               if ( $selfClose ) {
                                        // emit explicit </svg> tag.
                                        $this->stack->pop();
                                }
@@ -2770,7 +2758,7 @@ class Balancer {
                        // </body>,</html> are unsupported.
 
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
 
                        case 'address':
                        case 'article':
@@ -2830,7 +2818,7 @@ class Balancer {
                        case 'p':
                                if ( !$this->stack->inButtonScope( 'p' ) ) {
                                        $this->inBodyMode( 'tag', 'p', [] );
-                                       return $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       return $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                $this->stack->generateImpliedEndTags( $value );
                                $this->stack->popTag( $value );
@@ -2924,15 +2912,15 @@ class Balancer {
                }
        }
 
-       private function inTableMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inTableMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        if ( $this->textIntegrationMode ) {
-                               return $this->inBodyMode( $token, $value, $attribs, $selfclose );
+                               return $this->inBodyMode( $token, $value, $attribs, $selfClose );
                        } elseif ( $this->stack->currentNode->isA( BalanceSets::$tableSectionRowSet ) ) {
                                $this->pendingTableText = '';
                                $this->originalInsertionMode = $this->parseMode;
                                return $this->switchModeAndReprocess( 'inTableTextMode',
-                                       $token, $value, $attribs, $selfclose );
+                                       $token, $value, $attribs, $selfClose );
                        }
                        // fall through to default case.
                } elseif ( $token === 'eof' ) {
@@ -2952,7 +2940,7 @@ class Balancer {
                                return true;
                        case 'col':
                                $this->inTableMode( 'tag', 'colgroup', [] );
-                               return $this->insertToken( $token, $value, $attribs, $selfclose );
+                               return $this->insertToken( $token, $value, $attribs, $selfClose );
                        case 'tbody':
                        case 'tfoot':
                        case 'thead':
@@ -2964,18 +2952,18 @@ class Balancer {
                        case 'th':
                        case 'tr':
                                $this->inTableMode( 'tag', 'tbody', [] );
-                               return $this->insertToken( $token, $value, $attribs, $selfclose );
+                               return $this->insertToken( $token, $value, $attribs, $selfClose );
                        case 'table':
                                if ( !$this->stack->inTableScope( $value ) ) {
                                        return true; // Ignore this tag.
                                }
                                $this->inTableMode( 'endtag', $value );
-                               return $this->insertToken( $token, $value, $attribs, $selfclose );
+                               return $this->insertToken( $token, $value, $attribs, $selfClose );
 
                        case 'style':
                        // OMITTED: <script>
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
 
                        case 'input':
                                if ( !isset( $attribs['type'] ) || strcasecmp( $attribs['type'], 'hidden' ) !== 0 ) {
@@ -3020,7 +3008,7 @@ class Balancer {
                        case 'tr':
                                return true; // Ignore the token.
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        }
                        // Fall through for "anything else" clause.
                } elseif ( $token === 'comment' ) {
@@ -3029,12 +3017,12 @@ class Balancer {
                }
                // This is the "anything else" case:
                $this->stack->fosterParentMode = true;
-               $this->inBodyMode( $token, $value, $attribs, $selfclose );
+               $this->inBodyMode( $token, $value, $attribs, $selfClose );
                $this->stack->fosterParentMode = false;
                return true;
        }
 
-       private function inTableTextMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inTableTextMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        $this->pendingTableText .= $value;
                        return true;
@@ -3052,7 +3040,7 @@ class Balancer {
                        $this->stack->insertText( $text );
                }
                return $this->switchModeAndReprocess(
-                       $this->originalInsertionMode, $token, $value, $attribs, $selfclose
+                       $this->originalInsertionMode, $token, $value, $attribs, $selfClose
                );
        }
 
@@ -3068,7 +3056,7 @@ class Balancer {
                return true;
        }
 
-       private function inCaptionMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inCaptionMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'tag' ) {
                        switch ( $value ) {
                        case 'caption':
@@ -3081,7 +3069,7 @@ class Balancer {
                        case 'thead':
                        case 'tr':
                                if ( $this->endCaption() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        }
@@ -3093,7 +3081,7 @@ class Balancer {
                                return true;
                        case 'table':
                                if ( $this->endCaption() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        case 'body':
@@ -3112,10 +3100,10 @@ class Balancer {
                        // Fall through to "anything else" case.
                }
                // The Anything Else case
-               return $this->inBodyMode( $token, $value, $attribs, $selfclose );
+               return $this->inBodyMode( $token, $value, $attribs, $selfClose );
        }
 
-       private function inColumnGroupMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inColumnGroupMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        if ( preg_match( '/^[\x09\x0A\x0C\x0D\x20]+/', $value, $matches ) ) {
                                $this->stack->insertText( $matches[0] );
@@ -3133,7 +3121,7 @@ class Balancer {
                                $this->stack->pop();
                                return true;
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        }
                        // Fall through for "anything else".
                } elseif ( $token === 'endtag' ) {
@@ -3148,11 +3136,11 @@ class Balancer {
                        case 'col':
                                return true; // Ignore the token.
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        }
                        // Fall through for "anything else".
                } elseif ( $token === 'eof' ) {
-                       return $this->inBodyMode( $token, $value, $attribs, $selfclose );
+                       return $this->inBodyMode( $token, $value, $attribs, $selfClose );
                } elseif ( $token === 'comment' ) {
                        $this->stack->insertComment( $value );
                        return true;
@@ -3163,7 +3151,7 @@ class Balancer {
                        return true; // Ignore the token.
                }
                $this->inColumnGroupMode( 'endtag', 'colgroup' );
-               return $this->insertToken( $token, $value, $attribs, $selfclose );
+               return $this->insertToken( $token, $value, $attribs, $selfClose );
        }
 
        // Helper function for inTableBodyMode
@@ -3180,7 +3168,7 @@ class Balancer {
                $this->switchMode( 'inTableMode' );
                return true;
        }
-       private function inTableBodyMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inTableBodyMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'tag' ) {
                        switch ( $value ) {
                        case 'tr':
@@ -3191,7 +3179,7 @@ class Balancer {
                        case 'th':
                        case 'td':
                                $this->inTableBodyMode( 'tag', 'tr', [] );
-                               $this->insertToken( $token, $value, $attribs, $selfclose );
+                               $this->insertToken( $token, $value, $attribs, $selfClose );
                                return true;
                        case 'caption':
                        case 'col':
@@ -3200,7 +3188,7 @@ class Balancer {
                        case 'tfoot':
                        case 'thead':
                                if ( $this->endSection() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        }
@@ -3208,7 +3196,7 @@ class Balancer {
                        switch ( $value ) {
                        case 'table':
                                if ( $this->endSection() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        case 'tbody':
@@ -3230,7 +3218,7 @@ class Balancer {
                        }
                }
                // Anything else:
-               return $this->inTableMode( $token, $value, $attribs, $selfclose );
+               return $this->inTableMode( $token, $value, $attribs, $selfClose );
        }
 
        // Helper function for inRowMode
@@ -3243,7 +3231,7 @@ class Balancer {
                $this->switchMode( 'inTableBodyMode' );
                return true;
        }
-       private function inRowMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inRowMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'tag' ) {
                        switch ( $value ) {
                        case 'th':
@@ -3261,7 +3249,7 @@ class Balancer {
                        case 'thead':
                        case 'tr':
                                if ( $this->endRow() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        }
@@ -3272,7 +3260,7 @@ class Balancer {
                                return true;
                        case 'table':
                                if ( $this->endRow() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        case 'tbody':
@@ -3282,7 +3270,7 @@ class Balancer {
                                        $this->stack->inTableScope( $value ) &&
                                        $this->endRow()
                                ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        // OMITTED: <body>
@@ -3296,7 +3284,7 @@ class Balancer {
                        }
                }
                // Anything else:
-               return $this->inTableMode( $token, $value, $attribs, $selfclose );
+               return $this->inTableMode( $token, $value, $attribs, $selfClose );
        }
 
        // Helper for inCellMode
@@ -3311,7 +3299,7 @@ class Balancer {
                        return false;
                }
        }
-       private function inCellMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inCellMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'tag' ) {
                        switch ( $value ) {
                        case 'caption':
@@ -3324,7 +3312,7 @@ class Balancer {
                        case 'thead':
                        case 'tr':
                                if ( $this->endCell() ) {
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        }
@@ -3356,21 +3344,21 @@ class Balancer {
                                        $this->stack->popTag( BalanceSets::$tableCellSet );
                                        $this->afe->clearToMarker();
                                        $this->switchMode( 'inRowMode' );
-                                       $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        }
                }
                // Anything else:
-               return $this->inBodyMode( $token, $value, $attribs, $selfclose );
+               return $this->inBodyMode( $token, $value, $attribs, $selfClose );
        }
 
-       private function inSelectMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inSelectMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' ) {
                        $this->stack->insertText( $value );
                        return true;
                } elseif ( $token === 'eof' ) {
-                       return $this->inBodyMode( $token, $value, $attribs, $selfclose );
+                       return $this->inBodyMode( $token, $value, $attribs, $selfClose );
                } elseif ( $token === 'tag' ) {
                        switch ( $value ) {
                        // OMITTED: <html>
@@ -3399,10 +3387,10 @@ class Balancer {
                                        return true; // ignore token (fragment case)
                                }
                                $this->inSelectMode( 'endtag', 'select' );
-                               return $this->insertToken( $token, $value, $attribs, $selfclose );
+                               return $this->insertToken( $token, $value, $attribs, $selfClose );
                        case 'script':
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        }
                } elseif ( $token === 'endtag' ) {
                        switch ( $value ) {
@@ -3431,7 +3419,7 @@ class Balancer {
                                $this->resetInsertionMode();
                                return true;
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        }
                } elseif ( $token === 'comment' ) {
                        $this->stack->insertComment( $value );
@@ -3441,7 +3429,7 @@ class Balancer {
                return true;
        }
 
-       private function inSelectInTableMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inSelectInTableMode( $token, $value, $attribs = null, $selfClose = false ) {
                switch ( $value ) {
                case 'caption':
                case 'table':
@@ -3453,22 +3441,22 @@ class Balancer {
                case 'th':
                        if ( $token === 'tag' ) {
                                $this->inSelectInTableMode( 'endtag', 'select' );
-                               return $this->insertToken( $token, $value, $attribs, $selfclose );
+                               return $this->insertToken( $token, $value, $attribs, $selfClose );
                        } elseif ( $token === 'endtag' ) {
                                if ( $this->stack->inTableScope( $value ) ) {
                                        $this->inSelectInTableMode( 'endtag', 'select' );
-                                       return $this->insertToken( $token, $value, $attribs, $selfclose );
+                                       return $this->insertToken( $token, $value, $attribs, $selfClose );
                                }
                                return true;
                        }
                }
                // anything else
-               return $this->inSelectMode( $token, $value, $attribs, $selfclose );
+               return $this->inSelectMode( $token, $value, $attribs, $selfClose );
        }
 
-       private function inTemplateMode( $token, $value, $attribs = null, $selfclose = false ) {
+       private function inTemplateMode( $token, $value, $attribs = null, $selfClose = false ) {
                if ( $token === 'text' || $token === 'comment' ) {
-                       return $this->inBodyMode( $token, $value, $attribs, $selfclose );
+                       return $this->inBodyMode( $token, $value, $attribs, $selfClose );
                } elseif ( $token === 'eof' ) {
                        if ( $this->stack->indexOf( 'template' ) < 0 ) {
                                $this->stopParsing();
@@ -3477,7 +3465,7 @@ class Balancer {
                                $this->afe->clearToMarker();
                                array_pop( $this->templateInsertionModes );
                                $this->resetInsertionMode();
-                               $this->insertToken( $token, $value, $attribs, $selfclose );
+                               $this->insertToken( $token, $value, $attribs, $selfClose );
                        }
                        return true;
                } elseif ( $token === 'tag' ) {
@@ -3492,7 +3480,7 @@ class Balancer {
                        case 'style':
                        case 'template':
                        // OMITTED: <title>
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
 
                        case 'caption':
                        case 'colgroup':
@@ -3500,32 +3488,32 @@ class Balancer {
                        case 'tfoot':
                        case 'thead':
                                return $this->switchModeAndReprocess(
-                                       'inTableMode', $token, $value, $attribs, $selfclose
+                                       'inTableMode', $token, $value, $attribs, $selfClose
                                );
 
                        case 'col':
                                return $this->switchModeAndReprocess(
-                                       'inColumnGroupMode', $token, $value, $attribs, $selfclose
+                                       'inColumnGroupMode', $token, $value, $attribs, $selfClose
                                );
 
                        case 'tr':
                                return $this->switchModeAndReprocess(
-                                       'inTableBodyMode', $token, $value, $attribs, $selfclose
+                                       'inTableBodyMode', $token, $value, $attribs, $selfClose
                                );
 
                        case 'td':
                        case 'th':
                                return $this->switchModeAndReprocess(
-                                       'inRowMode', $token, $value, $attribs, $selfclose
+                                       'inRowMode', $token, $value, $attribs, $selfClose
                                );
                        }
                        return $this->switchModeAndReprocess(
-                               'inBodyMode', $token, $value, $attribs, $selfclose
+                               'inBodyMode', $token, $value, $attribs, $selfClose
                        );
                } elseif ( $token === 'endtag' ) {
                        switch ( $value ) {
                        case 'template':
-                               return $this->inHeadMode( $token, $value, $attribs, $selfclose );
+                               return $this->inHeadMode( $token, $value, $attribs, $selfClose );
                        }
                        return true;
                } else {