Passed
Push — trunk ( 338765...433e05 )
by SuperNova.WS
04:23
created

flyingFleetsModel()   C

Complexity

Conditions 7
Paths 6

Size

Total Lines 22
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 14
c 0
b 0
f 0
nc 6
nop 2
dl 0
loc 22
rs 6.9811
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 16 and the first side effect is on line 3.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
3
include('common.' . substr(strrchr(__FILE__, '.'), 1));
4
5
global $user, $debug;
0 ignored issues
show
Compatibility Best Practice introduced by
Use of global functionality is not recommended; it makes your code harder to test, and less reusable.

Instead of relying on global state, we recommend one of these alternatives:

1. Pass all data via parameters

function myFunction($a, $b) {
    // Do something
}

2. Create a class that maintains your state

class MyClass {
    private $a;
    private $b;

    public function __construct($a, $b) {
        $this->a = $a;
        $this->b = $b;
    }

    public function myFunction() {
        // Do something
    }
}
Loading history...
6
7
lng_include('overview');
8
lng_include('fleet');
9
10
/**
11
 * @param int|string $userId
12
 * @param debug      $debug
13
 *
14
 * @throws Exception
15
 */
16
function flyingFleetsModel($userId, $debug) {
17
  if (empty($_POST['return']) || !is_array($_POST['return'])) {
18
    return;
19
  }
20
21
  foreach ($_POST['return'] as $fleet_id) {
22
    if (empty($fleet_id = idval($fleet_id))) {
23
      continue;
24
    }
25
26
    sn_db_transaction_start();
27
    if (empty($fleet = SN::$gc->repoV2->getFleet($fleet_id))) {
28
      sn_db_transaction_rollback();
29
      continue;
30
    }
31
32
    if (!$fleet->returnForce($userId)) {
33
      $debug->warning('Trying to return fleet that not belong to user', 'Hack attempt', 302, ['base_dump' => true, 'fleet_row' => $fleet->asArray()]);
34
      sn_db_transaction_rollback();
35
      die('Hack attempt 302');
0 ignored issues
show
Best Practice introduced by
Using exit here is not recommended.

In general, usage of exit should be done with care and only when running in a scripting context like a CLI script.

Loading history...
36
    }
37
    sn_db_transaction_commit();
38
  }
39
}
40
41
/** @noinspection PhpUnhandledExceptionInspection */
42
flyingFleetsModel($user['id'], $debug);
43
44
if (!$planetrow) {
45
  messageBox($lang['fl_noplanetrow'], $lang['fl_error']);
46
}
47
48
$template = gettemplate('flying_fleets', true);
49
50
$i = 0;
51
$fleet_list = fleet_list_by_owner_id($user['id']);
52
foreach ($fleet_list as $fleet_id => $fleet_row) {
53
  $i++;
54
  $fleet_data = tpl_parse_fleet_db($fleet_row, $i, $user);
55
56
  $template->assign_block_vars('fleets', $fleet_data['fleet']);
57
58
  foreach ($fleet_data['ships'] as $ship_data) {
59
    $template->assign_block_vars('fleets.ships', $ship_data);
60
  }
61
}
62
63
$MaxExpeditions = get_player_max_expeditons($user);
64
$FlyingExpeditions = fleet_count_flying($user['id'], MT_EXPLORE);
65
$fleet_flying_amount = fleet_count_flying($user['id'], MT_NONE);
66
67
$template->assign_vars(array(
68
  'FLEETS_FLYING'      => $fleet_flying_amount,
69
  'FLEETS_MAX'         => GetMaxFleets($user),
70
  'EXPEDITIONS_FLYING' => $FlyingExpeditions,
71
  'EXPEDITIONS_MAX'    => $MaxExpeditions,
72
));
73
74
display($template, $lang['fl_title']);
75