xref: /webtrees/app/SurnameTradition/IcelandicSurnameTradition.php (revision 67994fb087e1b24564a780e4ae8aeff801733e35)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2018 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 a patronym instead of a surname.
22 *
23 * Sons get their father’s given name plus “sson”
24 * Daughters get their father’s given name plus “sdottir”
25 */
26class IcelandicSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface
27{
28    /**
29     * Does this surname tradition use surnames?
30     *
31     * @return bool
32     */
33    public function hasSurnames(): bool
34    {
35        return false;
36    }
37
38    /**
39     * What names are given to a new child
40     *
41     * @param string $father_name A GEDCOM NAME
42     * @param string $mother_name A GEDCOM NAME
43     * @param string $child_sex   M, F or U
44     *
45     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
46     */
47    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
48    {
49        if (preg_match(self::REGEX_GIVN, $father_name, $father_match)) {
50            switch ($child_sex) {
51                case 'M':
52                    return [
53                        'NAME' => $father_match['GIVN'] . 'sson',
54                    ];
55                case 'F':
56                    return [
57                        'NAME' => $father_match['GIVN'] . 'sdottir',
58                    ];
59            }
60        }
61
62        return [];
63    }
64
65    /**
66     * What names are given to a new parent
67     *
68     * @param string $child_name A GEDCOM NAME
69     * @param string $parent_sex M, F or U
70     *
71     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
72     */
73    public function newParentNames(string $child_name, string $parent_sex): array
74    {
75        if ($parent_sex === 'M' && preg_match('~(?<GIVN>[^ /]+)(:?sson|sdottir)$~', $child_name, $child_match)) {
76            return [
77                'NAME' => $child_match['GIVN'],
78                'GIVN' => $child_match['GIVN'],
79            ];
80        }
81
82        return [];
83    }
84
85    /**
86     * What names are given to a new spouse
87     *
88     * @param string $spouse_name A GEDCOM NAME
89     * @param string $spouse_sex  M, F or U
90     *
91     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
92     */
93    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
94    {
95        return [];
96    }
97}
98