MemberList::elders()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace ClashOfClans\Api\Clan;
4
5
use ClashOfClans\Api\AbstractResource;
6
7
class MemberList extends AbstractResource
8
{
9
10
    protected $casts = [
11
        'all' => Player::class
12
    ];
13
14
    /**
15
     * @return Player|null
16
     */
17
    public function first()
18
    {
19
        return $this->get(0);
20
    }
21
22
    /**
23
     * @return Player|null
24
     */
25
    public function nth($i)
26
    {
27
        return $this->get($i);
28
    }
29
30
    /**
31
     * @return array
32
     */
33
    public function all()
34
    {
35
        return $this->get();
36
    }
37
38
    /**
39
     * @return Player
40
     */
41
    public function leader()
42
    {
43
        $members = $this->all();
44
45
        return array_filter($members, function ($player) {
46
            return $player->isLeader();
47
        })[0];
48
    }
49
50
    /**
51
     * @return array
52
     */
53
    public function elders()
54
    {
55
        $members = $this->all();
56
57
        return array_filter($members, function ($player) {
58
            return $player->isElder();
59
        });
60
    }
61
62
    /**
63
     * @return array
64
     */
65
    public function coLeaders()
66
    {
67
        $members = $this->all();
68
69
        return array_filter($members, function ($player) {
70
            return $player->isCoLeader();
71
        });
72
    }
73
}
74