init
This commit is contained in:
66
app/Service/Entities/FailureReport.php
Normal file
66
app/Service/Entities/FailureReport.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Entities;
|
||||
|
||||
use App\Service\Enums\Priority;
|
||||
use App\Service\Enums\Status;
|
||||
use App\Service\Enums\Type;
|
||||
use DateTimeImmutable;
|
||||
|
||||
class FailureReport extends BaseReport implements EntityInterface
|
||||
{
|
||||
public Priority $priority = Priority::NORMAL;
|
||||
public string $serviceNotes = '';
|
||||
public Type $type = Type::FAILURE;
|
||||
|
||||
|
||||
public function __construct(InputEntity $entity)
|
||||
{
|
||||
$this->createdAt = new DateTimeImmutable();
|
||||
$this->fromData($entity);
|
||||
}
|
||||
|
||||
public static function isValid(InputEntity $entity): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
public function __toArray(): array
|
||||
{
|
||||
return [
|
||||
'description' => $this->description,
|
||||
'type' => $this->type->value,
|
||||
'priority' => $this->priority->value,
|
||||
'serviceDate' => $this->serviceDate?->format('Y-m-d') ?? '',
|
||||
'status' => $this->status->value,
|
||||
'serviceNotes' => $this->serviceNotes,
|
||||
'contactPhone' => $this->contactPhone ?? '',
|
||||
'createdAt' => $this->createdAt->format('Y-m-d')
|
||||
];
|
||||
}
|
||||
|
||||
private function fromData(InputEntity $entity): void
|
||||
{
|
||||
$this->description = $entity->description;
|
||||
$this->serviceDate = $entity->date;
|
||||
$this->contactPhone = $entity->phone;
|
||||
$this->checkPriority($entity->description);
|
||||
$this->status = $this->serviceDate ? Status::DEADLINE : Status::NEW;
|
||||
|
||||
}
|
||||
|
||||
private function checkPriority(string $description): void
|
||||
{
|
||||
$map = [
|
||||
'/bardzo pilne/im' => Priority::CRITICAL,
|
||||
'/pilne/im' => Priority::HIGH,
|
||||
];
|
||||
|
||||
foreach ($map as $pattern => $priority) {
|
||||
if (preg_match($pattern, $description)) {
|
||||
$this->priority = $priority;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user