Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
90.48% |
19 / 21 |
|
83.33% |
10 / 12 |
CRAP | |
0.00% |
0 / 1 |
MessageUpdateParameter | |
90.48% |
19 / 21 |
|
83.33% |
10 / 12 |
14.17 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getPageName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isRename | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getReplacementValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getTargetValue | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getContent | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
isFuzzy | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getOtherLangs | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
newFromJsonArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
toJsonArray | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
assignPropsFromArray | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
createFromJob | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Synchronization; |
5 | |
6 | use JsonSerializable; |
7 | use MediaWiki\Json\JsonUnserializable; |
8 | use MediaWiki\Json\JsonUnserializableTrait; |
9 | use MediaWiki\Json\JsonUnserializer; |
10 | use MessageUpdateJob; |
11 | |
12 | /** |
13 | * Store params for MessageUpdateJob. |
14 | * @author Abijeet Patro |
15 | * @license GPL-2.0-or-later |
16 | * @since 2020.06 |
17 | */ |
18 | class MessageUpdateParameter implements JsonSerializable, JsonUnserializable { |
19 | use JsonUnserializableTrait; |
20 | |
21 | /** @var string */ |
22 | private $pageName; |
23 | /** @var bool */ |
24 | private $rename; |
25 | /** @var bool */ |
26 | private $fuzzy; |
27 | /** @var string */ |
28 | private $content; |
29 | /** @var string */ |
30 | private $target; |
31 | /** @var string */ |
32 | private $replacement; |
33 | /** @var array|null */ |
34 | private $otherLangs; |
35 | |
36 | public function __construct( array $params ) { |
37 | $this->assignPropsFromArray( $params ); |
38 | } |
39 | |
40 | public function getPageName(): string { |
41 | return $this->pageName; |
42 | } |
43 | |
44 | public function isRename(): bool { |
45 | return $this->rename; |
46 | } |
47 | |
48 | public function getReplacementValue(): string { |
49 | return $this->replacement; |
50 | } |
51 | |
52 | public function getTargetValue(): string { |
53 | return $this->target; |
54 | } |
55 | |
56 | public function getContent(): string { |
57 | return $this->content; |
58 | } |
59 | |
60 | public function isFuzzy(): bool { |
61 | return $this->fuzzy; |
62 | } |
63 | |
64 | public function getOtherLangs(): ?array { |
65 | return $this->otherLangs; |
66 | } |
67 | |
68 | public static function newFromJsonArray( JsonUnserializer $unserializer, array $params ) { |
69 | return new self( $params ); |
70 | } |
71 | |
72 | /** @return mixed[] */ |
73 | protected function toJsonArray(): array { |
74 | return get_object_vars( $this ); |
75 | } |
76 | |
77 | private function assignPropsFromArray( array $params ) { |
78 | // We are using "rename" as value for $params['rename'] |
79 | // at some places otherwise this could be simplified to |
80 | // $params['rename'] ?? false |
81 | $this->rename = isset( $params['rename'] ) && $params['rename']; |
82 | $this->fuzzy = $params['fuzzy']; |
83 | $this->content = $params['content']; |
84 | $this->pageName = $params['title'] ?? $params['pageName']; |
85 | |
86 | if ( $this->rename ) { |
87 | $this->target = $params['target']; |
88 | $this->replacement = $params['replacement']; |
89 | $this->otherLangs = $params['otherLangs'] ?? []; |
90 | } |
91 | } |
92 | |
93 | /** Create a new instance of the class from MessageUpdateJob */ |
94 | public static function createFromJob( MessageUpdateJob $job ): self { |
95 | $jobParams = $job->getParams(); |
96 | $jobParams['title'] = $job->getTitle()->getPrefixedDBkey(); |
97 | return new self( $jobParams ); |
98 | } |
99 | } |