Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
CRAP
100.00% covered (success)
100.00%
71 / 71
InCaption
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
4 / 4
30
100.00% covered (success)
100.00%
71 / 71
 characters
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
3 / 3
 startTag
100.00% covered (success)
100.00%
1 / 1
11
100.00% covered (success)
100.00%
23 / 23
 endTag
100.00% covered (success)
100.00%
1 / 1
17
100.00% covered (success)
100.00%
43 / 43
 endDocument
100.00% covered (success)
100.00%
1 / 1
1
100.00% covered (success)
100.00%
2 / 2
<?php
namespace RemexHtml\TreeBuilder;
use RemexHtml\Tokenizer\Attributes;
/**
 * The "in caption" insertion mode
 */
class InCaption extends InsertionMode {
    public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
        $this->dispatcher->inBody->characters( $text, $start, $length,
            $sourceStart, $sourceLength );
    }
    public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
        $builder = $this->builder;
        $stack = $builder->stack;
        switch ( $name ) {
            case 'caption':
            case 'col':
            case 'colgroup':
            case 'tbody':
            case 'td':
            case 'tfoot':
            case 'th':
            case 'thead':
            case 'tr':
                $builder->error( "start tag <$name> not allowed in caption", $sourceStart );
                if ( !$stack->isInTableScope( 'caption' ) ) {
                    // Ignore
                    return;
                }
                $builder->popAllUpToName( 'caption', $sourceStart, 0 );
                $builder->afe->clearToMarker();
                $this->dispatcher->switchMode( Dispatcher::IN_TABLE )
                    ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
                break;
            default:
                $this->dispatcher->inBody->startTag( $name, $attrs, $selfClose,
                    $sourceStart, $sourceLength );
        }
    }
    public function endTag( $name, $sourceStart, $sourceLength ) {
        $dispatcher = $this->dispatcher;
        $builder = $this->builder;
        $stack = $builder->stack;
        switch ( $name ) {
        case 'caption':
            if ( !$stack->isInTableScope( 'caption' ) ) {
                $builder->error( "</caption> matches a start tag which is not in scope, ignoring",
                    $sourceStart );
                return;
            }
            $builder->generateImpliedEndTags( false, $sourceStart );
            if ( $stack->current->htmlName !== 'caption' ) {
                $builder->error( "</caption> found but another element is open", $sourceStart );
            }
            $builder->popAllUpToName( 'caption', $sourceStart, $sourceLength );
            $builder->afe->clearToMarker();
            $dispatcher->switchMode( Dispatcher::IN_TABLE );
            break;
        case 'table':
            if ( !$stack->isInTableScope( 'caption' ) ) {
                $builder->error( '</table> found in caption, but there is no ' .
                    'caption in scope, ignoring', $sourceStart );
                return;
            }
            $builder->generateImpliedEndTags( false, $sourceStart );
            if ( $stack->current->htmlName !== 'caption' ) {
                $builder->error( '</table> found in caption, closing caption', $sourceStart );
            }
            $builder->popAllUpToName( 'caption', $sourceStart, 0 );
            $builder->afe->clearToMarker();
            $dispatcher->switchMode( Dispatcher::IN_TABLE )
                ->endTag( $name, $sourceStart, $sourceLength );
            break;
        case 'body':
        case 'col':
        case 'colgroup':
        case 'html':
        case 'tbody':
        case 'td':
        case 'tfoot':
        case 'th':
        case 'thead':
        case 'tr':
            $this->builder->error( "end tag </$name> ignored in caption mode", $sourceStart );
            break;
        default:
            $this->dispatcher->inBody->endTag( $name, $sourceStart, $sourceLength );
        }
    }
    public function endDocument( $pos ) {
        $this->dispatcher->inBody->endDocument( $pos );
    }
}