MysqlConnection   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getDefaultSchemaGrammar() 0 3 1
A __construct() 0 19 3
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
/**
10
 * Class MysqlConnection
11
 *
12
 * @package LaravelSpatial
13
 */
14
class MysqlConnection extends BaseMysqlConnection
15
{
16
    /**
17
     * @inheritDoc
18
     * @throws \Doctrine\DBAL\Exception
19
     */
20 40
    public function __construct($pdo, $database = '', $tablePrefix = '', array $config = [])
21
    {
22 40
        parent::__construct($pdo, $database, $tablePrefix, $config);
23 40
        if (class_exists(Type::class)) {
24
            // Prevent geometry type fields from throwing a 'type not found' error when changing them
25
            $geometries = [
26 40
                'geometry',
27
                'point',
28
                'linestring',
29
                'polygon',
30
                'multipoint',
31
                'multilinestring',
32
                'multipolygon',
33
                'geomcollection',
34
                'geometrycollection',
35
            ];
36 40
            $dbPlatform = $this->getDoctrineSchemaManager()->getDatabasePlatform();
37 40
            foreach ($geometries as $type) {
38 40
                $dbPlatform->registerDoctrineTypeMapping($type, 'string');
39
            }
40
        }
41 40
    }
42
43
    /**
44
     * @inheritDoc
45
     */
46 12
    protected function getDefaultSchemaGrammar()
47
    {
48 12
        return $this->withTablePrefix(new MySqlGrammar());
49
    }
50
}
51