Labels::show()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 13
Ratio 100 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 0
Metric Value
dl 13
loc 13
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 7
nc 2
nop 2
crap 2
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
     * Set a label's name on a given board and for a given color
61
     * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-blue
62
     * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-green
63
     * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-orange
64
     * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-purple
65
     * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-red
66
     * @link https://trello.com/docs/api/board/#put-1-boards-board-id-labelnames-yellow
67
     *
68
     * @param string $id    the board's id
69
     * @param string $color the label color to set the name of
70
     * @param string $name
71
     *
72
     * @return array
73
     */
74 2
    public function setName($id, $color, $name)
75
    {
76 2
        $colors = array('blue', 'green', 'orange', 'purple', 'red', 'yellow');
77
78 2
        if (!in_array($color, $colors)) {
79 1
            throw new InvalidArgumentException(sprintf(
80 1
                'The "color" parameter must be one of "%s".',
81 1
                implode(", ", $colors)
82 1
            ));
83
        }
84
85 1
        return $this->put('boards/'.rawurlencode($id).'/labelNames/'.rawurlencode($color), array('value' => $name));
86
    }
87
}
88