Members::update()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 1
eloc 5
c 2
b 0
f 0
nc 1
nop 1
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\MemberCollection;
9
use Polidog\Chatwork\Entity\Factory\MemberFactory;
10
11
/**
12
 * Class Members.
13
 */
14
class Members
15
{
16
    /**
17
     * @var ClientInterface
18
     */
19
    private $client;
20
21
    /**
22
     * @var MemberFactory
23
     */
24
    private $factory;
25
26
    /**
27
     * @var int
28
     */
29
    private $roomId;
30
31
    /**
32
     * Members constructor.
33
     *
34
     * @param ClientInterface $client
35
     * @param MemberFactory   $factory
36
     * @param int             $roomId
37
     */
38
    public function __construct(ClientInterface $client, MemberFactory $factory, int $roomId)
39
    {
40
        $this->client = $client;
41
        $this->factory = $factory;
42
        $this->roomId = $roomId;
43
    }
44
45
    /**
46
     * @return MemberCollection
47
     */
48
    public function show()
49
    {
50
        return $this->factory->collection(
51
            $this->client->get("rooms/{$this->roomId}/members")
52
        );
53
    }
54
55
    /**
56
     * @param MemberCollection $members
57
     */
58
    public function update(MemberCollection $members): void
59
    {
60
        $options = [
61
            'members_admin_ids' => implode(',', $members->getAdminIds()),
62
            'members_member_ids' => implode(',', $members->getMemberIds()),
63
            'members_readonly_ids' => implode(',', $members->getReadonlyIds()),
64
        ];
65
        $this->client->put("rooms/{$this->roomId}/members", $options);
66
    }
67
}
68