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