TransformsAttachments::fromDevOpsAttachment()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 4
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 7
ccs 5
cts 5
cp 1
crap 1
rs 10
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 1
        return [
17 1
            [
18 1
                'op' => 'add',
19 1
                'path' => '/relations/-',
20 1
                'value' => [
21 1
                    'rel' => 'AttachedFile',
22 1
                    'url' => $attachmentUrl,
23 1
                    'attributes' => [
24 1
                        'comment' => '',
25 1
                    ],
26 1
                ],
27 1
            ],
28 1
        ];
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 1
        ]);
46
    }
47
}
48