Attachments::create()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 7
Ratio 100 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
dl 7
loc 7
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 2
crap 1
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