Поддержка nomenclature_code у предмета расчёта + мелкофиксы

- теперь `getSum()` проверяет по `Constraints::MAX_COUNT_ITEM_SUM` вместо `MAX_COUNT_ITEM_PRICE` (как и должен был изначально)
- подправил `TooLongException`
- всякие phpdoc-и
This commit is contained in:
2021-12-03 11:52:40 +08:00
parent 1c0d8ba64d
commit 2a66889e46
5 changed files with 192 additions and 19 deletions

View File

@@ -31,14 +31,13 @@ class TooLongException extends AtolException
*
* @param string $value
* @param string $message
* @param int $max
* @param float $max
*/
public function __construct(string $value, string $message = '', int $max = 0)
public function __construct(string $value, string $message = '', float $max = 0)
{
$message = ($message ?: $this->message) . ': '. $value;
if ($max > 0 || $this->max > 0) {
$message .= ' (макс. = ' . ($max ?? $this->max) . ', фактически = ' . mb_strlen($value) . ')';
}
parent::__construct($message);
parent::__construct(
($message ?: $this->message) . ': ' . $value . (((float)$max > 0 || (float)$this->max > 0) ?
' (макс = ' . ($max ?: $this->max) . ', фактически = ' . mb_strlen($value) . ')' : '')
);
}
}

View File

@@ -0,0 +1,35 @@
<?php
/*
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
*
* This code is licensed under MIT.
* Этот код распространяется по лицензии MIT.
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
*/
declare(strict_types = 1);
namespace AtolOnline\Exceptions;
use AtolOnline\Constants\Constraints;
use AtolOnline\Constants\Ffd105Tags;
/**
* Исключение, возникающее при попытке указать слишком длинный код товара
*/
class TooLongItemCodeException extends TooLongException
{
protected float $max = Constraints::MAX_LENGTH_ITEM_CODE;
protected array $ffd_tags = [Ffd105Tags::ITEM_NOMENCLATURE_CODE];
/**
* Конструктор
*
* @param string $name
* @param string $code
*/
public function __construct(string $name, string $code)
{
parent::__construct($code, "Слишком длинный код товара '$name'");
}
}