Completed
Pull Request — master (#5)
by Thijs
01:15
created

TransformsAccounts::fromDevOpsAccounts()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace TestMonitor\DevOps\Transforms;
4
5
use TestMonitor\DevOps\Validator;
6
use TestMonitor\DevOps\Resources\Account;
7
8 View Code Duplication
trait TransformsAccounts
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
9
{
10
    /**
11
     * @param array $accounts
12
     *
13 1
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
14
     * @return \TestMonitor\DevOps\Resources\Account[]
15 1
     */
16 1
    protected function fromDevOpsAccounts($accounts): array
17 1
    {
18
        Validator::isArray($accounts);
19
20
        return array_map(function ($account) {
21
            return $this->fromDevOpsAccount($account);
22
        }, $accounts);
23
    }
24
25
    /**
26
     * @param array $account
27
     *
28
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
29
     * @return \TestMonitor\DevOps\Resources\Account
30
     */
31
    protected function fromDevOpsAccount($account): Account
32
    {
33
        Validator::keysExists($account, ['AccountId', 'AccountName']);
34
35
        return new Account([
36
            'id' => $account['AccountId'],
37
            'name' => $account['AccountName'],
38
        ]);
39
    }
40
}
41