These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Part of the Joomla Framework Github Package |
||
4 | * |
||
5 | * @copyright Copyright (C) 2005 - 2015 Open Source Matters, Inc. All rights reserved. |
||
6 | * @license GNU General Public License version 2 or later; see LICENSE |
||
7 | */ |
||
8 | |||
9 | namespace Joomla\Github\Package\Issues; |
||
10 | |||
11 | use Joomla\Github\AbstractPackage; |
||
12 | |||
13 | /** |
||
14 | * GitHub API Comments class for the Joomla Framework. |
||
15 | * |
||
16 | * The Issue Comments API supports listing, viewing, editing, and creating comments |
||
17 | * on issues and pull requests. |
||
18 | * |
||
19 | * @documentation http://developer.github.com/v3/issues/comments/ |
||
20 | * |
||
21 | * @since 1.0 |
||
22 | */ |
||
23 | class Comments extends AbstractPackage |
||
24 | { |
||
25 | /** |
||
26 | * List comments on an issue. |
||
27 | * |
||
28 | * @param string $owner The name of the owner of the GitHub repository. |
||
29 | * @param string $repo The name of the GitHub repository. |
||
30 | * @param integer $issueId The issue number. |
||
31 | * @param integer $page The page number from which to get items. |
||
32 | * @param integer $limit The number of items on a page. |
||
33 | * @param \DateTime $since Only comments updated at or after this time are returned. |
||
34 | * |
||
35 | * @return object |
||
36 | * |
||
37 | * @since 1.0 |
||
38 | * @throws \DomainException |
||
39 | */ |
||
40 | public function getList($owner, $repo, $issueId, $page = 0, $limit = 0, \DateTime $since = null) |
||
41 | { |
||
42 | // Build the request path. |
||
43 | $path = '/repos/' . $owner . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; |
||
44 | $path .= ($since) ? '?since=' . $since->format(\DateTime::RFC3339) : ''; |
||
45 | |||
46 | // Send the request. |
||
47 | return $this->processResponse( |
||
48 | $this->client->get($this->fetchUrl($path, $page, $limit)) |
||
49 | ); |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * List comments in a repository. |
||
54 | * |
||
55 | * @param string $owner The name of the owner of the GitHub repository. |
||
56 | * @param string $repo The name of the GitHub repository. |
||
57 | * @param string $sort The sort field - created or updated. |
||
58 | * @param string $direction The sort order- asc or desc. Ignored without sort parameter. |
||
59 | * @param \DateTime $since Only comments updated at or after this time are returned. |
||
60 | * |
||
61 | * @return object |
||
62 | * |
||
63 | * @since 1.0 |
||
64 | * @throws \UnexpectedValueException |
||
65 | * @throws \DomainException |
||
66 | */ |
||
67 | public function getRepositoryList($owner, $repo, $sort = 'created', $direction = 'asc', \DateTime $since = null) |
||
68 | { |
||
69 | // Build the request path. |
||
70 | $path = '/repos/' . $owner . '/' . $repo . '/issues/comments'; |
||
71 | |||
72 | if (false == in_array($sort, array('created', 'updated'))) |
||
0 ignored issues
–
show
|
|||
73 | { |
||
74 | throw new \UnexpectedValueException( |
||
75 | sprintf( |
||
76 | '%1$s - sort field must be "created" or "updated"', __METHOD__ |
||
77 | ) |
||
78 | ); |
||
79 | } |
||
80 | |||
81 | View Code Duplication | if (false == in_array($direction, array('asc', 'desc'))) |
|
0 ignored issues
–
show
|
|||
82 | { |
||
83 | throw new \UnexpectedValueException( |
||
84 | sprintf( |
||
85 | '%1$s - direction field must be "asc" or "desc"', __METHOD__ |
||
86 | ) |
||
87 | ); |
||
88 | } |
||
89 | |||
90 | $path .= '?sort=' . $sort; |
||
91 | $path .= '&direction=' . $direction; |
||
92 | |||
93 | if ($since) |
||
94 | { |
||
95 | $path .= '&since=' . $since->format(\DateTime::RFC3339); |
||
96 | } |
||
97 | |||
98 | // Send the request. |
||
99 | return $this->processResponse($this->client->get($this->fetchUrl($path))); |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Get a single comment. |
||
104 | * |
||
105 | * @param string $owner The name of the owner of the GitHub repository. |
||
106 | * @param string $repo The name of the GitHub repository. |
||
107 | * @param integer $id The comment id. |
||
108 | * |
||
109 | * @return object |
||
110 | * |
||
111 | * @since 1.0 |
||
112 | * @throws \DomainException |
||
113 | */ |
||
114 | public function get($owner, $repo, $id) |
||
115 | { |
||
116 | // Build the request path. |
||
117 | $path = '/repos/' . $owner . '/' . $repo . '/issues/comments/' . (int) $id; |
||
118 | |||
119 | // Send the request. |
||
120 | return $this->processResponse( |
||
121 | $this->client->get($this->fetchUrl($path)) |
||
122 | ); |
||
123 | } |
||
124 | |||
125 | /** |
||
126 | * Edit a comment. |
||
127 | * |
||
128 | * @param string $user The name of the owner of the GitHub repository. |
||
129 | * @param string $repo The name of the GitHub repository. |
||
130 | * @param integer $commentId The id of the comment to update. |
||
131 | * @param string $body The new body text for the comment. |
||
132 | * |
||
133 | * @return object |
||
134 | * |
||
135 | * @since 1.0 |
||
136 | * @throws \DomainException |
||
137 | */ |
||
138 | public function edit($user, $repo, $commentId, $body) |
||
139 | { |
||
140 | // Build the request path. |
||
141 | $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; |
||
142 | |||
143 | // Build the request data. |
||
144 | $data = json_encode( |
||
145 | array( |
||
146 | 'body' => $body |
||
147 | ) |
||
148 | ); |
||
149 | |||
150 | // Send the request. |
||
151 | return $this->processResponse( |
||
152 | $this->client->patch($this->fetchUrl($path), $data) |
||
153 | ); |
||
154 | } |
||
155 | |||
156 | /** |
||
157 | * Create a comment. |
||
158 | * |
||
159 | * @param string $user The name of the owner of the GitHub repository. |
||
160 | * @param string $repo The name of the GitHub repository. |
||
161 | * @param integer $issueId The issue number. |
||
162 | * @param string $body The comment body text. |
||
163 | * |
||
164 | * @return object |
||
165 | * |
||
166 | * @since 1.0 |
||
167 | * @throws \DomainException |
||
168 | */ |
||
169 | public function create($user, $repo, $issueId, $body) |
||
170 | { |
||
171 | // Build the request path. |
||
172 | $path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId . '/comments'; |
||
173 | |||
174 | // Build the request data. |
||
175 | $data = json_encode( |
||
176 | array( |
||
177 | 'body' => $body, |
||
178 | ) |
||
179 | ); |
||
180 | |||
181 | // Send the request. |
||
182 | return $this->processResponse( |
||
183 | $this->client->post($this->fetchUrl($path), $data), |
||
184 | 201 |
||
185 | ); |
||
186 | } |
||
187 | |||
188 | /** |
||
189 | * Delete a comment. |
||
190 | * |
||
191 | * @param string $user The name of the owner of the GitHub repository. |
||
192 | * @param string $repo The name of the GitHub repository. |
||
193 | * @param integer $commentId The id of the comment to delete. |
||
194 | * |
||
195 | * @return boolean |
||
196 | * |
||
197 | * @since 1.0 |
||
198 | * @throws \DomainException |
||
199 | */ |
||
200 | View Code Duplication | public function delete($user, $repo, $commentId) |
|
201 | { |
||
202 | // Build the request path. |
||
203 | $path = '/repos/' . $user . '/' . $repo . '/issues/comments/' . (int) $commentId; |
||
204 | |||
205 | // Send the request. |
||
206 | $this->processResponse( |
||
207 | $this->client->delete($this->fetchUrl($path)), |
||
208 | 204 |
||
209 | ); |
||
210 | |||
211 | return true; |
||
212 | } |
||
213 | } |
||
214 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.