`Enum` стал абстрактным внутри `Enums`, наследникам созданы `getFfdTags()`

pull/10/head
Anthony Axenov 2021-11-28 00:55:28 +08:00
parent c9670a1321
commit e2141551d5
11 changed files with 95 additions and 63 deletions

View File

@ -1,23 +0,0 @@
<?php
declare(strict_types = 1);
namespace AtolOnline;
use AtolOnline\Exceptions\InvalidEnumValueException;
/**
* Расширение класса перечисления
*/
class Enum extends \MyCLabs\Enum\Enum
{
/**
* @inheritDoc
* @throws InvalidEnumValueException
*/
public static function isValid($value)
{
return parent::isValid($value)
?: throw new InvalidEnumValueException(static::class, $value);
}
}

View File

@ -11,14 +11,10 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use AtolOnline\Enum;
/**
* Константы, определяющие типы агента
*
* Тег ФФД - 1057
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 18 (agent_info)
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 18
*/
final class AgentTypes extends Enum
{
@ -58,7 +54,7 @@ final class AgentTypes extends Enum
const ANOTHER = 'another';
/**
* @return int[] Возвращает массив тегов ФФД
* @inheritDoc
*/
public static function getFfdTags(): array
{

View File

@ -11,14 +11,10 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use MyCLabs\Enum\Enum;
/**
* Константы, определяющие типы документов коррекции
*
* Тег ФФД - 1173
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35 (correction_info)
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35
*/
final class CorrectionTypes extends Enum
{
@ -31,4 +27,12 @@ final class CorrectionTypes extends Enum
* По предписанию
*/
const INSTRUCTION = 'instruction';
/**
* @inheritDoc
*/
public static function getFfdTags(): array
{
return [1173];
}
}

View File

@ -11,8 +11,6 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use MyCLabs\Enum\Enum;
/**
* Константы, определяющие типы документов
*/
@ -27,4 +25,12 @@ final class DocumentTypes extends Enum
* Чек коррекции
*/
const CORRECTION = 'correction';
/**
* @inheritDoc
*/
public static function getFfdTags(): array
{
return [];
}
}

37
src/Enums/Enum.php 100644
View File

@ -0,0 +1,37 @@
<?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\Enums;
use AtolOnline\Exceptions\InvalidEnumValueException;
/**
* Расширение класса перечисления
*/
abstract class Enum extends \MyCLabs\Enum\Enum
{
/**
* @inheritDoc
* @throws InvalidEnumValueException
*/
public static function isValid($value)
{
return parent::isValid($value)
?: throw new InvalidEnumValueException(static::class, $value);
}
/**
* Возвращает массив тегов ФФД
*
* @return int[]
*/
abstract public static function getFfdTags(): array;
}

View File

@ -11,14 +11,10 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use MyCLabs\Enum\Enum;
/**
* Константы, определяющие признаки способов расчёта
*
* Тег ФФД - 1214
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 22 (payment_method)
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 22
*/
final class PaymentMethods extends Enum
{
@ -56,4 +52,12 @@ final class PaymentMethods extends Enum
* Оплата кредита
*/
const CREDIT_PAYMENT = 'credit_payment';
}
/**
* @inheritDoc
*/
public static function getFfdTags(): array
{
return [1214];
}
}

View File

@ -11,14 +11,10 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use MyCLabs\Enum\Enum;
/**
* Константы, определяющие признаки предметов расчёта
*
* Тег ФФД - 1212
*
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 23 (payment_object)
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 23
*/
final class PaymentObjects extends Enum
{
@ -115,7 +111,7 @@ final class PaymentObjects extends Enum
const RESORT_FEE = 'resort_fee';
/**
* Взнос в счёт оплаты пени, штрафе, вознаграждении, бонусе и ином аналогичном предмете расчета
* Взнос в счёт оплаты пени, штрафе, вознаграждении, бонусе и ином аналогичном предмете расчёта
*/
const AWARD = 'award';
@ -158,4 +154,12 @@ final class PaymentObjects extends Enum
* Платёж казино
*/
const CASINO_PAYMENT = 'casino_payment';
/**
* @inheritDoc
*/
public static function getFfdTags(): array
{
return [1212];
}
}

View File

@ -11,37 +11,35 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use MyCLabs\Enum\Enum;
/**
* Константы, определяющие виды оплат
*
* Теги ФФД: 1031, 1081, 1215, 1216, 1217
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35
*/
final class PaymentTypes extends Enum
{
/**
* Расчёт наличными. Тег ФФД - 1031.
* Расчёт наличными
*/
const CASH = 0;
/**
* Расчёт безналичными. Тег ФФД - 1081.
* Расчёт безналичными
*/
const ELECTRON = 1;
/**
* Предварительная оплата (зачёт аванса). Тег ФФД - 1215.
* Предварительная оплата (зачёт аванса)
*/
const PRE_PAID = 2;
/**
* Предварительная оплата (кредит). Тег ФФД - 1216.
* Предварительная оплата (кредит)
*/
const CREDIT = 3;
/**
* Иная форма оплаты (встречное предоставление). Тег ФФД - 1217.
* Иная форма оплаты (встречное предоставление)
*/
const OTHER = 4;
@ -74,4 +72,12 @@ final class PaymentTypes extends Enum
* Для каждого фискального типа оплаты можно указать расширенный тип оплаты
*/
const ADD_9 = 9;
/**
* @inheritDoc
*/
public static function getFfdTags(): array
{
return [1031, 1081, 1215, 1216, 1217];
}
}

View File

@ -11,12 +11,10 @@ declare(strict_types = 1);
namespace AtolOnline\Enums;
use AtolOnline\Enum;
/**
* Константы, определяющие типы налогообложения
*
* Тег ФДД - 1055
* @see https://online.atol.ru/files/API_atol_online_v4.pdf Документация, стр 35
*/
final class SnoTypes extends Enum
{
@ -51,10 +49,10 @@ final class SnoTypes extends Enum
const PATENT = 'patent';
/**
* @return int[] Возвращает массив тегов ФФД
* @inheritDoc
*/
public static function getFfdTags(): array
{
return [1055];
}
}
}

View File

@ -11,7 +11,7 @@ declare(strict_types = 1);
namespace AtolOnline\Exceptions;
use AtolOnline\Enum;
use AtolOnline\Enums\Enum;
/**
* Исключение, возникающее при ошибке валидации типа агента

View File

@ -21,5 +21,5 @@ class TooLongUnitException extends TooLongException
{
protected $message = 'Слишком длинная единица измерения предмета расчёта';
protected float $max = Constraints::MAX_LENGTH_MEASUREMENT_UNIT;
protected array $ffd_tags = [Ffd105Tags::ITEM_MEASURE];
protected array $ffd_tags = [Ffd105Tags::ITEM_MEASUREMENT_UNIT];
}