Comments   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

6 Methods

Rating   Name   Duplication   Size   Complexity  
A listComments() 0 5 1
A listCommitComments() 0 5 1
A addCommitComment() 0 9 1
A getCommitComment() 0 5 1
A updateCommitComment() 0 8 1
A deleteCommitComment() 0 6 1
1
<?php
2
namespace FlexyProject\GitHub\Receiver\Repositories;
3
4
use Symfony\Component\HttpFoundation\Request;
5
6
/**
7
 * The Comments API class provides access to repository's comments.
8
 *
9
 * @link    https://developer.github.com/v3/repos/comments/
10
 * @package FlexyProject\GitHub\Receiver\Repositories
11
 */
12
class Comments extends AbstractRepositories
13
{
14
15
    /**
16
     * List commit comments for a repository
17
     *
18
     * @link https://developer.github.com/v3/repos/comments/#list-commit-comments-for-a-repository
19
     * @return array
20
     */
21
    public function listComments(): array
22
    {
23
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/comments',
24
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo()));
25
    }
26
27
    /**
28
     * List comments for a single commit
29
     *
30
     * @link https://developer.github.com/v3/repos/comments/#list-comments-for-a-single-commit
31
     *
32
     * @param string $ref
33
     *
34
     * @return array
35
     */
36
    public function listCommitComments(string $ref): array
37
    {
38
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits/:ref/comments',
39
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $ref));
40
    }
41
42
    /**
43
     * Create a commit comment
44
     *
45
     * @link https://developer.github.com/v3/repos/comments/#create-a-commit-comment
46
     *
47
     * @param string $sha
48
     * @param string $body
49
     * @param string $path
50
     * @param int    $position
51
     *
52
     * @return array
53
     */
54
    public function addCommitComment(string $sha, string $body, string $path = '', int $position = 0): array
55
    {
56
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/commits/:sha/comments',
57
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), $sha), Request::METHOD_POST, [
58
                'body'     => $body,
59
                'path'     => $path,
60
                'position' => $position
61
            ]);
62
    }
63
64
    /**
65
     * Get a single commit comment
66
     *
67
     * @link https://developer.github.com/v3/repos/comments/#get-a-single-commit-comment
68
     *
69
     * @param int $id
70
     *
71
     * @return array
72
     */
73
    public function getCommitComment(int $id): array
74
    {
75
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/comments/:id',
76
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), (string)$id));
77
    }
78
79
    /**
80
     * Update a commit comment
81
     *
82
     * @link https://developer.github.com/v3/repos/comments/#update-a-commit-comment
83
     *
84
     * @param int    $id
85
     * @param string $body
86
     *
87
     * @return array
88
     * @throws \Exception
89
     */
90
    public function updateCommitComment(int $id, string $body): array
91
    {
92
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/comments/:id',
93
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), (string)$id),
94
            Request::METHOD_PATCH, [
95
                'body' => $body
96
            ]);
97
    }
98
99
    /**
100
     * Delete a commit comment
101
     *
102
     * @link https://developer.github.com/v3/repos/comments/#delete-a-commit-comment
103
     *
104
     * @param int $id
105
     *
106
     * @return array
107
     */
108
    public function deleteCommitComment(int $id): array
109
    {
110
        return $this->getApi()->request($this->getApi()->sprintf('/repos/:owner/:repo/comments/:id',
111
            $this->getRepositories()->getOwner(), $this->getRepositories()->getRepo(), (string)$id),
112
            Request::METHOD_DELETE);
113
    }
114
}