original_string: public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess)
      {
          /** @var LanguageDataProvider $dataProvider */
          $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider');
  
          $langToCountry = $dataProvider->getLanguageToCountryList();
  
          if ($enableLanguageToCountryGuess) {
              if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) {
                  // match language (without region) to infer the country of origin
                  if (array_key_exists($matches[1], $langToCountry)) {
                      return $langToCountry[$matches[1]];
                  }
              }
          }
  
          if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) {
              foreach ($matches as $parts) {
                  // match location; we don't make any inferences from the language
                  if (array_key_exists($parts[1], $validCountries)) {
                      return $parts[1];
                  }
              }
          }
          return self::LANGUAGE_CODE_INVALID;
      }
code: public static function extractCountryCodeFromBrowserLanguage($browserLanguage, $validCountries, $enableLanguageToCountryGuess)
      {
          /** @var LanguageDataProvider $dataProvider */
          $dataProvider = StaticContainer::get('Piwik\Intl\Data\Provider\LanguageDataProvider');
  
          $langToCountry = $dataProvider->getLanguageToCountryList();
  
          if ($enableLanguageToCountryGuess) {
              if (preg_match('/^([a-z]{2,3})(?:,|;|$)/', $browserLanguage, $matches)) {
                  // match language (without region) to infer the country of origin
                  if (array_key_exists($matches[1], $langToCountry)) {
                      return $langToCountry[$matches[1]];
                  }
              }
          }
  
          if (!empty($validCountries) && preg_match_all('/[-]([a-z]{2})/', $browserLanguage, $matches, PREG_SET_ORDER)) {
              foreach ($matches as $parts) {
                  // match location; we don't make any inferences from the language
                  if (array_key_exists($parts[1], $validCountries)) {
                      return $parts[1];
                  }
              }
          }
          return self::LANGUAGE_CODE_INVALID;
      }
code_tokens: public static function extractCountryCodeFromBrowserLanguage ( $ browserLanguage , $ validCountries , $ enableLanguageToCountryGuess ) { /** @var LanguageDataProvider $dataProvider */ $ dataProvider = StaticContainer :: get ( 'Piwik\Intl\Data\Provider\LanguageDataProvider' ) ; $ langToCountry = $ dataProvider -> getLanguageToCountryList ( ) ; if ( $ enableLanguageToCountryGuess ) { if ( preg_match ( '/^([a-z]{2,3})(?:,|;|$)/' , $ browserLanguage , $ matches ) ) { // match language (without region) to infer the country of origin if ( array_key_exists ( $ matches [ 1 ] , $ langToCountry ) ) { return $ langToCountry [ $ matches [ 1 ] ] ; } } } if ( ! empty ( $ validCountries ) && preg_match_all ( '/[-]([a-z]{2})/' , $ browserLanguage , $ matches , PREG_SET_ORDER ) ) { foreach ( $ matches as $ parts ) { // match location; we don't make any inferences from the language if ( array_key_exists ( $ parts [ 1 ] , $ validCountries ) ) { return $ parts [ 1 ] ; } } } return self :: LANGUAGE_CODE_INVALID ; }
docstring: Returns list of valid country codes
  
  @param string $browserLanguage
  @param array $validCountries Array of valid countries
  @param bool $enableLanguageToCountryGuess (if true, will guess country based on language that lacks region information)
  @return array Array of 2 letter ISO codes
docstring_tokens: Returns list of valid country codes