Conditions | 23 |
Paths | 87 |
Total Lines | 80 |
Code Lines | 46 |
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 |
||
159 | private function buildLineage(LineageNode $node): LineageNode |
||
160 | { |
||
161 | $indi_surname = ''; |
||
162 | |||
163 | $indi_node = $node->individual(); |
||
164 | if ($indi_node !== null) { |
||
165 | if ($node->families()->count() === 0) { |
||
166 | foreach ($indi_node->spouseFamilies() as $spouse_family) { |
||
167 | $node->addFamily($spouse_family); |
||
168 | } |
||
169 | } |
||
170 | |||
171 | $indi_surname = $indi_node->getAllNames()[$indi_node->getPrimaryName()]['surname'] ?? ''; |
||
172 | $node->rootNode()->addPlace($indi_node->getBirthPlace()); |
||
173 | |||
174 | //Tag the individual as used |
||
175 | $this->used_indis->put($indi_node->xref(), true); |
||
176 | } |
||
177 | |||
178 | foreach ($node->families() as $family_node) { |
||
179 | /** @var Family $spouse_family */ |
||
180 | $spouse_family = $family_node->family; |
||
181 | $spouse_surname = ''; |
||
182 | $spouse = null; |
||
183 | if ( |
||
184 | $indi_node !== null && |
||
185 | ($spouse = $spouse_family->spouse($indi_node)) !== null && $spouse->canShowName() |
||
186 | ) { |
||
187 | $spouse_surname = $spouse->getAllNames()[$spouse->getPrimaryName()]['surname'] ?? ''; |
||
188 | } |
||
189 | |||
190 | $nb_children = $nb_natural = 0; |
||
191 | |||
192 | foreach ($spouse_family->children() as $child) { |
||
193 | if (!($child->isPendingAddition() && $child->privatizeGedcom(Auth::PRIV_HIDE) === '')) { |
||
194 | $child_surname = $child->getAllNames()[$child->getPrimaryName()]['surname'] ?? ''; |
||
195 | |||
196 | $nb_children++; |
||
197 | if ($indi_node !== null && $indi_node->sex() === 'F') { //If the root individual is the mother |
||
198 | //Print only lineages of children with the same surname as their mother |
||
199 | //(supposing they are natural children) |
||
200 | /** @psalm-suppress RedundantCondition */ |
||
201 | if ( |
||
202 | $spouse === null || |
||
203 | ($spouse_surname !== '' && I18N::comparator()($child_surname, $spouse_surname) != 0) |
||
204 | ) { |
||
205 | if (I18N::comparator()($child_surname, $indi_surname) === 0) { |
||
206 | $nb_natural++; |
||
207 | $node_child = new LineageNode($child, $node->rootNode()); |
||
208 | $node_child = $this->buildLineage($node_child); |
||
209 | $node->addChild($spouse_family, $node_child); |
||
210 | } |
||
211 | } |
||
212 | } else { //If the root individual is the father |
||
213 | $nb_natural++; |
||
214 | //Print if the children does not bear the same name as his mother |
||
215 | //(and different from his father) |
||
216 | if ( |
||
217 | mb_strlen($child_surname) === 0 || |
||
218 | mb_strlen($indi_surname) === 0 || mb_strlen($spouse_surname) === 0 || |
||
219 | I18N::comparator()($child_surname, $indi_surname) === 0 || |
||
220 | I18N::comparator()($child_surname, $spouse_surname) != 0 |
||
221 | ) { |
||
222 | $node_child = new LineageNode($child, $node->rootNode()); |
||
223 | $node_child = $this->buildLineage($node_child); |
||
224 | } else { |
||
225 | $node_child = new LineageNode($child, $node->rootNode(), $child_surname); |
||
226 | } |
||
227 | $node->addChild($spouse_family, $node_child); |
||
228 | } |
||
229 | } |
||
230 | } |
||
231 | |||
232 | //Do not print other children |
||
233 | if (($nb_children - $nb_natural) > 0) { |
||
234 | $node->addChild($spouse_family, null); |
||
235 | } |
||
236 | } |
||
237 | |||
238 | return $node; |
||
239 | } |
||
241 |