ItemTranslator: throw the proper exceptions when failing to map network IDs

This commit is contained in:
Dylan K. Taylor 2021-10-20 14:01:39 +01:00
parent a3f8546ac4
commit 80b402e529
No known key found for this signature in database
GPG Key ID: 8927471A91CAFD3D

View File

@ -175,11 +175,12 @@ final class ItemTranslator{
/**
* @return int[]
* @phpstan-return array{int, int}
* @throws TypeConversionException
*/
public function fromNetworkId(int $networkId, int $networkMeta, ?bool &$isComplexMapping = null) : array{
if(isset($this->complexNetToCoreMapping[$networkId])){
if($networkMeta !== 0){
throw new \UnexpectedValueException("Unexpected non-zero network meta on complex item mapping");
throw new TypeConversionException("Unexpected non-zero network meta on complex item mapping");
}
$isComplexMapping = true;
return $this->complexNetToCoreMapping[$networkId];
@ -188,12 +189,13 @@ final class ItemTranslator{
if(isset($this->simpleNetToCoreMapping[$networkId])){
return [$this->simpleNetToCoreMapping[$networkId], $networkMeta];
}
throw new \UnexpectedValueException("Unmapped network ID/metadata combination $networkId:$networkMeta");
throw new TypeConversionException("Unmapped network ID/metadata combination $networkId:$networkMeta");
}
/**
* @return int[]
* @phpstan-return array{int, int}
* @throws TypeConversionException
*/
public function fromNetworkIdWithWildcardHandling(int $networkId, int $networkMeta) : array{
$isComplexMapping = false;