Conditions | 2 |
Paths | 1 |
Total Lines | 123 |
Code Lines | 103 |
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 |
||
131 | public function relationships(): array |
||
132 | { |
||
133 | // Genitive forms in English are simple/regular, as no relationship name ends in "s". |
||
134 | $genitive = static fn (string $s): array => [$s, $s . '’s %s']; |
||
135 | |||
136 | $cousin = static fn (int $up, int $down): array => $genitive( |
||
137 | (static::COUSIN[min($up, $down)] ?? 'distant cousin') . |
||
138 | (static::REMOVED[abs($up - $down)] ?? ' many times removed') . |
||
139 | static::DIRECTION[$up <=> $down] |
||
140 | ); |
||
141 | |||
142 | $great = static fn (int $n, string $prefix, string $suffix): array => $genitive( |
||
143 | $prefix . ($n > 3 ? 'great ×' . $n . ' ' : str_repeat('great-', $n)) . $suffix |
||
144 | ); |
||
145 | |||
146 | return [ |
||
147 | // Adopted |
||
148 | Relationship::fixed('adoptive-mother', 'adoptive-mother’s %s')->adoptive()->mother(), |
||
149 | Relationship::fixed('adoptive-father', 'adoptive-father’s %s')->adoptive()->father(), |
||
150 | Relationship::fixed('adoptive-parent', 'adoptive-parent’s %s')->adoptive()->parent(), |
||
151 | Relationship::fixed('adopted-daughter', 'adopted-daughter’s %s')->adopted()->daughter(), |
||
152 | Relationship::fixed('adopted-son', 'adopted-son’s %s')->adopted()->son(), |
||
153 | Relationship::fixed('adopted-child', 'adopted-child’s %s')->adopted()->child(), |
||
154 | // Fostered |
||
155 | Relationship::fixed('foster-mother', 'foster-mother’s %s')->fostering()->mother(), |
||
156 | Relationship::fixed('foster-father', 'foster-father’s %s')->fostering()->father(), |
||
157 | Relationship::fixed('foster-parent', 'foster-parent’s %s')->fostering()->parent(), |
||
158 | Relationship::fixed('foster-daughter', 'foster-daughter’s %s')->fostered()->daughter(), |
||
159 | Relationship::fixed('foster-son', 'foster-son’s %s')->fostered()->son(), |
||
160 | Relationship::fixed('foster-child', 'foster-child’s %s')->fostered()->child(), |
||
161 | // Parents |
||
162 | Relationship::fixed('mother', 'mother’s %s')->mother(), |
||
163 | Relationship::fixed('father', 'father’s %s')->father(), |
||
164 | Relationship::fixed('parent', 'parent’s %s')->parent(), |
||
165 | // Children |
||
166 | Relationship::fixed('daughter', 'daughter’s %s')->daughter(), |
||
167 | Relationship::fixed('son', 'son’s %s')->son(), |
||
168 | Relationship::fixed('child', 'child’s %s')->child(), |
||
169 | // Siblings |
||
170 | Relationship::fixed('twin sister', 'twin sister’s %s')->twin()->sister(), |
||
171 | Relationship::fixed('twin brother', 'twin brother’s %s')->twin()->brother(), |
||
172 | Relationship::fixed('twin sibling', 'twin sibling’s %s')->twin()->sibling(), |
||
173 | Relationship::fixed('elder sister', 'elder sister’s %s')->older()->sister(), |
||
174 | Relationship::fixed('elder brother', 'elder brother’s %s')->older()->brother(), |
||
175 | Relationship::fixed('elder sibling', 'elder sibling’s %s')->older()->sibling(), |
||
176 | Relationship::fixed('younger sister', 'younger sister’s %s')->younger()->sister(), |
||
177 | Relationship::fixed('younger brother', 'younger brother’s %s')->younger()->brother(), |
||
178 | Relationship::fixed('younger sibling', 'younger sibling’s %s')->younger()->sibling(), |
||
179 | Relationship::fixed('sister', 'sister’s %s')->sister(), |
||
180 | Relationship::fixed('brother', 'brother’s %s')->brother(), |
||
181 | Relationship::fixed('sibling', 'sibling’s %s')->sibling(), |
||
182 | // Half-siblings |
||
183 | Relationship::fixed('half-sister', 'half-sister’s %s')->parent()->daughter(), |
||
184 | Relationship::fixed('half-brother', 'half-brother’s %s')->parent()->son(), |
||
185 | Relationship::fixed('half-sibling', 'half-sibling’s %s')->parent()->child(), |
||
186 | // Stepfamily |
||
187 | Relationship::fixed('stepmother', 'stepmother’s %s')->parent()->wife(), |
||
188 | Relationship::fixed('stepfather', 'stepfather’s %s')->parent()->husband(), |
||
189 | Relationship::fixed('stepparent', 'stepparent’s %s')->parent()->married()->spouse(), |
||
190 | Relationship::fixed('stepdaughter', 'stepdaughter’s %s')->married()->spouse()->daughter(), |
||
191 | Relationship::fixed('stepson', 'stepson’s %s')->married()->spouse()->son(), |
||
192 | Relationship::fixed('stepchild', 'stepchild’s %s')->married()->spouse()->child(), |
||
193 | Relationship::fixed('stepsister', 'stepsister’s %s')->parent()->spouse()->daughter(), |
||
194 | Relationship::fixed('stepbrother', 'stepbrother’s %s')->parent()->spouse()->son(), |
||
195 | Relationship::fixed('stepsibling', 'stepsibling’s %s')->parent()->spouse()->child(), |
||
196 | // Partners |
||
197 | Relationship::fixed('ex-wife', 'ex-wife’s %s')->divorced()->partner()->female(), |
||
198 | Relationship::fixed('ex-husband', 'ex-husband’s %s')->divorced()->partner()->male(), |
||
199 | Relationship::fixed('ex-spouse', 'ex-spouse’s %s')->divorced()->partner(), |
||
200 | Relationship::fixed('fiancée', 'fiancée’s %s')->engaged()->partner()->female(), |
||
201 | Relationship::fixed('fiancé', 'fiancé’s %s')->engaged()->partner()->male(), |
||
202 | Relationship::fixed('wife', 'wife’s %s')->wife(), |
||
203 | Relationship::fixed('husband', 'husband’s %s')->husband(), |
||
204 | Relationship::fixed('spouse', 'spouse’s %s')->spouse(), |
||
205 | Relationship::fixed('partner', 'partner’s %s')->partner(), |
||
206 | // In-laws |
||
207 | Relationship::fixed('mother-in-law', 'mother-in-law’s %s')->married()->spouse()->mother(), |
||
208 | Relationship::fixed('father-in-law', 'father-in-law’s %s')->married()->spouse()->father(), |
||
209 | Relationship::fixed('parent-in-law', 'parent-in-law’s %s')->married()->spouse()->parent(), |
||
210 | Relationship::fixed('daughter-in-law', 'daughter-in-law’s %s')->child()->wife(), |
||
211 | Relationship::fixed('son-in-law', 'son-in-law’s %s')->child()->husband(), |
||
212 | Relationship::fixed('child-in-law', 'child-in-law’s %s')->child()->married()->spouse(), |
||
213 | Relationship::fixed('sister-in-law', 'sister-in-law’s %s')->sibling()->spouse()->sister(), |
||
214 | Relationship::fixed('brother-in-law', 'brother-in-law’s %s')->sibling()->spouse()->brother(), |
||
215 | Relationship::fixed('sibling-in-law', 'sibling-in-law’s %s')->sibling()->spouse()->sibling(), |
||
216 | Relationship::fixed('sister-in-law', 'sister-in-law’s %s')->spouse()->sister(), |
||
217 | Relationship::fixed('brother-in-law', 'brother-in-law’s %s')->spouse()->brother(), |
||
218 | Relationship::fixed('sibling-in-law', 'sibling-in-law’s %s')->spouse()->sibling(), |
||
219 | Relationship::fixed('sister-in-law', 'sister-in-law’s %s')->sibling()->wife(), |
||
220 | Relationship::fixed('brother-in-law', 'brother-in-law’s %s')->sibling()->husband(), |
||
221 | Relationship::fixed('sibling-in-law', 'sibling-in-law’s %s')->sibling()->spouse(), |
||
222 | // Grandparents |
||
223 | Relationship::fixed('maternal-grandmother', 'maternal-grandmother’s %s')->mother()->mother(), |
||
224 | Relationship::fixed('maternal-grandfather', 'maternal-grandfather’s %s')->mother()->father(), |
||
225 | Relationship::fixed('maternal-grandparent', 'maternal-grandfather’s %s')->mother()->parent(), |
||
226 | Relationship::fixed('paternal-grandmother', 'paternal-grandmother’s %s')->father()->mother(), |
||
227 | Relationship::fixed('paternal-grandfather', 'paternal-grandfather’s %s')->father()->father(), |
||
228 | Relationship::fixed('paternal-grandparent', 'paternal-grandfather’s %s')->father()->parent(), |
||
229 | Relationship::fixed('grandmother', 'grandmother’s %s')->parent()->mother(), |
||
230 | Relationship::fixed('grandfather', 'grandfather’s %s')->parent()->father(), |
||
231 | Relationship::fixed('grandparent', 'grandparent’s %s')->parent()->parent(), |
||
232 | // Grandchildren |
||
233 | Relationship::fixed('granddaughter', 'granddaughter’s %s')->child()->daughter(), |
||
234 | Relationship::fixed('grandson', 'grandson’s %s')->child()->son(), |
||
235 | Relationship::fixed('grandchild', 'grandchild’s %s')->child()->child(), |
||
236 | // Relationships with dynamically generated names |
||
237 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'aunt'))->ancestor()->sister(), |
||
238 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'aunt'))->ancestor()->sibling()->wife(), |
||
239 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'uncle'))->ancestor()->brother(), |
||
240 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'uncle'))->ancestor()->sibling()->husband(), |
||
241 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'niece'))->sibling()->descendant()->female(), |
||
242 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'niece'))->married()->spouse()->sibling()->descendant()->female(), |
||
243 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'nephew'))->sibling()->descendant()->male(), |
||
244 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'nephew'))->married()->spouse()->sibling()->descendant()->male(), |
||
245 | Relationship::dynamic(static fn (int $n) => $great($n - 1, 'maternal ', 'grandmother'))->mother()->ancestor()->female(), |
||
246 | Relationship::dynamic(static fn (int $n) => $great($n - 1, 'maternal ', 'grandfather'))->mother()->ancestor()->male(), |
||
247 | Relationship::dynamic(static fn (int $n) => $great($n - 1, 'paternal ', 'grandmother'))->father()->ancestor()->female(), |
||
248 | Relationship::dynamic(static fn (int $n) => $great($n - 1, 'paternal ', 'grandfather'))->father()->ancestor()->male(), |
||
249 | Relationship::dynamic(static fn (int $n) => $great($n - 1, '', 'grandparent'))->ancestor(), |
||
250 | Relationship::dynamic(static fn (int $n) => $great($n - 2, '', 'granddaughter'))->descendant()->female(), |
||
251 | Relationship::dynamic(static fn (int $n) => $great($n - 2, '', 'grandson'))->descendant()->male(), |
||
252 | Relationship::dynamic(static fn (int $n) => $great($n - 2, '', 'grandchild'))->descendant(), |
||
253 | Relationship::dynamic($cousin)->ancestor()->sibling()->descendant(), |
||
254 | ]; |
||
257 |