Completed
Push — develop ( 2ca406...b33d79 )
by Greg
27:09 queued 11:25
created

LanguageSlovakian::relationships()   B

Complexity

Conditions 3
Paths 1

Size

Total Lines 99
Code Lines 73

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 73
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 99
rs 8.589

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) 2021 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\LocaleInterface;
23
use Fisharebest\Localization\Locale\LocaleSk;
24
use Fisharebest\Webtrees\Relationship;
25
26
use function str_repeat;
27
28
/**
29
 * Class LanguageSlovakian.
30
 */
31
class LanguageSlovakian extends AbstractModule implements ModuleLanguageInterface
32
{
33
    use ModuleLanguageTrait;
34
35
    protected const MALE_COUSINS = [
36
        ['', ''],
37
        ['bratranec', '%s bratranca'],
38
        ['druhostupňový bratranec', '%s druhostupňový bratranca'],
39
        ['bratranec z 3. kolena', '%s bratranca z 3. kolena'],
40
        ['bratranec zo 4. kolena', '%s bratranca zo 4. kolena'],
41
        ['bratranec z 5. kolena', '%s bratranca z 5. kolena'],
42
        ['bratranec zo 6. kolena', '%s bratranca zo 6. kolena'],
43
        ['bratranec zo 7. kolena', '%s bratranca zo 7. kolena'],
44
        ['bratranec z 8. kolena', '%s bratranca z 8. kolena'],
45
        ['bratranec z 9. kolena', '%s bratranca z 9. kolena'],
46
        ['bratranec z 10. kolena', '%s bratranca z 10. kolena'],
47
        ['bratranec z 11. kolena', '%s bratranca z 11. kolena'],
48
        ['bratranec z 12. kolena', '%s bratranca z 12. kolena'],
49
        ['bratranec z 13. kolena', '%s bratranca z 13. kolena'],
50
        ['bratranec zo 14. kolena', '%s bratranca zo 14. kolena'],
51
        ['bratranec z 15. kolena', '%s bratranca z 15. kolena'],
52
        ['bratranec zo 16. kolena', '%s bratranca zo 16. kolena'],
53
        ['bratranec zo 17. kolena', '%s bratranca zo 17. kolena'],
54
    ];
55
56
    protected const FEMALE_COUSINS = [
57
        ['', ''],
58
        ['sesternica', '%s sesternice'],
59
        ['druhostupňový sesternica', '%s druhostupňový sesternice'],
60
        ['sesternica z 3. kolena', '%s sesternice z 3. kolena'],
61
        ['sesternica zo 4. kolena', '%s sesternice zo 4. kolena'],
62
        ['sesternica z 5. kolena', '%s sesternice z 5. kolena'],
63
        ['sesternica zo 6. kolena', '%s sesternice zo 6. kolena'],
64
        ['sesternica zo 7. kolena', '%s sesternice zo 7. kolena'],
65
        ['sesternica z 8. kolena', '%s sesternice z 8. kolena'],
66
        ['sesternica z 9. kolena', '%s sesternice z 9. kolena'],
67
        ['sesternica z 10. kolena', '%s sesternice z 10. kolena'],
68
        ['sesternica z 11. kolena', '%s sesternice z 11. kolena'],
69
        ['sesternica z 12. kolena', '%s sesternice z 12. kolena'],
70
        ['sesternica z 13. kolena', '%s sesternice z 13. kolena'],
71
        ['sesternica zo 14. kolena', '%s sesternice zo 14. kolena'],
72
        ['sesternica z 15. kolena', '%s sesternice z 15. kolena'],
73
        ['sesternica zo 16. kolena', '%s sesternice zo 16. kolena'],
74
        ['sesternica zo 17. kolena', '%s sesternice zo 17. kolena'],
75
    ];
76
77
    /**
78
     * @return LocaleInterface
79
     */
80
    public function locale(): LocaleInterface
81
    {
82
        return new LocaleSk();
83
    }
84
    /**
85
     * @return array<Relationship>
86
     */
87
    public function relationships(): array
88
    {
89
        $pra = fn (int $n, string $nominative, string $genitive): array => [
90
            ($n > 3 ? 'pra ×' . $n . ' ' : str_repeat('pra-', $n)) . $nominative,
91
            ($n > 3 ? 'pra ×' . $n . ' ' : str_repeat('pra-', $n)) . $genitive,
92
        ];
93
94
        $cousin = fn (int $n, array $cousins, string $nominative, string $genitive): array => $cousins[$n] ?? [
95
            $nominative . ' z ' . $n . '. kolena',
96
            $genitive . '%s z ' . $n . '. kolena',
97
        ];
98
99
        return [
100
            // Parents
101
            Relationship::fixed('otec', '%s otca')->father(),
102
            Relationship::fixed('matka', '%s matky')->mother(),
103
            Relationship::fixed('rodič', '%s rodiča')->parent(),
104
            // Children
105
            Relationship::fixed('syn', '%s syna')->son(),
106
            Relationship::fixed('dcéra', '%s dcéry')->daughter(),
107
            Relationship::fixed('dcéra', '%s dcéry')->child(),
108
            // Siblings
109
            Relationship::fixed('brat', '%s brata')->brother(),
110
            Relationship::fixed('sestra', '%s sestry')->sister(),
111
            Relationship::fixed('súrodenec', '%s súrodenca')->sibling(),
112
            // Divorced partners
113
            Relationship::fixed('exmanželka', '%s exmanželka')->divorced()->partner()->female(),
114
            Relationship::fixed('exmanžel', '%s exmanžela')->divorced()->partner()->male(),
115
            Relationship::fixed('exmanžel/manželka', '%s exmanžel/manželka')->divorced()->partner(),
116
            // Engaged partners
117
            Relationship::fixed('snúbenec', '%s snúbenec')->engaged()->partner()->female(),
118
            Relationship::fixed('snúbenica', '%s snúbenica')->engaged()->partner()->male(),
119
            // Married parters
120
            Relationship::fixed('manželka', '%s manželky')->wife(),
121
            Relationship::fixed('manžel', '%s manžela')->husband(),
122
            Relationship::fixed('manžel/manželka', '%s manžel/manželka')->spouse(),
123
            Relationship::fixed('partnerka', '%s partnerky')->partner()->female(),
124
            // Unmarried partners
125
            Relationship::fixed('partner', '%s partnera')->partner(),
126
            // In-laws
127
            Relationship::fixed('tesť', '%s tesťa')->wife()->father(),
128
            Relationship::fixed('testiná', '%s testinej')->wife()->mother(),
129
            Relationship::fixed('svokor', '%s svokra')->spouse()->father(),
130
            Relationship::fixed('svokora', '%s svokry')->spouse()->mother(),
131
            Relationship::fixed('zať', '%s zaťa')->child()->husband(),
132
            Relationship::fixed('nevesta', '%s nevesty')->child()->wife(),
133
            Relationship::fixed('švagor', '%s švagra')->spouse()->brother(),
134
            Relationship::fixed('švagor', '%s švagra')->sibling()->husband(),
135
            Relationship::fixed('švagriná', '%s švagrinej')->spouse()->sister(),
136
            Relationship::fixed('švagriná', '%s švagrinej')->sibling()->wife(),
137
            // Half-siblings
138
            Relationship::fixed('nevlastný brat', '%s nevlastného brata')->parent()->son(),
139
            Relationship::fixed('nevlastná sestra', '%s nevlastnej sestry')->parent()->daughter(),
140
            Relationship::fixed('nevlastná súrodenec', '%s nevlastnej súrodenca')->parent()->child(),
141
            // Grandparents
142
            Relationship::fixed('starý otec', '%s starého otca')->parent()->father(),
143
            Relationship::fixed('stará matka', '%s starej matky')->parent()->mother(),
144
            Relationship::fixed('starý rodič', '%s starého rodiča')->parent()->parent(),
145
            // Great-grandparents
146
            Relationship::fixed('prastarý otec', '%s prastarého otca')->parent()->parent()->father(),
147
            Relationship::fixed('prastarý otec', '%s prastarého otca')->parent()->parent()->mother(),
148
            Relationship::fixed('prastarý otec', '%s prastarého otca')->parent()->parent()->parent(),
149
            // Ancestors
150
            Relationship::dynamic(fn (int $n) => $pra($n - 1, 'prastarý otec', '%s prastarého otca'))->ancestor()->male(),
151
            Relationship::dynamic(fn (int $n) => $pra($n - 1, 'prastará matka', '%s prastarej matky'))->ancestor()->female(),
152
            Relationship::dynamic(fn (int $n) => $pra($n - 1, 'prastarý rodič', '%s prastarého rodiča'))->ancestor(),
153
            // Grandchildren
154
            Relationship::fixed('vnuk', '%s vnuka')->child()->son(),
155
            Relationship::fixed('vnučka', '%s vnučky')->child()->daughter(),
156
            Relationship::fixed('vnúča', '%s vnúčaťa')->child()->child(),
157
            // Great-grandchildren
158
            Relationship::fixed('pravnuk', '%s pravnuka')->child()->child()->son(),
159
            Relationship::fixed('pravnučka', '%s pravnučky')->child()->child()->daughter(),
160
            Relationship::fixed('pravnúča', '%s pravnúčaťa')->child()->child()->child(),
161
            // Descendants
162
            Relationship::dynamic(fn (int $n) => $pra($n - 1, 'pravnuk', '%s pravnuka'))->ancestor()->male(),
163
            Relationship::dynamic(fn (int $n) => $pra($n - 1, 'pravnučka', '%s prastarej matky'))->ancestor()->female(),
164
            Relationship::dynamic(fn (int $n) => $pra($n - 1, 'pravnúča', '%s pravnúčaťa'))->ancestor(),
165
            // Aunts and uncles
166
            Relationship::fixed('ujo', '%s uja')->mother()->brother(),
167
            Relationship::fixed('ujčiná', '%s ujčinej')->mother()->brother()->wife(),
168
            Relationship::fixed('stryná', '%s strynej')->father()->brother()->wife(),
169
            Relationship::fixed('strýko', '%s strýka')->parent()->brother(),
170
            Relationship::fixed('teta', '%s tety')->parent()->sister(),
171
            // Great-aunts and great-uncles
172
            Relationship::dynamic(fn (int $n) => $pra($n - 2, 'prastrýko', '%s prastrýka'))->ancestor()->brother(),
173
            Relationship::dynamic(fn (int $n) => $pra($n - 2, 'prateta', '%s pratety'))->ancestor()->sister(),
174
            // Nieces and nephews
175
            Relationship::fixed('neter', '%s netere')->sibling()->son(),
176
            Relationship::fixed('synovec', '%s synovca')->sibling()->daughter(),
177
            // Great-nieces and great-nephews
178
            Relationship::fixed('prasynovec', '%s prasynovca')->sibling()->child()->son(),
179
            Relationship::fixed('praneter', '%s pranetere')->sibling()->child()->daughter(),
180
            Relationship::dynamic(fn (int $n) => $pra($n - 2, 'prasynovec', '%s prasynovca'))->sibling()->descendant()->son(),
181
            Relationship::dynamic(fn (int $n) => $pra($n - 2, 'praneter', '%s pranetere'))->sibling()->descendant()->daughter(),
182
            // Cousins
183
            Relationship::dynamic(fn (int $n): array => $cousin($n, static::FEMALE_COUSINS, '', ''))->symmetricCousin()->female(),
184
            Relationship::dynamic(fn (int $n): array => $cousin($n, static::MALE_COUSINS, '', ''))->symmetricCousin()->male(),
185
            Relationship::dynamic(fn (int $n): array => $cousin($n, static::MALE_COUSINS, '', ''))->symmetricCousin(),
186
        ];
187
    }
188
}
189