Skip to content

Commit 17f8779

Browse files
authored
Merge pull request #5 from festivalslab/support-php8
Support PHP 8.0
2 parents 0874816 + 5562bc8 commit 17f8779

13 files changed

Lines changed: 127 additions & 250 deletions

.github/workflows/test.yaml

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
name: Run tests
2+
on:
3+
push:
4+
branches:
5+
# Only mainline branches, features etc are covered on the pull_request trigger
6+
- '*.x'
7+
pull_request:
8+
9+
jobs:
10+
run-tests:
11+
runs-on: ubuntu-latest
12+
name: Run tests
13+
strategy:
14+
fail-fast: false
15+
matrix:
16+
php_version:
17+
- '7.4'
18+
- '8.0'
19+
dependencies:
20+
- 'default'
21+
include:
22+
- php_version: '7.4'
23+
dependencies: 'lowest'
24+
- php_version: '8.0'
25+
dependencies: 'lowest'
26+
steps:
27+
- name: Setup PHP
28+
uses: shivammathur/setup-php@v2
29+
with:
30+
php-version: ${{ matrix.php_version }}
31+
tools: composer:v2
32+
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
36+
- name: Get Composer Cache Directory
37+
id: composer-cache
38+
run: |
39+
echo "::set-output name=dir::$(composer config cache-files-dir)"
40+
- uses: actions/cache@v2
41+
with:
42+
path: ${{ steps.composer-cache.outputs.dir }}
43+
key: ${{ runner.os }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}
44+
restore-keys: |
45+
${{ runner.os }}-composer-${{ matrix.dependencies }}
46+
- name: Install composer dependencies
47+
env:
48+
DEPENDENCIES: ${{ matrix.dependencies }}
49+
run: |
50+
if [ $DEPENDENCIES == 'lowest' ]
51+
then
52+
composer update --prefer-lowest --no-interaction --no-progress
53+
else
54+
composer install --no-interaction --no-progress
55+
fi
56+
- name: Run unit tests
57+
run: |
58+
vendor/bin/phpunit

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
Thumbs.db
55
thumbs.db
66
/composer.lock
7+
.phpunit.result.cache

.travis.yml

Lines changed: 0 additions & 21 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
### Unreleased
22

3+
### v2.0.0 (2021-10-12)
4+
5+
* Drop support for php 7.2
6+
* Support php 7.4 & 8.0
7+
* Support Guzzle 6 and 7
8+
39
### v1.0.1 (2019-11-18)
410

511
* Accept (and ignore) a trailing `/` on the API client base url parameter, if provided.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The Edinburgh Festivals Listings API client for PHP makes it easy for developers
55

