Items   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 82
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A create() 0 7 1
A update() 0 8 1
A remove() 0 4 1
1
<?php
2
3
namespace Trello\Api\Checklist;
4
5
use Trello\Api\AbstractApi;
6
7
/**
8
 * Trello Checklist Items API
9
 * @link https://trello.com/docs/api/checklist
10
 *
11
 * Fully implemented.
12
 */
13
class Items extends AbstractApi
14
{
15
    protected $path = 'checklists/#id#/checkItems';
16
17
    public static $fields = array(
18
        'name',
19
        'nameData',
20
        'type',
21
        'pos',
22
        'state',
23
    );
24
25
    /**
26
     * Get items related to a given checklist
27
     * @link https://trello.com/docs/api/checklist/#get-1-checklists-idchecklist-checkitems
28
     *
29
     * @param string $id     the card's id or short link
30
     * @param array  $params optional parameters
31
     *
32
     * @return array
33
     */
34 1
    public function all($id, array $params = array())
35
    {
36 1
        return $this->get($this->getPath($id), $params);
37
    }
38
39
    /**
40
     * Create an item in the given checklist
41
     * @link https://trello.com/docs/api/checklist/#post-1-checklists-idchecklist-checkitems
42
     *
43
     * @param string $id      Id of the checklist
44
     * @param string $name    Name of the item
45
     * @param bool   $checked Check status
46
     * @param array  $data    optional attributes
47
     *
48
     * @return array
49
     */
50 2
    public function create($id, $name, $checked = false, array $data = array())
51
    {
52 2
        $data['checked'] = $checked;
53 2
        $data['name'] = $name;
54
55 2
        return $this->post($this->getPath($id), $data);
56
    }
57
58
    /**
59
     * Update an item in the given checklist
60
     *
61
     * FIXME
62
     * There is no put method on checklist items, so this is
63
     * a dirty workaround which works by deleting the item
64
     * and recreating it.
65
     *
66
     * @param string $id     Id of the checklist
67
     * @param string $itemId the id of the item to update
68
     * @param array  $data   check item data
69
     *
70
     * @return array
71
     */
72 1
    public function update($id, $itemId, array $data)
73
    {
74 1
        $this->validateRequiredParameters(array('name', 'state'), $data);
75
76 1
        $this->remove($id, $itemId);
77
78 1
        return $this->create($id, $data['name'], $data['state'], $data);
79
    }
80
81
    /**
82
     * Remove an item from checklist
83
     * @link https://trello.com/docs/api/checklist/#delete-1-checklists-idchecklist-checkitems-idcheckitem
84
     *
85
     * @param string $id     the id of the checklist the item should be removed from
86
     * @param string $itemId the id of the item to delete
87
     *
88
     * @return array card info
89
     */
90 2
    public function remove($id, $itemId)
91
    {
92 2
        return $this->delete($this->getPath($id).'/'.rawurlencode($itemId));
93
    }
94
}
95