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

TransformsAttachments   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
c 1
b 0
f 0
dl 0
loc 37
ccs 10
cts 10
cp 1
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromDevOpsAttachment() 0 7 1
A toDevOpsAttachment() 0 11 1
1
<?php
2
3
namespace TestMonitor\DevOps\Transforms;
4
5
use TestMonitor\DevOps\Validator;
6
use TestMonitor\DevOps\Resources\Attachment;
7
8
trait TransformsAttachments
9
{
10
    /**
11
     * @param string $attachmentUrl
12
     * @return array
13
     */
14 1
    protected function toDevOpsAttachment(string $attachmentUrl): array
15
    {
16
        return [
17
            [
18 1
                'op' => 'add',
19 1
                'path'=> '/relations/-',
20
                'value'=> [
21 1
                    'rel' => 'AttachedFile',
22 1
                    'url' => $attachmentUrl,
23
                    'attributes' => [
24
                        'comment' => '',
25
                    ],
26
                ],
27
            ],
28
        ];
29
    }
30
31
    /**
32
     * @param array $attachment
33
     *
34
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
35
     *
36
     * @return \TestMonitor\DevOps\Resources\Attachment
37
     */
38 1
    protected function fromDevOpsAttachment(array $attachment): Attachment
39
    {
40 1
        Validator::keysExists($attachment, ['id', 'url']);
41
42 1
        return new Attachment([
43 1
            'id' => $attachment['id'],
44 1
            'url' => $attachment['url'],
45
        ]);
46
    }
47
}
48