From 3ae23e701053c2407abdbfb3f5b548d6a4e6601d Mon Sep 17 00:00:00 2001 From: Toon Verwerft Date: Fri, 26 Jul 2024 15:34:20 +0200 Subject: [PATCH 1/2] Detect element information --- src/Schema/Element/Any/Any.php | 65 ++++++++++++ src/Schema/Element/Any/ProcessContents.php | 15 +++ src/SchemaReader.php | 61 +++++++++++ tests/AnyTest.php | 113 +++++++++++++++++++++ 4 files changed, 254 insertions(+) create mode 100644 src/Schema/Element/Any/Any.php create mode 100644 src/Schema/Element/Any/ProcessContents.php create mode 100644 tests/AnyTest.php diff --git a/src/Schema/Element/Any/Any.php b/src/Schema/Element/Any/Any.php new file mode 100644 index 0000000..9c65e5f --- /dev/null +++ b/src/Schema/Element/Any/Any.php @@ -0,0 +1,65 @@ +schema = $schema; + } + + public function getName(): string + { + return 'any'; + } + + public function getNamespace(): ?string + { + return $this->namespace; + } + + public function setNamespace(?string $namespace): void + { + $this->namespace = $namespace; + } + + public function getProcessContents(): ProcessContents + { + return $this->processContents; + } + + public function setProcessContents(ProcessContents $processContents): void + { + $this->processContents = $processContents; + } + + public function getId(): ?string + { + return $this->id; + } + + public function setId(?string $id): void + { + $this->id = $id; + } +} diff --git a/src/Schema/Element/Any/ProcessContents.php b/src/Schema/Element/Any/ProcessContents.php new file mode 100644 index 0000000..e397ec5 --- /dev/null +++ b/src/Schema/Element/Any/ProcessContents.php @@ -0,0 +1,15 @@ +loadSequenceChildNodeLoadAny( + $elementContainer, + $node, + $childNode, + $max, + $min + ); + break; } } @@ -535,6 +546,26 @@ private function loadSequenceChildNodeLoadElement( $elementContainer->addElement($element); } + private function loadSequenceChildNodeLoadAny( + ElementContainer $elementContainer, + \DOMElement $node, + \DOMElement $childNode, + ?int $max, + ?int $min + ): void { + $schema = $elementContainer->getSchema(); + $element = $this->createAnyElement($schema, $childNode); + + if (null !== $min) { + $element->setMin($min); + } + + if (null !== $max && 1 < $max) { + $element->setMax($max); + } + $elementContainer->addElement($element); + } + private function resolveSubstitutionGroup( Schema $schema, \DOMElement $node, @@ -1489,6 +1520,36 @@ private function fillElement(AbstractElementSingle $element, \DOMElement $node): $element->setCustomAttributes($this->loadCustomAttributesForElement($element, $node)); } + private function createAnyElement(Schema $schema, \DOMElement $node): Any + { + $element = new Any($schema); + $this->fillAnyElement($element, $node); + + return $element; + } + + private function fillAnyElement(Any $element, \DOMElement $node): void + { + self::maybeSetMax($element, $node); + self::maybeSetMin($element, $node); + + if ($node->hasAttribute('id')) { + $element->setId($node->getAttribute('id')); + } + + if ($node->hasAttribute('namespace')) { + $element->setNamespace($node->getAttribute('namespace')); + } + + if ($node->hasAttribute('processContents')) { + $element->setProcessContents( + ProcessContents::tryFrom($node->getAttribute('processContents')) ?? ProcessContents::default() + ); + } + + $element->setDoc($this->getDocumentation($node)); + } + private function addAttributeFromAttributeOrRef( BaseComplexType $type, \DOMElement $childNode, diff --git a/tests/AnyTest.php b/tests/AnyTest.php new file mode 100644 index 0000000..d5b352c --- /dev/null +++ b/tests/AnyTest.php @@ -0,0 +1,113 @@ +reader->readString( + ' + + + + + + + + + ' + ); + + $myElement = $schema->findElement('customerData', 'http://www.example.com'); + $myType = $myElement->getType(); + + self::assertInstanceOf(ComplexType::class, $myType); + + $elements = $myType->getElements(); + + self::assertCount(1, $elements); + self::assertInstanceOf(Any::class, $any = $elements[0]); + + self::assertSame($schema, $any->getSchema()); + self::assertSame('any', $any->getName()); + self::assertNull($any->getNamespace()); + self::assertSame(ProcessContents::Strict, $any->getProcessContents()); + self::assertNull($any->getId()); + self::assertSame(1, $any->getMin()); + self::assertSame(1, $any->getMax()); + self::assertSame('', $any->getDoc()); + } + + public function testAllArgsSet(): void + { + $schema = $this->reader->readString( + ' + + + + + + + Any description + + + + + + ' + ); + + $myElement = $schema->findElement('customerData', 'http://www.example.com'); + $myType = $myElement->getType(); + + self::assertInstanceOf(ComplexType::class, $myType); + + $elements = $myType->getElements(); + + self::assertCount(1, $elements); + self::assertInstanceOf(Any::class, $any = $elements[0]); + + self::assertSame($schema, $any->getSchema()); + self::assertSame('any', $any->getName()); + self::assertSame('##any', $any->getNamespace()); + self::assertSame(ProcessContents::Lax, $any->getProcessContents()); + self::assertSame('hello', $any->getId()); + self::assertSame(0, $any->getMin()); + self::assertSame(2, $any->getMax()); + self::assertSame('Any description', $any->getDoc()); + } + + public function testCombinationWithOtherElements(): void + { + $schema = $this->reader->readString( + ' + + + + + + + + + + + ' + ); + + $myElement = $schema->findElement('customerData', 'http://www.example.com'); + $myType = $myElement->getType(); + + self::assertInstanceOf(ComplexType::class, $myType); + + $elements = $myType->getElements(); + + self::assertCount(3, $elements); + self::assertInstanceOf(Any::class, $any = $elements[2]); + } +} From 4a0d976957534197b2b178d20461838ac51796d8 Mon Sep 17 00:00:00 2001 From: Github Actions Bot <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 30 Aug 2024 09:33:36 +0000 Subject: [PATCH 2/2] Update code coverage badge --- clover.xml | 2133 +++++++++++++++++++++++++++------------------------- 1 file changed, 1098 insertions(+), 1035 deletions(-) diff --git a/clover.xml b/clover.xml index 879a96d..894aae3 100644 --- a/clover.xml +++ b/clover.xml @@ -1,6 +1,6 @@ - - + + @@ -8,17 +8,17 @@ - - - - - - - - - - - + + + + + + + + + + + @@ -37,15 +37,15 @@ - - - + + + - - - - + + + + @@ -58,20 +58,20 @@ - - + + - - + + - - + + @@ -87,8 +87,8 @@ - - + + @@ -106,9 +106,9 @@ - - - + + + @@ -151,8 +151,8 @@ - - + + @@ -161,24 +161,24 @@ - - - - - - + + + + + + - - - - - - - - + + + + + + + + @@ -193,6 +193,36 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -212,10 +242,10 @@ - - - - + + + + @@ -239,13 +269,13 @@ - - - + + + - - + + @@ -263,17 +293,17 @@ - - - - - - - - - - - + + + + + + + + + + + @@ -306,14 +336,14 @@ - - - - - - - - + + + + + + + + @@ -340,9 +370,9 @@ - - - + + + @@ -355,8 +385,8 @@ - - + + @@ -370,158 +400,158 @@ - - - - - - - + + + + + + + - - - - + + + + - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - + + + + + + + + + - - - - - - - - - - - - + + + + + + + + + + + + - - + + - - - - - - - - - - - + + + + + + + + + + + - + - - - - - - - + + + + + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - + + + - - - - + + + + - - - - + + + + - - - - + + + + - - - - + + + + - + @@ -531,12 +561,12 @@ - - - - - - + + + + + + @@ -551,9 +581,9 @@ - - - + + + @@ -566,884 +596,917 @@ - - + + - - + + - - - - - + + + + + - - + + - - + + - - + + - + - - + - - - + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - + + - - + + @@ -1489,6 +1552,6 @@ - +