Test Setup Failed
Push — static-analysis ( af1336...1f5c7e )
by SignpostMarv
06:23
created

AttributesTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 88
Duplicated Lines 36.36 %

Importance

Changes 0
Metric Value
wmc 2
dl 32
loc 88
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B testAnonym() 32 32 1
A testBase() 0 49 1

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\Tests;
3
4
class AttributesTest extends BaseTest
5
{
6
7
8
    public function testBase()
9
    {
10
11
        $schema = $this->reader->readString(
12
            '
13
            <xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
14
                <xs:attribute name="myAttribute" type="xs:string"></xs:attribute>
15
                <xs:attribute name="myAttributeOptions" type="xs:string" use="reuqired" nil="true"></xs:attribute>
16
17
                <xs:attributeGroup name="myAttributeGroup">
18
                    <xs:attribute name="alone" type="xs:string"></xs:attribute>
19
                    <xs:attribute ref="ex:myAttribute"></xs:attribute>
20
                    <xs:attributeGroup ref="ex:myAttributeGroup2"></xs:attributeGroup>
21
                </xs:attributeGroup>
22
23
                <xs:attributeGroup name="myAttributeGroup2">
24
                    <xs:attribute name="alone2" type="xs:string"></xs:attribute>
25
                </xs:attributeGroup>
26
            </xs:schema>');
27
28
        $myAttribute = $schema->findAttribute('myAttribute', 'http://www.example.com');
29
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeDef', $myAttribute);
30
        //$this->assertEquals('http://www.example.com', $myAttribute->getSchema()->getTargetNamespace());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
31
        $this->assertEquals('myAttribute', $myAttribute->getName());
32
        $this->assertEquals("string", $myAttribute->getType()->getName());
0 ignored issues
show
Bug introduced by
The method getType() does not exist on GoetasWebservices\XML\XS...Attribute\AttributeItem. It seems like you code against a sub-type of GoetasWebservices\XML\XS...Attribute\AttributeItem such as GoetasWebservices\XML\XS...\Attribute\AttributeDef or GoetasWebservices\XML\XS...tribute\AttributeSingle. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

32
        $this->assertEquals("string", $myAttribute->/** @scrutinizer ignore-call */ getType()->getName());
Loading history...
33
34
35
        $base1 = $myAttribute->getType();
36
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base1);
37
        $this->assertEquals('http://www.w3.org/2001/XMLSchema', $base1->getSchema()->getTargetNamespace());
38
        $this->assertEquals('string', $base1->getName());
39
40
        $myAttributeGroup = $schema->findAttributeGroup('myAttributeGroup', 'http://www.example.com');
41
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\Group', $myAttributeGroup);
42
        //$this->assertEquals('http://www.example.com', $myAttribute->getSchema()->getTargetNamespace());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
43
        $this->assertEquals('myAttributeGroup', $myAttributeGroup->getName());
44
        $attributesInGroup = $myAttributeGroup->getAttributes();
45
        $this->assertCount(3, $attributesInGroup);
46
47
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\Attribute', $attributesInGroup[0]);
48
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeDef', $attributesInGroup[1]);
49
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\Group', $attributesInGroup[2]);
50
51
52
        $myAttribute = $schema->findAttribute('myAttributeOptions', 'http://www.example.com');
53
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeDef', $myAttribute);
54
        //$this->assertEquals('http://www.example.com', $myAttribute->getSchema()->getTargetNamespace());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
        $this->assertEquals('myAttributeOptions', $myAttribute->getName());
56
        $this->assertEquals("string", $myAttribute->getType()->getName());
57
58
    }
59
60 View Code Duplication
    public function testAnonym()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
61
    {
62
        $schema = $this->reader->readString(
63
            '
64
            <xs:schema targetNamespace="http://www.example.com" xmlns:xs="http://www.w3.org/2001/XMLSchema">
65
66
                <xs:attribute name="myAttributeAnonType">
67
                    <xs:simpleType>
68
                        <xs:restriction base="xs:string"></xs:restriction>
69
                    </xs:simpleType>
70
                </xs:attribute>
71
72
            </xs:schema>');
73
74
75
        $myAttributeAnon = $schema->findAttribute('myAttributeAnonType', 'http://www.example.com');
76
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Attribute\AttributeDef', $myAttributeAnon);
77
        //$this->assertEquals('http://www.example.com', $myAttribute->getSchema()->getTargetNamespace());
0 ignored issues
show
Unused Code Comprehensibility introduced by
78% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
78
        $this->assertEquals('myAttributeAnonType', $myAttributeAnon->getName());
79
        $this->assertNull($myAttributeAnon->getType()->getName());
80
81
        $base2 = $myAttributeAnon->getType();
82
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base2);
83
        $this->assertEquals('http://www.example.com', $base2->getSchema()->getTargetNamespace());
84
        $this->assertTrue(!$base2->getName());
85
86
87
        $restriction1 = $base2->getRestriction();
88
        $base3 = $restriction1->getBase();
89
        $this->assertInstanceOf('GoetasWebservices\XML\XSDReader\Schema\Type\SimpleType', $base3);
90
        $this->assertEquals('http://www.w3.org/2001/XMLSchema', $base3->getSchema()->getTargetNamespace());
91
        $this->assertEquals('string', $base3->getName());
92
    }
93
}
94