Files
ednotif-bundle/src/Bovin/Mapper/InventoryMapper.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

69 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Malio\EdnotifBundle\Bovin\Mapper;
use Malio\EdnotifBundle\Bovin\Dto\EarTagSeriesDto;
use Malio\EdnotifBundle\Bovin\Dto\InventoryDto;
use Malio\EdnotifBundle\Shared\Mapper\StandardResponseMapper;
final class InventoryMapper
{
use BovinNodeMappingTrait;
public function __construct(
private readonly AnimalSummaryMapper $animalSummaryMapper,
private readonly StandardResponseMapper $standardResponseMapper,
) {}
public function map(object $soapResponse, ?object $unzippedMessage): InventoryDto
{
$standardResponse = $this->standardResponseMapper->map($soapResponse->ReponseStandard ?? null);
$nbBovins = $this->toNullableInt($soapResponse->ReponseSpecifique->NbBovins ?? null) ?? 0;
$startDate = null;
$endDate = null;
$includesEarTagStock = null;
$animals = [];
$earTagSeries = [];
if (is_object($unzippedMessage)) {
$infoNode = $unzippedMessage->InformationsMessage ?? null;
if (is_object($infoNode)) {
$startDate = $this->toNullableDate($infoNode->DateDebut ?? null);
$endDate = $this->toNullableDate($infoNode->DateFin ?? null);
$includesEarTagStock = $this->toNullableBool($infoNode->StockBoucles ?? null);
}
$bovinsNode = $unzippedMessage->Bovins->Bovin ?? null;
foreach ($this->normalizeToList($bovinsNode) as $bovinNode) {
if (!is_object($bovinNode)) {
continue;
}
$animals[] = $this->animalSummaryMapper->map($bovinNode);
}
$seriesNode = $unzippedMessage->Boucles->SerieBoucles ?? null;
foreach ($this->normalizeToList($seriesNode) as $serieNode) {
if (!is_object($serieNode)) {
continue;
}
$earTagSeries[] = new EarTagSeriesDto(rawNode: $serieNode);
}
}
return new InventoryDto(
standardResponse: $standardResponse,
nbBovins: $nbBovins,
startDate: $startDate,
endDate: $endDate,
includesEarTagStock: $includesEarTagStock,
animals: $animals,
earTagSeries: $earTagSeries,
rawSoapResponse: $soapResponse,
);
}
}