xref: /webtrees/app/SurnameTradition/PolishSurnameTradition.php (revision 5bfc689774bb9a6401271c4ed15a6d50652c991b)
1323788f4SGreg Roach<?php
23976b470SGreg Roach
3323788f4SGreg Roach/**
4323788f4SGreg Roach * webtrees: online genealogy
5*5bfc6897SGreg Roach * Copyright (C) 2022 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
22cb7a42eaSGreg Roachuse Fisharebest\Webtrees\Individual;
23cb7a42eaSGreg Roach
24323788f4SGreg Roach/**
25323788f4SGreg Roach * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex.
26323788f4SGreg Roach */
275206405dSRico Sonntagclass PolishSurnameTradition extends PaternalSurnameTradition
28c1010edaSGreg Roach{
29e364afe4SGreg Roach    // Inflect a surname for females
30e364afe4SGreg Roach    private const INFLECT_FEMALE = [
31323788f4SGreg Roach        'cki\b'  => 'cka',
32323788f4SGreg Roach        'dzki\b' => 'dzka',
33323788f4SGreg Roach        'ski\b'  => 'ska',
3404a105eeSGreg Roach        'żki\b'  => 'żka',
3513abd6f3SGreg Roach    ];
36323788f4SGreg Roach
37e364afe4SGreg Roach    // Inflect a surname for males
38e364afe4SGreg Roach    private const INFLECT_MALE = [
39323788f4SGreg Roach        'cka\b'  => 'cki',
40323788f4SGreg Roach        'dzka\b' => 'dzki',
41323788f4SGreg Roach        'ska\b'  => 'ski',
4204a105eeSGreg Roach        'żka\b'  => 'żki',
4313abd6f3SGreg Roach    ];
44323788f4SGreg Roach
45323788f4SGreg Roach    /**
46cb7a42eaSGreg Roach     * What name is given to a new child
47323788f4SGreg Roach     *
48cb7a42eaSGreg Roach     * @param Individual|null $father
49cb7a42eaSGreg Roach     * @param Individual|null $mother
50cb7a42eaSGreg Roach     * @param string          $sex
51323788f4SGreg Roach     *
5201ffdfd0SGreg Roach     * @return array<int,string>
53323788f4SGreg Roach     */
54cb7a42eaSGreg Roach    public function newChildNames(?Individual $father, ?Individual $mother, string $sex): array
55c1010edaSGreg Roach    {
56cb7a42eaSGreg Roach        if (preg_match(self::REGEX_SURN, $this->extractName($father), $match)) {
57cb7a42eaSGreg Roach            if ($sex === 'F') {
58cb7a42eaSGreg Roach                $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE);
59cb7a42eaSGreg Roach            } else {
60cb7a42eaSGreg Roach                $name = $this->inflect($match['NAME'], self::INFLECT_MALE);
61b2ce94c6SRico Sonntag            }
62b2ce94c6SRico Sonntag
63cb7a42eaSGreg Roach            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
64cb7a42eaSGreg Roach
65cb7a42eaSGreg Roach            return [$this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn])];
66323788f4SGreg Roach        }
67b2ce94c6SRico Sonntag
68cb7a42eaSGreg Roach        return [$this->buildName('//', ['TYPE' => 'birth'])];
69323788f4SGreg Roach    }
70323788f4SGreg Roach
71323788f4SGreg Roach    /**
72cb7a42eaSGreg Roach     * What name is given to a new parent
73323788f4SGreg Roach     *
74cb7a42eaSGreg Roach     * @param Individual $child
75cb7a42eaSGreg Roach     * @param string     $sex
76323788f4SGreg Roach     *
7701ffdfd0SGreg Roach     * @return array<int,string>
78323788f4SGreg Roach     */
79cb7a42eaSGreg Roach    public function newParentNames(Individual $child, string $sex): array
80c1010edaSGreg Roach    {
81cb7a42eaSGreg Roach        if ($sex === 'M' && preg_match(self::REGEX_SURN, $this->extractName($child), $match)) {
82cb7a42eaSGreg Roach            $name = $this->inflect($match['NAME'], self::INFLECT_MALE);
83cb7a42eaSGreg Roach            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
84b2ce94c6SRico Sonntag
8513abd6f3SGreg Roach            return [
86cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'birth', 'SURN' => $surn]),
8713abd6f3SGreg Roach            ];
88323788f4SGreg Roach        }
89323788f4SGreg Roach
90cb7a42eaSGreg Roach        return [$this->buildName('//', ['TYPE' => 'birth'])];
91cb7a42eaSGreg Roach    }
92cb7a42eaSGreg Roach
93323788f4SGreg Roach    /**
94323788f4SGreg Roach     * What names are given to a new spouse
95323788f4SGreg Roach     *
96cb7a42eaSGreg Roach     * @param Individual $spouse
97cb7a42eaSGreg Roach     * @param string     $sex
98323788f4SGreg Roach     *
9901ffdfd0SGreg Roach     * @return array<int,string>
100323788f4SGreg Roach     */
101cb7a42eaSGreg Roach    public function newSpouseNames(Individual $spouse, string $sex): array
102c1010edaSGreg Roach    {
103cb7a42eaSGreg Roach        if ($sex === 'F' && preg_match(self::REGEX_SURN, $this->extractName($spouse), $match)) {
104cb7a42eaSGreg Roach            $name = $this->inflect($match['NAME'], self::INFLECT_FEMALE);
105cb7a42eaSGreg Roach            $surn = $this->inflect($match['SURN'], self::INFLECT_MALE);
106cb7a42eaSGreg Roach
10713abd6f3SGreg Roach            return [
108cb7a42eaSGreg Roach                $this->buildName('//', ['TYPE' => 'birth']),
109cb7a42eaSGreg Roach                $this->buildName($name, ['TYPE' => 'married', 'SURN' => $surn]),
11013abd6f3SGreg Roach            ];
111b2ce94c6SRico Sonntag        }
112b2ce94c6SRico Sonntag
113cb7a42eaSGreg Roach        return [$this->buildName('//', ['TYPE' => 'birth'])];
114323788f4SGreg Roach    }
115323788f4SGreg Roach}
116