Skip to content

Commit

Permalink
Return types mentioned (#67)
Browse files Browse the repository at this point in the history
* Return types mentioned
* Unexpected file removed
* Show installed libraries
* Remove no-longer existing error in baseline
* Remove no-longer used libraries in composer
  • Loading branch information
Alexandre-T committed May 12, 2024
1 parent 31be31f commit 4c9ac94
Show file tree
Hide file tree
Showing 43 changed files with 146 additions and 344 deletions.
3 changes: 3 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,6 @@ plugins:
enabled: true
phpmd:
enabled: true
checks:
NamingShortVariable:
enabled: false
3 changes: 3 additions & 0 deletions .github/workflows/full.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@ jobs:
- name: Install libraries
run: composer --prefer-stable update -vvv

- name: Show libraries
run: composer show

- name: Run test suite and with coverage for codeclimate for PHP 8.3 and doctrine/orm ^3.1 only
if: ${{ env.HAS_CC_SECRET == 'true' }}
uses: paambaati/codeclimate-action@v5.0.0
Expand Down
6 changes: 1 addition & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "longitude-one/doctrine-spatial",
"type": "library",
"description": "Doctrine2 multi-platform support for spatial types and functions",
"keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography"],
"keywords": ["orm", "dbal", "database", "postgresql", "mysql", "opengis", "postgis", "gis", "spatial", "geometry", "geography", "iso-13249"],
"authors": [
{
"name": "Derek Lambert",
Expand Down Expand Up @@ -32,13 +32,9 @@
"doctrine/orm": "^2.19|^3.1"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^3.0",
"monolog/monolog": "^2.0",
"phpmd/phpmd": "^2.10",
"phpunit/phpunit": "^10.0",
"phpunit/phpcov": "^9",
"php-coveralls/php-coveralls": "^2.4",
"squizlabs/php_codesniffer": "^3.6",
"cache/array-adapter": "^1.1",
"dg/bypass-finals": "^1.3"
},
Expand Down
22 changes: 8 additions & 14 deletions lib/LongitudeOne/Spatial/DBAL/Platform/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ abstract class AbstractPlatform implements PlatformInterface
/**
* Check both arguments and return srid when possible.
*
* @param array<string, mixed> $column array MAY contain 'srid' as key
* @param array<string, mixed> $column array MAY contain 'srid' key
* @param ?int $srid srid MAY be provided
*
* @throws InvalidValueException when SRID is not null nor an integer
Expand All @@ -64,7 +64,7 @@ protected static function checkSrid(array $column, ?int $srid): ?int
/**
* Check both argument and return AbstractSpatialType when possible.
*
* @param array<string, mixed> $column array SHOULD contain 'type' as key
* @param array<string, mixed> $column array SHOULD contain 'type' key
* @param ?AbstractSpatialType $type type is now provided
*
* @throws MissingArgumentException when $column doesn't contain 'type' and AbstractSpatialType is null
Expand All @@ -86,11 +86,9 @@ protected static function checkType(array $column, ?AbstractSpatialType $type):
* @param DoctrineSpatialTypeInterface $type The abstract spatial type
* @param resource|string $sqlExpr the SQL expression
*
* @return SpatialInterface
*
* @throws ExceptionInterface|InvalidValueException when the provided type is not supported
*/
public function convertBinaryToPhpValue(DoctrineSpatialTypeInterface $type, $sqlExpr)
public function convertBinaryToPhpValue(DoctrineSpatialTypeInterface $type, $sqlExpr): SpatialInterface
{
if (is_resource($sqlExpr)) {
$sqlExpr = stream_get_contents($sqlExpr);
Expand All @@ -111,11 +109,9 @@ public function convertBinaryToPhpValue(DoctrineSpatialTypeInterface $type, $sql
* @param AbstractSpatialType $type The abstract spatial type
* @param string $sqlExpr the SQL expression
*
* @return SpatialInterface
*
* @throws InvalidValueException when the provided type is not supported
*/
public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr)
public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr): SpatialInterface
{
$parser = new StringParser($sqlExpr);

Expand All @@ -129,10 +125,8 @@ public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr)
*
* @param AbstractSpatialType $type The spatial type
* @param SpatialInterface $value The geometry object
*
* @return string
*/
public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterface $value)
public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterface $value): string
{
// the unused variable $type is used by overriding method
return sprintf('%s(%s)', mb_strtoupper($value->getType()), $value);
Expand All @@ -147,7 +141,7 @@ public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterfa
*
* @return string[]
*/
public function getMappedDatabaseTypes(AbstractSpatialType $type)
public function getMappedDatabaseTypes(AbstractSpatialType $type): array
{
$sqlType = mb_strtolower($type->getSQLType());

Expand All @@ -159,14 +153,14 @@ public function getMappedDatabaseTypes(AbstractSpatialType $type)
}

/**
* Create spatial object from parsed value.
* Create a spatial object from parsed value.
*
* @param DoctrineSpatialTypeInterface $type The type spatial type
* @param array{type: string, srid?: ?int, value:mixed} $value The value of the spatial object
*
* @throws InvalidValueException when the provided type is not supported
*/
private function newObjectFromValue(DoctrineSpatialTypeInterface $type, $value): SpatialInterface
private function newObjectFromValue(DoctrineSpatialTypeInterface $type, array $value): SpatialInterface
{
$typeFamily = $type->getTypeFamily();
$typeName = mb_strtoupper($value['type']);
Expand Down
12 changes: 4 additions & 8 deletions lib/LongitudeOne/Spatial/DBAL/Platform/MySql.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
use LongitudeOne\Spatial\PHP\Types\SpatialInterface;

/**
* MySql5.7 and less spatial platform.
* MySql spatial platform.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @author Alexandre Tranchant <alexandre.tranchant@gmail.com>
Expand All @@ -36,10 +36,8 @@ class MySql extends AbstractPlatform
*
* @param AbstractSpatialType $type The spatial type
* @param string $sqlExpr The SQL expression
*
* @return string
*/
public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr)
public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr): string
{
return sprintf('ST_GeomFromText(%s)', $sqlExpr);
}
Expand All @@ -49,18 +47,16 @@ public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr)
*
* @param AbstractSpatialType $type The spatial type
* @param string $sqlExpr The SQL expression
*
* @return string
*/
public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr)
public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr): string
{
return sprintf('ST_AsBinary(%s)', $sqlExpr);
}

