Skip to content

Commit a8599c2

Browse files
committed
support for PHP 8.2 and function type updates
1 parent 6c0b93b commit a8599c2

30 files changed

Lines changed: 169 additions & 365 deletions

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ jobs:
99
fail-fast: true
1010
matrix:
1111
os: [ubuntu-latest, windows-latest]
12-
php: [8.0, 8.1]
12+
php: [8.0, 8.1, 8.2]
1313
dependency-version: [prefer-lowest, prefer-stable]
1414

1515
name: P${{ matrix.php }} - ${{ matrix.dependency-version }} - ${{ matrix.os }}

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,4 +4,6 @@ docs
44
vendor
55
coverage
66
.phpunit.result.cache
7+
.phpunit.cache
78
.php_cs.cache
9+
/.idea

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

5+
## v2.2.0 - 2023-03-04
6+
- Added support for PHP 8.2
7+
58
## v2.1.0 - 2022-07-05
69
- Added support for PHP 8.1
710

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
"authors": [
1212
{
1313
"name": "Tim Oladoyinbo",
14-
"email": "dev@digitalkraaft.com",
15-
"homepage": "https://digitalkraaft.com",
14+
"email": "hello@digikraaft.ng",
15+
"homepage": "https://digikraaft.com",
1616
"role": "Developer"
1717
}
1818
],
1919
"require": {
20-
"php": "^8.0|^8.1",
20+
"php": "^8.0|^8.1|^8.2",
2121
"guzzlehttp/guzzle": "^7.2.0",
2222
"ext-json": "*"
2323
},

src/ApiOperations/All.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44

