Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
33.33% covered (danger)
33.33%
2 / 6
CRAP
52.00% covered (warning)
52.00%
13 / 25
InTextarea
0.00% covered (danger)
0.00%
0 / 1
33.33% covered (danger)
33.33%
2 / 6
19.12
50.00% covered (danger)
50.00%
12 / 24
 characters
100.00% covered (success)
100.00%
1 / 1
4
100.00% covered (success)
100.00%
9 / 9
 endDocument
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 startTag
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 endTag
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 doctype
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
 comment
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
<?php
namespace Wikimedia\RemexHtml\TreeBuilder;
use Wikimedia\RemexHtml\Tokenizer\Attributes;
/**
 * This is not a tree builder state in the spec. I added it to handle the
 * "next token" references in textarea. If the first token is a newline, it is
 * ignored. Then we switch the dispatcher to the "text" mode regardless, which
 * is the correct mode for parsing textarea elements.
 */
class InTextarea extends InsertionMode {
    public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
        if ( $length > 0 && $text[$start] === "\n" ) {
            // Ignore initial line break
            $start++;
            $length--;
            $sourceStart++;
            $sourceLength--;
        }
        $mode = $this->dispatcher->switchMode( Dispatcher::TEXT );
        if ( $length ) {
            $mode->characters( $text, $start, $length, $sourceStart, $sourceLength );
        }
    }
    public function endDocument( $pos ) {
        $this->dispatcher->switchMode( Dispatcher::TEXT )
            ->endDocument( $pos );
    }
    public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
        $this->dispatcher->switchMode( Dispatcher::TEXT )
            ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
    }
    public function endTag( $name, $sourceStart, $sourceLength ) {
        $this->dispatcher->switchMode( Dispatcher::TEXT )
            ->endTag( $name, $sourceStart, $sourceLength );
    }
    public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
        $this->dispatcher->switchMode( Dispatcher::TEXT )
            ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength );
    }
    public function comment( $text, $sourceStart, $sourceLength ) {
        $this->dispatcher->switchMode( Dispatcher::TEXT )
            ->comment( $text, $sourceStart, $sourceLength );
    }
}
// Retain the old namespace for backwards compatibility.
class_alias( InTextarea::class, 'RemexHtml\TreeBuilder\InTextarea' );