NodeTest   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 179
Duplicated Lines 43.58 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 78
loc 179
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A shouldGetTypeForSimpleType() 0 11 1
A shouldGetNameForArray() 0 11 1
A shouldReturnFalseWhenTypeIsNotArray() 0 11 1
A shouldReturnTrueWhenTypeIsArray() 0 11 1
A shouldReturnFalseWhenTypeIsNotObject() 0 11 1
A shouldGetTypeForObjectType() 14 14 1
A shouldReturnName() 11 11 1
A shouldGetSanitizedName() 11 11 1
A shouldGetNameForObject() 14 14 1
A shouldSingularizeeNameForObject() 14 14 1
A shouldReturnTrueWhenTypeIsObject() 14 14 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
/**
3
 * Copyright (C) 2013-2020
4
 * Piotr Olaszewski <[email protected]>
5
 *
6
 * Permission is hereby granted, free of charge, to any person obtaining a copy
7
 * of this software and associated documentation files (the "Software"), to deal
8
 * in the Software without restriction, including without limitation the rights
9
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
 * copies of the Software, and to permit persons to whom the Software is
11
 * furnished to do so, subject to the following conditions:
12
 *
13
 * The above copyright notice and this permission notice shall be included in
14
 * all copies or substantial portions of the Software.
15
 *
16
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
 * SOFTWARE.
23
 */
24
namespace Tests\WSDL\Parser;
25
26
use PHPUnit\Framework\TestCase;
27
use WSDL\Parser\Node;
28
29
/**
30
 * NodeTest
31
 *
32
 * @author Piotr Olaszewski <[email protected]>
33
 */
34
class NodeTest extends TestCase
35
{
36
    /**
37
     * @test
38
     */
39
    public function shouldGetTypeForSimpleType()
40
    {
41
        //given
42
        $node = new Node('int', '$age', false);
43
44
        //when
45
        $type = $node->getType();
46
47
        //then
48
        $this->assertEquals('int', $type);
49
    }
50
51
    /**
52
     * @test
53
     */
54 View Code Duplication
    public function shouldGetTypeForObjectType()
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...
55
    {
56
        //given
57
        $elements = [
58
            new Node('string', '$name', false)
59
        ];
60
        $node = new Node('object', '$user', false, $elements);
61
62
        //when
63
        $type = $node->getType();
64
65
        //then
66
        $this->assertEquals('object', $type);
67
    }
68
69
    /**
70
     * @test
71
     */
72 View Code Duplication
    public function shouldReturnName()
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...
73
    {
74
        //given
75
        $node = new Node('int', '$age', false);
76
77
        //when
78
        $name = $node->getName();
79
80
        //then
81
        $this->assertEquals('$age', $name);
82
    }
83
84
    /**
85
     * @test
86
     */
87 View Code Duplication
    public function shouldGetSanitizedName()
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...
88
    {
89
        //given
90
        $node = new Node('int', '$age', false);
91
92
        //when
93
        $name = $node->getSanitizedName();
94
95
        //then
96
        $this->assertEquals('age', $name);
97
    }
98
99
    /**
100
     * @test
101
     */
102
    public function shouldGetNameForArray()
103
    {
104
        //given
105
        $node = new Node('int', '$age', true);
106
107
        //when
108
        $name = $node->getNameForArray();
109
110
        //then
111
        $this->assertEquals('ArrayOfAge', $name);
112
    }
113
114
    /**
115
     * @test
116
     */
117 View Code Duplication
    public function shouldGetNameForObject()
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...
118
    {
119
        //given
120
        $elements = [
121
            new Node('string', '$name', false)
122
        ];
123
        $node = new Node('object', '$user', false, $elements);
124
125
        //when
126
        $name = $node->getNameForObject();
127
128
        //then
129
        $this->assertEquals('User', $name);
130
    }
131
132
    /**
133
     * @test
134
     */
135 View Code Duplication
    public function shouldSingularizeeNameForObject()
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...
136
    {
137
        //given
138
        $elements = [
139
            new Node('string', '$name', false)
140
        ];
141
        $node = new Node('object', '$users', true, $elements);
142
143
        //when
144
        $name = $node->getNameForObject();
145
146
        //then
147
        $this->assertEquals('User', $name);
148
    }
149
150
    /**
151
     * @test
152
     */
153
    public function shouldReturnFalseWhenTypeIsNotArray()
154
    {
155
        //given
156
        $node = new Node('string', '$name', false);
157
158
        //when
159
        $isArray = $node->isArray();
160
161
        //then
162
        $this->assertFalse($isArray);
163
    }
164
165
    /**
166
     * @test
167
     */
168
    public function shouldReturnTrueWhenTypeIsArray()
169
    {
170
        //given
171
        $node = new Node('string', '$name', true);
172
173
        //when
174
        $isArray = $node->isArray();
175
176
        //then
177
        $this->assertTrue($isArray);
178
    }
179
180
    /**
181
     * @test
182
     */
183
    public function shouldReturnFalseWhenTypeIsNotObject()
184
    {
185
        //given
186
        $node = new Node('string', '$name', true);
187
188
        //when
189
        $isArray = $node->isObject();
190
191
        //then
192
        $this->assertFalse($isArray);
193
    }
194
195
    /**
196
     * @test
197
     */
198 View Code Duplication
    public function shouldReturnTrueWhenTypeIsObject()
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...
199
    {
200
        //given
201
        $elements = [
202
            new Node('string', '$name', false)
203
        ];
204
        $node = new Node('object', '$users', true, $elements);
205
206
        //when
207
        $isArray = $node->isObject();
208
209
        //then
210
        $this->assertTrue($isArray);
211
    }
212
}
213