Test Failed
Push — v0.1 ( 3df3e6...629e1b )
by Hennik
13:04 queued 08:54
created

MysqlConnection::getSchemaBuilder()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelSpatial;
4
5
use Doctrine\DBAL\Types\Type;
6
use Illuminate\Database\MySqlConnection as BaseMysqlConnection;
7
use LaravelSpatial\Schema\Grammars\MySqlGrammar;
8
9 40
/**
10
 * Class MysqlConnection
11 40
 *
12 40
 * @package LaravelSpatial
13
 */
14
class MysqlConnection extends BaseMysqlConnection
15 40
{
16
    /**
17
     * @inheritDoc
18
     * @throws \Doctrine\DBAL\DBALException
19
     */
20
    public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
21
    {
22
        parent::__construct($pdo, $database, $tablePrefix, $config);
23
        if (class_exists(Type::class)) {
24
            // Prevent geometry type fields from throwing a 'type not found' error when changing them
25 40
            $geometries = [
26 40
                'geometry',
27 40
                'point',
28
                'linestring',
29
                'polygon',
30 40
                'multipoint',
31
                'multilinestring',
32 13
                'multipolygon',
33
                'geomcollection',
34 13
                'geometrycollection',
35 13
            ];
36
            $dbPlatform = $this->getDoctrineSchemaManager()->getDatabasePlatform();
37
            foreach ($geometries as $type) {
38 13
                $dbPlatform->registerDoctrineTypeMapping($type, 'string');
39
            }
40
        }
41
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 13
    protected function getDefaultSchemaGrammar()
47
    {
48 13
        return $this->withTablePrefix(new MySqlGrammar());
49
    }
50
}
51