Passed
Pull Request — master (#15)
by Thijs
19:26 queued 09:27
created

TransformsTeams::fromDevOpsTeam()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 6
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 9
rs 10
1
<?php
2
3
namespace TestMonitor\DevOps\Transforms;
4
5
use TestMonitor\DevOps\Validator;
6
use TestMonitor\DevOps\Resources\Team;
7
8
trait TransformsTeams
9
{
10
    /**
11
     * @param array $teams
12
     * @param string $projectId
13
     *
14
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
15
     *
16
     * @return \TestMonitor\DevOps\Resources\Team[]
17
     */
18
    protected function fromDevOpsTeams($teams, string $projectId): array
19
    {
20
        Validator::isArray($teams);
21
22
        return array_map(function ($team) use ($projectId) {
23
            return $this->fromDevOpsTeam($team, $projectId);
24
        }, $teams);
25
    }
26
27
    /**
28
     * @param array $team
29
     * @param string $projectId
30
     *
31
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
32
     *
33
     * @return \TestMonitor\DevOps\Resources\Team
34
     */
35
    protected function fromDevOpsTeam($team, string $projectId): Team
36
    {
37
        Validator::keysExists($team, ['id', 'name']);
38
39
        return new Team([
40
            'id' => $team['id'],
41
            'name' => $team['name'],
42
            'description' => $team['description'],
43
            'path' => "{$projectId}\\{$team['name']}",
44
        ]);
45
    }
46
}
47