From a28747b7ba018adcfce465dcb6a3b00082b45a9f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jan=20B=C3=B6hmer?= Date: Wed, 8 Apr 2020 16:41:04 +0200 Subject: [PATCH] Dont return null in getPartsInstockSum() function, when no part lots are defined yet. This should fix issue #38. --- src/Repository/PartRepository.php | 8 ++++---- src/Services/StatisticsHelper.php | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Repository/PartRepository.php b/src/Repository/PartRepository.php index 8b21d0b8..bcde3d26 100644 --- a/src/Repository/PartRepository.php +++ b/src/Repository/PartRepository.php @@ -50,12 +50,12 @@ class PartRepository extends NamedDBElementRepository /** * Gets the summed up instock of all parts (only parts without an measurent unit). * - * @return string + * @return float * * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ - public function getPartsInstockSum(): string + public function getPartsInstockSum(): float { $qb = new QueryBuilder($this->getEntityManager()); $qb->select('SUM(part_lot.amount)') @@ -65,7 +65,7 @@ class PartRepository extends NamedDBElementRepository $query = $qb->getQuery(); - return $query->getSingleScalarResult(); + return (float) ($query->getSingleScalarResult() ?? 0.0); } /** @@ -86,6 +86,6 @@ class PartRepository extends NamedDBElementRepository $query = $qb->getQuery(); - return (int) $query->getSingleScalarResult(); + return (int) ($query->getSingleScalarResult() ?? 0); } } diff --git a/src/Services/StatisticsHelper.php b/src/Services/StatisticsHelper.php index f5174bce..da7613f2 100644 --- a/src/Services/StatisticsHelper.php +++ b/src/Services/StatisticsHelper.php @@ -61,12 +61,12 @@ class StatisticsHelper /** * Returns the summed instocked over all parts (only parts without a measurement unit). * - * @return string + * @return float * * @throws \Doctrine\ORM\NoResultException * @throws \Doctrine\ORM\NonUniqueResultException */ - public function getPartsInstockSum(): string + public function getPartsInstockSum(): float { return $this->part_repo->getPartsInstockSum(); }