getNationalNumber()) { $this->enrichFromEdnotif($data); } return $this->persistProcessor->process($data, $operation, $uriVariables, $context); } private function enrichFromEdnotif(Bovine $bovine): void { try { $animalFile = $this->bovinApi->getAnimalFile( nationalNumber: $bovine->getNationalNumber(), countryCode: 'FR', ); $identification = $animalFile->identification; if (null === $identification) { return; } $bovine->setWorkNumber($identification->workNumber); $bovine->setBirthDate($identification->birthDate?->date); $bovine->setBreedCode($this->normalizeBreedCode($identification->breedType)); } catch (Throwable) { // External service unavailable — persist bovine without enrichment. } } private function normalizeBreedCode(mixed $breedType): ?string { if (null === $breedType) { return null; } if (is_numeric($breedType)) { return (string) $breedType; } if (is_string($breedType) && preg_match('/\d+/', $breedType, $matches)) { return $matches[0]; } return null; } }