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

brick / geo / 13753277563

09 Mar 2025 10:43PM UTC coverage: 49.787% (+2.5%) from 47.295%
13753277563

push

github

BenMorel
Prepare for release

1749 of 3513 relevant lines covered (49.79%)

975.53 hits per line

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

94.74
/src/IO/EWKBReader.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\IO;
6

7
use Brick\Geo\Geometry;
8
use Brick\Geo\Exception\GeometryIOException;
9
use Override;
10

11
/**
12
 * Reads geometries out of the Extended WKB format designed by PostGIS.
13
 */
14
final class EWKBReader extends AbstractWKBReader
15
{
16
    /**
17
     * @throws GeometryIOException
18
     */
19
    public function read(string $ewkb) : Geometry
20
    {
21
        $buffer = new WKBBuffer($ewkb);
4,761✔
22
        $geometry = $this->readGeometry($buffer, 0);
4,761✔
23

24
        if (! $buffer->isEndOfStream()) {
4,761✔
25
            throw GeometryIOException::invalidWKB('unexpected data at end of stream');
×
26
        }
27

28
        return $geometry;
4,761✔
29
    }
30

31
    #[Override]
32
    protected function readGeometryHeader(WKBBuffer $buffer) : WKBGeometryHeader
33
    {
34
        $header = $buffer->readUnsignedLong();
4,761✔
35

36
        $srid = null;
4,761✔
37

38
        if ($header >= 0 && $header < 4000) {
4,761✔
39
            $geometryType = $header % 1000;
2,157✔
40
            $dimension = ($header - $geometryType) / 1000;
2,157✔
41

42
            $hasZ = ($dimension === 1 || $dimension === 3);
2,157✔
43
            $hasM = ($dimension === 2 || $dimension === 3);
2,157✔
44
        } else {
45
            $geometryType = $header & 0xFFF;
2,744✔
46

47
            $hasZ    = (($header & EWKBTools::Z) !== 0);
2,744✔
48
            $hasM    = (($header & EWKBTools::M) !== 0);
2,744✔
49
            $hasSRID = (($header & EWKBTools::S) !== 0);
2,744✔
50

51
            if ($hasSRID) {
2,744✔
52
                $srid = $buffer->readUnsignedLong();
1,568✔
53
            }
54
        }
55

56
        return new WKBGeometryHeader($geometryType, $hasZ, $hasM, $srid);
4,761✔
57
    }
58
}
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