Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove duplications #153

Merged
merged 2 commits into from
Feb 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Src/config/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,6 @@ function loadConfig()

require_once "lib/functions.php";
require_once "lib/database.php";
require_once "lib/request.php";
require_once "lib/appveyor.php";
require_once "lib/github.php";
51 changes: 2 additions & 49 deletions Src/lib/appveyor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,54 +5,7 @@ function requestAppVeyor($url, $data = null)
global $appVeyorKey;

$baseUrl = "https://ci.appveyor.com/api/";
$url = $baseUrl . $url;

$headers = array();
$headers[] = "User-Agent: " . USER_AGENT;
$headers[] = "Content-type: application/json";
$headers[] = "Authorization: Bearer " . $appVeyorKey;

$fields = array(
CURLOPT_URL => $baseUrl . $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $headers
);

if ($data !== null) {
$fields[CURLOPT_POST] = true;
$fields[CURLOPT_POSTFIELDS] = json_encode($data);
}

$curl = curl_init();

curl_setopt_array($curl, $fields);

$response = curl_exec($curl);

if ($response === false) {
echo htmlspecialchars($url);
echo "\r\n";
die(curl_error($curl));
}

if(curl_getinfo($curl, CURLINFO_HTTP_CODE) != 200) {
echo htmlspecialchars($url);
echo "\r\n";
die($response);
}

$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $headerSize);
$headers = extractHeaders($header);
$body = substr($response, $headerSize);
curl_close($curl);

return array("headers" => $headers, "body" => $body);
return doRequest($url, $appVeyorKey, $data);
}
46 changes: 2 additions & 44 deletions Src/lib/github.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,51 +9,9 @@
function requestGitHub($gitHubToken, $url, $data = null)
{
$baseUrl = "https://api.github.com/";
$url = $baseUrl . $url;

Check notice on line 12 in Src/lib/github.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/github.php#L12

Concat operator must not be surrounded by spaces

$headers = array();
$headers[] = "User-Agent: " . USER_AGENT;
$headers[] = "Content-type: application/json";
$headers[] = "Authorization: Bearer " . $gitHubToken;

$fields = array(
CURLOPT_URL => $baseUrl . $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,
CURLOPT_HTTPHEADER => $headers
);

if ($data !== null) {
$fields[CURLOPT_POST] = true;
$fields[CURLOPT_POSTFIELDS] = json_encode($data);
}

$curl = curl_init();

curl_setopt_array($curl, $fields);

$response = curl_exec($curl);

if ($response === false) {
echo htmlspecialchars($url);
echo "\r\n";
die(curl_error($curl));
}

$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);
$header = substr($response, 0, $headerSize);
$headers = extractHeaders($header);
$body = substr($response, $headerSize);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);
curl_close($curl);

return array("status" => $http_code, "headers" => $headers, "body" => $body);
return doRequest($url, $gitHubToken, $data);
}

function generateAppToken()
Expand Down
50 changes: 50 additions & 0 deletions Src/lib/request.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php


function doRequest($url, $authorizationBearerToken, $data = null)

Check notice on line 4 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L4

Avoid excessively long variable names like $authorizationBearerToken. Keep variable name length under 20.

Check notice on line 4 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L4

Incorrect spacing between argument "$data" and equals sign; expected 0 but found 1
{
$headers = array();

Check notice on line 6 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L6

Short array syntax must be used to define arrays
$headers[] = "User-Agent: " . USER_AGENT;

Check notice on line 7 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L7

Concat operator must not be surrounded by spaces
$headers[] = "Content-type: application/json";
$headers[] = "Authorization: Bearer " . $authorizationBearerToken;

$fields = array(

Check notice on line 11 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L11

Short array syntax must be used to define arrays
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => true,

Check notice on line 14 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L14

Array key not aligned correctly; expected 15 spaces but found 8
CURLOPT_ENCODING => "",
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,

Check notice on line 17 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L17

Array key not aligned correctly; expected 15 spaces but found 8
CURLOPT_FOLLOWLOCATION => true,

Check notice on line 18 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L18

Array key not aligned correctly; expected 15 spaces but found 8
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => false,

Check notice on line 21 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L21

Array key not aligned correctly; expected 15 spaces but found 8
CURLOPT_HTTPHEADER => $headers

Check notice on line 22 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L22

Array key not aligned correctly; expected 15 spaces but found 8
);

if ($data !== null) {
$fields[CURLOPT_POST] = true;
$fields[CURLOPT_POSTFIELDS] = json_encode($data);
}

$curl = curl_init();

Check warning on line 30 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L30

The use of function curl_init() is discouraged

curl_setopt_array($curl, $fields);

Check warning on line 32 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L32

The use of function curl_setopt_array() is discouraged

$response = curl_exec($curl);

if ($response === false) {
echo htmlspecialchars($url);

Check failure on line 37 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L37

Use of echo language construct is discouraged.
echo "\r\n";

Check failure on line 38 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L38

Use of echo language construct is discouraged.
die(curl_error($curl));

Check failure on line 39 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L39

All output should be run through an escaping function (see the Security sections in the WordPress Developer Handbooks), found 'curl_error'.

Check warning on line 39 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L39

The function doRequest() contains an exit expression.

Check warning on line 39 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L39

The use of function curl_error() is discouraged

Check failure on line 39 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L39

Use of die language construct is discouraged.
}

$headerSize = curl_getinfo($curl, CURLINFO_HEADER_SIZE);

Check warning on line 42 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L42

The use of function curl_getinfo() is discouraged
$header = substr($response, 0, $headerSize);
$headers = extractHeaders($header);
$body = substr($response, $headerSize);
$http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE);

Check warning on line 46 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L46

The use of function curl_getinfo() is discouraged
curl_close($curl);

Check warning on line 47 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L47

The use of function curl_close() is discouraged

return array("status" => $http_code, "headers" => $headers, "body" => $body);

Check notice on line 49 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L49

Array with multiple values cannot be declared on a single line
}

Check notice on line 50 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L50

Expected //end doRequest()

Check notice on line 50 in Src/lib/request.php

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

Src/lib/request.php#L50

Expected 1 blank line before closing function brace; 0 found
Loading