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

MysqlConnection::getDefaultSchemaGrammar()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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