Passed
Pull Request — master (#76)
by
unknown
14:50 queued 04:29
created

UserOrganizations::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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 1
    public function __construct(Client $client, Csv $csv)
25
    {
26 1
        $this->client = $client;
27 1
        $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 1
    public function get($code): array
38
    {
39 1
        $options = ['json' => ['code' => $code]];
40
41
        /** @var JsonStream $stream */
42 1
        $stream = $this->client
43 1
            ->get(UserApi::generateUrl('user/organizations.json'), $options)
44 1
            ->getBody();
45
46 1
        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 1
    public function getByCsv(): string
57
    {
58 1
        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 1
    public function postByCsv($filename): int
70
    {
71 1
        return $this->csv->post('userOrganizations', $filename);
72
    }
73
}
74