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