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

brick / geo / 13592026859

28 Feb 2025 04:11PM UTC coverage: 47.753% (+0.2%) from 47.546%
13592026859

Pull #55

github

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

17 of 23 new or added lines in 3 files covered. (73.91%)

6 existing lines in 1 file now uncovered.

1626 of 3405 relevant lines covered (47.75%)

691.32 hits per line

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

77.14
/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\Point;
12
use SQLite3;
13
use SQLite3Stmt;
14

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

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

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

38
        $this->sqlite3 = $sqlite3;
×
39
    }
40

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

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

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

58
            $statement = $this->sqlite3->prepare($query);
34✔
59

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

64
            $errorCode = $this->sqlite3->lastErrorCode();
34✔
65

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

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

81
        $index = 1;
205✔
82

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

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

100
        $result = $statement->execute();
205✔
101

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

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

113
        return $result;
4✔
114
    }
115
}
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