From 89888d20ac830d4bc342679e0310ebf29448b98e Mon Sep 17 00:00:00 2001 From: Scrutinizer Auto-Fixer Date: Tue, 14 Jun 2016 10:50:59 +0000 Subject: [PATCH] Scrutinizer Auto-Fixes This commit consists of patches automatically generated for this project on https://scrutinizer-ci.com --- examples/read_point.php | 6 ++-- examples/read_polygon.php | 6 ++-- src/ShapeFile.php | 38 ++++++++++++------------- src/ShapeRecord.php | 59 ++++++++++++++++++++------------------- src/Util.php | 14 ++++++---- 5 files changed, 64 insertions(+), 59 deletions(-) diff --git a/examples/read_point.php b/examples/read_point.php index b96c7a2..3bffe19 100644 --- a/examples/read_point.php +++ b/examples/read_point.php @@ -7,14 +7,14 @@ $shp->loadFromFile('../data/capitals.*'); $i = 1; -foreach ($shp->records as $record){ +foreach ($shp->records as $record) { echo "
";
     echo "Record No. $i:\n\n\n";
     echo "SHP Data = ";
-    print_r($record->SHPData);   //All the data related to the point
+    print_r($record->SHPData); //All the data related to the point
     print_r("\n\n\n");
     echo "DBF Data = ";
-    print_r($record->DBFData);   //All the information related to each point
+    print_r($record->DBFData); //All the information related to each point
     print_r("\n\n\n");
     echo "
"; $i++; diff --git a/examples/read_polygon.php b/examples/read_polygon.php index fa749b6..7b60741 100644 --- a/examples/read_polygon.php +++ b/examples/read_polygon.php @@ -7,14 +7,14 @@ $shp->loadFromFile('../data/mexico.*'); $i = 1; -foreach ($shp->records as $record){ +foreach ($shp->records as $record) { echo "
";
     echo "Record No. $i:\n\n\n";
     echo "SHP Data = ";
-    print_r($record->SHPData);   //All the data related to the poligon
+    print_r($record->SHPData); //All the data related to the poligon
     print_r("\n\n\n");
     echo "DBF Data = ";
-    print_r($record->DBFData);   //All the information related to each poligon
+    print_r($record->DBFData); //All the information related to each poligon
     print_r("\n\n\n");
     echo "
