Passed
Push — master ( 1f10fe...ebb318 )
by y
01:23
created

Expression::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Helix\DB;
4
5
/**
6
 * A basic expression, exempt from being quoted.
7
 *
8
 * @method static ExpressionInterface avg($column)
9
 * @method static ExpressionInterface count($column)
10
 * @method static ExpressionInterface max($column)
11
 * @method static ExpressionInterface min($column)
12
 * @method static ExpressionInterface sum($column)
13
 */
14
class Expression implements ExpressionInterface {
15
16
    /**
17
     * @var string
18
     */
19
    protected $string;
20
21
    /**
22
     * Converts a camelCase method call to an UPPER_SNAKE_CASE function call,
23
     * with all arguments separated by spaces.
24
     *
25
     * `NAME(argument [argument...])`
26
     *
27
     * @param string $name
28
     * @param array $arguments
29
     * @return ExpressionInterface
30
     */
31
    public static function __callStatic (string $name, array $arguments): ExpressionInterface {
32
        $arguments = implode(' ', $arguments);
33
        $name = strtoupper(preg_replace('/(?<!^)[A-Z]/', '_$0', $name));
34
        return new static("{$name}({$arguments})");
35
    }
36
37
    /**
38
     * @param string $string
39
     */
40
    public function __construct (string $string) {
41
        $this->string = $string;
42
    }
43
44
    /**
45
     * @return string
46
     */
47
    public function __toString () {
48
        return $this->string;
49
    }
50
}