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

brick / geo / 13872073621

15 Mar 2025 10:37AM UTC coverage: 51.165% (-36.2%) from 87.322%
13872073621

push

github

BenMorel
Add support for GeosOp in requireEngine()

1866 of 3647 relevant lines covered (51.17%)

1154.34 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\Exception\GeometryIOException;
8
use Brick\Geo\Geometry;
9
use Brick\Geo\IO\Internal\AbstractWKBReader;
10
use Brick\Geo\IO\Internal\EWKBTools;
11
use Brick\Geo\IO\Internal\WKBBuffer;
12
use Brick\Geo\IO\Internal\WKBGeometryHeader;
13
use Override;
14

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

28
        if (! $buffer->isEndOfStream()) {
5,433✔
29
            throw GeometryIOException::invalidWKB('unexpected data at end of stream');
×
30
        }
31

32
        return $geometry;
5,433✔
33
    }
34

35
    #[Override]
36
    protected function readGeometryHeader(WKBBuffer $buffer) : WKBGeometryHeader
37
    {
38
        $header = $buffer->readUnsignedLong();
5,433✔
39

40
        $srid = null;
5,433✔
41

42
        if ($header >= 0 && $header < 4000) {
5,433✔
43
            $geometryType = $header % 1000;
2,457✔
44
            $dimension = ($header - $geometryType) / 1000;
2,457✔
45

46
            $hasZ = ($dimension === 1 || $dimension === 3);
2,457✔
47
            $hasM = ($dimension === 2 || $dimension === 3);
2,457✔
48
        } else {
49
            $geometryType = $header & 0xFFF;
3,136✔
50

51
            $hasZ    = (($header & EWKBTools::Z) !== 0);
3,136✔
52
            $hasM    = (($header & EWKBTools::M) !== 0);
3,136✔
53
            $hasSRID = (($header & EWKBTools::S) !== 0);
3,136✔
54

55
            if ($hasSRID) {
3,136✔
56
                $srid = $buffer->readUnsignedLong();
1,792✔
57
            }
58
        }
59

60
        return new WKBGeometryHeader($geometryType, $hasZ, $hasM, $srid);
5,433✔
61
    }
62
}
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