Completed
Push — master ( 10b44f...a11b2a )
by Thijs
17:21 queued 17:19
created

ManagesTasks::createTask()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 1
b 0
f 0
nc 1
nop 3
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
namespace TestMonitor\DoneDone\Actions;
4
5
use TestMonitor\DoneDone\Resources\Task;
6
use TestMonitor\DoneDone\Transforms\TransformsTasks;
7
8
trait ManagesTasks
9
{
10
    use TransformsTasks;
11
12
    /**
13
     * Get a list of of tasks.
14
     *
15
     * @param int $accountId
16
     * @param int $projectId
17
     * @param int $page
18
     *
19
     * @return Task[]
20
     */
21 5
    public function tasks(int $accountId, int $projectId, int $page = 1): array
22
    {
23 5
        $result = $this->get("{$accountId}/internal-projects/{$projectId}/tasks", ['page' => $page]);
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
        $result = $this->get("{$accountId}/internal-projects/{$projectId}/tasks", ['page' => $page]);
Loading history...
24
25 1
        return array_map(function ($task) {
26 1
            return $this->fromDoneDoneTask($task);
27 1
        }, $result['listTasks']);
28
    }
29
30
    /**
31
     * Get a single task.
32
     *
33
     * @param int $id
34
     * @param int $accountId
35
     * @param int $projectId
36
     *
37
     * @return Task
38
     */
39 2
    public function task(int $id, int $accountId, int $projectId): Task
40
    {
41 2
        $result = $this->get("{$accountId}/internal-projects/{$projectId}/tasks/{$id}");
42
43 2
        return $this->fromDoneDoneTask($result);
44
    }
45
46
    /**
47
     * Create a new task.
48
     *
49
     * @param \TestMonitor\DoneDone\Resources\Task $task
50
     * @param int $accountId
51
     * @param int $projectId
52
     *
53
     * @return Task
54
     */
55 1
    public function createTask(Task $task, int $accountId, int $projectId)
56
    {
57 1
        $result = $this->post("{$accountId}/internal-projects/{$projectId}/tasks/", [
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

57
        /** @scrutinizer ignore-call */ 
58
        $result = $this->post("{$accountId}/internal-projects/{$projectId}/tasks/", [
Loading history...
58 1
            'json' => $this->toDoneDoneTask($task),
59
        ]);
60
61 1
        return $this->task($result['id'], $accountId, $projectId);
62
    }
63
}
64