Skip to content

Add TypedExpression support for better DQL type safety #80

@maxhelias

Description

@maxhelias

Since Doctrine ORM 2.13+, the TypedExpression interface allows DQL functions to explicitly declare their return types. This enables better type inference in queries and improves the overall developer experience.

Currently, PostGIS functions in this library don't implement TypedExpression, which means:

  • No explicit type information in DQL queries
  • Potential type mismatches in complex queries
  • Missing IDE autocomplete hints for return types

Proposed Changes

Implement TypedExpression on appropriate PostGIS functions to declare their return types explicitly.

Functions returning numeric types (float/integer)

  • ST_DistanceTypes::FLOAT
  • ST_LengthTypes::FLOAT
  • ST_AreaTypes::FLOAT
  • ST_PerimeterTypes::FLOAT
  • ST_XTypes::FLOAT
  • ST_YTypes::FLOAT
  • ST_ZTypes::FLOAT
  • ST_NumGeometriesTypes::INTEGER
  • ST_NPointsTypes::INTEGER
  • ST_SRIDTypes::INTEGER

Functions returning boolean types

  • ST_ContainsTypes::BOOLEAN
  • ST_WithinTypes::BOOLEAN
  • ST_IntersectsTypes::BOOLEAN
  • ST_CrossesTypes::BOOLEAN
  • ST_OverlapsTypes::BOOLEAN
  • ST_TouchesTypes::BOOLEAN
  • ST_DisjointTypes::BOOLEAN
  • ST_EqualsTypes::BOOLEAN
  • ST_DWithinTypes::BOOLEAN
  • ST_IsEmptyTypes::BOOLEAN
  • ST_IsValidTypes::BOOLEAN

Functions returning string types

  • ST_AsTextTypes::STRING
  • ST_AsEWKTTypes::STRING
  • ST_AsGeoJSONTypes::STRING
  • ST_AsGMLTypes::STRING
  • ST_AsKMLTypes::STRING
  • ST_AsSVGTypes::STRING
  • ST_GeometryTypeTypes::STRING

Functions returning geometry types

Functions like ST_Buffer, ST_Intersection, ST_Union, etc. could potentially return custom geometry types, but this might require more discussion on the implementation approach.

Implementation Example

final class ST_Distance extends FunctionNode implement TypedExpression
{
    // ... existing implementation

    public function getReturnType(): Type
    {
        return Type::getType(Types::FLOAT);
    }
}

Doctrine documentation : https://www.doctrine-project.org/projects/doctrine-orm/en/3.5/reference/dql-doctrine-query-language.html

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions