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

brick / geo / 14072842519

26 Mar 2025 12:34AM UTC coverage: 62.112% (-0.02%) from 62.13%
14072842519

push

github

BenMorel
Implement PgsqlDriver (pgsql extension)

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

36 existing lines in 4 files now uncovered.

1882 of 3030 relevant lines covered (62.11%)

1695.42 hits per line

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

75.68
/src/Engine/Database/Driver/PdoPgsqlDriver.php
1
<?php
2

3
declare(strict_types=1);
4

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

7
use Brick\Geo\Engine\Database\Driver\Internal\AbstractPdoDriver;
8
use Brick\Geo\Engine\Database\Query\BinaryValue;
9
use Brick\Geo\Engine\Database\Query\ScalarValue;
10
use Brick\Geo\Exception\GeometryEngineException;
11
use Override;
12
use PDO;
13

14
/**
15
 * Database driver using a pdo_pgsql connection.
16
 */
17
final class PdoPgsqlDriver extends AbstractPdoDriver
18
{
19
    #[Override]
20
    public function convertQuery(string|BinaryValue|ScalarValue ...$query) : array
21
    {
22
        $queryString = '';
300✔
23
        $queryParams = [];
300✔
24

25
        foreach ($query as $queryPart) {
300✔
26
            if ($queryPart instanceof BinaryValue) {
300✔
27
                $queryString .= '?';
300✔
28
                $queryParams[] = [$queryPart->value, PDO::PARAM_LOB];
300✔
29
            } elseif ($queryPart instanceof ScalarValue) {
300✔
30
                $queryString .= '?';
80✔
31

32
                if (is_int($queryPart->value)) {
80✔
33
                    $queryString .= '::int'; // PARAM_INT seems to have no effect on pdo_pgsql
7✔
34
                    $queryParams[] = [$queryPart->value, PDO::PARAM_INT];
7✔
35
                } elseif (is_float($queryPart->value)) {
73✔
36
                    $queryString .= '::float';
69✔
37
                    $queryParams[] = [$queryPart->value, PDO::PARAM_STR];
69✔
38
                } elseif (is_bool($queryPart->value)) {
9✔
39
                    $queryParams[] = [$queryPart->value, PDO::PARAM_BOOL];
5✔
40
                } else {
41
                    $queryParams[] = [$queryPart->value, PDO::PARAM_STR];
4✔
42
                }
43
            } else {
44
                $queryString .= $queryPart;
300✔
45
            }
46
        }
47

48
        return [$queryString, $queryParams];
300✔
49
    }
50

51
    #[Override]
52
    public function convertBinaryResult(mixed $value) : string
53
    {
54
        if (is_resource($value)) {
123✔
55
            $value = stream_get_contents($value);
123✔
56

57
            if ($value === false) {
123✔
UNCOV
58
                throw new GeometryEngineException('Failed to read stream contents.');
×
59
            }
60

61
            return $value;
123✔
62
        }
63

64
        throw GeometryEngineException::unexpectedDatabaseReturnType('resource', $value);
×
65
    }
66

67
    #[Override]
68
    public function convertStringResult(mixed $value) : string
69
    {
70
        if (is_string($value)) {
×
71
            return $value;
×
72
        }
73

74
        throw GeometryEngineException::unexpectedDatabaseReturnType('string', $value);
×
75
    }
76

77
    #[Override]
78
    public function convertIntResult(mixed $value) : int
79
    {
80
        // TODO check that actually returned as int;
81
        //      maybe checks for all types sent & received for each driver?
82

UNCOV
83
        if (is_int($value)) {
×
UNCOV
84
            return $value;
×
85
        }
86

87
        throw GeometryEngineException::unexpectedDatabaseReturnType('int', $value);
×
88
    }
89

90
    #[Override]
91
    public function convertFloatResult(mixed $value) : float
92
    {
93
        if (is_numeric($value)) {
41✔
94
            return (float) $value;
40✔
95
        }
96

97
        throw GeometryEngineException::unexpectedDatabaseReturnType('number or numeric string', $value);
1✔
98
    }
99

100
    #[Override]
101
    public function convertBoolResult(mixed $value) : bool
102
    {
103
        if (is_bool($value)) {
161✔
104
            return $value;
161✔
105
        }
106

107
        throw GeometryEngineException::unexpectedDatabaseReturnType('bool', $value);
×
108
    }
109
}
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