Attachments   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 9.09 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 1
dl 7
loc 77
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A all() 0 4 1
A create() 7 7 1
A show() 0 4 1
A remove() 0 4 1
A setAsCover() 0 4 1

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
7
/**
8
 * Trello Card Attachments API
9
 * @link https://trello.com/docs/api/card
10
 *
11
 * Fully implemented.
12
 */
13
class Attachments extends AbstractApi
14
{
15
    protected $path = 'cards/#id#/attachments';
16
17
    /**
18
     * Get attachments related to a given card
19
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-attachments
20
     *
21
     * @param string $id     the card's id or short link
22
     * @param array  $params optional parameters
23
     *
24
     * @return array
25
     */
26 1
    public function all($id, array $params = array())
27
    {
28 1
        return $this->get($this->getPath($id), $params);
29
    }
30
31
    /**
32
     * Add an attachment to a given card
33
     * @link https://trello.com/docs/api/card/#post-1-cards-card-id-or-shortlink-attachments
34
     *
35
     * @param string $id     the card's id or short link
36
     * @param array  $params optional parameters
37
     *
38
     * @return array
39
     */
40 2 View Code Duplication
    public function create($id, array $params)
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...
41
    {
42 2
        $atLeastOneOf = array('url', 'file');
43 2
        $this->validateAtLeastOneOf($atLeastOneOf, $params);
44
45 1
        return $this->post($this->getPath($id), $params);
46
    }
47
48
    /**
49
     * Get a given attachment on a given card
50
     * @link https://trello.com/docs/api/card/#get-1-cards-card-id-or-shortlink-attachments-idattachment
51
     *
52
     * @param string $id           the card's id or short link
53
     * @param string $attachmentId the attachment's id
54
     *
55
     * @return array
56
     */
57 1
    public function show($id, $attachmentId)
58
    {
59 1
        return $this->get($this->getPath($id).'/'.rawurlencode($attachmentId));
60
    }
61
62
    /**
63
     * Remove a given attachment from a given card
64
     * @link https://trello.com/docs/api/card/#delete-1-cards-card-id-or-shortlink-attachments-idattachment
65
     *
66
     * @param string $id           the card's id or short link
67
     * @param string $attachmentId the attachment's id
68
     *
69
     * @return array
70
     */
71 1
    public function remove($id, $attachmentId)
72
    {
73 1
        return $this->delete($this->getPath($id).'/'.rawurlencode($attachmentId));
74
    }
75
76
    /**
77
     * Set a given attachment as cover of a given card
78
     * @link https://trello.com/docs/api/card/#put-1-cards-card-id-or-shortlink-idattachmentcover
79
     *
80
     * @param string $id           the card's id or short link
81
     * @param string $attachmentId the attachment's id
82
     *
83
     * @return array
84
     */
85 1
    public function setAsCover($id, $attachmentId)
86
    {
87 1
        return $this->put('cards/'.rawurlencode($id).'/idAttachmentCover', array('value' => $attachmentId));
88
    }
89
}
90