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

brick / geo / 13730559764

07 Mar 2025 10:35PM UTC coverage: 84.117%. Remained the same
13730559764

push

github

BenMorel
Add tests for CompoundCurve explicit form

1557 of 1851 relevant lines covered (84.12%)

1351.65 hits per line

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

75.0
/src/Proxy/ProxyFactory.php
1
<?php
2

3
declare(strict_types=1);
4

5
namespace Brick\Geo\Proxy;
6

7
use Brick\Geo\Exception\UnexpectedGeometryException;
8
use Brick\Geo\Geometry;
9
use Brick\Geo\IO\EWKBReader;
10
use Brick\Geo\IO\EWKTReader;
11
use Brick\Geo\IO\WKBReader;
12
use Brick\Geo\IO\WKTReader;
13
use Closure;
14
use ReflectionClass;
15

16
/**
17
 * Creates proxies to lazily load geometries.
18
 */
19
final readonly class ProxyFactory
20
{
21
    /**
22
     * Creates a proxy to lazily load a Geometry from WKB data.
23
     *
24
     * @template T of Geometry
25
     *
26
     * @param class-string<T> $geometryClass The non-abstract Geometry class to create a proxy for.
27
     * @param string          $wkb           The WKB data that represents an instance of the given class.
28
     * @param int             $srid          The optional SRID of the geometry.
29
     *
30
     * @return T
31
     */
32
    public static function createWkbProxy(string $geometryClass, string $wkb, int $srid = 0) : Geometry
33
    {
34
        return self::createProxy($geometryClass, fn() => new WKBReader()->read($wkb, $srid));
1,796✔
35
    }
36

37
    /**
38
     * Creates a proxy to lazily load a Geometry from WKT data.
39
     *
40
     * @template T of Geometry
41
     *
42
     * @param class-string<T> $geometryClass The non-abstract Geometry class to create a proxy for.
43
     * @param string          $wkt           The WKT data that represents an instance of the given class.
44
     * @param int             $srid          The optional SRID of the geometry.
45
     *
46
     * @return T
47
     */
48
    public static function createWktProxy(string $geometryClass, string $wkt, int $srid = 0) : Geometry
49
    {
50
        return self::createProxy($geometryClass, fn() => new WKTReader()->read($wkt, $srid));
5✔
51
    }
52

53
    /**
54
     * Creates a proxy to lazily load a Geometry from EWKB data.
55
     *
56
     * @template T of Geometry
57
     *
58
     * @param class-string<T> $geometryClass The non-abstract Geometry class to create a proxy for.
59
     * @param string          $ewkb          The EWKB data that represents an instance of the given class.
60
     *
61
     * @return T
62
     */
63
    public static function createEwkbProxy(string $geometryClass, string $ewkb) : Geometry
64
    {
65
        return self::createProxy($geometryClass, fn() => new EWKBReader()->read($ewkb));
×
66
    }
67

68
    /**
69
     * Creates a proxy to lazily load a Geometry from EWKT data.
70
     *
71
     * @template T of Geometry
72
     *
73
     * @param class-string<T> $geometryClass The non-abstract Geometry class to create a proxy for.
74
     * @param string          $ewkt          The EWKT data that represents an instance of the given class.
75
     *
76
     * @return T
77
     */
78
    public static function createEwktProxy(string $geometryClass, string $ewkt) : Geometry
79
    {
80
        return self::createProxy($geometryClass, fn() => new EWKTReader()->read($ewkt));
×
81
    }
82

83
    /**
84
     * Creates a proxy to lazily load a Geometry from a closure.
85
     *
86
     * @template T of Geometry
87
     *
88
     * @param class-string<T>     $geometryClass The non-abstract Geometry class to create a proxy for.
89
     * @param Closure(): Geometry $readGeometry  A closure that creates a Geometry of the given class.
90
     *
91
     * @return T
92
     */
93
    public static function createProxy(string $geometryClass, Closure $readGeometry) : Geometry
94
    {
95
        return new ReflectionClass($geometryClass)->newLazyProxy(
1,801✔
96
            function() use ($geometryClass, $readGeometry) {
1,801✔
97
                $geometry = $readGeometry();
1,801✔
98

99
                if ($geometry instanceof $geometryClass) {
1,801✔
100
                    return $geometry;
1,801✔
101
                }
102

103
                throw UnexpectedGeometryException::unexpectedGeometryType($geometryClass, $geometry);
×
104
            },
1,801✔
105
        );
1,801✔
106
    }
107
}
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