Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
EquivEntities | |
100.00% |
13 / 13 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
validateMapping | |
100.00% |
10 / 10 |
|
100.00% |
1 / 1 |
6 | |||
toArray | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace MediaWiki\Extension\WikibaseManifest; |
4 | |
5 | use InvalidArgumentException; |
6 | |
7 | class EquivEntities { |
8 | |
9 | /** |
10 | * @var array |
11 | */ |
12 | private $mapping; |
13 | |
14 | /** |
15 | * @param string[] $mapping |
16 | */ |
17 | public function __construct( array $mapping ) { |
18 | $this->validateMapping( $mapping ); |
19 | $this->mapping = $mapping; |
20 | } |
21 | |
22 | private function validateMapping( array $mapping ): void { |
23 | foreach ( $mapping as $value ) { |
24 | if ( !is_array( $value ) ) { |
25 | throw new InvalidArgumentException( |
26 | 'Equivalent entities mappings should be grouped in arrays, e.g. "properties": [ "P31": "P1" ]' |
27 | ); |
28 | } |
29 | foreach ( $value as $remote => $local ) { |
30 | if ( !is_string( $remote ) ) { |
31 | throw new InvalidArgumentException( 'Keys of mapping should be strings' ); |
32 | } |
33 | if ( !is_string( $local ) ) { |
34 | throw new InvalidArgumentException( 'Values of mapping should be strings' ); |
35 | } |
36 | } |
37 | } |
38 | } |
39 | |
40 | public function toArray(): array { |
41 | return $this->mapping; |
42 | } |
43 | |
44 | } |