Passed
Pull Request — master (#26)
by Thijs
09:57
created

TransformsAccounts::fromDevOpsAccounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace TestMonitor\DevOps\Transforms;
4
5
use TestMonitor\DevOps\Validator;
6
use TestMonitor\DevOps\Resources\Account;
7
use TestMonitor\DevOps\Resources\Profile;
8
9
trait TransformsAccounts
10
{
11
    /**
12
     * @param array $accounts
13
     *
14
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
15
     *
16
     * @return \TestMonitor\DevOps\Resources\Account[]
17 1
     */
18
    protected function fromDevOpsAccounts($accounts): array
19 1
    {
20
        Validator::isArray($accounts);
21 1
22 1
        return array_map(function ($account) {
23 1
            return $this->fromDevOpsAccount($account);
24
        }, $accounts);
25
    }
26
27
    /**
28
     * @param array $account
29
     *
30
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
31
     *
32
     * @return \TestMonitor\DevOps\Resources\Account
33 1
     */
34
    protected function fromDevOpsAccount($account): Account
35 1
    {
36
        Validator::keysExists($account, ['AccountId', 'AccountName']);
37 1
38 1
        return new Account([
39 1
            'id' => $account['AccountId'],
40 1
            'name' => $account['AccountName'],
41
        ]);
42
    }
43
44
    /**
45
     * @param array $profile
46
     *
47
     * @return \TestMonitor\DevOps\Resources\Profile
48
     */
49
    protected function fromDevOpsProfile($profile): Profile
50
    {
51
        Validator::keysExists($profile, ['id', 'displayName', 'emailAddress']);
52
53
        return new Profile([
54
            'id' => $profile['id'],
55
            'name' => $profile['displayName'],
56
            'email' => $profile['emailAddress'],
57
        ]);
58
    }
59
60
}
61