34 lines
957 B
PHP
34 lines
957 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Factories;
|
|
|
|
use App\Data\ConnectService\ConnectServiceData;
|
|
use App\Enums\ConnectionStatusEnum;
|
|
|
|
final class ConnectedAppFactory
|
|
{
|
|
public function createDataFromDto(ConnectServiceData $data): array
|
|
{
|
|
$result = [
|
|
'name' => $data->name,
|
|
'service_provider_id' => $data->serviceProviderId,
|
|
'service_protocol_id' => $data->serviceProtocolId,
|
|
'logo_url' => $data->logoUrl,
|
|
'slug' => $data->slug,
|
|
'service_status_id' => $data->statusId,
|
|
];
|
|
|
|
// Check if the staus is filled, if not select disconnected by default
|
|
if (null === $data->statusId) {
|
|
$status = ConnectionStatusEnum::query()
|
|
->where('name', '=', ConnectionStatusEnum::Disconnected->value)
|
|
->pluck('id');
|
|
$result['service_status_id'] = $status[0];
|
|
}
|
|
|
|
return $result;
|
|
}
|
|
}
|