Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 6
CRAP
0.00% covered (danger)
0.00%
0 / 1
DataMwBody
0.00% covered (danger)
0.00%
0 / 19
0.00% covered (danger)
0.00%
0 / 6
90
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
 new
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
2
 __clone
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 equals
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 toJsonArray
0.00% covered (danger)
0.00%
0 / 8
0.00% covered (danger)
0.00%
0 / 1
20
 newFromJsonArray
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\NodeData;
5
6use Wikimedia\JsonCodec\JsonCodecable;
7use Wikimedia\JsonCodec\JsonCodecableTrait;
8
9/**
10 * Information about the body of an extension tag.
11 */
12class DataMwBody implements JsonCodecable {
13    use JsonCodecableTrait;
14
15    /**
16     * The original source string for this extension tag.
17     */
18    public ?string $extsrc;
19
20    /**
21     * Embedded HTML for the contents of this tag.
22     */
23    public ?string $html;
24
25    /**
26     * Used by the Cite extension.
27     */
28    public ?string $id;
29
30    public function __construct( ?string $extsrc = null, ?string $html = null, ?string $id = null ) {
31        $this->extsrc = $extsrc;
32        $this->html = $html;
33        $this->id = $id;
34    }
35
36    /**
37     * Transitional helper method to initialize a new value appropriate for DataMw::$body.
38     */
39    public static function new( array $values ): DataMwBody {
40        return new DataMwBody(
41            $values['extsrc'] ?? null,
42            $values['html'] ?? null,
43            $values['id'] ?? null,
44        );
45    }
46
47    /**
48     * @suppress PhanEmptyPublicMethod
49     */
50    public function __clone() {
51        // Shallow clone is sufficient.
52    }
53
54    public function equals( DataMwBody $other ): bool {
55        // Use non-strict equality test, which will compare the properties
56        // @phan-suppress-next-line PhanPluginComparisonObjectEqualityNotStrict
57        return $this == $other;
58    }
59
60    /** @inheritDoc */
61    public function toJsonArray(): array {
62        $result = [];
63        if ( $this->extsrc !== null ) {
64            $result['extsrc'] = $this->extsrc;
65        }
66        if ( $this->id !== null ) {
67            $result['id'] = $this->id;
68        }
69        if ( $this->html !== null ) {
70            $result['html'] = $this->html;
71        }
72        return $result;
73    }
74
75    /** @inheritDoc */
76    public static function newFromJsonArray( array $json ): DataMwBody {
77        return new DataMwBody( $json['extsrc'] ?? null, $json['html'] ?? null, $json['id'] ?? null );
78    }
79}