Completed
Pull Request — master (#16)
by
unknown
13:26 queued 04:20
created

Labels::add()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 10
ccs 3
cts 3
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 5
nc 1
nop 3
crap 1
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)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
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