Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
ParamInfo | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
56 | |
0.00% |
0 / 1 |
__construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
__clone | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
newFromJsonArray | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
toJsonArray | |
0.00% |
0 / 6 |
|
0.00% |
0 / 1 |
12 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace Wikimedia\Parsoid\NodeData; |
5 | |
6 | use Wikimedia\JsonCodec\JsonCodecable; |
7 | use Wikimedia\JsonCodec\JsonCodecableTrait; |
8 | use Wikimedia\Parsoid\Tokens\KVSourceRange; |
9 | |
10 | class ParamInfo implements JsonCodecable { |
11 | use JsonCodecableTrait; |
12 | |
13 | /** |
14 | * The parameter key |
15 | */ |
16 | public string $k; |
17 | |
18 | /** |
19 | * The key source wikitext, if different from $k |
20 | */ |
21 | public ?string $keyWt = null; |
22 | |
23 | /** |
24 | * The parameter value source wikitext |
25 | */ |
26 | public ?string $valueWt = null; |
27 | |
28 | public ?KVSourceRange $srcOffsets = null; |
29 | |
30 | public bool $named = false; |
31 | |
32 | /** |
33 | * @var string[]|null |
34 | */ |
35 | public ?array $spc = null; |
36 | |
37 | public ?string $html = null; |
38 | |
39 | public function __construct( string $key, ?KVSourceRange $srcOffsets = null ) { |
40 | $this->k = $key; |
41 | $this->srcOffsets = $srcOffsets; |
42 | } |
43 | |
44 | public function __clone() { |
45 | if ( $this->srcOffsets !== null ) { |
46 | $this->srcOffsets = clone $this->srcOffsets; |
47 | } |
48 | } |
49 | |
50 | /** |
51 | * Create an object from unserialized data-parsoid.pi |
52 | * @param array $data |
53 | * @return self |
54 | */ |
55 | public static function newFromJsonArray( array $data ): ParamInfo { |
56 | $info = new self( $data['k'] ?? '' ); |
57 | $info->named = $data['named'] ?? false; |
58 | $info->spc = $data['spc'] ?? null; |
59 | return $info; |
60 | } |
61 | |
62 | /** |
63 | * Serialize for data-parsoid.pi. The rest of the data is temporary, it is |
64 | * not needed across requests. |
65 | * |
66 | * @return array |
67 | */ |
68 | public function toJsonArray(): array { |
69 | $ret = [ 'k' => $this->k ]; |
70 | if ( $this->named ) { |
71 | $ret['named'] = true; |
72 | } |
73 | if ( $this->spc ) { |
74 | $ret['spc'] = $this->spc; |
75 | } |
76 | return $ret; |
77 | } |
78 | } |