Cardlist   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 188
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 12
lcom 2
cbo 4
dl 0
loc 188
ccs 26
cts 26
cp 1
rs 10
c 0
b 0
f 0

12 Methods

Rating   Name   Duplication   Size   Complexity  
A show() 0 4 1
A create() 0 6 1
A update() 0 4 1
A setBoard() 0 4 1
A getBoard() 0 4 1
A getBoardField() 0 6 1
A setName() 0 4 1
A setSubscribed() 0 4 1
A setClosed() 0 4 1
A setPosition() 0 4 1
A actions() 0 4 1
A cards() 0 4 1
1
<?php
2
3
namespace Trello\Api;
4
5
use Trello\Exception\InvalidArgumentException;
6
7
/**
8
 * Trello List API
9
 * @link https://trello.com/docs/api/list
10
 *
11
 * Fully implemented.
12
 */
13
class Cardlist extends AbstractApi
14
{
15
    /**
16
     * Base path of lists api
17
     * @var string
18
     */
19
    protected $path = 'lists';
20
21
    /**
22
     * List fields
23
     * @link https://trello.com/docs/api/list/#get-1-lists-list-id-or-shortlink-field
24
     * @var array
25
     */
26
    public static $fields = array(
27
        'name',
28
        'closed',
29
        'idBoard',
30
        'pos',
31
        'subscribed',
32
    );
33
34
    /**
35
     * Find a list by id
36
     * @link https://trello.com/docs/api/list/#get-1-lists-idlist
37
     *
38
     * @param string $id     the list's id
39
     * @param array  $params optional attributes
40
     *
41
     * @return array list info
42
     */
43 1
    public function show($id, array $params = array())
44
    {
45 1
        return $this->get($this->getPath().'/'.rawurlencode($id), $params);
46
    }
47
48
    /**
49
     * Create a list
50
     * @link https://trello.com/docs/api/list/#post-1-lists
51
     *
52
     * @param array $params Required attributes: 'name', 'idBoard'
53
     *                      Optional attributes: 'pos'
54
     *
55
     * @return array
56
     */
57 3
    public function create(array $params = array())
58
    {
59 3
        $this->validateRequiredParameters(array('name', 'idBoard'), $params);
60
61 1
        return $this->post($this->getPath(), $params);
62
    }
63
64
    /**
65
     * Update a list
66
     * @link https://trello.com/docs/api/list/#put-1-lists-idlist
67
     *
68
     * @param string $id     the list's id
69
     * @param array  $params list attributes to update
70
     *
71
     * @return array list info
72
     */
73 1
    public function update($id, array $params = array())
74
    {
75 1
        return $this->put($this->getPath().'/'.rawurlencode($id), $params);
76
    }
77
78
    /**
79
     * Set a given list's board
80
     * @link https://trello.com/docs/api/list/#put-1-lists-idlist-idboard
81
     *
82
     * @param string $id      the list's id
83
     * @param string $boardId the board's id
84
     *
85
     * @return array board info
86
     */
87 1
    public function setBoard($id, $boardId)
88
    {
89 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/idBoard', array('value' => $boardId));
90
    }
91
92
    /**
93
     * Get a given list's board
94
     * @link https://trello.com/docs/api/list/#get-1-lists-idlist-board
95
     *
96
     * @param string $id     the list's id
97
     * @param array  $params optional parameters
98
     *
99
     * @return array board info
100
     */
101 1
    public function getBoard($id, array $params = array())
102
    {
103 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board', $params);
104
    }
105
106
    /**
107
     * Get the field of a board of a given list
108
     * @link https://trello.com/docs/api/list/#get-1-lists-idlist-board-field
109
     *
110
     * @param string $id    the list's id
111
     * @param array  $field the name of the field
112
     *
113
     * @return array
114
     *
115
     * @throws InvalidArgumentException if the field does not exist
116
     */
117 2
    public function getBoardField($id, $field)
118
    {
119 2
        $this->validateAllowedParameters(Board::$fields, $field, 'field');
120
121 1
        return $this->get($this->getPath().'/'.rawurlencode($id).'/board/'.rawurlencode($field));
122
    }
123
124
    /**
125
     * Set a given list's name
126
     * @link https://trello.com/docs/api/list/#put-1-lists-idlist-name
127
     *
128
     * @param string $id   the list's id
129
     * @param string $name the name
130
     *
131
     * @return array list info
132
     */
133 1
    public function setName($id, $name)
134
    {
135 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/name', array('value' => $name));
136
    }
137
138
    /**
139
     * Set a given list's description
140
     * @link https://trello.com/docs/api/list/#put-1-lists-list-id-desc
141
     *
142
     * @param string $id         the list's id
143
     * @param bool   $subscribed subscription state
144
     *
145
     * @return array list info
146
     */
147 1
    public function setSubscribed($id, $subscribed)
148
    {
149 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/subscribed', array('value' => $subscribed));
150
    }
151
152
    /**
153
     * Set a given list's state
154
     * @link https://trello.com/docs/api/list/#put-1-lists-idlist-closed
155
     *
156
     * @param string $id     the list's id
157
     * @param bool   $closed whether the list should be closed or not
158
     *
159
     * @return array list info
160
     */
161 1
    public function setClosed($id, $closed = true)
162
    {
163 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/closed', array('value' => $closed));
164
    }
165
166
    /**
167
     * Set a given list's position
168
     * @link https://trello.com/docs/api/list/#put-1-lists-idlist-pos
169
     *
170
     * @param string         $id       the list's id
171
     * @param string|integer $position the position, eg. 'top', 'bottom'
172
     *                                 or a positive number
173
     *
174
     * @return array list info
175
     */
176 1
    public function setPosition($id, $position)
177
    {
178 1
        return $this->put($this->getPath().'/'.rawurlencode($id).'/pos', array('value' => $position));
179
    }
180
181
    /**
182
     * Actions API
183
     *
184
     * @return Cardlist\Actions
185
     */
186 1
    public function actions()
187
    {
188 1
        return new Cardlist\Actions($this->client);
189
    }
190
191
    /**
192
     * Cards API
193
     *
194
     * @return Cardlist\Cards
195
     */
196 1
    public function cards()
197
    {
198 1
        return new Cardlist\Cards($this->client);
199
    }
200
}
201