Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
98.41% |
62 / 63 |
|
75.00% |
3 / 4 |
CRAP | |
0.00% |
0 / 1 |
InColumnGroup | |
98.41% |
62 / 63 |
|
75.00% |
3 / 4 |
18 | |
0.00% |
0 / 1 |
characters | |
94.44% |
17 / 18 |
|
0.00% |
0 / 1 |
4.00 | |||
startTag | |
100.00% |
20 / 20 |
|
100.00% |
1 / 1 |
6 | |||
endTag | |
100.00% |
24 / 24 |
|
100.00% |
1 / 1 |
7 | |||
endDocument | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace Wikimedia\RemexHtml\TreeBuilder; |
4 | |
5 | use Wikimedia\RemexHtml\Tokenizer\Attributes; |
6 | |
7 | /** |
8 | * The "in column group" insertion mode |
9 | */ |
10 | class InColumnGroup 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 | |
15 | [ $start, $length, $sourceStart, $sourceLength ] = $part1; |
16 | if ( $length !== 0 ) { |
17 | $this->builder->insertCharacters( $text, $start, $length, |
18 | $sourceStart, $sourceLength ); |
19 | } |
20 | |
21 | [ $start, $length, $sourceStart, $sourceLength ] = $part2; |
22 | |
23 | if ( $length === 0 ) { |
24 | // All done with this sequence |
25 | return; |
26 | } |
27 | |
28 | // Handle non-whitespace as "anything else" |
29 | $builder = $this->builder; |
30 | $stack = $builder->stack; |
31 | if ( $stack->current->htmlName !== 'colgroup' ) { |
32 | $builder->error( 'text should close the colgroup but another element is open', |
33 | $sourceStart ); |
34 | // Ignore |
35 | return; |
36 | } else { |
37 | $builder->pop( $sourceStart, 0 ); |
38 | } |
39 | $this->dispatcher->switchMode( Dispatcher::IN_TABLE ) |
40 | ->characters( $text, $start, $length, $sourceStart, $sourceLength ); |
41 | } |
42 | |
43 | public function startTag( $name, Attributes $attrs, $selfClose, $sourceStart, $sourceLength ) { |
44 | $dispatcher = $this->dispatcher; |
45 | $builder = $this->builder; |
46 | $stack = $builder->stack; |
47 | |
48 | switch ( $name ) { |
49 | case 'html': |
50 | $dispatcher->inBody->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
51 | break; |
52 | |
53 | case 'col': |
54 | $dispatcher->ack = true; |
55 | $builder->insertElement( $name, $attrs, true, $sourceStart, $sourceLength ); |
56 | break; |
57 | |
58 | case 'template': |
59 | $dispatcher->inHead->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
60 | break; |
61 | |
62 | default: |
63 | if ( $stack->current->htmlName !== 'colgroup' ) { |
64 | $builder->error( 'start tag should close the colgroup but another element is open', |
65 | $sourceStart ); |
66 | // Ignore |
67 | return; |
68 | } else { |
69 | $builder->pop( $sourceStart, 0 ); |
70 | } |
71 | $this->dispatcher->switchMode( Dispatcher::IN_TABLE ) |
72 | ->startTag( $name, $attrs, $selfClose, $sourceStart, $sourceLength ); |
73 | } |
74 | } |
75 | |
76 | public function endTag( $name, $sourceStart, $sourceLength ) { |
77 | $dispatcher = $this->dispatcher; |
78 | $builder = $this->builder; |
79 | $stack = $builder->stack; |
80 | |
81 | switch ( $name ) { |
82 | case 'colgroup': |
83 | if ( $stack->current->htmlName !== 'colgroup' ) { |
84 | $builder->error( '</colgroup> found but another element is open, ignoring', |
85 | $sourceStart ); |
86 | return; |
87 | } |
88 | $builder->pop( $sourceStart, $sourceLength ); |
89 | $dispatcher->switchMode( Dispatcher::IN_TABLE ); |
90 | break; |
91 | |
92 | case 'col': |
93 | $builder->error( '</col> found in column group mode, ignoring', $sourceStart ); |
94 | break; |
95 | |
96 | case 'template': |
97 | $dispatcher->inHead->endTag( $name, $sourceStart, $sourceLength ); |
98 | break; |
99 | |
100 | default: |
101 | if ( $stack->current->htmlName !== 'colgroup' ) { |
102 | $builder->error( 'non-matching end tag should close the colgroup ' . |
103 | ' but another element is open', $sourceStart ); |
104 | // Ignore |
105 | return; |
106 | } else { |
107 | $builder->pop( $sourceStart, 0 ); |
108 | } |
109 | $dispatcher->switchMode( Dispatcher::IN_TABLE ) |
110 | ->endTag( $name, $sourceStart, $sourceLength ); |
111 | } |
112 | } |
113 | |
114 | public function endDocument( $pos ) { |
115 | $this->dispatcher->inBody->endDocument( $pos ); |
116 | } |
117 | } |