Skip to content

Commit

Permalink
Fix phpcs warning
Browse files Browse the repository at this point in the history
  • Loading branch information
ulrikmoe committed Oct 6, 2023
1 parent 66085ce commit 87c34a2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

[![Latest Stable Version](https://img.shields.io/github/v/release/scanpay/php-scanpay?cacheSeconds=600)](https://packagist.org/packages/scanpay/scanpay)
[![License](https://img.shields.io/github/license/scanpay/php-scanpay?cacheSeconds=6000)](https://github.com/scanpay/php-scanpay/blob/master/LICENSE)
[![CodeFactor Grade](https://img.shields.io/codefactor/grade/github/scanpay/php-scanpay?cacheSeconds=6000)](https://www.codefactor.io/repository/github/scanpay/php-scanpay)

The Scanpay PHP client library provides convenient and simplified access to the Scanpay API from programs written in PHP. The library is developed and maintained by Scanpay in Denmark.

Expand Down
16 changes: 8 additions & 8 deletions lib/Scanpay.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class IdempotentResponseException extends \Exception

class Scanpay
{
private object $ch; // CurlHandle. Not allowed until 8.0
private $ch; // CurlHandle class is added PHP 8.0
private array $headers;
private string $apikey;
private string $idemstatus;
Expand Down Expand Up @@ -59,7 +59,7 @@ private function request(string $path, array $opts = [], array $data = null): ar
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_HTTPHEADER => array_values($headers),
CURLOPT_VERBOSE => $opts['debug'] ?? 0,
CURLOPT_TCP_KEEPALIVE => 1, // CURLOPT_TCP_KEEPINTVL & CURLOPT_TCP_KEEPIDLE
CURLOPT_TCP_KEEPALIVE => 1, // TODO: CURLOPT_TCP_KEEPINTVL & CURLOPT_TCP_KEEPIDLE
CURLOPT_RETURNTRANSFER => 1,
CURLOPT_CONNECTTIMEOUT => 20,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_2TLS,
Expand Down Expand Up @@ -89,21 +89,21 @@ private function request(string $path, array $opts = [], array $data = null): ar
throw new \Exception(curl_strerror(curl_errno($this->ch)));
}

$statusCode = curl_getinfo($this->ch, CURLINFO_RESPONSE_CODE);
$statusCode = (int) curl_getinfo($this->ch, CURLINFO_RESPONSE_CODE);
if ($statusCode !== 200) {
throw new \Exception(('Scanpay returned "' . explode("\n", $result)[0] . '"'));
}

// Validate Idempotency-Status
if (isset($headers['idempotency-key']) && $this->idemstatus !== 'ok') {
throw new \Exception("Server failed to provide idempotency. Scanpay returned $statusCode - " . explode("\n", $result)[0]);
throw new \Exception("Server failed to provide idempotency. Scanpay returned $statusCode - "
. explode("\n", $result)[0]);
}

// Decode the json response (@: suppress warnings)
if (!is_array($resobj = @json_decode($result, true))) {
$json = json_decode($result, true);
if (!is_array($json)) {
throw new IdempotentResponseException('Invalid JSON response from server');
}
return $resobj;
return $json;
}

// newURL: Create a new payment link
Expand Down

0 comments on commit 87c34a2

Please sign in to comment.