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