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

brick / geo / 13717260378

07 Mar 2025 09:01AM UTC coverage: 49.431% (+1.5%) from 47.964%
13717260378

push

github

BenMorel
GEOSEngine: rename props + readonly

4 of 12 new or added lines in 1 file covered. (33.33%)

34 existing lines in 3 files now uncovered.

1737 of 3514 relevant lines covered (49.43%)

943.69 hits per line

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

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

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine;
6

7
use Brick\Geo\Engine\Internal\TypeChecker;
8
use Brick\Geo\Exception\GeometryEngineException;
9
use Brick\Geo\Exception\SQLite3Exception;
10
use Brick\Geo\Geometry;
11
use Brick\Geo\LineString;
12
use Brick\Geo\Point;
13
use Override;
14
use SQLite3;
15
use SQLite3Stmt;
16

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

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

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

40
        $this->sqlite3 = $sqlite3;
×
41
    }
42

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

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

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

UNCOV
61
            $statement = $this->sqlite3->prepare($query);
34✔
62

63
            // Restore the original settings.
UNCOV
64
            $this->sqlite3->enableExceptions($enableExceptions);
34✔
UNCOV
65
            error_reporting($errorReportingLevel);
34✔
66

UNCOV
67
            $errorCode = $this->sqlite3->lastErrorCode();
34✔
68

UNCOV
69
            if ($errorCode !== 0) {
34✔
70
                $exception = new SQLite3Exception($this->sqlite3->lastErrorMsg(), $errorCode);
×
71

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

UNCOV
84
        $index = 1;
205✔
85

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

UNCOV
99
                $statement->bindValue($index++, $parameter, $type);
21✔
100
            }
101
        }
102

UNCOV
103
        $result = $statement->execute();
205✔
104

105
        /** @var list<mixed> */
UNCOV
106
        return $result->fetchArray(SQLITE3_NUM);
205✔
107
    }
108

109
    #[Override]
110
    public function lineInterpolatePoint(LineString $lineString, float $fraction) : Point
111
    {
UNCOV
112
        $result = $this->queryGeometry('ST_Line_Interpolate_Point', $lineString, $fraction);
4✔
UNCOV
113
        TypeChecker::check($result, Point::class);
4✔
114

UNCOV
115
        return $result;
4✔
116
    }
117
}
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