Passed
Push — trunk ( 780f52...305828 )
by SuperNova.WS
04:36
created

sn_admin_ally_view_one()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 12
c 1
b 0
f 0
nc 2
nop 2
dl 0
loc 20
rs 9.4285
1
<?php
2
/**
3
 * Created by Gorlum 15.06.2017 10:08
4
 */
5
6
function sn_admin_ally_model($template = null) {
7
  define('IN_ADMIN', true);
8
  lng_include('admin');
9
  messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
10
11
  global $template_result;
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...
12
13
  if (
14
    ($allyId = sys_get_param_id('ally_id'))
15
    &&
16
    (sys_get_param_str('action') == 'pass')
17
    &&
18
    ($newOwnerId = sys_get_param_id('new_owner_id'))
19
  ) {
20
    try {
21
      if (empty($alliance = \Alliance\Alliance::findById($allyId))) {
0 ignored issues
show
Bug introduced by
It seems like $allyId can also be of type array; however, parameter $recordId of DBAL\ActiveRecordAbstractIndexed::findById() does only seem to accept integer|string, maybe add an additional type check? ( Ignorable by Annotation )

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

21
      if (empty($alliance = \Alliance\Alliance::findById(/** @scrutinizer ignore-type */ $allyId))) {
Loading history...
22
        throw new \Exception('{ Альянс с указанным ID не найден }', ERR_ERROR);
23
      }
24
      if (empty($newOwnerMember = $alliance->getMemberList()->getById($newOwnerId))) {
0 ignored issues
show
Bug introduced by
It seems like $newOwnerId can also be of type array; however, parameter $id of Alliance\AllianceMemberList::getById() does only seem to accept integer|string|double, maybe add an additional type check? ( Ignorable by Annotation )

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

24
      if (empty($newOwnerMember = $alliance->getMemberList()->getById(/** @scrutinizer ignore-type */ $newOwnerId))) {
Loading history...
25
        throw new \Exception('{ Новый владелец Альянса не найден }', ERR_ERROR);
26
      }
27
28
      $alliance->pass($newOwnerMember);
29
30
      $template_result['.']['result'][] = [
31
        'MESSAGE' => '{ Альянс успешно передан другому игроку }',
32
        'STATUS'  => ERR_NONE,
33
      ];
34
    } catch (Exception $e) {
35
      $template_result['.']['result'][] = [
36
        'MESSAGE' => $e->getMessage(),
37
        'STATUS'  => $e->getCode(),
38
      ];
39
    }
40
  }
41
42
  return $template;
43
}
44
45
function sn_admin_ally_view_one($template = null, $allyId) {
46
  global $template_result;
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...
47
48
  messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
49
50
  $template = gettemplate('admin/admin_ally_one', $template);
51
  if (empty($alliance = \Alliance\Alliance::findById($allyId))) {
52
    return $template;
53
  }
54
55
  $template_result['.']['members'] = $alliance->getMemberList()->asPtl();
56
57
  $template->assign_recursive($alliance->asPtl());
58
  $template->assign_vars([
59
    'PAGE_HEADER'                    => '{ Альянс }' . ' [' . $alliance->id . '] ' . ' [' . $alliance->tag . '] ' . $alliance->name,
60
    'ALLIANCE_HEAD_INACTIVE_TIMEOUT' => ALLIANCE_HEAD_INACTIVE_TIMEOUT,
61
    'SN_TIME_NOW'                    => SN_TIME_NOW,
62
  ]);
63
64
  return $template;
65
}
66
67
function sn_admin_ally_view_all($template = null) {
68
  messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
69
70
  $template = gettemplate('admin/admin_ally_all', $template);
71
72
  foreach (\Alliance\Alliance::findAll([]) as $alliance) {
73
    $template->assign_block_vars('ally', $alliance->asPtl());
74
  };
75
76
  $template->assign_vars([
77
    'PAGE_HEADER' => classSupernova::$lang['admin_ally_list'],
78
  ]);
79
80
  return $template;
81
}
82
83
function sn_admin_ally_view($template = null) {
84
  define('IN_ADMIN', true);
85
  lng_include('admin');
86
  messageBoxAdminAccessDenied(AUTH_LEVEL_ADMINISTRATOR);
87
88
  $allyId = sys_get_param_id('ally_id');
89
90
  return $allyId ? sn_admin_ally_view_one($template, $allyId) : sn_admin_ally_view_all($template);
91
}
92