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

Fragment   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 41
wmc 4
lcom 1
cbo 0
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A sqlStatement() 0 4 1
A __toString() 0 4 1
A __debugInfo() 0 4 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
}