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