Passed
Branch trunk (3f392c)
by SuperNova.WS
04:59
created

alliance.php (10 issues)

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 10 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 View Code Duplication
if (classSupernova::$config->game_mode == GAME_BLITZ) {
0 ignored issues
show
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
Bug Best Practice introduced by
The property game_mode does not exist on classConfig. Since you implemented __get, consider adding a @property annotation.
Loading history...
6
  messageBox($lang['sys_blitz_page_disabled'], $lang['sys_error'], 'overview.php', 10);
7
  die();
8
}
9
10
define('SN_IN_ALLY', true);
11
12
// Main admin page save themes
13
lng_include('alliance');
14
15
$mode = sys_get_param_str('mode');
16
17
if ($mode == 'ainfo') {
18
  include('includes/alliance/ali_info.inc');
19
}
20
21
if (!$user['ally_id']) {
22
  $user_request = doquery("SELECT * FROM {{alliance_requests}} WHERE `id_user` ='{$user['id']}' LIMIT 1;", '', true);
23
  if ($user_request['id_user']) {
24
    require('includes/alliance/ali_external_request.inc');
25
  } else {
26
    switch ($mode) {
27
      case 'search':
28
        require('includes/alliance/ali_external_search.inc');
29
      break;
30
31
      case 'apply':
32
        require('includes/alliance/ali_external_request.inc');
33
      break;
34
35
      case 'make':
36
        require('includes/alliance/ali_external_create_ally.inc');
37
      break;
38
39
      default:
40
        $parsetemplate = gettemplate('ali_external', true);
0 ignored issues
show
true of type true is incompatible with the type null|template expected by parameter $template of gettemplate(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

40
        $parsetemplate = gettemplate('ali_external', /** @scrutinizer ignore-type */ true);
Loading history...
41
        display($parsetemplate, $lang['alliance']);
42
      break;
43
    }
44
  }
45
}
46
47
\Alliance\Alliance::sn_ali_fill_user_ally($user);
0 ignored issues
show
Deprecated Code introduced by
The function Alliance\Alliance::sn_ali_fill_user_ally() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

47
/** @scrutinizer ignore-deprecated */ \Alliance\Alliance::sn_ali_fill_user_ally($user);
Loading history...
48
//$ally = doquery("SELECT * FROM {{alliance}} WHERE `id` ='{$user['ally_id']}'", '', true);
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
49
if (!isset($user['ally'])) {
50
  db_user_set_by_id($user['id'], "`ally_id` = null, `ally_name` = null, `ally_register_time` = 0, `ally_rank_id` = 0");
0 ignored issues
show
Deprecated Code introduced by
The function db_user_set_by_id() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

50
  /** @scrutinizer ignore-deprecated */ db_user_set_by_id($user['id'], "`ally_id` = null, `ally_name` = null, `ally_register_time` = 0, `ally_rank_id` = 0");
Loading history...
51
  messageBox($lang['ali_sys_notFound'], $lang['your_alliance'], 'alliance.php');
52
}
53
$ally = &$user['ally'];
54
/*
0 ignored issues
show
Unused Code Comprehensibility introduced by
56% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
55
$ally_rights = array(
56
  0 => 'name',
57
  1 => 'mail',
58
  2 => 'online',
59
  3 => 'invite',
60
  4 => 'kick',
61
  5 => 'admin',
62
  6 => 'forum',
63
  7 => 'diplomacy'
64
);
65
*/
66
$rights_old = array(
67
  0 => 'name',
68
  1 => 'mails',
69
  2 => 'onlinestatus',
70
  3 => 'bewerbungenbearbeiten',
71
  4 => 'kick',
72
  5 => 'rechtehand'
73
);
74
75
// This piece converting old ally data to new one
76
//  unset($ally['ranklist']);
77
if (!$ally['ranklist'] && $ally['ally_ranks']) {
78
  $ally_ranks = unserialize($ally['ally_ranks']);
79
  $i = 0;
80
  foreach ($ally_ranks as $rank_id => $rank) {
81
    foreach ($ally_rights as $key => $value) {
82
      $ranks[$i][$value] = $rank[$rights_old[$key]];
83
    }
84
    db_user_list_set_ally_deprecated_convert_ranks($user['ally_id'], $i, $rank_id);
0 ignored issues
show
Deprecated Code introduced by
The function db_user_list_set_ally_deprecated_convert_ranks() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

84
    /** @scrutinizer ignore-deprecated */ db_user_list_set_ally_deprecated_convert_ranks($user['ally_id'], $i, $rank_id);
Loading history...
85
    $i++;
86
  }
87
88
  if (!empty($ranks)) {
89
    ali_rank_list_save($ranks);
90
  }
91
}
92
93
$ranks = \Alliance\Alliance::ally_get_ranks($ally);
0 ignored issues
show
Deprecated Code introduced by
The function Alliance\Alliance::ally_get_ranks() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

93
$ranks = /** @scrutinizer ignore-deprecated */ \Alliance\Alliance::ally_get_ranks($ally);
Loading history...
94
95
$isAllyOwner = $ally['ally_owner'] == $user['id'];
96
$user_can_send_mails = $ranks[$user['ally_rank_id']]['mail'] || $isAllyOwner;
97
$userCanPostForum = $ranks[$user['ally_rank_id']]['forum'] || $isAllyOwner;
98
$user_onlinestatus = $ranks[$user['ally_rank_id']]['online'] || $isAllyOwner;
99
$user_admin_applications = $ranks[$user['ally_rank_id']]['invite'] || $isAllyOwner;
100
$user_can_kick = $ranks[$user['ally_rank_id']]['kick'] || $isAllyOwner;
101
$user_can_negotiate = $ranks[$user['ally_rank_id']]['diplomacy'] || $isAllyOwner;
102
$user_can_edit_rights = $user_admin = $ranks[$user['ally_rank_id']]['admin'] || $isAllyOwner;
103
104
$edit = sys_get_param_str('edit');
105
ally_pre_call();
106
switch ($mode) {
107
  case 'admin':
108
    if (!array_key_exists($edit, $sn_ali_admin_internal)) {
109
      $edit = 'default';
110
    }
111
    if ($sn_ali_admin_internal[$edit]['include']) {
112
      require("includes/{$sn_ali_admin_internal[$edit]['include']}");
113
    }
114
    if (isset($sn_ali_admin_internal[$edit]['function']) && is_callable($sn_ali_admin_internal[$edit]['function'])) {
115
      call_user_func($sn_ali_admin_internal[$edit]['function']);
116
    }
117
  break;
118
119
  case 'memberslist':
120
    require('includes/alliance/ali_internal_members.inc');
121
  break;
122
  case 'circular':
123
    require('includes/alliance/ali_internal_admin_mail.inc');
124
  break;
125
  default:
126
    require('includes/alliance/ali_info.inc');
127
  break;
128
}
129
130
function ally_pre_call() {
131
  $func_args = func_get_args();
132
133
  return sn_function_call('ally_pre_call', $func_args);
134
}
135