1<?php 2 3/** 4 * webtrees: online genealogy 5 * Copyright (C) 2022 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 22use Fisharebest\Webtrees\Elements\NameType; 23use Fisharebest\Webtrees\Individual; 24 25/** 26 * Children take a patronym instead of a surname. 27 * 28 * Sons get their father’s given name plus “sson” 29 * Daughters get their father’s given name plus “sdottir” 30 */ 31class IcelandicSurnameTradition extends DefaultSurnameTradition 32{ 33 /** 34 * A default/empty name 35 * 36 * @return string 37 */ 38 public function defaultName(): string 39 { 40 return ''; 41 } 42 43 /** 44 * What name is given to a new child 45 * 46 * @param Individual|null $father 47 * @param Individual|null $mother 48 * @param string $sex 49 * 50 * @return array<int,string> 51 */ 52 public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 53 { 54 if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match)) { 55 switch ($sex) { 56 case 'M': 57 $givn = $match['GIVN'] . 'sson'; 58 59 return [ 60 $this->buildName($givn, ['TYPE' => NameType::TYPE_BIRTH, 'GIVN' => $givn]), 61 ]; 62 63 case 'F': 64 $givn = $match['GIVN'] . 'sdottir'; 65 66 return [ 67 $this->buildName($givn, ['TYPE' => NameType::TYPE_BIRTH, 'GIVN' => $givn]), 68 ]; 69 } 70 } 71 72 return [ 73 $this->buildName('', ['TYPE' => NameType::TYPE_BIRTH]), 74 ]; 75 } 76 77 /** 78 * What name is given to a new parent 79 * 80 * @param Individual $child 81 * @param string $sex 82 * 83 * @return array<int,string> 84 */ 85 public function newParentNames(Individual $child, string $sex): array 86 { 87 if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match)) { 88 return [ 89 $this->buildName($match['GIVN'], ['TYPE' => NameType::TYPE_BIRTH, 'GIVN' => $match['GIVN']]), 90 ]; 91 } 92 93 if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match)) { 94 return [ 95 $this->buildName($match['GIVN'], ['TYPE' => NameType::TYPE_BIRTH, 'GIVN' => $match['GIVN']]), 96 ]; 97 } 98 99 return [ 100 $this->buildName('', ['TYPE' => NameType::TYPE_BIRTH]), 101 ]; 102 } 103 104 /** 105 * What names are given to a new spouse 106 * 107 * @param Individual $spouse 108 * @param string $sex 109 * 110 * @return array<int,string> 111 */ 112 public function newSpouseNames(Individual $spouse, string $sex): array 113 { 114 return [ 115 $this->buildName('', ['TYPE' => NameType::TYPE_BIRTH]), 116 ]; 117 } 118} 119