| Numéro du ticket | Titre du ticket | |------------------|-----------------| | | | ## Description de la PR ## Modification du .env ## Check list - [ ] Pas de régression - [x] TU/TI/TF rédigée - [x] TU/TI/TF OK - [ ] CHANGELOG modifié Reviewed-on: #2 Co-authored-by: tristan <tristan@yuno.malio.fr> Co-committed-by: tristan <tristan@yuno.malio.fr>
54 lines
1.4 KiB
PHP
54 lines
1.4 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Malio\EdnotifBundle\Shared\Mapper;
|
|
|
|
use Malio\EdnotifBundle\Shared\Dto\AnomalyDto;
|
|
use Malio\EdnotifBundle\Shared\Dto\StandardResponseDto;
|
|
|
|
final class StandardResponseMapper
|
|
{
|
|
public function map(mixed $standardResponseNode): StandardResponseDto
|
|
{
|
|
$result = (bool) ($standardResponseNode->Resultat ?? false);
|
|
$anomalyNode = is_object($standardResponseNode) ? ($standardResponseNode->Anomalie ?? null) : null;
|
|
|
|
$anomaly = null;
|
|
if (is_object($anomalyNode)) {
|
|
$anomaly = new AnomalyDto(
|
|
code: $this->toNullableString($anomalyNode->Code ?? null),
|
|
severity: $this->toNullableInt($anomalyNode->Severite ?? null),
|
|
message: $this->toNullableString($anomalyNode->Message ?? null),
|
|
);
|
|
}
|
|
|
|
return new StandardResponseDto($result, $anomaly);
|
|
}
|
|
|
|
private function toNullableString(mixed $value): ?string
|
|
{
|
|
if (null === $value) {
|
|
return null;
|
|
}
|
|
$stringValue = trim((string) $value);
|
|
|
|
return '' === $stringValue ? null : $stringValue;
|
|
}
|
|
|
|
private function toNullableInt(mixed $value): ?int
|
|
{
|
|
if (null === $value) {
|
|
return null;
|
|
}
|
|
if (is_int($value)) {
|
|
return $value;
|
|
}
|
|
if (is_numeric($value)) {
|
|
return (int) $value;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
}
|