Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| CommentTk | |
0.00% |
0 / 16 |
|
0.00% |
0 / 4 |
30 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| __clone | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| jsonSerialize | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| newFromJsonArray | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare( strict_types = 1 ); |
| 3 | |
| 4 | namespace Wikimedia\Parsoid\Tokens; |
| 5 | |
| 6 | use Wikimedia\Parsoid\NodeData\DataMw; |
| 7 | use Wikimedia\Parsoid\NodeData\DataParsoid; |
| 8 | |
| 9 | /** |
| 10 | * Represents a comment |
| 11 | */ |
| 12 | class CommentTk extends Token { |
| 13 | /** @var string Comment text */ |
| 14 | public $value; |
| 15 | |
| 16 | public function __construct( |
| 17 | string $value, |
| 18 | ?DataParsoid $dataParsoid = null, |
| 19 | ?DataMw $dataMw = null |
| 20 | ) { |
| 21 | // $dataParsoid won't survive in the DOM, but still useful for token serialization |
| 22 | // FIXME: verify if this is still required given that html->wt doesn't |
| 23 | // use tokens anymore. That was circa 2012 serializer code. |
| 24 | parent::__construct( $dataParsoid, $dataMw ); |
| 25 | $this->value = $value; |
| 26 | } |
| 27 | |
| 28 | public function __clone() { |
| 29 | parent::__clone(); |
| 30 | // No new non-primitive properties to clone. |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * @inheritDoc |
| 35 | */ |
| 36 | public function jsonSerialize(): array { |
| 37 | $ret = [ |
| 38 | 'type' => $this->getType(), |
| 39 | 'value' => $this->value, |
| 40 | 'dataParsoid' => $this->dataParsoid, |
| 41 | ]; |
| 42 | if ( $this->dataMw !== null ) { |
| 43 | $ret['dataMw'] = $this->dataMw; |
| 44 | } |
| 45 | return $ret; |
| 46 | } |
| 47 | |
| 48 | /** @inheritDoc */ |
| 49 | public static function newFromJsonArray( array $json ) { |
| 50 | return new self( |
| 51 | $json['value'], |
| 52 | $json['dataParsoid'] ?? null, |
| 53 | $json['dataMw'] ?? null |
| 54 | ); |
| 55 | } |
| 56 | } |