Completed
Push — trunk ( 5a98ee...c2d255 )
by SuperNova.WS
04:09
created

sn_ube_simulator_fleet_converter()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 19
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
nc 1
nop 2
dl 0
loc 19
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
function sn_ube_simulator_encode_replay($combat, $type) {
4
  $strPacked = "{$type}!";
5
6
  foreach ($combat as $fleetID => $fleetCompress) {
7
    foreach ($fleetCompress as $key => $value) {
8
      $value = intval($value);
9
      $strPacked .= "{$key},{$value};";
10
    }
11
    $strPacked .= '!';
12
  }
13
14
  return $strPacked;
15
}
16
17
function sn_ube_simulator_decode_replay($str_data) {
18
  $fleet_id = 0;
19
20
  $arr_data_unpacked = explode('!', $str_data);
21
  foreach ($arr_data_unpacked as $data_piece) {
22
    if (!$data_piece) {
23
      continue;
24
    }
25
26
    if ($data_piece == 'A' || $data_piece == 'D') {
27
      $fleet_type = $data_piece;
28
      continue;
29
    }
30
31
    $arr_unit_strings = explode(';', $data_piece);
32
    foreach ($arr_unit_strings as $str_unit_string) {
33
      if (!$str_unit_string) {
34
        continue;
35
      }
36
37
      $arr_unit_data = explode(',', $str_unit_string);
38
      if ($arr_unit_data[1]) {
39
        $unpacked[$fleet_type][$fleet_id][$arr_unit_data[0]] = intval($arr_unit_data[1]);
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $fleet_type does not seem to be defined for all execution paths leading up to this point.
Loading history...
40
      }
41
    }
42
43
    $fleet_id++;
44
  }
45
46
  return $unpacked;
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $unpacked does not seem to be defined for all execution paths leading up to this point.
Loading history...
47
}
48