/** * @param string|SortCode $sortCode * @param string $accountNumber */ public function __construct($sortCode, $accountNumber) { try { if (!$sortCode instanceof SortCode) { Assert::string($sortCode, 'Sort code must be a string or instance of SortCode'); $sortCode = SortCode::create($sortCode); } Assert::string($accountNumber, 'Account number must be a string'); Assert::regex($accountNumber, '{^(?:.*\\d.*){6}$}', 'Account number must contain at least 6 digits'); } catch (\InvalidArgumentException $e) { throw E::wrap($e); } $this->sortCode = $sortCode; $this->accountNumber = preg_replace('{[^0-9]}', '', $accountNumber); }
/** * @param BankAccountInterface $bankAccount * @param string|SortCode $sortCode * @param string $accountNumber */ public function __construct(BankAccountInterface $bankAccount, $sortCode, $accountNumber) { try { if (!$sortCode instanceof SortCode) { Assert::string($sortCode, 'Sort code must be a string or instance of SortCode'); $sortCode = SortCode::create($sortCode); } Assert::string($accountNumber, 'Account number must be a string'); } catch (\InvalidArgumentException $e) { throw E::wrap($e); } $this->bankAccount = $bankAccount; $this->sortCode = $sortCode; $this->accountNumber = preg_replace('{[^0-9]}', '', $accountNumber); if (self::LENGTH !== strlen($this->accountNumber)) { throw Exception\AccountNumberInvalidException::create($accountNumber); } }