$materials */ public function __construct( public string $title, public ?string $description = null, public ?int $workTypeId = null, public array $materials = [], ) {} /** * Rows without an item are left out. * * @param array{title?: string, description?: string|null, work_type_id?: int|string|null, materials?: list} $input */ public static function fromArray(array $input): self { $workTypeId = $input['work_type_id'] ?? null; $materials = []; foreach ($input['materials'] ?? [] as $material) { $itemId = $material['stock_item_id'] ?? null; if ($itemId !== null && $itemId !== '') { $materials[] = ['stockItemId' => (int) $itemId, 'quantity' => (string) ($material['quantity'] ?? '')]; } } return new self( (string) ($input['title'] ?? ''), $input['description'] ?? null, $workTypeId === null || $workTypeId === '' ? null : (int) $workTypeId, $materials, ); } }