xref: /webtrees/app/SurnameTradition/IcelandicSurnameTradition.php (revision a171b6a5f1a6037fc702a697eb572b1932e4c7ef)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
589f7189bSGreg Roach * Copyright (C) 2021 webtrees development team
6323788f4SGreg Roach * This program is free software: you can redistribute it and/or modify
7323788f4SGreg Roach * it under the terms of the GNU General Public License as published by
8323788f4SGreg Roach * the Free Software Foundation, either version 3 of the License, or
9323788f4SGreg Roach * (at your option) any later version.
10323788f4SGreg Roach * This program is distributed in the hope that it will be useful,
11323788f4SGreg Roach * but WITHOUT ANY WARRANTY; without even the implied warranty of
12323788f4SGreg Roach * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13323788f4SGreg Roach * GNU General Public License for more details.
14323788f4SGreg Roach * You should have received a copy of the GNU General Public License
1589f7189bSGreg Roach * along with this program. If not, see <https://www.gnu.org/licenses/>.
16323788f4SGreg Roach */
17fcfa147eSGreg Roach
18e7f56f2aSGreg Roachdeclare(strict_types=1);
19e7f56f2aSGreg Roach
20323788f4SGreg Roachnamespace Fisharebest\Webtrees\SurnameTradition;
21323788f4SGreg Roach
22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
23cb7a42eaSGreg Roach
24323788f4SGreg Roach/**
25323788f4SGreg Roach * Children take a patronym instead of a surname.
26323788f4SGreg Roach *
27323788f4SGreg Roach * Sons get their father’s given name plus “sson”
28323788f4SGreg Roach * Daughters get their father’s given name plus “sdottir”
29323788f4SGreg Roach */
305206405dSRico Sonntagclass IcelandicSurnameTradition extends DefaultSurnameTradition
31c1010edaSGreg Roach{
32323788f4SGreg Roach    /**
33*a171b6a5SGreg Roach     * A default/empty name
34c1ec7145SGreg Roach     *
35*a171b6a5SGreg Roach     * @return string
36c1ec7145SGreg Roach     */
37*a171b6a5SGreg Roach    public function defaultName(): string
38c1010edaSGreg Roach    {
39*a171b6a5SGreg Roach        return '';
40c1ec7145SGreg Roach    }
41c1ec7145SGreg Roach
42c1ec7145SGreg Roach    /**
43cb7a42eaSGreg Roach     * What name is given to a new child
44323788f4SGreg Roach     *
45cb7a42eaSGreg Roach     * @param Individual|null $father
46cb7a42eaSGreg Roach     * @param Individual|null $mother
47cb7a42eaSGreg Roach     * @param string          $sex
48323788f4SGreg Roach     *
4901ffdfd0SGreg Roach     * @return array<int,string>
50323788f4SGreg Roach     */
51cb7a42eaSGreg Roach    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
52c1010edaSGreg Roach    {
53cb7a42eaSGreg Roach        if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match)) {
54cb7a42eaSGreg Roach            switch ($sex) {
55323788f4SGreg Roach                case 'M':
56cb7a42eaSGreg Roach                    $givn = $match['GIVN'] . 'sson';
57cb7a42eaSGreg Roach
5813abd6f3SGreg Roach                    return [
59cb7a42eaSGreg Roach                        $this->buildName($givn, ['TYPE' => 'birth', 'GIVN' => $givn]),
6013abd6f3SGreg Roach                    ];
61cb7a42eaSGreg Roach
62323788f4SGreg Roach                case 'F':
63cb7a42eaSGreg Roach                    $givn = $match['GIVN'] . 'sdottir';
64cb7a42eaSGreg Roach
6513abd6f3SGreg Roach                    return [
66cb7a42eaSGreg Roach                        $this->buildName($givn, ['TYPE' => 'birth', 'GIVN' => $givn]),
6713abd6f3SGreg Roach                    ];
68323788f4SGreg Roach            }
69323788f4SGreg Roach        }
70323788f4SGreg Roach
71cb7a42eaSGreg Roach        return [
72cb7a42eaSGreg Roach            $this->buildName('', ['TYPE' => 'birth']),
73cb7a42eaSGreg Roach        ];
74323788f4SGreg Roach    }
75323788f4SGreg Roach
76323788f4SGreg Roach    /**
77cb7a42eaSGreg Roach     * What name is given to a new parent
78323788f4SGreg Roach     *
79cb7a42eaSGreg Roach     * @param Individual $child
80cb7a42eaSGreg Roach     * @param string     $sex
81323788f4SGreg Roach     *
8201ffdfd0SGreg Roach     * @return array<int,string>
83323788f4SGreg Roach     */
84cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
85c1010edaSGreg Roach    {
86cb7a42eaSGreg Roach        if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match)) {
8713abd6f3SGreg Roach            return [
88cb7a42eaSGreg Roach                $this->buildName($match['GIVN'], ['TYPE' => 'birth', 'GIVN' => $match['GIVN']]),
8913abd6f3SGreg Roach            ];
90323788f4SGreg Roach        }
91b2ce94c6SRico Sonntag
92cb7a42eaSGreg Roach        if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match)) {
93cb7a42eaSGreg Roach            return [
94cb7a42eaSGreg Roach                $this->buildName($match['GIVN'], ['TYPE' => 'birth', 'GIVN' => $match['GIVN']]),
95cb7a42eaSGreg Roach            ];
96cb7a42eaSGreg Roach        }
97cb7a42eaSGreg Roach
98cb7a42eaSGreg Roach        return [
99cb7a42eaSGreg Roach            $this->buildName('', ['TYPE' => 'birth']),
100cb7a42eaSGreg Roach        ];
101323788f4SGreg Roach    }
102323788f4SGreg Roach
103323788f4SGreg Roach    /**
104323788f4SGreg Roach     * What names are given to a new spouse
105323788f4SGreg Roach     *
106cb7a42eaSGreg Roach     * @param Individual $spouse
107cb7a42eaSGreg Roach     * @param string     $sex
108323788f4SGreg Roach     *
10901ffdfd0SGreg Roach     * @return array<int,string>
110323788f4SGreg Roach     */
111cb7a42eaSGreg Roach    public function newSpouseNames(Individual $spouse, string $sex): array
112c1010edaSGreg Roach    {
113cb7a42eaSGreg Roach        return [
114cb7a42eaSGreg Roach            $this->buildName('', ['TYPE' => 'birth']),
115cb7a42eaSGreg Roach        ];
116323788f4SGreg Roach    }
117323788f4SGreg Roach}
118