"; $i++; diff --git a/src/ShapeFile.php b/src/ShapeFile.php index 50569cc..2b00a74 100644 --- a/src/ShapeFile.php +++ b/src/ShapeFile.php @@ -97,34 +97,34 @@ public function addRecord($record) { $this->records[] = $record; $this->records[count($this->records) - 1]->recordNumber = count($this->records); - if ($this->boundingBox["xmin"]==0.0 || ($this->boundingBox["xmin"]>$record->SHPData["xmin"])) { + if ($this->boundingBox["xmin"] == 0.0 || ($this->boundingBox["xmin"] > $record->SHPData["xmin"])) { $this->boundingBox["xmin"] = $record->SHPData["xmin"]; } - if ($this->boundingBox["xmax"]==0.0 || ($this->boundingBox["xmax"]<$record->SHPData["xmax"])) { + if ($this->boundingBox["xmax"] == 0.0 || ($this->boundingBox["xmax"] < $record->SHPData["xmax"])) { $this->boundingBox["xmax"] = $record->SHPData["xmax"]; } - if ($this->boundingBox["ymin"]==0.0 || ($this->boundingBox["ymin"]>$record->SHPData["ymin"])) { + if ($this->boundingBox["ymin"] == 0.0 || ($this->boundingBox["ymin"] > $record->SHPData["ymin"])) { $this->boundingBox["ymin"] = $record->SHPData["ymin"]; } - if ($this->boundingBox["ymax"]==0.0 || ($this->boundingBox["ymax"]<$record->SHPData["ymax"])) { + if ($this->boundingBox["ymax"] == 0.0 || ($this->boundingBox["ymax"] < $record->SHPData["ymax"])) { $this->boundingBox["ymax"] = $record->SHPData["ymax"]; } - if (in_array($this->shapeType,array(11,13,15,18,21,23,25,28))) { - if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"]==0.0 || ($this->boundingBox["mmin"]>$record->SHPData["mmin"])) { + if (in_array($this->shapeType, array(11, 13, 15, 18, 21, 23, 25, 28))) { + if (!isset($this->boundingBox["mmin"]) || $this->boundingBox["mmin"] == 0.0 || ($this->boundingBox["mmin"] > $record->SHPData["mmin"])) { $this->boundingBox["mmin"] = $record->SHPData["mmin"]; } - if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"]==0.0 || ($this->boundingBox["mmax"]<$record->SHPData["mmax"])) { + if (!isset($this->boundingBox["mmax"]) || $this->boundingBox["mmax"] == 0.0 || ($this->boundingBox["mmax"] < $record->SHPData["mmax"])) { $this->boundingBox["mmax"] = $record->SHPData["mmax"]; } } - if (in_array($this->shapeType,array(11,13,15,18))) { - if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"]==0.0 || ($this->boundingBox["zmin"]>$record->SHPData["zmin"])) { + if (in_array($this->shapeType, array(11, 13, 15, 18))) { + if (!isset($this->boundingBox["zmin"]) || $this->boundingBox["zmin"] == 0.0 || ($this->boundingBox["zmin"] > $record->SHPData["zmin"])) { $this->boundingBox["zmin"] = $record->SHPData["zmin"]; } - if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"]==0.0 || ($this->boundingBox["zmax"]<$record->SHPData["zmax"])) { + if (!isset($this->boundingBox["zmax"]) || $this->boundingBox["zmax"] == 0.0 || ($this->boundingBox["zmax"] < $record->SHPData["zmax"])) { $this->boundingBox["zmax"] = $record->SHPData["zmax"]; } } @@ -237,23 +237,23 @@ private function _saveHeaders() { fwrite($this->SHPFile, Util::packDouble($this->boundingBox['ymin'])); fwrite($this->SHPFile, Util::packDouble($this->boundingBox['xmax'])); fwrite($this->SHPFile, Util::packDouble($this->boundingBox['ymax'])); - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0)); - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); - fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmin']) ? $this->boundingBox['zmin'] : 0)); + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['zmax']) ? $this->boundingBox['zmax'] : 0)); + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmin']) ? $this->boundingBox['mmin'] : 0)); + fwrite($this->SHPFile, Util::packDouble(isset($this->boundingBox['mmax']) ? $this->boundingBox['mmax'] : 0)); fwrite($this->SHXFile, pack("NNNNNN", 9994, 0, 0, 0, 0, 0)); - fwrite($this->SHXFile, pack("N", 50 + 4*count($this->records))); + fwrite($this->SHXFile, pack("N", 50 + 4 * count($this->records))); fwrite($this->SHXFile, pack("V", 1000)); fwrite($this->SHXFile, pack("V", $this->shapeType)); fwrite($this->SHXFile, Util::packDouble($this->boundingBox['xmin'])); fwrite($this->SHXFile, Util::packDouble($this->boundingBox['ymin'])); fwrite($this->SHXFile, Util::packDouble($this->boundingBox['xmax'])); fwrite($this->SHXFile, Util::packDouble($this->boundingBox['ymax'])); - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmin'])?$this->boundingBox['zmin']:0)); - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmax'])?$this->boundingBox['zmax']:0)); - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmin'])?$this->boundingBox['mmin']:0)); - fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmax'])?$this->boundingBox['mmax']:0)); + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmin']) ? $this->boundingBox['zmin'] : 0)); + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['zmax']) ? $this->boundingBox['zmax'] : 0)); + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmin']) ? $this->boundingBox['mmin'] : 0)); + fwrite($this->SHXFile, Util::packDouble(isset($this->boundingBox['mmax']) ? $this->boundingBox['mmax'] : 0)); } private function _loadRecords() { diff --git a/src/ShapeRecord.php b/src/ShapeRecord.php index 8d4853f..0fc4cc6 100644 --- a/src/ShapeRecord.php +++ b/src/ShapeRecord.php @@ -42,6 +42,9 @@ class ShapeRecord { public $SHPData = array(); public $DBFData = array(); + /** + * @param integer $shapeType + */ public function __construct($shapeType) { $this->shapeType = $shapeType; } @@ -275,7 +278,7 @@ private function _loadMultiPointRecord() { } } - private function _loadMultiPointMZRecord( $type ) { + private function _loadMultiPointMZRecord($type) { $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8)); @@ -308,7 +311,7 @@ private function _saveMultiPointRecord() { } } - private function _saveMultiPointMZRecord( $type ) { + private function _saveMultiPointMZRecord($type) { fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); @@ -358,10 +361,10 @@ private function _loadPolyLineRecord() { } } - fseek($this->SHPFile, $firstIndex + ($readPoints*16)); + fseek($this->SHPFile, $firstIndex + ($readPoints * 16)); } - private function _loadPolyLineMZRecord( $type ) { + private function _loadPolyLineMZRecord($type) { $this->SHPData[$type."min"] = Util::loadData("d", fread($this->SHPFile, 8)); $this->SHPData[$type."max"] = Util::loadData("d", fread($this->SHPFile, 8)); @@ -376,7 +379,7 @@ private function _loadPolyLineMZRecord( $type ) { } } - fseek($this->SHPFile, $firstIndex + ($readPoints*24)); + fseek($this->SHPFile, $firstIndex + ($readPoints * 24)); } private function _loadPolyLineMRecord() { @@ -398,10 +401,10 @@ private function _savePolyLineRecord() { fwrite($this->SHPFile, pack("VV", $this->SHPData["numparts"], $this->SHPData["numpoints"])); for ($i = 0; $i < $this->SHPData["numparts"]; $i++) { - fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i])-1)); + fwrite($this->SHPFile, pack("V", count($this->SHPData["parts"][$i]) - 1)); } - foreach ($this->SHPData["parts"] as $partData){ + foreach ($this->SHPData["parts"] as $partData) { reset($partData["points"]); while (list($pointIndex, $pointData) = each($partData["points"])) { $this->_savePoint($pointData); @@ -409,10 +412,10 @@ private function _savePolyLineRecord() { } } - private function _savePolyLineMZRecord( $type ) { + private function _savePolyLineMZRecord($type) { fwrite($this->SHPFile, pack("dd", $this->SHPData[$type."min"], $this->SHPData[$type."max"])); - foreach ($this->SHPData["parts"] as $partData){ + foreach ($this->SHPData["parts"] as $partData) { reset($partData["points"]); while (list($pointIndex, $pointData) = each($partData["points"])) { fwrite($this->SHPFile, Util::packDouble($pointData[$type])); @@ -465,10 +468,10 @@ public function addPoint($point, $partIndex = 0) { case 1: case 11: case 21: - if (in_array($this->shapeType,array(11,21)) && !isset($point["m"])) { + if (in_array($this->shapeType, array(11, 21)) && !isset($point["m"])) { $point["m"] = 0.0; // no_value } - if (in_array($this->shapeType,array(11)) && !isset($point["z"])) { + if (in_array($this->shapeType, array(11)) && !isset($point["z"])) { $point["z"] = 0.0; // no_value } //Substitutes the value of the current point @@ -480,10 +483,10 @@ public function addPoint($point, $partIndex = 0) { case 15: case 23: case 25: - if (in_array($this->shapeType,array(13,15,23,25)) && !isset($point["m"])) { + if (in_array($this->shapeType, array(13, 15, 23, 25)) && !isset($point["m"])) { $point["m"] = 0.0; // no_value } - if (in_array($this->shapeType,array(13,15)) && !isset($point["z"])) { + if (in_array($this->shapeType, array(13, 15)) && !isset($point["z"])) { $point["z"] = 0.0; // no_value } @@ -516,15 +519,15 @@ public function addPoint($point, $partIndex = 0) { $this->SHPData["parts"][$partIndex]["points"][] = $point; $this->SHPData["numparts"] = count($this->SHPData["parts"]); - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"]) ? $this->SHPData["numpoints"] : 0); break; case 8: case 18: case 28: - if (in_array($this->shapeType,array(18,28)) && !isset($point["m"])) { + if (in_array($this->shapeType, array(18, 28)) && !isset($point["m"])) { $point["m"] = 0.0; // no_value } - if (in_array($this->shapeType,array(18)) && !isset($point["z"])) { + if (in_array($this->shapeType, array(18)) && !isset($point["z"])) { $point["z"] = 0.0; // no_value } @@ -555,7 +558,7 @@ public function addPoint($point, $partIndex = 0) { } $this->SHPData["points"][] = $point; - $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"])?$this->SHPData["numpoints"]:0); + $this->SHPData["numpoints"] = 1 + (isset($this->SHPData["numpoints"]) ? $this->SHPData["numpoints"] : 0); break; default: $this->setError(sprintf("The Shape Type '%s' is not supported.", $this->shapeType)); @@ -574,10 +577,10 @@ public function deletePoint($pointIndex = 0, $partIndex = 0) { //Sets the value of the point to zero $this->SHPData["x"] = 0.0; $this->SHPData["y"] = 0.0; - if (in_array($this->shapeType,array(11,21))) { + if (in_array($this->shapeType, array(11, 21))) { $this->SHPData["m"] = 0.0; } - if (in_array($this->shapeType,array(11))) { + if (in_array($this->shapeType, array(11))) { $this->SHPData["z"] = 0.0; } break; @@ -635,33 +638,33 @@ public function getContentLength() { break; case 3: case 5: - $result = 22 + 2*count($this->SHPData["parts"]); + $result = 22 + 2 * count($this->SHPData["parts"]); for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { - $result += 8*count($this->SHPData["parts"][$i]["points"]); + $result += 8 * count($this->SHPData["parts"][$i]["points"]); } break; case 23: case 25: - $result = 22 + (2*4) + 2*count($this->SHPData["parts"]); + $result = 22 + (2 * 4) + 2 * count($this->SHPData["parts"]); for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { - $result += (8+4)*count($this->SHPData["parts"][$i]["points"]); + $result += (8 + 4) * count($this->SHPData["parts"][$i]["points"]); } break; case 13: case 15: - $result = 22 + (4*4) + 2*count($this->SHPData["parts"]); + $result = 22 + (4 * 4) + 2 * count($this->SHPData["parts"]); for ($i = 0; $i < count($this->SHPData["parts"]); $i++) { - $result += (8+8)*count($this->SHPData["parts"][$i]["points"]); + $result += (8 + 8) * count($this->SHPData["parts"][$i]["points"]); } break; case 8: - $result = 20 + 8*count($this->SHPData["points"]); + $result = 20 + 8 * count($this->SHPData["points"]); break; case 28: - $result = 20 + (2*4) + (8+4)*count($this->SHPData["points"]); + $result = 20 + (2 * 4) + (8 + 4) * count($this->SHPData["points"]); break; case 18: - $result = 20 + (4*4) + (8+8)*count($this->SHPData["points"]); + $result = 20 + (4 * 4) + (8 + 8) * count($this->SHPData["points"]); break; default: $result = false; diff --git a/src/Util.php b/src/Util.php index dacf59f..560c016 100644 --- a/src/Util.php +++ b/src/Util.php @@ -32,14 +32,16 @@ class Util { public static function loadData($type, $data) { - if (!$data) return $data; + if (!$data) { + return $data; + } $tmp = unpack($type, $data); return current($tmp); } public static function swap($binValue) { $result = $binValue{strlen($binValue) - 1}; - for($i = strlen($binValue) - 2; $i >= 0 ; $i--) { + for ($i = strlen($binValue) - 2; $i >= 0; $i--) { $result .= $binValue{$i}; } @@ -47,15 +49,15 @@ public static function swap($binValue) { } public static function packDouble($value, $mode = 'LE') { - $value = (double)$value; + $value = (double) $value; $bin = pack("d", $value); //We test if the conversion of an integer (1) is done as LE or BE by default - switch (pack ('L', 1)) { - case pack ('V', 1): //Little Endian + switch (pack('L', 1)) { + case pack('V', 1): //Little Endian $result = ($mode == 'LE') ? $bin : self::swap($bin); break; - case pack ('N', 1): //Big Endian + case pack('N', 1): //Big Endian $result = ($mode == 'BE') ? $bin : self::swap($bin); break; default: //Some other thing, we just return false