Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
CRAP
100.00% covered (success)
100.00%
1 / 1
PageEditStashContents
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
3 / 3
3
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 toJsonArray
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 newFromJsonArray
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare( strict_types = 1 );
3/**
4 * @license GPL-2.0-or-later
5 * @file
6 */
7
8namespace MediaWiki\Storage;
9
10use MediaWiki\Content\Content;
11use MediaWiki\Parser\ParserOutput;
12use Wikimedia\JsonCodec\JsonCodecable;
13use Wikimedia\JsonCodec\JsonCodecableTrait;
14
15/**
16 * A simple structured value for stash contents.
17 */
18class PageEditStashContents implements JsonCodecable {
19    use JsonCodecableTrait;
20
21    public function __construct(
22        public readonly Content $pstContent,
23        public readonly ParserOutput $output,
24        /** TS::MW */
25        public readonly string $timestamp,
26        public readonly ?int $edits,
27    ) {
28    }
29
30    public function toJsonArray(): array {
31        return [
32            'pstContent' => $this->pstContent,
33            'output' => $this->output,
34            'timestamp' => $this->timestamp,
35            'edits' => $this->edits,
36        ];
37    }
38
39    public static function newFromJsonArray( array $json ): PageEditStashContents {
40        return new self(
41            pstContent: $json['pstContent'],
42            output: $json['output'],
43            timestamp: $json['timestamp'],
44            edits: $json['edits'] ?? null,
45        );
46    }
47}