Skip to content

Commit

Permalink
Code simplified
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre-T committed Aug 7, 2024
1 parent 033c8f0 commit ee46ba1
Show file tree
Hide file tree
Showing 21 changed files with 161 additions and 228 deletions.
1 change: 0 additions & 1 deletion lib/LongitudeOne/SpatialTypes/Types/AbstractCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ abstract class AbstractCollection extends AbstractSpatialType implements Collect
*/
public function __construct(?int $srid = null)
{
$this->preConstruct();
$this->setSrid($srid);
}

Expand Down
1 change: 0 additions & 1 deletion lib/LongitudeOne/SpatialTypes/Types/AbstractLineString.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ abstract class AbstractLineString extends AbstractSpatialType implements LineStr
*/
public function __construct(array $points, ?int $srid = null)
{
$this->preConstruct();
$this->setSrid($srid);

$this->addPoints($points);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ abstract class AbstractMultiLineString extends AbstractSpatialType implements Mu
*/
public function __construct(array $lineStrings, ?int $srid = null)
{
$this->preConstruct();
$this->setSrid($srid);
$this->addLineStrings($lineStrings);
}
Expand Down
1 change: 0 additions & 1 deletion lib/LongitudeOne/SpatialTypes/Types/AbstractMultiPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ abstract class AbstractMultiPoint extends AbstractSpatialType implements MultiPo
*/
public function __construct(array $points, ?int $srid = null)
{
$this->preConstruct();
$this->setSrid($srid);

$this->addPoints($points);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ abstract class AbstractMultiPolygon extends AbstractSpatialType implements Multi
*/
public function __construct(array $polygons, ?int $srid = null)
{
$this->preConstruct();
$this->setSrid($srid);
$this->addPolygons($polygons);
}
Expand Down
1 change: 0 additions & 1 deletion lib/LongitudeOne/SpatialTypes/Types/AbstractPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ abstract class AbstractPolygon extends AbstractSpatialType implements PolygonInt
*/
public function __construct(array $rings, ?int $srid = null)
{
$this->preConstruct();
$this->setSrid($srid);
$this->addRings($rings);
}
Expand Down
81 changes: 13 additions & 68 deletions lib/LongitudeOne/SpatialTypes/Types/AbstractSpatialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

use LongitudeOne\SpatialTypes\Enum\DimensionEnum;
use LongitudeOne\SpatialTypes\Enum\FamilyEnum;
use LongitudeOne\SpatialTypes\Enum\TypeEnum;
use LongitudeOne\SpatialTypes\Helper\DimensionHelper;
use LongitudeOne\SpatialTypes\Interfaces\SpatialInterface;

/**
Expand All @@ -29,36 +27,11 @@
*/
abstract class AbstractSpatialType implements SpatialInterface
{
/**
* @var DimensionEnum the dimension of the object (2D, 3D with elevation, 3D with moment, 4D)
*/
protected DimensionEnum $dimension;

/**
* @var FamilyEnum the family of the object (Geometry, Geography)
*/
protected FamilyEnum $family;

/**
* @var null|int the SpatialTypes Reference Identifier (SRID)
*/
protected ?int $srid = null;

/**
* @var TypeEnum The type of the object (Point, LineString, Polygon, etc.).
*/
protected TypeEnum $type;

/**
* Family getter.
*
* @return FamilyEnum the family of the object (Geometry, Geography)
*/
public function getFamily(): FamilyEnum
{
return $this->family;
}

/**
* SRID getter.
*/
Expand All @@ -67,22 +40,15 @@ public function getSrid(): ?int
return $this->srid;
}

/**
* Type getter.
*/
public function getType(): string
{
return $this->type->value;
}

/**
* Does this object (or point of this object) have an M coordinate?
*/
public function hasM(): bool
{
$dimensionHelper = new DimensionHelper($this->dimension);

return $dimensionHelper->hasM();
return match ($this->getDimension()) {
DimensionEnum::X_Y_M, DimensionEnum::X_Y_Z_M => true,
default => false,
};
}

/**
Expand All @@ -100,9 +66,10 @@ public function hasSameDimension(SpatialInterface $spatial): bool
*/
public function hasZ(): bool
{
$dimensionHelper = new DimensionHelper($this->dimension);

return $dimensionHelper->hasZ();
return match ($this->getDimension()) {
DimensionEnum::X_Y_Z, DimensionEnum::X_Y_Z_M => true,
default => false,
};
}

/**
Expand Down Expand Up @@ -134,41 +101,19 @@ public function setSrid(?int $srid): static
/**
* Dimension getter.
*/
protected function getDimension(): DimensionEnum
{
return $this->dimension;
}
abstract protected function getDimension(): DimensionEnum;

/**
* Pre-construct method.
*/
protected function preConstruct(): void
{
$this->type = $this->initType();
$this->family = $this->initFamily();
$this->dimension = $this->initDimension();
}

/**
* This function is called in the main constructor.
*
* @return DimensionEnum the dimension of the object (2D, 3D with elevation, 3D with moment, 4D)
*/
abstract protected function initDimension(): DimensionEnum;

/**
* This function is called in the main constructor.
* Family getter.
*
* @return FamilyEnum the family of the object (Geometry, Geography)
*/
abstract protected function initFamily(): FamilyEnum;
abstract public function getFamily(): FamilyEnum;

/**
* This function is called in the main constructor.
*
* @return TypeEnum The type of the object (Point, LineString, Polygon, etc.).
* Type getter.
*/
abstract protected function initType(): TypeEnum;
abstract public function getType(): string;

/**
* Convert any spatial object to its array representation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
class GeographyCollection extends AbstractCollection implements CollectionInterface
{
/**
* initDimension.
* init Family.
*/
protected function initDimension(): DimensionEnum
public function getFamily(): FamilyEnum
{
return DimensionEnum::X_Y;
return FamilyEnum::GEOGRAPHY;
}

/**
* init Family.
* initType.
*/
protected function initFamily(): FamilyEnum
public function getType(): string
{
return FamilyEnum::GEOGRAPHY;
return TypeEnum::COLLECTION->value;
}

/**
* initType.
* initDimension.
*/
protected function initType(): TypeEnum
protected function getDimension(): DimensionEnum
{
return TypeEnum::COLLECTION;
return DimensionEnum::X_Y;
}
}
18 changes: 9 additions & 9 deletions lib/LongitudeOne/SpatialTypes/Types/Geography/LineString.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
class LineString extends AbstractLineString implements LineStringInterface
{
/**
* Define the dimension.
* Define the family.
*/
protected function initDimension(): DimensionEnum
public function getFamily(): FamilyEnum
{
return DimensionEnum::X_Y;
return FamilyEnum::GEOGRAPHY;
}

/**
* Define the family.
* Define the type.
*/
protected function initFamily(): FamilyEnum
public function getType(): string
{
return FamilyEnum::GEOGRAPHY;
return TypeEnum::LINESTRING->value;
}

/**
* Define the type.
* Define the dimension.
*/
protected function initType(): TypeEnum
protected function getDimension(): DimensionEnum
{
return TypeEnum::LINESTRING;
return DimensionEnum::X_Y;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
class MultiLineString extends AbstractMultiLineString implements MultiLineStringInterface
{
/**
* Initialize the dimension of the object.
* Initialize the family of the object.
*/
protected function initDimension(): DimensionEnum
public function getFamily(): FamilyEnum
{
return DimensionEnum::X_Y;
return FamilyEnum::GEOGRAPHY;
}

/**
* Initialize the family of the object.
* Initialize the type of the object.
*/
protected function initFamily(): FamilyEnum
public function getType(): string
{
return FamilyEnum::GEOGRAPHY;
return TypeEnum::MULTILINESTRING->value;
}

/**
* Initialize the type of the object.
* Initialize the dimension of the object.
*/
protected function initType(): TypeEnum
protected function getDimension(): DimensionEnum
{
return TypeEnum::MULTILINESTRING;
return DimensionEnum::X_Y;
}
}
18 changes: 9 additions & 9 deletions lib/LongitudeOne/SpatialTypes/Types/Geography/MultiPoint.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
class MultiPoint extends AbstractMultiPoint implements MultiPointInterface
{
/**
* Define the dimension.
* Define the family.
*/
protected function initDimension(): DimensionEnum
public function getFamily(): FamilyEnum
{
return DimensionEnum::X_Y;
return FamilyEnum::GEOGRAPHY;
}

/**
* Define the family.
* Define the type.
*/
protected function initFamily(): FamilyEnum
public function getType(): string
{
return FamilyEnum::GEOGRAPHY;
return TypeEnum::MULTIPOINT->value;
}

/**
* Define the type.
* Define the dimension.
*/
protected function initType(): TypeEnum
protected function getDimension(): DimensionEnum
{
return TypeEnum::MULTIPOINT;
return DimensionEnum::X_Y;
}
}
18 changes: 9 additions & 9 deletions lib/LongitudeOne/SpatialTypes/Types/Geography/MultiPolygon.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,26 +25,26 @@
class MultiPolygon extends AbstractMultiPolygon implements MultiPolygonInterface
{
/**
* Initialize the dimension of the object.
* Initialize the family of the object.
*/
protected function initDimension(): DimensionEnum
public function getFamily(): FamilyEnum
{
return DimensionEnum::X_Y;
return FamilyEnum::GEOGRAPHY;
}

/**
* Initialize the family of the object.
* Initialize the type of the object.
*/
protected function initFamily(): FamilyEnum
public function getType(): string
{
return FamilyEnum::GEOGRAPHY;
return TypeEnum::MULTIPOLYGON->value;
}

/**
* Initialize the type of the object.
* Initialize the dimension of the object.
*/
protected function initType(): TypeEnum
protected function getDimension(): DimensionEnum
{
return TypeEnum::MULTIPOLYGON;
return DimensionEnum::X_Y;
}
}
Loading

0 comments on commit ee46ba1

Please sign in to comment.