Completed
Push — master ( 8f69e2...0f05a9 )
by ARCANEDEV
06:56
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 80%

Importance

Changes 0
Metric Value
dl 0
loc 46
c 0
b 0
f 0
wmc 2
lcom 1
cbo 1
ccs 4
cts 5
cp 0.8
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A make() 0 9 2
1
<?php namespace Arcanedev\LaravelMetrics\Expressions;
2
3
use Illuminate\Support\Arr;
4
use InvalidArgumentException;
5
6
/**
7
 * Class     Factory
8
 *
9
 * @package  Arcanedev\LaravelMetrics\Expressions
10
 * @author   ARCANEDEV <[email protected]>
11
 */
12
class Factory
13
{
14
    /* -----------------------------------------------------------------
15
     |  Properties
16
     | -----------------------------------------------------------------
17
     */
18
19
    /**
20
     * The registered expressions.
21
     *
22
     * @var array
23
     */
24
    protected static $expressions = [
25
        'if_null' => [
26
            'mariadb' => IfNull\MySqlExpression::class,
27
            'mysql'   => IfNull\MySqlExpression::class,
28
            'pgsql'   => IfNull\PostgresExpression::class,
29
            'sqlite'  => IfNull\SqliteExpression::class,
30
        ],
31
    ];
32
33
    /* -----------------------------------------------------------------
34
     |  Properties
35
     | -----------------------------------------------------------------
36
     */
37
38
    /**
39
     * Make an expression.
40
     *
41
     * @param  string  $driver
42
     * @param  string  $name
43
     * @param  mixed   $value
44
     * @param  array   $params
45
     *
46
     * @return \Arcanedev\LaravelMetrics\Expressions\Expression|mixed
47
     */
48 4
    public static function make(string $driver, string $name, $value, array $params = []): Expression
49
    {
50 4
        $expression = Arr::get(static::$expressions, "{$name}.{$driver}");
51
52 4
        if (is_null($expression))
53
            throw new InvalidArgumentException("Expression `{$name}` not found for `{$driver}` driver");
54
55 4
        return new $expression($value, ...$params);
56
    }
57
}
58