Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
85.71% |
36 / 42 |
|
62.50% |
5 / 8 |
CRAP | |
0.00% |
0 / 1 |
InTableText | |
85.71% |
36 / 42 |
|
62.50% |
5 / 8 |
14.57 | |
0.00% |
0 / 1 |
characters | |
87.50% |
7 / 8 |
|
0.00% |
0 / 1 |
2.01 | |||
doctype | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
comment | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
startTag | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
endTag | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
endDocument | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
flush | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
processPendingCharacters | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
6 |
1 | <?php |
2 | |
3 | namespace Wikimedia\RemexHtml\TreeBuilder; |
4 | |
5 | use Wikimedia\RemexHtml\Tokenizer\Attributes; |
6 | |
7 | /** |
8 | * The "in table text" insertion mode |
9 | */ |
10 | class InTableText extends InsertionMode { |
11 | public function characters( $text, $start, $length, $sourceStart, $sourceLength ) { |
12 | $handleNonNull = function ( $text, $start, $length, $sourceStart, $sourceLength ) { |
13 | $this->builder->pendingTableCharacters[] = [ |
14 | $text, $start, $length, $sourceStart, $sourceLength ]; |
15 | }; |
16 | if ( !$this->builder->ignoreNulls ) { |
17 | $this->stripNulls( $handleNonNull, $text, $start, $length, |
18 | $sourceStart, $sourceLength ); |
19 | } else { |
20 | $handleNonNull( $text, $start, $length, $sourceStart, $sourceLength ); |
21 | } |
22 | } |
23 | |
24 | public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) { |
25 | $this->processPendingCharacters(); |
26 | $this->dispatcher->restoreMode() |
27 | ->doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ); |
28 | } |
29 | |
30 | public function comment( $text, $sourceStart, $sourceLength ) { |
31 | $this->processPendingCharacters(); |
32 | $this->dispatcher->restoreMode() |
33 | ->comment( $text, $sourceStart, $sourceLength ); |
34 | } |
35 | |
36 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
37 | $this->processPendingCharacters(); |
38 | $this->dispatcher->restoreMode() |
39 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
40 | } |
41 | |
42 | public function endTag( $name, $sourceStart, $sourceLength ) { |
43 | $this->processPendingCharacters(); |
44 | $this->dispatcher->restoreMode() |
45 | ->endTag( $name, $sourceStart, $sourceLength ); |
46 | } |
47 | |
48 | public function endDocument( $pos ) { |
49 | $this->processPendingCharacters(); |
50 | $this->dispatcher->restoreMode() |
51 | ->endDocument( $pos ); |
52 | } |
53 | |
54 | /** |
55 | * Flush the pending table text and restore the mode |
56 | */ |
57 | public function flush() { |
58 | $this->processPendingCharacters(); |
59 | $this->dispatcher->restoreMode(); |
60 | } |
61 | |
62 | /** |
63 | * Common code for the "anything else" case. Process the pending table |
64 | * character tokens. |
65 | */ |
66 | protected function processPendingCharacters() { |
67 | $builder = $this->builder; |
68 | $allSpace = true; |
69 | foreach ( $builder->pendingTableCharacters as $token ) { |
70 | [ $text, $start, $length, $sourceStart, $sourceLength ] = $token; |
71 | if ( strspn( $text, "\t\n\f\r ", $start, $length ) !== $length ) { |
72 | $allSpace = false; |
73 | } |
74 | } |
75 | if ( $allSpace ) { |
76 | foreach ( $builder->pendingTableCharacters as $token ) { |
77 | [ $text, $start, $length, $sourceStart, $sourceLength ] = $token; |
78 | $builder->insertCharacters( $text, $start, $length, $sourceStart, $sourceLength ); |
79 | } |
80 | } else { |
81 | $builder->fosterParenting = true; |
82 | foreach ( $builder->pendingTableCharacters as $token ) { |
83 | [ $text, $start, $length, $sourceStart, $sourceLength ] = $token; |
84 | $builder->error( 'invalid characters in table text, fostering', $sourceStart ); |
85 | $this->dispatcher->inBody->characters( $text, $start, $length, |
86 | $sourceStart, $sourceLength ); |
87 | } |
88 | $builder->fosterParenting = false; |
89 | } |
90 | } |
91 | } |