Conditions | 23 |
Paths | 122 |
Total Lines | 89 |
Code Lines | 47 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
70 | public function nextQuery(): ?string |
||
71 | { |
||
72 | $sql = ''; |
||
73 | $hasQuery = false; |
||
74 | |||
75 | while (($line = $this->sqlReader->readLine()) !== null) { |
||
76 | $delimiter = $this->parent->getDelimiter(); |
||
77 | $project = $this->parent->getOwningTarget()->getProject(); |
||
78 | if (!$this->keepformat) { |
||
79 | $line = trim($line); |
||
80 | } |
||
81 | if ($this->expandProperties) { |
||
82 | $line = $project->replaceProperties($line); |
||
83 | } |
||
84 | |||
85 | if ( |
||
86 | !$this->keepformat |
||
87 | && ($line !== $delimiter) |
||
88 | && (StringHelper::startsWith('//', $line) |
||
89 | || StringHelper::startsWith('--', $line) |
||
90 | || StringHelper::startsWith('#', $line)) |
||
91 | ) { |
||
92 | continue; |
||
93 | } |
||
94 | |||
95 | if ( |
||
96 | strlen($line) > 4 |
||
97 | && stripos($line, 'REM ') === 0 |
||
98 | ) { |
||
99 | continue; |
||
100 | } |
||
101 | |||
102 | // MySQL supports defining new delimiters |
||
103 | if (preg_match('/DELIMITER [\'"]?([^\'" $]+)[\'"]?/i', $line, $matches)) { |
||
104 | $this->parent->setDelimiter($matches[1]); |
||
105 | |||
106 | continue; |
||
107 | } |
||
108 | |||
109 | if ('' !== $this->sqlBacklog) { |
||
110 | $sql = $this->sqlBacklog; |
||
111 | $this->sqlBacklog = ''; |
||
112 | } |
||
113 | |||
114 | $sql .= ' ' . $line . "\n"; |
||
115 | |||
116 | // SQL defines "--" as a comment to EOL |
||
117 | // and in Oracle it may contain a hint |
||
118 | // so we cannot just remove it, instead we must end it |
||
119 | if (!$this->keepformat && false !== strpos((string) $line, '--')) { |
||
120 | $sql .= "\n"; |
||
121 | } |
||
122 | |||
123 | // DELIM_ROW doesn't need this (as far as i can tell) |
||
124 | if (PDOSQLExecTask::DELIM_NORMAL === $this->delimiterType) { |
||
125 | $reg = "#((?:\"(?:\\\\.|[^\"])*\"?)+|'(?:\\\\.|[^'])*'?|" . preg_quote($delimiter, null) . ')#'; |
||
126 | |||
127 | $sqlParts = preg_split($reg, $sql, 0, PREG_SPLIT_DELIM_CAPTURE); |
||
128 | $this->sqlBacklog = ''; |
||
129 | foreach ($sqlParts as $sqlPart) { |
||
130 | // we always want to append, even if it's a delim (which will be stripped off later) |
||
131 | $this->sqlBacklog .= $sqlPart; |
||
132 | |||
133 | // we found a single (not enclosed by ' or ") delimiter, so we can use all stuff before the delim as the actual query |
||
134 | if ($sqlPart === $delimiter) { |
||
135 | $sql = $this->sqlBacklog; |
||
136 | $this->sqlBacklog = ''; |
||
137 | $hasQuery = true; |
||
138 | } |
||
139 | } |
||
140 | } |
||
141 | |||
142 | if ($hasQuery || (PDOSQLExecTask::DELIM_ROW === $this->delimiterType && $line === $delimiter)) { |
||
143 | // this assumes there is always a delimter on the end of the SQL statement. |
||
144 | return StringHelper::substring( |
||
145 | $sql, |
||
146 | 0, |
||
147 | strlen($sql) - strlen($delimiter) |
||
148 | - (PDOSQLExecTask::DELIM_ROW === $this->delimiterType ? 2 : 1) |
||
149 | ); |
||
150 | } |
||
151 | } |
||
152 | |||
153 | // Catch any statements not followed by ; |
||
154 | if ('' !== $sql) { |
||
155 | return $sql; |
||
156 | } |
||
157 | |||
158 | return null; |
||
159 | } |
||
161 |