Completed
Push — work-fleets ( 7496c9...2bd11a )
by SuperNova.WS
06:07
created

BuddyView   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 74
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
dl 0
loc 74
rs 10
c 2
b 0
f 0
ccs 0
cts 49
cp 0
wmc 6
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
B makeTemplate() 0 64 6
1
<?php
2
/**
3
 * Created by Gorlum 30.07.2016 20:52
4
 */
5
namespace Buddy;
6
use Common\GlobalContainer;
7
8
9
class BuddyView {
10
11
  /**
12
   * @param GlobalContainer $gc
13
   * @param array           $user
14
   *
15
   * @return \template
16
   */
17
  public function makeTemplate($gc, $user) {
18
    $playerLocale = $gc->localePlayer;
19
20
    $cBuddy = new BuddyRoutingParams();
21
22
    $cBuddy->gc = $gc;
23
    $cBuddy->buddy_id = sys_get_param_id('buddy_id');
24
    $cBuddy->mode = sys_get_param_str('mode');
25
    $cBuddy->newFriendIdSafe = sys_get_param_id('request_user_id');
26
    $cBuddy->new_friend_name_unsafe = sys_get_param_str_unsafe('request_user_name');
27
    $cBuddy->new_request_text_unsafe = sys_get_param_str_unsafe('request_text');
28
    $cBuddy->playerArray = $user;
29
30
    $cBuddy->playerId = function (BuddyRoutingParams $cBuddy) {
31
      return $cBuddy->playerArray['id'];
32
    };
33
    $cBuddy->playerName = function (BuddyRoutingParams $cBuddy) {
34
      return $cBuddy->playerArray['username'];
35
    };
36
    $cBuddy->playerNameAndCoordinates = function (BuddyRoutingParams $cBuddy) {
37
      return "{$cBuddy->playerArray['username']} " . uni_render_coordinates($cBuddy->playerArray);
38
    };
39
40
    $result = array();
41
    sn_db_transaction_start();
42
    try {
43
      $gc->buddy->route($cBuddy);
0 ignored issues
show
Bug introduced by
The method route cannot be called on $gc->buddy (of type callable).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
44
    } catch (BuddyException $e) {
45
      $exceptionCode = \ResultMessages::parseException($e, $result);
46
47
      $exceptionCode == ERR_NONE ? sn_db_transaction_commit() : sn_db_transaction_rollback();
48
    }
49
    sn_db_transaction_rollback();
50
    unset($buddy);
51
52
    empty($template_result) ? $template_result = array() : false;
0 ignored issues
show
Bug introduced by
The variable $template_result seems only to be defined at a later point. As such the call to empty() seems to always evaluate to true.

This check marks calls to isset(...) or empty(...) that are found before the variable itself is defined. These will always have the same result.

This is likely the result of code being shifted around. Consider removing these calls.

Loading history...
53
54
    foreach (BuddyModel::db_buddy_list_by_user($gc->db, $user['id']) as $row) {
55
      $row['BUDDY_REQUEST'] = sys_bbcodeParse($row['BUDDY_REQUEST']);
56
57
      $row['BUDDY_ACTIVE'] = $row['BUDDY_STATUS'] == BUDDY_REQUEST_ACTIVE;
58
      $row['BUDDY_DENIED'] = $row['BUDDY_STATUS'] == BUDDY_REQUEST_DENIED;
59
      $row['BUDDY_INCOMING'] = $row['BUDDY_OWNER_ID'] == $user['id'];
60
      $row['BUDDY_ONLINE'] = floor((SN_TIME_NOW - $row['onlinetime']) / 60);
61
62
      $template_result['.']['buddy'][] = $row;
63
    }
64
65
    $template_result += array(
66
      'PAGE_HEADER'       => $playerLocale['buddy_buddies'],
67
      'PAGE_HINT'         => $playerLocale['buddy_hint'],
68
      'USER_ID'           => $user['id'],
69
      'REQUEST_USER_ID'   => $cBuddy->newFriendIdSafe,
70
      'REQUEST_USER_NAME' => $cBuddy->new_friend_name_unsafe,
71
    );
72
73
    $template_result['.']['result'] = is_array($template_result['.']['result']) ? $template_result['.']['result'] : array();
74
    $template_result['.']['result'] += $result;
75
76
    $template = gettemplate('buddy', true);
77
    $template->assign_recursive($template_result);
78
79
    return $template;
80
  }
81
82
}
83