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