Completed
Push — master ( 001830...de2f31 )
by Michal
03:36
created

ShapeRecord::saveToFile()   C

Complexity

Conditions 14
Paths 14

Size

Total Lines 52
Code Lines 49

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 52
rs 5.9535
cc 14
eloc 49
nc 14
nop 3

How to fix   Long Method    Complexity   

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
 * BytesFall ShapeFiles library
4
 *
5
 * The library implements the 2D variants of the ShapeFile format as defined in
6
 * http://www.esri.com/library/whitepapers/pdfs/shapefile.pdf.
7
 * The library currently supports reading and editing of ShapeFiles and the
8
 * Associated information (DBF file).
9
 *
10
 * @package bfShapeFiles
11
 * @version 0.0.2
12
 * @link http://bfshapefiles.sourceforge.net/
13
 * @license http://www.gnu.org/licenses/gpl-2.0.html GPLv2-or-later
14
 *
15
 * Copyright 2006-2007 Ovidio <ovidio AT users.sourceforge.net>
16
 *
17
 * This program is free software; you can redistribute it and/or
18
 * modify it under the terms of the GNU General Public License
19
 * as published by the Free Software Foundation.
20
 *
21
 * This program is distributed in the hope that it will be useful,
22
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24
 * GNU General Public License for more details.
25
 *
26
 * You should have received a copy of the GNU General Public License
27
 * along with this program; if not, you can download one from
28
 * http://www.gnu.org/copyleft/gpl.html.
29
 *
30
 */
31
namespace ShapeFile;
32
33
  class ShapeRecord {
34
    var $SHPFile = NULL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $SHPFile.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
35
    var $DBFFile = NULL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $DBFFile.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
36
37
    var $recordNumber = NULL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $recordNumber.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
38
    var $shapeType = NULL;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $shapeType.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
39
40
    var $lastError = "";
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $lastError.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
41
42
    var $SHPData = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $SHPData.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
43
    var $DBFData = array();
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $DBFData.

The PSR-2 coding standard requires that all properties in a class have their visibility explicitly declared. If you declare a property using

class A {
    var $property;
}

the property is implicitly global.

To learn more about the PSR-2, please see the PHP-FIG site on the PSR-2.

Loading history...
44
45
    public function __construct($shapeType) {
46
      $this->shapeType = $shapeType;
47
    }
48
49
    function loadFromFile(&$SHPFile, &$DBFFile) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
50
      $this->SHPFile = $SHPFile;
51
      $this->DBFFile = $DBFFile;
52
      $this->_loadHeaders();
53
54
      switch ($this->shapeType) {
55
        case 0:
56
          $this->_loadNullRecord();
57
        break;
58
        case 1:
59
          $this->_loadPointRecord();
60
        break;
61
        case 21:
62
          $this->_loadPointMRecord();
63
        break;
64
        case 11:
65
          $this->_loadPointZRecord();
66
        break;
67
        case 3:
68
          $this->_loadPolyLineRecord();
69
        break;
70
        case 23:
71
          $this->_loadPolyLineMRecord();
72
        break;
73
        case 13:
74
          $this->_loadPolyLineZRecord();
75
        break;
76
        case 5:
77
          $this->_loadPolygonRecord();
78
        break;
79
        case 25:
80
          $this->_loadPolygonMRecord();
81
        break;
82
        case 15:
83
          $this->_loadPolygonZRecord();
84
        break;
85
        case 8:
86
          $this->_loadMultiPointRecord();
87
        break;
88
        case 28:
89
          $this->_loadMultiPointMRecord();
90
        break;
91
        case 18:
92
          $this->_loadMultiPointZRecord();
93
        break;
94
        default:
95
          $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
96
        break;
97
      }
98
      $this->_loadDBFData();
99
    }
100
101
    function saveToFile(&$SHPFile, &$DBFFile, $recordNumber) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
102
      $this->SHPFile = $SHPFile;
103
      $this->DBFFile = $DBFFile;
104
      $this->recordNumber = $recordNumber;
105
      $this->_saveHeaders();
