Files
ednotif-bundle/src/Shared/Mapper/StandardResponseMapper.php
tristan f757822f36
All checks were successful
Auto Tag Develop / tag (push) Successful in 6s
Build Release Artefact / build (push) Successful in 39s
[#ED-1] Ajout des API de lecture bovin (#2)
| 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>
2026-04-21 08:14:37 +00:00

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;
}
}