StatSubAccounts::list()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 27

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 27
rs 9.488
c 0
b 0
f 0
cc 3
nc 3
nop 0
1
<?php
2
3
namespace SchulzeFelix\Stat\Api;
4
5
use Illuminate\Support\Collection;
6
use SchulzeFelix\Stat\Objects\StatSubAccount;
7
8
class StatSubAccounts extends BaseStat
9
{
10
    /**
11
     * @return Collection
12
     */
13
    public function list(): Collection
14
    {
15
        $response = $this->performQuery('subaccounts/list');
16
17
        $subaccounts = collect();
18
19
        if (! isset($response['User'])) {
20
            return $subaccounts;
21
        }
22
23
        if (isset($response['User']['Id'])) {
24
            $subaccounts->push($response['User']);
25
        } else {
26
            $subaccounts = collect($response['User']);
27
        }
28
29
        $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...
30
            return new StatSubAccount([
31
                'id' => $item['Id'],
32
                'login' => $item['Login'],
33
                'api_key' => $item['ApiKey'],
34
                'created_at' => $item['CreatedAt'],
35
            ]);
36
        });
37
38
        return $subaccounts;
39
    }
40
}
41