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

brick / geo / 13589819199

28 Feb 2025 02:08PM UTC coverage: 47.681% (+0.1%) from 47.546%
13589819199

Pull #55

github

web-flow
Merge 10b505eb4 into 5c954d80e
Pull Request #55: Add LineInterpolatePoint for Postgis

16 of 24 new or added lines in 3 files covered. (66.67%)

12 existing lines in 2 files now uncovered.

1624 of 3406 relevant lines covered (47.68%)

967.35 hits per line

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

77.5
/src/Engine/SQLite3Engine.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine;
6

7
use Brick\Geo\Exception\GeometryEngineException;
8
use Brick\Geo\Exception\SQLite3Exception;
9
use Brick\Geo\Geometry;
10
use Brick\Geo\LineString;
11
use Brick\Geo\MultiPoint;
12
use Brick\Geo\Point;
13
use SQLite3;
14
use SQLite3Stmt;
15

16
/**
17
 * Database engine based on a SQLite3 driver.
18
 *
19
 * The spatialite extension must be loaded in this driver.
20
 */
21
class SQLite3Engine extends DatabaseEngine
22
{
23
    /**
24
     * The database connection.
25
     */
26
    private readonly SQLite3 $sqlite3;
27

28
    /**
29
     * A cache of the prepared statements, indexed by query.
30
     *
31
     * @var array<string, SQLite3Stmt>
32
     */
33
    private array $statements = [];
34

35
    public function __construct(SQLite3 $sqlite3, bool $useProxy = true)
36
    {
UNCOV
37
        parent::__construct($useProxy);
×
38

UNCOV
39
        $this->sqlite3 = $sqlite3;
×
40
    }
41

42
    public function getSQLite3() : SQLite3
43
    {
44
        return $this->sqlite3;
2✔
45
    }
46

47
    protected function executeQuery(string $query, array $parameters) : array
48
    {
49
        if (isset($this->statements[$query])) {
207✔
50
            $statement = $this->statements[$query];
179✔
51
            $statement->reset();
179✔
52
        } else {
53
            // Temporary set the error reporting level to 0 to avoid any warning.
54
            $errorReportingLevel = error_reporting(0);
35✔
55

56
            // Don't use exceptions, they're just \Exception instances that don't even contain the SQLite error code!
57
            $enableExceptions = $this->sqlite3->enableExceptions(false);
35✔
58

59
            $statement = $this->sqlite3->prepare($query);
35✔
60

61
            // Restore the original settings.
62
            $this->sqlite3->enableExceptions($enableExceptions);
35✔
63
            error_reporting($errorReportingLevel);
35✔
64

65
            $errorCode = $this->sqlite3->lastErrorCode();
35✔
66

67
            if ($errorCode !== 0) {
35✔
UNCOV
68
                $exception = new SQLite3Exception($this->sqlite3->lastErrorMsg(), $errorCode);
×
69

UNCOV
70
                if ($errorCode === 1) {
×
71
                    // SQL error cause by a missing function, this must be reported with a GeometryEngineException.
UNCOV
72
                    throw GeometryEngineException::operationNotSupportedByEngine($exception);
×
73
                } else {
74
                    // Other SQLite3 error; we cannot trigger the original E_WARNING, so we throw this exception instead.
UNCOV
75
                    throw $exception;
×
76
                }
77
            } else {
78
                $this->statements[$query] = $statement;
35✔
79
            }
80
        }
81

82
        $index = 1;
207✔
83

84
        foreach ($parameters as $parameter) {
207✔
85
            if ($parameter instanceof GeometryParameter) {
207✔
86
                $statement->bindValue($index++, $parameter->data, $parameter->isBinary ? SQLITE3_BLOB : SQLITE3_TEXT);
207✔
87
                $statement->bindValue($index++, $parameter->srid, SQLITE3_INTEGER);
207✔
88
            } else {
89
                if (is_int($parameter)) {
23✔
UNCOV
90
                    $type = SQLITE3_INTEGER;
×
91
                } elseif (is_float($parameter)) {
23✔
92
                    $type = SQLITE3_FLOAT;
19✔
93
                } else {
94
                    $type = SQLITE3_TEXT;
4✔
95
                }
96

97
                $statement->bindValue($index++, $parameter, $type);
23✔
98
            }
99
        }
100

101
        $result = $statement->execute();
207✔
102

103
        /** @psalm-var list<mixed> */
104
        return $result->fetchArray(SQLITE3_NUM);
207✔
105
    }
106

107
    public function lineInterpolatePoint(LineString $linestring, float $fraction) : Point
108
    {
109
        $result = $this->queryGeometry('ST_Line_Interpolate_Point', $linestring, $fraction);
4✔
110
        if (! $result instanceof Point) {
4✔
NEW
111
            throw new GeometryEngineException('This operation yielded the wrong geometry type: ' . $result::class);
×
112
        }
113

114
        return $result;
4✔
115
    }
116

117
    public function lineInterpolateEquidistantPoints(LineString $linestring, float $fraction) : MultiPoint
118
    {
119
        $fraction = $this->length($linestring) * $fraction;
2✔
120

121
        $result = $this->queryGeometry('ST_Line_Interpolate_Equidistant_Points', $linestring, $fraction);
2✔
122
        if (! $result instanceof MultiPoint) {
2✔
NEW
UNCOV
123
            throw new GeometryEngineException('This operation yielded the wrong geometry type: ' . $result::class);
×
124
        }
125

126
        return $result;
2✔
127
    }
128
}
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