| Conditions | 19 |
| Paths | 16 |
| Total Lines | 85 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 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 |
||
| 127 | protected function readFile($filePath, $contentOnly = false) |
||
| 128 | { |
||
| 129 | $separator = "\r\n"; |
||
| 130 | |||
| 131 | if ($contentOnly) { |
||
| 132 | $line = strtok($filePath, $separator); |
||
| 133 | } else { |
||
| 134 | $flags = FILE_SKIP_EMPTY_LINES | FILE_TEXT; |
||
| 135 | $lines = file($filePath, $flags); |
||
| 136 | } |
||
| 137 | |||
| 138 | $currentTag = ''; |
||
| 139 | $risRecords = []; |
||
| 140 | $risRecord = []; |
||
| 141 | $recordIndex = 0; |
||
| 142 | |||
| 143 | if ($contentOnly) { |
||
| 144 | |||
| 145 | while ($line !== false) { |
||
|
|
|||
| 146 | if (mb_detect_encoding($line) == 'UTF-8') { |
||
| 147 | $line = utf8_decode($line); |
||
| 148 | if (strpos($line, '?') === 0) { |
||
| 149 | $line = substr($line, 1); |
||
| 150 | } |
||
| 151 | } |
||
| 152 | |||
| 153 | $tempTag = trim(substr($line, 0, 2)); |
||
| 154 | if ($tempTag == 'EF') { |
||
| 155 | // End of file |
||
| 156 | break; |
||
| 157 | } |
||
| 158 | |||
| 159 | if ($tempTag == 'ER') { |
||
| 160 | $risRecords[$recordIndex] = $risRecord; |
||
| 161 | $risRecord = []; |
||
| 162 | $recordIndex += 1; |
||
| 163 | } else { |
||
| 164 | if ($tempTag) { |
||
| 165 | $currentTag = $tempTag; |
||
| 166 | } |
||
| 167 | |||
| 168 | $line = substr($line, 2); |
||
| 169 | |||
| 170 | if ($currentTag && array_key_exists($currentTag, self::$tagMap)) { |
||
| 171 | $risRecord[$currentTag][] = trim($line); |
||
| 172 | } |
||
| 173 | } |
||
| 174 | $line = strtok($separator); |
||
| 175 | } |
||
| 176 | |||
| 177 | } else { |
||
| 178 | foreach($lines as $line) { |
||
| 179 | |||
| 180 | if (mb_detect_encoding($line) == 'UTF-8') { |
||
| 181 | $line = utf8_decode($line); |
||
| 182 | if (strpos($line, '?') === 0) { |
||
| 183 | $line = substr($line, 1); |
||
| 184 | } |
||
| 185 | } |
||
| 186 | |||
| 187 | $tempTag = trim(substr($line, 0, 2)); |
||
| 188 | if ($tempTag == 'EF') { |
||
| 189 | // End of file |
||
| 190 | break; |
||
| 191 | } |
||
| 192 | |||
| 193 | if ($tempTag == 'ER') { |
||
| 194 | $risRecords[$recordIndex] = $risRecord; |
||
| 195 | $risRecord = []; |
||
| 196 | $recordIndex += 1; |
||
| 197 | } else { |
||
| 198 | if ($tempTag) { |
||
| 199 | $currentTag = $tempTag; |
||
| 200 | } |
||
| 201 | |||
| 202 | $line = substr($line, 2); |
||
| 203 | |||
| 204 | if ($currentTag && array_key_exists($currentTag, self::$tagMap)) { |
||
| 205 | $risRecord[$currentTag][] = trim($line); |
||
| 206 | } |
||
| 207 | } |
||
| 208 | } |
||
| 209 | } |
||
| 210 | |||
| 211 | return $risRecords; |
||
| 212 | } |
||
| 317 | } |