/**
* Gets the SQL declaration snippet for a field of this type.
*
* @param array<string, mixed> $column array SHOULD contain 'type' as key
* @param array<string, mixed> $column array SHOULD contain 'type' key
* @param ?AbstractSpatialType $type type is now provided
* @param ?int $srid the srid SHOULD be forwarded when known
*
Expand Down
25 changes: 7 additions & 18 deletions lib/LongitudeOne/Spatial/DBAL/Platform/PlatformInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

use LongitudeOne\Spatial\DBAL\Types\AbstractSpatialType;
use LongitudeOne\Spatial\Exception\MissingArgumentException;
use LongitudeOne\Spatial\PHP\Types\Geometry\GeometryInterface;
use LongitudeOne\Spatial\PHP\Types\SpatialInterface;

/**
Expand All @@ -33,50 +32,40 @@ interface PlatformInterface
*
* @param AbstractSpatialType $type Spatial type
* @param null|resource|string $sqlExpr Sql expression
*
* @return GeometryInterface
*/
public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr);
public function convertBinaryToPhpValue(AbstractSpatialType $type, $sqlExpr): SpatialInterface;

/**
* Convert string data to a php value.
*
* @param AbstractSpatialType $type The abstract spatial type
* @param string $sqlExpr the SQL expression
*
* @return GeometryInterface
*/
public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr);
public function convertStringToPhpValue(AbstractSpatialType $type, $sqlExpr): SpatialInterface;

/**
* Convert to database value.
*
* @param AbstractSpatialType $type The spatial type
* @param SpatialInterface $value The geometry or geographic interface
*
* @return string
*/
public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterface $value);
public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterface $value): string;

/**
* Convert to database value to SQL.
*
* @param AbstractSpatialType $type The spatial type
* @param string $sqlExpr The SQL expression
*
* @return string
*/
public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr);
public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr): string;

/**
* Convert to php value to SQL.
*
* @param AbstractSpatialType $type The spatial type
* @param string $sqlExpr The SQL expression
*
* @return string
*/
public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr);
public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr): string;

/**
* Get an array of database types that map to this Doctrine type.
Expand All @@ -85,12 +74,12 @@ public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr);
*
* @return string[]
*/
public function getMappedDatabaseTypes(AbstractSpatialType $type);
public function getMappedDatabaseTypes(AbstractSpatialType $type): array;

