GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( fa9233...7f89d9 )
by Tomas
06:55
created

RpcLiteralTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 177
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 6
Bugs 1 Features 2
Metric Value
wmc 9
c 6
b 1
f 2
lcom 1
cbo 5
dl 177
loc 177
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 5 5 1
A shouldReturnCorrectBindingStyle() 8 8 1
A shouldReturnCorrectBindingUse() 8 8 1
A shouldParseArrayWithSimpleType() 14 14 1
A shouldParseSimpleObject() 17 17 1
B shouldParseObjectWithWrapper() 24 24 1
A shouldParseObjectWithArrayOfElement() 18 18 1
A shouldParseArrayOfObjects() 18 18 1
B shouldParseObjectWithArrayOfWrapper() 25 25 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-2015
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
use Factory\ParameterFactory;
25
use Ouzo\Tests\Assert;
26
use WSDL\XML\Styles\RpcLiteral;
27
28
/**
29
 * RpcLiteralTest
30
 *
31
 * @author Piotr Olaszewski <[email protected]>
32
 */
33 View Code Duplication
class RpcLiteralTest extends PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class 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...
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
34
{
35
    /**
36
     * @var RpcLiteral
37
     */
38
    private $_rpcLiteral;
39
40
    protected function setUp()
41
    {
42
        parent::setUp();
43
        $this->_rpcLiteral = new RpcLiteral();
44
    }
45
46
    /**
47
     * @test
48
     */
49
    public function shouldReturnCorrectBindingStyle()
50
    {
51
        //when
52
        $style = $this->_rpcLiteral->bindingStyle();
53
54
        //then
55
        $this->assertEquals('rpc', $style);
56
    }
57
58
    /**
59
     * @test
60
     */
61
    public function shouldReturnCorrectBindingUse()
62
    {
63
        //when
64
        $style = $this->_rpcLiteral->bindingUse();
65
66
        //then
67
        $this->assertEquals('literal', $style);
68
    }
69
70
    /**
71
     * @test
72
     */
73
    public function shouldParseArrayWithSimpleType()
74
    {
75
        //given
76
        $parameter = ParameterFactory::createParameterForSimpleArray();
77
78
        //when
79
        $types = $this->_rpcLiteral->typeParameters($parameter);
80
81
        //then
82
        $type = $types[0];
83
        $this->assertEquals('ArrayOfNames', $type->getName());
84
        $this->assertEquals('xsd:string[]', $type->getArrayType());
85
        $this->assertNull($type->getComplex());
86
    }
87
88
    /**
89
     * @test
90
     */
91
    public function shouldParseSimpleObject()
92
    {
93
        //given
94
        $parameter = ParameterFactory::createParameterForSimpleObject();
95
96
        //when
97
        $types = $this->_rpcLiteral->typeParameters($parameter);
98
99
        //then
100
        $type = $types[0];
101
        $this->assertEquals('Info', $type->getName());
102
        $this->assertEquals(array(
103
            array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'),
104
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age')
105
        ), $type->getElementAttributes());
106
//        $this->assertNull($type->getComplex());
0 ignored issues
show
Unused Code Comprehensibility introduced by
75% 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...
107
    }
108
109
    /**
110
     * @test
111
     */
112
    public function shouldParseObjectWithWrapper()
113
    {
114
        //given
115
        $parameter = ParameterFactory::createParameterForObjectWithWrapper();
116
117
        //when
118
        $types = $this->_rpcLiteral->typeParameters($parameter);
119
120
        //then
121
        $type = $types[0];
122
        $this->assertEquals('AgentNameWithId', $type->getName());
123
        $this->assertEquals(array(
124
            array('type' => 'element', 'value' => 'ns:MocksMockUserWrapper', 'name' => 'agent'),
125
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id')
126
        ), $type->getElementAttributes());
127
        $actualComplex = $type->getComplex();
128
        Assert::thatArray($actualComplex)->onMethod('getName')->containsExactly('MocksMockUserWrapper');
129
        Assert::thatArray($type->getComplex())->onMethod('getElementAttributes')
130
            ->containsKeyAndValue(array(array(
131
                array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id'),
132
                array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'),
133
                array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age')
134
            )));
135
    }
136
137
    /**
138
     * @test
139
     */
140
    public function shouldParseObjectWithArrayOfElement()
141
    {
142
        //given
143
        $parameter = ParameterFactory::createParameterForObjectWithArrayOfSimpleType();
144
145
        //when
146
        $types = $this->_rpcLiteral->typeParameters($parameter);
147
148
        //then
149
        $type = $types[0];
150
        $this->assertEquals('NamesInfo', $type->getName());
151
        $this->assertEquals(array(
152
            array('type' => 'type', 'value' => 'ns:ArrayOfNames', 'name' => 'names'),
153
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id')
154
        ), $type->getElementAttributes());
155
        Assert::thatArray($type->getComplex())->onMethod('getName')->containsExactly('ArrayOfNames');
156
        Assert::thatArray($type->getComplex())->onMethod('getArrayType')->containsExactly('xsd:string[]');
157
    }
158
159
    /**
160
     * @test
161
     */
162
    public function shouldParseArrayOfObjects()
163
    {
164
        //given
165
        $parameter = ParameterFactory::createParameterForArrayOfObjects();
166
167
        //when
168
        $types = $this->_rpcLiteral->typeParameters($parameter);
169
170
        //then
171
        $type = $types[0];
172
        $this->assertEquals('ArrayOfCompanies', $type->getName());
173
        $this->assertEquals('ns:Companies[]', $type->getArrayType());
174
        $this->assertEquals('Companies', $type->getComplex()->getName());
175
        $this->assertEquals(array(
176
            array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'),
177
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id')
178
        ), $type->getComplex()->getElementAttributes());
179
    }
180
181
    /**
182
     * @test
183
     */
184
    public function shouldParseObjectWithArrayOfWrapper()
185
    {
186
        //given
187
        $parameter = ParameterFactory::createParameterObjectWithArrayOfWrapper();
188
189
        //when
190
        $types = $this->_rpcLiteral->typeParameters($parameter);
191
192
        //then
193
        $type = $types[0];
194
        $this->assertEquals('ListOfAgents', $type->getName());
195
        $this->assertEquals(array(
196
            array('type' => 'type', 'value' => 'ns:ArrayOfAgents', 'name' => 'agents'),
197
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id')
198
        ), $type->getElementAttributes());
199
        $actualComplex = $type->getComplex();
200
        Assert::thatArray($actualComplex)->onMethod('getName')->containsExactly('ArrayOfAgents');
201
        Assert::thatArray($actualComplex)->onMethod('getArrayType')->containsExactly('ns:MocksMockUserWrapper[]');
202
        $this->assertEquals('MocksMockUserWrapper', $actualComplex[0]->getComplex()->getName());
203
        $this->assertEquals(array(
204
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'id'),
205
            array('type' => 'type', 'value' => 'xsd:string', 'name' => 'name'),
206
            array('type' => 'type', 'value' => 'xsd:int', 'name' => 'age')
207
        ), $actualComplex[0]->getComplex()->getElementAttributes());
208
    }
209
}
210