Улучшен trait HasInn

* Constraints::PATTERN_INN
* phpdoc
This commit is contained in:
Anthony Axenov 2020-06-07 19:26:33 +08:00
parent 1061914a5f
commit b74f652127

View File

@ -9,6 +9,7 @@
namespace AtolOnline\Traits; namespace AtolOnline\Traits;
use AtolOnline\Constants\Constraints;
use AtolOnline\Exceptions\AtolInnWrongLengthException; use AtolOnline\Exceptions\AtolInnWrongLengthException;
/** /**
@ -39,12 +40,12 @@ trait HasInn
* *
* @param string $inn * @param string $inn
* @return $this * @return $this
* @throws AtolInnWrongLengthException * @throws AtolInnWrongLengthException Некорректная длина ИНН
*/ */
public function setInn(string $inn) public function setInn(string $inn)
{ {
$inn = preg_replace("/[^0-9]/", '', $inn); $inn = preg_replace("/[^0-9]/", '', $inn);
if (preg_match_all("/(^[0-9]{10}$)|(^[0-9]{12}$)/", $inn) == 0) { if (preg_match_all(Constraints::PATTERN_INN, $inn) == 0) {
throw new AtolInnWrongLengthException($inn); throw new AtolInnWrongLengthException($inn);
} }
$this->inn = $inn; $this->inn = $inn;