| Conditions | 3 |
| Paths | 1 |
| Total Lines | 99 |
| Code Lines | 73 |
| 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 |
||
| 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 | ]; |
||
| 189 |