Рефакторинг исключений, новые константы ограничений
Описывать все слишком долго, TLDR:
- упрощены корневые AtolException, {BasicTooLongException => TooLongException}, {BasicTooManyException => TooManyException}
- InvalidSnoException заменён на InvalidEnumValueException
- добавлены новые константы, общий порядок изменён в соответствии с порядком упоминания в документации, ссылки на которую тоже добавлены с указанием страниц
Помимо этого, в enum-ах теперь должен быть предусмотрен метод getFfdTags()
This commit is contained in:
@@ -15,9 +15,10 @@ use AtolOnline\{
|
||||
Constants\Constraints,
|
||||
Exceptions\InvalidEmailException,
|
||||
Exceptions\InvalidInnLengthException,
|
||||
Exceptions\TooLongClientContactException,
|
||||
Exceptions\TooLongClientNameException,
|
||||
Exceptions\TooLongEmailException,
|
||||
Exceptions\TooLongNameException,
|
||||
Exceptions\TooLongPhoneException};
|
||||
Exceptions\TooLongItemNameException};
|
||||
|
||||
/**
|
||||
* Класс Client, описывающий сущность покупателя
|
||||
@@ -53,8 +54,8 @@ class Client extends Entity
|
||||
* @param string|null $phone Email. Тег ФФД - 1008.
|
||||
* @param string|null $email Телефон покупателя. Тег ФФД - 1008.
|
||||
* @param string|null $inn ИНН. Тег ФФД - 1228.
|
||||
* @throws TooLongNameException
|
||||
* @throws TooLongPhoneException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooLongClientContactException
|
||||
* @throws TooLongEmailException
|
||||
* @throws InvalidEmailException
|
||||
* @throws InvalidInnLengthException
|
||||
@@ -91,14 +92,14 @@ class Client extends Entity
|
||||
*
|
||||
* @param string|null $name
|
||||
* @return $this
|
||||
* @throws TooLongNameException
|
||||
* @throws TooLongClientNameException
|
||||
*/
|
||||
public function setName(?string $name): self
|
||||
{
|
||||
if (is_string($name)) {
|
||||
$name = preg_replace('/[\n\r\t]/', '', trim($name));
|
||||
if (mb_strlen($name) > Constraints::MAX_LENGTH_CLIENT_NAME) {
|
||||
throw new TooLongNameException($name, Constraints::MAX_LENGTH_CLIENT_NAME);
|
||||
throw new TooLongClientNameException($name);
|
||||
}
|
||||
}
|
||||
$this->name = empty($name) ? null : $name;
|
||||
@@ -128,7 +129,7 @@ class Client extends Entity
|
||||
if (is_string($email)) {
|
||||
$email = preg_replace('/[\n\r\t]/', '', trim($email));
|
||||
if (mb_strlen($email) > Constraints::MAX_LENGTH_EMAIL) {
|
||||
throw new TooLongEmailException($email, Constraints::MAX_LENGTH_EMAIL);
|
||||
throw new TooLongEmailException($email);
|
||||
} elseif (filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
||||
throw new InvalidEmailException($email);
|
||||
}
|
||||
@@ -156,14 +157,14 @@ class Client extends Entity
|
||||
*
|
||||
* @param string|null $phone Номер телефона
|
||||
* @return $this
|
||||
* @throws TooLongPhoneException
|
||||
* @throws TooLongClientContactException
|
||||
*/
|
||||
public function setPhone(?string $phone): self
|
||||
{
|
||||
if (is_string($phone)) {
|
||||
$phone = preg_replace('/[^\d]/', '', trim($phone));
|
||||
if (mb_strlen($phone) > Constraints::MAX_LENGTH_CLIENT_PHONE) {
|
||||
throw new TooLongPhoneException($phone, Constraints::MAX_LENGTH_CLIENT_PHONE);
|
||||
if (mb_strlen($phone) > Constraints::MAX_LENGTH_CLIENT_CONTACT) {
|
||||
throw new TooLongClientContactException($phone);
|
||||
}
|
||||
}
|
||||
$this->phone = empty($phone) ? null : "+$phone";
|
||||
|
||||
@@ -15,9 +15,9 @@ use AtolOnline\{
|
||||
Constants\Constraints,
|
||||
Enums\SnoTypes,
|
||||
Exceptions\InvalidEmailException,
|
||||
Exceptions\InvalidEnumValueException,
|
||||
Exceptions\InvalidInnLengthException,
|
||||
Exceptions\InvalidPaymentAddressException,
|
||||
Exceptions\InvalidSnoException,
|
||||
Exceptions\TooLongEmailException,
|
||||
Exceptions\TooLongPaymentAddressException};
|
||||
|
||||
@@ -58,7 +58,7 @@ class Company extends Entity
|
||||
* @throws InvalidEmailException
|
||||
* @throws InvalidInnLengthException
|
||||
* @throws InvalidPaymentAddressException
|
||||
* @throws InvalidSnoException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws TooLongEmailException
|
||||
* @throws TooLongPaymentAddressException
|
||||
*/
|
||||
@@ -96,7 +96,7 @@ class Company extends Entity
|
||||
{
|
||||
$email = preg_replace('/[\n\r\t]/', '', trim($email));
|
||||
if (mb_strlen($email) > Constraints::MAX_LENGTH_EMAIL) {
|
||||
throw new TooLongEmailException($email, Constraints::MAX_LENGTH_EMAIL);
|
||||
throw new TooLongEmailException($email);
|
||||
} elseif (empty($email) || filter_var($email, FILTER_VALIDATE_EMAIL) === false) {
|
||||
throw new InvalidEmailException($email);
|
||||
}
|
||||
@@ -123,14 +123,12 @@ class Company extends Entity
|
||||
*
|
||||
* @param string $sno
|
||||
* @return $this
|
||||
* @throws InvalidSnoException
|
||||
* @throws InvalidEnumValueException
|
||||
*/
|
||||
public function setSno(string $sno): self
|
||||
{
|
||||
$sno = trim($sno);
|
||||
if (empty($sno) || !in_array($sno, SnoTypes::toArray())) {
|
||||
throw new InvalidSnoException($sno);
|
||||
}
|
||||
SnoTypes::isValid($sno);
|
||||
$this->sno = $sno;
|
||||
return $this;
|
||||
}
|
||||
@@ -194,7 +192,7 @@ class Company extends Entity
|
||||
if (empty($payment_address)) {
|
||||
throw new InvalidPaymentAddressException();
|
||||
} elseif (mb_strlen($payment_address) > Constraints::MAX_LENGTH_PAYMENT_ADDRESS) {
|
||||
throw new TooLongPaymentAddressException($payment_address, Constraints::MAX_LENGTH_PAYMENT_ADDRESS);
|
||||
throw new TooLongPaymentAddressException($payment_address);
|
||||
}
|
||||
$this->payment_address = $payment_address;
|
||||
return $this;
|
||||
@@ -203,7 +201,7 @@ class Company extends Entity
|
||||
/**
|
||||
* @inheritDoc
|
||||
* @throws InvalidEmailException
|
||||
* @throws InvalidSnoException
|
||||
* @throws InvalidEnumValueException
|
||||
* @throws InvalidInnLengthException
|
||||
* @throws InvalidPaymentAddressException
|
||||
*/
|
||||
@@ -215,7 +213,7 @@ class Company extends Entity
|
||||
: throw new InvalidEmailException(),
|
||||
'sno' => $this->sno
|
||||
? $this->getSno()
|
||||
: throw new InvalidSnoException(),
|
||||
: throw new InvalidEnumValueException(SnoTypes::class, 'null'),
|
||||
'inn' => $this->inn
|
||||
? $this->getInn()
|
||||
: throw new InvalidInnLengthException(),
|
||||
|
||||
@@ -13,18 +13,18 @@ namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\Constants\Constraints;
|
||||
use AtolOnline\Exceptions\AtolException;
|
||||
use AtolOnline\Exceptions\BasicTooManyException;
|
||||
use AtolOnline\Exceptions\InvalidEmailException;
|
||||
use AtolOnline\Exceptions\InvalidInnLengthException;
|
||||
use AtolOnline\Exceptions\InvalidJsonException;
|
||||
use AtolOnline\Exceptions\TooHighPriceException;
|
||||
use AtolOnline\Exceptions\TooLongCashierException;
|
||||
use AtolOnline\Exceptions\TooLongClientContactException;
|
||||
use AtolOnline\Exceptions\TooLongEmailException;
|
||||
use AtolOnline\Exceptions\TooLongNameException;
|
||||
use AtolOnline\Exceptions\TooLongItemNameException;
|
||||
use AtolOnline\Exceptions\TooLongPaymentAddressException;
|
||||
use AtolOnline\Exceptions\TooLongPhoneException;
|
||||
use AtolOnline\Exceptions\TooLongUnitException;
|
||||
use AtolOnline\Exceptions\TooLongUserdataException;
|
||||
use AtolOnline\Exceptions\TooManyException;
|
||||
use AtolOnline\Exceptions\TooManyItemsException;
|
||||
use AtolOnline\Exceptions\TooManyPaymentsException;
|
||||
use AtolOnline\Exceptions\TooManyVatsException;
|
||||
@@ -66,7 +66,7 @@ class Document extends Entity
|
||||
* @var float Итоговая сумма чека. Тег ФФД - 1020.
|
||||
*/
|
||||
protected float $total = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @var string ФИО кассира. Тег ФФД - 1021.
|
||||
*/
|
||||
@@ -76,7 +76,7 @@ class Document extends Entity
|
||||
* @var CorrectionInfo Данные коррекции
|
||||
*/
|
||||
protected CorrectionInfo $correction_info;
|
||||
|
||||
|
||||
/**
|
||||
* Document constructor.
|
||||
*/
|
||||
@@ -211,7 +211,7 @@ class Document extends Entity
|
||||
$this->items->set($items);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает заданного клиента (покупателя)
|
||||
*
|
||||
@@ -221,7 +221,7 @@ class Document extends Entity
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Устанавливает клиента (покупателя)
|
||||
*
|
||||
@@ -233,7 +233,7 @@ class Document extends Entity
|
||||
$this->client = $client;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает заданную компанию (продавца)
|
||||
*
|
||||
@@ -243,7 +243,7 @@ class Document extends Entity
|
||||
{
|
||||
return $this->company;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Устанавливает компанию (продавца)
|
||||
*
|
||||
@@ -255,7 +255,7 @@ class Document extends Entity
|
||||
$this->company = $company;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает ФИО кассира. Тег ФФД - 1021.
|
||||
*
|
||||
@@ -323,7 +323,7 @@ class Document extends Entity
|
||||
}
|
||||
return $this->total = round($sum, 2);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает итоговую сумму чека. Тег ФФД - 1020.
|
||||
*
|
||||
@@ -344,11 +344,11 @@ class Document extends Entity
|
||||
* @throws AtolException
|
||||
* @throws InvalidInnLengthException
|
||||
* @throws InvalidJsonException
|
||||
* @throws TooLongNameException
|
||||
* @throws TooLongItemNameException
|
||||
* @throws TooLongPaymentAddressException
|
||||
* @throws TooLongPhoneException
|
||||
* @throws TooLongClientContactException
|
||||
* @throws TooHighPriceException
|
||||
* @throws BasicTooManyException
|
||||
* @throws TooManyException
|
||||
* @throws TooManyItemsException
|
||||
* @throws TooManyPaymentsException
|
||||
* @throws TooLongUnitException
|
||||
|
||||
@@ -13,11 +13,11 @@ namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\{
|
||||
Constants\Constraints,
|
||||
Exceptions\BasicTooManyException,
|
||||
Exceptions\TooHighPriceException,
|
||||
Exceptions\TooLongNameException,
|
||||
Exceptions\TooLongItemNameException,
|
||||
Exceptions\TooLongUnitException,
|
||||
Exceptions\TooLongUserdataException};
|
||||
Exceptions\TooLongUserdataException,
|
||||
Exceptions\TooManyException};
|
||||
|
||||
/**
|
||||
* Предмет расчёта (товар, услуга)
|
||||
@@ -30,22 +30,22 @@ class Item extends Entity
|
||||
* @var string Наименование. Тег ФФД - 1030.
|
||||
*/
|
||||
protected string $name;
|
||||
|
||||
|
||||
/**
|
||||
* @var int Цена в копейках (с учётом скидок и наценок). Тег ФФД - 1079.
|
||||
*/
|
||||
protected int $price = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @var float Количество, вес. Тег ФФД - 1023.
|
||||
*/
|
||||
protected float $quantity = 0.0;
|
||||
|
||||
|
||||
/**
|
||||
* @var float Сумма в копейках. Тег ФФД - 1043.
|
||||
*/
|
||||
protected float $sum = 0;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Единица измерения количества. Тег ФФД - 1197.
|
||||
*/
|
||||
@@ -55,17 +55,17 @@ class Item extends Entity
|
||||
* @var Vat|null Ставка НДС
|
||||
*/
|
||||
protected ?Vat $vat;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Признак способа расчёта. Тег ФФД - 1214.
|
||||
*/
|
||||
protected string $payment_method;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Признак объекта расчёта. Тег ФФД - 1212.
|
||||
*/
|
||||
protected string $payment_object;
|
||||
|
||||
|
||||
/**
|
||||
* @var string Дополнительный реквизит. Тег ФФД - 1191.
|
||||
*/
|
||||
@@ -81,9 +81,9 @@ class Item extends Entity
|
||||
* @param string|null $vat_type Ставка НДС
|
||||
* @param string|null $payment_object Признак
|
||||
* @param string|null $payment_method Способ расчёта
|
||||
* @throws TooLongNameException Слишком длинное наименование
|
||||
* @throws TooLongItemNameException Слишком длинное наименование
|
||||
* @throws TooHighPriceException Слишком высокая цена за одну единицу
|
||||
* @throws BasicTooManyException Слишком большое количество
|
||||
* @throws TooManyException Слишком большое количество
|
||||
* @throws TooLongUnitException Слишком длинное название единицы измерения
|
||||
*/
|
||||
public function __construct(
|
||||
@@ -117,7 +117,7 @@ class Item extends Entity
|
||||
$this->setPaymentMethod($payment_method);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает наименование. Тег ФФД - 1030.
|
||||
*
|
||||
@@ -133,18 +133,18 @@ class Item extends Entity
|
||||
*
|
||||
* @param string $name Наименование
|
||||
* @return $this
|
||||
* @throws TooLongNameException Слишком длинное имя/наименование
|
||||
* @throws TooLongItemNameException Слишком длинное имя/наименование
|
||||
*/
|
||||
public function setName(string $name): self
|
||||
{
|
||||
$name = trim($name);
|
||||
if (mb_strlen($name) > Constraints::MAX_LENGTH_ITEM_NAME) {
|
||||
throw new TooLongNameException($name, Constraints::MAX_LENGTH_ITEM_NAME);
|
||||
throw new TooLongItemNameException($name, Constraints::MAX_LENGTH_ITEM_NAME);
|
||||
}
|
||||
$this->name = $name;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает цену в рублях. Тег ФФД - 1079.
|
||||
*
|
||||
@@ -171,7 +171,7 @@ class Item extends Entity
|
||||
$this->calcSum();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает количество. Тег ФФД - 1023.
|
||||
*
|
||||
@@ -188,7 +188,7 @@ class Item extends Entity
|
||||
* @param float $quantity Количество
|
||||
* @param string|null $measurement_unit Единица измерения количества
|
||||
* @return $this
|
||||
* @throws BasicTooManyException Слишком большое количество
|
||||
* @throws TooManyException Слишком большое количество
|
||||
* @throws TooHighPriceException Слишком высокая общая стоимость
|
||||
* @throws TooLongUnitException Слишком длинное название единицы измерения
|
||||
*/
|
||||
@@ -196,7 +196,7 @@ class Item extends Entity
|
||||
{
|
||||
$quantity = round($quantity, 3);
|
||||
if ($quantity > 99999.999) {
|
||||
throw new BasicTooManyException($quantity, 99999.999);
|
||||
throw new TooManyException($quantity, 99999.999);
|
||||
}
|
||||
$this->quantity = $quantity;
|
||||
$this->calcSum();
|
||||
@@ -205,7 +205,7 @@ class Item extends Entity
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает заданную единицу измерения количества. Тег ФФД - 1197.
|
||||
*
|
||||
@@ -232,7 +232,7 @@ class Item extends Entity
|
||||
$this->measurement_unit = $measurement_unit;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает признак способа оплаты. Тег ФФД - 1214.
|
||||
*
|
||||
@@ -242,7 +242,7 @@ class Item extends Entity
|
||||
{
|
||||
return $this->payment_method;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Устанавливает признак способа оплаты. Тег ФФД - 1214.
|
||||
*
|
||||
@@ -255,7 +255,7 @@ class Item extends Entity
|
||||
$this->payment_method = trim($payment_method);
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает признак предмета расчёта. Тег ФФД - 1212.
|
||||
*
|
||||
@@ -265,7 +265,7 @@ class Item extends Entity
|
||||
{
|
||||
return $this->payment_object;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Устанавливает признак предмета расчёта. Тег ФФД - 1212.
|
||||
*
|
||||
@@ -308,7 +308,7 @@ class Item extends Entity
|
||||
$this->calcSum();
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает дополнительный реквизит. Тег ФФД - 1191.
|
||||
*
|
||||
@@ -335,7 +335,7 @@ class Item extends Entity
|
||||
$this->user_data = $user_data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Возвращает стоимость. Тег ФФД - 1043.
|
||||
*
|
||||
@@ -364,7 +364,7 @@ class Item extends Entity
|
||||
}
|
||||
return $this->getSum();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @inheritDoc
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user