Tasks::create()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 1
nop 3
dl 0
loc 8
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Polidog\Chatwork\Api\Rooms;
6
7
use Polidog\Chatwork\Client\ClientInterface;
8
use Polidog\Chatwork\Entity\Collection\CollectionInterface;
9
use Polidog\Chatwork\Entity\Factory\TaskFactory;
10
use Polidog\Chatwork\Entity\Task;
11
12
class Tasks
13
{
14
    /**
15
     * @var ClientInterface
16
     */
17
    private $client;
18
19
    /**
20
     * @var TaskFactory
21
     */
22
    private $factory;
23
24
    /**
25
     * @var int
26
     */
27
    private $roomId;
28
29
    /**
30
     * Tasks constructor.
31
     *
32
     * @param ClientInterface $client
33
     * @param TaskFactory     $factory
34
     * @param int             $roomId
35
     */
36
    public function __construct(ClientInterface $client, TaskFactory $factory, int $roomId)
37
    {
38
        $this->client = $client;
39
        $this->factory = $factory;
40
        $this->roomId = $roomId;
41
    }
42
43
    /**
44
     * @param array $options
45
     *
46
     * @return CollectionInterface
47
     */
48
    public function show(array $options = [])
49
    {
50
        return $this->factory->collection(
51
            $this->client->get(
52
                "rooms/{$this->roomId}/tasks",
53
                $options
54
            )
55
        );
56
    }
57
58
    /**
59
     * @param int $id
60
     *
61
     * @return Task
62
     */
63
    public function detail($id)
64
    {
65
        return $this->factory->entity(
66
            $this->client->get(
67
                "rooms/{$this->roomId}/tasks/{$id}"
68
            )
69
        );
70
    }
71
72
    /**
73
     * @param string         $body
74
     * @param array          $toIds
75
     * @param \DateTime|null $limit
76
     *
77
     * @return int[] task ids
78
     */
79
    public function create(string $body, array $toIds, \DateTime $limit = null): array
80
    {
81
        return $this->client->post(
82
            "rooms/{$this->roomId}/tasks",
83
            [
84
                'body' => $body,
85
                'to_ids' => implode(',', $toIds),
86
                'limit' => $limit instanceof \DateTime ? $limit->getTimestamp() : null,
87
            ]
88
        );
89
    }
90
}
91