Completed
Push — master ( b1d0ff...f51f35 )
by Toni
04:43
created

MemberList::coLeaders()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

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