Completed
Push — trunk ( 8c8cf8...dc0cf2 )
by SuperNova.WS
04:27
created

QueUnitStatic::que_unit_make_sql()   B

Complexity

Conditions 6
Paths 24

Size

Total Lines 42
Code Lines 27

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 27
nc 24
nop 8
dl 0
loc 42
ccs 0
cts 31
cp 0
crap 42
rs 8.439
c 0
b 0
f 0

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
/**
3
 * Created by Gorlum 24.03.2018 19:45
4
 */
5
6
namespace Que;
7
8
use Planet\DBStaticPlanet;
9
10
class QueUnitStatic {
11
12
  /**
13
   * @param array $prevSqlBlock
14
   * @param int   $unit_id
15
   * @param array $user
16
   * @param array $planet
17
   * @param array $build_data
18
   * @param int   $unit_level
19
   * @param int   $unit_amount
20
   * @param int   $build_mode
21
   *
22
   * @return array
23
   */
24
  public static function que_unit_make_sql($prevSqlBlock = [], $unit_id, $user = array(), $planet = array(), $build_data, $unit_level = 0, $unit_amount = 1, $build_mode = BUILD_CREATE) {
25
    // TODO Унифицировать проверки
26
27
    // TODO que_process() тут
28
29
    sn_db_transaction_check(true);
30
31
    $build_mode = $build_mode == BUILD_CREATE ? BUILD_CREATE : BUILD_DESTROY;
32
33
    // TODO: Some checks
34
    db_change_units($user, $planet, array(
35
      RES_METAL     => -$build_data[$build_mode][RES_METAL] * $unit_amount,
36
      RES_CRYSTAL   => -$build_data[$build_mode][RES_CRYSTAL] * $unit_amount,
37
      RES_DEUTERIUM => -$build_data[$build_mode][RES_DEUTERIUM] * $unit_amount,
38
    ));
39
40
    $que_type = que_get_unit_que($unit_id);
41
    $planet_id_origin = $planet['id'] ? floatval($planet['id']) : null;
42
    $planet_id = $que_type == QUE_RESEARCH ? null : $planet_id_origin;
43
    if (is_numeric($planet_id)) {
44
      DBStaticPlanet::db_planet_set_by_id($planet_id, "`que_processed` = UNIX_TIMESTAMP(NOW())");
45
    } elseif (is_numeric($user['id'])) {
46
      db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

46
      /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], '`que_processed` = UNIX_TIMESTAMP(NOW())');
Loading history...
47
    }
48
49
    $resource_list = sys_unit_arr2str($build_data[$build_mode]);
50
51
    $result = [
52
      'que_player_id'        => $user['id'],
53
      'que_planet_id'        => $planet_id,
54
      'que_planet_id_origin' => $planet_id_origin,
55
      'que_type'             => $que_type,
56
      'que_time_left'        => $build_data[RES_TIME][$build_mode],
57
      'que_unit_id'          => $unit_id,
58
      'que_unit_amount'      => $unit_amount,
59
      'que_unit_mode'        => $build_mode,
60
      'que_unit_level'       => $unit_level,
61
      'que_unit_time'        => $build_data[RES_TIME][$build_mode],
62
      'que_unit_price'       => $resource_list,
63
    ];
64
65
    return $result;
66
  }
67
68
}
69