xref: /webtrees/app/SurnameTradition/IcelandicSurnameTradition.php (revision 88a035604b5083c54cbfbe51294b65fe8cf9a5ed)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
55bfc6897SGreg Roach * Copyright (C) 2022 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
227c29ac65SGreg Roachuse Fisharebest\Webtrees\Elements\NameType;
23cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
24cb7a42eaSGreg Roach
25323788f4SGreg Roach/**
26323788f4SGreg Roach * Children take a patronym instead of a surname.
27323788f4SGreg Roach *
28323788f4SGreg Roach * Sons get their father’s given name plus “sson”
29323788f4SGreg Roach * Daughters get their father’s given name plus “sdottir”
30323788f4SGreg Roach */
315206405dSRico Sonntagclass IcelandicSurnameTradition extends DefaultSurnameTradition
32c1010edaSGreg Roach{
33323788f4SGreg Roach    /**
34a171b6a5SGreg Roach     * A default/empty name
35c1ec7145SGreg Roach     *
36a171b6a5SGreg Roach     * @return string
37c1ec7145SGreg Roach     */
38a171b6a5SGreg Roach    public function defaultName(): string
39c1010edaSGreg Roach    {
40a171b6a5SGreg Roach        return '';
41c1ec7145SGreg Roach    }
42c1ec7145SGreg Roach
43c1ec7145SGreg Roach    /**
44cb7a42eaSGreg Roach     * What name is given to a new child
45323788f4SGreg Roach     *
46cb7a42eaSGreg Roach     * @param Individual|null $father
47cb7a42eaSGreg Roach     * @param Individual|null $mother
48cb7a42eaSGreg Roach     * @param string          $sex
49323788f4SGreg Roach     *
5001ffdfd0SGreg Roach     * @return array<int,string>
51323788f4SGreg Roach     */
52cb7a42eaSGreg Roach    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
53c1010edaSGreg Roach    {
54cb7a42eaSGreg Roach        if (preg_match(self::REGEX_GIVN, $this->extractName($father), $match)) {
55cb7a42eaSGreg Roach            switch ($sex) {
56323788f4SGreg Roach                case 'M':
57cb7a42eaSGreg Roach                    $givn = $match['GIVN'] . 'sson';
58cb7a42eaSGreg Roach
5913abd6f3SGreg Roach                    return [
60*88a03560SGreg Roach                        $this->buildName($givn, ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $givn]),
6113abd6f3SGreg Roach                    ];
62cb7a42eaSGreg Roach
63323788f4SGreg Roach                case 'F':
64cb7a42eaSGreg Roach                    $givn = $match['GIVN'] . 'sdottir';
65cb7a42eaSGreg Roach
6613abd6f3SGreg Roach                    return [
67*88a03560SGreg Roach                        $this->buildName($givn, ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $givn]),
6813abd6f3SGreg Roach                    ];
69323788f4SGreg Roach            }
70323788f4SGreg Roach        }
71323788f4SGreg Roach
72cb7a42eaSGreg Roach        return [
73*88a03560SGreg Roach            $this->buildName('', ['TYPE' => NameType::VALUE_BIRTH]),
74cb7a42eaSGreg Roach        ];
75323788f4SGreg Roach    }
76323788f4SGreg Roach
77323788f4SGreg Roach    /**
78cb7a42eaSGreg Roach     * What name is given to a new parent
79323788f4SGreg Roach     *
80cb7a42eaSGreg Roach     * @param Individual $child
81cb7a42eaSGreg Roach     * @param string     $sex
82323788f4SGreg Roach     *
8301ffdfd0SGreg Roach     * @return array<int,string>
84323788f4SGreg Roach     */
85cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
86c1010edaSGreg Roach    {
87cb7a42eaSGreg Roach        if ($sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson)$~', $this->extractName($child), $match)) {
8813abd6f3SGreg Roach            return [
89*88a03560SGreg Roach                $this->buildName($match['GIVN'], ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $match['GIVN']]),
9013abd6f3SGreg Roach            ];
91323788f4SGreg Roach        }
92b2ce94c6SRico Sonntag
93cb7a42eaSGreg Roach        if ($sex === 'F' && preg_match('~(?<GIVN>[^ /]+)(:?sdottir)$~', $this->extractName($child), $match)) {
94cb7a42eaSGreg Roach            return [
95*88a03560SGreg Roach                $this->buildName($match['GIVN'], ['TYPE' => NameType::VALUE_BIRTH, 'GIVN' => $match['GIVN']]),
96cb7a42eaSGreg Roach            ];
97cb7a42eaSGreg Roach        }
98cb7a42eaSGreg Roach
99cb7a42eaSGreg Roach        return [
100*88a03560SGreg Roach            $this->buildName('', ['TYPE' => NameType::VALUE_BIRTH]),
101cb7a42eaSGreg Roach        ];
102323788f4SGreg Roach    }
103323788f4SGreg Roach
104323788f4SGreg Roach    /**
105323788f4SGreg Roach     * What names are given to a new spouse
106323788f4SGreg Roach     *
107cb7a42eaSGreg Roach     * @param Individual $spouse
108cb7a42eaSGreg Roach     * @param string     $sex
109323788f4SGreg Roach     *
11001ffdfd0SGreg Roach     * @return array<int,string>
111323788f4SGreg Roach     */
112cb7a42eaSGreg Roach    public function newSpouseNames(Individual $spouse, string $sex): array
113c1010edaSGreg Roach    {
114cb7a42eaSGreg Roach        return [
115*88a03560SGreg Roach            $this->buildName('', ['TYPE' => NameType::VALUE_BIRTH]),
116cb7a42eaSGreg Roach        ];
117323788f4SGreg Roach    }
118323788f4SGreg Roach}
119