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

brick / geo / 14062212560

25 Mar 2025 02:26PM UTC coverage: 53.902% (+1.7%) from 52.154%
14062212560

push

github

BenMorel
Implement PgsqlDriver (pgsql extension)

0 of 52 new or added lines in 1 file covered. (0.0%)

110 existing lines in 8 files now uncovered.

1637 of 3037 relevant lines covered (53.9%)

409.17 hits per line

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

0.0
/src/Engine/Database/Driver/PdoMysqlDriver.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine\Database\Driver;
6

7
use Brick\Geo\Engine\Database\Query\BinaryValue;
8
use Brick\Geo\Engine\Database\Query\ScalarValue;
9
use Brick\Geo\Engine\Database\Result\Row;
10
use Brick\Geo\Exception\GeometryEngineException;
11
use Override;
12
use PDO;
13
use PDOException;
14

15
/**
16
 * Database driver using a pdo_mysql connection.
17
 */
18
final class PdoMysqlDriver implements DatabaseDriver
19
{
20
    public function __construct(
21
        private readonly PDO $pdo,
22
    ) {
UNCOV
23
    }
×
24

25
    #[Override]
26
    public function executeQuery(string|BinaryValue|ScalarValue ...$query) : Row
27
    {
UNCOV
28
        $queryString = '';
×
UNCOV
29
        $queryParams = [];
×
30

31
        foreach ($query as $queryPart) {
×
UNCOV
32
            if ($queryPart instanceof BinaryValue) {
×
33
                $queryString .= 'BINARY ?';
×
34
                $queryParams[] = [$queryPart->value, PDO::PARAM_LOB];
×
35
            } elseif ($queryPart instanceof ScalarValue) {
×
36
                $queryString .= '?';
×
37

38
                if (is_int($queryPart->value)) {
×
UNCOV
39
                    $queryParams[] = [$queryPart->value, PDO::PARAM_INT];
×
40
                } elseif (is_bool($queryPart->value)) {
×
41
                    $queryParams[] = [$queryPart->value, PDO::PARAM_BOOL];
×
42
                } else {
43
                    $queryParams[] = [$queryPart->value, PDO::PARAM_STR];
×
44
                }
45
            } else {
UNCOV
46
                $queryString .= $queryPart;
×
47
            }
48
        }
49

50
        /** @var int $errMode */
UNCOV
51
        $errMode = $this->pdo->getAttribute(PDO::ATTR_ERRMODE);
×
UNCOV
52
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
×
53

54
        try {
UNCOV
55
            $statement = $this->pdo->prepare($queryString);
×
56

57
            $position = 1;
×
58

59
            foreach ($queryParams as [$value, $type]) {
×
UNCOV
60
                $statement->bindValue($position++, $value, $type);
×
61
            }
62

UNCOV
63
            $statement->execute();
×
64

65
            /** @var list<list<mixed>> $result */
UNCOV
66
            $result = $statement->fetchAll(PDO::FETCH_NUM);
×
UNCOV
67
        } catch (PDOException $e) {
×
68
            throw GeometryEngineException::wrap($e);
×
69
        } finally {
70
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, $errMode);
×
71
        }
72

UNCOV
73
        if (count($result) !== 1) {
×
UNCOV
74
            throw new GeometryEngineException(sprintf('Expected exactly one row, got %d.', count($result)));
×
75
        }
76

UNCOV
77
        return new Row($this, $result[0]);
×
78
    }
79

80
    public function convertBinaryResult(mixed $value) : string
81
    {
UNCOV
82
        if (is_string($value)) {
×
UNCOV
83
            return $value;
×
84
        }
85

UNCOV
86
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
×
87
    }
88

89
    public function convertStringResult(mixed $value) : string
90
    {
UNCOV
91
        if (is_string($value)) {
×
UNCOV
92
            return $value;
×
93
        }
94

UNCOV
95
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
×
96
    }
97

98
    public function convertIntResult(mixed $value) : int
99
    {
100
        // TODO check that actually returned as int;
101
        //      maybe checks for all types sent & received for each driver?
102

UNCOV
103
        if (is_int($value)) {
×
UNCOV
104
            return $value;
×
105
        }
106

UNCOV
107
        throw GeometryEngineException::unexpectedDatabaseReturnType('int', $value);
×
108
    }
109

110
    public function convertFloatResult(mixed $value) : float
111
    {
UNCOV
112
        if (is_numeric($value)) {
×
UNCOV
113
            return (float) $value;
×
114
        }
115

UNCOV
116
        throw GeometryEngineException::unexpectedDatabaseReturnType('number or numeric string', $value);
×
117
    }
118

119
    public function convertBoolResult(mixed $value) : bool
120
    {
UNCOV
121
        return match ($value) {
×
UNCOV
122
            0 => false,
×
123
            1 => true,
×
124
            default => throw GeometryEngineException::unexpectedDatabaseReturnType('0 or 1', $value),
×
125
        };
×
126
    }
127
}
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