Labels   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 48
Duplicated Lines 16.67 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 8
loc 48
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A set() 0 12 3
A remove() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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