Completed
Pull Request — master (#64)
by
unknown
07:14
created

Labels::all()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 14 and the first side effect is on line 112.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
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
    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
     * 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
    /**
89
     * Create a list on a given board
90
     * @link https://trello.com/docs/api/board/#post-1-boards-board-id-lists
91
     *
92
     * @param string $id    the board's id
93
     * @param string $color the label color to set the name of
94
     * @param string $name
95
     *
96
     * @return array
97
     */
98
    public function create($id, $color, $name)
99
    {
100
        $colors = array('blue', 'green', 'orange', 'purple', 'red', 'yellow');
101
102
        if (!in_array($color, $colors)) {
103
            throw new InvalidArgumentException(sprintf(
104
                'The "color" parameter must be one of "%s".',
105
                implode(", ", $colors)
106
            ));
107
        }
108
109
        return $this->post('boards/'.rawurlencode($id).'/labels/', array('name' => $name, 'color' => $color));
110
    }
111
}
112
}
0 ignored issues
show
Bug introduced by
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected '}'
Loading history...
113