| Conditions | 15 |
| Paths | 8 |
| Total Lines | 36 |
| Code Lines | 21 |
| 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 |
||
| 88 | public function getStatementArray(string $dumpContent, string $queryRegex = null): array |
||
| 89 | { |
||
| 90 | $statementArray = []; |
||
| 91 | $statementArrayPointer = 0; |
||
| 92 | $isInMultilineComment = false; |
||
| 93 | foreach (explode(LF, $dumpContent) as $lineContent) { |
||
| 94 | $lineContent = trim($lineContent); |
||
| 95 | |||
| 96 | // Skip empty lines and comments |
||
| 97 | if ($lineContent === '' || $lineContent[0] === '#' || strpos($lineContent, '--') === 0 || |
||
| 98 | strpos($lineContent, '/*') === 0 || substr($lineContent, -2) === '*/' || $isInMultilineComment |
||
| 99 | ) { |
||
| 100 | // skip c style multiline comments |
||
| 101 | if (strpos($lineContent, '/*') === 0 && substr($lineContent, -2) !== '*/') { |
||
| 102 | $isInMultilineComment = true; |
||
| 103 | } |
||
| 104 | if (substr($lineContent, -2) === '*/') { |
||
| 105 | $isInMultilineComment = false; |
||
| 106 | } |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | $statementArray[$statementArrayPointer] = ($statementArray[$statementArrayPointer] ?? '') . $lineContent; |
||
| 111 | |||
| 112 | if (substr($lineContent, -1) === ';') { |
||
| 113 | $statement = trim($statementArray[$statementArrayPointer]); |
||
| 114 | if (!$statement || ($queryRegex && !preg_match('/' . $queryRegex . '/i', $statement))) { |
||
| 115 | unset($statementArray[$statementArrayPointer]); |
||
| 116 | } |
||
| 117 | $statementArrayPointer++; |
||
| 118 | } else { |
||
| 119 | $statementArray[$statementArrayPointer] .= ' '; |
||
| 120 | } |
||
| 121 | } |
||
| 122 | |||
| 123 | return $statementArray; |
||
| 124 | } |
||
| 148 |