77abstract class Adapter
88{
99 public const CLONE_TYPE_BRANCH = 'branch ' ;
10+
1011 public const CLONE_TYPE_TAG = 'tag ' ;
12+
1113 public const CLONE_TYPE_COMMIT = 'commit ' ;
1214
1315 public const METHOD_GET = 'GET ' ;
16+
1417 public const METHOD_POST = 'POST ' ;
18+
1519 public const METHOD_PUT = 'PUT ' ;
20+
1621 public const METHOD_PATCH = 'PATCH ' ;
22+
1723 public const METHOD_DELETE = 'DELETE ' ;
24+
1825 public const METHOD_HEAD = 'HEAD ' ;
26+
1927 public const METHOD_OPTIONS = 'OPTIONS ' ;
28+
2029 public const METHOD_CONNECT = 'CONNECT ' ;
30+
2131 public const METHOD_TRACE = 'TRACE ' ;
2232
2333 public const TYPE_GIT = 'git ' ;
34+
2435 public const TYPE_SVN = 'svn ' ;
2536
2637 protected bool $ selfSigned = true ;
@@ -36,61 +47,44 @@ abstract class Adapter
3647
3748 /**
3849 * Get Adapter Name
39- *
40- * @return string
4150 */
4251 abstract public function getName (): string ;
4352
4453 /**
4554 * Get Adapter Type
46- *
47- * @return string
4855 */
4956 abstract public function getType (): string ;
5057
5158 /**
5259 * Initialize Variables
53- *
54- * @param string $installationId
55- * @param string $privateKey
56- * @param string|null $appId
57- * @param string|null $accessToken
58- * @param string|null $refreshToken
59- * @return void
6060 */
6161 abstract public function initializeVariables (string $ installationId , string $ privateKey , ?string $ appId = null , ?string $ accessToken = null , ?string $ refreshToken = null ): void ;
6262
6363 /**
6464 * Generate Access Token
65- *
66- * @param string $privateKey
67- * @param string $appId
68- * @return void
6965 */
7066 abstract protected function generateAccessToken (string $ privateKey , string $ appId ): void ;
7167
7268 /**
7369 * Get user
7470 *
7571 * @return array<mixed>
76- *
7772 */
7873 abstract public function getUser (string $ username ): array ;
7974
8075 /**
8176 * Get owner name of the installation
82- *
83- * @return string
8477 */
8578 abstract public function getOwnerName (string $ installationId ): string ;
8679
8780 /**
8881 * Search repositories for GitHub App
89- * @param string $installationId ID of the installation
90- * @param string $owner Name of user or org
91- * @param int $page page number
92- * @param int $per_page number of results per page
93- * @param string $search Query to be searched to filter repo names
82+ *
83+ * @param string $installationId ID of the installation
84+ * @param string $owner Name of user or org
85+ * @param int $page page number
86+ * @param int $per_page number of results per page
87+ * @param string $search Query to be searched to filter repo names
9488 * @return array<mixed>
9589 *
9690 * @throws Exception
@@ -100,7 +94,6 @@ abstract public function searchRepositories(string $installationId, string $owne
10094 /**
10195 * Get repository for the installation
10296 *
103- * @param string $repositoryName
10497 * @return array<mixed>
10598 */
10699 abstract public function getInstallationRepository (string $ repositoryName ): array ;
@@ -126,6 +119,7 @@ abstract public function deleteRepository(string $owner, string $repositoryName)
126119
127120 /**
128121 * Get latest opened pull request with specific base branch
122+ *
129123 * @return array<mixed>
130124 */
131125 abstract public function getPullRequestFromBranch (string $ owner , string $ repositoryName , string $ branch ): array ;
@@ -139,29 +133,27 @@ abstract public function getPullRequest(string $owner, string $repositoryName, i
139133
140134 /**
141135 * Add Comment to Pull Request
142- *
143- * @return string
144136 */
145137 abstract public function createComment (string $ owner , string $ repositoryName , int $ pullRequestNumber , string $ comment ): string ;
146138
147139 /**
148140 * Get Comment of Pull Request
149141 *
150- * @param string $owner The owner of the repository
151- * @param string $repositoryName The name of the repository
152- * @param string $commentId The ID of the comment to retrieve
153- * @return string The retrieved comment
142+ * @param string $owner The owner of the repository
143+ * @param string $repositoryName The name of the repository
144+ * @param string $commentId The ID of the comment to retrieve
145+ * @return string The retrieved comment
154146 */
155147 abstract public function getComment (string $ owner , string $ repositoryName , string $ commentId ): string ;
156148
157149 /**
158150 * Update Pull Request Comment
159151 *
160- * @param string $owner The owner of the repository
161- * @param string $repositoryName The name of the repository
162- * @param int $commentId The ID of the comment to update
163- * @param string $comment The updated comment content
164- * @return string The ID of the updated comment
152+ * @param string $owner The owner of the repository
153+ * @param string $repositoryName The name of the repository
154+ * @param int $commentId The ID of the comment to update
155+ * @param string $comment The updated comment content
156+ * @return string The ID of the updated comment
165157 */
166158 abstract public function updateComment (string $ owner , string $ repositoryName , int $ commentId , string $ comment ): string ;
167159
@@ -173,35 +165,34 @@ abstract public function generateCloneCommand(string $owner, string $repositoryN
173165 /**
174166 * Parses webhook event payload
175167 *
176- * @param string $payload Raw body of HTTP request
177- * @param string $signature Signature provided by Git provider in header
178- * @param string $signatureKey Webhook secret configured on Git provider
179- * @return bool
168+ * @param string $payload Raw body of HTTP request
169+ * @param string $signature Signature provided by Git provider in header
170+ * @param string $signatureKey Webhook secret configured on Git provider
180171 */
181172 abstract public function validateWebhookEvent (string $ payload , string $ signature , string $ signatureKey ): bool ;
182173
183174 /**
184175 * Parses webhook event payload
185176 *
186- * @param string $event Type of event: push, pull_request etc
187- * @param string $payload The webhook payload received from Git provider
177+ * @param string $event Type of event: push, pull_request etc
178+ * @param string $payload The webhook payload received from Git provider
188179 * @return array<mixed> Parsed payload as a json object
189180 */
190181 abstract public function getEvent (string $ event , string $ payload ): array ;
191182
192183 /**
193184 * Fetches repository name using repository id
194185 *
195- * @param string $repositoryId ID of the repository
186+ * @param string $repositoryId ID of the repository
196187 * @return string name of the repository
197188 */
198189 abstract public function getRepositoryName (string $ repositoryId ): string ;
199190
200191 /**
201192 * Lists branches for a given repository
202193 *
203- * @param string $owner Owner name of the repository
204- * @param string $repositoryName Name of the repository
194+ * @param string $owner Owner name of the repository
195+ * @param string $repositoryName Name of the repository
205196 * @return array<string> List of branch names as array
206197 */
207198 abstract public function listBranches (string $ owner , string $ repositoryName ): array ;
@@ -215,61 +206,61 @@ abstract public function updateCommitStatus(string $repositoryName, string $SHA,
215206 /**
216207 * Get repository tree
217208 *
218- * @param string $owner Owner name of the repository
219- * @param string $repositoryName Name of the GitHub repository
220- * @param string $branch Name of the branch
221- * @param bool $recursive Whether to fetch the tree recursively
209+ * @param string $owner Owner name of the repository
210+ * @param string $repositoryName Name of the GitHub repository
211+ * @param string $branch Name of the branch
212+ * @param bool $recursive Whether to fetch the tree recursively
222213 * @return array<string> List of files in the repository
223214 */
224215 abstract public function getRepositoryTree (string $ owner , string $ repositoryName , string $ branch , bool $ recursive = false ): array ;
225216
226217 /**
227218 * Get repository languages
228219 *
229- * @param string $owner Owner name of the repository
230- * @param string $repositoryName Name of the repository
220+ * @param string $owner Owner name of the repository
221+ * @param string $repositoryName Name of the repository
231222 * @return array<mixed> List of repository languages
232223 */
233224 abstract public function listRepositoryLanguages (string $ owner , string $ repositoryName ): array ;
234225
235226 /**
236227 * List contents of the specified root directory.
237228 *
238- * @param string $owner Owner name of the repository
239- * @param string $repositoryName Name of the repository
240- * @param string $path Path to list contents from
241- * @param string $ref The name of the commit/branch/tag
229+ * @param string $owner Owner name of the repository
230+ * @param string $repositoryName Name of the repository
231+ * @param string $path Path to list contents from
232+ * @param string $ref The name of the commit/branch/tag
242233 * @return array<mixed> List of contents at the specified path
243234 */
244235 abstract public function listRepositoryContents (string $ owner , string $ repositoryName , string $ path = '' , string $ ref = '' ): array ;
245236
246237 /**
247238 * Get contents of the specified file.
248239 *
249- * @param string $owner Owner name
250- * @param string $repositoryName Name of the repository
251- * @param string $path Path to the file
252- * @param string $ref The name of the commit/branch/tag
240+ * @param string $owner Owner name
241+ * @param string $repositoryName Name of the repository
242+ * @param string $path Path to the file
243+ * @param string $ref The name of the commit/branch/tag
253244 * @return array<string, mixed> File details
254245 */
255246 abstract public function getRepositoryContent (string $ owner , string $ repositoryName , string $ path , string $ ref = '' ): array ;
256247
257248 /**
258249 * Get details of a commit using commit hash
259250 *
260- * @param string $owner Owner name of the repository
261- * @param string $repositoryName Name of the GitHub repository
262- * @param string $commitHash SHA of the commit
251+ * @param string $owner Owner name of the repository
252+ * @param string $repositoryName Name of the GitHub repository
253+ * @param string $commitHash SHA of the commit
263254 * @return array<mixed> Details of the commit
264255 */
265256 abstract public function getCommit (string $ owner , string $ repositoryName , string $ commitHash ): array ;
266257
267258 /**
268259 * Get latest commit of a branch
269260 *
270- * @param string $owner Owner name of the repository
271- * @param string $repositoryName Name of the GitHub repository
272- * @param string $branch Name of the branch
261+ * @param string $owner Owner name of the repository
262+ * @param string $repositoryName Name of the GitHub repository
263+ * @param string $branch Name of the branch
273264 * @return array<mixed> Details of the commit
274265 */
275266 abstract public function getLatestCommit (string $ owner , string $ repositoryName , string $ branch ): array ;
@@ -279,21 +270,18 @@ abstract public function getLatestCommit(string $owner, string $repositoryName,
279270 *
280271 * Make an API call
281272 *
282- * @param string $method
283- * @param string $path
284273 * @param array<mixed> $params
285274 * @param array<string, string> $headers
286- * @param bool $decode
287275 * @return array<mixed>
288276 *
289277 * @throws Exception
290278 */
291279 protected function call (string $ method , string $ path = '' , array $ headers = [], array $ params = [], bool $ decode = true )
292280 {
293281 $ headers = array_merge ($ this ->headers , $ headers );
294- $ ch = curl_init ($ this ->endpoint . $ path . (($ method == self ::METHOD_GET && !empty ($ params )) ? '? ' . http_build_query ($ params ) : '' ));
282+ $ ch = curl_init ($ this ->endpoint . $ path. (($ method == self ::METHOD_GET && ! empty ($ params )) ? '? ' . http_build_query ($ params ) : '' ));
295283
296- if (!$ ch ) {
284+ if (! $ ch ) {
297285 throw new Exception ('Curl failed to initialize ' );
298286 }
299287
@@ -321,7 +309,7 @@ protected function call(string $method, string $path = '', array $headers = [],
321309 }
322310
323311 foreach ($ headers as $ i => $ header ) {
324- $ headers [] = $ i . ': ' . $ header ;
312+ $ headers [] = $ i. ': ' . $ header ;
325313 unset($ headers [$ i ]);
326314 }
327315
@@ -372,7 +360,7 @@ protected function call(string $method, string $path = '', array $headers = [],
372360 $ json = \json_decode ($ responseBody , true );
373361
374362 if ($ json === null ) {
375- throw new Exception ('Failed to parse response: ' . $ responseBody );
363+ throw new Exception ('Failed to parse response: ' . $ responseBody );
376364 }
377365
378366 $ responseBody = $ json ;
@@ -381,16 +369,16 @@ protected function call(string $method, string $path = '', array $headers = [],
381369 }
382370 }
383371
384- if ((curl_errno ($ ch )/* || 200 != $responseStatus*/ )) {
385- throw new Exception (curl_error ($ ch ) . ' with status code ' . $ responseStatus , $ responseStatus );
372+ if ((curl_errno ($ ch )/* || 200 != $responseStatus */ )) {
373+ throw new Exception (curl_error ($ ch ). ' with status code ' . $ responseStatus , $ responseStatus );
386374 }
387375
388376 curl_close ($ ch );
389377
390378 $ responseHeaders ['status-code ' ] = $ responseStatus ;
391379
392380 if ($ responseStatus === 500 ) {
393- echo 'Server error( ' . $ method . ': ' . $ path . '. Params: ' . json_encode ($ params ) . '): ' . json_encode ($ responseBody ) . "\n" ;
381+ echo 'Server error( ' . $ method. ': ' . $ path. '. Params: ' . json_encode ($ params ). '): ' . json_encode ($ responseBody ). "\n" ;
394382 }
395383
396384 return [
@@ -403,7 +391,6 @@ protected function call(string $method, string $path = '', array $headers = [],
403391 * Flatten params array to PHP multiple format
404392 *
405393 * @param array<mixed> $data
406- * @param string $prefix
407394 * @return array<mixed>
408395 */
409396 protected function flatten (array $ data , string $ prefix = '' ): array
0 commit comments