Task::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 3
1
<?php
2
3
namespace Streak\Endpoint;
4
5
class Task extends AbstractEndpoint
6
{
7
    const ENDPOINT = 'tasks';
8
9
    public function findAll($boxKey)
10
    {
11
        return $this->client->get(sprintf('/api/v2/boxes/%s/%s', $boxKey, self::ENDPOINT));
12
    }
13
14
    public function find($taskKey)
15
    {
16
        return $this->client->get(sprintf('/api/v2/%s/%s', self::ENDPOINT, $taskKey));
17
    }
18
19
    public function create($boxKey, $text, $dueDate)
20
    {
21
        return $this->client->post(sprintf('/api/v2/boxes/%s/%s', $boxKey, self::ENDPOINT), [
22
            'form_params' => [
23
                'text' => $text,
24
                'dueDate' => $dueDate,
25
            ],
26
        ]);
27
    }
28
29
    public function delete($taskKey)
30
    {
31
        return $this->client->delete(sprintf('api/v2/%s/%s', self::ENDPOINT, $taskKey));
32
    }
33
34 View Code Duplication
    public function edit($taskKey, array $task)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
35
    {
36
        foreach ($task as $field => $value) {
37
            if (!in_array($field, ['text', 'dueDate', 'assignedToSharingEntries'])) {
38
                throw new \InvalidArgumentException('Not allowed field.');
39
            }
40
        }
41
42
        return $this->client->post(sprintf('/api/v2/%s/%s', self::ENDPOINT, $taskKey), [
43
            'json' => $task,
44
        ]);
45
    }
46
}
47