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

ShapeFile::addRecord()   F

Complexity

Conditions 25
Paths 800

Size

Total Lines 27
Code Lines 17

Duplication

Lines 4
Ratio 14.81 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 4
loc 27
rs 2.771
cc 25
eloc 17
nc 800
nop 1

How to fix   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
/**
34
 * ShapeFile class
35
 *
36
 * @package bfShapeFiles
37
 */
38
  class ShapeFile {
39
    var $FileName;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $FileName.

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...
40
41
    var $SHPFile;
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...
42
    var $SHXFile;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $SHXFile.

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 $DBFFile;
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...
44
45
    var $DBFHeader;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $DBFHeader.

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...
46
47
    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...
48
49
    var $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0);
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $boundingBox.

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...
50
    var $fileLength = 0;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $fileLength.

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...
51
    var $shapeType = 0;
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...
52
53
    var $records;
0 ignored issues
show
Coding Style introduced by
The visibility should be declared for property $records.

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...
54
55
    public function __construct($shapeType, $boundingBox = array("xmin" => 0.0, "ymin" => 0.0, "xmax" => 0.0, "ymax" => 0.0), $FileName = NULL) {
56
      $this->shapeType = $shapeType;
57
      $this->boundingBox = $boundingBox;
58
      $this->FileName = $FileName;
59
      $this->fileLength = 50; // The value for file length is the total length of the file in 16-bit words (including the fifty 16-bit words that make up the header).
60
    }
61
62
    function loadFromFile($FileName) {
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...
63
      $this->FileName = $FileName;
64
65
      if (($this->_openSHPFile()) && ($this->_openDBFFile())) {
66
        $this->_loadHeaders();
67
        $this->_loadRecords();
68
        $this->_closeSHPFile();
69
        $this->_closeDBFFile();
70
      } else {
71
        return false;
72
      }
73
    }
74
75
    function saveToFile($FileName = NULL) {
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...
76
      if ($FileName != NULL) $this->FileName = $FileName;
77
78
      if (($this->_openSHPFile(TRUE)) && ($this->_openSHXFile(TRUE)) && ($this->_openDBFFile(TRUE))) {
79
        $this->_saveHeaders();
80
        $this->_saveRecords();
81
        $this->_closeSHPFile();
82
        $this->_closeSHXFile();
83
        $this->_closeDBFFile();
84
      } else {
85
        return false;
86
      }
87
    }
88
89
    function addRecord($record) {
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...
90
      if ((isset($this->DBFHeader)) && (is_array($this->DBFHeader))) {
91
        $record->updateDBFInfo($this->DBFHeader);
92
      }
93
94
      $this->fileLength += ($record->getContentLength() + 4);
95
      $this->records[] = $record;
96
      $this->records[count($this->records) - 1]->recordNumber = count($this->records);
97
98
      if ($this->boundingBox["xmin"]==0.0 || ($this->boundingBox["xmin"]>$record->SHPData["xmin"])) $this->boundingBox["xmin"] = $record->SHPData["xmin"];
99
      if ($this->boundingBox["xmax"]==0.0 || ($this->boundingBox["xmax"]<$record->SHPData["xmax"])) $this->boundingBox["xmax"] = $record->SHPData["xmax"];
100
101
      if ($this->boundingBox["ymin"]==0.0 || ($this->boundingBox["ymin"]>$record->SHPData["ymin"])) $this->boundingBox["ymin"] = $record->SHPData["ymin"];
102
      if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) $this->boundingBox["ymax"] = $record->SHPData["ymax"];
103
104
      if (in_array($this->shapeType,array(11,13,15,18,21,23,25,28))) {
105 View Code Duplication
        if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) $this->boundingBox["mmin"] = $record->SHPData["mmin"];
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...
106 View Code Duplication
        if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) $this->boundingBox["mmax"] = $record->SHPData["mmax"];
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...
107
      }
108
109
      if (in_array($this->shapeType,array(11,13,15,18))) {
110 View Code Duplication
        if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) $this->boundingBox["zmin"] = $record->SHPData["zmin"];
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...
111 View Code Duplication
        if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) $this->boundingBox["zmax"] = $record->SHPData["zmax"];
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...
112
      }
113
114
      return (count($this->records) - 1);
115
    }
116
117
    function deleteRecord($index) {
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...
118
      if (isset($this->records[$index])) {
119
        $this->fileLength -= ($this->records[$index]->getContentLength() + 4);
120
        for ($i = $index; $i < (count($this->records) - 1); $i++) {
121
          $this->records[$i] = $this->records[$i + 1];
122
        }
123
        unset($this->records[count($this->records) - 1]);
124
        $this->_deleteRecordFromDBF($index);
125
      }
126
    }
