Повсюду улучшена проверка длин строк

This commit is contained in:
Anthony Axenov 2020-05-28 22:56:26 +08:00
parent 9ea1c81666
commit ca32fe5923
5 changed files with 7 additions and 7 deletions

View File

@ -118,7 +118,7 @@ class Kkt extends Client
if (!$this->isTestMode()) { if (!$this->isTestMode()) {
if (empty($login)) { if (empty($login)) {
throw new AtolKktLoginEmptyException(); throw new AtolKktLoginEmptyException();
} elseif (strlen($login) > 100) { } elseif ((function_exists('mb_strlen') ? mb_strlen($login) : strlen($login)) > 100) {
throw new AtolKktLoginTooLongException($login, 100); throw new AtolKktLoginTooLongException($login, 100);
} }
} }

View File

@ -89,7 +89,7 @@ class Client extends Entity
public function setName(string $name) public function setName(string $name)
{ {
$name = trim($name); $name = trim($name);
if (strlen($name) > 256) { if ((function_exists('mb_strlen') ? mb_strlen($name) : strlen($name)) > 256) {
throw new AtolNameTooLongException($name, 256); throw new AtolNameTooLongException($name, 256);
} }
$this->name = $name; $this->name = $name;
@ -119,7 +119,7 @@ class Client extends Entity
public function setPhone(string $phone) public function setPhone(string $phone)
{ {
$phone = preg_replace("/[^0-9+]/", '', $phone); $phone = preg_replace("/[^0-9+]/", '', $phone);
if (strlen($phone) > 64) { if ((function_exists('mb_strlen') ? mb_strlen($phone) : strlen($phone)) > 64) {
throw new AtolPhoneTooLongException($phone, 64); throw new AtolPhoneTooLongException($phone, 64);
} }
$this->phone = $phone; $this->phone = $phone;

View File

@ -115,7 +115,7 @@ class Company extends Entity
public function setPaymentAddress(string $payment_address) public function setPaymentAddress(string $payment_address)
{ {
$payment_address = trim($payment_address); $payment_address = trim($payment_address);
if (strlen($payment_address) > 256) { if ((function_exists('mb_strlen') ? mb_strlen($payment_address) : strlen($payment_address)) > 256) {
throw new AtolPaymentAddressTooLongException($payment_address, 256); throw new AtolPaymentAddressTooLongException($payment_address, 256);
} }
$this->payment_address = $payment_address; $this->payment_address = $payment_address;

View File

@ -137,7 +137,7 @@ class Item extends Entity
public function setName(string $name) public function setName(string $name)
{ {
$name = trim($name); $name = trim($name);
if (strlen($name) > 128) { if ((function_exists('mb_strlen') ? mb_strlen($name) : strlen($name)) > 128) {
throw new AtolNameTooLongException($name, 128); throw new AtolNameTooLongException($name, 128);
} }
$this->name = $name; $this->name = $name;
@ -328,7 +328,7 @@ class Item extends Entity
public function setUserData(string $user_data) public function setUserData(string $user_data)
{ {
$user_data = trim($user_data); $user_data = trim($user_data);
if (strlen($user_data) > 64) { if ((function_exists('mb_strlen') ? mb_strlen($user_data) : strlen($user_data)) > 64) {
throw new AtolUserdataTooLongException($user_data, 64); throw new AtolUserdataTooLongException($user_data, 64);
} }
$this->user_data = $user_data; $this->user_data = $user_data;

View File

@ -44,7 +44,7 @@ trait HasEmail
public function setEmail(string $email) public function setEmail(string $email)
{ {
$email = trim($email); $email = trim($email);
if (strlen($email) > 64) { if ((function_exists('mb_strlen') ? mb_strlen($email) : strlen($email)) > 64) {
throw new AtolEmailTooLongException($email, 64); throw new AtolEmailTooLongException($email, 64);
} }
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {