Completed
Push — master ( ec18ae...5b38d7 )
by Felix
10:07
created

StatSubAccounts::list()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 28
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 28
rs 8.8571
c 0
b 0
f 0
cc 3
eloc 16
nc 3
nop 0
1
<?php
2
3
namespace SchulzeFelix\Stat\Api;
4
5
use Carbon\Carbon;
6
use Carbon\CarbonInterval;
7
use Illuminate\Support\Collection;
8
use SchulzeFelix\Stat\Objects\StatSubAccount;
9
10
class StatSubAccounts extends BaseStat
11
{
12
13
    /**
14
     * @return Collection
15
     */
16
    public function list() : Collection
17
    {
18
        $response = $this->performQuery('subaccounts/list');
19
20
        $subaccounts = collect();
21
22
        if( ! isset($response['User']) ){
23
            return $subaccounts;
24
        }
25
26
        if(isset($response['User']['Id'])) {
27
            $subaccounts->push($response['User']);
28
        } else {
29
            $subaccounts = collect($response['User']);
30
        }
31
32
        $subaccounts->transform(function ($item, $key) {
0 ignored issues
show
Unused Code introduced by
The parameter $key is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
33
34
            return new StatSubAccount([
35
                'id' => $item['Id'],
36
                'login' => $item['Login'],
37
                'api_key' => $item['ApiKey'],
38
                'created_at' => $item['CreatedAt'],
39
            ]);
40
        });
41
42
        return $subaccounts;
43
    }
44
45
}
46