• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

brick / geo / 14062212560

25 Mar 2025 02:26PM UTC coverage: 53.902% (+1.7%) from 52.154%
14062212560

push

github

BenMorel
Implement PgsqlDriver (pgsql extension)

0 of 52 new or added lines in 1 file covered. (0.0%)

110 existing lines in 8 files now uncovered.

1637 of 3037 relevant lines covered (53.9%)

409.17 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/Engine/PostgisEngine.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine;
6

7
use Brick\Geo\Engine\Database\Driver\DatabaseDriver;
8
use Brick\Geo\Engine\Database\Internal\AbstractDatabaseEngine;
9
use Brick\Geo\Engine\Database\Query\BinaryValue;
10
use Brick\Geo\Engine\Database\Query\ScalarValue;
11
use Brick\Geo\Engine\Database\Result\Row;
12
use Brick\Geo\Exception\GeometryEngineException;
13
use Brick\Geo\Geometry;
14
use Brick\Geo\Io\EwkbReader;
15
use Brick\Geo\Io\EwkbWriter;
16

17
/**
18
 * Database engine based on PostgreSQL with the PostGIS extension.
19
 */
20
final readonly class PostgisEngine extends AbstractDatabaseEngine
21
{
22
    private EwkbReader $ewkbReader;
23
    private EwkbWriter $ewkbWriter;
24

25
    public function __construct(
26
        private DatabaseDriver $driver,
27
    ) {
UNCOV
28
        $this->ewkbReader = new EwkbReader();
×
UNCOV
29
        $this->ewkbWriter = new EwkbWriter();
×
30
    }
31

32
    /**
33
     * Builds and executes a SQL query for a GIS function.
34
     *
35
     * @param string                $function        The SQL GIS function to execute.
36
     * @param list<Geometry|scalar> $parameters      The Geometry objects or scalar values to pass as parameters.
37
     * @param bool                  $returnsGeometry Whether the GIS function returns a Geometry.
38
     *
39
     * @throws GeometryEngineException
40
     */
41
    private function query(string $function, array $parameters, bool $returnsGeometry) : Row
42
    {
UNCOV
43
        $query = ['SELECT '];
×
44

UNCOV
45
        if ($returnsGeometry) {
×
UNCOV
46
            $query[] = 'ST_AsEWKB(';
×
47
        }
48

UNCOV
49
        $query[] = $function . '(';
×
50

UNCOV
51
        foreach ($parameters as $key => $parameter) {
×
UNCOV
52
            if ($key !== 0) {
×
UNCOV
53
                $query[] = ',';
×
54
            }
55

56
            if ($parameter instanceof Geometry) {
×
57
                $query[] = 'ST_GeomFromEWKB(';
×
UNCOV
58
                $query[] = new BinaryValue($this->ewkbWriter->write($parameter));
×
UNCOV
59
                $query[] = ')';
×
60
            } else {
UNCOV
61
                $query[] = new ScalarValue($parameter);
×
62
            }
63
        }
64

UNCOV
65
        $query[] = ')';
×
66

67
        if ($returnsGeometry) {
×
68
            $query[] = ')';
×
69
        }
70

UNCOV
71
        return $this->driver->executeQuery(...$query);
×
72
    }
73

74
    /**
75
     * Queries a GIS function returning a boolean value.
76
     *
77
     * @param string          $function      The SQL GIS function to execute.
78
     * @param Geometry|scalar ...$parameters The Geometry objects or scalar values to pass as parameters.
79
     *
80
     * @throws GeometryEngineException
81
     */
82
    public function queryBool(string $function, Geometry|string|float|int|bool ...$parameters) : bool
83
    {
UNCOV
84
        return $this->query($function, $parameters, false)->get(0)->asBool();
×
85
    }
86

87
    /**
88
     * Queries a GIS function returning a floating point value.
89
     *
90
     * @param string          $function      The SQL GIS function to execute.
91
     * @param Geometry|scalar ...$parameters The Geometry objects or scalar values to pass as parameters.
92
     *
93
     * @throws GeometryEngineException
94
     */
95
    public function queryFloat(string $function, Geometry|string|float|int|bool ...$parameters) : float
96
    {
UNCOV
97
        return $this->query($function, $parameters, false)->get(0)->asFloat();
×
98
    }
99

100
    /**
101
     * Queries a GIS function returning a Geometry object.
102
     *
103
     * @param string             $function   The SQL GIS function to execute.
104
     * @param Geometry|scalar ...$parameters The Geometry objects or scalar values to pass as parameters.
105
     *
106
     * @throws GeometryEngineException
107
     */
108
    public function queryGeometry(string $function, Geometry|string|float|int|bool ...$parameters) : Geometry
109
    {
UNCOV
110
        $ewkb = $this->query($function, $parameters, true)->get(0)->asBinary();
×
111

UNCOV
112
        return $this->ewkbReader->read($ewkb);
×
113
    }
114
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc