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

brick / geo / 13969988840

20 Mar 2025 01:03PM UTC coverage: 50.432% (-0.7%) from 51.179%
13969988840

push

github

BenMorel
Prepare for release

1867 of 3702 relevant lines covered (50.43%)

1140.21 hits per line

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

54.76
/src/Proxy/PointProxy.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\Point;
13

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

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

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

37
    /**
38
     * The underlying geometry, or NULL if not yet loaded.
39
     */
40
    private ?Point $proxyGeometry = null;
41

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

54
    /**
55
     * Loads the underlying geometry.
56
     *
57
     * @throws GeometryIoException         If the proxy data is not valid.
58
     * @throws CoordinateSystemException   If the resulting geometry contains mixed coordinate systems.
59
     * @throws InvalidGeometryException    If the resulting geometry is not valid.
60
     * @throws UnexpectedGeometryException If the resulting geometry is not an instance of the proxied class.
61
     */
62
    private function load() : void
63
    {
64
        $this->proxyGeometry = $this->isProxyBinary
230✔
65
            ? Point::fromBinary($this->proxyData, $this->proxySrid)
205✔
66
            : Point::fromText($this->proxyData, $this->proxySrid);
25✔
67
    }
68

69
    public function isLoaded() : bool
70
    {
71
        return $this->proxyGeometry !== null;
8✔
72
    }
73

74
    public function getGeometry() : Geometry
75
    {
76
        if ($this->proxyGeometry === null) {
8✔
77
            $this->load();
×
78
        }
79

80
        return $this->proxyGeometry;
8✔
81
    }
82

83
    public function isProxyBinary() : bool
84
    {
85
        return $this->isProxyBinary;
28✔
86
    }
87

88
    public static function fromText(string $wkt, int $srid = 0) : Geometry
89
    {
90
        return new self($wkt, false, $srid);
×
91
    }
92

93
    public static function fromBinary(string $wkb, int $srid = 0) : Geometry
94
    {
95
        return new self($wkb, true, $srid);
×
96
    }
97

98
    public function srid() : int
99
    {
100
        return $this->proxySrid;
68✔
101
    }
102

103
    public function asText() : string
104
    {
105
        if (! $this->isProxyBinary) {
164✔
106
            return $this->proxyData;
21✔
107
        }
108

109
        if ($this->proxyGeometry === null) {
143✔
110
            $this->load();
127✔
111
        }
112

113
        return $this->proxyGeometry->asText();
143✔
114
    }
115

116
    public function asBinary() : string
117
    {
118
        if ($this->isProxyBinary) {
52✔
119
            return $this->proxyData;
44✔
120
        }
121

122
        if ($this->proxyGeometry === null) {
8✔
123
            $this->load();
×
124
        }
125

126
        return $this->proxyGeometry->asBinary();
8✔
127
    }
128

129

130
    public function x(): ?float
131
    {
132
        if ($this->proxyGeometry === null) {
94✔
133
            $this->load();
45✔
134
        }
135

136
        return $this->proxyGeometry->x();
94✔
137
    }
138

139
    public function y(): ?float
140
    {
141
        if ($this->proxyGeometry === null) {
94✔
142
            $this->load();
×
143
        }
144

145
        return $this->proxyGeometry->y();
94✔
146
    }
147

148
    public function z(): ?float
149
    {
150
        if ($this->proxyGeometry === null) {
49✔
151
            $this->load();
×
152
        }
153

154
        return $this->proxyGeometry->z();
49✔
155
    }
156

157
    public function m(): ?float
158
    {
159
        if ($this->proxyGeometry === null) {
49✔
160
            $this->load();
×
161
        }
162

163
        return $this->proxyGeometry->m();
49✔
164
    }
165

166
    public function getBoundingBox(): \Brick\Geo\BoundingBox
167
    {
168
        if ($this->proxyGeometry === null) {
×
169
            $this->load();
×
170
        }
171

172
        return $this->proxyGeometry->getBoundingBox();
×
173
    }
174

175
    public function toArray(): array
176
    {
177
        if ($this->proxyGeometry === null) {
68✔
178
            $this->load();
8✔
179
        }
180

181
        return $this->proxyGeometry->toArray();
68✔
182
    }
183

184
    public function project(\Brick\Geo\Projector\Projector $projector): \Brick\Geo\Point
185
    {
186
        if ($this->proxyGeometry === null) {
×
187
            $this->load();
×
188
        }
189

190
        return $this->proxyGeometry->project($projector);
×
191
    }
192

193
    public function coordinateDimension(): int
194
    {
195
        if ($this->proxyGeometry === null) {
32✔
196
            $this->load();
×
197
        }
198

199
        return $this->proxyGeometry->coordinateDimension();
32✔
200
    }
201

202
    public function spatialDimension(): int
203
    {
204
        if ($this->proxyGeometry === null) {
32✔
205
            $this->load();
×
206
        }
207

208
        return $this->proxyGeometry->spatialDimension();
32✔
209
    }
210

211
    public function isEmpty(): bool
212
    {
213
        if ($this->proxyGeometry === null) {
50✔
214
            $this->load();
18✔
215
        }
216

217
        return $this->proxyGeometry->isEmpty();
50✔
218
    }
219

220
    public function is3D(): bool
221
    {
222
        if ($this->proxyGeometry === null) {
40✔
223
            $this->load();
32✔
224
        }
225

226
        return $this->proxyGeometry->is3D();
40✔
227
    }
228

229
    public function isMeasured(): bool
230
    {
231
        if ($this->proxyGeometry === null) {
8✔
232
            $this->load();
×
233
        }
234

235
        return $this->proxyGeometry->isMeasured();
8✔
236
    }
237

238
    public function coordinateSystem(): \Brick\Geo\CoordinateSystem
239
    {
240
        if ($this->proxyGeometry === null) {
18✔
241
            $this->load();
×
242
        }
243

244
        return $this->proxyGeometry->coordinateSystem();
18✔
245
    }
246

247
    public function withSrid(int $srid): \Brick\Geo\Geometry
248
    {
249
        if ($this->proxyGeometry === null) {
×
250
            $this->load();
×
251
        }
252

253
        return $this->proxyGeometry->withSrid($srid);
×
254
    }
255

256
    public function toXy(): \Brick\Geo\Geometry
257
    {
258
        if ($this->proxyGeometry === null) {
×
259
            $this->load();
×
260
        }
261

262
        return $this->proxyGeometry->toXy();
×
263
    }
264

265
    public function withoutZ(): \Brick\Geo\Geometry
266
    {
267
        if ($this->proxyGeometry === null) {
×
268
            $this->load();
×
269
        }
270

271
        return $this->proxyGeometry->withoutZ();
×
272
    }
273

274
    public function withoutM(): \Brick\Geo\Geometry
275
    {
276
        if ($this->proxyGeometry === null) {
×
277
            $this->load();
×
278
        }
279

280
        return $this->proxyGeometry->withoutM();
×
281
    }
282

283
    public function withRoundedCoordinates(int $precision): \Brick\Geo\Geometry
284
    {
285
        if ($this->proxyGeometry === null) {
×
286
            $this->load();
×
287
        }
288

289
        return $this->proxyGeometry->withRoundedCoordinates($precision);
×
290
    }
291

292
    public function swapXy(): \Brick\Geo\Geometry
293
    {
294
        if ($this->proxyGeometry === null) {
×
295
            $this->load();
×
296
        }
297

298
        return $this->proxyGeometry->swapXy();
×
299
    }
300

301
    public function isIdenticalTo(\Brick\Geo\Geometry $that): bool
302
    {
303
        if ($this->proxyGeometry === null) {
×
304
            $this->load();
×
305
        }
306

307
        return $this->proxyGeometry->isIdenticalTo($that);
×
308
    }
309

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