127
128
    function getDBFHeader() {
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...
129
      return $this->DBFHeader;
130
    }
131
132
    function setDBFHeader($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...
133
      $this->DBFHeader = $header;
134
135
      for ($i = 0; $i < count($this->records); $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...
136
        $this->records[$i]->updateDBFInfo($header);
137
      }
138
    }
139
140
    function getIndexFromDBFData($field, $value) {
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...
141
      $result = -1;
142
      for ($i = 0; $i < (count($this->records) - 1); $i++) {
143
        if (isset($this->records[$i]->DBFData[$field]) && (strtoupper($this->records[$i]->DBFData[$field]) == strtoupper($value))) {
144
          $result = $i;
145
        }
146
      }
147
148
      return $result;
149
    }
150
151
    function _loadDBFHeader() {
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...
152
      $DBFFile = fopen(str_replace('.*', '.dbf', $this->FileName), 'r');
153
154
      $result = array();
155
      $buff32 = array();
0 ignored issues
show
Unused Code introduced by
$buff32 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...
156
      $i = 1;
157
      $inHeader = true;
158
159
      while ($inHeader) {
160
        if (!feof($DBFFile)) {
161
          $buff32 = fread($DBFFile, 32);
162
          if ($i > 1) {
163
            if (substr($buff32, 0, 1) == chr(13)) {
164
              $inHeader = false;
165
            } else {
166
              $pos = strpos(substr($buff32, 0, 10), chr(0));
167
              $pos = ($pos == 0 ? 10 : $pos);
168
169
              $fieldName = substr($buff32, 0, $pos);
170
              $fieldType = substr($buff32, 11, 1);
171
              $fieldLen = ord(substr($buff32, 16, 1));
172
              $fieldDec = ord(substr($buff32, 17, 1));
173
174
              array_push($result, array($fieldName, $fieldType, $fieldLen, $fieldDec));
175
            }
176
          }
177
          $i++;
178
        } else {
179
          $inHeader = false;
180
        }
181
      }
182
183
      fclose($DBFFile);
184
      return($result);
185
    }
186
187
    function _deleteRecordFromDBF($index) {
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...
188
      if (@dbase_delete_record($this->DBFFile, $index)) {
189
        @dbase_pack($this->DBFFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
190
      }
191
    }
192
193
    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...
194
      fseek($this->SHPFile, 24, SEEK_SET);
195
      $this->fileLength = Util::loadData("N", fread($this->SHPFile, 4));
196
197
      fseek($this->SHPFile, 32, SEEK_SET);
198
      $this->shapeType = Util::loadData("V", fread($this->SHPFile, 4));
199
200
      $this->boundingBox = array();
201
      $this->boundingBox["xmin"] = Util::loadData("d", fread($this->SHPFile, 8));
202
      $this->boundingBox["ymin"] = Util::loadData("d", fread($this->SHPFile, 8));
203
      $this->boundingBox["xmax"] = Util::loadData("d", fread($this->SHPFile, 8));
204
      $this->boundingBox["ymax"] = Util::loadData("d", fread($this->SHPFile, 8));
205
      $this->boundingBox["zmin"] = Util::loadData("d", fread($this->SHPFile, 8));
206
      $this->boundingBox["zmax"] = Util::loadData("d", fread($this->SHPFile, 8));
207
      $this->boundingBox["mmin"] = Util::loadData("d", fread($this->SHPFile, 8));
208
      $this->boundingBox["mmax"] = Util::loadData("d", fread($this->SHPFile, 8));
209
210
      $this->DBFHeader = $this->_loadDBFHeader();
211
    }
212
213
    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...
214
      fwrite($this->SHPFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0));
215
      fwrite($this->SHPFile, pack("N", $this->fileLength));
216
      fwrite($this->SHPFile, pack("V", 1000));
217
      fwrite($this->SHPFile, pack("V", $this->shapeType));
218
      fwrite($this->SHPFile, Util::packDouble($this->boundingBox['xmin']));
219
      fwrite($this->SHPFile, Util::packDouble($this->boundingBox['ymin']));
220
      fwrite($this->SHPFile, Util::packDouble($this->boundingBox['xmax']));
221
      fwrite($this->SHPFile, Util::packDouble($this->boundingBox['ymax']));
222
      fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0));
223
      fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0));
224
      fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0));
225
      fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0));
226
227
      fwrite($this->SHXFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0));
228
      fwrite($this->SHXFile, pack("N", 50 + 4*count($this->records)));
229
      fwrite($this->SHXFile, pack("V", 1000));
230
      fwrite($this->SHXFile, pack("V", $this->shapeType));
231
      fwrite($this->SHXFile, Util::packDouble($this->boundingBox['xmin']));
