Users::postByCsv()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 2
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
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 Users
13
{
14
    public const MAX_GET_USERS = 100;
15
16
    /**
17
     * @var Client
18
     */
19
    private $client;
20
21
    /**
22
     * @var Csv
23
     */
24
    private $csv;
25
26 1
    public function __construct(Client $client, Csv $csv)
27
    {
28 1
        $this->client = $client;
29 1
        $this->csv = $csv;
30
    }
31
32
    /**
33
     * Get users
34
     * https://cybozudev.zendesk.com/hc/ja/articles/202363040#step2
35
     *
36
     * @param array $ids
37
     * @param array $codes
38
     * @param integer $offset
39
     * @param integer $limit
40
     * @return array
41
     */
42 1
    public function get(array $ids = [], array $codes = [], $offset = 0, $limit = self::MAX_GET_USERS): array
43
    {
44 1
        $options = ['json' => compact('ids', 'codes')];
45 1
        $options['json']['size'] = $limit;
46 1
        $options['json']['offset'] = $offset;
47
48
        /** @var JsonStream $stream */
49 1
        $stream = $this->client
50 1
            ->get(UserApi::generateUrl('users.json'), $options)
51 1
            ->getBody();
52
53 1
        return $stream->jsonSerialize()['users'];
54
    }
55
56
    /**
57
     * Get users by csv
58
     * https://cybozudev.zendesk.com/hc/ja/articles/202363040#step1
59
     *
60
     * @return string
61
     * @throws \InvalidArgumentException
62
     */
63 1
    public function getByCsv(): string
64
    {
65 1
        return $this->csv->get('user');
66
    }
67
68
    /**
69
     * Post users by csv
70
     * https://cybozudev.zendesk.com/hc/ja/articles/202111404
71
     *
72
     * @param $filename
73
     * @return int
74
     * @throws \InvalidArgumentException
75
     */
76 5
    public function postByCsv($filename): int
77
    {
78 5
        return $this->csv->post('user', $filename);
79
    }
80
}
81