Skip to content

Commit ebfc8fd

Browse files
committed
Changes Enum cases in PascalCase and adds Unknown type.
1 parent 22744ef commit ebfc8fd

File tree

6 files changed

+150
-147
lines changed

6 files changed

+150
-147
lines changed

examples/create_shapefile.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,26 +29,26 @@
2929

3030
require_once __DIR__ . '/../vendor/autoload.php';
3131

32-
$shp = new ShapeFile(ShapeType::POINT, [
32+
$shp = new ShapeFile(ShapeType::Point, [
3333
'xmin' => 464079.002268,
3434
'ymin' => 2120153.74792,
3535
'xmax' => 505213.52849,
3636
'ymax' => 2163205.70036,
3737
]);
3838

39-
$record0 = new ShapeRecord(ShapeType::POINT);
39+
$record0 = new ShapeRecord(ShapeType::Point);
4040
$record0->addPoint([
4141
'x' => 482131.764567,
4242
'y' => 2143634.39608,
4343
]);
4444

45-
$record1 = new ShapeRecord(ShapeType::POINT);
45+
$record1 = new ShapeRecord(ShapeType::Point);
4646
$record1->addPoint([
4747
'x' => 472131.764567,
4848
'y' => 2143634.39608,
4949
]);
5050

51-
$record2 = new ShapeRecord(ShapeType::POINT);
51+
$record2 = new ShapeRecord(ShapeType::Point);
5252
$record2->addPoint([
5353
'x' => 492131.764567,
5454
'y' => 2143634.39608,

examples/read.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
// phpcs:ignore Squiz.Functions.GlobalFunction.Found
3535
function display_file(string $filename): void
3636
{
37-
$shp = new ShapeFile(ShapeType::POINT);
37+
$shp = new ShapeFile(ShapeType::Point);
3838
$shp->loadFromFile($filename);
3939

4040
$i = 1;

src/ShapeFile.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ private function loadHeaders(): bool
374374
$this->readSHP(4);
375375

376376
$shapeType = Util::loadData('V', $this->readSHP(4));
377-
$this->shapeType = ShapeType::tryFrom((int) $shapeType) ?? ShapeType::NULL;
377+
$this->shapeType = ShapeType::tryFrom((int) $shapeType) ?? ShapeType::Unknown;
378378

379379
$this->boundingBox = [];
380380
$this->boundingBox['xmin'] = Util::loadData('d', $this->readSHP(8));
@@ -456,15 +456,15 @@ private function loadRecords(): bool
456456
{
457457
/* Need to start at offset 100 */
458458
while (! $this->eofSHP()) {
459-
$record = new ShapeRecord(ShapeType::NULL);
459+
$record = new ShapeRecord(ShapeType::Unknown);
460460
$record->loadFromFile($this, $this->dbfFile);
461461
if ($record->lastError !== '') {
462462
$this->setError($record->lastError);
463463

464464
return false;
465465
}
466466

467-
if (($record->shapeType === ShapeType::NULL) && $this->eofSHP()) {
467+
if (($record->shapeType === ShapeType::Unknown) && $this->eofSHP()) {
468468
break;
469469
}
470470

src/ShapeRecord.php

Lines changed: 69 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -78,19 +78,19 @@ public function loadFromFile(ShapeFile $shapeFile, $dbfFile): void
7878
}
7979

8080
match ($this->shapeType) {
81-
ShapeType::NULL => $this->loadNullRecord(),
82-
ShapeType::POINT => $this->loadPointRecord(),
83-
ShapeType::POINT_M => $this->loadPointMRecord(),
84-
ShapeType::POINT_Z => $this->loadPointZRecord(),
85-
ShapeType::POLY_LINE => $this->loadPolyLineRecord(),
86-
ShapeType::POLY_LINE_M => $this->loadPolyLineMRecord(),
87-
ShapeType::POLY_LINE_Z => $this->loadPolyLineZRecord(),
88-
ShapeType::POLYGON => $this->loadPolygonRecord(),
89-
ShapeType::POLYGON_M => $this->loadPolygonMRecord(),
90-
ShapeType::POLYGON_Z => $this->loadPolygonZRecord(),
91-
ShapeType::MULTI_POINT => $this->loadMultiPointRecord(),
92-
ShapeType::MULTI_POINT_M => $this->loadMultiPointMRecord(),
93-
ShapeType::MULTI_POINT_Z => $this->loadMultiPointZRecord(),
81+
ShapeType::Null => $this->loadNullRecord(),
82+
ShapeType::Point => $this->loadPointRecord(),
83+
ShapeType::PointM => $this->loadPointMRecord(),
84+
ShapeType::PointZ => $this->loadPointZRecord(),
85+
ShapeType::PolyLine => $this->loadPolyLineRecord(),
86+
ShapeType::PolyLineM => $this->loadPolyLineMRecord(),
87+
ShapeType::PolyLineZ => $this->loadPolyLineZRecord(),
88+
ShapeType::Polygon => $this->loadPolygonRecord(),
89+
ShapeType::PolygonM => $this->loadPolygonMRecord(),
90+
ShapeType::PolygonZ => $this->loadPolygonZRecord(),
91+
ShapeType::MultiPoint => $this->loadMultiPointRecord(),
92+
ShapeType::MultiPointM => $this->loadMultiPointMRecord(),
93+
ShapeType::MultiPointZ => $this->loadMultiPointZRecord(),
9494
default => $this->reportInvalidShapeTypeError(),
9595
};
9696

@@ -125,19 +125,19 @@ public function saveToFile($shpFile, $dbfFile, int $recordNumber): void
125125
$this->saveHeaders();
126126

127127
match ($this->shapeType) {
128-
ShapeType::NULL => null, // Nothing to save
129-
ShapeType::POINT => $this->savePointRecord(),
130-
ShapeType::POINT_M => $this->savePointMRecord(),
131-
ShapeType::POINT_Z => $this->savePointZRecord(),
132-
ShapeType::POLY_LINE => $this->savePolyLineRecord(),
133-
ShapeType::POLY_LINE_M => $this->savePolyLineMRecord(),
134-
ShapeType::POLY_LINE_Z => $this->savePolyLineZRecord(),
135-
ShapeType::POLYGON => $this->savePolygonRecord(),
136-
ShapeType::POLYGON_M => $this->savePolygonMRecord(),
137-
ShapeType::POLYGON_Z => $this->savePolygonZRecord(),
138-
ShapeType::MULTI_POINT => $this->saveMultiPointRecord(),
139-
ShapeType::MULTI_POINT_M => $this->saveMultiPointMRecord(),
140-
ShapeType::MULTI_POINT_Z => $this->saveMultiPointZRecord(),
128+
ShapeType::Null => null, // Nothing to save
129+
ShapeType::Point => $this->savePointRecord(),
130+
ShapeType::PointM => $this->savePointMRecord(),
131+
ShapeType::PointZ => $this->savePointZRecord(),
132+
ShapeType::PolyLine => $this->savePolyLineRecord(),
133+
ShapeType::PolyLineM => $this->savePolyLineMRecord(),
134+
ShapeType::PolyLineZ => $this->savePolyLineZRecord(),
135+
ShapeType::Polygon => $this->savePolygonRecord(),
136+
ShapeType::PolygonM => $this->savePolygonMRecord(),
137+
ShapeType::PolygonZ => $this->savePolygonZRecord(),
138+
ShapeType::MultiPoint => $this->saveMultiPointRecord(),
139+
ShapeType::MultiPointM => $this->saveMultiPointMRecord(),
140+
ShapeType::MultiPointZ => $this->saveMultiPointZRecord(),
141141
default => $this->reportInvalidShapeTypeError(),
142142
};
143143

@@ -185,7 +185,7 @@ private function loadData(string $type, int $count): mixed
185185
*/
186186
private function loadHeaders(): void
187187
{
188-
$this->shapeType = ShapeType::NULL;
188+
$this->shapeType = ShapeType::Unknown;
189189
$recordNumber = $this->loadData('N', 4);
190190
if ($recordNumber === false) {
191191
return;
@@ -206,7 +206,7 @@ private function loadHeaders(): void
206206
return;
207207
}
208208

209-
$this->shapeType = ShapeType::tryFrom((int) $shapeType) ?? ShapeType::NULL;
209+
$this->shapeType = ShapeType::tryFrom((int) $shapeType) ?? ShapeType::Unknown;
210210
}
211211

212212
/**
@@ -604,30 +604,30 @@ public function addPoint(array $point, int $partIndex = 0): void
604604
{
605605
$point = $this->adjustPoint($point);
606606
switch ($this->shapeType) {
607-
case ShapeType::NULL:
607+
case ShapeType::Null:
608608
//Don't add anything
609609
return;
610610

611-
case ShapeType::POINT:
612-
case ShapeType::POINT_Z:
613-
case ShapeType::POINT_M:
611+
case ShapeType::Point:
612+
case ShapeType::PointZ:
613+
case ShapeType::PointM:
614614
//Substitutes the value of the current point
615615
$this->shpData = $point;
616616
break;
617-
case ShapeType::POLY_LINE:
618-
case ShapeType::POLYGON:
619-
case ShapeType::POLY_LINE_Z:
620-
case ShapeType::POLYGON_Z:
621-
case ShapeType::POLY_LINE_M:
622-
case ShapeType::POLYGON_M:
617+
case ShapeType::PolyLine:
618+
case ShapeType::Polygon:
619+
case ShapeType::PolyLineZ:
620+
case ShapeType::PolygonZ:
621+
case ShapeType::PolyLineM:
622+
case ShapeType::PolygonM:
623623
//Adds a new point to the selected part
624624
$this->shpData['parts'][$partIndex]['points'][] = $point;
625625
$this->shpData['numparts'] = count($this->shpData['parts']);
626626
$this->shpData['numpoints'] = 1 + ($this->shpData['numpoints'] ?? 0);
627627
break;
628-
case ShapeType::MULTI_POINT:
629-
case ShapeType::MULTI_POINT_Z:
630-
case ShapeType::MULTI_POINT_M:
628+
case ShapeType::MultiPoint:
629+
case ShapeType::MultiPointZ:
630+
case ShapeType::MultiPointM:
631631
//Adds a new point
632632
$this->shpData['points'][] = $point;
633633
$this->shpData['numpoints'] = 1 + ($this->shpData['numpoints'] ?? 0);
@@ -650,30 +650,30 @@ public function addPoint(array $point, int $partIndex = 0): void
650650
public function deletePoint(int $pointIndex = 0, int $partIndex = 0): void
651651
{
652652
switch ($this->shapeType) {
653-
case ShapeType::NULL:
653+
case ShapeType::Null:
654654
//Don't delete anything
655655
break;
656-
case ShapeType::POINT:
657-
case ShapeType::POINT_Z:
658-
case ShapeType::POINT_M:
656+
case ShapeType::Point:
657+
case ShapeType::PointZ:
658+
case ShapeType::PointM:
659659
//Sets the value of the point to zero
660660
$this->shpData['x'] = 0.0;
661661
$this->shpData['y'] = 0.0;
662-
if (in_array($this->shapeType, [ShapeType::POINT_Z, ShapeType::POINT_M], true)) {
662+
if (in_array($this->shapeType, [ShapeType::PointZ, ShapeType::PointM], true)) {
663663
$this->shpData['m'] = 0.0;
664664
}
665665

666-
if ($this->shapeType === ShapeType::POINT_Z) {
666+
if ($this->shapeType === ShapeType::PointZ) {
667667
$this->shpData['z'] = 0.0;
668668
}
669669

670670
break;
671-
case ShapeType::POLY_LINE:
672-
case ShapeType::POLYGON:
673-
case ShapeType::POLY_LINE_Z:
674-
case ShapeType::POLYGON_Z:
675-
case ShapeType::POLY_LINE_M:
676-
case ShapeType::POLYGON_M:
671+
case ShapeType::PolyLine:
672+
case ShapeType::Polygon:
673+
case ShapeType::PolyLineZ:
674+
case ShapeType::PolygonZ:
675+
case ShapeType::PolyLineM:
676+
case ShapeType::PolygonM:
677677
//Deletes the point from the selected part, if exists
678678
if (
679679
isset($this->shpData['parts'][$partIndex])
@@ -693,9 +693,9 @@ public function deletePoint(int $pointIndex = 0, int $partIndex = 0): void
693693
}
694694

695695
break;
696-
case ShapeType::MULTI_POINT:
697-
case ShapeType::MULTI_POINT_Z:
698-
case ShapeType::MULTI_POINT_M:
696+
case ShapeType::MultiPoint:
697+
case ShapeType::MultiPointZ:
698+
case ShapeType::MultiPointM:
699699
//Deletes the point, if exists
700700
if (isset($this->shpData['points'][$pointIndex])) {
701701
$count = count($this->shpData['points']) - 1;
@@ -723,52 +723,52 @@ public function getContentLength(): int|null
723723
// The content length for a record is the length of the record contents section measured in 16-bit words.
724724
// one coordinate makes 4 16-bit words (64 bit double)
725725
switch ($this->shapeType) {
726-
case ShapeType::NULL:
726+
case ShapeType::Null:
727727
$result = 0;
728728
break;
729-
case ShapeType::POINT:
729+
case ShapeType::Point:
730730
$result = 10;
731731
break;
732-
case ShapeType::POINT_M:
732+
case ShapeType::PointM:
733733
$result = 10 + 4;
734734
break;
735-
case ShapeType::POINT_Z:
735+
case ShapeType::PointZ:
736736
$result = 10 + 8;
737737
break;
738-
case ShapeType::POLY_LINE:
739-
case ShapeType::POLYGON:
738+
case ShapeType::PolyLine:
739+
case ShapeType::Polygon:
740740
$count = count($this->shpData['parts']);
741741
$result = 22 + 2 * $count;
742742
for ($i = 0; $i < $count; ++$i) {
743743
$result += 8 * count($this->shpData['parts'][$i]['points']);
744744
}
745745

746746
break;
747-
case ShapeType::POLY_LINE_M:
748-
case ShapeType::POLYGON_M:
747+
case ShapeType::PolyLineM:
748+
case ShapeType::PolygonM:
749749
$count = count($this->shpData['parts']);
750750
$result = 22 + (2 * 4) + 2 * $count;
751751
for ($i = 0; $i < $count; ++$i) {
752752
$result += (8 + 4) * count($this->shpData['parts'][$i]['points']);
753753
}
754754

755755
break;
756-
case ShapeType::POLY_LINE_Z:
757-
case ShapeType::POLYGON_Z:
756+
case ShapeType::PolyLineZ:
757+
case ShapeType::PolygonZ:
758758
$count = count($this->shpData['parts']);
759759
$result = 22 + (4 * 4) + 2 * $count;
760760
for ($i = 0; $i < $count; ++$i) {
761761
$result += (8 + 8) * count($this->shpData['parts'][$i]['points']);
762762
}
763763

764764
break;
765-
case ShapeType::MULTI_POINT:
765+
case ShapeType::MultiPoint:
766766
$result = 20 + 8 * count($this->shpData['points']);
767767
break;
768-
case ShapeType::MULTI_POINT_M:
768+
case ShapeType::MultiPointM:
769769
$result = 20 + (2 * 4) + (8 + 4) * count($this->shpData['points']);
770770
break;
771-
case ShapeType::MULTI_POINT_Z:
771+
case ShapeType::MultiPointZ:
772772
$result = 20 + (4 * 4) + (8 + 8) * count($this->shpData['points']);
773773
break;
774774
default:

0 commit comments

Comments
 (0)