106
107
      switch ($this->shapeType) {
108
        case 0:
109
          $this->_saveNullRecord();
110
        break;
111
        case 1:
112
          $this->_savePointRecord();
113
        break;
114
        case 21:
115
          $this->_savePointMRecord();
116
        break;
117
        case 11:
118
          $this->_savePointZRecord();
119
        break;
120
        case 3:
121
          $this->_savePolyLineRecord();
122
        break;
123
        case 23:
124
          $this->_savePolyLineMRecord();
125
        break;
126
        case 13:
127
          $this->_savePolyLineZRecord();
128
        break;
129
        case 5:
130
          $this->_savePolygonRecord();
131
        break;
132
        case 25:
133
          $this->_savePolygonMRecord();
134
        break;
135
        case 15:
136
          $this->_savePolygonZRecord();
137
        break;
138
        case 8:
139
          $this->_saveMultiPointRecord();
140
        break;
141
        case 28:
142
          $this->_saveMultiPointMRecord();
143
        break;
144
        case 18:
145
          $this->_saveMultiPointZRecord();
146
        break;
147
        default:
148
          $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
149
        break;
150
      }
151
      $this->_saveDBFData();
152
    }
153
154
    function updateDBFInfo($header) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
155
      $tmp = $this->DBFData;
156
      unset($this->DBFData);
157
      $this->DBFData = array();
158
      reset($header);
159
      while (list($key, $value) = each($header)) {
0 ignored issues
show
Unused Code introduced by
The assignment to $key is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
160
        $this->DBFData[$value[0]] = (isset($tmp[$value[0]])) ? $tmp[$value[0]] : "";
161
      }
162
    }
163
164
    function _loadHeaders() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
165
      $this->recordNumber = Util::loadData("N", fread($this->SHPFile, 4));
166
      $tmp = Util::loadData("N", fread($this->SHPFile, 4)); //We read the length of the record
0 ignored issues
show
Unused Code introduced by
$tmp is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
167
      $this->shapeType = Util::loadData("V", fread($this->SHPFile, 4));
168
    }
169
170
    function _saveHeaders() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
171
      fwrite($this->SHPFile, pack("N", $this->recordNumber));
172
      fwrite($this->SHPFile, pack("N", $this->getContentLength()));
173
      fwrite($this->SHPFile, pack("V", $this->shapeType));
174
    }
175
176
    function _loadPoint() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
177
      $data = array();
178
179
      $data["x"] = Util::loadData("d", fread($this->SHPFile, 8));
180
      $data["y"] = Util::loadData("d", fread($this->SHPFile, 8));
181
182
      return $data;
183
    }
184
185
    function _loadPointM() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
186
      $data = array();
187
188
      $data["x"] = Util::loadData("d", fread($this->SHPFile, 8));
189
      $data["y"] = Util::loadData("d", fread($this->SHPFile, 8));
190
      $data["m"] = Util::loadData("d", fread($this->SHPFile, 8));
191
192
      return $data;
193
    }
194
195
    function _loadPointZ() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
196
      $data = array();
197
198
      $data["x"] = Util::loadData("d", fread($this->SHPFile, 8));
199
      $data["y"] = Util::loadData("d", fread($this->SHPFile, 8));
200
      $data["z"] = Util::loadData("d", fread($this->SHPFile, 8));
201
      $data["m"] = Util::loadData("d", fread($this->SHPFile, 8));
202
203
      return $data;
204
    }
205
206
    function _savePoint($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
207
      fwrite($this->SHPFile, Util::packDouble($data["x"]));
208
      fwrite($this->SHPFile, Util::packDouble($data["y"]));
209
    }
210
211
    function _savePointM($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
212
      fwrite($this->SHPFile, Util::packDouble($data["x"]));
213
      fwrite($this->SHPFile, Util::packDouble($data["y"]));
214
      fwrite($this->SHPFile, Util::packDouble($data["m"]));
215
    }
216
217
    function _savePointZ($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
218
      fwrite($this->SHPFile, Util::packDouble($data["x"]));
219
      fwrite($this->SHPFile, Util::packDouble($data["y"]));
220
      fwrite($this->SHPFile, Util::packDouble($data["z"]));
221
      fwrite($this->SHPFile, Util::packDouble($data["m"]));
222
    }
223
224
    function _saveMeasure($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
225
      fwrite($this->SHPFile, Util::packDouble($data["m"]));
226
    }
227
228
    function _saveZCoordinate($data) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
229
      fwrite($this->SHPFile, Util::packDouble($data["z"]));
230
    }
231
232
    function _loadNullRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
233
      $this->SHPData = array();
234
    }
235
236
    function _saveNullRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
