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