Общие сеттеры-геттеры сущностей вынесены в трейты HasEmail, HasInn, HasPhones

Кодстайл и микрорефакторинг сущностей
This commit is contained in:
2021-12-03 18:23:00 +08:00
parent c30c7d069f
commit 2260233e3f
13 changed files with 305 additions and 453 deletions

View File

@@ -12,8 +12,11 @@ declare(strict_types = 1);
namespace AtolOnline\Entities;
use AtolOnline\Constants\Constraints;
use AtolOnline\Exceptions\InvalidPhoneException;
use AtolOnline\Exceptions\TooLongPayingAgentOperationException;
use AtolOnline\Exceptions\{
InvalidPhoneException,
TooLongPayingAgentOperationException
};
use AtolOnline\Traits\HasPhones;
use Illuminate\Support\Collection;
/**
@@ -23,16 +26,13 @@ use Illuminate\Support\Collection;
*/
class PayingAgent extends Entity
{
use HasPhones;
/**
* @var string|null Наименование операции (1044)
*/
protected ?string $operation = null;
/**
* @var Collection Телефоны платёжного агента (1073)
*/
protected Collection $phones;
/**
* Конструктор
*
@@ -78,40 +78,6 @@ class PayingAgent extends Entity
return $this->operation;
}
/**
* Устанавливает массив номеров телефонов
*
* @todo вытащить в трейт
* @param array|Collection|null $phones
* @return $this
* @throws InvalidPhoneException
*/
public function setPhones(array|Collection|null $phones): self
{
if (!is_null($phones)) {
$phones = is_array($phones) ? collect($phones) : $phones;
$phones->each(function ($phone) {
$phone = preg_replace('/[^\d]/', '', trim($phone));
if (preg_match(Constraints::PATTERN_PHONE, $phone) != 1) {
throw new InvalidPhoneException($phone);
}
});
}
$this->phones = empty($phones) ? collect() : $phones;
return $this;
}
/**
* Возвращает установленные номера телефонов
*
* @todo вытащить в трейт
* @return Collection
*/
public function getPhones(): Collection
{
return $this->phones;
}
/**
* @inheritDoc
*/