Completed
Push — work-fleets ( d28adc...7496c9 )
by SuperNova.WS
06:01
created

BuddyView   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 75
rs 10
ccs 0
cts 49
cp 0
wmc 8
lcom 0
cbo 5

1 Method

Rating   Name   Duplication   Size   Complexity  
C makeTemplate() 0 65 8
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
    $result = array();
21
    try {
22
      sn_db_transaction_start();
23
24
      $cBuddy = new BuddyRoutingParams();
25
26
      $cBuddy->gc = $gc;
27
      $cBuddy->buddy_id = sys_get_param_id('buddy_id');
28
      $cBuddy->mode = sys_get_param_str('mode');
29
      $cBuddy->newFriendIdSafe = sys_get_param_id('request_user_id');
30
      $cBuddy->new_friend_name_unsafe = sys_get_param_str_unsafe('request_user_name');
31
      $cBuddy->new_request_text_unsafe = sys_get_param_str_unsafe('request_text');
32
      $cBuddy->playerArray = $user;
33
34
      $cBuddy->playerId = function (BuddyRoutingParams $cBuddy) {
35
        return $cBuddy->playerArray['id'];
36
      };
37
      $cBuddy->playerName = function (BuddyRoutingParams $cBuddy) {
38
        return $cBuddy->playerArray['username'];
39
      };
40
      $cBuddy->playerNameAndCoordinates = function (BuddyRoutingParams $cBuddy) {
41
        return "{$cBuddy->playerArray['username']} " . uni_render_coordinates($cBuddy->playerArray);
42
      };
43
44
      $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...
45
    } catch (BuddyException $e) {
46
      $exceptionCode = \ResultMessages::parseException($e, $result);
47
48
      $exceptionCode == ERR_NONE ? sn_db_transaction_commit() : sn_db_transaction_rollback();
49
    }
50
    sn_db_transaction_rollback();
51
    unset($buddy);
52
53
    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...
54
55
    foreach (BuddyModel::db_buddy_list_by_user($gc->db, $user['id']) as $row) {
56
      $row['BUDDY_REQUEST'] = sys_bbcodeParse($row['BUDDY_REQUEST']);
57
58
      $row['BUDDY_ACTIVE'] = $row['BUDDY_STATUS'] == BUDDY_REQUEST_ACTIVE;
59
      $row['BUDDY_DENIED'] = $row['BUDDY_STATUS'] == BUDDY_REQUEST_DENIED;
60
      $row['BUDDY_INCOMING'] = $row['BUDDY_OWNER_ID'] == $user['id'];
61
      $row['BUDDY_ONLINE'] = floor((SN_TIME_NOW - $row['onlinetime']) / 60);
62
63
      $template_result['.']['buddy'][] = $row;
64
    }
65
66
    $template_result += array(
67
      'PAGE_HEADER'       => $playerLocale['buddy_buddies'],
68
      'PAGE_HINT'         => $playerLocale['buddy_hint'],
69
      'USER_ID'           => $user['id'],
70
      'REQUEST_USER_ID'   => isset($new_friend_row['id']) ? $new_friend_row['id'] : 0,
0 ignored issues
show
Bug introduced by
The variable $new_friend_row seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
71
      'REQUEST_USER_NAME' => isset($new_friend_row['username']) ? $new_friend_row['username'] : '',
72
    );
73
74
    $template_result['.']['result'] = is_array($template_result['.']['result']) ? $template_result['.']['result'] : array();
75
    $template_result['.']['result'] += $result;
76
77
    $template = gettemplate('buddy', true);
78
    $template->assign_recursive($template_result);
79
80
    return $template;
81
  }
82
83
}
84