237
      //Don't save anything
238
    }
239
240
    function _loadPointRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
241
      $this->SHPData = $this->_loadPoint();
242
    }
243
244
    function _loadPointMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
245
      $this->SHPData = $this->_loadPointM();
246
    }
247
248
    function _loadPointZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
249
      $this->SHPData = $this->_loadPointZ();
250
    }
251
252
    function _savePointRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
253
      $this->_savePoint($this->SHPData);
254
    }
255
256
    function _savePointMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
257
      $this->_savePointM($this->SHPData);
258
    }
259
260
    function _savePointZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
261
      $this->_savePointZ($this->SHPData);
262
    }
263
264
    function _loadMultiPointRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
265
      $this->SHPData = array();
266
      $this->SHPData["xmin"] = Util::loadData("d", fread($this->SHPFile, 8));
267
      $this->SHPData["ymin"] = Util::loadData("d", fread($this->SHPFile, 8));
268
      $this->SHPData["xmax"] = Util::loadData("d", fread($this->SHPFile, 8));
269
      $this->SHPData["ymax"] = Util::loadData("d", fread($this->SHPFile, 8));
270
271
      $this->SHPData["numpoints"] = Util::loadData("V", fread($this->SHPFile, 4));
272
273 View Code Duplication
      for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
274
        $this->SHPData["points"][] = $this->_loadPoint();
275
      }
276
    }
277
278
    function _loadMultiPointMZRecord( $type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
279
280
      $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8));
281
      $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8));
282
283 View Code Duplication
      for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
284
        $this->SHPData["points"][$i][$type] = Util::loadData("d", fread($this->SHPFile, 8));
285
      }
286
    }
287
288
    function _loadMultiPointMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
289
      $this->_loadMultiPointRecord();
290
291
      $this->_loadMultiPointMZRecord("m");
292
    }
293
294
    function _loadMultiPointZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
295
      $this->_loadMultiPointRecord();
296
297
      $this->_loadMultiPointMZRecord("z");
298
      $this->_loadMultiPointMZRecord("m");
299
    }
300
301
    function _saveMultiPointRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
302
      fwrite($this->SHPFile, pack("dddd", $this->SHPData["xmin"], $this->SHPData["ymin"], $this->SHPData["xmax"], $this->SHPData["ymax"]));
303
304
      fwrite($this->SHPFile, pack("V", $this->SHPData["numpoints"]));
305
306 View Code Duplication
      for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
307
        $this->_savePoint($this->SHPData["points"][$i]);
308
      }
309
    }
310
311
    function _saveMultiPointMZRecord( $type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
312
313
      fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"]));
314
315 View Code Duplication
      for ($i = 0; $i <= $this->SHPData["numpoints"]; $i++) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
316
        fwrite($this->SHPFile, Util::packDouble($this->SHPData["points"][$type]));
317
      }
318
    }
319
320
    function _saveMultiPointMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
321
      $this->_saveMultiPointRecord();
322
323
      $this->_saveMultiPointMZRecord("m");
324
    }
325
326
    function _saveMultiPointZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
327
      $this->_saveMultiPointRecord();
328
329
      $this->_saveMultiPointMZRecord("z");
330
      $this->_saveMultiPointMZRecord("m");
331
    }
332
333
    function _loadPolyLineRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
334
      $this->SHPData = array();
335
      $this->SHPData["xmin"] = Util::loadData("d", fread($this->SHPFile, 8));
336
      $this->SHPData["ymin"] = Util::loadData("d", fread($this->SHPFile, 8));
337
      $this->SHPData["xmax"] = Util::loadData("d", fread($this->SHPFile, 8));
338
      $this->SHPData["ymax"] = Util::loadData("d", fread($this->SHPFile, 8));
339
340
      $this->SHPData["numparts"]  = Util::loadData("V", fread($this->SHPFile, 4));
341
      $this->SHPData["numpoints"] = Util::loadData("V", fread($this->SHPFile, 4));
342
343 View Code Duplication
      for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
344
        $this->SHPData["parts"][$i] = Util::loadData("V", fread($this->SHPFile, 4));
345
      }
346
347
      $firstIndex = ftell($this->SHPFile);
348
      $readPoints = 0;
349
      reset($this->SHPData["parts"]);
