Миграция на php8.1
* enum-ы теперь enum-ы, а не говно -- теперь всё переведено на них, где это было возможно * некоторые свойства классов объявлены в конструкторе * некоторые классы перемещены в корневой неймспейс * исправлен код-стайл, вычищен некоторый мусор, выправлены тесты... работы над этим продолжаются
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Copyright (c) 2020-2021 Антон Аксенов (Anthony Axenov)
|
||||
*
|
||||
@@ -7,12 +8,11 @@
|
||||
* https://github.com/anthonyaxenov/atol-online/blob/master/LICENSE
|
||||
*/
|
||||
|
||||
declare(strict_types = 1);
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace AtolOnline\Entities;
|
||||
|
||||
use AtolOnline\Enums\VatTypes;
|
||||
use AtolOnline\Exceptions\InvalidEnumValueException;
|
||||
use AtolOnline\Enums\VatType;
|
||||
use AtolOnline\Helpers;
|
||||
use JetBrains\PhpStorm\{
|
||||
ArrayShape,
|
||||
@@ -25,49 +25,38 @@ use JetBrains\PhpStorm\{
|
||||
*/
|
||||
final class Vat extends Entity
|
||||
{
|
||||
/**
|
||||
* @var string Тип ставки НДС (1199, 1105, 1104, 1103, 1102, 1107, 1106)
|
||||
*/
|
||||
private string $type;
|
||||
|
||||
/**
|
||||
* @var float Сумма в рублях, от которой пересчитывается размер НДС
|
||||
*/
|
||||
private float $sum;
|
||||
|
||||
/**
|
||||
* Конструктор
|
||||
*
|
||||
* @param string $type Тип ставки НДС (1199, 1105, 1104, 1103, 1102, 1107, 1106)
|
||||
* @param float $rubles Исходная сумма в рублях, от которой нужно расчитать размер НДС
|
||||
* @throws InvalidEnumValueException
|
||||
* @param VatType $type Тип ставки НДС (1199, 1105, 1104, 1103, 1102, 1107, 1106)
|
||||
* @param float $sum Исходная сумма в рублях, от которой нужно расчитать размер НДС
|
||||
*/
|
||||
public function __construct(string $type, float $rubles)
|
||||
{
|
||||
$this->setType($type)->setSum($rubles);
|
||||
public function __construct(
|
||||
protected VatType $type,
|
||||
protected float $sum,
|
||||
) {
|
||||
$this->setType($type)->setSum($sum);
|
||||
}
|
||||
|
||||
/**
|
||||
* Устанавливает тип ставки НДС
|
||||
* Автоматически пересчитывает итоговый размер НДС от исходной суммы.
|
||||
*
|
||||
* @param string $type Тип ставки НДС
|
||||
* @param VatType $type Тип ставки НДС
|
||||
* @return $this
|
||||
* @throws InvalidEnumValueException
|
||||
*/
|
||||
public function setType(string $type): self
|
||||
public function setType(VatType $type): self
|
||||
{
|
||||
$type = trim($type);
|
||||
VatTypes::isValid($type) && $this->type = $type;
|
||||
$this->type = $type;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Возвращает тип ставки НДС
|
||||
*
|
||||
* @return string
|
||||
* @return VatType
|
||||
*/
|
||||
public function getType(): string
|
||||
public function getType(): VatType
|
||||
{
|
||||
return $this->type;
|
||||
}
|
||||
@@ -108,12 +97,12 @@ final class Vat extends Entity
|
||||
{
|
||||
return Helpers::toRub(
|
||||
match ($this->getType()) {
|
||||
VatTypes::VAT10 => Helpers::toKop($this->sum) * 10 / 100,
|
||||
VatTypes::VAT18 => Helpers::toKop($this->sum) * 18 / 100,
|
||||
VatTypes::VAT20 => Helpers::toKop($this->sum) * 20 / 100,
|
||||
VatTypes::VAT110 => Helpers::toKop($this->sum) * 10 / 110,
|
||||
VatTypes::VAT118 => Helpers::toKop($this->sum) * 18 / 118,
|
||||
VatTypes::VAT120 => Helpers::toKop($this->sum) * 20 / 120,
|
||||
VatType::VAT10 => Helpers::toKop($this->sum) * 10 / 100,
|
||||
VatType::VAT18 => Helpers::toKop($this->sum) * 18 / 100,
|
||||
VatType::VAT20 => Helpers::toKop($this->sum) * 20 / 100,
|
||||
VatType::VAT110 => Helpers::toKop($this->sum) * 10 / 110,
|
||||
VatType::VAT118 => Helpers::toKop($this->sum) * 18 / 118,
|
||||
VatType::VAT120 => Helpers::toKop($this->sum) * 20 / 120,
|
||||
default => 0,
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user