Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
94.74% |
18 / 19 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
ReplacementValidator | |
94.74% |
18 / 19 |
|
50.00% |
1 / 2 |
5.00 | |
0.00% |
0 / 1 |
__construct | |
83.33% |
5 / 6 |
|
0.00% |
0 / 1 |
3.04 | |||
getIssues | |
100.00% |
13 / 13 |
|
100.00% |
1 / 1 |
2 |
1 | <?php |
2 | declare( strict_types = 1 ); |
3 | |
4 | namespace MediaWiki\Extension\Translate\Validation\Validators; |
5 | |
6 | use InvalidArgumentException; |
7 | use MediaWiki\Extension\Translate\MessageLoading\Message; |
8 | use MediaWiki\Extension\Translate\Validation\MessageValidator; |
9 | use MediaWiki\Extension\Translate\Validation\ValidationIssue; |
10 | use MediaWiki\Extension\Translate\Validation\ValidationIssues; |
11 | |
12 | /** |
13 | * @author Niklas Laxström |
14 | * @license GPL-2.0-or-later |
15 | * @since 2020.07 |
16 | */ |
17 | class ReplacementValidator implements MessageValidator { |
18 | private $search; |
19 | private $replace; |
20 | |
21 | public function __construct( array $params ) { |
22 | $this->search = $params['search'] ?? null; |
23 | $this->replace = $params['replace'] ?? null; |
24 | if ( !is_string( $this->search ) ) { |
25 | throw new InvalidArgumentException( '`search` is not a string' ); |
26 | } |
27 | |
28 | if ( !is_string( $this->replace ) ) { |
29 | throw new InvalidArgumentException( '`replace` is not a string' ); |
30 | } |
31 | } |
32 | |
33 | public function getIssues( Message $message, string $targetLanguage ): ValidationIssues { |
34 | $issues = new ValidationIssues(); |
35 | |
36 | if ( str_contains( $message->translation(), $this->search ) ) { |
37 | $issue = new ValidationIssue( |
38 | 'replacement', |
39 | 'replacement', |
40 | 'translate-checks-replacement', |
41 | [ |
42 | [ 'PLAIN', $this->search ], |
43 | [ 'PLAIN', $this->replace ], |
44 | ] |
45 | ); |
46 | |
47 | $issues->add( $issue ); |
48 | } |
49 | |
50 | return $issues; |
51 | } |
52 | } |