protected function filterValidCountry($countries)
    {
        $result = Collection::make($countries)
                            ->filter(function ($country) {
                                try {
                                    $instance = $this->lib->parse($this->number, $country);

                                    return $this->lenient
                                        ? $this->lib->isPossibleNumber($instance, $country)
                                        : $this->lib->isValidNumberForRegion($instance, $country);
                                } catch (libNumberParseException $e) {
                                    return false;
                                }
                            })->first();

        // If we got a new result, return it.
        if ($result) {
            return $result;
        }

        // Last resort: try to detect it from an international number.
        if ($this->numberLooksInternational()) {
            $countries[] = null;
        }

        foreach ($countries as $country) {
            $instance = $this->lib->parse($this->number, $country);

            if ($this->lib->isValidNumber($instance)) {
                return $this->lib->getRegionCodeForNumber($instance);
            }
        }

        if ($countries = array_filter($countries)) {
            throw NumberParseException::countryMismatch($this->number, $countries);
        }

        throw NumberParseException::countryRequired($this->number);
    }
protected function filterValidCountry($countries)
    {
        $result = Collection::make($countries)
                            ->filter(function ($country) {
                                try {
                                    $instance = $this->lib->parse($this->number, $country);

                                    return $this->lenient
                                        ? $this->lib->isPossibleNumber($instance, $country)
                                        : $this->lib->isValidNumberForRegion($instance, $country);
                                } catch (libNumberParseException $e) {
                                    return false;
                                }
                            })->first();

        // If we got a new result, return it.
        if ($result) {
            return $result;
        }

        // Last resort: try to detect it from an international number.
        if ($this->numberLooksInternational()) {
            $countries[] = null;
        }

        foreach ($countries as $country) {
            $instance = $this->lib->parse($this->number, $country);

            if ($this->lib->isValidNumber($instance)) {
                return $this->lib->getRegionCodeForNumber($instance);
            }
        }

        if ($countries = array_filter($countries)) {
            throw NumberParseException::countryMismatch($this->number, $countries);
        }

        throw NumberParseException::countryRequired($this->number);
    }
protected function filterValidCountry ( $ countries ) { $ result = Collection :: make ( $ countries ) -> filter ( function ( $ country ) { try { $ instance = $ this -> lib -> parse ( $ this -> number , $ country ) ; return $ this -> lenient ? $ this -> lib -> isPossibleNumber ( $ instance , $ country ) : $ this -> lib -> isValidNumberForRegion ( $ instance , $ country ) ; } catch ( libNumberParseException $ e ) { return false ; } } ) -> first ( ) ; // If we got a new result, return it. if ( $ result ) { return $ result ; } // Last resort: try to detect it from an international number. if ( $ this -> numberLooksInternational ( ) ) { $ countries [ ] = null ; } foreach ( $ countries as $ country ) { $ instance = $ this -> lib -> parse ( $ this -> number , $ country ) ; if ( $ this -> lib -> isValidNumber ( $ instance ) ) { return $ this -> lib -> getRegionCodeForNumber ( $ instance ) ; } } if ( $ countries = array_filter ( $ countries ) ) { throw NumberParseException :: countryMismatch ( $ this -> number , $ countries ) ; } throw NumberParseException :: countryRequired ( $ this -> number ) ; }
Filter the provided countries to the one that is valid for the number.

@param string|array $countries
@return string
@throws \Propaganistas\LaravelPhone\Exceptions\NumberParseException
Filter the provided countries to the one that is valid for the number .