xref: /webtrees/app/SurnameTradition/MatrilinealSurnameTradition.php (revision 1ff45046fabc22237b5d0d8e489c96f031fc598d)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5d11be702SGreg Roach * Copyright (C) 2023 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;
237e128bbfSGreg Roachuse Fisharebest\Webtrees\I18N;
24cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
25cb7a42eaSGreg Roach
26323788f4SGreg Roach/**
27323788f4SGreg Roach * Children take their mother’s surname.
28323788f4SGreg Roach */
295206405dSRico Sonntagclass MatrilinealSurnameTradition extends DefaultSurnameTradition
30c1010edaSGreg Roach{
31323788f4SGreg Roach    /**
327e128bbfSGreg Roach     * The name of this surname tradition
337e128bbfSGreg Roach     *
347e128bbfSGreg Roach     * @return string
357e128bbfSGreg Roach     */
367e128bbfSGreg Roach    public function name(): string
377e128bbfSGreg Roach    {
387e128bbfSGreg Roach        /* I18N: A system where children take their mother’s surname */
397e128bbfSGreg Roach        return I18N::translate('matrilineal');
407e128bbfSGreg Roach    }
417e128bbfSGreg Roach
427e128bbfSGreg Roach    /**
437e128bbfSGreg Roach     * A short description of this surname tradition
447e128bbfSGreg Roach     *
457e128bbfSGreg Roach     * @return string
467e128bbfSGreg Roach     */
477e128bbfSGreg Roach    public function description(): string
487e128bbfSGreg Roach    {
497e128bbfSGreg Roach        /* I18N: In the matrilineal surname tradition, ... */
507e128bbfSGreg Roach        return I18N::translate('Children take their mother’s surname.');
517e128bbfSGreg Roach    }
527e128bbfSGreg Roach
537e128bbfSGreg Roach    /**
54cb7a42eaSGreg Roach     * What name is given to a new child
55323788f4SGreg Roach     *
56cb7a42eaSGreg Roach     * @param Individual|null $father
57cb7a42eaSGreg Roach     * @param Individual|null $mother
58cb7a42eaSGreg Roach     * @param string          $sex
59323788f4SGreg Roach     *
6001ffdfd0SGreg Roach     * @return array<int,string>
61323788f4SGreg Roach     */
62*1ff45046SGreg Roach    public function newChildNames(Individual|null $father, Individual|null $mother, string $sex): array
63c1010edaSGreg Roach    {
64ef475b14SGreg Roach        if (preg_match(self::REGEX_SPFX_SURN, $this->extractName($mother), $match) === 1) {
65cb7a42eaSGreg Roach            $name = $match['NAME'];
66cb7a42eaSGreg Roach            $spfx = $match['SPFX'];
67cb7a42eaSGreg Roach            $surn = $match['SURN'];
68b2ce94c6SRico Sonntag
6913abd6f3SGreg Roach            return [
7088a03560SGreg Roach                $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SPFX' => $spfx, 'SURN' => $surn]),
7113abd6f3SGreg Roach            ];
72323788f4SGreg Roach        }
73323788f4SGreg Roach
74cb7a42eaSGreg Roach        return parent::newChildNames($father, $mother, $sex);
75cb7a42eaSGreg Roach    }
76cb7a42eaSGreg 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    {
87ef475b14SGreg Roach        if ($sex === 'F' && preg_match(self::REGEX_SPFX_SURN, $this->extractName($child), $match) === 1) {
88cb7a42eaSGreg Roach            $name = $match['NAME'];
89cb7a42eaSGreg Roach            $spfx = $match['SPFX'];
90cb7a42eaSGreg Roach            $surn = $match['SURN'];
91b2ce94c6SRico Sonntag
9213abd6f3SGreg Roach            return [
9388a03560SGreg Roach                $this->buildName($name, ['TYPE' => NameType::VALUE_BIRTH, 'SPFX' => $spfx, 'SURN' => $surn]),
9413abd6f3SGreg Roach            ];
95323788f4SGreg Roach        }
96cb7a42eaSGreg Roach
97cb7a42eaSGreg Roach        return parent::newParentNames($child, $sex);
98cb7a42eaSGreg Roach    }
99323788f4SGreg Roach}
100