Skip to content

Commit

Permalink
Merge pull request #5 from festivalslab/support-php8
Browse files Browse the repository at this point in the history
Support PHP 8.0
  • Loading branch information
craig410 authored Oct 12, 2021
2 parents 0874816 + 5562bc8 commit 17f8779
Show file tree
Hide file tree
Showing 13 changed files with 127 additions and 250 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Run tests
on:
push:
branches:
# Only mainline branches, features etc are covered on the pull_request trigger
- '*.x'
pull_request:

jobs:
run-tests:
runs-on: ubuntu-latest
name: Run tests
strategy:
fail-fast: false
matrix:
php_version:
- '7.4'
- '8.0'
dependencies:
- 'default'
include:
- php_version: '7.4'
dependencies: 'lowest'
- php_version: '8.0'
dependencies: 'lowest'
steps:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php_version }}
tools: composer:v2

- name: Checkout
uses: actions/checkout@v2

- name: Get Composer Cache Directory
id: composer-cache
run: |
echo "::set-output name=dir::$(composer config cache-files-dir)"
- uses: actions/cache@v2
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ matrix.dependencies }}-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-${{ matrix.dependencies }}
- name: Install composer dependencies
env:
DEPENDENCIES: ${{ matrix.dependencies }}
run: |
if [ $DEPENDENCIES == 'lowest' ]
then
composer update --prefer-lowest --no-interaction --no-progress
else
composer install --no-interaction --no-progress
fi
- name: Run unit tests
run: |
vendor/bin/phpunit
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
Thumbs.db
thumbs.db
/composer.lock
.phpunit.result.cache
21 changes: 0 additions & 21 deletions .travis.yml

This file was deleted.

6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
### Unreleased

### v2.0.0 (2021-10-12)

* Drop support for php 7.2
* Support php 7.4 & 8.0
* Support Guzzle 6 and 7

### v1.0.1 (2019-11-18)

* Accept (and ignore) a trailing `/` on the API client base url parameter, if provided.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ The Edinburgh Festivals Listings API client for PHP makes it easy for developers

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

[![Build Status](https://travis-ci.org/festivalslab/api-client-php.svg?branch=1.0.x)](https://travis-ci.org/festivalslab/api-client-php)
[![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)

## Quick Examples

Expand Down
13 changes: 4 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
}
],
"require": {
"guzzlehttp/guzzle": "^6.0",
"php": "^7.2"
"guzzlehttp/guzzle": "^6.2 || ^7.0",
"php": "^7.4 || ~8.0.0"
},
"require-dev": {
"phpunit/phpunit": "^7.0",
"johnkary/phpunit-speedtrap": "^3.0"
"phpunit/phpunit": "^9.5",
"johnkary/phpunit-speedtrap": "^3.3"
},
"support": {
"source": "https://github.com/festivalslab/api-client-php",
Expand All @@ -27,11 +27,6 @@
"FestivalsApi\\": "src/"
}
},
"autoload-dev": {
"psr-4": {
"test\\unit\\FestivalsApi\\": "test"
}
},
"config": {
"preferred-install": "dist"
}
Expand Down
27 changes: 13 additions & 14 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,23 +1,22 @@
<?xml version="1.0" ?>
<?xml version="1.0"?>
<!-- Config file for PHPUnit automated tests -->
<phpunit
bootstrap="test/phpunit-bootstrap.php"
cacheTokens="false"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="test/phpunit-bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src</directory>
</include>
</coverage>
<testsuites>
<testsuite name="unit">
<directory>test/unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src</directory>
</whitelist>
</filter>
<listeners>
<listener class="JohnKary\PHPUnit\Listener\SpeedTrapListener">
<arguments>
Expand Down
34 changes: 5 additions & 29 deletions src/EventSearchIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,42 +18,22 @@

