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

TransformsAccounts::fromDevOpsAccount()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 5
cts 5
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
     */
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