350
      while (list($partIndex, $partData) = each($this->SHPData["parts"])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $partData is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
351
        if (!isset($this->SHPData["parts"][$partIndex]["points"]) || !is_array($this->SHPData["parts"][$partIndex]["points"])) {
352
          $this->SHPData["parts"][$partIndex] = array();
353
          $this->SHPData["parts"][$partIndex]["points"] = array();
354
        }
355
        while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) {
356
          $this->SHPData["parts"][$partIndex]["points"][] = $this->_loadPoint();
357
          $readPoints++;
358
        }
359
      }
360
361
      fseek($this->SHPFile, $firstIndex + ($readPoints*16));
362
    }
363
364
    function _loadPolyLineMZRecord( $type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
365
366
      $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8));
367
      $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8));
368
369
      $firstIndex = ftell($this->SHPFile);
370
      $readPoints = 0;
371
      reset($this->SHPData["parts"]);
372
      while (list($partIndex, $partData) = each($this->SHPData["parts"])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $partData is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
373
        while (!in_array($readPoints, $this->SHPData["parts"]) && ($readPoints < ($this->SHPData["numpoints"])) && !feof($this->SHPFile)) {
374
          $this->SHPData["parts"][$partIndex]["points"][$readPoints][$type] = Util::loadData("d", fread($this->SHPFile, 8));
375
          $readPoints++;
376
        }
377
      }
378
379
      fseek($this->SHPFile, $firstIndex + ($readPoints*24));
380
    }
381
382
    function _loadPolyLineMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
383
      $this->_loadPolyLineRecord();
384
385
      $this->_loadPolyLineMZRecord("m");
386
    }
387
388
    function _loadPolyLineZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
389
      $this->_loadPolyLineRecord();
390
391
      $this->_loadPolyLineMZRecord("z");
392
      $this->_loadPolyLineMZRecord("m");
393
    }
394
395
    function _savePolyLineRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
396
      fwrite($this->SHPFile, pack("dddd", $this->SHPData["xmin"], $this->SHPData["ymin"], $this->SHPData["xmax"], $this->SHPData["ymax"]));
397
398
      fwrite($this->SHPFile, pack("VV", $this->SHPData["numparts"], $this->SHPData["numpoints"]));
399
400
      for ($i = 0; $i < $this->SHPData["numparts"]; $i++) {
401
        fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])-1));
402
      }
403
404
      foreach ($this->SHPData["parts"] as $partData){
405
        reset($partData["points"]);
406
        while (list($pointIndex, $pointData) = each($partData["points"])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $pointIndex is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
407
          $this->_savePoint($pointData);
408
        }
409
      }
410
    }
411
412
    function _savePolyLineMZRecord( $type ) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
413
      fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"]));
414
415
      foreach ($this->SHPData["parts"] as $partData){
416
        reset($partData["points"]);
417
        while (list($pointIndex, $pointData) = each($partData["points"])) {
0 ignored issues
show
Unused Code introduced by
The assignment to $pointIndex is unused. Consider omitting it like so list($first,,$third).

This checks looks for assignemnts to variables using the list(...) function, where not all assigned variables are subsequently used.

Consider the following code example.

<?php

function returnThreeValues() {
    return array('a', 'b', 'c');
}

list($a, $b, $c) = returnThreeValues();

print $a . " - " . $c;

Only the variables $a and $c are used. There was no need to assign $b.

Instead, the list call could have been.

list($a,, $c) = returnThreeValues();
Loading history...
418
          fwrite($this->SHPFile, Util::packDouble($pointData[$type]));
419
        }
420
      }
421
    }
422
423
    function _savePolyLineMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
424
      $this->_savePolyLineRecord();
425
426
      $this->_savePolyLineMZRecord("m");
427
    }
428
429
    function _savePolyLineZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
430
      $this->_savePolyLineRecord();
431
432
      $this->_savePolyLineMZRecord("z");
433
      $this->_savePolyLineMZRecord("m");
434
    }
435
436
    function _loadPolygonRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
437
      $this->_loadPolyLineRecord();
438
    }
439
440
    function _loadPolygonMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
441
      $this->_loadPolyLineMRecord();
442
    }
443
444
    function _loadPolygonZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
445
      $this->_loadPolyLineZRecord();
446
    }
447
448
    function _savePolygonRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
449
      $this->_savePolyLineRecord();
450
    }
451
452
    function _savePolygonMRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
453
      $this->_savePolyLineMRecord();
