ManagesStates   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 60
ccs 23
cts 23
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A findCurrentProjectProcess() 0 11 1
A states() 0 16 1
A statesForWorkItem() 0 5 1
1
<?php
2
3
namespace TestMonitor\DevOps\Actions;
4
5
use TestMonitor\DevOps\Support\Arrays;
6
use TestMonitor\DevOps\Transforms\TransformsStates;
7
8
trait ManagesStates
9
{
10
    use TransformsStates;
11
12
    /**
13
     * Get a list of states for a project.
14
     *
15
     * @param string $projectId
16
     * @param string $workItemType
17
     * @return \TestMonitor\DevOps\Resources\States[]
18
     */
19 6
    public function states($projectId)
20
    {
21 6
        $process = $this->findCurrentProjectProcess($projectId);
22
23 1
        $response = $this->get("_apis/work/processes/{$process}/workitemtypes", [
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

23
        /** @scrutinizer ignore-call */ 
24
        $response = $this->get("_apis/work/processes/{$process}/workitemtypes", [
Loading history...
24 1
            'query' => ['$expand' => 'states'],
25 1
        ]);
26
27 1
        $states = Arrays::unique(
28 1
            Arrays::flatten(
29 1
                array_column($response['value'], 'states')
30 1
            ),
31 1
            'id'
32 1
        );
33
34 1
        return $this->fromDevOpsStates($states);
35
    }
36
37
    /**
38
     * Determine the process ID for the provided project.
39
     *
40
     * @param string $projectId
41
     * @return string
42
     */
43 6
    protected function findCurrentProjectProcess($projectId)
44
    {
45 6
        $response = $this->get("_apis/projects/{$projectId}/properties", [
46 6
            'query' => ['api-version' => $this->previewApiVersion],
47 6
        ]);
48
49 1
        $property = current(
50 1
            array_filter($response['value'], fn ($property) => $property['name'] === 'System.CurrentProcessTemplateId'),
51 1
        );
52
53 1
        return $property['value'];
54
    }
55
56
    /**
57
     * Get a list of states for a project and work item type.
58
     *
59
     * @param string $projectId
60
     * @param string $workItemType
61
     * @return \TestMonitor\DevOps\Resources\States[]
62
     */
63 6
    public function statesForWorkItem($projectId, $workItemType)
64
    {
65 6
        $response = $this->get("{$projectId}/_apis/wit/workitemtypes/{$workItemType}/states");
66
67 1
        return $this->fromDevOpsStates($response['value']);
68
    }
69
}
70