ConversationsListPayload::setCursor()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 1
1
<?php
2
namespace PortlandLabs\Slackbot\Slack\Api\Payload;
3
4
use CL\Slack\Payload\ChannelsListPayload;
5
6
class ConversationsListPayload extends ChannelsListPayload
7
{
8
9
    /** @var string */
10
    protected $types = 'public_channel';
11
12
    /** @var string */
13
    protected $cursor;
14
15
    public function getMethod()
16
    {
17
        return 'conversations.list';
18
    }
19
20
    /**
21
     * Set whether we exclude public channels
22
     *
23
     * @param bool $exclude
24
     */
25
    public function setExcludePublic(bool $exclude)
26
    {
27
        $this->toggleType('public_channel', $exclude);
28
    }
29
30
    /**
31
     * Set whether we exclude public channels
32
     * @param bool $exclude
33
     */
34
    public function setExcludePrivate(bool $exclude)
35
    {
36
        $this->toggleType('private_channel', $exclude);
37
    }
38
39
    /**
40
     * Toggle types from our $types array
41
     *
42
     * @param string $type
43
     * @param bool $exclude
44
     */
45
    public function toggleType(string $type, bool $exclude)
46
    {
47
        $typeArray = explode(',', $this->types);
48
        $key = array_search($type, $typeArray);
49
50
        if ($exclude && $key !== false) {
51
            unset($typeArray[$key]);
52
        }
53
54
        if (!$exclude) {
55
            $typeArray[] = '' . $type;
56
            $typeArray = array_unique($typeArray);
57
        }
58
59
        $this->types = implode(',', $typeArray);
60
    }
61
62
    /**
63
     * Get the types in string value
64
     *
65
     * @return string
66
     */
67
    public function getTypes(): string
68
    {
69
        return $this->types;
70
    }
71
72
    /**
73
     * @return string
74
     */
75
    public function getCursor(): string
76
    {
77
        return $this->cursor;
78
    }
79
80
    /**
81
     * @param string $cursor
82
     */
83
    public function setCursor(string $cursor): void
84
    {
85
        $this->cursor = $cursor;
86
    }
87
88
}