Completed
Push — master ( d38bb3...5cc041 )
by Thijs
07:56 queued 06:53
created

ManagesWorkItems::workitem()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
crap 1
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 $projectId
16
     * @param string $id
17
     *
18
     *@return \TestMonitor\DevOps\Resources\WorkItem
19
     */
20 4
    public function workitem(string $id, string $projectId): WorkItem
21
    {
22 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?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
23
24 1
        return $this->fromDevOpsWorkItem($response);
25
    }
26
27
    /**
28
     * Create a new work item.
29
     *
30
     * @param \TestMonitor\DevOps\Resources\WorkItem $workItem
31
     * @param string $projectId
32
     *
33
     * @return WorkItem
34
     */
35 2
    public function createWorkItem(WorkItem $workItem, string $projectId): WorkItem
36
    {
37 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?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
38 2
            "{$projectId}/_apis/wit/workitems/\${$workItem->workItemType}",
39
            [
40 2
                'headers' => ['Content-Type' => 'application/json-patch+json'],
41 2
                'json' => $this->toDevOpsWorkItem($workItem),
42
            ]
43
        );
44
45 1
        return $this->fromDevOpsWorkItem($response);
46
    }
47
}
48