Code review comment: maybe here we should access directly `identifier.getPhoneNumber().getValue()` as the value is used in both places

Code before review:
public static CommunicationIdentifier convert(CommunicationIdentifierModel identifier) {
if (identifier == null) {
return null;
}
assertSingleType(identifier);
String rawId = identifier.getRawId();
CommunicationIdentifierModelKind kind = identifier.getKind();
if (kind != null) {
if (kind == CommunicationIdentifierModelKind.COMMUNICATION_USER
&& identifier.getCommunicationUser() != null) {
Objects.requireNonNull(identifier.getCommunicationUser().getId());
return new CommunicationUserIdentifier(identifier.getCommunicationUser().getId());
}
if (kind == CommunicationIdentifierModelKind.PHONE_NUMBER
&& identifier.getPhoneNumber() != null) {
PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();
Objects.requireNonNull(phoneNumberModel.getValue());
return new PhoneNumberIdentifier(phoneNumberModel.getValue()).setRawId(rawId);
}
if (kind == CommunicationIdentifierModelKind.MICROSOFT_TEAMS_USER
&& identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
Objects.requireNonNull(teamsUserIdentifierModel.getUserId());
Objects.requireNonNull(teamsUserIdentifierModel.getCloud());
Objects.requireNonNull(rawId);
return new MicrosoftTeamsUserIdentifier(teamsUserIdentifierModel.getUserId(),
teamsUserIdentifierModel.isAnonymous())
.setRawId(rawId)
.setCloudEnvironment(CommunicationCloudEnvironment
.fromString(teamsUserIdentifierModel.getCloud().toString()));
}
Objects.requireNonNull(rawId);
return new UnknownIdentifier(rawId);
}
if (identifier.getCommunicationUser() != null) {
Objects.requireNonNull(identifier.getCommunicationUser().getId());
return new CommunicationUserIdentifier(identifier.getCommunicationUser().getId());
}
if (identifier.getPhoneNumber() != null) {
PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();
Objects.requireNonNull(phoneNumberModel.getValue());
return new PhoneNumberIdentifier(phoneNumberModel.getValue()).setRawId(rawId);
}
if (identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
Objects.requireNonNull(teamsUserIdentifierModel.getUserId());
Objects.requireNonNull(teamsUserIdentifierModel.getCloud());
Objects.requireNonNull(rawId);
return new MicrosoftTeamsUserIdentifier(teamsUserIdentifierModel.getUserId(),
teamsUserIdentifierModel.isAnonymous())
.setRawId(rawId)
.setCloudEnvironment(CommunicationCloudEnvironment
.fromString(teamsUserIdentifierModel.getCloud().toString()));
}
Objects.requireNonNull(rawId);
return new UnknownIdentifier(rawId);
}

Line under review: PhoneNumberIdentifierModel phoneNumberModel = identifier.getPhoneNumber();

Code after addressing the review:
public static CommunicationIdentifier convert(CommunicationIdentifierModel identifier) {
if (identifier == null) {
return null;
}
assertSingleType(identifier);
String rawId = identifier.getRawId();
CommunicationIdentifierModelKind kind = (identifier.getKind() != null) ? identifier.getKind() : extractKind(identifier);
if (kind == CommunicationIdentifierModelKind.COMMUNICATION_USER
&& identifier.getCommunicationUser() != null) {
Objects.requireNonNull(identifier.getCommunicationUser().getId(),
"'ID' of the CommunicationIdentifierModel cannot be null.");
return new CommunicationUserIdentifier(identifier.getCommunicationUser().getId());
}
if (kind == CommunicationIdentifierModelKind.PHONE_NUMBER
&& identifier.getPhoneNumber() != null) {
String phoneNumber = identifier.getPhoneNumber().getValue();
Objects.requireNonNull(phoneNumber, "'PhoneNumber' of the CommunicationIdentifierModel cannot be null.");
Objects.requireNonNull(rawId, "'RawID' of the CommunicationIdentifierModel cannot be null.");
return new PhoneNumberIdentifier(phoneNumber).setRawId(rawId);
}
if (kind == CommunicationIdentifierModelKind.MICROSOFT_TEAMS_USER
&& identifier.getMicrosoftTeamsUser() != null) {
MicrosoftTeamsUserIdentifierModel teamsUserIdentifierModel = identifier.getMicrosoftTeamsUser();
Objects.requireNonNull(teamsUserIdentifierModel.getUserId(), "'UserID' of the CommunicationIdentifierModel cannot be null.");
Objects.requireNonNull(teamsUserIdentifierModel.getCloud(), "'Cloud' of the CommunicationIdentifierModel cannot be null.");
Objects.requireNonNull(rawId, "'RawID' of the CommunicationIdentifierModel cannot be null.");
return new MicrosoftTeamsUserIdentifier(teamsUserIdentifierModel.getUserId(),
teamsUserIdentifierModel.isAnonymous())
.setRawId(rawId)
.setCloudEnvironment(CommunicationCloudEnvironment
.fromString(teamsUserIdentifierModel.getCloud().toString()));
}
Objects.requireNonNull(rawId, "'RawID' of the CommunicationIdentifierModel cannot be null.");
return new UnknownIdentifier(rawId);
}