list of ingredient strings without a section label * - a labelled group (string key) -> list of ingredient strings under a section label * (e.g. "Ingrédients", "Traces possibles") * * @phpstan-type IngredientGroup array */ final readonly class Ingredients { /** * @param array $groups */ public function __construct( public readonly array $groups ) { foreach ($groups as $key => $lines) { if (! is_array($lines)) { throw new \DomainException( "Invalid ingredient group at key '{$key}': value must be an array of strings" ); } foreach ($lines as $i => $line) { if (! is_string($line)) { throw new \DomainException( "Invalid ingredient at group '{$key}', index '{$i}': value must be a string" ); } if (empty(trim($line))) { throw new \DomainException( "Invalid ingredient at group '{$key}', index '{$i}': string should not be empty" ); } } } } }