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