/** * Note in some regions, the national number can be written in two completely different ways * depending on whether it forms part of the NATIONAL format or INTERNATIONAL format. The * numberFormat parameter here is used to specify which format to use for those cases. If a * carrierCode is specified, this will be inserted into the formatted string to replace $CC. * @param string $number * @param PhoneMetadata $metadata * @param int $numberFormat PhoneNumberFormat * @param null|string $carrierCode * @return string */ private function formatNsn($number, PhoneMetadata $metadata, $numberFormat, $carrierCode = null) { $intlNumberFormats = $metadata->intlNumberFormats(); // When the intlNumberFormats exists, we use that to format national number for the // INTERNATIONAL format instead of using the numberDesc.numberFormats. $availableFormats = count($intlNumberFormats) == 0 || $numberFormat == PhoneNumberFormat::NATIONAL ? $metadata->numberFormats() : $metadata->intlNumberFormats(); $formattingPattern = $this->chooseFormattingPatternForNumber($availableFormats, $number); return $formattingPattern === null ? $number : $this->formatNsnUsingPattern($number, $formattingPattern, $numberFormat, $carrierCode); }