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

MysqlConnection::__construct()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 19
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 15
nc 3
nop 4
dl 0
loc 19
ccs 7
cts 7
cp 1
crap 3
rs 9.7666
c 0
b 0
f 0
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