Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| NlTk | |
0.00% |
0 / 15 |
|
0.00% |
0 / 3 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
12 | |||
| jsonSerialize | |
0.00% |
0 / 7 |
|
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 | * Newline token. |
| 11 | */ |
| 12 | class NlTk extends Token { |
| 13 | /** |
| 14 | * @param ?SourceRange $tsr |
| 15 | * TSR ("tag source range") represents the (start, end) wikitext |
| 16 | * byte offsets for a token (in this case, the newline) in the |
| 17 | * UTF8-encoded source string |
| 18 | * @param ?DataParsoid $dataParsoid |
| 19 | * @param ?DataMw $dataMw |
| 20 | */ |
| 21 | public function __construct( |
| 22 | ?SourceRange $tsr, |
| 23 | ?DataParsoid $dataParsoid = null, |
| 24 | ?DataMw $dataMw = null |
| 25 | ) { |
| 26 | parent::__construct( $dataParsoid, $dataMw ); |
| 27 | if ( $dataParsoid == null && $tsr !== null ) { |
| 28 | $this->dataParsoid->tsr = $tsr; |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * @inheritDoc |
| 34 | */ |
| 35 | public function jsonSerialize(): array { |
| 36 | $ret = [ |
| 37 | 'type' => $this->getType(), |
| 38 | 'dataParsoid' => $this->dataParsoid, |
| 39 | ]; |
| 40 | if ( $this->dataMw !== null ) { |
| 41 | $ret['dataMw'] = $this->dataMw; |
| 42 | } |
| 43 | return $ret; |
| 44 | } |
| 45 | |
| 46 | /** @inheritDoc */ |
| 47 | public static function newFromJsonArray( array $json ) { |
| 48 | return new self( |
| 49 | null, |
| 50 | $json['dataParsoid'] ?? null, |
| 51 | $json['dataMw'] ?? null |
| 52 | ); |
| 53 | } |
| 54 | } |