Passed
Pull Request — master (#42)
by Viacheslav
02:53 queued 10s
created

Issue40Test::testIssue()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 234
Code Lines 228

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 228
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 234
rs 8

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
namespace Swaggest\JsonDiff\Tests\Issues;
4
5
use Swaggest\JsonDiff\JsonDiff;
6
use Swaggest\JsonDiff\JsonPatch;
7
8
class Issue40Test extends \PHPUnit_Framework_TestCase
9
{
10
    public function testIssue() {
11
        $json1 = <<<JSON
12
    {
13
      "type": "FeatureCollection",
14
      "features": [
15
        {
16
          "type": "Feature",
17
          "properties": {},
18
          "geometry": {
19
            "type": "Polygon",
20
            "coordinates": [
21
              [
22
                [
23
                  0.582275390625,
24
                  43.04881979669318
25
                ],
26
                [
27
                  0.97503662109375,
28
                  43.04881979669318
29
                ],
30
                [
31
                  0.97503662109375,
32
                  43.29120116988416
33
                ],
34
                [
35
                  0.582275390625,
36
                  43.29120116988416
37
                ],
38
                [
39
                  0.582275390625,
40
                  43.04881979669318
41
                ]
42
              ]
43
            ]
44
          }
45
        },
46
        {
47
          "type": "Feature",
48
          "properties": {},
49
          "geometry": {
50
            "type": "Polygon",
51
            "coordinates": [
52
              [
53
                [
54
                  0.9722900390624999,
55
                  42.97049193148623
56
                ],
57
                [
58
                  1.329345703125,
59
                  42.97049193148623
60
                ],
61
                [
62
                  1.329345703125,
63
                  43.29120116988416
64
                ],
65
                [
66
                  0.9722900390624999,
67
                  43.29120116988416
68
                ],
69
                [
70
                  0.9722900390624999,
71
                  42.97049193148623
72
                ]
73
              ]
74
            ]
75
          }
76
        },
77
        {
78
          "type": "Feature",
79
          "properties": {
80
            "stroke": "#555555",
81
            "stroke-width": 2,
82
            "stroke-opacity": 1,
83
            "fill": "#555555",
84
            "fill-opacity": 0.5
85
          },
86
          "geometry": {
87
            "type": "Polygon",
88
            "coordinates": [
89
              [
90
                [
91
                  0.8778762817382812,
92
                  42.97275278822627
93
                ],
94
                [
95
                  0.8205413818359375,
96
                  42.945365709261324
97
                ],
98
                [
99
                  0.8758163452148438,
100
                  42.9224919308288
101
                ],
102
                [
103
                  0.91461181640625,
104
                  42.94234987312984
105
                ],
106
                [
107
                  0.8778762817382812,
108
                  42.97275278822627
109
                ]
110
              ]
111
            ]
112
          }
113
        },
114
        {
115
          "type": "Feature",
116
          "properties": {
117
            "stroke": "#555555",
118
            "stroke-width": 2,
119
            "stroke-opacity": 1,
120
            "fill": "#555555",
121
            "fill-opacity": 0.7,
122
            "dinasty": "qi"
123
          },
124
          "geometry": {
125
            "type": "Polygon",
126
            "coordinates": [
127
              [
128
                [
129
                  0.8778762817382812,
130
                  42.97325518954874
131
                ],
132
                [
133
                  0.9156417846679686,
134
                  42.94234987312984
135
                ],
136
                [
137
                  0.9578704833984375,
138
                  42.934055561994754
139
                ],
140
                [
141
                  0.9836196899414061,
142
                  42.96697487803267
143
                ],
144
                [
145
                  0.9348678588867186,
146
                  42.98857645832184
147
                ],
148
                [
149
                  0.8778762817382812,
150
                  42.97325518954874
151
                ]
152
              ]
153
            ]
154
          }
155
        }
156
      ]
157
    }
158
JSON;
159
160
        $json2 = <<<JSON
161
    {
162
      "type": "FeatureCollection",
163
      "features": [
164
        {
165
          "type": "Feature",
166
          "properties": {},
167
          "geometry": {
168
            "type": "Polygon",
169
            "coordinates": [
170
              [
171
                [
172
                  0.582275390625,
173
                  43.04881979669318
174
                ],
175
                [
176
                  0.97503662109375,
177
                  43.04881979669318
178
                ],
179
                [
180
                  0.97503662109375,
181
                  43.29120116988416
182
                ],
183
                [
184
                  0.582275390625,
185
                  43.29120116988416
186
                ],
187
                [
188
                  0.582275390625,
189
                  43.04881979669318
190
                ]
191
              ]
192
            ]
193
          }
194
        },
195
        {
196
          "type": "Feature",
197
          "properties": {
198
            "stroke": "#555555",
199
            "stroke-width": 2,
200
            "stroke-opacity": 1,
201
            "fill": "#555555",
202
            "fill-opacity": 0.5
203
          },
204
          "geometry": {
205
            "type": "Polygon",
206
            "coordinates": [
207
              [
208
                [
209
                  0.8778762817382812,
210
                  42.97275278822627
211
                ],
212
                [
213
                  0.8205413818359375,
214
                  42.945365709261324
215
                ],
216
                [
217
                  0.8758163452148438,
218
                  42.9224919308288
219
                ],
220
                [
221
                  0.91461181640625,
222
                  42.94234987312984
223
                ],
224
                [
225
                  0.8778762817382812,
226
                  42.97275278822627
227
                ]
228
              ]
229
            ]
230
          }
231
        }
232
      ]
233
    }
234
JSON;
235
236
        $j1 = json_decode($json1);
237
238
        $diff = new JsonDiff($j1, json_decode($json2));
239
        $exportedPatch = $diff->getPatch()->export($diff->getPatch());
240
241
        $patch = JsonPatch::import($exportedPatch);
242
243
        var_dump($patch->apply($j1));
0 ignored issues
show
Security Debugging Code introduced by
var_dump($patch->apply($j1)) looks like debug code. Are you sure you do not want to remove it?
Loading history...
244
    }
245
}