/**
* Gets the SQL declaration snippet for a field of this type.
*
* @param array<string, mixed> $column array SHOULD contain 'type' as key
* @param array<string, mixed> $column array SHOULD contain 'type' key
* @param ?AbstractSpatialType $type type is now provided
* @param ?int $srid the srid SHOULD be forwarded when known
*
Expand Down
12 changes: 3 additions & 9 deletions lib/LongitudeOne/Spatial/DBAL/Platform/PostgreSql.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,8 @@ class PostgreSql extends AbstractPlatform
*
* @param AbstractSpatialType $type The spatial type
* @param SpatialInterface $value The geometry interface
*
* @return string
*/
public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterface $value)
public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterface $value): string
{
$sridSQL = null;
$srid = null;
Expand All @@ -68,10 +66,8 @@ public function convertToDatabaseValue(AbstractSpatialType $type, SpatialInterfa
*
* @param AbstractSpatialType $type The spatial type
* @param string $sqlExpr The SQL expression
*
* @return string
*/
public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr)
public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr): string
{
if ($type instanceof GeographyType) {
return sprintf('ST_GeographyFromText(%s)', $sqlExpr);
Expand All @@ -85,10 +81,8 @@ public function convertToDatabaseValueSql(AbstractSpatialType $type, $sqlExpr)
*
* @param AbstractSpatialType $type The spatial type
* @param string $sqlExpr The SQL expression
*
* @return string
*/
public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr)
public function convertToPhpValueSql(AbstractSpatialType $type, $sqlExpr): string
{
if ($type instanceof GeographyType) {
return sprintf('ST_AsEWKT(%s)', $sqlExpr);
Expand Down
11 changes: 4 additions & 7 deletions lib/LongitudeOne/Spatial/DBAL/Types/AbstractSpatialType.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
use LongitudeOne\Spatial\DBAL\Platform\PostgreSql;
use LongitudeOne\Spatial\Exception\InvalidValueException;
use LongitudeOne\Spatial\Exception\UnsupportedPlatformException;
use LongitudeOne\Spatial\PHP\Types\Geometry\GeometryInterface;
use LongitudeOne\Spatial\PHP\Types\SpatialInterface;

/**
Expand All @@ -41,12 +40,12 @@ abstract class AbstractSpatialType extends Type implements DoctrineSpatialTypeIn
/**
* Does working with this column require SQL conversion functions?
*
* This is a metadata function that is required for example in the ORM.
* This is a metadata function required, for example, in the ORM.
* Usage of {@link convertToDatabaseValueSql} and
* {@link convertToPhpValueSql} works for any type and mostly
* does nothing. This method can additionally be used for optimization purposes.
* does nothing. This method can additionally be used for optimization.
*
* Spatial types requires conversion.
* Spatial types require conversion.
*
* @return bool
*/
Expand Down Expand Up @@ -100,11 +99,9 @@ public function convertToDatabaseValueSql($sqlExpr, AbstractPlatform $platform):
* @param null|resource|string $value value to convert to PHP
* @param AbstractPlatform $platform platform database
*
* @return null|GeometryInterface
*
* @throws UnsupportedPlatformException when platform is unsupported
*/
public function convertToPHPValue($value, AbstractPlatform $platform): mixed
public function convertToPHPValue($value, AbstractPlatform $platform): ?SpatialInterface
{
if (null === $value) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

/**
* Doctrine LINESTRING type.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license https://dlambert.mit-license.org MIT
*/
class LineStringType extends GeographyType
{
Expand Down
3 changes: 0 additions & 3 deletions lib/LongitudeOne/Spatial/DBAL/Types/Geography/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

/**
* Doctrine POINT type.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license https://dlambert.mit-license.org MIT
*/
class PointType extends GeographyType
{
Expand Down
3 changes: 0 additions & 3 deletions lib/LongitudeOne/Spatial/DBAL/Types/Geography/PolygonType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

/**
* Doctrine POLYGON type.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license https://dlambert.mit-license.org MIT
*/
class PolygonType extends GeographyType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

/**
* Doctrine LINESTRING type.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license https://dlambert.mit-license.org MIT
*/
class LineStringType extends GeometryType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

/**
* Doctrine MULTILineString type.
*
* @author Alexandre Tranchant <alexandre.tranchant@gmail.com>
* @license https://alexandre-tranchant.mit-license.org MIT
*
* TODO create a MultiLineStringTypeTest as MultiPolygonTypeTest
*/
class MultiLineStringType extends GeometryType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,6 @@

/**
* Doctrine MULTIPOINT type.
*
* @author Alexandre Tranchant <alexandre.tranchant@gmail.com>
* @license https://alexandre-tranchant.mit-license.org MIT
*
* TODO create a MultiPointTypeTest as MultiPolygonTypeTest
*/
class MultiPointType extends GeometryType
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

/**
* Doctrine MULTIPOLYGON type.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license https://dlambert.mit-license.org MIT
*/
class MultiPolygonType extends GeometryType
{
Expand Down
3 changes: 0 additions & 3 deletions lib/LongitudeOne/Spatial/DBAL/Types/Geometry/PointType.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@

/**
* Doctrine POINT type.
*
* @author Derek J. Lambert <dlambert@dereklambert.com>
* @license https://dlambert.mit-license.org MIT
*/
class PointType extends GeometryType
{
Expand Down
Loading

0 comments on commit 4c9ac94

Please sign in to comment.