xref: /webtrees/app/SurnameTradition/PolishSurnameTradition.php (revision 389266c09abfff6214aea2ef212036f49977020e)
1<?php
2/**
3 * webtrees: online genealogy
4 * Copyright (C) 2019 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 */
16declare(strict_types=1);
17
18namespace Fisharebest\Webtrees\SurnameTradition;
19
20/**
21 * Children take their father’s surname. Wives take their husband’s surname. Surnames are inflected to indicate an individual’s sex.
22 */
23class PolishSurnameTradition extends PaternalSurnameTradition implements SurnameTraditionInterface
24{
25    /** @var string[] Inflect a surname for females */
26    protected $inflect_female = [
27        'cki\b'  => 'cka',
28        'dzki\b' => 'dzka',
29        'ski\b'  => 'ska',
30        'żki\b'  => 'żka',
31    ];
32
33    /** @var string[] Inflect a surname for males */
34    protected $inflect_male = [
35        'cka\b'  => 'cki',
36        'dzka\b' => 'dzki',
37        'ska\b'  => 'ski',
38        'żka\b'  => 'żki',
39    ];
40
41    /**
42     * What names are given to a new child
43     *
44     * @param string $father_name A GEDCOM NAME
45     * @param string $mother_name A GEDCOM NAME
46     * @param string $child_sex   M, F or U
47     *
48     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
49     */
50    public function newChildNames(string $father_name, string $mother_name, string $child_sex): array
51    {
52        if (preg_match(self::REGEX_SURN, $father_name, $match)) {
53            if ($child_sex === 'F') {
54                return array_filter([
55                    'NAME' => $this->inflect($match['NAME'], $this->inflect_female),
56                    'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
57                ]);
58            }
59
60            return array_filter([
61                'NAME' => $this->inflect($match['NAME'], $this->inflect_male),
62                'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
63            ]);
64        }
65
66        return [
67            'NAME' => '//',
68        ];
69    }
70
71    /**
72     * What names are given to a new parent
73     *
74     * @param string $child_name A GEDCOM NAME
75     * @param string $parent_sex M, F or U
76     *
77     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
78     */
79    public function newParentNames(string $child_name, string $parent_sex): array
80    {
81        if ($parent_sex === 'M' && preg_match(self::REGEX_SURN, $child_name, $match)) {
82            return array_filter([
83                'NAME' => $this->inflect($match['NAME'], $this->inflect_male),
84                'SURN' => $this->inflect($match['SURN'], $this->inflect_male),
85            ]);
86        }
87
88        return [
89            'NAME' => '//',
90        ];
91    }
92
93    /**
94     * What names are given to a new spouse
95     *
96     * @param string $spouse_name A GEDCOM NAME
97     * @param string $spouse_sex  M, F or U
98     *
99     * @return string[] Associative array of GEDCOM name parts (SURN, _MARNM, etc.)
100     */
101    public function newSpouseNames(string $spouse_name, string $spouse_sex): array
102    {
103        if ($spouse_sex === 'F' && preg_match(self::REGEX_SURN, $spouse_name, $match)) {
104            return [
105                'NAME'   => '//',
106                '_MARNM' => $this->inflect($match['NAME'], $this->inflect_female),
107            ];
108        }
109
110        return [
111            'NAME' => '//',
112        ];
113    }
114}
115