Labels::remove()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 8
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 8
loc 8
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 4
nc 2
nop 2
crap 2
1
<?php
2
3
namespace Trello\Api\Card;
4
5
use Trello\Api\AbstractApi;
6
use Trello\Exception\InvalidArgumentException;
7
8
/**
9
 * Trello Card Labels API
10
 * @link https://trello.com/docs/api/card
11
 *
12
 * Fully implemented.
13
 */
14
class Labels extends AbstractApi
15
{
16
    protected $path = 'cards/#id#/labels';
17
18
    /**
19
     * Set a given card's labels
20
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-labels
21
     *
22
     * @param string $id     the card's id or short link
23
     * @param array  $labels the labels
24
     *
25
     * @return array card info
26
     *
27
     * @throws InvalidArgumentException If a label does not exist
28
     */
29 2
    public function set($id, array $labels)
30
    {
31 2
        foreach ($labels as $label) {
32 2
            if (!in_array($label, array('all', 'green', 'yellow', 'orange', 'red', 'purple', 'blue'))) {
33 1
                throw new InvalidArgumentException(sprintf('Label "%s" does not exist.', $label));
34
            }
35 1
        }
36
37 1
        $labels = implode(',', $labels);
38
39 1
        return $this->put($this->getPath($id), array('value' => $labels));
40
    }
41
42
    /**
43
     * Remove a given label from a given card
44
     * @link https://trello.com/docs/api/card/#delete-1-cards-card-id-or-shortlink-labels-color
45
     *
46
     * @param string $id    the card's id or short link
47
     * @param string $label the label to remove
48
     *
49
     * @return array card info
50
     *
51
     * @throws InvalidArgumentException If a label does not exist
52
     */
53 2 View Code Duplication
    public function remove($id, $label)
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...
54
    {
55 2
        if (!in_array($label, array('green', 'yellow', 'orange', 'red', 'purple', 'blue'))) {
56 1
            throw new InvalidArgumentException(sprintf('Label "%s" does not exist.', $label));
57
        }
58
59 1
        return $this->delete($this->getPath($id).'/'.rawurlencode($label));
60
    }
61
}
62