66
You can get started quickly by [installing the client through composer](#installing)
77

8-
[![Build Status](https://travis-ci.org/festivalslab/api-client-php.svg?branch=1.0.x)](https://travis-ci.org/festivalslab/api-client-php)
8+
[![Build Status](https://github.com/festivalslab/api-client-php/actions/workflows/test.yaml/badge.svg)](https://github.com/festivalslab/api-client-php/actions/workflows/test.yaml)
99

1010
## Quick Examples
1111

composer.json

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
}
1212
],
1313
"require": {
14-
"guzzlehttp/guzzle": "^6.0",
15-
"php": "^7.2"
14+
"guzzlehttp/guzzle": "^6.2 || ^7.0",
15+
"php": "^7.4 || ~8.0.0"
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^7.0",
19-
"johnkary/phpunit-speedtrap": "^3.0"
18+
"phpunit/phpunit": "^9.5",
19+
"johnkary/phpunit-speedtrap": "^3.3"
2020
},
2121
"support": {
2222
"source": "https://github.com/festivalslab/api-client-php",
@@ -27,11 +27,6 @@
2727
"FestivalsApi\\": "src/"
2828
}
2929
},
30-
"autoload-dev": {
31-
"psr-4": {
32-
"test\\unit\\FestivalsApi\\": "test"
33-
}
34-
},
3530
"config": {
3631
"preferred-install": "dist"
3732
}

phpunit.xml

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
1-
<?xml version="1.0" ?>
1+
<?xml version="1.0"?>
22
<!-- Config file for PHPUnit automated tests -->
3-
<phpunit
4-
bootstrap="test/phpunit-bootstrap.php"
5-
cacheTokens="false"
6-
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
>
3+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
bootstrap="test/phpunit-bootstrap.php"
5+
colors="true"
6+
convertErrorsToExceptions="true"
7+
convertNoticesToExceptions="true"
8+
convertWarningsToExceptions="true"
9+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
10+
<coverage>
11+
<include>
12+
<directory suffix=".php">src</directory>
13+
</include>
14+
</coverage>
1115
<testsuites>
1216
<testsuite name="unit">
1317
<directory>test/unit</directory>
1418
</testsuite>
1519
</testsuites>
16-
<filter>
17-
<whitelist>
18-
<directory suffix=".php">src</directory>
19-
</whitelist>
20-
</filter>
2120
<listeners>
2221
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
2322
<arguments>

src/EventSearchIterator.php

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -18,42 +18,22 @@
1818

1919
class EventSearchIterator implements IteratorAggregate
2020
{
21-
/**
22-
* @var FestivalsApiClient
23-
*/
24-
protected $client;
21+
protected FestivalsApiClient $client;
2522

26-
/**
27-
* @var EventSearchResult
28-
*/
29-
protected $last_result;
23+
protected EventSearchResult $last_result;
3024

31-
/**
32-
* @var int
33-
*/
34-
protected $page_size;
25+
protected ?int $page_size = NULL;
3526

36-
/**
37-
* @var array
38-
*/
39-
protected $query;
27+
protected ?array $query = NULL;
4028

41-
/**
42-
* @var int
43-
*/
44-
protected $request_count = 0;
29+
protected int $request_count = 0;
4530

46-
/**
47-
* @param FestivalsApiClient $client
48-
*/
4931
public function __construct(FestivalsApiClient $client)
5032
{
5133
$this->client = $client;
5234
}
5335

5436
/**
55-
* @return Traversable
56-
*
5737
* @throws FestivalsApiClientException if API client encounters an error
5838
* @throws GuzzleException if Guzzle encounters an error
5939
* @throws LogicException if no query set
@@ -75,8 +55,6 @@ public function getIterator(): Traversable
7555

7656
/**
7757
* Total number of calls to API made by this query
78-
*
79-
* @return int
8058
*/
8159
public function getNoOfRequestsMadeByQuery(): int
8260
{
@@ -99,8 +77,6 @@ public function setQuery(array $query, int $page_size = 100): void
9977
/**
10078
* Execute the query and return the events
10179
*
102-
* @return array
103-
*
10480
* @throws GuzzleException
10581
* @throws FestivalsApiClientException
10682
*/

src/FestivalsApiClient.php

Lines changed: 6 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -22,31 +22,15 @@ class FestivalsApiClient
2222
const BASE_URL = 'https://api.edinburghfestivalcity.com';
2323
const EVENTS_ENDPOINT = '/events';
2424

25-
/**
26-
* @var string
27-
*/
28-
protected $access_key;
25+
protected string $access_key;
2926

30-
/**
31-
* @var string
32-
*/
33-
protected $base_url;
27+
protected string $base_url;
3428

35-
/**
36-
* @var Client
37-
*/
38-
protected $guzzle;
29+
protected Client $guzzle;
3930

40-
/**
41-
* @var string
42-
*/
43-
protected $secret;
31+
protected string $secret;
4432

45-
/**
46-
* @param Client $guzzle
47-
* @param string $base_url
48-
*/
49-
public function __construct(Client $guzzle, $base_url = self::BASE_URL)
33+
public function __construct(Client $guzzle, string $base_url = self::BASE_URL)
5034
{
5135
$this->guzzle = $guzzle;
5236
$this->setBaseUrl($base_url);
@@ -55,9 +39,6 @@ public function __construct(Client $guzzle, $base_url = self::BASE_URL)
5539
/**
5640
* Load a single event by ID or throw if not found
5741
*
58-
* @param string $id
59-
*
60-
* @return SingleEventResult
6142
* @throws GuzzleException
6243
* @throws FestivalsApiClientException if event not found
6344
*/
@@ -75,9 +56,6 @@ public function loadEvent(string $id): SingleEventResult
7556
/**
7657
* Search API for events matching query
7758
*
78-
* @param array $query
79-
*
80-
* @return EventSearchResult
8159
* @throws FestivalsApiClientException
8260
* @throws GuzzleException
8361
*/
@@ -98,29 +76,17 @@ public function searchEvents(array $query): EventSearchResult
9876
return new EventSearchResult($events, (string) $request->getUri(), $total_results);
9977
}
10078

101-
/**
102-
* @param string $base_url
103-
*/
10479
public function setBaseUrl(string $base_url): void
10580
{
10681
$this->base_url = rtrim($base_url, '/');
10782
}
10883

109-
/**
110-
* @param string $access_key
111-
* @param string $secret
112-
*/
11384
public function setCredentials(string $access_key, string $secret): void
11485
{
11586
$this->access_key = $access_key;
11687
$this->secret = $secret;
11788
}
11889

119-
/**
120-
* @param string $url
121-
*
122-
* @return Request
123-
*/
12490
protected function createRequest(string $url): Request
12591
{
12692
$full_url = $this->base_url.$this->getSignedUrl($url);
@@ -129,12 +95,6 @@ protected function createRequest(string $url): Request
12995
return $request;
13096
}
13197

132-
/**
133-
* @param ResponseInterface $response
134-
*
135-
* @return array
136-
* @throws FestivalsApiClientException if JSON decode failed
137-
*/
13898
protected function decodeJsonResponse(ResponseInterface $response): array
13999
{
140100
try {
@@ -144,24 +104,13 @@ protected function decodeJsonResponse(ResponseInterface $response): array
144104
}
145105
}
146106

147-
/**
148-
* Get signature for $data string
149-
*
150-
* @param string $data
151-
*
152-
* @return string
153-
*/
154107
protected function getSignature(string $data): string
155108
{
156109
return hash_hmac('sha1', $data, $this->secret);
157110
}
158111

159112
/**
160113
* Calculate signature and append it to the URL
161-
*
162-
* @param string $url
163-
*
164-
* @return string
165114
*/
166115
protected function getSignedUrl(string $url): string
167116
{
@@ -177,11 +126,9 @@ protected function getSignedUrl(string $url): string
177126
}
178127

179128
/**
180-
* @param BadResponseException $e
181-
*
182129
* @throws FestivalsApiClientException
183130
*/
184-
protected function handleApiError($e): void
131+
protected function handleApiError(BadResponseException $e): void
185132
{
186133
$msg = $e->getResponse()->getBody();
187134
$code = $e->getResponse()->getStatusCode();
@@ -200,10 +147,6 @@ protected function handleApiError($e): void
200147
}
201148

202149
/**
203-
* @param Request $request
204-
*
205-
* @return ResponseInterface
206-
*
207150
* @throws GuzzleException
208151
* @throws FestivalsApiClientException
209152
*/

0 commit comments

Comments
 (0)