Completed
Push — develop ( 505f0b...e8b338 )
by Peter
01:58
created

SqlString::key()   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 0
1
<?php
2
/**
3
 * Webino (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino/WebinoDbDump for the canonical source repository
6
 * @copyright   Copyright (c) 2016 Webino, s. r. o. (http://webino.sk)
7
 * @license     The BSD 3-Clause License
8
 */
9
10
namespace WebinoDbDump\Db\Sql;
11
12
/**
13
 * Sql string
14
 *
15
 * @author Peter Bačinský <[email protected]>
16
 */
17
class SqlString implements SqlInterface
18
{
19
    use SqlTrait;
20
21
    /**
22
     * @var array
23
     */
24
    protected $lines = [];
25
26
    /**
27
     * @param string $sql
28
     */
29
    public function __construct($sql)
30
    {
31
        $this->lines = explode(PHP_EOL, $sql);
32
    }
33
34
    /**
35
     * @param callable $callback
36
     */
37
    protected function eachQuery(callable $callback)
38
    {
39
        while ($line = current($this->lines)) {
40
            next($this->lines);
41
42
            $result = call_user_func($callback, $line);
43
            if (false === $result) {
44
                continue;
45
            } elseif (true === $result) {
46
                break;
47
            }
48
        }
49
    }
50
51
    /**
52
     * @return mixed
53
     */
54
    public function key()
55
    {
56
        return key($this->lines);
57
    }
58
59
    /**
60
     * @return void
61
     */
62
    public function rewind()
63
    {
64
        reset($this->lines);
65
    }
66
}
67