1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2019 webtrees development team 6 * This program is free software: you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation, either version 3 of the License, or 9 * (at your option) any later version. 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17declare(strict_types=1); 18 19namespace Fisharebest\Webtrees\SurnameTradition; 20 21/** 22 * Children take a patronym instead of a surname. 23 * 24 * Sons get their father’s given name plus “sson” 25 * Daughters get their father’s given name plus “sdottir” 26 */ 27class IcelandicSurnameTradition extends DefaultSurnameTradition 28{ 29 /** 30 * Does this surname tradition use surnames? 31 * 32 * @return bool 33 */ 34 public function hasSurnames(): bool 35 { 36 return false; 37 } 38 39 /** 40 * What names are given to a new child 41 * 42 * @param string $father_name A GEDCOM NAME 43 * @param string $mother_name A GEDCOM NAME 44 * @param string $child_sex M, F or U 45 * 46 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 47 */ 48 public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 49 { 50 if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) { 51 switch ($child_sex) { 52 case 'M': 53 return [ 54 'NAME' => $father_match['GIVN'] . 'sson', 55 ]; 56 case 'F': 57 return [ 58 'NAME' => $father_match['GIVN'] . 'sdottir', 59 ]; 60 } 61 } 62 63 return []; 64 } 65 66 /** 67 * What names are given to a new parent 68 * 69 * @param string $child_name A GEDCOM NAME 70 * @param string $parent_sex M, F or U 71 * 72 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 73 */ 74 public function newParentNames(string $child_name, string $parent_sex): array 75 { 76 if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) { 77 return [ 78 'NAME' => $child_match['GIVN'], 79 'GIVN' => $child_match['GIVN'], 80 ]; 81 } 82 83 return []; 84 } 85 86 /** 87 * What names are given to a new spouse 88 * 89 * @param string $spouse_name A GEDCOM NAME 90 * @param string $spouse_sex M, F or U 91 * 92 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 93 */ 94 public function newSpouseNames(string $spouse_name, string $spouse_sex): array 95 { 96 return []; 97 } 98} 99