Passed
Pull Request — master (#35)
by
unknown
12:58
created

TransformsStates::fromDevOpsState()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

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