From 85ad54f91ce1f2d7a170f8933f4c7fe6a4e99fde Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Fri, 22 Oct 2021 09:23:39 +0200 Subject: [PATCH 1/3] feat: add all report messages to help logs --- common/report/class.Report.php | 14 ++++++++++++++ test/unit/ReportTest.php | 12 ++++++++++++ 2 files changed, 26 insertions(+) diff --git a/common/report/class.Report.php b/common/report/class.Report.php index c4a5af576..13b17bca0 100755 --- a/common/report/class.Report.php +++ b/common/report/class.Report.php @@ -141,6 +141,20 @@ public function getMessage(): string return $this->message; } + public function getAllMessages(): string + { + $messages = [$this->getMessage()]; + + array_map( + function (Report $child) use (&$messages) { + $messages[] = $child->getAllMessages(); + }, + $this->children + ); + + return implode(', ', $messages); + } + /** * Update message of the report * diff --git a/test/unit/ReportTest.php b/test/unit/ReportTest.php index 9c3edb077..8a58916ba 100644 --- a/test/unit/ReportTest.php +++ b/test/unit/ReportTest.php @@ -378,4 +378,16 @@ public function testCreateWithInterpolation(): void self::assertSame('my data test', $unSerialized->getMessage()); self::assertSame('my data test', $unSerialized->translateMessage()); } + + public function testGetAllMessages(): void + { + $report = Report::createInfo('1') + ->add( + Report::createSuccess('2') + ->add(Report::createWarning('3') + ) + ); + + self::assertEquals('1, 2, 3', $report->getAllMessages()); + } } From 2f10a6e5faf94692d261a8f02d69bbb6ab1db014 Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Fri, 22 Oct 2021 11:20:02 +0200 Subject: [PATCH 2/3] feat: add methods to make easier access properties values and domain --- core/kernel/classes/class.Property.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/core/kernel/classes/class.Property.php b/core/kernel/classes/class.Property.php index 07c4d5988..f8e1c031c 100644 --- a/core/kernel/classes/class.Property.php +++ b/core/kernel/classes/class.Property.php @@ -155,6 +155,17 @@ public function getDomain() return $returnValue; } + public function getRelatedClass(): ?core_kernel_classes_Class + { + try { + $class = $this->getDomain()->get(0); + + return $class instanceof core_kernel_classes_Class ? $class : null; + } catch (common_Exception $exception) { + return null; + } + } + /** * Short description of method setDomain * @@ -227,6 +238,17 @@ public function setRange(core_kernel_classes_Class $class) return (bool) $returnValue; } + public function getAlias(): ?string + { + $container = $this->getOnePropertyValue($this->getProperty(GenerisRdf::PROPERTY_ALIAS)); + + if ($container instanceof core_kernel_classes_Literal) { + return $container->__toString(); + } + + return null; + } + public function getDependsOnPropertyCollection(): DependsOnPropertyCollection { if (!isset($this->dependsOnPropertyCollection)) { From d8bfc681ab4e4bde5c82ea036340e8d45b7141cb Mon Sep 17 00:00:00 2001 From: Gabriel Felipe Soares Date: Fri, 22 Oct 2021 11:52:00 +0200 Subject: [PATCH 3/3] refactor: reduce complexity --- common/report/class.Report.php | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/common/report/class.Report.php b/common/report/class.Report.php index 13b17bca0..460d520f0 100755 --- a/common/report/class.Report.php +++ b/common/report/class.Report.php @@ -145,12 +145,9 @@ public function getAllMessages(): string { $messages = [$this->getMessage()]; - array_map( - function (Report $child) use (&$messages) { - $messages[] = $child->getAllMessages(); - }, - $this->children - ); + foreach ($this->children as $child) { + $messages[] = $child->getAllMessages(); + } return implode(', ', $messages); }