Completed
Push — master ( 0f05a9...994973 )
by ARCANEDEV
06:19
created

Factory   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

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

1 Method

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