Schema   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 2
Bugs 0 Features 2
Metric Value
wmc 4
c 2
b 0
f 2
lcom 1
cbo 4
dl 0
loc 49
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A connection() 0 5 1
A getFacadeAccessor() 0 5 1
A useCustomGrammar() 0 15 2
1
<?php namespace jlourenco\support\Database;
2
3
use Illuminate\Support\Facades\Facade;
4
5
class Schema extends Facade
6
{
7
8
    /**
9
     * Get a schema builder instance for a connection.
10
     *
11
     * @param  string  $name
12
     * @return \Illuminate\Database\Schema\Builder
13
     */
14
    public static function connection($name)
15
    {
16
        $connection = static::$app['db']->connection($name);
17
        return static::useCustomGrammar($connection);
18
    }
19
20
    /**
21
     * Get a schema builder.
22
     *
23
     * @return \Illuminate\Database\Schema\Builder
24
     */
25
    protected static function getFacadeAccessor()
26
    {
27
        $connection = static::$app['db']->connection();
28
        return static::useCustomGrammar($connection);
29
    }
30
31
    /**
32
     * Boot system by calling our custom Grammar
33
     *
34
     * @param  object  $connection \Illuminate\Database\Connection
35
     * @return \Illuminate\Database\Schema\Builder
36
     */
37
    protected static function useCustomGrammar($connection)
38
    {
39
        // Only for MySqlGrammar
40
        if (get_class($connection) === 'Illuminate\Database\MySqlConnection') {
41
            $MySqlGrammar = $connection->withTablePrefix(new MySqlGrammar);
42
            $connection->setSchemaGrammar($MySqlGrammar);
43
        }
44
45
        $schema = $connection->getSchemaBuilder();
46
        $schema->blueprintResolver(function($table, $callback) {
47
            return new Blueprint($table, $callback);
48
        });
49
50
        return $schema;
51
    }
52
53
}