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

brick / geo / 13731438031

07 Mar 2025 11:54PM UTC coverage: 49.73%. Remained the same
13731438031

push

github

BenMorel
Use array_reduce() in getBoundingBox()

10 of 30 new or added lines in 6 files covered. (33.33%)

48 existing lines in 8 files now uncovered.

1748 of 3515 relevant lines covered (49.73%)

974.97 hits per line

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

84.38
/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\LineString;
10
use Brick\Geo\Point;
11
use Override;
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
final 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
    {
UNCOV
43
        return $this->sqlite3;
2✔
44
    }
45

46
    #[Override]
47
    protected function executeQuery(string $query, array $parameters) : array
48
    {
UNCOV
49
        $enableExceptions = $this->sqlite3->enableExceptions(true);
258✔
50

51
        try {
UNCOV
52
            if (isset($this->statements[$query])) {
258✔
UNCOV
53
                $statement = $this->statements[$query];
200✔
UNCOV
54
                $statement->reset();
200✔
55
            } else {
UNCOV
56
                $statement = $this->sqlite3->prepare($query);
64✔
UNCOV
57
                $this->statements[$query] = $statement;
35✔
58
            }
59

UNCOV
60
            $index = 1;
229✔
61

UNCOV
62
            foreach ($parameters as $parameter) {
229✔
UNCOV
63
                if ($parameter instanceof GeometryParameter) {
229✔
UNCOV
64
                    $statement->bindValue($index++, $parameter->data, $parameter->isBinary ? SQLITE3_BLOB : SQLITE3_TEXT);
229✔
UNCOV
65
                    $statement->bindValue($index++, $parameter->srid, SQLITE3_INTEGER);
229✔
66
                } else {
UNCOV
67
                    if (is_int($parameter)) {
45✔
UNCOV
68
                        $type = SQLITE3_INTEGER;
7✔
UNCOV
69
                    } elseif (is_float($parameter)) {
38✔
UNCOV
70
                        $type = SQLITE3_FLOAT;
34✔
71
                    } else {
UNCOV
72
                        $type = SQLITE3_TEXT;
4✔
73
                    }
74

UNCOV
75
                    $statement->bindValue($index++, $parameter, $type);
45✔
76
                }
77
            }
78

UNCOV
79
            $sqlite3Result = $statement->execute();
229✔
80

81
            /** @var list<mixed>|false $result */
UNCOV
82
            $result = $sqlite3Result->fetchArray(SQLITE3_NUM);
222✔
UNCOV
83
        } catch (\Exception $e) {
36✔
UNCOV
84
            throw GeometryEngineException::wrap($e);
36✔
85
        } finally {
UNCOV
86
            $this->sqlite3->enableExceptions($enableExceptions);
258✔
87
        }
88

UNCOV
89
        assert($result !== false);
90

UNCOV
91
        return $result;
222✔
92
    }
93

94
    #[Override]
95
    public function lineInterpolatePoint(LineString $lineString, float $fraction) : Point
96
    {
UNCOV
97
        $result = $this->queryGeometry('ST_Line_Interpolate_Point', $lineString, $fraction);
21✔
UNCOV
98
        TypeChecker::check($result, Point::class);
21✔
99

UNCOV
100
        return $result;
21✔
101
    }
102

103
    /**
104
     * @template T
105
     *
106
     * @param \Closure(): T $action
107
     *
108
     * @return T
109
     *
110
     * @throws GeometryEngineException
111
     */
112
    private function execute(\Closure $action) : mixed
113
    {
114
        try {
115
            return $action();
×
116
        } catch (\Exception $e) {
×
117
            throw GeometryEngineException::wrap($e);
×
118
        }
119
    }
120
}
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