Conditions | 12 |
Paths | 1 |
Total Lines | 135 |
Code Lines | 109 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
67 | public function relationships(): array |
||
68 | { |
||
69 | $genitive = fn (string $s, string $genitive_link): array => [$s, '%s ' . $genitive_link . $s]; |
||
70 | |||
71 | $great = fn (int $n, string $suffix, string $genitive_link): array => $genitive( |
||
72 | ($n > 2 ? 'arrière-(x' . $n . ')-' : str_repeat('arrière-', max($n, 0))) . $suffix, |
||
73 | $n === 0 ? $genitive_link : 'de l’' |
||
74 | ); |
||
75 | |||
76 | $compoundgreat = |
||
77 | fn (int $n, string $first_level, string $suffix, string $genitive_none, string $genitive_first): array => |
||
78 | $great($n - 1, ($n > 0 ? $first_level : '' ) . $suffix, $n === 0 ? $genitive_none : $genitive_first); |
||
79 | |||
80 | $symmetricCousin = fn(int $n, string $sex): array => self::SYMMETRIC_COUSINS[$n][$sex] ?? $genitive( |
||
81 | $sex === 'F' ? 'cousine au ' . $n . '<sup>e</sup> degré' : 'cousin au ' . $n . '<sup>e</sup> degré', |
||
82 | $sex === 'F' ? 'de la ' : 'du ' |
||
83 | ); |
||
84 | |||
85 | $asymmetricCousin = |
||
86 | function (int $up, int $down, string $sex) use ($symmetricCousin, $compoundgreat, $genitive): array { |
||
87 | if ($up === $down) { |
||
88 | return $symmetricCousin($up, $sex); |
||
89 | } |
||
90 | $fixed = self::ASYMMETRIC_COUSINS[$up][$sex] ?? self::ASYMMETRIC_COUSINS[-$down][$sex] ?? null; |
||
91 | if ($fixed !== null) { |
||
92 | $fixed[0] = $fixed[0] === 'up' ? $up - 1 : $down - 1; |
||
93 | return $compoundgreat(...$fixed); |
||
94 | } |
||
95 | return $genitive( |
||
96 | $sex === 'F' ? |
||
97 | 'cousine du ' . $down . '<sup>e</sup> au ' . $up . '<sup>e</sup> degré' : |
||
98 | 'cousin du ' . $down . '<sup>e</sup> au ' . $up . '<sup>e</sup> degré', |
||
99 | $sex === 'F' ? 'de la ' : 'du ' |
||
100 | ); |
||
101 | }; |
||
102 | |||
103 | return [ |
||
104 | // Adopted |
||
105 | Relationship::fixed('mère adoptive', '%s de la mère adoptive')->adoptive()->mother(), |
||
106 | Relationship::fixed('père adoptif', '%s du père adoptif')->adoptive()->father(), |
||
107 | Relationship::fixed('parent adoptif', '%s du parent adoptif')->adoptive()->parent(), |
||
108 | Relationship::fixed('fille adoptive', '%s de la fille adoptive')->adopted()->daughter(), |
||
109 | Relationship::fixed('fils adoptif', '%s du fils adoptif')->adopted()->son(), |
||
110 | Relationship::fixed('enfant adoptif', '%s de l’enfant adoptif')->adopted()->child(), |
||
111 | // Fostered |
||
112 | Relationship::fixed('mère d’accueil', '%s de la mère d’acceuil')->fostering()->mother(), |
||
113 | Relationship::fixed('père d’accueil', '%s du père d’acceuil')->fostering()->father(), |
||
114 | Relationship::fixed('parent d’accueil', '%s du parent d’acceuil')->fostering()->parent(), |
||
115 | Relationship::fixed('fille accueillie', '%s de la fille accueillie')->fostered()->daughter(), |
||
116 | Relationship::fixed('fils accueilli', '%s du fils accueilli')->fostered()->son(), |
||
117 | Relationship::fixed('enfant accueilli', '%s de l’enfant accueilli')->fostered()->child(), |
||
118 | // Parents |
||
119 | Relationship::fixed('mère', '%s de la mère')->mother(), |
||
120 | Relationship::fixed('père', '%s du père')->father(), |
||
121 | Relationship::fixed('parent', '%s du parent')->parent(), |
||
122 | // Children |
||
123 | Relationship::fixed('fille', '%s de la fille')->daughter(), |
||
124 | Relationship::fixed('fils', '%s du fils')->son(), |
||
125 | Relationship::fixed('enfant', '%s de l’enfant')->child(), |
||
126 | // Siblings |
||
127 | Relationship::fixed('sœur jumelle', '%s de la sœur jumelle')->twin()->sister(), |
||
128 | Relationship::fixed('frère jumeau', '%s du frère jumeau')->twin()->brother(), |
||
129 | Relationship::fixed('jumeau', '%s du jumeau')->twin()->sibling(), |
||
130 | Relationship::fixed('grande sœur', '%s de la grande sœur')->older()->sister(), |
||
131 | Relationship::fixed('grand frère', '%s du grand frère')->older()->brother(), |
||
132 | Relationship::fixed('grand frère/sœur', '%s du grand frère/sœur')->older()->sibling(), |
||
133 | Relationship::fixed('petite sœur', '%s de la petite sœur')->younger()->sister(), |
||
134 | Relationship::fixed('petit frère', '%s du petit-frère')->younger()->brother(), |
||
135 | Relationship::fixed('petit frère/sœur', '%s du petit frère/sœur')->younger()->sibling(), |
||
136 | Relationship::fixed('sœur', '%s de la sœur')->sister(), |
||
137 | Relationship::fixed('frère', '%s du frère')->brother(), |
||
138 | Relationship::fixed('frère/sœur', '%s du frère/sœur')->sibling(), |
||
139 | // Half-family |
||
140 | Relationship::fixed('demi-sœur', '%s de la demi-sœur')->parent()->daughter(), |
||
141 | Relationship::fixed('demi-frère', '%s du demi-frère')->parent()->son(), |
||
142 | Relationship::fixed('demi-frère/sœur', '%s du demi-frère/sœur')->parent()->child(), |
||
143 | // Stepfamily |
||
144 | Relationship::fixed('belle-mère', '%s de la belle-mère')->parent()->wife(), |
||
145 | Relationship::fixed('beau-père', '%s du beau-père')->parent()->husband(), |
||
146 | Relationship::fixed('beau-parent', '%s du beau-parent')->parent()->married()->spouse(), |
||
147 | Relationship::fixed('belle-fille', '%s de la belle-fille')->married()->spouse()->daughter(), |
||
148 | Relationship::fixed('beau-fils', '%s du beau-fils')->married()->spouse()->son(), |
||
149 | Relationship::fixed('beau-fils/fille', '%s du beau-fils/fille')->married()->spouse()->child(), |
||
150 | Relationship::fixed('quasi-sœur', '%s de la quasi-sœur')->parent()->spouse()->daughter(), |
||
151 | Relationship::fixed('quasi-frère', '%s du quasi-frère')->parent()->spouse()->son(), |
||
152 | Relationship::fixed('quasi-frère/sœur', '%s du quasi-frère/sœur')->parent()->spouse()->child(), |
||
153 | // Partners |
||
154 | Relationship::fixed('ex-épouse', '%s de l’ex-épouse')->divorced()->partner()->female(), |
||
155 | Relationship::fixed('ex-époux', '%s de l’ex-époux')->divorced()->partner()->male(), |
||
156 | Relationship::fixed('ex-conjoint', '%s de l’ex-conjoint')->divorced()->partner(), |
||
157 | Relationship::fixed('fiancée', '%s de la fiancée')->engaged()->partner()->female(), |
||
158 | Relationship::fixed('fiancé', '%s du fiancé')->engaged()->partner()->male(), |
||
159 | Relationship::fixed('épouse', '%s de l’épouse')->wife(), |
||
160 | Relationship::fixed('époux', '%s de l’époux')->husband(), |
||
161 | Relationship::fixed('époux', '%s de l’époux')->spouse(), |
||
162 | Relationship::fixed('conjoint', '%s du conjoint')->partner(), |
||
163 | // In-laws |
||
164 | Relationship::fixed('belle-mère', '%s de la belle-mère')->married()->spouse()->mother(), |
||
165 | Relationship::fixed('beau-père', '%s du beau-père')->married()->spouse()->father(), |
||
166 | Relationship::fixed('beau-parent', '%s du beau-parent')->married()->spouse()->parent(), |
||
167 | Relationship::fixed('belle-fille', '%s de la belle-fille')->child()->wife(), |
||
168 | Relationship::fixed('beau-fils', '%s du beau-fils')->child()->husband(), |
||
169 | Relationship::fixed('beau-fils/belle-fille', '%s du beau-fils/belle-fille')->child()->married()->spouse(), |
||
170 | Relationship::fixed('belle-sœur', '%s de la belle-sœur')->spouse()->sister(), |
||
171 | Relationship::fixed('beau-frère', '%s du beau-frère')->spouse()->brother(), |
||
172 | Relationship::fixed('beau-frère/belle-sœur', '%s du beau-frère/belle-sœur')->spouse()->sibling(), |
||
173 | Relationship::fixed('belle-sœur', '%s de la belle-sœur')->sibling()->wife(), |
||
174 | Relationship::fixed('beau-frère', '%s du beau-frère')->sibling()->husband(), |
||
175 | Relationship::fixed('beau-frère/belle-sœur', '%s du beau-frère/belle-sœur')->sibling()->spouse(), |
||
176 | // Grandparents and above |
||
177 | Relationship::dynamic(fn (int $n) => $great($n - 1, 'grand-mère maternelle', 'de la '))->mother()->ancestor()->female(), |
||
178 | Relationship::dynamic(fn (int $n) => $great($n - 1, 'grand-père maternel', 'du '))->mother()->ancestor()->male(), |
||
179 | Relationship::dynamic(fn (int $n) => $great($n - 1, 'grand-mère paternelle', 'de la '))->father()->ancestor()->female(), |
||
180 | Relationship::dynamic(fn (int $n) => $great($n - 1, 'grand-père paternel', 'du '))->father()->ancestor()->male(), |
||
181 | Relationship::dynamic(fn (int $n) => $great($n - 2, 'grand-mère', 'de la '))->ancestor()->female(), |
||
182 | Relationship::dynamic(fn (int $n) => $great($n - 2, 'grand-père', 'du '))->ancestor()->male(), |
||
183 | Relationship::dynamic(fn (int $n) => $great($n - 2, 'grand-parent', 'du '))->ancestor(), |
||
184 | // Grandchildren and below |
||
185 | Relationship::dynamic(fn (int $n) => $great($n - 2, 'petite-fille', 'de la '))->descendant()->female(), |
||
186 | Relationship::dynamic(fn (int $n) => $great($n - 2, 'petit-fils', 'du '))->descendant()->male(), |
||
187 | Relationship::dynamic(fn (int $n) => $great($n - 2, 'petit-enfant', 'du'))->descendant(), |
||
188 | // Collateral relatives |
||
189 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'grand-', 'tante', 'de la ', 'de la '))->ancestor()->sister(), |
||
190 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'grand-', 'tante par alliance', 'de la ', 'de la '))->ancestor()->sibling()->wife(), |
||
191 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'grand-', 'oncle', 'de l’', 'du '))->ancestor()->brother(), |
||
192 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'grand-', 'oncle par alliance', 'de l’', 'du '))->ancestor()->sibling()->husband(), |
||
193 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'petite-', 'nièce', 'de la ', 'de la '))->sibling()->descendant()->female(), |
||
194 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'petite-', 'nièce par alliance', 'de la ', 'de la '))->married()->spouse()->sibling()->descendant()->female(), |
||
195 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'petit-', 'neveu', 'du ', 'du '))->sibling()->descendant()->male(), |
||
196 | Relationship::dynamic(fn (int $n) => $compoundgreat($n - 1, 'petit-', 'neveu par alliance', 'du ', 'du '))->married()->spouse()->sibling()->descendant()->male(), |
||
197 | // Cousins (based on canon law) |
||
198 | Relationship::dynamic(fn(int $n) => $symmetricCousin($n, 'F'))->symmetricCousin()->female(), |
||
199 | Relationship::dynamic(fn(int $n) => $symmetricCousin($n, 'M'))->symmetricCousin()->male(), |
||
200 | Relationship::dynamic(fn(int $up, int $down) => $asymmetricCousin($up, $down, 'F'))->asymmetricCousin()->female(), |
||
201 | Relationship::dynamic(fn(int $up, int $down) => $asymmetricCousin($up, $down, 'M'))->asymmetricCousin()->male(), |
||
202 | |||
206 |