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

brick / geo / 13730800263

07 Mar 2025 10:56PM UTC coverage: 49.73% (-0.03%) from 49.758%
13730800263

push

github

BenMorel
Use array_reduce() in getBoundingBox()

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

49 existing lines in 3 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

93.33
/src/Engine/PDOEngine.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Engine;
6

7
use Brick\Geo\Exception\GeometryEngineException;
8
use Brick\Geo\Geometry;
9
use Override;
10
use PDO;
11
use PDOException;
12
use PDOStatement;
13

14
/**
15
 * Database engine based on a PDO driver.
16
 */
17
final class PDOEngine extends DatabaseEngine
18
{
19
    /**
20
     * The database connection.
21
     */
22
    private readonly PDO $pdo;
23

24
    /**
25
     * A cache of the prepared statements, indexed by query.
26
     *
27
     * @var array<string, PDOStatement>
28
     */
29
    private array $statements = [];
30

31
    public function __construct(PDO $pdo, bool $useProxy = true)
32
    {
33
        parent::__construct($useProxy);
×
34

35
        $this->pdo = $pdo;
×
36
    }
37

38
    public function getPDO() : PDO
39
    {
UNCOV
40
        return $this->pdo;
1,032✔
41
    }
42

43
    #[Override]
44
    protected function executeQuery(string $query, array $parameters) : array
45
    {
46
        /** @var int $errMode */
UNCOV
47
        $errMode = $this->pdo->getAttribute(PDO::ATTR_ERRMODE);
1,412✔
UNCOV
48
        $this->pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
1,412✔
49

50
        try {
UNCOV
51
            if (! isset($this->statements[$query])) {
1,412✔
UNCOV
52
                $this->statements[$query] = $this->pdo->prepare($query);
333✔
53
            }
54

UNCOV
55
            $statement = $this->statements[$query];
1,275✔
56

UNCOV
57
            $index = 1;
1,275✔
58

UNCOV
59
            foreach ($parameters as $parameter) {
1,275✔
UNCOV
60
                if ($parameter instanceof GeometryParameter) {
1,275✔
UNCOV
61
                    $statement->bindValue($index++, $parameter->data, $parameter->isBinary ? PDO::PARAM_LOB : PDO::PARAM_STR);
1,275✔
UNCOV
62
                    $statement->bindValue($index++, $parameter->srid, PDO::PARAM_INT);
1,275✔
63
                } else {
UNCOV
64
                    if (is_int($parameter)) {
295✔
UNCOV
65
                        $type = PDO::PARAM_INT;
28✔
66
                    } else {
UNCOV
67
                        $type = PDO::PARAM_STR;
267✔
68
                    }
69

UNCOV
70
                    $statement->bindValue($index++, $parameter, $type);
295✔
71
                }
72
            }
73

UNCOV
74
            $statement->execute();
1,275✔
75

76
            /** @var list<mixed>|false $result */
UNCOV
77
            $result = $statement->fetch(PDO::FETCH_NUM);
1,018✔
78
        } catch (PDOException $e) {
404✔
79
            throw GeometryEngineException::wrap($e);
404✔
80
        } finally {
UNCOV
81
            $this->pdo->setAttribute(PDO::ATTR_ERRMODE, $errMode);
1,412✔
82
        }
83

UNCOV
84
        assert($result !== false);
85

UNCOV
86
        return $result;
1,018✔
87
    }
88

89
    #[Override]
90
    protected function getGeomFromWKBSyntax(): string
91
    {
UNCOV
92
        if ($this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME) === 'mysql') {
1,297✔
93
            return 'ST_GeomFromWKB(BINARY ?, ?)';
1,036✔
94
        }
95

UNCOV
96
        return parent::getGeomFromWKBSyntax();
261✔
97
    }
98

99
    #[Override]
100
    protected function getParameterPlaceholder(string|float|int $parameter): string
101
    {
UNCOV
102
        if ($this->pdo->getAttribute(PDO::ATTR_DRIVER_NAME) === 'pgsql') {
375✔
UNCOV
103
            if (is_int($parameter)) {
75✔
104
                // https://stackoverflow.com/q/66625661/759866
105
                // https://externals.io/message/113521
UNCOV
106
                return 'CAST (? AS INTEGER)';
7✔
107
            }
108
        }
109

UNCOV
110
        return parent::getParameterPlaceholder($parameter);
368✔
111
    }
112
}
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