mirror of
https://github.com/php-curl-class/php-curl-class.git
synced 2026-08-31 04:34:27 +00:00
Merge pull request #378 from zachborboa/cleanup
Highlight continuous integration errors
This commit is contained in:
+1
-2
@@ -8,8 +8,7 @@ $curl->get('https://httpbin.org/get');
|
||||
|
||||
if ($curl->error) {
|
||||
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
echo 'Response:' . "\n";
|
||||
var_dump($curl->response);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
require __DIR__ . '/vendor/autoload.php';
|
||||
|
||||
use \Curl\Curl;
|
||||
|
||||
|
||||
const OAUTH2_AUTH_URL = 'https://accounts.google.com/o/oauth2/auth';
|
||||
const OAUTH2_TOKEN_URI = 'https://www.googleapis.com/oauth2/v4/token';
|
||||
|
||||
const CLIENT_ID = 'XXXXXXXXXXXX-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX.apps.googleusercontent.com';
|
||||
const CLIENT_SECRET = 'XXXXXXXXXXXXXXXXXXXXXXXX';
|
||||
const REDIRECT_URI = 'https://www.example.com/oauth2callback';
|
||||
|
||||
if (php_sapi_name() !== 'cli') {
|
||||
throw new Exception('This application must be run on the command line.');
|
||||
}
|
||||
|
||||
// Request authorization from the user.
|
||||
$auth_url = OAUTH2_AUTH_URL . '?' . http_build_query(array(
|
||||
'access_type' => 'offline',
|
||||
'approval_prompt' => 'force',
|
||||
'client_id' => CLIENT_ID,
|
||||
'redirect_uri' => REDIRECT_URI,
|
||||
'response_type' => 'code',
|
||||
'scope' => 'https://www.googleapis.com/auth/spreadsheets',
|
||||
));
|
||||
echo 'Open the following link in your browser:' . "\n";
|
||||
echo $auth_url . "\n";
|
||||
echo 'Enter verification code: ';
|
||||
$code = trim(fgets(STDIN));
|
||||
|
||||
// Exchange authorization code for an access token.
|
||||
$curl = new Curl();
|
||||
$curl->post(OAUTH2_TOKEN_URI, array(
|
||||
'client_id' => CLIENT_ID,
|
||||
'client_secret' => CLIENT_SECRET,
|
||||
'code' => $code,
|
||||
'grant_type' => 'authorization_code',
|
||||
'redirect_uri' => REDIRECT_URI,
|
||||
));
|
||||
$access_token = $curl->response;
|
||||
|
||||
// Update spreadsheet.
|
||||
$spreadsheet_id = '1Z2cXhdG-K44KgSzHTcGhx1dY-xY31yuYGwX21F4GeUp';
|
||||
$range = 'Sheet1!A1';
|
||||
$url = 'https://sheets.googleapis.com/v4/spreadsheets/' . $spreadsheet_id . '/values/' . $range;
|
||||
$url .= '?' . http_build_query(array(
|
||||
'valueInputOption' => 'USER_ENTERED',
|
||||
));
|
||||
|
||||
$data = array(
|
||||
'values' => array(
|
||||
array(
|
||||
'This is cell A1',
|
||||
'B1',
|
||||
'C1',
|
||||
'and D1',
|
||||
),
|
||||
),
|
||||
);
|
||||
|
||||
$curl = new Curl();
|
||||
$curl->setHeader('Content-Type', 'application/json');
|
||||
$curl->setHeader('Authorization', 'Bearer ' . $access_token->access_token);
|
||||
$curl->put($url, $data);
|
||||
|
||||
if ($curl->error) {
|
||||
echo 'Error: ' . $curl->errorCode . ': ' . $curl->errorMessage;
|
||||
var_dump($curl);
|
||||
} else {
|
||||
var_dump($curl->response);
|
||||
}
|
||||
+11
-8
@@ -10,14 +10,14 @@ if [[ "${?}" -ne 0 ]]; then
|
||||
fi
|
||||
|
||||
# Enforce line ending consistency in php files.
|
||||
crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --files-with-matches $'\r' {} \;)
|
||||
crlf_file=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --files-with-matches $'\r' {} \;)
|
||||
if [[ ! -z "${crlf_file}" ]]; then
|
||||
echo "${crlf_file}" | perl -pe 's/(.*)/CRLF line terminators found in \1/'
|
||||
((errors++))
|
||||
fi
|
||||
|
||||
# Enforce indentation character consistency in php files.
|
||||
tab_char=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --line-number -H --perl-regexp "\t" {} \;)
|
||||
tab_char=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp "\t" {} \;)
|
||||
if [[ ! -z "${tab_char}" ]]; then
|
||||
echo -e "${tab_char}" | perl -pe 's/^(.*)$/Tab character found in \1/'
|
||||
((errors++))
|
||||
@@ -60,7 +60,7 @@ if [[ "${TRAVIS_PHP_VERSION}" != "hhvm" ]]; then
|
||||
fi
|
||||
|
||||
# Prohibit trailing whitespace in php files.
|
||||
trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --line-number -H " +$" {} \;)
|
||||
trailing_whitespace=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H " +$" {} \;)
|
||||
if [[ ! -z "${trailing_whitespace}" ]]; then
|
||||
echo -e "${trailing_whitespace}" | perl -pe 's/^(.*)$/Trailing whitespace found in \1/'
|
||||
((errors++))
|
||||
@@ -74,7 +74,7 @@ if [[ ! -z "${long_lines}" ]]; then
|
||||
fi
|
||||
|
||||
# Prohibit @author in php files.
|
||||
at_author=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --line-number -H "@author" {} \;)
|
||||
at_author=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec egrep --color=always --line-number -H "@author" {} \;)
|
||||
if [[ ! -z "${at_author}" ]]; then
|
||||
echo -e "${at_author}" | perl -pe 's/^(.*)$/\@author found in \1/'
|
||||
((errors++))
|
||||
@@ -101,8 +101,11 @@ if [[ ! -z "${elseif}" ]]; then
|
||||
((errors++))
|
||||
fi
|
||||
|
||||
if [ $errors -eq 0 ]; then
|
||||
exit 0
|
||||
else
|
||||
exit 1
|
||||
# Require both braces on else statement line; "} else {" and not "}\nelse {".
|
||||
elses=$(find . -type "f" -iname "*.php" ! -path "*/vendor/*" -exec grep --color=always --line-number -H --perl-regexp '^(\s+)?else(\s+)?{' {} \;)
|
||||
if [[ ! -z "${elses}" ]]; then
|
||||
echo -e "${elses}" | perl -pe 's/^(.*)$/Found newline before "else" statement in \1/'
|
||||
((errors++))
|
||||
fi
|
||||
|
||||
exit "${errors}"
|
||||
|
||||
Reference in New Issue
Block a user