Completed
Push — work-fleets ( 0f036f...867546 )
by SuperNova.WS
06:49
created

BuddyContainer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 21 1
A isEmpty() 0 10 4
1
<?php
2
3
namespace Buddy;
4
5
use Common\GlobalContainer;
6
7
/**
8
 * Class BuddyContainer
9
 *
10
 * @method BuddyModel getModel()
11
 *
12
 * @property int|float|string $playerSenderId Who makes buddy request
13
 * @property int|float|string $playerOwnerId To whom this buddy request made
14
 * @property int              $buddyStatusId Current buddy request status
15
 * @property string           $requestText Request text
16
 *
17
 * @property int|float        $buddy_id
18
 * @property string           $mode
19
 * @property int|float        $newFriendIdSafe
20
 * @property string           $new_friend_name_unsafe
21
 * @property array            $playerArray - optional. Unfortunately - we need full record to get name and capital coordinates for buddy message
22
 * @property int|float        $playerId
23
 * @property string           $playerName
24
 * @property string           $playerNameAndCoordinates
25
 *
26
 * @package Buddy
27
 */
28
class BuddyContainer extends \EntityContainer {
29
  /**
30
   * @var BuddyModel $model
31
   */
32
  protected $model;
33
34
  protected static $exceptionClass = 'BuddyException';
35
  protected static $modelClass = 'Buddy\BuddyModel';
36
37
  /**
38
   * Name of table for this entity
39
   *
40
   * @var string $tableName
41
   */
42
  protected $tableName = 'buddy';
43
  /**
44
   * Name of key field field in this table
45
   *
46
   * @var string $idField
47
   */
48
  protected $idField = 'BUDDY_ID';
49
  /**
50
   * Property list
51
   *
52
   * @var array $properties
53
   */
54
  protected $properties = array(
55
    'dbId'           => array(
56
      P_DB_FIELD => 'BUDDY_ID',
57
    ),
58
    'playerSenderId' => array(
59
      P_DB_FIELD => 'BUDDY_SENDER_ID',
60
    ),
61
    'playerOwnerId'  => array(
62
      P_DB_FIELD => 'BUDDY_OWNER_ID',
63
    ),
64
    'buddyStatusId'  => array(
65
      P_DB_FIELD => 'BUDDY_STATUS',
66
    ),
67
    'requestText'    => array(
68
      P_DB_FIELD => 'BUDDY_REQUEST',
69
    ),
70
  );
71
72
  /**
73
   * BuddyContainer constructor.
74
   *
75
   * @param GlobalContainer $gc
76
   * @param array           $user
77
   */
78
  public function __construct($gc, $user = array()) {
79
    parent::__construct($gc);
80
81
    $this->buddy_id = sys_get_param_id('buddy_id');
82
    $this->mode = sys_get_param_str('mode');
83
    $this->newFriendIdSafe = sys_get_param_id('request_user_id');
84
    $this->new_friend_name_unsafe = sys_get_param_str_unsafe('request_user_name');
85
    $this->requestText = sys_get_param_str_unsafe('request_text');
86
87
    $this->playerArray = $user;
88
89
    $this->playerId = function (BuddyContainer $cBuddy) {
90
      return $cBuddy->playerArray['id'];
91
    };
92
    $this->playerName = function (BuddyContainer $cBuddy) {
93
      return $cBuddy->playerArray['username'];
94
    };
95
    $this->playerNameAndCoordinates = function (BuddyContainer $cBuddy) {
96
      return "{$cBuddy->playerArray['username']} " . uni_render_coordinates($cBuddy->playerArray);
97
    };
98
  }
99
100
  public function isEmpty() {
101
    return
102
      $this->buddyStatusId === null
103
      ||
104
      $this->buddyStatusId === BUDDY_REQUEST_NOT_SET
105
      ||
106
      empty($this->playerSenderId)
107
      ||
108
      empty($this->playerOwnerId);
109
  }
110
111
}
112