Passed
Push — main ( c100f9...14c5bb )
by Siad
07:13
created

DummyPDOQuerySplitter::nextQuery()   C

Complexity

Conditions 12
Paths 21

Size

Total Lines 44
Code Lines 21

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 19
CRAP Score 12.1242

Importance

Changes 0
Metric Value
eloc 21
c 0
b 0
f 0
dl 0
loc 44
rs 6.9666
ccs 19
cts 21
cp 0.9048
cc 12
nc 21
nop 0
crap 12.1242

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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 9
    public function nextQuery(): ?string
39
    {
40 9
        $sql = null;
41
42 9
        while (($line = $this->sqlReader->readLine()) !== null) {
43 9
            $delimiter = $this->parent->getDelimiter();
44 9
            $project = $this->parent->getOwningTarget()->getProject();
45 9
            if (!$this->keepformat) {
46 9
                $line = trim($line);
47
            }
48 9
            if ($this->expandProperties) {
49 9
                $line = $project->replaceProperties($line);
50
            }
51
52
            if (
53 9
                !$this->keepformat
54 9
                && ($line !== $delimiter)
55 9
                && (StringHelper::startsWith('//', $line)
56 9
                    || StringHelper::startsWith('--', $line)
57 9
                    || StringHelper::startsWith('#', $line))
58
            ) {
59
                continue;
60
            }
61
62 9
            $sql .= ' ' . $line . "\n";
63
64
            // SQL defines "--" as a comment to EOL
65
            // and in Oracle it may contain a hint
66
            // so we cannot just remove it, instead we must end it
67 9
            if (!$this->keepformat && strpos($line, '--') !== false) {
68
                $sql .= "\n";
69
            }
70
71
            /*
72
             * fix issue with PDO and wrong formatted multi statements
73
             *
74
             * @issue 1108
75
             */
76 9
            if (StringHelper::endsWith($delimiter, $line)) {
77 3
                break;
78
            }
79
        }
80
81 9
        return $sql;
82
    }
83
}
84