Skip to content

Commit

Permalink
support for PHP 8.2 and function type updates
Browse files Browse the repository at this point in the history
  • Loading branch information
timoladoyinbo committed Mar 4, 2023
1 parent 6c0b93b commit a8599c2
Show file tree
Hide file tree
Showing 30 changed files with 169 additions and 365 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.0, 8.1]
php: [8.0, 8.1, 8.2]
dependency-version: [prefer-lowest, prefer-stable]

name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}
Expand Down
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ docs
vendor
coverage
.phpunit.result.cache
.phpunit.cache
.php_cs.cache
/.idea
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

All notable changes to `paystack-php` will be documented in this file

## v2.2.0 - 2023-03-04
- Added support for PHP 8.2

## v2.1.0 - 2022-07-05
- Added support for PHP 8.1

Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@
"authors": [
{
"name": "Tim Oladoyinbo",
"email": "dev@digitalkraaft.com",
"homepage": "https://digitalkraaft.com",
"email": "hello@digikraaft.ng",
"homepage": "https://digikraaft.com",
"role": "Developer"
}
],
"require": {
"php": "^8.0|^8.1",
"php": "^8.0|^8.1|^8.2",
"guzzlehttp/guzzle": "^7.2.0",
"ext-json": "*"
},
Expand Down
8 changes: 2 additions & 6 deletions src/ApiOperations/All.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

