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

brick / geo / 13970069988

20 Mar 2025 01:07PM UTC coverage: 65.472%. First build
13970069988

push

github

BenMorel
Introduce ProxyRegistry

71 of 595 new or added lines in 19 files covered. (11.93%)

1881 of 2873 relevant lines covered (65.47%)

1472.18 hits per line

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

0.0
/src/Proxy/GeometryProxy.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Proxy;
6

7
use Brick\Geo\Exception\GeometryIoException;
8
use Brick\Geo\Exception\CoordinateSystemException;
9
use Brick\Geo\Exception\InvalidGeometryException;
10
use Brick\Geo\Exception\UnexpectedGeometryException;
11
use Brick\Geo\Geometry;
12
use Brick\Geo\Internal\ProxyRegistry;
13
use Override;
14

15
/**
16
 * Proxy class for Geometry.
17
 *
18
 * @internal This class is not part of the public API and can change at any time.
19
 *           Please type-hint against Brick\Geo\Geometry in your projects.
20
 */
21
class GeometryProxy extends Geometry implements ProxyInterface
22
{
23
    /**
24
     * The WKT or WKB data.
25
     */
26
    private readonly string $proxyData;
27

28
    /**
29
     * `true` if WKB, `false` if WKT.
30
     */
31
    private readonly bool $isProxyBinary;
32

33
    /**
34
     * The SRID of the underlying geometry.
35
     */
36
    private readonly int $proxySrid;
37

38
    /**
39
     * @param string $data     The WKT or WKB data.
40
     * @param bool   $isBinary Whether the data is binary (true) or text (false).
41
     * @param int    $srid     The SRID of the geometry.
42
     */
43
    public function __construct(string $data, bool $isBinary, int $srid = 0)
44
    {
45
        $this->proxyData     = $data;
×
46
        $this->isProxyBinary = $isBinary;
×
47
        $this->proxySrid     = $srid;
×
48
    }
49

50
    /**
51
     * Loads the underlying geometry.
52
     *
53
     * @throws GeometryIoException         If the proxy data is not valid.
54
     * @throws CoordinateSystemException   If the resulting geometry contains mixed coordinate systems.
55
     * @throws InvalidGeometryException    If the resulting geometry is not valid.
56
     * @throws UnexpectedGeometryException If the resulting geometry is not an instance of the proxied class.
57
     */
58
    private function load() : Geometry
59
    {
NEW
60
        return $this->isProxyBinary
×
61
            ? Geometry::fromBinary($this->proxyData, $this->proxySrid)
×
62
            : Geometry::fromText($this->proxyData, $this->proxySrid);
×
63
    }
64

65
    #[Override]
66
    public function isLoaded() : bool
67
    {
NEW
68
        return ProxyRegistry::hasProxiedGeometry($this);
×
69
    }
70

71
    #[Override]
72
    public function getGeometry() : Geometry
73
    {
NEW
74
        $geometry = ProxyRegistry::getProxiedGeometry($this);
×
75

NEW
76
        if ($geometry !== null) {
×
NEW
77
            return $geometry;
×
78
        }
79

NEW
80
        $geometry = $this->load();
×
NEW
81
        ProxyRegistry::setProxiedGeometry($this, $geometry);
×
82

NEW
83
        return $geometry;
×
84
    }
85

86
    #[Override]
87
    public function isProxyBinary() : bool
88
    {
89
        return $this->isProxyBinary;
×
90
    }
91

92
    #[Override]
93
    public static function fromText(string $wkt, int $srid = 0) : Geometry
94
    {
95
        return new self($wkt, false, $srid);
×
96
    }
97

98
    #[Override]
99
    public static function fromBinary(string $wkb, int $srid = 0) : Geometry
100
    {
101
        return new self($wkb, true, $srid);
×
102
    }
103

104
    #[Override]
105
    public function srid() : int
106
    {
107
        return $this->proxySrid;
×
108
    }
109

110
    #[Override]
111
    public function asText() : string
112
    {
113
        if (! $this->isProxyBinary) {
×
114
            return $this->proxyData;
×
115
        }
116

NEW
117
        return $this->getGeometry()->asText();
×
118
    }
119

120
    #[Override]
121
    public function asBinary() : string
122
    {
123
        if ($this->isProxyBinary) {
×
124
            return $this->proxyData;
×
125
        }
126

NEW
127
        return $this->getGeometry()->asBinary();
×
128
    }
129

130

131
    #[Override]
132
    public function dimension(): int
133
    {
NEW
134
        return $this->getGeometry()->dimension();
×
135
    }
136

137
    #[Override]
138
    public function coordinateDimension(): int
139
    {
NEW
140
        return $this->getGeometry()->coordinateDimension();
×
141
    }
142

143
    #[Override]
144
    public function spatialDimension(): int
145
    {
NEW
146
        return $this->getGeometry()->spatialDimension();
×
147
    }
148

149
    #[Override]
150
    public function geometryType(): string
151
    {
NEW
152
        return $this->getGeometry()->geometryType();
×
153
    }
154

155
    #[Override]
156
    public function geometryTypeBinary(): int
157
    {
NEW
158
        return $this->getGeometry()->geometryTypeBinary();
×
159
    }
160

161
    #[Override]
162
    public function isEmpty(): bool
163
    {
NEW
164
        return $this->getGeometry()->isEmpty();
×
165
    }
166

167
    #[Override]
168
    public function is3D(): bool
169
    {
NEW
170
        return $this->getGeometry()->is3D();
×
171
    }
172

173
    #[Override]
174
    public function isMeasured(): bool
175
    {
NEW
176
        return $this->getGeometry()->isMeasured();
×
177
    }
178

179
    #[Override]
180
    public function coordinateSystem(): \Brick\Geo\CoordinateSystem
181
    {
NEW
182
        return $this->getGeometry()->coordinateSystem();
×
183
    }
184

185
    #[Override]
186
    public function withSrid(int $srid): \Brick\Geo\Geometry
187
    {
NEW
188
        return $this->getGeometry()->withSrid($srid);
×
189
    }
190

191
    #[Override]
192
    public function toXy(): \Brick\Geo\Geometry
193
    {
NEW
194
        return $this->getGeometry()->toXy();
×
195
    }
196

197
    #[Override]
198
    public function withoutZ(): \Brick\Geo\Geometry
199
    {
NEW
200
        return $this->getGeometry()->withoutZ();
×
201
    }
202

203
    #[Override]
204
    public function withoutM(): \Brick\Geo\Geometry
205
    {
NEW
206
        return $this->getGeometry()->withoutM();
×
207
    }
208

209
    #[Override]
210
    public function withRoundedCoordinates(int $precision): \Brick\Geo\Geometry
211
    {
NEW
212
        return $this->getGeometry()->withRoundedCoordinates($precision);
×
213
    }
214

215
    #[Override]
216
    public function getBoundingBox(): \Brick\Geo\BoundingBox
217
    {
NEW
218
        return $this->getGeometry()->getBoundingBox();
×
219
    }
220

221
    #[Override]
222
    public function toArray(): array
223
    {
NEW
224
        return $this->getGeometry()->toArray();
×
225
    }
226

227
    #[Override]
228
    public function swapXy(): \Brick\Geo\Geometry
229
    {
NEW
230
        return $this->getGeometry()->swapXy();
×
231
    }
232

233
    #[Override]
234
    public function project(\Brick\Geo\Projector\Projector $projector): \Brick\Geo\Geometry
235
    {
NEW
236
        return $this->getGeometry()->project($projector);
×
237
    }
238

239
    #[Override]
240
    public function isIdenticalTo(\Brick\Geo\Geometry $that): bool
241
    {
NEW
242
        return $this->getGeometry()->isIdenticalTo($that);
×
243
    }
244

245
}
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