Thread::put()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 3
eloc 9
c 1
b 0
f 0
nc 4
nop 4
dl 0
loc 16
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
1
<?php
2
3
namespace CybozuHttp\Api\Kintone;
4
5
use CybozuHttp\Client;
6
use CybozuHttp\Api\KintoneApi;
7
use CybozuHttp\Middleware\JsonStream;
8
9
/**
10
 * @author ochi51 <[email protected]>
11
 */
12
class Thread
13
{
14
    /**
15
     * @var Client
16
     */
17
    private $client;
18
19 1
    public function __construct(Client $client)
20
    {
21 1
        $this->client = $client;
22
    }
23
24
    /**
25
     * Put thread
26
     * https://cybozudev.zendesk.com/hc/ja/articles/201941894
27
     *
28
     * @param integer $id
29
     * @param string  $name
30
     * @param string  $body
31
     * @param integer $guestSpaceId
32
     * @return array
33
     */
34 1
    public function put($id, $name = null, $body = null, $guestSpaceId = null): array
35
    {
36 1
        $options = ['json' => ['id' => $id]];
37 1
        if ($name !== null) {
38 1
            $options['json']['name'] = $name;
39
        }
40 1
        if ($body !== null) {
41 1
            $options['json']['body'] = $body;
42
        }
43
44
        /** @var JsonStream $stream */
45 1
        $stream = $this->client
46 1
            ->put(KintoneApi::generateUrl('space/thread.json', $guestSpaceId), $options)
47 1
            ->getBody();
48
49 1
        return $stream->jsonSerialize();
50
    }
51
52
    /**
53
     * Post thread comment
54
     * https://cybozudev.zendesk.com/hc/ja/articles/209732306
55
     *
56
     * @param int $spaceId
57
     * @param int $threadId
58
     * @param string $comment
59
     * @param array $mentions
60
     * @param array $files
61
     * @param int $guestSpaceId
62
     * @return array
63
     */
64 1
    public function comment($spaceId, $threadId, $comment, array $mentions = [], array $files = [], $guestSpaceId = null): array
65
    {
66 1
        $options = ['json' => [
67 1
            'space'  => $spaceId,
68 1
            'thread' => $threadId,
69 1
            'comment'  => [
70 1
                'text' => $comment,
71 1
                'mentions' => $mentions,
72 1
                'files' => $files
73 1
            ],
74 1
        ]];
75
76
        /** @var JsonStream $stream */
77 1
        $stream = $this->client
78 1
            ->post(KintoneApi::generateUrl('space/thread/comment.json', $guestSpaceId), $options)
79 1
            ->getBody();
80
81 1
        return $stream->jsonSerialize();
82
    }
83
}
84