| Conditions | 26 | 
| Paths | 26 | 
| Total Lines | 60 | 
| Code Lines | 38 | 
| 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 | ||
| 214 | public function parse($fileName) | ||
| 215 |     { | ||
| 216 |         $this->_file = fopen($fileName, 'r'); //explode("\n", mb_convert_encoding($contents, 'UTF-8')); | ||
| 217 | |||
| 218 |         if (!$this->_file) { | ||
| 219 | return null; | ||
| 220 | } | ||
| 221 | |||
| 222 | $this->forward(); | ||
| 223 | |||
| 224 |         while (!$this->eof()) { | ||
| 225 | $record = $this->getCurrentLineRecord(); | ||
| 226 | |||
| 227 |             if ($record === false) { | ||
| 228 | continue; | ||
| 229 | } | ||
| 230 | |||
| 231 | $depth = (int) $record[0]; | ||
| 232 | |||
| 233 | // We only process 0 level records here. Sub levels are processed | ||
| 234 | // in methods for those data types (individuals, sources, etc) | ||
| 235 | |||
| 236 |             if ($depth == 0) { | ||
| 237 | // Although not always an identifier (HEAD,TRLR): | ||
| 238 |                 if (isset($record[1])) { | ||
| 239 | $identifier = $this->normalizeIdentifier($record[1]); | ||
| 240 | } | ||
| 241 | |||
| 242 |                 if (isset($record[1]) && trim($record[1]) == 'HEAD') { | ||
| 243 | Parser\Head::parse($this); | ||
| 244 |                 } elseif (isset($record[2]) && trim($record[2]) == 'SUBN') { | ||
| 245 | Parser\Subn::parse($this); | ||
| 246 |                 } elseif (isset($record[2]) && trim($record[2]) == 'SUBM') { | ||
| 247 | Parser\Subm::parse($this); | ||
| 248 |                 } elseif (isset($record[2]) && $record[2] == 'SOUR') { | ||
| 249 | Parser\Sour::parse($this); | ||
| 250 |                 } elseif (isset($record[2]) && $record[2] == 'INDI') { | ||
| 251 | Parser\Indi::parse($this); | ||
| 252 |                 } elseif (isset($record[2]) && $record[2] == 'FAM') { | ||
| 253 | Parser\Fam::parse($this); | ||
| 254 |                 } elseif (isset($record[2]) && substr(trim($record[2]), 0, 4) == 'NOTE') { | ||
| 255 | Parser\Note::parse($this); | ||
| 256 |                 } elseif (isset($record[2]) && $record[2] == 'REPO') { | ||
| 257 | Parser\Repo::parse($this); | ||
| 258 |                 } elseif (isset($record[2]) && $record[2] == 'OBJE') { | ||
| 259 | Parser\Obje::parse($this); | ||
| 260 |                 } elseif (isset($record[1]) && trim($record[1]) == 'TRLR') { | ||
| 261 | // EOF | ||
| 262 | break; | ||
| 263 |                 } else { | ||
| 264 | $this->logUnhandledRecord(get_class().' @ '.__LINE__); | ||
| 265 | } | ||
| 266 |             } else { | ||
| 267 | $this->logUnhandledRecord(get_class().' @ '.__LINE__); | ||
| 268 | } | ||
| 269 | |||
| 270 | $this->forward(); | ||
| 271 | } | ||
| 272 | |||
| 273 | return $this->getGedcom(); | ||
| 274 | } | ||
| 276 |