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 their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex. 27 */ 28class PolishSurnameTradition extends PaternalSurnameTradition 29{ 30 // Inflect a surname for females 31 private const INFLECT_FEMALE = [ 32 'cki\b' => 'cka', 33 'dzki\b' => 'dzka', 34 'ski\b' => 'ska', 35 'żki\b' => 'żka', 36 ]; 37 38 // Inflect a surname for males 39 private const INFLECT_MALE = [ 40 'cka\b' => 'cki', 41 'dzka\b' => 'dzki', 42 'ska\b' => 'ski', 43 'żka\b' => 'żki', 44 ]; 45 46 /** 47 * What name is given to a new child 48 * 49 * @param Individual|null $father 50 * @param Individual|null $mother 51 * @param string $sex 52 * 53 * @return array<int,string> 54 */ 55 public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array 56 { 57 if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) { 58 if ($sex === 'F') { 59 $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 60 } else { 61 $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 62 } 63 64 $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 65 66 return [$this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn])]; 67 } 68 69 return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 70 } 71 72 /** 73 * What name is given to a new parent 74 * 75 * @param Individual $child 76 * @param string $sex 77 * 78 * @return array<int,string> 79 */ 80 public function newParentNames(Individual $child, string $sex): array 81 { 82 if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) { 83 $name = $this->inflect($match['NAME'], self::INFLECT_MALE); 84 $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 85 86 return [ 87 $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SURN' => $surn]), 88 ]; 89 } 90 91 return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 92 } 93 94 /** 95 * What names are given to a new spouse 96 * 97 * @param Individual $spouse 98 * @param string $sex 99 * 100 * @return array<int,string> 101 */ 102 public function newSpouseNames(Individual $spouse, string $sex): array 103 { 104 if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) { 105 $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE); 106 $surn = $this->inflect($match['SURN'], self::INFLECT_MALE); 107 108 return [ 109 $this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH]), 110 $this->buildName($name, ['TYPE' => NameType::VALUE_MARRIED, 'SURN' => $surn]), 111 ]; 112 } 113 114 return [$this->buildName('//', ['TYPE' => NameType::VALUE_BIRTH])]; 115 } 116} 117