GrammarFactory   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 0
dl 0
loc 18
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 10 2
1
<?php
2
3
namespace Tonysm\LaravelParatest\Database\Schema;
4
5
use RuntimeException;
6
7
class GrammarFactory
8
{
9
    private static $availableOptions = [
10
        'mysql' => Grammars\MySQL::class,
11
        'pgsql' => Grammars\PgSQL::class,
12
    ];
13
14
    public function make(string $driver): Grammars\SQL
15
    {
16
        if (!array_key_exists($driver, static::$availableOptions)) {
0 ignored issues
show
Bug introduced by
Since $availableOptions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $availableOptions to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
17
            throw new RuntimeException(sprintf('Unkown driver "%s".', $driver));
18
        }
19
20
        $grammar = static::$availableOptions[$driver];
0 ignored issues
show
Bug introduced by
Since $availableOptions is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $availableOptions to at least protected.

Let’s assume you have a class which uses late-static binding:

class YourClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return static::$someVariable;
    }
}

The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
21
22
        return new $grammar;
23
    }
24
}
25