Completed
Push — master ( 177022...fa1d20 )
by Joao
11:37
created

Schema::useCustomGrammar()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 15
rs 9.4285
cc 2
eloc 8
nc 2
nop 1
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);
1 ignored issue
show
Compatibility introduced by
$MySqlGrammar of type object<Illuminate\Database\Grammar> is not a sub-type of object<Illuminate\Databa...chema\Grammars\Grammar>. It seems like you assume a child class of the class Illuminate\Database\Grammar to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
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
}