Comments   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 91
Duplicated Lines 12.09 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 1
dl 11
loc 91
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A listComments() 0 4 1
A getSingleComment() 0 4 1
A createComment() 0 7 1
A editComment() 0 7 1
A deleteComment() 11 11 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
namespace FlexyProject\GitHub\Receiver\Gists;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The Comments API class provides access to gists's comments.
8
 *
9
 * @link    https://developer.github.com/v3/gists/comments/
10
 * @package FlexyProject\GitHub\Receiver\Gists
11
 */
12
class Comments extends AbstractGists
13
{
14
15
    /**
16
     * List comments on a gist
17
     *
18
     * @link https://developer.github.com/v3/gists/comments/#list-comments-on-a-gist
19
     *
20
     * @param string $gistId
21
     *
22
     * @return array
23
     */
24
    public function listComments(string $gistId): array
25
    {
26
        return $this->getApi()->request($this->getApi()->sprintf('/gists/:gist_id/comments', $gistId));
27
    }
28
29
    /**
30
     * Get a single comment
31
     *
32
     * @link https://developer.github.com/v3/gists/comments/#get-a-single-comment
33
     *
34
     * @param string $gistId
35
     * @param int    $id
36
     *
37
     * @return array
38
     */
39
    public function getSingleComment(string $gistId, int $id): array
40
    {
41
        return $this->getApi()->request($this->getApi()->sprintf('/gists/:gist_id/comments/:id', $gistId, (string)$id));
42
    }
43
44
    /**
45
     * Create a comment
46
     *
47
     * @link https://developer.github.com/v3/gists/comments/#create-a-comment
48
     *
49
     * @param string $gistId
50
     * @param string $body
51
     *
52
     * @return array
53
     */
54
    public function createComment(string $gistId, string $body): array
55
    {
56
        return $this->getApi()->request($this->getApi()->sprintf('/gists/:gist_id/comments', $gistId),
57
            Request::METHOD_POST, [
58
                'body' => $body
59
            ]);
60
    }
61
62
    /**
63
     * Edit a comment
64
     *
65
     * @link https://developer.github.com/v3/gists/comments/#edit-a-comment
66
     *
67
     * @param string $gistId
68
     * @param int    $id
69
     * @param string $body
70
     *
71
     * @return array
72
     */
73
    public function editComment(string $gistId, int $id, string $body): array
74
    {
75
        return $this->getApi()->request($this->getApi()->sprintf('/gists/:gist_id/comments/:id', $gistId, (string)$id),
76
            Request::METHOD_PATCH, [
77
                'body' => $body
78
            ]);
79
    }
80
81
    /**
82
     * Delete a comment
83
     *
84
     * @link https://developer.github.com/v3/gists/comments/#delete-a-comment
85
     *
86
     * @param string $gistId
87
     * @param int    $id
88
     *
89
     * @return bool
90
     */
91 View Code Duplication
    public function deleteComment(string $gistId, int $id): bool
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...
92
    {
93
        $this->getApi()->request($this->getApi()->sprintf('/gists/:gist_id/comments/:id', $gistId, (string)$id),
94
            Request::METHOD_DELETE);
95
96
        if ($this->getApi()->getHeaders()['Status'] == '204 No Content') {
97
            return true;
98
        }
99
100
        return false;
101
    }
102
}