Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 4
CRAP
0.00% covered (danger)
0.00%
0 / 1
DataMwAttrib
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 4
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 jsonClassHintFor
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 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 newFromJsonArray
0.00% covered (danger)
0.00%
0 / 5
0.00% covered (danger)
0.00%
0 / 1
6
1<?php
2declare( strict_types = 1 );
3
4namespace Wikimedia\Parsoid\NodeData;
5
6use Wikimedia\Assert\Assert;
7use Wikimedia\JsonCodec\JsonCodecable;
8use Wikimedia\JsonCodec\JsonCodecableTrait;
9
10/**
11 * Rich attribute data for a DOM Element.  Both the key and the value
12 * can be strings or more complex values.
13 */
14class DataMwAttrib implements JsonCodecable {
15    use JsonCodecableTrait;
16
17    /**
18     * The attribute name.
19     * @var array{txt?:string,html?:string}|string
20     */
21    public $key;
22
23    /**
24     * The attribute value.
25     * @var array|string
26     */
27    public $value;
28
29    /**
30     * @param array{txt?:string,html?:string}|string $key Attribute name
31     * @param array|string $value Attribute value
32     */
33    public function __construct( $key, $value ) {
34        $this->key = $key;
35        $this->value = $value;
36    }
37
38    /** @inheritDoc */
39    public static function jsonClassHintFor( string $keyname ) {
40        // No hints necessary, both $key and $value are arrays
41        return null;
42    }
43
44    /** @inheritDoc */
45    public function toJsonArray(): array {
46        return [ $this->key, $this->value ];
47    }
48
49    /** @inheritDoc */
50    public static function newFromJsonArray( array $json ): DataMwAttrib {
51        Assert::invariant(
52            array_is_list( $json ) && count( $json ) === 2,
53            "bad data-mw.attrib"
54        );
55        return new DataMwAttrib( $json[0], $json[1] );
56    }
57}