Passed
Pull Request — master (#77)
by Yuichi
04:41 queued 02:24
created

UserOrganizations   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 12
c 2
b 0
f 0
dl 0
loc 60
ccs 0
cts 13
cp 0
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getByCsv() 0 3 1
A postByCsv() 0 3 1
A get() 0 10 1
1
<?php
2
3
namespace CybozuHttp\Api\User;
4
5
use CybozuHttp\Client;
6
use CybozuHttp\Api\UserApi;
7
use CybozuHttp\Middleware\JsonStream;
8
9
/**
10
 * @author ochi51 <[email protected]>
11
 */
12
class UserOrganizations
13
{
14
    /**
15
     * @var Client
16
     */
17
    private $client;
18
19
    /**
20
     * @var Csv
21
     */
22
    private $csv;
23
24
    public function __construct(Client $client, Csv $csv)
25
    {
26
        $this->client = $client;
27
        $this->csv = $csv;
28
    }
29
30
    /**
31
     * Get organizations and titles of user
32
     * https://cybozudev.zendesk.com/hc/ja/articles/202124774#step2
33
     *
34
     * @param string $code
35
     * @return array
36
     */
37
    public function get($code): array
38
    {
39
        $options = ['json' => ['code' => $code]];
40
41
        /** @var JsonStream $stream */
42
        $stream = $this->client
43
            ->get(UserApi::generateUrl('user/organizations.json'), $options)
44
            ->getBody();
45
46
        return $stream->jsonSerialize()['organizationTitles'];
47
    }
48
49
    /**
50
     * Get userOrganizations by csv
51
     * https://cybozudev.zendesk.com/hc/ja/articles/202124774#step1
52
     *
53
     * @return string
54
     * @throws \InvalidArgumentException
55
     */
56
    public function getByCsv(): string
57
    {
58
        return $this->csv->get('userOrganizations');
59
    }
60
61
    /**
62
     * Post userOrganizations by csv
63
     * https://cybozudev.zendesk.com/hc/ja/articles/202362860
64
     *
65
     * @param $filename
66
     * @return int
67
     * @throws \InvalidArgumentException
68
     */
69
    public function postByCsv($filename): int
70
    {
71
        return $this->csv->post('userOrganizations', $filename);
72
    }
73
}
74