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

BuildDataStatic::getCapitalTimeDivisor()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 30

Importance

Changes 0
Metric Value
cc 5
eloc 13
nc 4
nop 3
dl 0
loc 20
ccs 0
cts 17
cp 0
crap 30
rs 8.8571
c 0
b 0
f 0
1
<?php
2
/**
3
 * Created by Gorlum 24.03.2018 21:54
4
 */
5
6
namespace Meta\Economic;
7
8
9
use SN;
10
11
class BuildDataStatic {
12
13
  /**
14
   * @param float $prevDivisor - because this is Hooker prev result variable should be declared
15
   * @param array $user
16
   * @param array $planet
17
   * @param int   $unit_id
18
   * @param array $unit_data
19
   *
20
   * @return float
21
   */
22
  public static function getStructuresTimeDivisor($prevDivisor, $user, $planet, $unit_id, $unit_data) {
23
    $result = 1;
24
    if (in_array($unit_id, sn_get_groups('structures'))) {
25
      $result = pow(2, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) * (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1);
0 ignored issues
show
Bug introduced by
It seems like mrc_get_level($user, $pl...mic\STRUC_FACTORY_NANO) can also be of type boolean; however, parameter $exp of pow() does only seem to accept integer|double, maybe add an additional type check? ( Ignorable by Annotation )

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

25
      $result = pow(2, /** @scrutinizer ignore-type */ mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) * (mrc_get_level($user, $planet, STRUC_FACTORY_ROBOT) + 1);
Loading history...
26
    } elseif (in_array($unit_id, sn_get_groups('defense'))) {
27
      $result = pow(2, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) * (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1);
28
    } elseif (in_array($unit_id, sn_get_groups('fleet'))) {
29
      $result = pow(2, mrc_get_level($user, $planet, STRUC_FACTORY_NANO)) * (mrc_get_level($user, $planet, STRUC_FACTORY_HANGAR) + 1);
30
    } elseif (in_array($unit_id, sn_get_groups('tech'))) {
31
      $result = eco_get_lab_max_effective_level($user, intval($unit_data[P_REQUIRE][STRUC_LABORATORY]));
32
    }
33
34
    return $result;
35
  }
36
37
  /**
38
   * @param int $unit_id
39
   *
40
   * @return float
41
   */
42
  public static function getMercenaryTimeDivisor($user, $planet, $unit_id) {
43
    if (in_array($unit_id, sn_get_groups('structures'))) {
44
      $mercenary = MRC_ENGINEER;
45
    } elseif (in_array($unit_id, sn_get_groups('tech'))) {
46
      $mercenary = MRC_ACADEMIC;
47
    } elseif (in_array($unit_id, sn_get_groups('defense'))) {
48
      $mercenary = MRC_FORTIFIER;
49
    } elseif (in_array($unit_id, sn_get_groups('fleet'))) {
50
      $mercenary = MRC_ENGINEER;
51
    } else {
52
      $mercenary = 0;
53
    }
54
55
    return $mercenary ? mrc_modify_value($user, $planet, $mercenary, 1) : 1;
56
  }
57
58
  /**
59
   * @param array $user
60
   * @param array $planet
61
   * @param int   $unit_id
62
   *
63
   * @return float|int
64
   */
65
  public static function getCapitalTimeDivisor($user, $planet, $unit_id) {
66
    static $capitalUnitGroups;
67
    if(empty($capitalUnitGroups)) {
68
      $capitalUnitGroups = sn_get_groups(sn_get_groups(GROUP_CAPITAL_BUILDING_BONUS_GROUPS));
0 ignored issues
show
Bug introduced by
It seems like sn_get_groups(Meta\Econo..._BUILDING_BONUS_GROUPS) can also be of type array<mixed,array>; however, parameter $groups of sn_get_groups() does only seem to accept string|string[], maybe add an additional type check? ( Ignorable by Annotation )

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

68
      $capitalUnitGroups = sn_get_groups(/** @scrutinizer ignore-type */ sn_get_groups(GROUP_CAPITAL_BUILDING_BONUS_GROUPS));
Loading history...
69
    }
70
71
    if (
72
      // If planet is capital
73
      $user['id_planet'] == $planet['id']
74
      &&
75
      SN::$gc->config->planet_capital_building_rate > 0
76
      &&
77
      in_array($unit_id, $capitalUnitGroups)
78
    ) {
79
      $capitalTimeDivisor = SN::$gc->config->planet_capital_building_rate;
80
    } else {
81
      $capitalTimeDivisor = 1;
82
    }
83
84
    return $capitalTimeDivisor;
85
  }
86
87
}
88