Skip to content

Commit

Permalink
Merge pull request #9 from Harrk/release/2.0
Browse files Browse the repository at this point in the history
Upgrade packages. Remove support for PHP7. Add return types.
  • Loading branch information
Harrk authored Feb 19, 2023
2 parents 413484b + d9c3173 commit 488c2c6
Show file tree
Hide file tree
Showing 27 changed files with 294 additions and 350 deletions.
19 changes: 5 additions & 14 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,17 @@
version: 2

jobs:
"php-7.2":
docker:
- image: circleci/php:7.2
steps:
- checkout
- run: composer install
- run: ./vendor/bin/phpunit

"php-8.0":
"php-8.1":
docker:
- image: circleci/php:8.0
- image: cimg/php:8.1
steps:
- checkout
- run: composer install
- run: ./vendor/bin/phpunit

"php-8.1":
"php-8.2":
docker:
- image: cimg/php:8.1
- image: cimg/php:8.2
steps:
- checkout
- run: composer install
Expand All @@ -29,6 +21,5 @@ workflows:
version: 2
build:
jobs:
- "php-7.2"
- "php-8.0"
- "php-8.1"
- "php-8.2"
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ Create an instance of GamejoltApi and provide a GamejoltConfig
to begin making API calls to Game Jolt.

```php
$gameId = 0; // Your game's ID
$gamePrivaykey = "Your game's private key";

$api = new GamejoltApi(new GamejoltConfig(
'mygameid',
'mygameprivatekey'
$gameId,
$gamePrivaykey
));
```

Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"authors": [
{
"name": "Harry Kirkman",
"homepage": "https://harrykirkman.co.uk"
"homepage": "https://harrk.dev"
}
],
"description": "A PHP library for the Game Jolt API.",
Expand All @@ -23,16 +23,16 @@
}
},
"require": {
"php": "^7.2|^8.0",
"guzzlehttp/guzzle": "^6.5.7|^7.4.5",
"php": "^8.1|8.2",
"guzzlehttp/guzzle": "^7.5",
"ext-json": "*"
},
"require-dev": {
"phpunit/phpunit": "^7.5|^9.3.3",
"phpstan/phpstan": "^0.11.0|^0.12.0"
"phpunit/phpunit": "^10.0",
"phpstan/phpstan": "^1.9.18"
},
"scripts": {
"test": "vendor/bin/phpunit",
"analyse": "vendor/bin/phpstan analyse ./src --level=5"
"analyse": "vendor/bin/phpstan analyse ./src --level 5"
}
}
40 changes: 15 additions & 25 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,17 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap = "vendor/autoload.php"
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
processIsolation = "false"
stopOnFailure = "false">

<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>

<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>

<php>
<env name="APP_ENV" value="testing"/>
</php>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.0/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Project Test Suite">
<directory>tests</directory>
<exclude>tests/GamejoltApiBaseTest.php</exclude>
</testsuite>
</testsuites>
<php>
<env name="APP_ENV" value="testing"/>
</php>
</phpunit>
6 changes: 3 additions & 3 deletions src/ApiCallService.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Harrk\GameJoltApi;

use GuzzleHttp\Client;
use GuzzleHttp\Exception\GuzzleException;
use Harrk\GameJoltApi\Exceptions\TimeOutException;
use Harrk\GameJoltApi\Callers\AbstractCaller;
use GuzzleHttp\Exception\ConnectException;
Expand Down Expand Up @@ -35,11 +36,10 @@ public function __construct(AbstractCaller $caller) {
}

