diff --git a/.travis.yml b/.travis.yml
index dd4f23ca..6025a420 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,4 +1,5 @@
language: php
+
sudo: false
php:
diff --git a/composer.json b/composer.json
index db8064b9..5ab340ec 100644
--- a/composer.json
+++ b/composer.json
@@ -16,7 +16,10 @@
}
],
"config": {
- "sort-packages": true
+ "sort-packages": true,
+ "allow-plugins": {
+ "composer/package-versions-deprecated": true
+ }
},
"require" : {
"php": "^7.1|^8.0"
diff --git a/src/Documentation/StandardDocumentationReader.php b/src/Documentation/StandardDocumentationReader.php
index efa3c44d..edef2aa1 100644
--- a/src/Documentation/StandardDocumentationReader.php
+++ b/src/Documentation/StandardDocumentationReader.php
@@ -23,7 +23,7 @@ public function get(DOMElement $node): string
foreach ($childNode->childNodes as $subChildNode) {
if ($subChildNode instanceof DOMElement && $subChildNode->localName == 'documentation') {
if (!empty($doc)) {
- $doc .= "\n" . ($subChildNode->nodeValue);
+ $doc .= "\n".($subChildNode->nodeValue);
} else {
$doc .= ($subChildNode->nodeValue);
}
diff --git a/src/Schema/Element/ElementSingle.php b/src/Schema/Element/ElementSingle.php
index 9795b961..a53fd2b6 100644
--- a/src/Schema/Element/ElementSingle.php
+++ b/src/Schema/Element/ElementSingle.php
@@ -8,7 +8,7 @@
interface ElementSingle extends ElementItem, InterfaceSetMinMax, InterfaceSetDefault
{
- public function getType(): ? Type;
+ public function getType(): ?Type;
public function isQualified(): bool;
diff --git a/src/Schema/Inheritance/Base.php b/src/Schema/Inheritance/Base.php
index 8d5c5d08..017bc003 100644
--- a/src/Schema/Inheritance/Base.php
+++ b/src/Schema/Inheritance/Base.php
@@ -13,7 +13,7 @@ abstract class Base
*/
protected $base;
- public function getBase(): ? Type
+ public function getBase(): ?Type
{
return $this->base;
}
diff --git a/src/Schema/Inheritance/Restriction.php b/src/Schema/Inheritance/Restriction.php
index 05d88593..b65cff6f 100644
--- a/src/Schema/Inheritance/Restriction.php
+++ b/src/Schema/Inheritance/Restriction.php
@@ -32,6 +32,6 @@ public function getChecks(): array
*/
public function getChecksByType(string $type): array
{
- return isset($this->checks[$type]) ? $this->checks[$type] : [];
+ return $this->checks[$type] ?? [];
}
}
diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php
index 6d6283fc..2d4c55b8 100644
--- a/src/Schema/Schema.php
+++ b/src/Schema/Schema.php
@@ -24,7 +24,7 @@ protected function findSomethingNoThrow(
string $name,
string $namespace = null,
array &$calling = []
- ): ? SchemaItem {
+ ): ?SchemaItem {
$calling[spl_object_hash($this)] = true;
$cid = "$getter, $name, $namespace";
@@ -64,7 +64,7 @@ protected function findSomethingNoThrowSchemas(
string $name,
string $namespace = null,
array &$calling = []
- ): ? SchemaItem {
+ ): ?SchemaItem {
foreach ($schemas as $childSchema) {
if (!isset($calling[spl_object_hash($childSchema)])) {
/**
@@ -182,7 +182,7 @@ public function getTargetNamespace(): ?string
return $this->targetNamespace;
}
- public function setTargetNamespace(? string $targetNamespace): void
+ public function setTargetNamespace(?string $targetNamespace): void
{
$this->targetNamespace = $targetNamespace;
}
@@ -318,7 +318,7 @@ public function getType(string $name): ?Type
return null;
}
- public function getAttribute(string $name): ? AttributeItem
+ public function getAttribute(string $name): ?AttributeItem
{
if (isset($this->attributes[$name])) {
return $this->attributes[$name];
diff --git a/src/SchemaReader.php b/src/SchemaReader.php
index 651c5f9f..d6e399a0 100644
--- a/src/SchemaReader.php
+++ b/src/SchemaReader.php
@@ -338,7 +338,7 @@ private static function maybeSetDefault(InterfaceSetDefault $ref, DOMElement $no
}
}
- private function loadSequence(ElementContainer $elementContainer, DOMElement $node, int $max = null): void
+ private function loadSequence(ElementContainer $elementContainer, DOMElement $node, int $max = null, int $min = null): void
{
$max =
(
@@ -348,6 +348,13 @@ private function loadSequence(ElementContainer $elementContainer, DOMElement $no
)
? 2
: null;
+ $min =
+ (
+ $min === null &&
+ !$node->hasAttribute('minOccurs')
+ )
+ ? null
+ : (int) max((int) $min, $node->getAttribute('minOccurs'));
self::againstDOMNodeList(
$node,
@@ -356,13 +363,15 @@ function (
DOMElement $childNode
) use (
$elementContainer,
- $max
+ $max,
+ $min
): void {
$this->loadSequenceChildNode(
$elementContainer,
$node,
$childNode,
- $max
+ $max,
+ $min
);
}
);
@@ -372,7 +381,8 @@ private function loadSequenceChildNode(
ElementContainer $elementContainer,
DOMElement $node,
DOMElement $childNode,
- ? int $max
+ ?int $max,
+ ?int $min = null
): void {
switch ($childNode->localName) {
case 'sequence':
@@ -381,7 +391,8 @@ private function loadSequenceChildNode(
$this->loadSequence(
$elementContainer,
$childNode,
- $max
+ $max,
+ $min
);
break;
case 'element':
@@ -389,7 +400,8 @@ private function loadSequenceChildNode(
$elementContainer,
$node,
$childNode,
- $max
+ $max,
+ $min
);
break;
case 'group':
@@ -407,7 +419,8 @@ private function loadSequenceChildNodeLoadElement(
ElementContainer $elementContainer,
DOMElement $node,
DOMElement $childNode,
- ? int $max
+ ?int $max,
+ ?int $min
): void {
if ($childNode->hasAttribute('ref')) {
$elementDef = $this->findElement($elementContainer->getSchema(), $node, $childNode->getAttribute('ref'));
@@ -436,6 +449,11 @@ private function loadSequenceChildNodeLoadElement(
$childNode
);
}
+
+ if ($min !== null) {
+ $element->setMin($min);
+ }
+
if ($max > 1) {
/*
* although one might think the typecast is not needed with $max being `? int $max` after passing > 1,
@@ -897,7 +915,7 @@ private static function splitParts(DOMElement $node, string $typeName): array
$prefix = null;
$name = $typeName;
if (strpos($typeName, ':') !== false) {
- list($prefix, $name) = explode(':', $typeName);
+ [$prefix, $name] = explode(':', $typeName);
}
/**
@@ -914,7 +932,7 @@ private static function splitParts(DOMElement $node, string $typeName): array
private function findAttributeItem(Schema $schema, DOMElement $node, string $typeName): AttributeItem
{
- list($name, $namespace) = static::splitParts($node, $typeName);
+ [$name, $namespace] = static::splitParts($node, $typeName);
/**
* @var string|null $namespace
@@ -935,7 +953,7 @@ private function findAttributeItem(Schema $schema, DOMElement $node, string $typ
private function findAttributeGroup(Schema $schema, DOMElement $node, string $typeName): AttributeGroup
{
- list($name, $namespace) = static::splitParts($node, $typeName);
+ [$name, $namespace] = static::splitParts($node, $typeName);
/**
* @var string|null $namespace
@@ -956,7 +974,7 @@ private function findAttributeGroup(Schema $schema, DOMElement $node, string $ty
private function findElement(Schema $schema, DOMElement $node, string $typeName): ElementDef
{
- list($name, $namespace) = static::splitParts($node, $typeName);
+ [$name, $namespace] = static::splitParts($node, $typeName);
/**
* @var string|null $namespace
@@ -972,7 +990,7 @@ private function findElement(Schema $schema, DOMElement $node, string $typeName)
private function findGroup(Schema $schema, DOMElement $node, string $typeName): Group
{
- list($name, $namespace) = static::splitParts($node, $typeName);
+ [$name, $namespace] = static::splitParts($node, $typeName);
/**
* @var string|null $namespace
@@ -993,7 +1011,7 @@ private function findGroup(Schema $schema, DOMElement $node, string $typeName):
private function findType(Schema $schema, DOMElement $node, string $typeName): SchemaItem
{
- list($name, $namespace) = static::splitParts($node, $typeName);
+ [$name, $namespace] = static::splitParts($node, $typeName);
/**
* @var string|null $namespace
@@ -1147,9 +1165,8 @@ private function loadImportFresh(
): Closure {
return function () use ($namespace, $schema, $file): void {
$dom = $this->getDOM(
- isset($this->knownLocationSchemas[$file])
- ? $this->knownLocationSchemas[$file]
- : $file
+ $this->knownLocationSchemas[$file]
+ ?? $file
);
$schemaNew = $this->createOrUseSchemaForNs($schema, $namespace);
diff --git a/tests/FilesystemTest.php b/tests/FilesystemTest.php
index ef6e77c4..78845a71 100644
--- a/tests/FilesystemTest.php
+++ b/tests/FilesystemTest.php
@@ -11,7 +11,7 @@ class FilesystemTest extends BaseTest
*
* Covers the issue described in {@link https://github.com/goetas/xsd-reader/pull/10 PR #10}.
*/
- public function testReferencedOnFileSystem_1()
+ public function testReferencedOnFileSystem1()
{
/*
* Using vfsStream seems ideal, but currently seems to have an issue with directorypaths with a space in
diff --git a/tests/RestrictionsTest.php b/tests/RestrictionsTest.php
index 3782b727..962e0c39 100644
--- a/tests/RestrictionsTest.php
+++ b/tests/RestrictionsTest.php
@@ -12,7 +12,7 @@ class RestrictionsTest extends BaseTest
/**
* Test the correct detection an Enumeration-restriction.
*/
- public function testRestriction_1()
+ public function testRestriction1()
{
$schema = $this->reader->readString(
'
@@ -52,7 +52,7 @@ public function testRestriction_1()
/**
* Test the correct detection a pattern-restriction.
*/
- public function testRestriction_2()
+ public function testRestriction2()
{
$schema = $this->reader->readString(
'
@@ -87,7 +87,7 @@ public function testRestriction_2()
/**
* Test the correct detection a length-restriction.
*/
- public function testRestriction_3()
+ public function testRestriction3()
{
$schema = $this->reader->readString(
'
@@ -122,7 +122,7 @@ public function testRestriction_3()
/**
* Test the correct detection a minLength- and maxLength-restriction.
*/
- public function testRestriction_4()
+ public function testRestriction4()
{
$schema = $this->reader->readString(
'
@@ -164,7 +164,7 @@ public function testRestriction_4()
/**
* Test the correct detection a minInclusive- and maxInclusive-restriction.
*/
- public function testRestriction_5()
+ public function testRestriction5()
{
$schema = $this->reader->readString(
'
@@ -206,7 +206,7 @@ public function testRestriction_5()
/**
* Test the correct detection a minExclusive- and maxExclusive-restriction.
*/
- public function testRestriction_6()
+ public function testRestriction6()
{
$schema = $this->reader->readString(
'
@@ -248,7 +248,7 @@ public function testRestriction_6()
/**
* Test the correct detection a fractionDigits-restriction.
*/
- public function testRestriction_7()
+ public function testRestriction7()
{
$schema = $this->reader->readString(
'
@@ -283,7 +283,7 @@ public function testRestriction_7()
/**
* Test the correct detection a totalDigits-restriction.
*/
- public function testRestriction_8()
+ public function testRestriction8()
{
$schema = $this->reader->readString(
'
@@ -318,7 +318,7 @@ public function testRestriction_8()
/**
* Test the correct detection a totalDigits- and fractionDigits-restriction.
*/
- public function testRestriction_9()
+ public function testRestriction9()
{
$schema = $this->reader->readString(
'
@@ -360,7 +360,7 @@ public function testRestriction_9()
/**
* Test the correct detection a whiteSpace-restriction.
*/
- public function testRestriction_10()
+ public function testRestriction10()
{
$schema = $this->reader->readString(
'
diff --git a/tests/TypesTest.php b/tests/TypesTest.php
index 3934fb54..0d8bab8b 100644
--- a/tests/TypesTest.php
+++ b/tests/TypesTest.php
@@ -140,6 +140,65 @@ public function testElementMaxOccurences($xml, $expected)
$this->assertEquals($expected, $elements[0]->getMax());
}
+ /**
+ * @dataProvider getMinOccurencesOverride
+ */
+ public function testSequencMinOccursOverride($xml, $expected)
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+ ');
+
+ $complex = $schema->findType('complexType', 'http://www.example.com');
+ $elements = $complex->getElements();
+ $this->assertEquals($expected, $elements[0]->getMin());
+ }
+
+ public function getMinOccurencesOverride()
+ {
+ return [
+ ['2', 2],
+ ['1', 1],
+ ['0', 0],
+ ];
+ }
+
+ /**
+ * @dataProvider getMaxOccurencesOverride
+ */
+ public function testSequencMaxOccursOverride($xml, $expected)
+ {
+ $schema = $this->reader->readString(
+ '
+
+
+
+
+
+
+ ');
+
+ $complex = $schema->findType('complexType', 'http://www.example.com');
+ $elements = $complex->getElements();
+ $this->assertEquals($expected, $elements[0]->getMax());
+ }
+
+ public function getMaxOccurencesOverride()
+ {
+ return [
+ ['0', 5], //maxOccurs=0 is ignored
+ ['1', 5],
+ ['2', 2], // 2 in this case just means "many"
+ ['unbounded', 2], // 2 in this case just means "many"
+ ];
+ }
+
public function getMinOccurences()
{
return [