Passed
Push — static-analysis ( c3aabf...c8fdad )
by SignpostMarv
03:22
created

SchemaReader::loadSequenceChildNode()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 38
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 24
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 19
nc 1
nop 4
dl 0
loc 38
ccs 24
cts 24
cp 1
crap 1
rs 8.8571
c 0
b 0
f 0
1
<?php
2
namespace GoetasWebservices\XML\XSDReader;
3
4
use Closure;
5
use DOMDocument;
6
use DOMElement;
7
use DOMNode;
8
use DOMNodeList;
9
use GoetasWebservices\XML\XSDReader\Exception\IOException;
10
use GoetasWebservices\XML\XSDReader\Exception\TypeException;
11
use GoetasWebservices\XML\XSDReader\Schema\Attribute\Attribute;
12
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeDef;
13
use GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeItem;
14
use GoetasWebservices\XML\XSDReader\Schema\Attribute\Group as AttributeGroup;
15
use GoetasWebservices\XML\XSDReader\Schema\Element\Element;
16
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementContainer;
17
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementDef;
18
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementItem;
19
use GoetasWebservices\XML\XSDReader\Schema\Element\ElementRef;
20
use GoetasWebservices\XML\XSDReader\Schema\Element\Group;
21
use GoetasWebservices\XML\XSDReader\Schema\Element\GroupRef;
22
use GoetasWebservices\XML\XSDReader\Schema\Element\InterfaceSetMinMax;
23
use GoetasWebservices\XML\XSDReader\Schema\Exception\TypeNotFoundException;
24
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Base;
25
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Extension;
26
use GoetasWebservices\XML\XSDReader\Schema\Inheritance\Restriction;
27
use GoetasWebservices\XML\XSDReader\Schema\Item;
28
use GoetasWebservices\XML\XSDReader\Schema\Schema;
29
use GoetasWebservices\XML\XSDReader\Schema\SchemaItem;
30
use GoetasWebservices\XML\XSDReader\Schema\Type\BaseComplexType;
31
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexType;
32
use GoetasWebservices\XML\XSDReader\Schema\Type\ComplexTypeSimpleContent;
33
use GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType;
34
use GoetasWebservices\XML\XSDReader\Schema\Type\Type;
35
use GoetasWebservices\XML\XSDReader\Utils\UrlUtils;
36
use RuntimeException;
37
38
class SchemaReader extends SchemaReaderLoadAbstraction
39
{
40
    /**
41
    * @param string $typeName
42
    *
43
    * @return mixed[]
44
    */
45 135
    protected static function splitParts(DOMElement $node, $typeName)
46
    {
47 135
        $prefix = null;
48 135
        $name = $typeName;
49 135
        if (strpos($typeName, ':') !== false) {
50 135
            list ($prefix, $name) = explode(':', $typeName);
51 45
        }
52
53 135
        $namespace = $node->lookupNamespaceUri($prefix ?: '');
54
        return array(
55 135
            $name,
56 135
            $namespace,
57 90
            $prefix
58 45
        );
59
    }
60
61
    /**
62
     * It is possible that a single file contains multiple <xsd:schema/> nodes, for instance in a WSDL file.
63
     *
64
     * Each of these  <xsd:schema/> nodes typically target a specific namespace. Append the target namespace to the
65
     * file to distinguish between multiple schemas in a single file.
66
     *
67
     * @param string $file
68
     * @param string $targetNamespace
69
     *
70
     * @return string
71
     */
72 135
    protected function getNamespaceSpecificFileIndex($file, $targetNamespace)
73
    {
74 135
        return $file . '#' . $targetNamespace;
75
    }
76
77
    /**
78
     * @param string $file
79
     *
80
     * @return DOMDocument
81
     *
82
     * @throws IOException
83
     */
84 135
    protected function getDOM($file)
85
    {
86 135
        $xml = new DOMDocument('1.0', 'UTF-8');
87 135
        if (!$xml->load($file)) {
88
            throw new IOException("Can't load the file $file");
89
        }
90 135
        return $xml;
91
    }
92
}
93