/**
* @return array
* @throws TimeOutException
* @throws \GuzzleHttp\Exception\GuzzleException
* @throws GuzzleException
*/
public function execute() {
public function execute(): array {
try {
$request = $this->client->request(
$this->method,
Expand Down
50 changes: 18 additions & 32 deletions src/Callers/AbstractCaller.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,18 @@
use Harrk\GameJoltApi\GamejoltConfig;

class AbstractCaller {
protected string $uri;
protected array $params;
protected GamejoltConfig $gameJoltConfig;

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

/**
* @var array
*/
protected $params;

/**
* @var GamejoltConfig
*/
protected $gameJoltConfig;


public function __construct(GamejoltConfig $gamejoltConfig) {
public function __construct(GamejoltConfig $gamejoltConfig)
{
$this->gameJoltConfig = $gamejoltConfig;
}

protected function getSignature(string $url, array $params = []) {
protected function getSignature(string $url, array $params = []): string
{
$urlWithPrivateKey = $url . $this->gameJoltConfig->getPrivateKey();
$toHashString = $urlWithPrivateKey;

Expand All @@ -46,7 +36,8 @@ protected function getSignature(string $url, array $params = []) {
return sha1($toHashString);
}

public function getFullUrl($withSignature = false) {
public function getFullUrl(bool $withSignature = false)
{
$url = $this->gameJoltConfig->getEndpoint() . $this->uri . '/';

$url .= '?' . http_build_query($this->getParams());
Expand All @@ -58,23 +49,18 @@ public function getFullUrl($withSignature = false) {
return $url;
}

public function call($uri, $params = []) {
public function call(string $uri, array $params = []): array
{
$this->uri = $uri;
$this->params = array_merge(
[
'game_id' => $this->gameJoltConfig->getGameId()
],
$params
);

$apiCallService = new ApiCallService($this);
$this->params = array_merge([
'game_id' => $this->gameJoltConfig->getGameId()
], $params);

return $apiCallService->execute();
return (new ApiCallService($this))->execute();
}

public function getParams() {
return array_filter((array) $this->params, function ($param) {
return ! empty($param);
});
public function getParams(): array
{
return array_filter($this->params, static fn ($param) => ! empty($param));
}
}
41 changes: 13 additions & 28 deletions src/Callers/DataStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
use Harrk\GameJoltApi\Exceptions\InvalidParameterException;

class DataStore extends AbstractCaller {
const OPERATION_ADD = 'add';
const OPERATION_SUBTRACT = 'subtract';
const OPERATION_MULTIPLY = 'multiply';
const OPERATION_DIVIDE = 'divide';
const OPERATION_APPEND = 'append';
const OPERATION_PREPEND = 'prepend';
public const OPERATION_ADD = 'add';
public const OPERATION_SUBTRACT = 'subtract';
public const OPERATION_MULTIPLY = 'multiply';
public const OPERATION_DIVIDE = 'divide';
public const OPERATION_APPEND = 'append';
public const OPERATION_PREPEND = 'prepend';

CONST OPERATIONS = [
public const OPERATIONS = [
self::OPERATION_ADD,
self::OPERATION_SUBTRACT,
self::OPERATION_MULTIPLY,
Expand All @@ -23,44 +23,29 @@ class DataStore extends AbstractCaller {

/**
* @link https://gamejolt.com/game-api/doc/data-store/fetch
*
* @param string $key
* @param null|string $username
* @param null|string $user_token
*
* @return array
*/
public function fetch($key, $username = null, $user_token = null) {
public function fetch(string $key, ?string $username = null, ?string $user_token = null): array
{
return $this->call('data-store', compact(
'key', 'username', 'user_token'
));
}

/**
* @link https://gamejolt.com/game-api/doc/data-store/get-keys
*
* @param null|string $pattern
* @param null|string $username
* @param null|string $user_token
*
* @return array
*/
public function getKeys($pattern = null, $username = null, $user_token = null) {
public function getKeys(?string $pattern = null, ?string $username = null, ?string $user_token = null): array
{
return $this->call('data-store/get-keys', compact(
'pattern', 'username', 'user_token'
));
}

/**
* @link https://gamejolt.com/game-api/doc/data-store/remove
*
* @param string $key
* @param null|string $username
* @param null|string $user_token
*
* @return array
*/
public function remove($key, $username = null, $user_token = null) {
public function remove(string $key, ?string $username = null, ?string $user_token = null): array
{
return $this->call('data-store/remove', compact(
'key', 'username', 'user_token'
));
Expand Down
8 changes: 2 additions & 6 deletions src/Callers/Friends.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ class Friends extends AbstractCaller {

/**
* @link https://gamejolt.com/game-api/doc/friends/fetch
*
* @param string $username
* @param string $user_token
*
* @return array
*/
public function fetch($username, $user_token) {
public function fetch(string $username, string $user_token): array
{
return $this->call('friends', compact(
'username', 'user_token'
));
Expand Down
Loading

0 comments on commit 488c2c6

Please sign in to comment.