GrammarFactory::make()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.9332
c 0
b 0
f 0
cc 2
nc 2
nop 1
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