Completed
Push — revert-4-support-laravel-5.x ( ad9bef )
by Hennik
09:26
created

MysqlConnection   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 42
ccs 14
cts 14
cp 1
rs 10
wmc 6

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 3
A getDefaultSchemaGrammar() 0 3 1
A getSchemaBuilder() 0 7 2
1
<?php
2
3
namespace LaravelSpatial;
4
5
use Doctrine\DBAL\Types\Type;
6
7
class MysqlConnection extends \Illuminate\Database\MySqlConnection
8
{
9 40
    public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
10
    {
11 40
        parent::__construct($pdo, $database, $tablePrefix, $config);
12 40
        if (class_exists(Type::class)) {
13
            // Prevent geometry type fields from throwing a 'type not found' error when changing them
14
            $geometries = [
15 40
                'geometry',
16
                'point',
17
                'linestring',
18
                'polygon',
19
                'multipoint',
20
                'multilinestring',
21
                'multipolygon',
22
                'geomcollection',
23
                'geometrycollection',
24
            ];
25 40
            $dbPlatform = $this->getDoctrineSchemaManager()->getDatabasePlatform();
26 40
            foreach ($geometries as $type) {
27 40
                $dbPlatform->registerDoctrineTypeMapping($type, 'string');
28
            }
29
        }
30 40
    }
31
32 13
    public function getSchemaBuilder()
33
    {
34 13
        if (is_null($this->schemaGrammar)) {
35 13
            $this->useDefaultSchemaGrammar();
36
        }
37
38 13
        return new Schema\Builder($this);
39
    }
40
41
    /**
42
     * Get the default schema grammar instance.
43
     *
44
     * @return \Illuminate\Database\Grammar
45
     */
46 13
    protected function getDefaultSchemaGrammar()
47
    {
48 13
        return $this->withTablePrefix(new Schema\Grammars\MySqlGrammar());
49
    }
50
}
51