*/ private $details; /** @var MessageType|null */ public $machineDecision; public function __construct( MessageType $decision, ClassificationMethod $method, float $confidence, array $details = [], ?MessageType $machineDecision = null ) { $this->decision = $decision; $this->method = $method; $this->confidence = $confidence; $this->details = $details; $this->machineDecision = $machineDecision; // * Validation des détails foreach ($details as $key => $value) { if (empty($key) || !is_string($key)) { throw new \InvalidArgumentException("Clé de détail invalide : " . var_export($key, true)); } if (!is_float($value) && !is_int($value)) { throw new \InvalidArgumentException("Valeur de détail pour '$key' invalide : " . var_export($value, true)); } } foreach ($details as $key => $value) { if (empty($key) || !is_string($key)) { throw new \InvalidArgumentException("Clé de détail invalide : " . var_export($key, true)); } if (!is_float($value) && !is_int($value)) { throw new \InvalidArgumentException("Valeur de détail pour '$key' invalide : " . var_export($value, true)); } } } /** @return array{word:string,score:float}[] */ public function getDetails(): array { /** @var object{'word':string,'score':float}[] */ $output = []; foreach ($this->details as $key => $value) { $output[] = (object)[ 'word' => $key, 'score' => $value ]; } return $output; } }