232
      fwrite($this->SHXFile, Util::packDouble($this->boundingBox['ymin']));
233
      fwrite($this->SHXFile, Util::packDouble($this->boundingBox['xmax']));
234
      fwrite($this->SHXFile, Util::packDouble($this->boundingBox['ymax']));
235
      fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0));
236
      fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0));
237
      fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0));
238
      fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0));
239
    }
240
241
    function _loadRecords() {
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...
242
      fseek($this->SHPFile, 100);
243
      while (!feof($this->SHPFile)) {
244
        $bByte = ftell($this->SHPFile);
245
        $record = new ShapeRecord(-1);
246
        $record->loadFromFile($this->SHPFile, $this->DBFFile);
247
        $eByte = ftell($this->SHPFile);
248
        if (($eByte <= $bByte) || ($record->lastError != "")) {
0 ignored issues
show
Bug introduced by
The property lastError cannot be accessed from this context as it is declared private in class ShapeFile\ShapeRecord.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
249
          return false;
250
        }
251
252
        $this->records[] = $record;
253
      }
254
    }
255
256
    function _saveRecords() {
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
      if (file_exists(str_replace('.*', '.dbf', $this->FileName))) {
258
        @unlink(str_replace('.*', '.dbf', $this->FileName));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
259
      }
260 View Code Duplication
      if (!($this->DBFFile = @dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader))) {
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...
261
        return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
262
      }
263
264
      $offset = 50;
265
      if (is_array($this->records) && (count($this->records) > 0)) {
266
        reset($this->records);
267
        while (list($index, $record) = each($this->records)) {
268
          //Save the record to the .shp file
269
          $record->saveToFile($this->SHPFile, $this->DBFFile, $index + 1);
270
271
          //Save the record to the .shx file
272
          fwrite($this->SHXFile, pack("N", $offset));
273
          fwrite($this->SHXFile, pack("N", $record->getContentLength()));
274
          $offset += (4 + $record->getContentLength());
275
        }
276
      }
277
      @dbase_pack($this->DBFFile);
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
278
    }
279
280 View Code Duplication
    function _openSHPFile($toWrite = false) {
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...
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...
281
      $this->SHPFile = @fopen(str_replace('.*', '.shp', $this->FileName), ($toWrite ? "wb+" : "rb"));
282
      if (!$this->SHPFile) {
283
        return $this->setError(sprintf("It wasn't possible to open the Shape file '%s'", str_replace('.*', '.shp', $this->FileName)));
284
      }
285
286
      return TRUE;
287
    }
288
289
    function _closeSHPFile() {
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...
290
      if ($this->SHPFile) {
291
        fclose($this->SHPFile);
292
        $this->SHPFile = NULL;
293
      }
294
    }
295
296 View Code Duplication
    function _openSHXFile($toWrite = false) {
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...
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...
297
      $this->SHXFile = @fopen(str_replace('.*', '.shx', $this->FileName), ($toWrite ? "wb+" : "rb"));
298
      if (!$this->SHXFile) {
299
        return $this->setError(sprintf("It wasn't possible to open the Index file '%s'", str_replace('.*', '.shx', $this->FileName)));
300
      }
301
302
      return TRUE;
303
    }
304
305
    function _closeSHXFile() {
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...
306
      if ($this->SHXFile) {
307
        fclose($this->SHXFile);
308
        $this->SHXFile = NULL;
309
      }
310
    }
311
312
    function _openDBFFile($toWrite = false) {
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...
313
      $checkFunction = $toWrite ? "is_writable" : "is_readable";
314
      if (($toWrite) && (!file_exists(str_replace('.*', '.dbf', $this->FileName)))) {
315 View Code Duplication
        if (!@dbase_create(str_replace('.*', '.dbf', $this->FileName), $this->DBFHeader)) {
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...
316
          return $this->setError(sprintf("It wasn't possible to create the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
317
        }
318
      }
319
      if ($checkFunction(str_replace('.*', '.dbf', $this->FileName))) {
320
        $this->DBFFile = dbase_open(str_replace('.*', '.dbf', $this->FileName), ($toWrite ? 2 : 0));
321
        if (!$this->DBFFile) {
322
          return $this->setError(sprintf("It wasn't possible to open the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
323
        }
324
      } else {
325
        return $this->setError(sprintf("It wasn't possible to find the DBase file '%s'", str_replace('.*', '.dbf', $this->FileName)));
326
      }
327
      return TRUE;
328
    }
329
330
    function _closeDBFFile() {
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...
331
      if ($this->DBFFile) {
332
        dbase_close($this->DBFFile);
333
        $this->DBFFile = NULL;
334
      }
335
    }
336
337
    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...
338
      $this->lastError = $error;
339
      return false;
340
    }
341
  }
342
343