SpatialServiceProvider   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 19
c 2
b 0
f 0
dl 0
loc 41
ccs 10
cts 10
cp 1
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A register() 0 33 4
1
<?php
2
3
namespace LaravelSpatial;
4
5
use Doctrine\DBAL\Types\Type;
6
use Illuminate\Database\DatabaseManager;
7
use Illuminate\Database\DatabaseServiceProvider;
8
use LaravelSpatial\Connectors\ConnectionFactory;
9
use LaravelSpatial\Doctrine\Geometry;
10
use LaravelSpatial\Doctrine\GeometryCollection;
11
use LaravelSpatial\Doctrine\LineString;
12
use LaravelSpatial\Doctrine\MultiLineString;
13
use LaravelSpatial\Doctrine\MultiPoint;
14
use LaravelSpatial\Doctrine\MultiPolygon;
15
use LaravelSpatial\Doctrine\Point;
16
use LaravelSpatial\Doctrine\Polygon;
17
18
/**
19
 * Class DatabaseServiceProvider
20
 * @package LaravelSpatial
21
 */
22
class SpatialServiceProvider extends DatabaseServiceProvider
23
{
24
25
    /**
26
     * Register the service provider.
27
     *
28
     * @return void
29
     */
30 24
    public function register()
31
    {
32
        // The connection factory is used to create the actual connection instances on
33
        // the database. We will inject the factory into the manager so that it may
34
        // make the connections while they are actually needed and not of before.
35
        $this->app->singleton('db.factory', function ($app) {
36 24
            return new ConnectionFactory($app);
37 24
        });
38
39
        // The database manager is used to resolve various connections, since multiple
40
        // connections might be managed. It also implements the connection resolver
41
        // interface which may be used by other components requiring connections.
42
        $this->app->singleton('db', function ($app) {
43 24
            return new DatabaseManager($app, $app['db.factory']);
44 24
        });
45
46 24
        if (class_exists(Type::class)) {
47
            // Prevent geometry type fields from throwing a 'type not found' error when changing them
48
            $geometries = [
49 24
                'geometry' => Geometry::class,
50
                'point' => Point::class,
51
                'linestring' => LineString::class,
52
                'polygon' => Polygon::class,
53
                'multipoint' => MultiPoint::class,
54
                'multilinestring' => MultiLineString::class,
55
                'multipolygon' => MultiPolygon::class,
56
                'geomcollection' => GeometryCollection::class,
57
                'geometrycollection' => GeometryCollection::class,
58
            ];
59
60 24
            foreach ($geometries as $type => $class) {
61 24
                if (!Type::hasType($type)) {
62 1
                    Type::addType($type, $class);
63
                }
64
            }
65
        }
66 24
    }
67
}
68