/** * @param string * * @return $this * * @throws Exceptions\InvalidArgumentException * @throws IPub\Phone\Exceptions\NoValidCountryException * @throws IPub\Phone\Exceptions\NoValidPhoneException */ public function setValue($value) { if ($value === NULL) { $this->country = NULL; $this->number = NULL; return $this; } foreach ($this->getAllowedCountries() as $country) { if ($this->phoneUtils->isValid($value, $country)) { $phone = IPub\Phone\Entities\Phone::fromNumber($value, $country); $this->country = $phone->getCountry(); $this->number = str_replace(' ', '', $phone->getNationalNumber()); return $this; } } throw new Exceptions\InvalidArgumentException('Provided value is not valid phone number, or is out of list of allowed countries, "' . $value . '" given.'); }