454
    }
455
456
    function _savePolygonZRecord() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
457
      $this->_savePolyLineZRecord();
458
    }
459
460
    function addPoint($point, $partIndex = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
461
      switch ($this->shapeType) {
462
        case 0:
463
          //Don't add anything
464
        break;
465
        case 1:
466
        case 11:
467
        case 21:
468 View Code Duplication
          if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) $point["m"] = 0.0; // no_value
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
469 View Code Duplication
          if (in_array($this->shapeType,array(11)) && !isset($point["z"])) $point["z"] = 0.0; // no_value
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
470
          //Substitutes the value of the current point
471
          $this->SHPData = $point;
472
        break;
473
        case 3:
474
        case 5:
475
        case 13:
476
        case 15:
477
        case 23:
478
        case 25:
479 View Code Duplication
          if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) $point["m"] = 0.0; // no_value
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
480 View Code Duplication
          if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) $point["z"] = 0.0; // no_value
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
481
482
          //Adds a new point to the selected part
483 View Code Duplication
          if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"];
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
484 View Code Duplication
          if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"];
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
485 View Code Duplication
          if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
486 View Code Duplication
          if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"];
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
487 View Code Duplication
          if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"];
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
488 View Code Duplication
          if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
489 View Code Duplication
          if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
490 View Code Duplication
          if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
491
492
          $this->SHPData["parts"][$partIndex]["points"][] = $point;
493
494
          $this->SHPData["numparts"] = count($this->SHPData["parts"]);
495
          $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0);
496
        break;
497
        case 8:
498
        case 18:
499
        case 28:
500 View Code Duplication
          if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) $point["m"] = 0.0; // no_value
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
501 View Code Duplication
          if (in_array($this->shapeType,array(18)) && !isset($point["z"])) $point["z"] = 0.0; // no_value
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
502
503
          //Adds a new point
