Passed
Push — main ( bb891e...7e6e75 )
by Siad
09:02
created

DummyPDOQuerySplitter   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Test Coverage

Coverage 93.33%

Importance

Changes 0
Metric Value
wmc 7
eloc 16
c 0
b 0
f 0
dl 0
loc 38
rs 10
ccs 14
cts 15
cp 0.9333

1 Method

Rating   Name   Duplication   Size   Complexity  
B nextQuery() 0 31 7
1
<?php
2
3
/**
4
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
5
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
6
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
7
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
8
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
9
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
10
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
11
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
12
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
13
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
14
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
15
 *
16
 * This software consists of voluntary contributions made by many individuals
17
 * and is licensed under the LGPL. For more information please see
18
 * <http://phing.info>.
19
 */
20
21
namespace Phing\Task\System\Pdo;
22
23
use Phing\Util\StringHelper;
24
25
/**
26
 * Dummy query splitter: converts entire input into single
27
 * SQL string.
28
 *
29
 * @author  Michiel Rook <[email protected]>
30
 */
31
class DummyPDOQuerySplitter extends PDOQuerySplitter
32
{
33
    /**
34
     * Returns entire SQL source.
35
     *
36
     * @return null|string
37
     */
38 8
    public function nextQuery(): ?string
39
    {
40 8
        $sql = null;
41
42 8
        while (($line = $this->sqlReader->readLine()) !== null) {
43 8
            $delimiter = $this->parent->getDelimiter();
44 8
            $project = $this->parent->getOwningTarget()->getProject();
45 8
            $line = $project->replaceProperties(trim($line));
46
47
            if (
48 8
                ($line != $delimiter)
49 8
                && (StringHelper::startsWith('//', $line)
50 8
                    || StringHelper::startsWith('--', $line)
51 8
                    || StringHelper::startsWith('#', $line))
52
            ) {
53
                continue;
54
            }
55
56 8
            $sql .= ' ' . $line . "\n";
57
58
            /*
59
             * fix issue with PDO and wrong formated multistatements
60
             *
61
             * @issue 1108
62
             */
63 8
            if (StringHelper::endsWith($delimiter, $line)) {
64 3
                break;
65
            }
66
        }
67
68 8
        return $sql;
69
    }
70
}
71