xref: /webtrees/app/SurnameTradition/MatrilinealSurnameTradition.php (revision cb7a42eae1efabac96d9d7693151fe0421b6717b)
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
22*cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
23*cb7a42eaSGreg Roach
24323788f4SGreg Roach/**
25323788f4SGreg Roach * Children take their mother’s surname.
26323788f4SGreg Roach */
275206405dSRico Sonntagclass MatrilinealSurnameTradition extends DefaultSurnameTradition
28c1010edaSGreg Roach{
29323788f4SGreg Roach    /**
30*cb7a42eaSGreg Roach     * What name is given to a new child
31323788f4SGreg Roach     *
32*cb7a42eaSGreg Roach     * @param Individual|null $father
33*cb7a42eaSGreg Roach     * @param Individual|null $mother
34*cb7a42eaSGreg Roach     * @param string          $sex
35323788f4SGreg Roach     *
36*cb7a42eaSGreg Roach     * @return array<string>
37323788f4SGreg Roach     */
38*cb7a42eaSGreg Roach    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
39c1010edaSGreg Roach    {
40*cb7a42eaSGreg Roach        if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($mother), $match)) {
41*cb7a42eaSGreg Roach            $name = $match['NAME'];
42*cb7a42eaSGreg Roach            $spfx = $match['SPFX'];
43*cb7a42eaSGreg Roach            $surn = $match['SURN'];
44b2ce94c6SRico Sonntag
4513abd6f3SGreg Roach            return [
46*cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'birth', 'SPFX' => $spfx, 'SURN' => $surn]),
4713abd6f3SGreg Roach            ];
48323788f4SGreg Roach        }
49323788f4SGreg Roach
50*cb7a42eaSGreg Roach        return parent::newChildNames($father, $mother, $sex);
51*cb7a42eaSGreg Roach    }
52*cb7a42eaSGreg Roach
53323788f4SGreg Roach    /**
54*cb7a42eaSGreg Roach     * What name is given to a new parent
55323788f4SGreg Roach     *
56*cb7a42eaSGreg Roach     * @param Individual $child
57*cb7a42eaSGreg Roach     * @param string                           $sex
58323788f4SGreg Roach     *
59*cb7a42eaSGreg Roach     * @return array<string>
60323788f4SGreg Roach     */
61*cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
62c1010edaSGreg Roach    {
63*cb7a42eaSGreg Roach        if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match)) {
64*cb7a42eaSGreg Roach            $name = $match['NAME'];
65*cb7a42eaSGreg Roach            $spfx = $match['SPFX'];
66*cb7a42eaSGreg Roach            $surn = $match['SURN'];
67b2ce94c6SRico Sonntag
6813abd6f3SGreg Roach            return [
69*cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'birth', 'SPFX' => $spfx, 'SURN' => $surn]),
7013abd6f3SGreg Roach            ];
71323788f4SGreg Roach        }
72*cb7a42eaSGreg Roach
73*cb7a42eaSGreg Roach        return parent::newParentNames($child, $sex);
74*cb7a42eaSGreg Roach    }
75323788f4SGreg Roach}
76