1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Trello\Api\Board; |
4
|
|
|
|
5
|
|
|
use Trello\Api\AbstractApi; |
6
|
|
|
use Trello\Exception\InvalidArgumentException; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Trello Board Labels API |
10
|
|
|
* @link https://trello.com/docs/api/board |
11
|
|
|
* |
12
|
|
|
* Fully implemented. |
13
|
|
|
*/ |
14
|
|
|
class Labels extends AbstractApi |
15
|
|
|
{ |
16
|
|
|
/** |
17
|
|
|
* Base path of board labels api |
18
|
|
|
* @var string |
19
|
|
|
*/ |
20
|
|
|
protected $path = 'boards/#id#/labels'; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Get labels related to a given board |
24
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-labels |
25
|
|
|
* |
26
|
|
|
* @param string $id the board's |
27
|
|
|
* @param array $params optional parameters |
28
|
|
|
* |
29
|
|
|
* @return array |
30
|
|
|
*/ |
31
|
1 |
|
public function all($id, array $params = array()) |
32
|
|
|
{ |
33
|
1 |
|
return $this->get($this->getPath($id), $params); |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Get a label related to a given board |
38
|
|
|
* @link https://trello.com/docs/api/board/#get-1-boards-board-id-labels-idlabel |
39
|
|
|
* |
40
|
|
|
* @param string $id the board's id |
41
|
|
|
* @param string $color the label's color |
42
|
|
|
* |
43
|
|
|
* @return array |
44
|
|
|
*/ |
45
|
2 |
View Code Duplication |
public function show($id, $color) |
|
|
|
|
46
|
|
|
{ |
47
|
2 |
|
$colors = array('blue', 'green', 'orange', 'purple', 'red', 'yellow'); |
48
|
|
|
|
49
|
2 |
|
if (!in_array($color, $colors)) { |
50
|
1 |
|
throw new InvalidArgumentException(sprintf( |
51
|
1 |
|
'The "color" parameter must be one of "%s".', |
52
|
1 |
|
implode(", ", $colors) |
53
|
1 |
|
)); |
54
|
|
|
} |
55
|
|
|
|
56
|
1 |
|
return $this->get($this->getPath($id).'/'.rawurlencode($color)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Add a label related to a given board |
61
|
|
|
* @link https://developers.trello.com/advanced-reference/board#post-1-boards-board-id-labels |
62
|
|
|
* |
63
|
|
|
* @param string $id the board's id |
64
|
|
|
* @param string $color the label's color |
65
|
|
|
* @param string $name the label's name |
66
|
|
|
* |
67
|
|
|
* @return array |
68
|
|
|
*/ |
69
|
|
|
public function add($id, $color, $name) |
70
|
|
|
{ |
71
|
|
|
|
72
|
|
|
$params = array( |
73
|
|
|
'color' => $color, |
74
|
2 |
|
'name' => $name |
75
|
|
|
); |
76
|
2 |
|
|
77
|
|
|
return $this->post($this->getPath($id), $params); |
78
|
2 |
|
} |
79
|
1 |
|
|
80
|
1 |
|
/** |
81
|
1 |
|
* Set a label's name on a given board and for a given color |
82
|
1 |
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-blue |
83
|
|
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-green |
84
|
|
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-orange |
85
|
1 |
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-purple |
86
|
|
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-red |
87
|
|
|
* @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-yellow |
88
|
|
|
* |
89
|
|
|
* @param string $id the board's id |
90
|
|
|
* @param string $color the label color to set the name of |
91
|
|
|
* @param string $name |
92
|
|
|
* |
93
|
|
|
* @return array |
94
|
|
|
*/ |
95
|
|
|
public function setName($id, $color, $name) |
96
|
|
|
{ |
97
|
|
|
$colors = array('blue', 'green', 'orange', 'purple', 'red', 'yellow'); |
98
|
|
|
|
99
|
|
|
if (!in_array($color, $colors)) { |
100
|
|
|
throw new InvalidArgumentException(sprintf( |
101
|
|
|
'The "color" parameter must be one of "%s".', |
102
|
|
|
implode(", ", $colors) |
103
|
|
|
)); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return $this->put('boards/'.rawurlencode($id).'/labelNames/'.rawurlencode($color), array('value' => $name)); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.