55
trait All
66
{
7-
/**
8-
* @param null|array $params query parameters
9-
*
10-
* @return array|object
11-
*/
12-
public static function list($params = null)
7+
8+
public static function list($params = null): array|object
139
{
1410
self::validateParams($params);
1511
$url = static::classUrl();

src/ApiOperations/Create.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44

55
trait Create
66
{
7-
/**
8-
* @param array $params
9-
*
10-
* @return array|object
11-
*/
12-
public static function create($params)
7+
8+
public static function create($params): array|object
139
{
1410
self::validateParams($params, true);
1511
$url = static::classUrl();

src/ApiOperations/Fetch.php

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,8 @@
44

55
trait Fetch
66
{
7-
/**
8-
* @param string $id Resource id
9-
*
10-
* @return array|object
11-
*/
12-
public static function fetch(string $id)
7+
8+
public static function fetch(string $id): array|object
139
{
1410
$url = static::resourceUrl($id);
1511

src/ApiOperations/Request.php

Lines changed: 10 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -12,25 +12,14 @@
1212
*/
1313
trait Request
1414
{
15-
/**
16-
* Instance of Client.
17-
*/
15+
1816
protected static $client;
1917

20-
/**
21-
* Response from requests made to Paystack.
22-
*
23-
* @var mixed
24-
*/
25-
protected static $response;
2618

27-
/**
28-
* @param null|array|mixed $params The list of parameters to validate
29-
* @param bool $required
30-
*
31-
* @throws InvalidArgumentException if $params exists and is not an array
32-
*/
33-
public static function validateParams($params = null, $required = false): void
19+
protected static mixed $response;
20+
21+
22+
public static function validateParams(mixed $params = null, bool $required = false): void
3423
{
3524
if ($required) {
3625
if (empty($params) || ! is_array($params)) {
@@ -46,18 +35,7 @@ public static function validateParams($params = null, $required = false): void
4635
}
4736
}
4837

49-
/**
50-
* @param string $method HTTP method ('get', 'post', etc.)
51-
* @param string $url URL for the request
52-
* @param array $params list of parameters for the request
53-
* @param string $return_type return array or object accepted values: 'arr' and 'obj'
54-
*
55-
* @throws InvalidArgumentException
56-
* @throws IsNullException
57-
*
58-
* @return array|object (the JSON response as array or object)
59-
*/
60-
public static function staticRequest($method, $url, $params = [], $return_type = 'obj')
38+
public static function staticRequest(string $method, string $url, array $params = [], string $return_type = 'obj'): array|object
6139
{
6240
if ($return_type != 'arr' && $return_type != 'obj') {
6341
throw new InvalidArgumentException('Return type can only be obj or arr');
@@ -90,18 +68,9 @@ protected static function setRequestOptions(): void
9068
);
9169
}
9270

93-
/**
94-
* @param string $url
95-
* @param string $method
96-
* @param array $body
97-
*
98-
* @throws IsNullException
99-
*/
100-
private static function setHttpResponse($method, $url, $body = []): \GuzzleHttp\Psr7\Response
71+
72+
private static function setHttpResponse(string $method, string $url, array $body = []): \GuzzleHttp\Psr7\Response
10173
{
102-
if (is_null($method)) {
103-
throw new IsNullException('Empty method not allowed');
104-
}
10574

10675
static::setRequestOptions();
10776

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

116-
/**
117-
* Get the data response from an API operation.
118-
*
119-
* @return array
120-
*/
85+
12186
private static function getResponse(): array
12287
{
12388
return json_decode(static::$response->getBody(), true);
12489
}
12590

126-
/**
127-
* Get the data response from a get operation.
128-
*
129-
* @return array
130-
*/
91+
13192
private static function getResponseData(): array
13293
{
13394
return json_decode(static::$response->getBody(), true)['data'];

src/ApiOperations/Update.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,8 @@
44

55
trait Update
66
{
7-
/**
8-
* @param string $id Resource id
9-
* @param array $params
10-
*
11-
* @return array|object
12-
*/
13-
public static function update(string $id, $params)
7+
8+
public static function update(string $id, array $params): array|object
149
{
1510
self::validateParams($params, true);
1611
$url = static::resourceUrl($id);

src/ApiResource.php

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -10,32 +10,25 @@ class ApiResource
1010

1111
use ApiOperations\Request;
1212

13-
/**
14-
* @return string the base URL for the given class
15-
*/
16-
public static function baseUrl()
13+
14+
public static function baseUrl(): string
1715
{
1816
return Paystack::$apiBase;
1917
}
2018

21-
/**
22-
* @return string the endpoint URL for the given class
23-
*/
24-
public static function classUrl()
19+
20+
public static function classUrl(): string
2521
{
2622
$base = static::OBJECT_NAME;
2723

2824
return "{$base}";
2925
}
3026

27+
3128
/**
32-
* @param null|string $id the ID of the resource
33-
*
34-
* @throws InvalidArgumentException if $id is null
35-
*
36-
* @return string the endpoint URL for the given class
29+
* @throws InvalidArgumentException
3730
*/
38-
public static function resourceUrl($id)
31+
public static function resourceUrl(?string $id = null): string
3932
{
4033
if (null === $id) {
4134
$message = 'Invalid ID supplied. ID cannot be null';
@@ -49,26 +42,16 @@ public static function resourceUrl($id)
4942
return "{$base}/{$extn}";
5043
}
5144

52-
/**
53-
* @param string $slug
54-
*
55-
* @return string the endpoint URL for the given class
56-
*/
57-
public static function endPointUrl($slug)
45+
public static function endPointUrl(string $slug): string
5846
{
5947
$slug = Util\Util::utf8($slug);
6048
$base = static::classUrl();
6149

6250
return "{$base}/{$slug}";
6351
}
6452

65-
/**
66-
* @param string $slug
67-
* @param $params array of query parameters
68-
*
69-
* @return string the endpoint URL for the given class
70-
*/
71-
public static function buildQueryString($slug, $params = null)
53+
54+
public static function buildQueryString(string $slug, array $params = null): string
7255
{
7356
$url = self::endPointUrl($slug);
7457
if (! empty($params)) {

0 commit comments

Comments
 (0)