Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
5 / 5
CRAP
100.00% covered (success)
100.00%
1 / 1
AfterAfterBody
100.00% covered (success)
100.00%
26 / 26
100.00% covered (success)
100.00%
5 / 5
9
100.00% covered (success)
100.00%
1 / 1
 characters
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
 startTag
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
3
 endTag
100.00% covered (success)
100.00%
3 / 3
100.00% covered (success)
100.00%
1 / 1
1
 endDocument
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 comment
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2
3namespace Wikimedia\RemexHtml\TreeBuilder;
4
5use Wikimedia\RemexHtml\Tokenizer\Attributes;
6
7/**
8 * The "after after body" insertion mode
9 */
10class AfterAfterBody extends InsertionMode {
11    public function characters( $text, $start, $length, $sourceStart, $sourceLength ) {
12        [ $part1, $part2 ] = $this->splitInitialMatch( true, "\t\n\f\r ",
13            $text, $start, $length, $sourceStart, $sourceLength );
14        [ $start, $length, $sourceStart, $sourceLength ] = $part1;
15        if ( $length ) {
16            $this->builder->insertCharacters( $text, $start, $length, $sourceStart, $sourceLength );
17        }
18
19        [ $start, $length, $sourceStart, $sourceLength ] = $part2;
20        if ( !$length ) {
21            return;
22        }
23        $this->builder->error( "unexpected non-whitespace characters after after body",
24            $sourceStart );
25        $this->dispatcher->switchMode( Dispatcher::IN_BODY )
26            ->characters( $text, $start, $length, $sourceStart, $sourceLength );
27    }
28
29    public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) {
30        $builder = $this->builder;
31        $dispatcher = $this->dispatcher;
32
33        switch ( $name ) {
34            case 'html':
35                $dispatcher->inBody->startTag(
36                    $name, $attrs, $selfClose, $sourceStart, $sourceLength );
37                break;
38
39            default:
40                $builder->error( "unexpected start tag after after body", $sourceStart );
41                $dispatcher->switchMode( Dispatcher::IN_BODY )
42                    ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength );
43        }
44    }
45
46    public function endTag( $name, $sourceStart, $sourceLength ) {
47        $this->builder->error( "unexpected end tag after after body", $sourceStart );
48        $this->dispatcher->switchMode( Dispatcher::IN_BODY )
49            ->endTag( $name, $sourceStart, $sourceLength );
50    }
51
52    public function endDocument( $pos ) {
53        $this->builder->stopParsing( $pos );
54    }
55
56    public function comment( $text, $sourceStart, $sourceLength ) {
57        $this->builder->comment( [ TreeBuilder::ROOT, null ], $text, $sourceStart, $sourceLength );
58    }
59}