Completed
Push — master ( c4e3cd...c5cae6 )
by Anton
05:38
created

Fragment::sqlStatement()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Spiral Framework.
4
 *
5
 * @license   MIT
6
 * @author    Anton Titov (Wolfy-J)
7
 */
8
namespace Spiral\Database\Injections;
9
10
use Spiral\Database\Entities\QueryCompiler;
11
12
/**
13
 * Default implementation of SQLFragmentInterface, provides ability to inject custom SQL code into
14
 * query builders. Usually used to mock database specific functions.
15
 *
16
 * Example: ...->where('time_created', '>', new SQLFragment("NOW()"));
17
 */
18
class Fragment implements FragmentInterface
19
{
20
    /**
21
     * @var string
22
     */
23
    private $statement = null;
24
25
    /**
26
     * @param string $statement
27
     */
28
    public function __construct($statement)
29
    {
30
        $this->statement = $statement;
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     *
36
     * @param QueryCompiler $compiler
37
     */
38
    public function sqlStatement(QueryCompiler $compiler = null)
39
    {
40
        return $this->statement;
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46
    public function __toString()
47
    {
48
        return $this->sqlStatement();
49
    }
50
51
    /**
52
     * @return object
53
     */
54
    public function __debugInfo()
55
    {
56
        return (object)['statement' => $this->sqlStatement()];
57
    }
58
}