@@ -169,6 +169,13 @@ class PhoneNumberUtil
169169 86 , // China
170170 ];
171171
172+ /**
173+ * Set of country codes that doesn't have national prefix, but it has area codes.
174+ */
175+ protected const COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES = [
176+ 52 , // Mexico
177+ ];
178+
172179 /**
173180 * Set of country calling codes that have geographically assigned mobile numbers. This may not be
174181 * complete; we add calling codes case by case, as we find geographical mobile numbers or hear
@@ -787,20 +794,25 @@ public function getLengthOfGeographicalAreaCode(PhoneNumber $number): int
787794 if ($ metadata === null ) {
788795 return 0 ;
789796 }
797+
798+ $ countryCallingCode = $ number ->getCountryCode ();
799+
800+
790801 // If a country doesn't use a national prefix, and this number doesn't have an Italian leading
791802 // zero, we assume it is a closed dialling plan with no area codes.
792- if (!$ metadata ->hasNationalPrefix () && !$ number ->isItalianLeadingZero ()) {
803+ // Note:this is our general assumption, but there are exceptions which are tracked in
804+ // COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES.
805+ if (!$ metadata ->hasNationalPrefix () && !$ number ->isItalianLeadingZero () && !in_array ($ countryCallingCode , static ::COUNTRIES_WITHOUT_NATIONAL_PREFIX_WITH_AREA_CODES )) {
793806 return 0 ;
794807 }
795808
796809 $ type = $ this ->getNumberType ($ number );
797- $ countryCallingCode = $ number ->getCountryCode ();
798810
799811 if ($ type === PhoneNumberType::MOBILE
800812 // Note this is a rough heuristic; it doesn't cover Indonesia well, for example, where area
801813 // codes are present for some mobile phones but not for others. We have no better way of
802814 // representing this in the metadata at this point.
803- && in_array ($ countryCallingCode , self ::GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES )
815+ && in_array ($ countryCallingCode , static ::GEO_MOBILE_COUNTRIES_WITHOUT_MOBILE_AREA_CODES )
804816 ) {
805817 return 0 ;
806818 }
0 commit comments