Passed
Push — static-analysis ( ae4331...8e814c )
by SignpostMarv
03:31
created

SchemaReaderFillAbstraction   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 60
Duplicated Lines 31.67 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 19
loc 60
ccs 29
cts 29
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
B fillTypeNode() 17 32 4
A fillItemNonLocalType() 0 19 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
abstract class SchemaReaderFillAbstraction extends SchemaReaderFindAbstraction
39
{
40
    /**
41
    * @param bool $checkAbstract
42
    */
43 135
    protected function fillTypeNode(Type $type, DOMElement $node, $checkAbstract = false)
44
    {
45
46 135
        if ($checkAbstract) {
47 135
            $type->setAbstract($node->getAttribute("abstract") === "true" || $node->getAttribute("abstract") === "1");
48 45
        }
49
50 90
        static $methods = [
51
            'restriction' => 'loadRestriction',
52
            'extension' => 'maybeLoadExtensionFromBaseComplexType',
53
            'simpleContent' => 'fillTypeNode',
54
            'complexContent' => 'fillTypeNode',
55 45
        ];
56
57 135
        $limit = $node->childNodes->length;
58 135 View Code Duplication
        for ($i = 0; $i < $limit; $i += 1) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
59
            /**
60
            * @var DOMNode $childNode
61
            */
62 135
            $childNode = $node->childNodes->item($i);
63
64
            /**
65
            * @var string[] $methods
66
            */
67 135
            $methods = $methods;
68
69 135
            $this->maybeCallMethod(
70 135
                $methods,
71 135
                $childNode->localName,
72 135
                $childNode,
73 135
                $type,
74 90
                $childNode
75 45
            );
76 45
        }
77 135
    }
78
79 135
    protected function fillItemNonLocalType(Item $element, DOMElement $node)
80
    {
81 135
        if ($node->getAttribute("type")) {
82
            /**
83
            * @var Type $type
84
            */
85 135
            $type = $this->findSomeType($element, $node, 'type');
86 45
        } else {
87
            /**
88
            * @var Type $type
89
            */
90 135
            $type = $this->findSomeTypeFromAttribute(
91 135
                $element,
92 135
                $node,
93 135
                ($node->lookupPrefix(self::XSD_NS) . ':anyType')
94 45
            );
95
        }
96
97 135
        $element->setType($type);
98 135
    }
99
}
100