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

AllianceMemberList::getOwner()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
cc 3
eloc 4
c 0
b 0
f 0
nc 3
nop 0
dl 0
loc 8
rs 9.4285
ccs 0
cts 7
cp 0
crap 12
1
<?php
2
/**
3
 * Created by Gorlum 28.11.2017 11:16
4
 */
5
6
namespace Alliance;
7
8
9
use \db_mysql;
10
use Player\RecordPlayer;
11
12
class AllianceMemberList {
13
  /**
14
   * @var Alliance $alliance
15
   */
16
  protected $alliance;
17
  /**
18
   * @var db_mysql $db
19
   */
20
  protected $db;
21
22
  /**
23
   * @var AllianceMember[] $members
24
   */
25
  protected $members;
26
27
28
  /**
29
   * AllianceMemberList constructor.
30
   *
31
   * @param db_mysql $db
32
   * @param Alliance $alliance
33
   */
34
  public function __construct(db_mysql $db, Alliance $alliance) {
35
    $this->alliance = $alliance;
36
    $this->db = $db;
37
38
    foreach (RecordPlayer::findAll(['ally_id' => $this->alliance->id]) as $member) {
39
      $this->members[] = new AllianceMember($this->alliance, $member);
40
    }
41
//    die('here');
0 ignored issues
show
Unused Code Comprehensibility introduced by
84% 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...
42
43
//      $this->members = db_user_list("`ally_id`= {$allyId_safe} ORDER BY `ally_rank_id`", false,
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...
44
//        'id, username, galaxy, system, planet, onlinetime, ally_rank_id, ally_register_time, total_points');
45
//    foreach (db_user_list("`ally_id`= {$allyId_safe} ORDER BY `ally_rank_id`", false,
46
//      'id, username, galaxy, system, planet, onlinetime, ally_rank_id, ally_register_time, total_points') as $player) {
47
//      var_dump($player);
48
//      die();
49
//    }
50
//    foreach (db_user_list("`ally_id`= {$allyId_safe} ORDER BY `ally_rank_id`", false,
51
//      'id, username, galaxy, system, planet, onlinetime, ally_rank_id, ally_register_time, total_points') as $player) {
52
//      var_dump($player);
53
//      die();
54
//    }
55
56
  }
57
58
  /**
59
   * Get ally's owner
60
   *
61
   * @return AllianceMember|null
62
   */
63
  public function getOwner() {
64
    foreach ($this->members as $member) {
65
      if ($member->isOwner()) {
66
        return $member;
67
      }
68
    }
69
70
    return null;
71
  }
72
73
  /**
74
   * @return array
75
   */
76
  public function asPtl() {
77
    $result = [];
78
    if ($this->isEmpty()) {
79
      return $result;
80
    }
81
82
    foreach ($this->members as $member) {
83
      $result[] = $member->asPtl();
84
    }
85
86
    return $result;
87
  }
88
89
  /**
90
   * @return bool
91
   */
92
  public function isEmpty() {
93
    return empty($this->members);
94
  }
95
96
  /**
97
   * @param int|float|string $id
98
   *
99
   * @return AllianceMember|null
100
   */
101
  public function getById($id) {
102
    foreach ($this->members as $member) {
103
      if ($member->getPlayerId() == $id) {
104
        return $member;
105
      }
106
    }
107
108
    return null;
109
  }
110
111
}
112