Conditions | 1 |
Paths | 1 |
Total Lines | 71 |
Code Lines | 52 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 namespace Xaoc303\BattleCalc; |
||
36 | public function create(Unit $unit, $units_count) |
||
37 | { |
||
38 | $masUnitTownDistruct = array(104, 204, 308); |
||
39 | |||
40 | $base = array(); |
||
41 | $base['ID'] = $unit->id; // id |
||
42 | $base['ManCount'] = $units_count; // Количество |
||
43 | $base['Iniciative'] = 0; // Инициатива |
||
44 | $base['ShieldUp'] = 1; // Щит |
||
45 | $base['ArmorUp'] = 1; // Броня |
||
46 | $base['AttackTerUp'] = 1; // атака земля |
||
47 | $base['AttackAirUp'] = 1; // атака воздух |
||
48 | $base['AttackMagicUp'] = 1; // Магия |
||
49 | $base['Magic'][0] = $unit->magic1; // Магия |
||
50 | $base['Magic'][1] = $unit->magic2; // Магия |
||
51 | $base['Magic'][2] = $unit->magic3; // Магия |
||
52 | |||
53 | |||
54 | $battle = array(); |
||
55 | $base['TownDistruct'] = in_array($base['ID'], $masUnitTownDistruct); |
||
56 | $battle['TownDistruct'] = $base['TownDistruct']; |
||
57 | |||
58 | $battle['Iniciative'] = $unit->init; // Инициатива |
||
59 | $battle['UT'] = $unit->type; // Тип |
||
60 | |||
61 | $battle['Bio'] = $unit->bio; // био-тип |
||
62 | |||
63 | $base['Shield'] = $unit->shield; // Щит |
||
64 | $battle['Shield'] = $base['Shield'] * $base['ManCount']; |
||
65 | |||
66 | $base['Armor'] = $unit->armor; // Броня |
||
67 | $battle['Armor'] = $base['Armor'] * $base['ManCount']; |
||
68 | |||
69 | $base['HP'] = $unit->hp; // Здоровье |
||
70 | $battle['HP'] = $base['HP'] * $base['ManCount']; |
||
71 | |||
72 | $battle['Magic'][0] = null; |
||
73 | $battle['Magic'][1] = null; |
||
74 | $battle['Magic'][2] = null; |
||
75 | |||
76 | $battle['MagicRound'] = $unit->mround; // Магическая атака |
||
77 | $battle['AttackMagicAll'] = 0; |
||
78 | $battle['AttackMagicShield'] = 0; |
||
79 | $battle['AttackMagicHP'] = 0; |
||
80 | |||
81 | $base['AttackCool'] = $unit->cool; // атака задержка |
||
82 | $battle['AttackCoolInt'] = 0; |
||
83 | $battle['AttackCoolDouble'] = 0; |
||
84 | |||
85 | $base['AttackTer'] = $unit->attack_ter; // атака земля |
||
86 | $battle['AttackTer'] = 0; |
||
87 | |||
88 | $base['AttackAir'] = $unit->attack_air; // атака воздух |
||
89 | $battle['AttackAir'] = 0; |
||
90 | |||
91 | $battle['ManCountVisible'] = 0; |
||
92 | $battle['MagicManCount'] = $unit->attack_magic * $base['AttackMagicUp']; |
||
93 | $battle['ManLock'] = 0; |
||
94 | $battle['ManPhantom'] = 0; |
||
95 | $battle['Damage'] = 0; |
||
96 | $battle['Color'] = 0; |
||
97 | $battle['ManCount'] = $base['ManCount']; |
||
98 | |||
99 | $battle['HealingLive'] = 0; |
||
100 | $battle['HealingTech'] = 0; |
||
101 | |||
102 | return [ |
||
103 | 'Base' => $base, |
||
104 | 'All' => $battle |
||
105 | ]; |
||
106 | } |
||
107 | } |
||
108 |