From 3628ab1f5165a1960bf9a82c1041cbb721a55e5d Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Fri, 15 Jan 2021 05:09:42 -0800 Subject: [PATCH] Assume empty "from unit" is serving --- app/Support/Nutrients.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Support/Nutrients.php b/app/Support/Nutrients.php index 445cf04..2689fd1 100644 --- a/app/Support/Nutrients.php +++ b/app/Support/Nutrients.php @@ -30,7 +30,7 @@ class Nutrients return $amount; } - if ($food->serving_unit === $fromUnit) { + if (empty($fromUnit) || $food->serving_unit === $fromUnit) { $multiplier = 1; } elseif ($fromUnit === 'tsp') { @@ -52,7 +52,7 @@ class Nutrients }; } else { - throw new \DomainException("Unhandled unit combination: {$fromUnit}, {$food->serving_unit}"); + throw new \DomainException("Unhandled unit combination: {$fromUnit}, {$food->serving_unit} ({$food->name})"); } return $multiplier / $food->serving_size * $amount;