Passed
Push — master ( 4a97f2...e97872 )
by Thijs
10:20
created

ManagesWorkItems::workitems()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 28
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 18
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 13
c 1
b 0
f 0
nc 2
nop 3
dl 0
loc 28
ccs 18
cts 18
cp 1
crap 3
rs 9.8333
1
<?php
2
3
namespace TestMonitor\DevOps\Actions;
4
5
use TestMonitor\DevOps\Resources\WorkItem;
6
use TestMonitor\DevOps\Transforms\TransformsWorkItems;
7
8
trait ManagesWorkItems
9
{
10
    use TransformsWorkItems;
11
12
    /**
13
     * Get a single work item.
14
     *
15
     * @param string $id
16
     * @param string $projectId
17
     *
18
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
19
     *
20
     * @return \TestMonitor\DevOps\Resources\WorkItem
21
     */
22 4
    public function workitem(string $id, string $projectId): WorkItem
23
    {
24 4
        $response = $this->get("{$projectId}/_apis/wit/workitems/{$id}");
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

24
        /** @scrutinizer ignore-call */ 
25
        $response = $this->get("{$projectId}/_apis/wit/workitems/{$id}");
Loading history...
25
26 1
        return $this->fromDevOpsWorkItem($response);
27
    }
28
29
    /**
30
     * Create a new work item.
31
     *
32
     * @param \TestMonitor\DevOps\Resources\WorkItem $workItem
33
     * @param string $projectId
34
     *
35
     * @throws \TestMonitor\DevOps\Exceptions\InvalidDataException
36
     *
37
     * @return WorkItem
38
     */
39 2
    public function createWorkItem(WorkItem $workItem, string $projectId): WorkItem
40
    {
41 2
        $response = $this->post(
0 ignored issues
show
Bug introduced by
It seems like post() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

41
        /** @scrutinizer ignore-call */ 
42
        $response = $this->post(
Loading history...
42 2
            "{$projectId}/_apis/wit/workitems/\${$workItem->workItemType}",
43 2
            [
44 2
                'headers' => ['Content-Type' => 'application/json-patch+json'],
45 2
                'json' => $this->toDevOpsWorkItem($workItem),
46 2
            ]
47 2
        );
48
49 1
        return $this->fromDevOpsWorkItem($response);
50
    }
51
}
52