Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
66.67% |
12 / 18 |
|
33.33% |
2 / 6 |
CRAP | |
0.00% |
0 / 1 |
FastFormatter | |
66.67% |
12 / 18 |
|
33.33% |
2 / 6 |
17.33 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
startDocument | |
66.67% |
2 / 3 |
|
0.00% |
0 / 1 |
2.15 | |||
doctype | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
characters | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
element | |
72.73% |
8 / 11 |
|
0.00% |
0 / 1 |
6.73 | |||
comment | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace Wikimedia\RemexHtml\Serializer; |
4 | |
5 | /** |
6 | * A formatter suitable for pre-sanitized input with ignoreEntities enabled |
7 | * in the Tokenizer. |
8 | */ |
9 | class FastFormatter implements Formatter { |
10 | public function __construct( $options = [] ) { |
11 | } |
12 | |
13 | /** |
14 | * @inheritDoc |
15 | */ |
16 | public function startDocument( $fragmentNamespace, $fragmentName ) { |
17 | if ( $fragmentNamespace === null ) { |
18 | return "<!DOCTYPE html>\n"; |
19 | } else { |
20 | return ''; |
21 | } |
22 | } |
23 | |
24 | /** |
25 | * @inheritDoc |
26 | */ |
27 | public function doctype( $name, $public, $system ) { |
28 | return ''; |
29 | } |
30 | |
31 | /** |
32 | * @inheritDoc |
33 | */ |
34 | public function characters( SerializerNode $parent, $text, $start, $length ) { |
35 | return substr( $text, $start, $length ); |
36 | } |
37 | |
38 | /** |
39 | * @inheritDoc |
40 | */ |
41 | public function element( SerializerNode $parent, SerializerNode $node, $contents ) { |
42 | $name = $node->name; |
43 | $ret = "<$name"; |
44 | foreach ( $node->attrs->getValues() as $attrName => $value ) { |
45 | $ret .= " $attrName=\"$value\""; |
46 | } |
47 | if ( $contents === null ) { |
48 | $ret .= "/>"; |
49 | } elseif ( isset( $contents[0] ) && $contents[0] === "\n" |
50 | && in_array( $name, [ 'pre', 'textarea', 'listing' ] ) |
51 | ) { |
52 | $ret .= ">\n$contents</$name>"; |
53 | } else { |
54 | $ret .= ">$contents</$name>"; |
55 | } |
56 | return $ret; |
57 | } |
58 | |
59 | /** |
60 | * @inheritDoc |
61 | */ |
62 | public function comment( SerializerNode $parent, $text ) { |
63 | return "<!--$text-->"; |
64 | } |
65 | } |