xref: /webtrees/app/SurnameTradition/PortugueseSurnameTradition.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 one surname from the mother and one surname from the father.
26323788f4SGreg Roach *
27323788f4SGreg Roach * Mother: Maria /AAAA/ /BBBB/
28323788f4SGreg Roach * Father: Jose  /CCCC/ /DDDD/
29323788f4SGreg Roach * Child:  Pablo /DDDD/ /BBBB/
30323788f4SGreg Roach */
315206405dSRico Sonntagclass PortugueseSurnameTradition extends DefaultSurnameTradition
32c1010edaSGreg Roach{
33323788f4SGreg Roach    /**
34*cb7a42eaSGreg Roach     * What name is given to a new child
35323788f4SGreg Roach     *
36*cb7a42eaSGreg Roach     * @param Individual|null $father
37*cb7a42eaSGreg Roach     * @param Individual|null $mother
38*cb7a42eaSGreg Roach     * @param string          $sex
39323788f4SGreg Roach     *
40*cb7a42eaSGreg Roach     * @return array<string>
41323788f4SGreg Roach     */
42*cb7a42eaSGreg Roach    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
43c1010edaSGreg Roach    {
44*cb7a42eaSGreg Roach        if (preg_match(self::REGEX_SURNS, $this->extractName($father), $match_father)) {
45323788f4SGreg Roach            $father_surname = $match_father['SURN2'];
46323788f4SGreg Roach        } else {
47323788f4SGreg Roach            $father_surname = '';
48323788f4SGreg Roach        }
49323788f4SGreg Roach
50*cb7a42eaSGreg Roach        if (preg_match(self::REGEX_SURNS, $this->extractName($mother), $match_mother)) {
51323788f4SGreg Roach            $mother_surname = $match_mother['SURN2'];
52323788f4SGreg Roach        } else {
53323788f4SGreg Roach            $mother_surname = '';
54323788f4SGreg Roach        }
55323788f4SGreg Roach
5613abd6f3SGreg Roach        return [
57*cb7a42eaSGreg Roach            $this->buildName('/' . $father_surname . '/ /' . $mother_surname . '/', [
58*cb7a42eaSGreg Roach                'TYPE' => 'birth',
59323788f4SGreg Roach                'SURN' => trim($father_surname . ',' . $mother_surname, ','),
60*cb7a42eaSGreg Roach            ]),
6113abd6f3SGreg Roach        ];
62323788f4SGreg Roach    }
63323788f4SGreg Roach
64323788f4SGreg Roach    /**
65*cb7a42eaSGreg Roach     * What name is given to a new parent
66323788f4SGreg Roach     *
67*cb7a42eaSGreg Roach     * @param Individual $child
68*cb7a42eaSGreg Roach     * @param string     $sex
69323788f4SGreg Roach     *
70*cb7a42eaSGreg Roach     * @return array<string>
71323788f4SGreg Roach     */
72*cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
73c1010edaSGreg Roach    {
74*cb7a42eaSGreg Roach        if (preg_match(self::REGEX_SURNS, $this->extractName($child), $match)) {
75*cb7a42eaSGreg Roach            switch ($sex) {
76323788f4SGreg Roach                case 'M':
7713abd6f3SGreg Roach                    return [
78*cb7a42eaSGreg Roach                        $this->buildName('// /' . $match['SURN1'] . '/', [
79*cb7a42eaSGreg Roach                            'TYPE' => 'birth',
80323788f4SGreg Roach                            'SURN' => $match['SURN1'],
81*cb7a42eaSGreg Roach                        ]),
8213abd6f3SGreg Roach                    ];
83*cb7a42eaSGreg Roach
84323788f4SGreg Roach                case 'F':
8513abd6f3SGreg Roach                    return [
86*cb7a42eaSGreg Roach                        $this->buildName('// /' . $match['SURN2'] . '/', [
87*cb7a42eaSGreg Roach                            'TYPE' => 'birth',
88323788f4SGreg Roach                            'SURN' => $match['SURN2'],
89*cb7a42eaSGreg Roach                        ]),
9013abd6f3SGreg Roach                    ];
91323788f4SGreg Roach            }
92323788f4SGreg Roach        }
93323788f4SGreg Roach
9413abd6f3SGreg Roach        return [
95*cb7a42eaSGreg Roach            $this->buildName('// //', ['TYPE' => 'birth']),
9613abd6f3SGreg Roach        ];
97323788f4SGreg Roach    }
98323788f4SGreg Roach
99323788f4SGreg Roach    /**
100323788f4SGreg Roach     * What names are given to a new spouse
101323788f4SGreg Roach     *
102*cb7a42eaSGreg Roach     * @param Individual $spouse
103*cb7a42eaSGreg Roach     * @param string     $sex
104323788f4SGreg Roach     *
105*cb7a42eaSGreg Roach     * @return array<string>
106323788f4SGreg Roach     */
107*cb7a42eaSGreg Roach    public function newSpouseNames(Individual $spouse, string $sex): array
108c1010edaSGreg Roach    {
10913abd6f3SGreg Roach        return [
110*cb7a42eaSGreg Roach            $this->buildName('// //', ['TYPE' => 'birth']),
11113abd6f3SGreg Roach        ];
112323788f4SGreg Roach    }
113323788f4SGreg Roach}
114