serving_weight; } elseif ($fromUnit === 'servings') { return $amount; } if ( empty($fromUnit) || empty($food->serving_unit) || $food->serving_unit === $fromUnit ) { $multiplier = 1; } elseif ($fromUnit === 'tsp') { $multiplier = match ($food->serving_unit) { 'tbsp' => 1/3, 'cup' => 1/48, }; } elseif ($fromUnit === 'tbsp') { $multiplier = match ($food->serving_unit) { 'tsp' => 3, 'cup' => 1/16, }; } elseif ($fromUnit === 'cup') { $multiplier = match ($food->serving_unit) { 'tsp' => 48, 'tbsp' => 16, }; } else { throw new \DomainException("Unhandled unit combination: {$fromUnit}, {$food->serving_unit} ({$food->name})"); } return $multiplier / $food->serving_size * $amount; } }