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

brick / geo / 13721917585

07 Mar 2025 01:37PM UTC coverage: 49.758%. Remained the same
13721917585

push

github

BenMorel
Unconditionally catch exceptions in PDOEngine & SQLite3Engine

+ include underlying engine message in exception message.

23 of 28 new or added lines in 4 files covered. (82.14%)

4 existing lines in 3 files now uncovered.

1746 of 3509 relevant lines covered (49.76%)

974.92 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

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

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

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

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

60
            $index = 1;
229✔
61

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

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

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

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

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

91
        return $result;
222✔
92
    }
93

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

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 {
NEW
115
            return $action();
×
NEW
116
        } catch (\Exception $e) {
×
NEW
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