Conditions | 45 |
Paths | > 20000 |
Total Lines | 135 |
Code Lines | 87 |
Lines | 0 |
Ratio | 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 |
||
58 | public static function eftarray($md5, $items, $victimID = 0) |
||
59 | { |
||
60 | $Cache = Cache::get($md5."eftarray"); |
||
61 | if ($Cache) return $Cache; |
||
|
|||
62 | |||
63 | // EFT / Fitting Wheel |
||
64 | $eftarray["high"] = array(); // high |
||
65 | $eftarray["mid"] = array(); // mid |
||
66 | $eftarray["low"] = array(); // low |
||
67 | $eftarray["rig"] = array(); // rig |
||
68 | $eftarray["drone"] = array(); // drone |
||
69 | $eftarray["sub"] = array(); // sub |
||
70 | $eftammo["high"] = array(); // high ammo |
||
71 | $eftammo["mid"] = array(); // mid ammo |
||
72 | |||
73 | foreach($items as $itm) |
||
74 | { |
||
75 | if (!isset($itm["inContainer"])) $itm["inContainer"] = 0; |
||
76 | if ($victimID >= 2100000000 && $victimID <= 2999999999) $itm["flagName"] = Info::getGroupName(Info::getGroupID($itm["typeID"])); |
||
77 | else if (!isset($itm["flagName"])) $itm["flagName"] = Info::getFlagName($itm["flag"]); |
||
78 | |||
79 | if ($itm["flagName"] == "Infantry Modules") $itm["flagName"] = "Mid Slots"; |
||
80 | if ($itm["flagName"] == "Infantry Weapons") $itm["flagName"] = "High Slots"; |
||
81 | if ($itm["flagName"] == "Infantry Equipment") $itm["flagName"] = "Low Slots"; |
||
82 | if ($itm["flag"] == 89) { |
||
83 | $slot = Db::queryField("select coalesce(valueInt, valueFloat) slot from ccp_dgmTypeAttributes where typeID = :typeID and attributeID = 331", "slot", array(":typeID" => $itm["typeID"])); |
||
84 | if ($slot <= 5 && $slot >= 1) { |
||
85 | $itm["flagName"] = "High Slots"; |
||
86 | $itm["flag"] = 27 + ($slot - 1); |
||
87 | } |
||
88 | else if ($slot > 5 && $slot <= 10) { |
||
89 | $itm["flagName"] = "Low Slots"; |
||
90 | $itm["flag"] = 11 + ($slot - 6); |
||
91 | } |
||
92 | $itm["fittable"] = 1; |
||
93 | } |
||
94 | |||
95 | if (!isset($itm["flag"]) || $itm["flag"] == 0) { |
||
96 | if ($itm["flagName"] == "High Slots") $itm["flag"] = 27; |
||
97 | if ($itm["flagName"] == "Mid Slots") $itm["flag"] = 19; |
||
98 | if ($itm["flagName"] == "Low Slots") $itm["flag"] = 11; |
||
99 | } |
||
100 | |||
101 | $key = $itm["typeName"] . "|" . $itm["flagName"]; |
||
102 | if(isset($itm["flagName"])) |
||
103 | { |
||
104 | if($itm["fittable"] && $itm["inContainer"] == 0) // not ammo or whatever |
||
105 | { |
||
106 | $repeats = $itm["qtyDropped"] + $itm["qtyDestroyed"]; |
||
107 | $i = 0; |
||
108 | while($i < $repeats) |
||
109 | { |
||
110 | if($itm["flagName"] == "High Slots") |
||
111 | { |
||
112 | high: |
||
113 | if(isset($eftarray["high"][$itm["flag"]])) |
||
114 | { |
||
115 | $itm["flag"] = $itm["flag"]+1; |
||
116 | goto high; |
||
117 | } |
||
118 | $eftarray["high"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]); |
||
119 | } |
||
120 | if($itm["flagName"] == "Mid Slots") |
||
121 | { |
||
122 | mid: |
||
123 | if(isset($eftarray["mid"][$itm["flag"]])) |
||
124 | { |
||
125 | $itm["flag"] = $itm["flag"]+1; |
||
126 | goto mid; |
||
127 | } |
||
128 | $eftarray["mid"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]); |
||
129 | } |
||
130 | if($itm["flagName"] == "Low Slots") |
||
131 | { |
||
132 | low: |
||
133 | if(isset($eftarray["low"][$itm["flag"]])) |
||
134 | { |
||
135 | $itm["flag"] = $itm["flag"]+1; |
||
136 | goto low; |
||
137 | } |
||
138 | $eftarray["low"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]); |
||
139 | } |
||
140 | if($itm["flagName"] == "Rigs") |
||
141 | { |
||
142 | rigs: |
||
143 | if(isset($eftarray["rig"][$itm["flag"]])) |
||
144 | { |
||
145 | $itm["flag"] = $itm["flag"]+1; |
||
146 | goto rigs; |
||
147 | } |
||
148 | $eftarray["rig"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]); |
||
149 | } |
||
150 | if($itm["flagName"] == "SubSystems") |
||
151 | { |
||
152 | subs: |
||
153 | if(isset($eftarray["sub"][$itm["flag"]])) |
||
154 | { |
||
155 | $itm["flag"] = $itm["flag"]+1; |
||
156 | goto subs; |
||
157 | } |
||
158 | $eftarray["sub"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"]); |
||
159 | } |
||
160 | $i++; |
||
161 | } |
||
162 | } |
||
163 | else |
||
164 | { |
||
165 | if($itm["flagName"] == "Drone Bay") |
||
166 | $eftarray["drone"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "qty" => $itm["qtyDropped"] + $itm["qtyDestroyed"]); |
||
167 | } |
||
168 | } |
||
169 | } |
||
170 | |||
171 | // Ammo shit |
||
172 | foreach($items as $itm) { |
||
173 | if (!isset($itm["inContainer"])) $itm["inContainer"] = 0; |
||
174 | if($itm["inContainer"] == 0 && !$itm["fittable"] && isset($itm["flagName"])) // possibly ammo |
||
175 | { |
||
176 | if($itm["flagName"] == "High Slots") // high slot ammo |
||
177 | $eftarray["high"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "charge" => true); |
||
178 | if($itm["flagName"] == "Mid Slots") // mid slot ammo |
||
179 | $eftarray["mid"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "charge" => true); |
||
180 | if($itm["flagName"] == "Low Slots") // mid slot ammo |
||
181 | $eftarray["low"][$itm["flag"]][] = array("typeName" => $itm["typeName"], "typeID" => $itm["typeID"], "charge" => true); |
||
182 | } |
||
183 | } |
||
184 | foreach($eftarray as $key=>$value) { |
||
185 | if (sizeof($value)) { |
||
186 | asort($value); |
||
187 | $eftarray[$key] = $value; |
||
188 | } else unset($eftarray[$key]); |
||
189 | } |
||
190 | Cache::set($md5."eftarray", $eftarray); |
||
191 | return $eftarray; |
||
192 | } |
||
193 | |||
352 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.