familytree365 /
php-gedcom
| 1 | <?php |
||||||
| 2 | /** |
||||||
| 3 | * php-gedcom. |
||||||
| 4 | * |
||||||
| 5 | * php-gedcom is a library for parsing, manipulating, importing and exporting |
||||||
| 6 | * GEDCOM 5.5 files in PHP 5.3+. |
||||||
| 7 | * |
||||||
| 8 | * @author Kristopher Wilson <[email protected]> |
||||||
| 9 | * @copyright Copyright (c) 2010-2013, Kristopher Wilson |
||||||
| 10 | * @license MIT |
||||||
| 11 | * |
||||||
| 12 | * @link http://github.com/mrkrstphr/php-gedcom |
||||||
| 13 | */ |
||||||
| 14 | |||||||
| 15 | namespace Gedcom\Parser\Indi; |
||||||
| 16 | |||||||
| 17 | class Even extends \Gedcom\Parser\Component |
||||||
| 18 | { |
||||||
| 19 | public static function parse(\Gedcom\Parser $parser) |
||||||
| 20 | { |
||||||
| 21 | $record = $parser->getCurrentLineRecord(); |
||||||
| 22 | $depth = (int) $record[0]; |
||||||
| 23 | if (empty($record[1])) { |
||||||
| 24 | $parser->skipToNextLevel($depth); |
||||||
| 25 | |||||||
| 26 | return null; |
||||||
| 27 | } |
||||||
| 28 | |||||||
| 29 | if (strtoupper(trim($record[1])) != 'EVEN') { |
||||||
| 30 | $className = '\Gedcom\Record\Indi\\'.ucfirst(strtolower(trim($record[1]))); |
||||||
| 31 | $even = new $className(); |
||||||
| 32 | } else { |
||||||
| 33 | $even = new \Gedcom\Record\Indi\Even(); |
||||||
| 34 | } |
||||||
| 35 | |||||||
| 36 | if (isset($record[1]) && strtoupper(trim($record[1])) != 'EVEN') { |
||||||
| 37 | $even->setType(trim($record[1])); |
||||||
| 38 | } |
||||||
| 39 | |||||||
| 40 | // ensures we capture any data following the EVEN type |
||||||
| 41 | if (isset($record[2]) && !empty($record[2])) { |
||||||
| 42 | $even->setAttr(trim($record[2])); |
||||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||||
| 43 | } |
||||||
| 44 | |||||||
| 45 | $parser->forward(); |
||||||
| 46 | |||||||
| 47 | while (!$parser->eof()) { |
||||||
| 48 | $record = $parser->getCurrentLineRecord(); |
||||||
| 49 | $recordType = strtoupper(trim($record[1])); |
||||||
| 50 | $currentDepth = (int) $record[0]; |
||||||
| 51 | |||||||
| 52 | if ($currentDepth <= $depth) { |
||||||
| 53 | $parser->back(); |
||||||
| 54 | break; |
||||||
| 55 | } |
||||||
| 56 | |||||||
| 57 | switch ($recordType) { |
||||||
| 58 | case 'TYPE': |
||||||
| 59 | $even->setType(trim($record[2])); |
||||||
| 60 | break; |
||||||
| 61 | case 'DATE': |
||||||
| 62 | $dat = \Gedcom\Parser\Date::parse($parser); |
||||||
| 63 | $even->setDate($dat); |
||||||
| 64 | //$even->setDate(trim($record[2])) |
||||||
| 65 | break; |
||||||
| 66 | case 'PLAC': |
||||||
| 67 | $plac = \Gedcom\Parser\Plac::parse($parser); |
||||||
| 68 | $even->setPlac($plac); |
||||||
|
0 ignored issues
–
show
It seems like
$plac can also be of type Gedcom\Record\Plac; however, parameter $plac of Gedcom\Record\Indi\Even::setPlac() does only seem to accept Gedcom\Record\Indi\Even\Plac, maybe add an additional type check?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 69 | break; |
||||||
| 70 | case 'ADDR': |
||||||
| 71 | $even->setAddr(\Gedcom\Parser\Addr::parse($parser)); |
||||||
| 72 | break; |
||||||
| 73 | case 'PHON': |
||||||
| 74 | $phone = \Gedcom\Parser\Phon::parse($parser); |
||||||
| 75 | $even->addPhone($phone); |
||||||
|
0 ignored issues
–
show
The method
addPhone() does not exist on Gedcom\Record\Indi\Even. Since you implemented __call, consider adding a @method annotation.
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||||
| 76 | break; |
||||||
| 77 | case 'CAUS': |
||||||
| 78 | $even->setCaus(trim($record[2])); |
||||||
| 79 | break; |
||||||
| 80 | case 'AGE': |
||||||
| 81 | $even->setAge(trim($record[2])); |
||||||
| 82 | break; |
||||||
| 83 | case 'AGNC': |
||||||
| 84 | $even->setAgnc(trim($record[2])); |
||||||
| 85 | break; |
||||||
| 86 | case 'SOUR': |
||||||
| 87 | $sour = \Gedcom\Parser\SourRef::parse($parser); |
||||||
| 88 | $even->addSour($sour); |
||||||
| 89 | break; |
||||||
| 90 | case 'OBJE': |
||||||
| 91 | $obje = \Gedcom\Parser\ObjeRef::parse($parser); |
||||||
| 92 | $even->addObje($obje); |
||||||
| 93 | break; |
||||||
| 94 | case 'NOTE': |
||||||
| 95 | $note = \Gedcom\Parser\NoteRef::parse($parser); |
||||||
| 96 | if ($note) { |
||||||
| 97 | $even->addNote($note); |
||||||
| 98 | } |
||||||
| 99 | break; |
||||||
| 100 | case 'CHAN': |
||||||
| 101 | $change = \Gedcom\Parser\Chan::parse($parser); |
||||||
| 102 | $even->setChan($change); |
||||||
| 103 | break; |
||||||
| 104 | default: |
||||||
| 105 | $self = get_called_class(); |
||||||
| 106 | $method = 'parse'.$recordType; |
||||||
| 107 | |||||||
| 108 | if (method_exists($self, $method)) { |
||||||
| 109 | $self::$method($parser, $even); |
||||||
| 110 | } else { |
||||||
| 111 | $parser->logUnhandledRecord($self.' @ '.__LINE__); |
||||||
| 112 | $parser->skipToNextLevel($currentDepth); |
||||||
| 113 | } |
||||||
| 114 | } |
||||||
| 115 | |||||||
| 116 | $parser->forward(); |
||||||
| 117 | } |
||||||
| 118 | |||||||
| 119 | return $even; |
||||||
| 120 | } |
||||||
| 121 | } |
||||||
| 122 |