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.

OffsetRepresentationTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 299
Duplicated Lines 72.91 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 5
dl 218
loc 299
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
B testSerialize() 128 128 1
B testGenerateAbsoluteURIs() 90 90 1
B testExclusion() 0 76 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
namespace Hateoas\Tests\Representation;
4
5
use Hateoas\Representation\CollectionRepresentation;
6
use Hateoas\Representation\OffsetRepresentation;
7
use Hateoas\Tests\Fixtures\UsersRepresentation;
8
9
class OffsetRepresentationTest extends RepresentationTestCase
10
{
11 View Code Duplication
    public function testSerialize()
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...
12
    {
13
        $collection = new OffsetRepresentation(
14
            new CollectionRepresentation(
15
                array(
16
                    'Adrien',
17
                    'William',
18
                ),
19
                'authors',
20
                'users'
21
            ),
22
            '/authors',
23
            array(
24
                'query' => 'willdurand/Hateoas',
25
            ),
26
            44,
27
            20,
28
            95,
29
            null,
30
            null,
31
            false
32
        );
33
34
        $this->assertSame(
35
            <<<XML
36
<?xml version="1.0" encoding="UTF-8"?>
37
<collection offset="44" limit="20" total="95">
38
  <users rel="authors">
39
    <entry><![CDATA[Adrien]]></entry>
40
    <entry><![CDATA[William]]></entry>
41
  </users>
42
  <link rel="self" href="/authors?query=willdurand%2FHateoas&amp;offset=44&amp;limit=20"/>
43
  <link rel="first" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
44
  <link rel="last" href="/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
45
  <link rel="next" href="/authors?query=willdurand%2FHateoas&amp;offset=64&amp;limit=20"/>
46
  <link rel="previous" href="/authors?query=willdurand%2FHateoas&amp;offset=24&amp;limit=20"/>
47
</collection>
48
49
XML
50
            ,
51
            $this->hateoas->serialize($collection, 'xml')
52
        );
53
54
        $this->assertSame(
55
            <<<XML
56
<?xml version="1.0" encoding="UTF-8"?>
57
<collection offset="44" limit="20" total="95" href="/authors?query=willdurand%2FHateoas&amp;offset=44&amp;limit=20">
58
  <resource rel="authors"><![CDATA[Adrien]]></resource>
59
  <resource rel="authors"><![CDATA[William]]></resource>
60
  <link rel="first" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
61
  <link rel="last" href="/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
62
  <link rel="next" href="/authors?query=willdurand%2FHateoas&amp;offset=64&amp;limit=20"/>
63
  <link rel="previous" href="/authors?query=willdurand%2FHateoas&amp;offset=24&amp;limit=20"/>
64
</collection>
65
66
XML
67
            ,
68
            $this->halHateoas->serialize($collection, 'xml')
69
        );
70
        $this->assertSame(
71
            <<<XML
72
<?xml version="1.0" encoding="UTF-8"?>
73
<users offset="44" limit="20" total="95">
74
  <users rel="authors">
75
    <entry><![CDATA[Adrien]]></entry>
76
    <entry><![CDATA[William]]></entry>
77
  </users>
78
  <link rel="self" href="/authors?query=willdurand%2FHateoas&amp;offset=44&amp;limit=20"/>
79
  <link rel="first" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
80
  <link rel="last" href="/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
81
  <link rel="next" href="/authors?query=willdurand%2FHateoas&amp;offset=64&amp;limit=20"/>
82
  <link rel="previous" href="/authors?query=willdurand%2FHateoas&amp;offset=24&amp;limit=20"/>
83
</users>
84
85
XML
86
            ,
87
            $this->hateoas->serialize(new UsersRepresentation($collection), 'xml')
88
        );
89
90
        $this->assertSame(
91
            <<<XML
92
<?xml version="1.0" encoding="UTF-8"?>
93
<users offset="44" limit="20" total="95" href="/authors?query=willdurand%2FHateoas&amp;offset=44&amp;limit=20">
94
  <resource rel="authors"><![CDATA[Adrien]]></resource>
95
  <resource rel="authors"><![CDATA[William]]></resource>
96
  <link rel="first" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
97
  <link rel="last" href="/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
98
  <link rel="next" href="/authors?query=willdurand%2FHateoas&amp;offset=64&amp;limit=20"/>
99
  <link rel="previous" href="/authors?query=willdurand%2FHateoas&amp;offset=24&amp;limit=20"/>
100
</users>
101
102
XML
103
            ,
104
            $this->halHateoas->serialize(new UsersRepresentation($collection), 'xml')
105
        );
106
107
        $this->assertSame(
108
            '{'
109
                .'"offset":44,'
110
                .'"limit":20,'
111
                .'"total":95,'
112
                .'"_links":{'
113
                    .'"self":{'
114
                        .'"href":"\/authors?query=willdurand%2FHateoas&offset=44&limit=20"'
115
                    .'},'
116
                    .'"first":{'
117
                        .'"href":"\/authors?query=willdurand%2FHateoas&limit=20"'
118
                    .'},'
119
                    .'"last":{'
120
                        .'"href":"\/authors?query=willdurand%2FHateoas&offset=80&limit=20"'
121
                    .'},'
122
                    .'"next":{'
123
                        .'"href":"\/authors?query=willdurand%2FHateoas&offset=64&limit=20"'
124
                    .'},'
125
                    .'"previous":{'
126
                        .'"href":"\/authors?query=willdurand%2FHateoas&offset=24&limit=20"'
127
                    .'}'
128
                .'},'
129
                .'"_embedded":{'
130
                    .'"authors":['
131
                        .'"Adrien",'
132
                        .'"William"'
133
                    .']'
134
                .'}'
135
            .'}',
136
            $this->halHateoas->serialize($collection, 'json')
137
        );
138
    }
139
140 View Code Duplication
    public function testGenerateAbsoluteURIs()
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...
141
    {
142
        $collection = new OffsetRepresentation(
143
            new CollectionRepresentation(
144
                array(
145
                    'Adrien',
146
                    'William',
147
                ),
148
                'authors',
149
                'users'
150
            ),
151
            '/authors',
152
            array(
153
                'query' => 'willdurand/Hateoas',
154
            ),
155
            44,
156
            20,
157
            95,
158
            null,
159
            null,
160
            true // force absolute URIs
161
        );
162
163
        $this->assertSame(
164
            <<<XML
165
<?xml version="1.0" encoding="UTF-8"?>
166
<collection offset="44" limit="20" total="95">
167
  <users rel="authors">
168
    <entry><![CDATA[Adrien]]></entry>
169
    <entry><![CDATA[William]]></entry>
170
  </users>
171
  <link rel="self" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=44&amp;limit=20"/>
172
  <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&amp;limit=20"/>
173
  <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
174
  <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=64&amp;limit=20"/>
175
  <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=24&amp;limit=20"/>
176
</collection>
177
178
XML
179
            ,
180
            $this->hateoas->serialize($collection, 'xml')
181
        );
182
        $this->assertSame(
183
            <<<XML
184
<?xml version="1.0" encoding="UTF-8"?>
185
<collection offset="44" limit="20" total="95" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=44&amp;limit=20">
186
  <resource rel="authors"><![CDATA[Adrien]]></resource>
187
  <resource rel="authors"><![CDATA[William]]></resource>
188
  <link rel="first" href="http://example.com/authors?query=willdurand%2FHateoas&amp;limit=20"/>
189
  <link rel="last" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
190
  <link rel="next" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=64&amp;limit=20"/>
191
  <link rel="previous" href="http://example.com/authors?query=willdurand%2FHateoas&amp;offset=24&amp;limit=20"/>
192
</collection>
193
194
XML
195
            ,
196
            $this->halHateoas->serialize($collection, 'xml')
197
        );
198
        $this->assertSame(
199
            '{'
200
                .'"offset":44,'
201
                .'"limit":20,'
202
                .'"total":95,'
203
                .'"_links":{'
204
                    .'"self":{'
205
                        .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=44&limit=20"'
206
                    .'},'
207
                    .'"first":{'
208
                        .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&limit=20"'
209
                    .'},'
210
                    .'"last":{'
211
                        .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=80&limit=20"'
212
                    .'},'
213
                    .'"next":{'
214
                        .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=64&limit=20"'
215
                    .'},'
216
                    .'"previous":{'
217
                        .'"href":"http:\/\/example.com\/authors?query=willdurand%2FHateoas&offset=24&limit=20"'
218
                    .'}'
219
                .'},'
220
                .'"_embedded":{'
221
                    .'"authors":['
222
                        .'"Adrien",'
223
                        .'"William"'
224
                    .']'
225
                .'}'
226
            .'}',
227
            $this->halHateoas->serialize($collection, 'json')
228
        );
229
    }
230
231
    public function testExclusion()
232
    {
233
        $inline = new CollectionRepresentation(
234
            array(
235
                'Adrien',
236
                'William',
237
            ),
238
            'authors',
239
            'users'
240
        );
241
242
        /*
243
         * no last entry since `total` is missing
244
         * no previous only when offset is 0/null
245
         */
246
        $collection = new OffsetRepresentation(
247
            $inline,
248
            '/authors',
249
            array(
250
                'query' => 'willdurand/Hateoas',
251
            ),
252
            null,
253
            20
254
        );
255
256
        $this->assertSame(
257
            <<<XML
258
<?xml version="1.0" encoding="UTF-8"?>
259
<collection limit="20">
260
  <users rel="authors">
261
    <entry><![CDATA[Adrien]]></entry>
262
    <entry><![CDATA[William]]></entry>
263
  </users>
264
  <link rel="self" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
265
  <link rel="first" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
266
  <link rel="next" href="/authors?query=willdurand%2FHateoas&amp;offset=20&amp;limit=20"/>
267
</collection>
268
269
XML
270
            ,
271
            $this->hateoas->serialize($collection, 'xml')
272
        );
273
274
        /*
275
         * no next since on last block
276
         */
277
        $collection = new OffsetRepresentation(
278
            $inline,
279
            '/authors',
280
            array(
281
                'query' => 'willdurand/Hateoas',
282
            ),
283
            80,
284
            20,
285
            100
286
        );
287
288
        $this->assertSame(
289
            <<<XML
290
<?xml version="1.0" encoding="UTF-8"?>
291
<collection offset="80" limit="20" total="100">
292
  <users rel="authors">
293
    <entry><![CDATA[Adrien]]></entry>
294
    <entry><![CDATA[William]]></entry>
295
  </users>
296
  <link rel="self" href="/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
297
  <link rel="first" href="/authors?query=willdurand%2FHateoas&amp;limit=20"/>
298
  <link rel="last" href="/authors?query=willdurand%2FHateoas&amp;offset=80&amp;limit=20"/>
299
  <link rel="previous" href="/authors?query=willdurand%2FHateoas&amp;offset=60&amp;limit=20"/>
300
</collection>
301
302
XML
303
            ,
304
            $this->hateoas->serialize($collection, 'xml')
305
        );
306
    }
307
}
308