Completed
Push — master ( 361a8c...49bd9d )
by Thijs
16s queued 13s
created

TransformsAccounts   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDevOpsAccount() 0 7 1
A fromDevOpsAccounts() 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
     */
18 1
    protected function fromDevOpsAccounts($accounts): array
19
    {
20 1
        Validator::isArray($accounts);
21
22 1
        return array_map(function ($account) {
23 1
            return $this->fromDevOpsAccount($account);
24 1
        }, $accounts);
25
    }
26
27
    /**
28
     * @param array $account
29
     *
30
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
31
     *
32
     * @return \TestMonitor\DevOps\Resources\Account
33
     */
34 1
    protected function fromDevOpsAccount($account): Account
35
    {
36 1
        Validator::keysExists($account, ['AccountId', 'AccountName']);
37
38 1
        return new Account([
39 1
            'id' => $account['AccountId'],
40 1
            'name' => $account['AccountName'],
41 1
        ]);
42
    }
43
44
    /**
45
     * @param array $profile
46
     * @return \TestMonitor\DevOps\Resources\Profile
47
     */
48 2
    protected function fromDevOpsProfile($profile): Profile
49
    {
50 2
        Validator::keysExists($profile, ['id', 'displayName', 'emailAddress']);
51
52 2
        return new Profile([
53 2
            'id' => $profile['id'],
54 2
            'name' => $profile['displayName'],
55 2
            'email' => $profile['emailAddress'],
56 2
        ]);
57
    }
58
}
59