From 0dc62f4ba0f7e532e9c8409584fa2cfe29f09856 Mon Sep 17 00:00:00 2001 From: Beatrycze Volk <beatrycze.volk@slub-dresden.de> Date: Tue, 24 Oct 2023 11:50:50 +0200 Subject: [PATCH] Check for array before passing to foreach loop --- Classes/Model/Score.php | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/Classes/Model/Score.php b/Classes/Model/Score.php index ce581ac..745c113 100644 --- a/Classes/Model/Score.php +++ b/Classes/Model/Score.php @@ -89,16 +89,22 @@ class Score */ public function __construct($score) { - foreach ($score->title as $title) { - $this->titleArticles[] = new Article($title); + if (is_array($score->title) || is_object($score->title)) { + foreach ($score->title as $title) { + $this->titleArticles[] = new Article($title); + } } - foreach ($score->abstract as $abstract) { - $this->abstractArticles[] = new Article($abstract); + if (is_array($score->abstract) || is_object($score->abstract)) { + foreach ($score->abstract as $abstract) { + $this->abstractArticles[] = new Article($abstract); + } } - foreach ($score->dois as $doi) { - $this->referenceArticles[] = new Article($doi); + if (is_array($score->dois) || is_object($score->dois)) { + foreach ($score->dois as $doi) { + $this->referenceArticles[] = new Article($doi); + } } $this->semanticScore = $score->semantic_score; -- GitLab