Passed
Pull Request — main (#5150)
by Greg
07:28
created

LanguageGerman::relationships()   B

Complexity

Conditions 5
Paths 1

Size

Total Lines 156
Code Lines 122

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 122
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 156
rs 7.6888

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
3
/**
4
 * webtrees: online genealogy
5
 * Copyright (C) 2025 webtrees development team
6
 * This program is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
 * GNU General Public License for more details.
14
 * You should have received a copy of the GNU General Public License
15
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16
 */
17
18
declare(strict_types=1);
19
20
namespace Fisharebest\Webtrees\Module;
21
22
use Fisharebest\Localization\Locale\LocaleDe;
23
use Fisharebest\Localization\Locale\LocaleInterface;
24
use Fisharebest\Webtrees\Relationship;
0 ignored issues
show
Bug introduced by
The type Fisharebest\Webtrees\Relationship was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
25
use Fisharebest\Webtrees\Encodings\UTF8;
0 ignored issues
show
Bug introduced by
The type Fisharebest\Webtrees\Encodings\UTF8 was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
26
// use Illuminate\Database\Query\Builder;
27
28
/**
29
 * Class LanguageGerman.
30
 */
31
class LanguageGerman extends AbstractModule implements ModuleLanguageInterface
32
{
33
    use ModuleLanguageTrait;
0 ignored issues
show
Bug introduced by
The type Fisharebest\Webtrees\Module\ModuleLanguageTrait was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
34
35
    /**
36
     * @return LocaleInterface
37
     */
38
    public function locale(): LocaleInterface
39
    {
40
        return new LocaleDe();
41
    }
42
43
    /**
44
     * Letters with diacritics that are considered distinct letters in this language.
45
     *
46
     * @return array<string,string>
47
     */
48
    protected function normalizeExceptions(): array
49
    {
50
        return [
51
            'A' . UTF8::COMBINING_DIAERESIS    => 'AE',
52
            'O' . UTF8::COMBINING_DIAERESIS    => 'OE',
53
            'U' . UTF8::COMBINING_DIAERESIS    => 'UE',
54
            UTF8::LATIN_CAPITAL_LETTER_SHARP_S => 'SS',
55
            'a' . UTF8::COMBINING_DIAERESIS    => 'ae',
56
            'o' . UTF8::COMBINING_DIAERESIS    => 'oe',
57
            'u' . UTF8::COMBINING_DIAERESIS    => 'ue',
58
            UTF8::LATIN_SMALL_LETTER_SHARP_S   => 'ss',
59
        ];
60
    }
61
	public function relationships(): array
62
    {
63
        // returns array => [nominativ, genitive %s] 
64
        // $genitive = static fn (string $prefix, string $suffix): array => [$prefix . $suffix, $prefix . 's' . $suffix . '%s'];
65
        $genitive = static fn (string $prefix, string $suffix, int $gender): array =>			
66
		    ($gender == 0) ? [$prefix . $suffix, '%s' . ' des ' . $prefix . 's' . $suffix] : (($gender == 1) ? [$prefix . $suffix, '%s' . ' der ' . $prefix . $suffix] : [$prefix . $suffix, '%s' . ' der ' . $prefix . $suffix]);
67
		
68
        $ur = static fn (int $n, string $simpleGreat, string $suffix, int $gender): array => $genitive(
69
		    (($n > 1) ?  ($n + 1) . ' x Ur' : (($n > -1) ? 'Ur' . str_repeat('ur', $n) : '')) . $simpleGreat, $suffix, $gender
70
			// $n <= -1 -> ''
71
			// $n == 0 -> Ur 
72
			// $n == 1 -> Urur 
73
			// $n >= 2 -> $n+1 ' x Ur'
74
        );
75
76
        return [
77
            // Adopted
78
            Relationship::fixed('Adoptivmutter', '%s der Adoptivmutter')->adoptive()->mother(),
79
            Relationship::fixed('Adoptivvater', '%s des Adoptivvaters')->adoptive()->father(),
80
            Relationship::fixed('Adoptiveltern', '%s der Adoptiveltern')->adoptive()->parent(),
81
            Relationship::fixed('Adoptivtochter', '%s der Adoptivtochter')->adopted()->daughter(),
82
            Relationship::fixed('Adoptivsohn', '%s des Adoptivsohnes')->adopted()->son(),
83
            Relationship::fixed('Adoptivkind', '%s des Adoptivkindes')->adopted()->child(),
84
            // Fostered
85
            Relationship::fixed('Pflegemutter', '%s der Pflegemutter')->fostering()->mother(),
86
            Relationship::fixed('Pflegevater', '%s des Pflegevaters')->fostering()->father(),
87
            Relationship::fixed('Pflegeeltern', '%s der Pflegeeltern')->fostering()->parent(),
88
            Relationship::fixed('Pflegetochter', '%s der Pflegetochter')->fostered()->daughter(),
89
            Relationship::fixed('Pflegesohn', '%s des Pflegesohnes')->fostered()->son(),
90
            Relationship::fixed('Pflegekind', '%s des Pflegekindes')->fostered()->child(),
91
            // Parents
92
            Relationship::fixed('Mutter', '%s der Mutter')->mother(),
93
            Relationship::fixed('Vater', '%s des Vaters')->father(),
94
            Relationship::fixed('Elternteil', '%s der Eltern')->parent(),
95
            // Children
96
            Relationship::fixed('Tochter', '%s der Tochter')->daughter(),
97
            Relationship::fixed('Sohn', '%s des Sohnes')->son(),
98
            Relationship::fixed('Kind', '%s des Kindes')->child(),
99
            // Siblings
100
            Relationship::fixed('Zwillingsschwester', '%s der Zwillingsschwester')->twin()->sister(),
101
            Relationship::fixed('Zwillingsbruder', '%s des Zwillingsbruders')->twin()->brother(),
102
            Relationship::fixed('Zwillingsgeschwister', '%s des Zwillingsgeschwisters')->twin()->sibling(),
103
            Relationship::fixed('Ältere Schwester', '%s der älterer Schwester')->older()->sister(),
104
            Relationship::fixed('Älterer Bruder', '%s des älteren Bruders')->older()->brother(),
105
            Relationship::fixed('Älteres Geschwister', '%s des älteren Geschwisters')->older()->sibling(),
106
            Relationship::fixed('Jüngere Schwester', '%s der jüngeren Schwester')->younger()->sister(),
107
            Relationship::fixed('Jüngerer Bruder', '%s des jüngeren Bruders')->younger()->brother(),
108
            Relationship::fixed('Jüngeres Geschwister', '%s des jüngeres Geschwisters')->younger()->sibling(),
109
            Relationship::fixed('Schwester', '%s der Schwester')->sister(),
110
            Relationship::fixed('Bruder', '%s des Bruders')->brother(),
111
            Relationship::fixed('Geschwister', '%s der Geschwister')->sibling(),
112
            // Half-siblings
113
            Relationship::fixed('Halbschwester', '%s der Halbschwester')->parent()->daughter(),
114
            Relationship::fixed('Halbbruder', '%s des Halbbruders')->parent()->son(),
115
            Relationship::fixed('Halbgeschwister', '%s der Halbgeschwister')->parent()->child(),
116
            // Stepfamily
117
            Relationship::fixed('Stiefmutter', '%s der Stiefmutter')->parent()->wife(),
118
            Relationship::fixed('Stiefvater', '%s des Stiefvaters')->parent()->husband(),
119
            Relationship::fixed('Stiefelternteil', '%s des Stiefelternteils')->parent()->married()->spouse(),
120
            Relationship::fixed('Stieftochter', '%s der Stieftochter')->married()->spouse()->daughter(),
121
            Relationship::fixed('Stiefsohn', '%s des Stiefsohnes')->married()->spouse()->son(),
122
            Relationship::fixed('Stiefkind', '%s des Stiefkindes')->married()->spouse()->child(),
123
            Relationship::fixed('Stiefschwester', '%s der Stiefschwester')->parent()->spouse()->daughter(),
124
            Relationship::fixed('Stiefbruder', '%s des Stiefbruders')->parent()->spouse()->son(),
125
            Relationship::fixed('Stiefgeschwister', '%s der Stiefgeschwister')->parent()->spouse()->child(),
126
			// Cousin / Cousine
127
            Relationship::fixed('Cousine', '%s der Cousine')->parent()->sister()->child()->female(),
128
            Relationship::fixed('Cousine', '%s der Cousine')->parent()->brother()->child()->female(),
129
            Relationship::fixed('Cousin', '%s des Cousins')->parent()->sister()->child()->male(),
130
            Relationship::fixed('Cousin', '%s des Cousins')->parent()->brother()->child()->male(),
131
            // Partners
132
            Relationship::fixed('Ex-Frau', '%s der Ex-Frau')->divorced()->partner()->female(),
133
            Relationship::fixed('Ex-Mann', '%s des Ex-Mannes')->divorced()->partner()->male(),
134
            Relationship::fixed('Ex-Ehepartner', '%s des Ex-Ehepartners')->divorced()->partner(),
135
            Relationship::fixed('Verlobte', '%s der Verlobten')->engaged()->partner()->female(),
136
            Relationship::fixed('Verlobter', '%s des Verlobten')->engaged()->partner()->male(),
137
            Relationship::fixed('Ehefrau', '%s der Ehefrau')->wife(),
138
            Relationship::fixed('Ehemann', '%s des Ehemannes')->husband(),
139
            Relationship::fixed('Ehepartner', '%s des Ehepartners')->spouse(),
140
            Relationship::fixed('Partner', '%s des Partners')->partner(),
141
            // In-laws
142
            Relationship::fixed('Schwiegermutter', '%s der Schwiegermutter')->married()->spouse()->mother(),
143
            Relationship::fixed('Schwiegervater', '%s des Schwiegervaters')->married()->spouse()->father(),
144
            Relationship::fixed('Schwiegereltern', '%s der Schwiegereltern')->married()->spouse()->parent(),
145
            Relationship::fixed('Schwiegertochter', '%s der Schwiegertochter')->child()->wife(),
146
            Relationship::fixed('Schwiegersohn', '%s des Schwiegersohnes')->child()->husband(),
147
            Relationship::fixed('Schwiegerkind', '%s des Schwiegerkindes')->child()->married()->spouse(),
148
			//
149
            Relationship::fixed('Schwägerin', '%s der Schwägerin')->sibling()->spouse()->sister(),
150
            Relationship::fixed('Schwager', '%s des Schwagers')->sibling()->spouse()->brother(),
151
            Relationship::fixed('Schwager/Schwägerin', '%s des Schwagers / der Schwägerin')->sibling()->spouse()->sibling(),
152
            Relationship::fixed('Schwägerin', '%s der Schwägerin')->spouse()->sister(),
153
            Relationship::fixed('Schwager', '%s des Schwagers')->spouse()->brother(),
154
            Relationship::fixed('Schwager/Schwägerin', '%s des Schwagers / der Schwägerin')->spouse()->sibling(),
155
            Relationship::fixed('Schwägerin', '%s der Schwägerin')->sibling()->wife(),
156
            Relationship::fixed('Schwager', '%s des Schwagers')->sibling()->husband(),
157
            Relationship::fixed('Schwager/Schwägerin', '%s des Schwagers / der Schwägerin')->sibling()->spouse(),
158
            // Grandparents
159
            Relationship::fixed('Großmutter mütterlicherseits', '%s der Großmutter (mütterlicherseits)')->mother()->mother(),
160
            Relationship::fixed('Großvater mütterlicherseits', '%s des Großvaters (mütterlicherseits)')->mother()->father(),
161
            Relationship::fixed('Großeltern mütterlicherseits', '%s der Großeltern (mütterlicherseits)')->mother()->parent(),
162
            Relationship::fixed('Großmutter väterlicherseits', '%s der Großmutter (väterlicherseits)')->father()->mother(),
163
            Relationship::fixed('Großvater väterlicherseits', '%s des Großvaters (väterlicherseits)')->father()->father(),
164
            Relationship::fixed('Großeltern väterlicherseits', '%s der Großeltern (väterlicherseits)')->father()->parent(),
165
			// 
166
            Relationship::fixed('Großmutter', '%s der Großmutter')->parent()->mother(),
167
            Relationship::fixed('Großvater', '%s des Großvaters')->parent()->father(),
168
            Relationship::fixed('Großeltern', '%s der Großeltern')->parent()->parent(),
169
            // Grandchildren
170
            Relationship::fixed('Enkelin', '%s der Enkelin')->child()->daughter(),
171
            Relationship::fixed('Enkel', '%s des Enkels')->child()->son(),
172
            Relationship::fixed('Enkelin/Enkel', '%s der Enkelin/des Enkels')->child()->child(),
173
			// Nichte / Neffe
174
            Relationship::fixed('Nichte', '%s der Nichte')->sibling()->daughter(),
175
            Relationship::fixed('Nichte', '%s der Nichte')->married()->spouse()->sibling()->daughter(),			
176
            Relationship::fixed('Neffe', '%s des Neffen')->sibling()->son(),
177
            Relationship::fixed('Neffe', '%s des Neffen')->married()->spouse()->sibling()->son(),
178
            Relationship::fixed('Nichte/Neffe', '%s der Nichte / des Neffen')->sibling()->child(),
179
            Relationship::fixed('Nichte/Neffe', '%s der Nichte/ des Neffen')->married()->spouse()->sibling()->child(),
180
			// Großnichte / Großneffe
181
            Relationship::fixed('Großnichte', '%s der Großnichte')->sibling()->child()->child()->female(),
182
            Relationship::fixed('Großnichte', '%s der Großnichte')->married()->spouse()->sibling()->child()->child()->female(),
183
            Relationship::fixed('Großneffe', '%s des Großneffen')->sibling()->child()->child()->male(),
184
            Relationship::fixed('Großneffe', '%s des Großneffen')->married()->spouse()->sibling()->child()->child()->male(),
185
			// Tante / Onkel
186
            Relationship::fixed('Tante', '%s der Tante')->parent()->sister(),
187
            Relationship::fixed('Tante', '%s der Tante')->parent()->brother()->wife(),
188
            Relationship::fixed('Onkel', '%s des Onkels')->parent()->sister()->husband(),
189
            Relationship::fixed('Onkel', '%s des Onkels')->parent()->brother(),
190
			// Großtante / Großonkel
191
            Relationship::fixed('Großtante', '%s der Großtante')->parent()->parent()->sister(),
192
            Relationship::fixed('Großtante', '%s der Großtante')->parent()->parent()->brother()->wife(),
193
            Relationship::fixed('Großonkel', '%s des Großonkels')->parent()->parent()->brother(),
194
            Relationship::fixed('Großonkel', '%s des Großonkels')->parent()->parent()->sister()->husband(),
195
            // Relationships with dynamically generated names
196
			// ancestors: n=2 -> Urgroßmutter (mütterlicherseits) / Großmutter der Mutter
197
            Relationship::dynamic(static fn (int $n) => $ur($n - 2, 'großmutter', ' (mütterlicherseits) ', 1))->mother()->ancestor()->female(),
198
            Relationship::dynamic(static fn (int $n) => $ur($n - 2, 'großvater', ' (mütterlicherseits) ', 0))->mother()->ancestor()->male(),
199
            Relationship::dynamic(static fn (int $n) => $ur($n - 2, 'großmutter', ' (väterlicherseits) ', 1))->father()->ancestor()->female(),
200
            Relationship::dynamic(static fn (int $n) => $ur($n - 2, 'großvater', ' (väterlicherseits) ', 0))->father()->ancestor()->male(),
201
			//
202
            Relationship::dynamic(static fn (int $n) => $ur($n - 2, 'großeltern', ' (väterlicherseits) ', 2))->father()->ancestor(),
203
            Relationship::dynamic(static fn (int $n) => $ur($n - 2, 'großeltern', ' (mütterlicherseits) ', 2))->mother()->ancestor(),
204
			//
205
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großtante', ' ', 1))->ancestor()->sister(),
206
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großtante', ' ', 1))->ancestor()->sibling()->wife(),
207
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großonkel', ' ', 0))->ancestor()->brother(),
208
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großonkel', ' ', 0))->ancestor()->sibling()->husband(),
209
			// descendants
210
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großnichte', ' ', 1))->sibling()->descendant()->female(),
211
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großnichte', ' ', 1))->married()->spouse()->sibling()->descendant()->female(),
212
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großneffe', ' ', 0))->sibling()->descendant()->male(),
213
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'großneffe'), ' ', 0)->married()->spouse()->sibling()->descendant()->male(),
214
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'enkelin', ' ', 1))->descendant()->female(),
215
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'enkel', ' ', 0))->descendant()->male(),
216
            Relationship::dynamic(static fn (int $n) => $ur($n - 3, 'enkelin/enkel', ' ', 2))->descendant(),
217
        ];
218
    }
219
}
220