From 872706857b3f9d63b8439535d6b2d8654759dd25 Mon Sep 17 00:00:00 2001 From: Thomas Peterson Date: Thu, 24 Jul 2025 12:37:08 +0200 Subject: [PATCH] Fixes --- cobertura.xml | 88 +++++++++++++++++++++++++++------- src/Option/Parser/Headline.php | 31 ++++++++---- src/Option/Type/Headline.php | 32 +++++++++++-- 3 files changed, 123 insertions(+), 28 deletions(-) diff --git a/cobertura.xml b/cobertura.xml index 7b3bd6c..3bad32c 100644 --- a/cobertura.xml +++ b/cobertura.xml @@ -1,6 +1,6 @@ - + /home/thomas/projekte/calc/src @@ -5742,9 +5742,9 @@ - + - + @@ -5758,13 +5758,25 @@ - - + + + - - + + + + + + + + + + + + + @@ -5775,13 +5787,21 @@ - - + + + - - + + + + + + + + + @@ -7268,24 +7288,58 @@ - + - + - + - + + + + + + + + + + + + + + + + + + + + + + - - + + + + + + + + + + + + + + + diff --git a/src/Option/Parser/Headline.php b/src/Option/Parser/Headline.php index 624d62c..46d2087 100644 --- a/src/Option/Parser/Headline.php +++ b/src/Option/Parser/Headline.php @@ -1,4 +1,5 @@ node->data) { - $this->element->setValue((string)$this->node->data); + if ($this->node->data) { + $this->element->setValue((string) $this->node->data); } - if($this->node['variant']) { - $this->element->setVariant((int)$this->node['variant']); + if ($this->node['variant']) { + $this->element->setVariant((int) $this->node['variant']); } - - if($this->element->getDefault() != null) { + if ($this->element->getDefault() != null) { $this->element->setValue($this->element->getDefault()); } - if($this->node->children()) { + if ($this->node->children()) { $edgeCollectionContainerParser = new EdgeCollectionContainer(); $edgeCollectionContainerParser->fromXML($this->node); $this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseXML()); @@ -40,4 +39,20 @@ class Headline extends Base return $this->element; } + public function parseJSON(): PSCHeadline + { + parent::parseJson(); + + if ($this->json['variant']) { + $this->element->setVariant((int) $this->json['variant']); + } + + if (isset($this->json['dependencys']) && count($this->json['dependencys']) > 0) { + $edgeCollectionContainerParser = new EdgeCollectionContainer(); + $edgeCollectionContainerParser->fromJson($this->json['dependencys']); + $this->element->setEdgesCollectionContainer($edgeCollectionContainerParser->parseJson()); + } + + return $this->element; + } } diff --git a/src/Option/Type/Headline.php b/src/Option/Type/Headline.php index 7b0c6a5..ce98668 100644 --- a/src/Option/Type/Headline.php +++ b/src/Option/Type/Headline.php @@ -1,17 +1,43 @@ variant = $variant; } - public function getVariant():int { + + public function getVariant(): int + { return $this->variant; } + + public function generateXML(): array + { + $tmp = []; + + $tmp = array_merge_recursive($tmp, ['_attributes' => [ + 'default' => $this->getDefault(), + ]]); + if ($this->getVariant()) { + $tmp = array_merge_recursive($tmp, ['_attributes' => [ + 'variant' => $this->getVariant(), + ]]); + } + return array_merge_recursive($tmp, parent::generateXML()); + } + + public function generateJson(): \stdClass + { + $obj = parent::generateJson(); + $obj->variant = $this->getVariant(); + $obj->type = 6; + return $obj; + } }