class EventSearchIterator implements IteratorAggregate
{
/**
* @var FestivalsApiClient
*/
protected $client;
protected FestivalsApiClient $client;

/**
* @var EventSearchResult
*/
protected $last_result;
protected EventSearchResult $last_result;

/**
* @var int
*/
protected $page_size;
protected ?int $page_size = NULL;

/**
* @var array
*/
protected $query;
protected ?array $query = NULL;

/**
* @var int
*/
protected $request_count = 0;
protected int $request_count = 0;

/**
* @param FestivalsApiClient $client
*/
public function __construct(FestivalsApiClient $client)
{
$this->client = $client;
}

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

/**
* Total number of calls to API made by this query
*
* @return int
*/
public function getNoOfRequestsMadeByQuery(): int
{
Expand All @@ -99,8 +77,6 @@ public function setQuery(array $query, int $page_size = 100): void
/**
* Execute the query and return the events
*
* @return array
*
* @throws GuzzleException
* @throws FestivalsApiClientException
*/
Expand Down
69 changes: 6 additions & 63 deletions src/FestivalsApiClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,31 +22,15 @@ class FestivalsApiClient
const BASE_URL = 'https://api.edinburghfestivalcity.com';
const EVENTS_ENDPOINT = '/events';

/**
* @var string
*/
protected $access_key;
protected string $access_key;

/**
* @var string
*/
protected $base_url;
protected string $base_url;

/**
* @var Client
*/
protected $guzzle;
protected Client $guzzle;

/**
* @var string
*/
protected $secret;
protected string $secret;

/**
* @param Client $guzzle
* @param string $base_url
*/
public function __construct(Client $guzzle, $base_url = self::BASE_URL)
public function __construct(Client $guzzle, string $base_url = self::BASE_URL)
{
$this->guzzle = $guzzle;
$this->setBaseUrl($base_url);
Expand All @@ -55,9 +39,6 @@ public function __construct(Client $guzzle, $base_url = self::BASE_URL)
/**
* Load a single event by ID or throw if not found
*
* @param string $id
*
* @return SingleEventResult
* @throws GuzzleException
* @throws FestivalsApiClientException if event not found
*/
Expand All @@ -75,9 +56,6 @@ public function loadEvent(string $id): SingleEventResult
/**
* Search API for events matching query
*
* @param array $query
*
* @return EventSearchResult
* @throws FestivalsApiClientException
* @throws GuzzleException
*/
Expand All @@ -98,29 +76,17 @@ public function searchEvents(array $query): EventSearchResult
return new EventSearchResult($events, (string) $request->getUri(), $total_results);
}

/**
* @param string $base_url
*/
public function setBaseUrl(string $base_url): void
{
$this->base_url = rtrim($base_url, '/');
}

/**
* @param string $access_key
* @param string $secret
*/
public function setCredentials(string $access_key, string $secret): void
{
$this->access_key = $access_key;
$this->secret = $secret;
}

/**
* @param string $url
*
* @return Request
*/
protected function createRequest(string $url): Request
{
$full_url = $this->base_url.$this->getSignedUrl($url);
Expand All @@ -129,12 +95,6 @@ protected function createRequest(string $url): Request
return $request;
}

/**
* @param ResponseInterface $response
*
* @return array
* @throws FestivalsApiClientException if JSON decode failed
*/
protected function decodeJsonResponse(ResponseInterface $response): array
{
try {
Expand All @@ -144,24 +104,13 @@ protected function decodeJsonResponse(ResponseInterface $response): array
}
}

/**
* Get signature for $data string
*
* @param string $data
*
* @return string
*/
protected function getSignature(string $data): string
{
return hash_hmac('sha1', $data, $this->secret);
}

/**
* Calculate signature and append it to the URL
*
* @param string $url
*
* @return string
*/
protected function getSignedUrl(string $url): string
{
Expand All @@ -177,11 +126,9 @@ protected function getSignedUrl(string $url): string
}

/**
* @param BadResponseException $e
*
* @throws FestivalsApiClientException
*/
protected function handleApiError($e): void
protected function handleApiError(BadResponseException $e): void
{
$msg = $e->getResponse()->getBody();
$code = $e->getResponse()->getStatusCode();
Expand All @@ -200,10 +147,6 @@ protected function handleApiError($e): void
}

/**
* @param Request $request
*
* @return ResponseInterface
*
* @throws GuzzleException
* @throws FestivalsApiClientException
*/
Expand Down
Loading

0 comments on commit 17f8779

Please sign in to comment.