From e4916567911f8b5281a4282d8f4de54add568259 Mon Sep 17 00:00:00 2001 From: Jonathan Foucher <jfoucher@gmail.com> Date: Thu, 5 Oct 2023 11:07:57 +0200 Subject: [PATCH] Do not crash if collectivity has no maturity survey. Fixes https://gitlab.adullact.net/soluris/madis/-/issues/827 --- src/Domain/Reporting/Metrics/UserMetric.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Domain/Reporting/Metrics/UserMetric.php b/src/Domain/Reporting/Metrics/UserMetric.php index 127b69ef3..7e4270ec1 100644 --- a/src/Domain/Reporting/Metrics/UserMetric.php +++ b/src/Domain/Reporting/Metrics/UserMetric.php @@ -227,10 +227,13 @@ class UserMetric implements MetricInterface ] ); - $maturity = $this->surveyRepository->findLatestByReferentialAndCollectivity( - $referentiel, - $collectivity - ); + if ($referentiel) { + $maturity = $this->surveyRepository->findLatestByReferentialAndCollectivity( + $referentiel, + $collectivity + ); + } + $mesurements = $this->entityManager->getRepository(Model\Mesurement::class)->findBy( ['collectivity' => $collectivity] ); @@ -273,7 +276,7 @@ class UserMetric implements MetricInterface } // MATURITY - if (isset($maturity[0]) && null !== $maturity[0]->getReferentiel()) { + if (isset($maturity) && isset($maturity[0]) && null !== $maturity[0]->getReferentiel()) { $data['maturity']['new']['name'] = $maturity[0]->getCreatedAt()->format('d/m/Y'); foreach ($maturity[0]->getMaturity() as $item) { $data['maturity']['new']['data'][$item->getDomain()->getPosition()]['name'] = $item->getDomain()->getName(); @@ -281,7 +284,7 @@ class UserMetric implements MetricInterface } \ksort($data['maturity']['new']['data']); } - if (isset($maturity[1]) && null !== $maturity[0]->getReferentiel()) { + if (isset($maturity) && isset($maturity[1]) && null !== $maturity[0]->getReferentiel()) { $data['maturity']['old']['name'] = $maturity[1]->getCreatedAt()->format('d/m/Y'); foreach ($maturity[1]->getMaturity() as $item) { $data['maturity']['old']['data'][$item->getDomain()->getPosition()]['name'] = $item->getDomain()->getName(); -- GitLab