Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
Total | |
0.00% |
0 / 1 |
|
66.67% |
2 / 3 |
CRAP | |
92.86% |
13 / 14 |
EntityNamespaces | |
0.00% |
0 / 1 |
|
66.67% |
2 / 3 |
10.04 | |
92.86% |
13 / 14 |
__construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
3 / 3 |
|||
validateMapping | |
0.00% |
0 / 1 |
8.06 | |
90.00% |
9 / 10 |
|||
toArray | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
<?php | |
namespace MediaWiki\Extension\WikibaseManifest; | |
use InvalidArgumentException; | |
class EntityNamespaces { | |
public const NAMESPACE_ID = 'namespace_id'; | |
public const NAMESPACE_NAME = 'namespace_name'; | |
/** | |
* @var array | |
*/ | |
private $mapping; | |
/** | |
* @param array[] $mapping Key entity type, Value array keyed with namespaceId and | |
* namespaceString | |
*/ | |
public function __construct( array $mapping ) { | |
$this->validateMapping( $mapping ); | |
$this->mapping = $mapping; | |
} | |
private function validateMapping( array $mapping ): void { | |
foreach ( $mapping as $k => $v ) { | |
if ( !is_string( $k ) ) { | |
throw new InvalidArgumentException( 'Keys of mapping should be strings' ); | |
} | |
if ( | |
!is_array( $v ) | |
|| !array_key_exists( self::NAMESPACE_ID, $v ) | |
|| !array_key_exists( self::NAMESPACE_NAME, $v ) | |
|| !is_int( $v[self::NAMESPACE_ID] ) | |
|| !is_string( $v[self::NAMESPACE_NAME] ) | |
) { | |
throw new InvalidArgumentException( 'Values of mapping should be arrays with needed keys and correct types' ); | |
} | |
} | |
} | |
public function toArray(): array { | |
return $this->mapping; | |
} | |
} |