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