Completed
Push — work-fleets ( 12f80e...a9ddb1 )
by SuperNova.WS
07:15 queued 01:56
created
includes/includes/flt_mission_recycle.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
 
21 21
   $destination_planet = &$mission_data->dst_planet;
22 22
 
23
-  if(empty($destination_planet['id'])) {
23
+  if (empty($destination_planet['id'])) {
24 24
     $objFleet->mark_fleet_as_returned();
25 25
     $objFleet->flush_changes_to_db();
26 26
 
@@ -31,10 +31,10 @@  discard block
 block discarded – undo
31 31
   $OtherFleetCapacity = 0;
32 32
 
33 33
   $fleet_array = $objFleet->get_unit_list();
34
-  foreach($fleet_array as $unit_id => $unit_count) {
35
-    if(in_array($unit_id, sn_get_groups('fleet'))) {
34
+  foreach ($fleet_array as $unit_id => $unit_count) {
35
+    if (in_array($unit_id, sn_get_groups('fleet'))) {
36 36
       $capacity = get_unit_param($unit_id, P_CAPACITY) * $unit_count;
37
-      if(in_array($unit_id, sn_get_groups('flt_recyclers'))) {
37
+      if (in_array($unit_id, sn_get_groups('flt_recyclers'))) {
38 38
         $RecyclerCapacity += $capacity;
39 39
       } else {
40 40
         $OtherFleetCapacity += $capacity;
@@ -43,33 +43,33 @@  discard block
 block discarded – undo
43 43
   }
44 44
 
45 45
   $fleet_resources_amount = $objFleet->get_resources_amount();
46
-  if($fleet_resources_amount > $OtherFleetCapacity) {
46
+  if ($fleet_resources_amount > $OtherFleetCapacity) {
47 47
     // Если во флоте есть другие корабли И количество ресурсов больше, чем их ёмкость трюмов - значит часть этих ресурсов лежит в трюмах переработчиков
48 48
     // Уменьшаем ёмкость переработчиков на указанную величину
49 49
     $RecyclerCapacity -= ($fleet_resources_amount - $OtherFleetCapacity);
50 50
   }
51 51
 
52 52
   $resources_recycled = array();
53
-  if(($destination_planet["debris_metal"] + $destination_planet["debris_crystal"]) <= $RecyclerCapacity) {
53
+  if (($destination_planet["debris_metal"] + $destination_planet["debris_crystal"]) <= $RecyclerCapacity) {
54 54
     $resources_recycled[RES_METAL] = $destination_planet["debris_metal"];
55 55
     $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"];
56 56
   } else {
57
-    if(($destination_planet["debris_metal"] > $RecyclerCapacity / 2) &&
57
+    if (($destination_planet["debris_metal"] > $RecyclerCapacity / 2) &&
58 58
       ($destination_planet["debris_crystal"] > $RecyclerCapacity / 2)
59 59
     ) {
60 60
       $resources_recycled[RES_METAL] = $RecyclerCapacity / 2;
61 61
       $resources_recycled[RES_CRYSTAL] = $RecyclerCapacity / 2;
62 62
     } else {
63
-      if($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) {
63
+      if ($destination_planet["debris_metal"] > $destination_planet["debris_crystal"]) {
64 64
         $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"];
65
-        if($destination_planet["debris_metal"] > ($RecyclerCapacity - $resources_recycled[RES_CRYSTAL])) {
65
+        if ($destination_planet["debris_metal"] > ($RecyclerCapacity - $resources_recycled[RES_CRYSTAL])) {
66 66
           $resources_recycled[RES_METAL] = $RecyclerCapacity - $resources_recycled[RES_CRYSTAL];
67 67
         } else {
68 68
           $resources_recycled[RES_METAL] = $destination_planet["debris_metal"];
69 69
         }
70 70
       } else {
71 71
         $resources_recycled[RES_METAL] = $destination_planet["debris_metal"];
72
-        if($destination_planet["debris_crystal"] > ($RecyclerCapacity - $resources_recycled[RES_METAL])) {
72
+        if ($destination_planet["debris_crystal"] > ($RecyclerCapacity - $resources_recycled[RES_METAL])) {
73 73
           $resources_recycled[RES_CRYSTAL] = $RecyclerCapacity - $resources_recycled[RES_METAL];
74 74
         } else {
75 75
           $resources_recycled[RES_CRYSTAL] = $destination_planet["debris_crystal"];
Please login to merge, or discard this patch.
includes/classes/UBE/UBEUnit.php 1 patch
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
     parent::setUnitId($unitId);
51 51
 
52 52
     // Reset combat stats??
53
-    if($this->_unitId) {
53
+    if ($this->_unitId) {
54 54
       $this->amplify = $this->info[P_AMPLIFY];
55 55
       $this->capacity = $this->info[P_CAPACITY];
56 56
       $this->price[RES_METAL] = $this->info[P_COST][RES_METAL];
@@ -72,7 +72,7 @@  discard block
 block discarded – undo
72 72
     $this->bonus_attack = $this->info[P_ATTACK];
73 73
     $this->bonus_shield = $this->info[P_SHIELD];
74 74
     $this->bonus_armor = $this->info[P_ARMOR];
75
-    if(is_object($this->unit_bonus)) {
75
+    if (is_object($this->unit_bonus)) {
76 76
       $this->bonus_attack = floor($this->bonus_attack * $this->unit_bonus->calcBonus(P_ATTACK));
77 77
       $this->bonus_shield = floor($this->bonus_shield * $this->unit_bonus->calcBonus(P_SHIELD));
78 78
       $this->bonus_armor = floor($this->bonus_armor * $this->unit_bonus->calcBonus(P_ARMOR));
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     $this->randomized_attack = $this->bonus_attack;
81 81
     $this->randomized_shield = $this->bonus_shield;
82 82
     $this->randomized_armor = $this->bonus_armor;
83
-    if(!$is_simulator) {
83
+    if (!$is_simulator) {
84 84
       // TODO - randomize attack if is not simulator
85 85
       $this->randomized_attack = floor($this->bonus_attack * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100));
86 86
       $this->randomized_shield = floor($this->bonus_shield * ($is_simulator ? 1 : mt_rand(UBE_RANDOMIZE_FROM, UBE_RANDOMIZE_TO) / 100));
@@ -159,22 +159,22 @@  discard block
 block discarded – undo
159 159
    * @version 2016-02-25 23:42:45 41a4.68
160 160
    */
161 161
   public function restore_unit($is_simulator) {
162
-    if($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) {
162
+    if ($this->_type != UNIT_DEFENCE || $this->units_lost <= 0) {
163 163
       return;
164 164
     }
165 165
 
166
-    if($is_simulator) {
166
+    if ($is_simulator) {
167 167
       $units_giveback = round($this->units_lost * UBE_DEFENCE_RESTORATION_CHANCE_AVG / 100); // for simulation just return 75% of loss
168 168
     } else {
169 169
       // Checking - should we trigger mass-restore
170
-      if($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) {
170
+      if ($this->units_lost >= UBE_DEFENCE_RESTORATION_MASS_COUNT) {
171 171
         // For large amount - mass-restoring defence
172 172
         $units_giveback = round($this->units_lost * mt_rand(UBE_DEFENCE_RESTORATION_CHANCE_MIN, UBE_DEFENCE_RESTORATION_CHANCE_MAX) / 100);
173 173
       } else {
174 174
         // For small amount - restoring defence per single unit
175 175
         $units_giveback = 0;
176
-        for($i = 1; $i <= $this->units_lost; $i++) {
177
-          if(mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) {
176
+        for ($i = 1; $i <= $this->units_lost; $i++) {
177
+          if (mt_rand(1, 100) <= UBE_DEFENCE_RESTORATION_CHANCE_AVG) {
178 178
             $units_giveback++;
179 179
           }
180 180
         }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
    */
194 194
   public function receive_damage($is_simulator) {
195 195
     // TODO - Добавить взрывы от полуповрежденных юнитов - т.е. заранее вычислить из убитых юнитов еще количество убитых умножить на вероятность от структуры
196
-    if($this->_count <= 0) {
196
+    if ($this->_count <= 0) {
197 197
       return;
198 198
     }
199 199
 
@@ -216,7 +216,7 @@  discard block
 block discarded – undo
216 216
     $this->adjustCount(-$units_lost);
217 217
 
218 218
     // Проверяем - не взорвался ли текущий юнит
219
-    while($this->_count > 0 && $this->attack_income > 0) {
219
+    while ($this->_count > 0 && $this->attack_income > 0) {
220 220
       $this->attack_damaged_unit($is_simulator);
221 221
     }
222 222
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
     $armor_left = $this->pool_armor % $this->randomized_armor;
242 242
     // Проверка - не атакуем ли мы целый корабль
243 243
     // Такое может быть, если на прошлой итерации поврежденный корабль был взорван и еще осталась входящяя атака
244
-    if($shield_left == 0 && $armor_left == 0) {
244
+    if ($shield_left == 0 && $armor_left == 0) {
245 245
       $shield_left = $this->randomized_shield;
246 246
       $armor_left = $this->randomized_armor;
247 247
     }
@@ -255,7 +255,7 @@  discard block
 block discarded – undo
255 255
     // Вычитаем этот дамадж из щитов пула
256 256
     $this->pool_shield -= $damage_to_shield;
257 257
     // Если весь дамадж был поглощён щитами - выходим
258
-    if($this->attack_income <= 0) {
258
+    if ($this->attack_income <= 0) {
259 259
       return;
260 260
     }
261 261
 
@@ -272,7 +272,7 @@  discard block
 block discarded – undo
272 272
     $armor_left -= $damage_to_armor;
273 273
 
274 274
     // Проверяем - осталась ли броня на текущем корабле и вааще
275
-    if($this->pool_armor <= 0 || $armor_left <= 0) {
275
+    if ($this->pool_armor <= 0 || $armor_left <= 0) {
276 276
       // Не осталось - корабль уничтожен
277 277
       $this->adjustCount(-1);
278 278
 
@@ -283,10 +283,10 @@  discard block
 block discarded – undo
283 283
     $armor_left_percent = $armor_left / $this->randomized_armor * 100;
284 284
     // Проверяем % здоровья
285 285
     // TODO - сделать динамический процент для каждого вида юнитов
286
-    if($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) {
286
+    if ($armor_left_percent <= UBE_CRITICAL_DAMAGE_THRESHOLD) {
287 287
       // Дамадж пошёл по структуре. Чем более поврежден юнит - тем больше шансов у него взорваться
288 288
       $random = $is_simulator ? UBE_CRITICAL_DAMAGE_THRESHOLD / 2 : mt_rand(0, 100);
289
-      if($random >= $armor_left_percent) {
289
+      if ($random >= $armor_left_percent) {
290 290
         $this->adjustCount(-1);
291 291
         $this->unit_count_boom++;
292 292
 
Please login to merge, or discard this patch.
includes/classes/UBE/UBEPlayerList.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
       UBE_PLAYER_IS_DEFENDER => array(),
56 56
     );
57 57
 
58
-    foreach($this->_container as $player_id => $UBEPlayer) {
58
+    foreach ($this->_container as $player_id => $UBEPlayer) {
59 59
       $result[$UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER][$player_id] = $UBEPlayer->getDbRow();
60 60
     }
61 61
 
@@ -70,8 +70,8 @@  discard block
 block discarded – undo
70 70
    */
71 71
   public function get_first_player_on_side($side) {
72 72
     $result = null;
73
-    foreach($this->_container as $player_id => $UBEPlayer) {
74
-      if($UBEPlayer->getSide() == $side) {
73
+    foreach ($this->_container as $player_id => $UBEPlayer) {
74
+      if ($UBEPlayer->getSide() == $side) {
75 75
         $result = $UBEPlayer;
76 76
         break;
77 77
       }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
    */
89 89
   public function get_player_sides() {
90 90
     $result = array();
91
-    foreach($this->_container as $player_id => $UBEPlayer) {
91
+    foreach ($this->_container as $player_id => $UBEPlayer) {
92 92
       $result[$player_id] = $UBEPlayer->getSide() ? UBE_PLAYER_IS_ATTACKER : UBE_PLAYER_IS_DEFENDER;
93 93
     }
94 94
 
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
   }
97 97
 
98 98
   public function ubeLoadPlayersAndSetSideFromFleetIdList(array $added_fleets, UBEFleetList $fleetList, $side = UBE_PLAYER_IS_DEFENDER) {
99
-    foreach($added_fleets as $fleet_id) {
99
+    foreach ($added_fleets as $fleet_id) {
100 100
       $this->db_load_player_by_id($fleetList[$fleet_id]->owner_id, $side);
101 101
     }
102 102
   }
Please login to merge, or discard this patch.
includes/classes/UBE/UBERoundList.php 1 patch
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -25,7 +25,7 @@  discard block
 block discarded – undo
25 25
    */
26 26
   public function report_render_rounds(&$template_result, UBE $ube) {
27 27
     $round_count = $this->count();
28
-    for($round = 1; $round <= $round_count - 1; $round++) {
28
+    for ($round = 1; $round <= $round_count - 1; $round++) {
29 29
       $template_result['.']['round'][] = array(
30 30
         'NUMBER' => $round,
31 31
         '.'      => array(
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
    */
49 49
   public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, $ube_report_id, UBEFleetList $UBEFleetList) {
50 50
     $unit_sort_order = 1;
51
-    foreach($this->_container as $round_number => $UBERound) {
51
+    foreach ($this->_container as $round_number => $UBERound) {
52 52
       $outer_prefix = array(
53 53
         $ube_report_id,
54 54
         $round_number,
@@ -66,9 +66,9 @@  discard block
 block discarded – undo
66 66
    */
67 67
   public function db_load_round_list_from_report_row($report_row, UBE $ube) {
68 68
     $query = doquery("SELECT * FROM {{ube_report_unit}} WHERE `ube_report_id` = {$report_row['ube_report_id']} ORDER BY `ube_report_unit_id`");
69
-    while($report_unit_row = db_fetch($query)) {
69
+    while ($report_unit_row = db_fetch($query)) {
70 70
       $round_number = $report_unit_row['ube_report_unit_round'];
71
-      if(!isset($this[$round_number])) {
71
+      if (!isset($this[$round_number])) {
72 72
         $this[$round_number] = new UBERound();
73 73
         $this[$round_number]->init_round_from_report_unit_row($report_unit_row);
74 74
       }
Please login to merge, or discard this patch.
includes/classes/UBE/UBERound.php 1 patch
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
    * @version 2016-02-25 23:42:45 41a4.68
37 37
    */
38 38
   public function make_snapshot(UBEFleetList $UBEFleetList) {
39
-    foreach($UBEFleetList->_container as $fleet_id => $UBEFleet) {
40
-      foreach($UBEFleet->unit_list->_container as $UBEUnit) {
39
+    foreach ($UBEFleetList->_container as $fleet_id => $UBEFleet) {
40
+      foreach ($UBEFleet->unit_list->_container as $UBEUnit) {
41 41
         $this->snapshot[$fleet_id][$UBEUnit->unitId] = new UBESnapshotUnit();
42 42
         $this->snapshot[$fleet_id][$UBEUnit->unitId]->init_from_UBEUnit($UBEUnit);
43 43
       }
@@ -53,12 +53,12 @@  discard block
 block discarded – undo
53 53
    * @version 2016-02-25 23:42:45 41a4.68
54 54
    */
55 55
   public function sql_generate_unit_array(array &$sql_perform_ube_report_unit, &$unit_sort_order, UBEFleetList $UBEFleetList, array $outer_prefix) {
56
-    foreach($this->snapshot as $fleet_id => $fleet_snapshot) {
56
+    foreach ($this->snapshot as $fleet_id => $fleet_snapshot) {
57 57
       $inner_prefix = array(
58 58
         $UBEFleetList[$fleet_id]->owner_id,
59 59
         $fleet_id,
60 60
       );
61
-      foreach($fleet_snapshot as $unit_id => $unit_snapshot) {
61
+      foreach ($fleet_snapshot as $unit_id => $unit_snapshot) {
62 62
         $sql_perform_ube_report_unit[] = array_merge(
63 63
           $outer_prefix,
64 64
           $inner_prefix,
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
       UBE_PLAYER_IS_DEFENDER => array(),
102 102
     );
103 103
 
104
-    foreach($this->snapshot as $fleet_id => $fleet_snapshot) {
104
+    foreach ($this->snapshot as $fleet_id => $fleet_snapshot) {
105 105
       $fleet_owner_id = $ube->fleet_list[$fleet_id]->owner_id;
106 106
       $planet_ube_row = $ube->fleet_list[$fleet_id]->UBE_PLANET;
107 107
 
@@ -111,13 +111,13 @@  discard block
 block discarded – undo
111 111
         'PLAYER_NAME' => htmlentities($ube->players[$fleet_owner_id]->name, ENT_COMPAT, 'UTF-8'),
112 112
       );
113 113
 
114
-      if(is_array($planet_ube_row)) {
114
+      if (is_array($planet_ube_row)) {
115 115
         $template_fleet += $planet_ube_row;
116 116
         $template_fleet[PLANET_NAME] = $template_fleet[PLANET_NAME] ? htmlentities($template_fleet[PLANET_NAME], ENT_COMPAT, 'UTF-8') : '';
117 117
         $template_fleet['PLANET_TYPE_TEXT'] = $lang['sys_planet_type_sh'][$template_fleet['PLANET_TYPE']];
118 118
       }
119 119
 
120
-      foreach($fleet_snapshot as $unit_id => $unit_snapshot) {
120
+      foreach ($fleet_snapshot as $unit_id => $unit_snapshot) {
121 121
         $template_fleet['.']['ship'][] = $unit_snapshot->report_render_unit($prevSnapshot[$fleet_id][$unit_id]);
122 122
       }
123 123
 
Please login to merge, or discard this patch.
includes/classes/UBE/ArrayAccessV2.php 1 patch
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -42,7 +42,7 @@  discard block
 block discarded – undo
42 42
 
43 43
 
44 44
   public function __clone() {
45
-    if(static::$_clonable == ArrayAccessV2::CLONE_NONE) {
45
+    if (static::$_clonable == ArrayAccessV2::CLONE_NONE) {
46 46
       return;
47 47
     }
48 48
 
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
   }
51 51
 
52 52
   protected static function _deep_clone(&$array) {
53
-    foreach($array as &$value) {
54
-      if(is_object($value)) {
53
+    foreach ($array as &$value) {
54
+      if (is_object($value)) {
55 55
         $value = clone $value;
56
-      } elseif(is_array($value) && static::$_clonable == ArrayAccessV2::CLONE_DEEP) {
56
+      } elseif (is_array($value) && static::$_clonable == ArrayAccessV2::CLONE_DEEP) {
57 57
         static::_deep_clone($value);
58 58
       }
59 59
     }
@@ -67,8 +67,8 @@  discard block
 block discarded – undo
67 67
    */
68 68
   public function __call($method_name, array $arguments) {
69 69
     $object_first = reset($this->_container);
70
-    if($object_first !== false && method_exists($object_first, $method_name)) {
71
-      foreach($this->_container as $unit_id => $object) {
70
+    if ($object_first !== false && method_exists($object_first, $method_name)) {
71
+      foreach ($this->_container as $unit_id => $object) {
72 72
         call_user_func_array(array($object, $method_name), $arguments);
73 73
       }
74 74
     }
@@ -83,8 +83,8 @@  discard block
 block discarded – undo
83 83
    */
84 84
   public function getSumProperty($property_name) {
85 85
     $result = 0.0;
86
-    foreach($this->_container as $object) {
87
-      if(is_object($object) && property_exists($object, $property_name)) {
86
+    foreach ($this->_container as $object) {
87
+      if (is_object($object) && property_exists($object, $property_name)) {
88 88
         $result += $object->$property_name;
89 89
       }
90 90
     }
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
    * @return mixed
101 101
    */
102 102
   public function aggregateByMethod($method_name, &$result) {
103
-    foreach($this->_container as $object) {
104
-      if(is_object($object) && method_exists($object, $method_name)) {
103
+    foreach ($this->_container as $object) {
104
+      if (is_object($object) && method_exists($object, $method_name)) {
105 105
         call_user_func(array($object, $method_name), $result);
106 106
       }
107 107
     }
Please login to merge, or discard this patch.
includes/classes/PlayerList.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@
 block discarded – undo
23 23
    * @version 41a6.16
24 24
    */
25 25
   protected function db_load_player_by_id($player_id) {
26
-    if(isset($this[$player_id])) {
26
+    if (isset($this[$player_id])) {
27 27
       return;
28 28
     }
29 29
 
Please login to merge, or discard this patch.
includes/classes/Unit.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -154,15 +154,15 @@  discard block
 block discarded – undo
154 154
    * @param string $group_name
155 155
    */
156 156
   public static function _init($group_name = '') {
157
-    if(static::$_is_static_init) {
157
+    if (static::$_is_static_init) {
158 158
       return;
159 159
     }
160 160
 
161
-    if($group_name) {
161
+    if ($group_name) {
162 162
       static::$_sn_group_name = $group_name;
163 163
     }
164 164
 
165
-    if(static::$_sn_group_name) {
165
+    if (static::$_sn_group_name) {
166 166
       static::$_group_unit_id_list = sn_get_groups(static::$_sn_group_name);
167 167
       empty(static::$_group_unit_id_list) ? static::$_group_unit_id_list = array() : false;
168 168
     }
@@ -187,7 +187,7 @@  discard block
 block discarded – undo
187 187
     // TODO - Reset combat stats??
188 188
     $this->_unitId = $unitId;
189 189
 
190
-    if($this->_unitId) {
190
+    if ($this->_unitId) {
191 191
       $this->info = get_unit_param($this->_unitId);
192 192
       $this->_type = $this->info[P_UNIT_TYPE];
193 193
     } else {
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 
199 199
   protected function setCount($value) {
200 200
     // TODO - Reset combat stats??
201
-    if($value < 0) {
201
+    if ($value < 0) {
202 202
       classSupernova::$debug->error('Can not set Unit::$count to negative value');
203 203
     }
204 204
     $this->_count = $value;
Please login to merge, or discard this patch.
includes/classes/DBRow.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -411,7 +411,7 @@
 block discarded – undo
411 411
   /**
412 412
    * @param array $field_set
413 413
    *
414
-   * @return int|string
414
+   * @return integer
415 415
    */
416 416
   protected function db_field_set_create(array $field_set) {
417 417
     !sn_db_field_set_is_safe($field_set) ? $field_set = sn_db_field_set_make_safe($field_set) : false;
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
    */
109 109
   public function __get($name) {
110 110
     // Redirecting inaccessible get to __call which will handle the rest
111
-    return $this->__call('get' . ucfirst($name), array());
111
+    return $this->__call('get'.ucfirst($name), array());
112 112
   }
113 113
 
114 114
   /**
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
   // TODO - сеттер должен параллельно изменять значение db_row - for now...
121 121
   public function __set($name, $value) {
122 122
     // Redirecting inaccessible set to __call which will handle the rest
123
-    $this->__call('set' . ucfirst($name), array($value));
123
+    $this->__call('set'.ucfirst($name), array($value));
124 124
   }
125 125
 
126 126
   /**
@@ -138,15 +138,15 @@  discard block
 block discarded – undo
138 138
 
139 139
     // If method is not getter or setter OR property name not exists in $_properties - raising exception
140 140
     // Descendants can catch this Exception to make own __call magic
141
-    if(($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) {
142
-      throw new ExceptionPropertyNotExists('Property ' . $propertyName . ' not exists when calling getter/setter ' . get_called_class() . '::' . $name, ERR_ERROR);
141
+    if (($left3 != 'get' && $left3 != 'set') || empty(static::$_properties[$propertyName])) {
142
+      throw new ExceptionPropertyNotExists('Property '.$propertyName.' not exists when calling getter/setter '.get_called_class().'::'.$name, ERR_ERROR);
143 143
     }
144 144
 
145 145
     // TODO check for read-only
146 146
 
147
-    if($left3 == 'set') {
148
-      if(!empty($this->propertiesAdjusted[$propertyName])) {
149
-        throw new PropertyAccessException('Property ' . $propertyName . ' already was adjusted so no SET is possible until dbSave in ' . get_called_class() . '::' . $name, ERR_ERROR);
147
+    if ($left3 == 'set') {
148
+      if (!empty($this->propertiesAdjusted[$propertyName])) {
149
+        throw new PropertyAccessException('Property '.$propertyName.' already was adjusted so no SET is possible until dbSave in '.get_called_class().'::'.$name, ERR_ERROR);
150 150
       }
151 151
       $this->propertiesChanged[$propertyName] = 1;
152 152
     }
@@ -154,18 +154,18 @@  discard block
 block discarded – undo
154 154
     // Now deciding - will we call a protected setter or will we work with protected property
155 155
 
156 156
     // If method exists - just calling it
157
-    if(method_exists($this, $name)) {
157
+    if (method_exists($this, $name)) {
158 158
       return call_user_func_array(array($this, $name), $arguments);
159 159
     }
160 160
     // No getter/setter exists - works directly with protected property
161 161
 
162 162
     // Is it getter?
163
-    if($left3 === 'get') {
164
-      return $this->{'_' . $propertyName};
163
+    if ($left3 === 'get') {
164
+      return $this->{'_'.$propertyName};
165 165
     }
166 166
 
167 167
     // Not getter? Then it's setter
168
-    $this->{'_' . $propertyName} = $arguments[0];
168
+    $this->{'_'.$propertyName} = $arguments[0];
169 169
 
170 170
     return null;
171 171
   }
@@ -182,8 +182,8 @@  discard block
 block discarded – undo
182 182
    */
183 183
   public function dbLoad($dbId, $lockSkip = false) {
184 184
     $dbId = idval($dbId);
185
-    if($dbId <= 0) {
186
-      classSupernova::$debug->error(get_called_class() . '::dbLoad $dbId not positive = ' . $dbId);
185
+    if ($dbId <= 0) {
186
+      classSupernova::$debug->error(get_called_class().'::dbLoad $dbId not positive = '.$dbId);
187 187
 
188 188
       return;
189 189
     }
@@ -191,12 +191,12 @@  discard block
 block discarded – undo
191 191
     $this->_dbId = $dbId;
192 192
     $this->lockSkip = $lockSkip;
193 193
     // TODO - Use classSupernova::$db_records_locked
194
-    if(false && !$lockSkip && sn_db_transaction_check(false)) {
194
+    if (false && !$lockSkip && sn_db_transaction_check(false)) {
195 195
       $this->dbGetLockById($this->_dbId);
196 196
     }
197 197
 
198
-    $db_row = doquery("SELECT * FROM `{{" . static::$_table . "}}` WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId . " LIMIT 1 FOR UPDATE;", true);
199
-    if(empty($db_row)) {
198
+    $db_row = doquery("SELECT * FROM `{{".static::$_table."}}` WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId." LIMIT 1 FOR UPDATE;", true);
199
+    if (empty($db_row)) {
200 200
       return;
201 201
     }
202 202
 
@@ -224,26 +224,26 @@  discard block
 block discarded – undo
224 224
    */
225 225
   // TODO - perform operations only if properties was changed
226 226
   public function dbSave() {
227
-    if($this->isNew()) {
227
+    if ($this->isNew()) {
228 228
       // No DB_ID - new unit
229
-      if($this->isEmpty()) {
230
-        classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - object is empty on ' . get_called_class() . '::dbSave');
229
+      if ($this->isEmpty()) {
230
+        classSupernova::$debug->error(__FILE__.':'.__LINE__.' - object is empty on '.get_called_class().'::dbSave');
231 231
       }
232 232
       $this->dbInsert();
233 233
     } else {
234 234
       // DB_ID is present
235
-      if($this->isEmpty()) {
235
+      if ($this->isEmpty()) {
236 236
         $this->dbDelete();
237 237
       } else {
238
-        if(!sn_db_transaction_check(false)) {
239
-          classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - transaction should always be started on ' . get_called_class() . '::dbUpdate');
238
+        if (!sn_db_transaction_check(false)) {
239
+          classSupernova::$debug->error(__FILE__.':'.__LINE__.' - transaction should always be started on '.get_called_class().'::dbUpdate');
240 240
         }
241 241
         $this->dbUpdate();
242 242
       }
243 243
     }
244 244
 
245
-    if(!empty($this->triggerDbOperationOn)) {
246
-      foreach($this->triggerDbOperationOn as $item) {
245
+    if (!empty($this->triggerDbOperationOn)) {
246
+      foreach ($this->triggerDbOperationOn as $item) {
247 247
         $item->dbSave();
248 248
       }
249 249
     }
@@ -263,13 +263,13 @@  discard block
 block discarded – undo
263 263
    */
264 264
   // TODO - protected
265 265
   public function dbInsert() {
266
-    if(!$this->isNew()) {
267
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - record db_id is not empty on ' . get_called_class() . '::dbInsert');
266
+    if (!$this->isNew()) {
267
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - record db_id is not empty on '.get_called_class().'::dbInsert');
268 268
     }
269 269
     $this->_dbId = $this->db_field_set_create($this->dbMakeFieldSet());
270 270
 
271
-    if(empty($this->_dbId)) {
272
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - error saving record ' . get_called_class() . '::dbInsert');
271
+    if (empty($this->_dbId)) {
272
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - error saving record '.get_called_class().'::dbInsert');
273 273
     }
274 274
 
275 275
     return $this->_dbId;
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
   // TODO - protected
282 282
   public function dbUpdate() {
283 283
     // TODO - Update
284
-    if($this->isNew()) {
285
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbUpdate');
284
+    if ($this->isNew()) {
285
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbUpdate');
286 286
     }
287 287
     $this->db_field_update($this->dbMakeFieldSet(true));
288 288
   }
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
    */
293 293
   // TODO - protected
294 294
   public function dbDelete() {
295
-    if($this->isNew()) {
296
-      classSupernova::$debug->error(__FILE__ . ':' . __LINE__ . ' - unit db_id is empty on dbDelete');
295
+    if ($this->isNew()) {
296
+      classSupernova::$debug->error(__FILE__.':'.__LINE__.' - unit db_id is empty on dbDelete');
297 297
     }
298
-    doquery("DELETE FROM {{" . static::$_table . "}} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId);
298
+    doquery("DELETE FROM {{".static::$_table."}} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId);
299 299
     $this->_dbId = 0;
300 300
     // Обо всём остальном должен позаботиться контейнер
301 301
   }
@@ -334,18 +334,18 @@  discard block
 block discarded – undo
334 334
    * @param array $db_row
335 335
    */
336 336
   public function dbRowParse(array $db_row) {
337
-    foreach(static::$_properties as $property_name => &$property_data) {
337
+    foreach (static::$_properties as $property_name => &$property_data) {
338 338
       // Advanced values extraction procedure. Should be used when at least one of following rules is matched:
339 339
       // - one field should translate to several properties;
340 340
       // - one property should be filled according to several fields;
341 341
       // - property filling requires some lookup in object values;
342
-      if(!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) {
342
+      if (!empty($property_data[P_METHOD_EXTRACT]) && is_callable(array($this, $property_data[P_METHOD_EXTRACT]))) {
343 343
         call_user_func_array(array($this, $property_data[P_METHOD_EXTRACT]), array(&$db_row));
344 344
         continue;
345 345
       }
346 346
 
347 347
       // If property is read-only - doing nothing
348
-      if(!empty($property_data[P_READ_ONLY])) {
348
+      if (!empty($property_data[P_READ_ONLY])) {
349 349
         continue;
350 350
       }
351 351
 
@@ -356,7 +356,7 @@  discard block
 block discarded – undo
356 356
       !empty($property_data[P_FUNC_INPUT]) && is_callable($property_data[P_FUNC_INPUT]) ? $value = call_user_func($property_data[P_FUNC_INPUT], $value) : false;
357 357
 
358 358
       // If there is setter for this field - using it. Setters is always a methods of $THIS
359
-      if(!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) {
359
+      if (!empty($property_data[P_METHOD_SET]) && is_callable(array($this, $property_data[P_METHOD_SET]))) {
360 360
         call_user_func(array($this, $property_data[P_METHOD_SET]), $value);
361 361
       } else {
362 362
         $this->{$property_name} = $value;
@@ -372,21 +372,21 @@  discard block
 block discarded – undo
372 372
   protected function dbMakeFieldSet($isUpdate = false) {
373 373
     $array = array();
374 374
 
375
-    foreach(static::$_properties as $property_name => &$property_data) {
375
+    foreach (static::$_properties as $property_name => &$property_data) {
376 376
       // TODO - on isUpdate add only changed/adjusted properties
377 377
 
378
-      if(!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) {
378
+      if (!empty($property_data[P_METHOD_INJECT]) && is_callable(array($this, $property_data[P_METHOD_INJECT]))) {
379 379
         call_user_func_array(array($this, $property_data[P_METHOD_INJECT]), array(&$array));
380 380
         continue;
381 381
       }
382 382
 
383 383
       // Skipping properties which have no corresponding field in DB
384
-      if(empty($property_data[P_DB_FIELD])) {
384
+      if (empty($property_data[P_DB_FIELD])) {
385 385
         continue;
386 386
       }
387 387
 
388 388
       // Checking - is property was adjusted or changed
389
-      if($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) {
389
+      if ($isUpdate && array_key_exists($property_name, $this->propertiesAdjusted)) {
390 390
         // For adjusted property - take value from propertiesAdjusted array
391 391
         // TODO - differ how treated conversion to string for changed and adjusted properties
392 392
         $value = $this->propertiesAdjusted[$property_name];
@@ -416,17 +416,17 @@  discard block
 block discarded – undo
416 416
    */
417 417
   protected function isFieldChanged($fieldName) {
418 418
     $isFieldChanged = false;
419
-    foreach($this->propertiesChanged as $propertyName => $cork) {
419
+    foreach ($this->propertiesChanged as $propertyName => $cork) {
420 420
       $propertyScheme = static::$_properties[$propertyName];
421
-      if(!empty($propertyScheme[P_DB_FIELDS_LINKED])) {
422
-        foreach($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) {
423
-          if($linkedFieldName == $fieldName) {
421
+      if (!empty($propertyScheme[P_DB_FIELDS_LINKED])) {
422
+        foreach ($propertyScheme[P_DB_FIELDS_LINKED] as $linkedFieldName) {
423
+          if ($linkedFieldName == $fieldName) {
424 424
             $isFieldChanged = $propertyName;
425 425
             break 2;
426 426
           }
427 427
         }
428 428
       }
429
-      if(!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) {
429
+      if (!empty($propertyScheme[P_DB_FIELD]) && $propertyScheme[P_DB_FIELD] == $fieldName) {
430 430
         $isFieldChanged = $propertyName;
431 431
         break;
432 432
       }
@@ -448,7 +448,7 @@  discard block
 block discarded – undo
448 448
     $fields = implode(',', array_keys($field_set));
449 449
 
450 450
     $result = 0;
451
-    if(classSupernova::db_query("INSERT INTO `{{" . static::$_table . "}}` ({$fields}) VALUES ({$values});")) {
451
+    if (classSupernova::db_query("INSERT INTO `{{".static::$_table."}}` ({$fields}) VALUES ({$values});")) {
452 452
       $result = db_insert_id();
453 453
     }
454 454
 
@@ -466,13 +466,13 @@  discard block
 block discarded – undo
466 466
     sn_db_field_set_safe_flag_clear($field_set);
467 467
 
468 468
     $set = array();
469
-    foreach($field_set as $fieldName => $value) {
470
-      if(!($changedProperty = $this->isFieldChanged($fieldName))) {
469
+    foreach ($field_set as $fieldName => $value) {
470
+      if (!($changedProperty = $this->isFieldChanged($fieldName))) {
471 471
         continue;
472 472
       }
473 473
 
474 474
       // TODO - separate sets from adjusts
475
-      if(array_key_exists($changedProperty, $this->propertiesAdjusted)) {
475
+      if (array_key_exists($changedProperty, $this->propertiesAdjusted)) {
476 476
         $value = "`{$fieldName}` + ($value)"; // braces for negative values
477 477
       }
478 478
 
@@ -484,7 +484,7 @@  discard block
 block discarded – undo
484 484
 
485 485
     return empty($set_string)
486 486
       ? true
487
-      : classSupernova::db_query("UPDATE `{{" . static::$_table . "}}` SET {$set_string} WHERE `" . static::$_dbIdFieldName . "` = " . $this->_dbId);
487
+      : classSupernova::db_query("UPDATE `{{".static::$_table."}}` SET {$set_string} WHERE `".static::$_dbIdFieldName."` = ".$this->_dbId);
488 488
   }
489 489
 
490 490
 }
Please login to merge, or discard this patch.