504 View Code Duplication
          if (!isset($this->SHPData["xmin"]) || ($this->SHPData["xmin"] > $point["x"])) $this->SHPData["xmin"] = $point["x"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
505 View Code Duplication
          if (!isset($this->SHPData["ymin"]) || ($this->SHPData["ymin"] > $point["y"])) $this->SHPData["ymin"] = $point["y"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
506 View Code Duplication
          if (isset($point["m"]) && (!isset($this->SHPData["mmin"]) || ($this->SHPData["mmin"] > $point["m"]))) $this->SHPData["mmin"] = $point["m"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
507 View Code Duplication
          if (isset($point["z"]) && (!isset($this->SHPData["zmin"]) || ($this->SHPData["zmin"] > $point["z"]))) $this->SHPData["zmin"] = $point["z"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
508 View Code Duplication
          if (!isset($this->SHPData["xmax"]) || ($this->SHPData["xmax"] < $point["x"])) $this->SHPData["xmax"] = $point["x"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
509 View Code Duplication
          if (!isset($this->SHPData["ymax"]) || ($this->SHPData["ymax"] < $point["y"])) $this->SHPData["ymax"] = $point["y"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
510 View Code Duplication
          if (isset($point["m"]) && (!isset($this->SHPData["mmax"]) || ($this->SHPData["mmax"] < $point["m"]))) $this->SHPData["mmax"] = $point["m"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
511 View Code Duplication
          if (isset($point["z"]) && (!isset($this->SHPData["zmax"]) || ($this->SHPData["zmax"] < $point["z"]))) $this->SHPData["zmax"] = $point["z"];
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
512
513
          $this->SHPData["points"][] = $point;
514
          $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0);
515
        break;
516
        default:
517
          $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
518
        break;
519
      }
520
    }
521
522
    function deletePoint($pointIndex = 0, $partIndex = 0) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
523
      switch ($this->shapeType) {
524
        case 0:
525
          //Don't delete anything
526
        break;
527
        case 1:
528
        case 11:
529
        case 21:
530
          //Sets the value of the point to zero
531
          $this->SHPData["x"] = 0.0;
532
          $this->SHPData["y"] = 0.0;
533
          if (in_array($this->shapeType,array(11,21))) $this->SHPData["m"] = 0.0;
534
          if (in_array($this->shapeType,array(11))) $this->SHPData["z"] = 0.0;
535
        break;
536
        case 3:
537
        case 5:
538
        case 13:
539
        case 15:
540
        case 23:
541
        case 25:
542
          //Deletes the point from the selected part, if exists
543
          if (isset($this->SHPData["parts"][$partIndex]) && isset($this->SHPData["parts"][$partIndex]["points"][$pointIndex])) {
544
            for ($i = $pointIndex; $i < (count($this->SHPData["parts"][$partIndex]["points"]) - 1); $i++) {
545
              $this->SHPData["parts"][$partIndex]["points"][$i] = $this->SHPData["parts"][$partIndex]["points"][$i + 1];
546
            }
547
            unset($this->SHPData["parts"][$partIndex]["points"][count($this->SHPData["parts"][$partIndex]["points"]) - 1]);
548
549
            $this->SHPData["numparts"] = count($this->SHPData["parts"]);
550
            $this->SHPData["numpoints"]--;
551
          }
552
        break;
553
        case 8:
554
        case 18:
555
        case 28:
556
          //Deletes the point, if exists
557
          if (isset($this->SHPData["points"][$pointIndex])) {
558
            for ($i = $pointIndex; $i < (count($this->SHPData["points"]) - 1); $i++) {
559
              $this->SHPData["points"][$i] = $this->SHPData["points"][$i + 1];
560
            }
561
            unset($this->SHPData["points"][count($this->SHPData["points"]) - 1]);
562
563
            $this->SHPData["numpoints"]--;
564
          }
565
        break;
566
        default:
567
          $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
568
        break;
569
      }
570
    }
571
572
    function getContentLength() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
573
      // The content length for a record is the length of the record contents section measured in 16-bit words.
574
      // one coordinate makes 4 16-bit words (64 bit double)
575
      switch ($this->shapeType) {
576
        case 0:
577
          $result = 0;
578
        break;
579
        case 1:
580
          $result = 10;
581
        break;
582
        case 21:
583
          $result = 10 + 4;
584
        break;
585
        case 11:
586
          $result = 10 + 8;
587
        break;
588
        case 3:
589
        case 5:
590
          $result = 22 + 2*count($this->SHPData["parts"]);
591
          for ($i = 0; $i < count($this->SHPData["parts"]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
592
            $result += 8*count($this->SHPData["parts"][$i]["points"]);
593
          }
594
        break;
595
        case 23:
596 View Code Duplication
        case 25:
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
597
          $result = 22 + (2*4) + 2*count($this->SHPData["parts"]);
598
          for ($i = 0; $i < count($this->SHPData["parts"]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
599
            $result += (8+4)*count($this->SHPData["parts"][$i]["points"]);
600
          }
601
        break;
602
        case 13:
603 View Code Duplication
        case 15:
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
604
          $result = 22 + (4*4) + 2*count($this->SHPData["parts"]);
605
          for ($i = 0; $i < count($this->SHPData["parts"]); $i++) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
606
            $result += (8+8)*count($this->SHPData["parts"][$i]["points"]);
607
          }
608
        break;
609
        case 8:
610
          $result = 20 + 8*count($this->SHPData["points"]);
611
        break;
612 View Code Duplication
        case 28:
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
613
          $result = 20 + (2*4) + (8+4)*count($this->SHPData["points"]);
614
        break;
615 View Code Duplication
        case 18:
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across 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...
616
          $result = 20 + (4*4) + (8+8)*count($this->SHPData["points"]);
617
        break;
618
        default:
619
          $result = false;
620
          $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType));
621
        break;
622
      }
623
      return $result;
624
    }
625
626
    function _loadDBFData() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
627
      $this->DBFData = @dbase_get_record_with_names($this->DBFFile, $this->recordNumber);
628
      unset($this->DBFData["deleted"]);
629
    }
630
631
    function _saveDBFData() {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
632
      unset($this->DBFData["deleted"]);
633
      if ($this->recordNumber <= dbase_numrecords($this->DBFFile)) {
634
        if (!dbase_replace_record($this->DBFFile, array_values($this->DBFData), $this->recordNumber)) {
635
          $this->setError("I wasn't possible to update the information in the DBF file.");
636
        }
637
      } else {
638
        if (!dbase_add_record($this->DBFFile, array_values($this->DBFData))) {
639
          $this->setError("I wasn't possible to add the information to the DBF file.");
640
        }
641
      }
642
    }
643
644
    function setError($error) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
645
      $this->lastError = $error;
646
      return false;
647
    }
648
  }
649