| Conditions | 3 |
| Paths | 3 |
| Total Lines | 68 |
| Code Lines | 55 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 12 |
| 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 |
||
| 191 | public function getForSubspaceEllipseCreation(): array |
||
| 192 | { |
||
| 193 | $rsm = new ResultSetMapping(); |
||
| 194 | $rsm->addScalarResult('sys_map_id', 'sys_map_id', 'integer'); |
||
| 195 | $rsm->addScalarResult('descriminator', 'descriminator', 'integer'); |
||
| 196 | |||
| 197 | $sysMapIds = $this->getEntityManager() |
||
| 198 | ->createNativeQuery( |
||
| 199 | 'select sys_map_id, descriminator from ( |
||
| 200 | select coalesce(sum(r1.tractor_mass) / 10, 0) |
||
| 201 | + coalesce(sum(r2.tractor_mass), 0) |
||
| 202 | + coalesce((select count(ca.id) |
||
| 203 | from stu_crew_assign ca |
||
| 204 | join stu_ships s |
||
| 205 | on ca.ship_id = s.id |
||
| 206 | where s.user_id >= :firstUserId |
||
| 207 | and s.starsystem_map_id = sm.id) |
||
| 208 | * (select count(ss.id) |
||
| 209 | from stu_ship_system ss |
||
| 210 | join stu_ships s |
||
| 211 | on ss.ship_id = s.id |
||
| 212 | where s.user_id >= :firstUserId |
||
| 213 | and s.starsystem_map_id = sm.id |
||
| 214 | and ss.mode > :mode) |
||
| 215 | * 100, 0) - :threshold as descriminator, |
||
| 216 | sm.id as sys_map_id from stu_sys_map sm |
||
| 217 | join stu_ships s |
||
| 218 | on s.starsystem_map_id = sm.id |
||
| 219 | left join stu_rumps r1 |
||
| 220 | on s.rumps_id = r1.id |
||
| 221 | and r1.category_id = :rumpCategory |
||
| 222 | left join stu_rumps r2 |
||
| 223 | on s.rumps_id = r2.id |
||
| 224 | and r2.category_id != :rumpCategory |
||
| 225 | where s.user_id >= :firstUserId |
||
| 226 | group by sm.id) as foo |
||
| 227 | where descriminator > 0', |
||
| 228 | $rsm |
||
| 229 | ) |
||
| 230 | ->setParameters([ |
||
| 231 | 'threshold' => SubspaceEllipseHandler::MASS_CALCULATION_THRESHOLD, |
||
| 232 | 'rumpCategory' => ShipRumpEnum::SHIP_CATEGORY_STATION, |
||
| 233 | 'firstUserId' => UserEnum::USER_FIRST_ID, |
||
| 234 | 'mode' => ShipSystemModeEnum::MODE_OFF |
||
| 235 | ]) |
||
| 236 | ->getResult(); |
||
| 237 | |||
| 238 | $finalIds = []; |
||
| 239 | foreach ($sysMapIds as $entry) { |
||
| 240 | $descriminator = $entry['descriminator']; |
||
| 241 | |||
| 242 | if ((int)ceil($descriminator / 500000 + 25) > rand(1, 100)) { |
||
| 243 | $finalIds[] = $entry['sys_map_id']; |
||
| 244 | } |
||
| 245 | } |
||
| 246 | |||
| 247 | return $this->getEntityManager() |
||
|
1 ignored issue
–
show
|
|||
| 248 | ->createQuery( |
||
| 249 | sprintf( |
||
| 250 | 'SELECT sm FROM %s sm |
||
| 251 | WHERE sm.id in (:ids)', |
||
| 252 | StarSystemMap::class |
||
| 253 | ) |
||
| 254 | ) |
||
| 255 | ->setParameters([ |
||
| 256 | 'ids' => $finalIds |
||
| 257 | ]) |
||
| 258 | ->getResult(); |
||
| 259 | } |
||
| 261 |