Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RemexMungerData
0.00% covered (danger)
0.00%
0 / 23
0.00% covered (danger)
0.00%
0 / 2
132
0.00% covered (danger)
0.00%
0 / 1
 __set
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 dump
0.00% covered (danger)
0.00%
0 / 22
0.00% covered (danger)
0.00%
0 / 1
110
1<?php
2
3namespace MediaWiki\Tidy;
4
5use InvalidArgumentException;
6use Wikimedia\RemexHtml\Serializer\SerializerNode;
7use Wikimedia\RemexHtml\TreeBuilder\Element;
8
9/**
10 * @internal
11 */
12class RemexMungerData {
13    /**
14     * The Element for the mw:p-wrap which is a child of the current node. If
15     * this is set, inline insertions into this node will be diverted so that
16     * they insert into the p-wrap.
17     *
18     * @var Element|null
19     */
20    public $childPElement;
21
22    /**
23     * This tracks the mw:p-wrap node in the Serializer stack which is an
24     * ancestor of this node. If there is no mw:p-wrap ancestor, it is null.
25     *
26     * @var SerializerNode|null
27     */
28    public $ancestorPNode;
29
30    /**
31     * The wrap base node is the body or blockquote node which is the parent
32     * of active p-wrappers. This is set if there is an ancestor p-wrapper,
33     * or if a p-wrapper was closed due to a block element being encountered
34     * inside it.
35     *
36     * @var SerializerNode|null
37     */
38    public $wrapBaseNode;
39
40    /**
41     * Stack splitting (essentially our idea of AFE reconstruction) can clone
42     * formatting elements which are split over multiple paragraphs.
43     * TreeBuilder is not aware of the cloning, and continues to insert into
44     * the original element. This is set to the newer clone if this node was
45     * cloned, i.e. if there is an active diversion of the insertion location.
46     *
47     * @var Element|null
48     */
49    public $currentCloneElement;
50
51    /**
52     * Is the node a p-wrapper, with name mw:p-wrap?
53     *
54     * @var bool
55     */
56    public $isPWrapper = false;
57
58    /**
59     * Is the node splittable, i.e. a formatting element or a node with a
60     * formatting element ancestor which is under an active or deactivated
61     * p-wrapper.
62     *
63     * @var bool
64     */
65    public $isSplittable = false;
66
67    /**
68     * This is true if the node is a body or blockquote, which activates
69     * p-wrapping of child nodes.
70     */
71    public $needsPWrapping = false;
72
73    /**
74     * The number of child nodes, not counting whitespace-only text nodes or
75     * comments.
76     */
77    public $nonblankNodeCount = 0;
78
79    public function __set( $name, $value ) {
80        // @phan-suppress-previous-line PhanPluginNeverReturnMethod
81        throw new InvalidArgumentException( "Cannot set property \"$name\"" );
82    }
83
84    /**
85     * Get a text representation of the current state of the serializer, for
86     * debugging.
87     *
88     * @return string
89     */
90    public function dump() {
91        $parts = [];
92
93        if ( $this->childPElement ) {
94            $parts[] = 'childPElement=' . $this->childPElement->getDebugTag();
95        }
96        if ( $this->ancestorPNode ) {
97            $parts[] = "ancestorPNode=<{$this->ancestorPNode->name}>";
98        }
99        if ( $this->wrapBaseNode ) {
100            $parts[] = "wrapBaseNode=<{$this->wrapBaseNode->name}>";
101        }
102        if ( $this->currentCloneElement ) {
103            $parts[] = "currentCloneElement=" . $this->currentCloneElement->getDebugTag();
104        }
105        if ( $this->isPWrapper ) {
106            $parts[] = 'isPWrapper';
107        }
108        if ( $this->isSplittable ) {
109            $parts[] = 'isSplittable';
110        }
111        if ( $this->needsPWrapping ) {
112            $parts[] = 'needsPWrapping';
113        }
114        if ( $this->nonblankNodeCount ) {
115            $parts[] = "nonblankNodeCount={$this->nonblankNodeCount}";
116        }
117        $s = "RemexMungerData {\n";
118        foreach ( $parts as $part ) {
119            $s .= "  $part\n";
120        }
121        $s .= "}\n";
122        return $s;
123    }
124}