1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2021 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 <https://www.gnu.org/licenses/>. 16 */ 17 18declare(strict_types=1); 19 20namespace Fisharebest\Webtrees\SurnameTradition; 21 22/** 23 * Children take a patronym instead of a surname. 24 * 25 * Sons get their father’s given name plus “sson” 26 * Daughters get their father’s given name plus “sdottir” 27 */ 28class IcelandicSurnameTradition extends DefaultSurnameTradition 29{ 30 /** 31 * Does this surname tradition use surnames? 32 * 33 * @return bool 34 */ 35 public function hasSurnames(): bool 36 { 37 return false; 38 } 39 40 /** 41 * What names are given to a new child 42 * 43 * @param string $father_name A GEDCOM NAME 44 * @param string $mother_name A GEDCOM NAME 45 * @param string $child_sex M, F or U 46 * 47 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 48 */ 49 public function newChildNames(string $father_name, string $mother_name, string $child_sex): array 50 { 51 if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) { 52 switch ($child_sex) { 53 case 'M': 54 return [ 55 'NAME' => $father_match['GIVN'] . 'sson', 56 ]; 57 case 'F': 58 return [ 59 'NAME' => $father_match['GIVN'] . 'sdottir', 60 ]; 61 } 62 } 63 64 return []; 65 } 66 67 /** 68 * What names are given to a new parent 69 * 70 * @param string $child_name A GEDCOM NAME 71 * @param string $parent_sex M, F or U 72 * 73 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 74 */ 75 public function newParentNames(string $child_name, string $parent_sex): array 76 { 77 if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) { 78 return [ 79 'NAME' => $child_match['GIVN'], 80 'GIVN' => $child_match['GIVN'], 81 ]; 82 } 83 84 return []; 85 } 86 87 /** 88 * What names are given to a new spouse 89 * 90 * @param string $spouse_name A GEDCOM NAME 91 * @param string $spouse_sex M, F or U 92 * 93 * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.) 94 */ 95 public function newSpouseNames(string $spouse_name, string $spouse_sex): array 96 { 97 return []; 98 } 99} 100