xref: /webtrees/app/SurnameTradition/MatrilinealSurnameTradition.php (revision c1010eda29c0909ed4d5d463f32d32bfefdd4dfe)
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 their mother’s surname.
20 */
21class MatrilinealSurnameTradition extends DefaultSurnameTradition implements SurnameTraditionInterface
22{
23    /**
24     * What names are given to a new child
25     *
26     * @param string $father_name A GEDCOM NAME
27     * @param string $mother_name A GEDCOM NAME
28     * @param string $child_sex   M, F or U
29     *
30     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
31     */
32    public function newChildNames($father_name, $mother_name, $child_sex)
33    {
34        if (preg_match(self::REGEX_SPFX_SURN, $mother_name, $match)) {
35            return array_filter([
36                'NAME' => $match['NAME'],
37                'SPFX' => $match['SPFX'],
38                'SURN' => $match['SURN'],
39            ]);
40        } else {
41            return [
42                'NAME' => '//',
43            ];
44        }
45    }
46
47    /**
48     * What names are given to a new parent
49     *
50     * @param string $child_name A GEDCOM NAME
51     * @param string $parent_sex M, F or U
52     *
53     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
54     */
55    public function newParentNames($child_name, $parent_sex)
56    {
57        if ($parent_sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $child_name, $match)) {
58            return array_filter([
59                'NAME' => $match['NAME'],
60                'SPFX' => $match['SPFX'],
61                'SURN' => $match['SURN'],
62            ]);
63        } else {
64            return [
65                'NAME' => '//',
66            ];
67        }
68    }
69}
70