Completed
Push — master ( 2de20d...d4d19b )
by Marcin
02:35
created

SqlQuery::removeNewLines()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Mnabialek\LaravelSqlLogger\Objects;
4
5
use Mnabialek\LaravelSqlLogger\Objects\Concerns\ReplacesBindings;
6
7
class SqlQuery
8
{
9
    use ReplacesBindings;
10
11
    /**
12
     * @var int
13
     */
14
    private $number;
15
16
    /**
17
     * @var string
18
     */
19
    private $sql;
20
21
    /**
22
     * @var array
23
     */
24
    private $bindings;
25
26
    /**
27
     * @var float
28
     */
29
    private $time;
30
31
    /**
32
     * SqlQuery constructor.
33
     *
34
     * @param int $number
35
     * @param string $sql
36
     * @param array $bindings
37
     * @param float $time
38
     */
39
    public function __construct($number, $sql, array $bindings, $time)
40
    {
41
        $this->number = $number;
42
        $this->sql = $sql;
43
        $this->bindings = $bindings;
44
        $this->time = $time;
45
    }
46
47
    /**
48
     * Get number of query.
49
     * 
50
     * @return int
51
     */
52
    public function number()
53
    {
54
        return $this->number;
55
    }
56
57
    /**
58
     * Get raw SQL (without bindings).
59
     * 
60
     * @return string
61
     */
62
    public function raw()
63
    {
64
        return $this->sql;
65
    }
66
67
    /**
68
     * Get bindings.
69
     * 
70
     * @return array
71
     */
72
    public function bindings()
73
    {
74
        return $this->bindings;
75
    }
76
77
    /**
78
     * Get time.
79
     * 
80
     * @return float
81
     */
82
    public function time()
83
    {
84
        return $this->time;
85
    }
86
87
    /**
88
     * Get full query with values from bindings inserted.
89
     *
90
     * @return string
91
     */
92
    public function get()
93
    {
94
        return $this->removeNewLines($this->replaceBindings($this->sql, $this->bindings));
95
    }
96
97
    /**
98
     * Remove new lines from SQL to keep it in single line if possible.
99
     *
100
     * @param string $sql
101
     *
102
     * @return string
103
     */
104
    protected function removeNewLines($sql)
105
    {
106
        return preg_replace($this->wrapRegex($this->notInsideQuotes('\v', false)), ' ', $sql);
107
    }
108
}
109