trait All
{
/**
* @param null|array $params query parameters
*
* @return array|object
*/
public static function list($params = null)

public static function list($params = null): array|object
{
self::validateParams($params);
$url = static::classUrl();
Expand Down
8 changes: 2 additions & 6 deletions src/ApiOperations/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

trait Create
{
/**
* @param array $params
*
* @return array|object
*/
public static function create($params)

public static function create($params): array|object
{
self::validateParams($params, true);
$url = static::classUrl();
Expand Down
8 changes: 2 additions & 6 deletions src/ApiOperations/Fetch.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

trait Fetch
{
/**
* @param string $id Resource id
*
* @return array|object
*/
public static function fetch(string $id)

public static function fetch(string $id): array|object
{
$url = static::resourceUrl($id);

Expand Down
59 changes: 10 additions & 49 deletions src/ApiOperations/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,14 @@
*/
trait Request
{
/**
* Instance of Client.
*/

protected static $client;

/**
* Response from requests made to Paystack.
*
* @var mixed
*/
protected static $response;

/**
* @param null|array|mixed $params The list of parameters to validate
* @param bool $required
*
* @throws InvalidArgumentException if $params exists and is not an array
*/
public static function validateParams($params = null, $required = false): void
protected static mixed $response;


public static function validateParams(mixed $params = null, bool $required = false): void
{
if ($required) {
if (empty($params) || ! is_array($params)) {
Expand All @@ -46,18 +35,7 @@ public static function validateParams($params = null, $required = false): void
}
}

/**
* @param string $method HTTP method ('get', 'post', etc.)
* @param string $url URL for the request
* @param array $params list of parameters for the request
* @param string $return_type return array or object accepted values: 'arr' and 'obj'
*
* @throws InvalidArgumentException
* @throws IsNullException
*
* @return array|object (the JSON response as array or object)
*/
public static function staticRequest($method, $url, $params = [], $return_type = 'obj')
public static function staticRequest(string $method, string $url, array $params = [], string $return_type = 'obj'): array|object
{
if ($return_type != 'arr' && $return_type != 'obj') {
throw new InvalidArgumentException('Return type can only be obj or arr');
Expand Down Expand Up @@ -90,18 +68,9 @@ protected static function setRequestOptions(): void
);
}

/**
* @param string $url
* @param string $method
* @param array $body
*
* @throws IsNullException
*/
private static function setHttpResponse($method, $url, $body = []): \GuzzleHttp\Psr7\Response

private static function setHttpResponse(string $method, string $url, array $body = []): \GuzzleHttp\Psr7\Response
{
if (is_null($method)) {
throw new IsNullException('Empty method not allowed');
}

static::setRequestOptions();

Expand All @@ -113,21 +82,13 @@ private static function setHttpResponse($method, $url, $body = []): \GuzzleHttp\
return static::$response;
}

/**
* Get the data response from an API operation.
*
* @return array
*/

private static function getResponse(): array
{
return json_decode(static::$response->getBody(), true);
}

/**
* Get the data response from a get operation.
*
* @return array
*/

private static function getResponseData(): array
{
return json_decode(static::$response->getBody(), true)['data'];
Expand Down
9 changes: 2 additions & 7 deletions src/ApiOperations/Update.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,8 @@

trait Update
{
/**
* @param string $id Resource id
* @param array $params
*
* @return array|object
*/
public static function update(string $id, $params)

public static function update(string $id, array $params): array|object
{
self::validateParams($params, true);
$url = static::resourceUrl($id);
Expand Down
37 changes: 10 additions & 27 deletions src/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,25 @@ class ApiResource

use ApiOperations\Request;

/**
* @return string the base URL for the given class
*/
public static function baseUrl()

public static function baseUrl(): string
{
return Paystack::$apiBase;
}

/**
* @return string the endpoint URL for the given class
*/
public static function classUrl()

public static function classUrl(): string
{
$base = static::OBJECT_NAME;

return "{$base}";
}


/**
* @param null|string $id the ID of the resource
*
* @throws InvalidArgumentException if $id is null
*
* @return string the endpoint URL for the given class
* @throws InvalidArgumentException
*/
public static function resourceUrl($id)
public static function resourceUrl(?string $id = null): string
{
if (null === $id) {
$message = 'Invalid ID supplied. ID cannot be null';
Expand All @@ -49,26 +42,16 @@ public static function resourceUrl($id)
return "{$base}/{$extn}";
}

/**
* @param string $slug
*
* @return string the endpoint URL for the given class
*/
public static function endPointUrl($slug)
public static function endPointUrl(string $slug): string
{
$slug = Util\Util::utf8($slug);
$base = static::classUrl();

return "{$base}/{$slug}";
}

/**
* @param string $slug
* @param $params array of query parameters
*
* @return string the endpoint URL for the given class
*/
public static function buildQueryString($slug, $params = null)

public static function buildQueryString(string $slug, array $params = null): string
{
$url = self::endPointUrl($slug);
if (! empty($params)) {
Expand Down
12 changes: 5 additions & 7 deletions src/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,22 @@

namespace Digikraaft\Paystack;

use Digikraaft\Paystack\Exceptions\InvalidArgumentException;

class Balance extends ApiResource
{
const OBJECT_NAME = 'balance';

use ApiOperations\All;

/**
* @param array $params
*
* @throws Exceptions\InvalidArgumentException|Exceptions\IsNullException
*
* @param array|null $params
* @return array|object
*
* @throws InvalidArgumentException
* @link https://developers.paystack.co/reference#fetch-balance-history
*
* @returns array|Object
*/
public static function ledger($params = null)
public static function ledger(?array $params = null): array|object
{
self::validateParams($params);
$url = self::buildQueryString('ledger', $params);
Expand Down
5 changes: 1 addition & 4 deletions src/BalanceHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,12 @@ class BalanceHistory extends ApiResource
const OBJECT_NAME = 'balance';

/**
* @param array $params
*
* @throws Exceptions\InvalidArgumentException
*
* @return array|object
*
* @link https://developers.paystack.co/reference#fetch-balance-history
*/
public static function ledger($params)
public static function ledger(array $params): array|object
{
self::validateParams($params, true);
$url = static::classUrl().'/ledger';
Expand Down
19 changes: 7 additions & 12 deletions src/Bank.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@

namespace Digikraaft\Paystack;

use Digikraaft\Paystack\Exceptions\InvalidArgumentException;

class Bank extends ApiResource
{
const OBJECT_NAME = 'bank';

use ApiOperations\All;

/**
* @param string $bvn
*
* @throws InvalidArgumentException
* @link https://paystack.com/docs/api/#verification-resolve-bvn
*
* @return array|object
*/
public static function resolveBvn(string $bvn)
public static function resolveBvn(string $bvn): array|object
{
$url = "resolve_bvn/{$bvn}";
$url = static::endPointUrl($url);
Expand All @@ -24,27 +24,22 @@ public static function resolveBvn(string $bvn)
}

/**
* @param string $bvn
* @return array|object
*
* @throws Exceptions\InvalidArgumentException
* @throws Exceptions\IsNullException
* @link https://paystack.com/docs/api/#verification-resolve-bvn-premium
*/
public static function resolveBvnPremium(string $bvn)
public static function resolveBvnPremium(string $bvn): array|object
{
$url = "identity/bvn/resolve/{$bvn}";

return static::staticRequest('GET', $url);
}

/**
* @param array $params
*
* @link https://paystack.com/docs/api/#verification-match-bvn
*
* @return array|object
*/
public static function bvnMatch($params)
public static function bvnMatch(array $params): array|object
{
self::validateParams($params);
$url = urlencode('bvn/match');
Expand Down
Loading

0 comments on commit a8599c2

Please sign in to comment.