Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 14
CRAP
0.00% covered (danger)
0.00%
0 / 1
SerializerWithTracer
0.00% covered (danger)
0.00%
0 / 27
0.00% covered (danger)
0.00%
0 / 14
380
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 3
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
12
 trace
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 startDocument
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 endDocument
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
 characters
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 insertElement
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 endTag
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 doctype
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 comment
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 error
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 mergeAttributes
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 removeNode
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 reparentChildren
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3namespace Wikimedia\RemexHtml\Serializer;
4
5use Wikimedia\RemexHtml\Tokenizer\Attributes;
6use Wikimedia\RemexHtml\TreeBuilder\Element;
7use Wikimedia\RemexHtml\TreeBuilder\TraceFormatter;
8
9class SerializerWithTracer extends Serializer {
10    private $traceCallback;
11    private $verbosity;
12
13    public function __construct( Formatter $formatter, $errorCallback = null, $traceCallback = null,
14        $verbosity = 0
15    ) {
16        $this->traceCallback = $traceCallback;
17        $this->verbosity = $verbosity;
18        parent::__construct( $formatter, $errorCallback );
19    }
20
21    private function handle( $funcName, $args ) {
22        $this->trace( call_user_func_array( [ TraceFormatter::class, $funcName ], $args ) );
23        call_user_func_array( [ parent::class, $funcName ], $args );
24        if ( $this->verbosity > 0 && $funcName !== 'endDocument' ) {
25            $this->trace( "Dump after $funcName" . $this->dump() );
26        }
27    }
28
29    private function trace( $msg ) {
30        call_user_func( $this->traceCallback, "[Serializer] $msg" );
31    }
32
33    public function startDocument( $fragmentNamespace, $fragmentName ) {
34        $this->handle( __FUNCTION__, func_get_args() );
35    }
36
37    public function endDocument( $pos ) {
38        if ( count( $this->nodes ) ) {
39            $nodeTags = '';
40            foreach ( $this->nodes as $node ) {
41                if ( $nodeTags !== '' ) {
42                    $nodeTags .= ', ';
43                }
44                $nodeTags .= $node->getDebugTag();
45            }
46            $this->trace( "endDocument: unclosed elements: $nodeTags" );
47        } else {
48            $this->trace( "endDocument: no unclosed elements" );
49        }
50
51        $this->handle( __FUNCTION__, func_get_args() );
52    }
53
54    public function characters( $preposition, $refElement, $text, $start, $length,
55        $sourceStart, $sourceLength
56    ) {
57        $this->handle( __FUNCTION__, func_get_args() );
58    }
59
60    public function insertElement( $preposition, $refElement, Element $element, $void,
61        $sourceStart, $sourceLength
62    ) {
63        $this->handle( __FUNCTION__, func_get_args() );
64    }
65
66    public function endTag( Element $element, $sourceStart, $sourceLength ) {
67        $this->handle( __FUNCTION__, func_get_args() );
68    }
69
70    public function doctype( $name, $public, $system, $quirks, $sourceStart, $sourceLength ) {
71        $this->handle( __FUNCTION__, func_get_args() );
72    }
73
74    public function comment( $preposition, $refElement, $text, $sourceStart, $sourceLength ) {
75        $this->handle( __FUNCTION__, func_get_args() );
76    }
77
78    public function error( $text, $pos ) {
79        $this->handle( __FUNCTION__, func_get_args() );
80    }
81
82    public function mergeAttributes( Element $element, Attributes $attrs, $sourceStart ) {
83        $this->handle( __FUNCTION__, func_get_args() );
84    }
85
86    public function removeNode( Element $element, $sourceStart ) {
87        $this->handle( __FUNCTION__, func_get_args() );
88    }
89
90    public function reparentChildren( Element $element, Element $newParent, $sourceStart ) {
91        $this->handle( __FUNCTION__, func_get_args() );
92    }
93}