Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
87.50% covered (warning)
87.50%
7 / 8
CRAP
0.00% covered (danger)
0.00%
0 / 1
TranslatablePageMarkOperation
92.31% covered (success)
92.31%
12 / 13
87.50% covered (warning)
87.50%
7 / 8
8.03
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
1
 getPage
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getParserOutput
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUnits
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getDeletedUnits
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 isFirstMark
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 isValid
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getUnitValidationStatus
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
1<?php
2declare( strict_types = 1 );
3
4namespace MediaWiki\Extension\Translate\PageTranslation;
5
6use Status;
7
8/**
9 * This class encapsulates the information / state needed to mark a page for translation
10 * @since 2023.10
11 */
12class TranslatablePageMarkOperation {
13    /** @var TranslationUnit[] */
14    private array $units;
15    /** @var TranslationUnit[] */
16    private array $deletedUnits;
17    private ParserOutput $parserOutput;
18    private TranslatablePage $page;
19    private bool $firstMark;
20    private Status $unitValidationStatus;
21
22    public function __construct(
23        TranslatablePage $page,
24        ParserOutput $parserOutput,
25        array $units,
26        array $deletedUnits,
27        bool $firstMark,
28        Status $unitValidationStatus
29    ) {
30        $this->page = $page;
31        $this->parserOutput = $parserOutput;
32        $this->units = $units;
33        $this->deletedUnits = $deletedUnits;
34        $this->firstMark = $firstMark;
35        $this->unitValidationStatus = $unitValidationStatus;
36    }
37
38    public function getPage(): TranslatablePage {
39        return $this->page;
40    }
41
42    /** Get the result of the parse */
43    public function getParserOutput(): ParserOutput {
44        return $this->parserOutput;
45    }
46
47    /**
48     * Get translation units present in the parsed text
49     * @return TranslationUnit[]
50     */
51    public function getUnits(): array {
52        return $this->units;
53    }
54
55    /**
56     * Get translation units present in the previously marked text, but
57     * not in the parsed one
58     * @return TranslationUnit[]
59     */
60    public function getDeletedUnits(): array {
61        return $this->deletedUnits;
62    }
63
64    /** Whether the page has not been marked for translation before */
65    public function isFirstMark(): bool {
66        return $this->firstMark;
67    }
68
69    /** Whether the operation is valid */
70    public function isValid(): bool {
71        return $this->unitValidationStatus->isOK();
72    }
73
74    /** Get the status of the unit validation */
75    public function getUnitValidationStatus(): Status {
76        return $this->unitValidationStatus;
77    }
78}