holderName, 'bank_account.holder_name'); self::requireIn($this->holderType, ['individual', 'company'], 'bank_account.holder_type'); self::requireFilled($this->holderDocument, 'bank_account.holder_document'); self::requireFilled($this->bank, 'bank_account.bank'); self::requireFilled($this->branchNumber, 'bank_account.branch_number'); self::requireFilled($this->accountNumber, 'bank_account.account_number'); self::requireFilled($this->accountCheckDigit, 'bank_account.account_check_digit'); self::requireFilled($this->type, 'bank_account.type'); } public static function fromArray(array $payload): self { return new self( holderName: self::normalizeHolderName($payload['holder_name']), holderType: $payload['holder_type'], holderDocument: self::digits($payload['holder_document']), bank: $payload['bank'], branchNumber: $payload['branch_number'], branchCheckDigit: $payload['branch_check_digit'] ?? null, accountNumber: $payload['account_number'], accountCheckDigit: $payload['account_check_digit'], type: $payload['type'], ); } public function toArray(): array { return $this->filterFilledRecursive([ 'bank_account' => [ 'holder_name' => $this->holderName, 'holder_type' => $this->holderType, 'holder_document' => $this->holderDocument, 'bank' => $this->bank, 'branch_number' => $this->branchNumber, 'branch_check_digit' => $this->branchCheckDigit, 'account_number' => $this->accountNumber, 'account_check_digit' => $this->accountCheckDigit, 'type' => $this->type, ], ]); } // private static function normalizeHolderName(string $holderName): string { $holderName = trim(preg_replace('/\s+/', ' ', $holderName) ?? ''); if (Str::length($holderName) < 30) { return $holderName; } $parts = explode(' ', $holderName); if (count($parts) >= 3) { $firstName = array_shift($parts); $lastName = array_pop($parts); $initials = array_map( static fn (string $part): string => Str::upper(Str::substr($part, 0, 1)), $parts ); $abbreviated = trim($firstName.' '.implode(' ', $initials).' '.$lastName); if (Str::length($abbreviated) < 30) { return $abbreviated; } $firstAndLast = trim($firstName.' '.$lastName); if (Str::length($firstAndLast) < 30) { return $firstAndLast; } } return Str::limit($holderName, 29, ''); } }