Passed
Push — master ( 6aff30...239879 )
by Thijs
09:39
created

TransformsWorkItems::toDevOpsWorkItem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 1
eloc 13
c 2
b 1
f 0
nc 1
nop 1
dl 0
loc 20
ccs 10
cts 10
cp 1
crap 1
rs 9.8333
1
<?php
2
3
namespace TestMonitor\DevOps\Transforms;
4
5
use TestMonitor\DevOps\Validator;
6
use TestMonitor\DevOps\Resources\WorkItem;
7
8
trait TransformsWorkItems
9
{
10
    /**
11
     * @param \TestMonitor\DevOps\Resources\WorkItem $workItem
12
     * @return array
13
     */
14 2
    protected function toDevOpsWorkItem(WorkItem $workItem): array
15
    {
16
        return [
17
            [
18 2
                'op' => 'add',
19 2
                'path' => '/fields/System.Title',
20
                'from' => null,
21 2
                'value' => $workItem->title,
22
            ],
23
            [
24 2
                'op' => 'add',
25 2
                'path' => '/fields/System.Description',
26
                'from' => null,
27 2
                'value' => $workItem->description,
28
            ],
29
            [
30 2
                'op' => 'add',
31 2
                'path' => '/fields/Microsoft.VSTS.TCM.ReproSteps',
32
                'from' => null,
33 2
                'value' => $workItem->stepsToReproduce,
34
            ],
35
        ];
36
    }
37
38
    /**
39
     * @param array $workItem
40
     *
41
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
42
     *
43
     * @return \TestMonitor\DevOps\Resources\WorkItem
44
     */
45 2
    protected function fromDevOpsWorkItem(array $workItem): WorkItem
46
    {
47 2
        Validator::keyExists($workItem, 'fields');
48
49 2
        return new WorkItem([
50 2
            'id' => $workItem['id'] ?? '',
51 2
            'title' => $workItem['fields']['System.Title'],
52 2
            'description' => $workItem['fields']['System.Description'] ?? '',
53 2
            'workItemType' => $workItem['fields']['System.WorkItemType'],
54 2
            'stepsToReproduce' => $workItem['fields']['Microsoft.VSTS.TCM.ReproSteps'] ?? '',
55 2
            'url' => $workItem['_links']['html']['href'] ?? '',
56
        ]);
57
    }
58
}
59