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

TransformsAccounts   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 48
ccs 11
cts 11
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDevOpsAccounts() 0 7 1
A fromDevOpsAccount() 0 7 1
A fromDevOpsProfile() 0 8 1
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